Skip to content

Commit

Permalink
Merge pull request #715 from SUNET/lundberg_manacc_fixes
Browse files Browse the repository at this point in the history
Backend fixes for managed accounts
  • Loading branch information
helylle authored Nov 19, 2024
2 parents 6852018 + 41a9e96 commit c35040e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
7 changes: 4 additions & 3 deletions src/eduid/graphdb/groupdb/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@ def save(self, group: Group) -> Group:
with self.db.driver.session(default_access_mode=WRITE_ACCESS) as session:
try:
tx = session.begin_transaction()
except ClientError as e:
logger.error(e)
raise EduIDGroupDBError(e.message)
try:
self._remove_missing_users_and_groups(tx, group, Role.OWNER)
self._remove_missing_users_and_groups(tx, group, Role.MEMBER)
saved_group = self._create_or_update_group(tx, group)
Expand All @@ -396,9 +400,6 @@ def save(self, group: Group) -> Group:
except ConstraintError as e:
logger.error(e)
raise VersionMismatch("Tried to save a group with wrong version")
except ClientError as e:
logger.error(e)
raise EduIDGroupDBError(e.message)
finally:
if tx.closed():
logger.info("Group save successful")
Expand Down
7 changes: 3 additions & 4 deletions src/eduid/maccapi/routers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,12 @@ async def remove_user(
)
request.app.context.stats.count("maccapi_remove_user_success")
except UserDoesNotExist as e:
request.app.context.logger.error(f"remove_user error: {e}")
request.app.context.logger.error(f"remove_user error: {e} - user already removed")
remove_user_response = UserRemovedResponse(
status="error",
status="success",
scope=request.app.context.config.default_eppn_scope,
)
request.app.context.stats.count("maccapi_remove_user_error")
response.status_code = status.HTTP_422_UNPROCESSABLE_ENTITY

return remove_user_response

Expand Down Expand Up @@ -185,7 +184,7 @@ async def reset_password(
)
request.app.context.stats.count("maccapi_reset_password_error")
if isinstance(e, UserDoesNotExist):
response.status_code = status.HTTP_422_UNPROCESSABLE_ENTITY
response.status_code = status.HTTP_404_NOT_FOUND
else:
response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR

Expand Down
4 changes: 2 additions & 2 deletions src/eduid/maccapi/tests/test_maccapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ def test_remove_error(self) -> None:
headers["Authorization"] = f"Bearer {token}"

response = self.client.post(url="/Users/remove", json={"eppn": "made_up"}, headers=headers)
assert response.status_code == 422
assert response.status_code == 200

def test_reset_error(self) -> None:
token = self._make_bearer_token(claims=self.claims)

headers = self.headers
headers["Authorization"] = f"Bearer {token}"
response = self.client.post(url="/Users/reset_password", json={"eppn": "made_up"}, headers=headers)
assert response.status_code == 422
assert response.status_code == 404
2 changes: 1 addition & 1 deletion src/eduid/userdb/scimapi/groupdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def update_group(self, update_request: GroupUpdateRequest, db_group: ScimApiGrou
db_group.external_id = update_request.external_id
logger.debug(f"Changed external id for group: {db_group.external_id} -> {update_request.external_id}")

# Check if there where new, changed or removed members
# Check if there were new, changed or removed members
if db_group.graph.members != updated_members:
changed = True
db_group.graph = replace(db_group.graph, members=updated_members)
Expand Down

0 comments on commit c35040e

Please sign in to comment.