feat: add UserOrGroupNotFound

This commit is contained in:
dettlaff 2024-12-20 02:01:00 +04:00
parent e74717d56b
commit b864ca5fea
3 changed files with 18 additions and 4 deletions

View file

@ -31,6 +31,7 @@ from selfprivacy_api.repositories.users.exceptions import (
DisplaynameTooLong,
NoPasswordResetLinkFoundInResponse,
PasswordIsEmpty,
UserOrGroupNotFound,
UsernameForbidden,
InvalidConfiguration,
UserAlreadyExists,
@ -142,7 +143,7 @@ class UsersMutations:
def delete_user(self, username: str) -> GenericMutationReturn:
try:
delete_user_action(username)
except UserNotFound as error:
except (UserNotFound, UserOrGroupNotFound) as error:
return GenericMutationReturn(
success=False,
message=error.get_error_message(),
@ -195,7 +196,7 @@ class UsersMutations:
return return_failed_mutation_return(
message=error.get_error_message(),
)
except UserNotFound as error:
except (UserNotFound, UserOrGroupNotFound) as error:
return return_failed_mutation_return(
message=error.get_error_message(),
code=404,
@ -270,7 +271,7 @@ class UsersMutations:
def generate_password_reset_link(self, username: str) -> PasswordResetLinkReturn:
try:
password_reset_link = generate_password_reset_link_action(username=username)
except UserNotFound as error:
except (UserNotFound, UserOrGroupNotFound) as error:
return PasswordResetLinkReturn(
success=False,
message=error.get_error_message(),

View file

@ -9,6 +9,14 @@ class UserNotFound(Exception):
return "User not found"
class UserOrGroupNotFound(Exception):
"""User or group not found"""
@staticmethod
def get_error_message() -> str:
return "User or group not found"
class UserIsProtected(Exception):
"""User is protected and cannot be deleted or modified"""

View file

@ -10,6 +10,7 @@ from selfprivacy_api.repositories.users.exceptions import (
NoPasswordResetLinkFoundInResponse,
UserAlreadyExists,
UserNotFound,
UserOrGroupNotFound,
)
from selfprivacy_api.repositories.users.exceptions_kanidm import (
FailedToGetValidKanidmToken,
@ -236,6 +237,7 @@ class KanidmUserRepository(AbstractUserRepository):
KanidmQueryError: If an error occurs during the request.
UserAlreadyExists: If the user already exists.
UserNotFound: If the user is not found.
UserOrGroupNotFound: If the user or group does not exist.
Raises from KanidmAdminToken:
KanidmCliSubprocessError: If there is an error with the Kanidm CLI subprocess.
@ -295,7 +297,7 @@ class KanidmUserRepository(AbstractUserRepository):
if isinstance(response_data, str):
if response_data == "nomatchingentries":
raise UserNotFound # does it work only for user?
raise UserOrGroupNotFound # does it work only for user? - NO
elif response_data == "accessdenied":
raise KanidmQueryError(
error_text="Kanidm access issue",
@ -422,6 +424,7 @@ class KanidmUserRepository(AbstractUserRepository):
Raises:
KanidmQueryError: If an error occurs while deleting the user.
UserNotFound: If the user does not exist.
UserOrGroupNotFound: If the user does not exist.
Raises from KanidmAdminToken:
KanidmCliSubprocessError: If there is an error with the Kanidm CLI subprocess.
@ -448,6 +451,7 @@ class KanidmUserRepository(AbstractUserRepository):
Raises:
KanidmQueryError: If an error occurs while updating the user.
UserNotFound: If the user does not exist.
UserOrGroupNotFound: If the user or group does not exist.
Raises from KanidmAdminToken:
KanidmCliSubprocessError: If there is an error with the Kanidm CLI subprocess.
@ -483,6 +487,7 @@ class KanidmUserRepository(AbstractUserRepository):
Raises:
UserNotFound: If the user does not exist.
UserOrGroupNotFound: If the user does not exist.
KanidmQueryError: If an error occurs while retrieving the user data.
KanidmReturnUnknownResponseType: If response type is unknown.