mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-02-05 23:50:37 +00:00
feat: add UserOrGroupNotFound
This commit is contained in:
parent
e74717d56b
commit
b864ca5fea
|
@ -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(),
|
||||
|
|
|
@ -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"""
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
Loading…
Reference in a new issue