From ec9f2a53b4dd52072d5e72f0f4cbe95f476f0718 Mon Sep 17 00:00:00 2001 From: Gabriel de Godoy Braz <61150821+GabrielGodoy01@users.noreply.github.com> Date: Mon, 3 Jun 2024 12:15:25 -0300 Subject: [PATCH 1/3] Update get_all_users_usecase.py --- src/modules/get_all_users/app/get_all_users_usecase.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/get_all_users/app/get_all_users_usecase.py b/src/modules/get_all_users/app/get_all_users_usecase.py index b111aa8..9f1c012 100644 --- a/src/modules/get_all_users/app/get_all_users_usecase.py +++ b/src/modules/get_all_users/app/get_all_users_usecase.py @@ -12,7 +12,7 @@ def __init__(self, repo: IUserRepository): def __call__(self, requester_role: ROLE) -> List[User]: if requester_role != ROLE.ADMIN_COLLABORATOR: - raise ForbiddenAction("Usuário não tem permissão para criar usuários") + raise ForbiddenAction("Usuário não tem permissão para listar usuários") users_response = self.repo.get_all_users() From f0ef1e59f7284e500a07999c6395a2047f7caad8 Mon Sep 17 00:00:00 2001 From: Gabriel de Godoy Braz <61150821+GabrielGodoy01@users.noreply.github.com> Date: Mon, 3 Jun 2024 12:26:01 -0300 Subject: [PATCH 2/3] UPDATE CONTROLLERS --- src/modules/create_user/app/create_user_controller.py | 5 ++++- src/modules/get_all_users/app/get_all_users_controller.py | 7 +++++-- src/modules/update_user/app/update_user_controller.py | 7 +++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/modules/create_user/app/create_user_controller.py b/src/modules/create_user/app/create_user_controller.py index 5f98de4..658d795 100644 --- a/src/modules/create_user/app/create_user_controller.py +++ b/src/modules/create_user/app/create_user_controller.py @@ -8,7 +8,7 @@ from .create_user_usecase import CreateUserUsecase from src.shared.helpers.errors.controller_errors import MissingParameters from src.shared.helpers.errors.domain_errors import EntityError -from src.shared.helpers.errors.usecase_errors import DuplicatedItem, InvalidCredentials +from src.shared.helpers.errors.usecase_errors import DuplicatedItem, ForbiddenAction, InvalidCredentials from src.shared.helpers.external_interfaces.external_interface import IRequest, IResponse from src.shared.helpers.external_interfaces.http_codes import BadRequest, InternalServerError, Conflict, \ Created, Forbidden, Unauthorized @@ -69,5 +69,8 @@ def __call__(self, request: IRequest) -> IResponse: except EntityError as err: return BadRequest(body=f"Parâmetro inválido: {err.message}") + except ForbiddenAction as err: + return Forbidden(body=err.args[0]) + except Exception as err: return InternalServerError(body=err.args[0]) diff --git a/src/modules/get_all_users/app/get_all_users_controller.py b/src/modules/get_all_users/app/get_all_users_controller.py index 91c062a..fc27707 100644 --- a/src/modules/get_all_users/app/get_all_users_controller.py +++ b/src/modules/get_all_users/app/get_all_users_controller.py @@ -3,9 +3,9 @@ from .get_all_users_viewmodel import GetAllUsersViewmodel from src.shared.helpers.errors.controller_errors import MissingParameters from src.shared.helpers.errors.domain_errors import EntityError -from src.shared.helpers.errors.usecase_errors import InvalidCredentials, InvalidTokenError, NoItemsFound +from src.shared.helpers.errors.usecase_errors import ForbiddenAction, InvalidCredentials, InvalidTokenError, NoItemsFound from src.shared.helpers.external_interfaces.external_interface import IRequest, IResponse -from src.shared.helpers.external_interfaces.http_codes import OK, BadRequest, InternalServerError, Unauthorized +from src.shared.helpers.external_interfaces.http_codes import OK, BadRequest, Forbidden, InternalServerError, Unauthorized class GetAllUsersController: @@ -27,6 +27,9 @@ def __call__(self, request: IRequest) -> IResponse: except MissingParameters as err: return BadRequest(body=f"Parâmetro ausente: {err.message}") + + except ForbiddenAction as err: + return Forbidden(body=err.args[0]) except Exception as err: return InternalServerError(body=err.args[0]) \ No newline at end of file diff --git a/src/modules/update_user/app/update_user_controller.py b/src/modules/update_user/app/update_user_controller.py index 45e629e..0cdded2 100644 --- a/src/modules/update_user/app/update_user_controller.py +++ b/src/modules/update_user/app/update_user_controller.py @@ -5,9 +5,9 @@ from src.shared.domain.enums.groups_enum import GROUPS from src.shared.helpers.errors.controller_errors import MissingParameters from src.shared.helpers.errors.domain_errors import EntityError -from src.shared.helpers.errors.usecase_errors import InvalidCredentials, InvalidTokenError, NoItemsFound +from src.shared.helpers.errors.usecase_errors import ForbiddenAction, InvalidCredentials, InvalidTokenError, NoItemsFound from src.shared.helpers.external_interfaces.external_interface import IRequest, IResponse -from src.shared.helpers.external_interfaces.http_codes import OK, BadRequest, InternalServerError, Unauthorized +from src.shared.helpers.external_interfaces.http_codes import OK, BadRequest, Forbidden, InternalServerError, Unauthorized class UpdateUserController: @@ -70,5 +70,8 @@ def __call__(self, request: IRequest) -> IResponse: except InvalidTokenError as err: return Unauthorized(body="Token inválido ou expirado") + except ForbiddenAction as err: + return Forbidden(body=err.args[0]) + except Exception as err: return InternalServerError(body=err.args[0]) \ No newline at end of file From 409b6d7788639b090aa966e71bd545d9ad7d63cd Mon Sep 17 00:00:00 2001 From: Gabriel de Godoy Braz <61150821+GabrielGodoy01@users.noreply.github.com> Date: Tue, 25 Jun 2024 10:59:52 -0300 Subject: [PATCH 3/3] Update groups_enum.py --- src/shared/domain/enums/groups_enum.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/shared/domain/enums/groups_enum.py b/src/shared/domain/enums/groups_enum.py index 4b90c07..eb72e25 100644 --- a/src/shared/domain/enums/groups_enum.py +++ b/src/shared/domain/enums/groups_enum.py @@ -5,3 +5,4 @@ class GROUPS(Enum): GAIA = "GAIA" JUNDIAI = "JUNDIAI" FORMULARIOS = "FORMULARIOS" + RECAPE_SP = "RECAPE_SP"