diff --git a/src/modules/list_users_in_group/app/list_users_in_group_usecase.py b/src/modules/list_users_in_group/app/list_users_in_group_usecase.py index b98e670..858c62d 100644 --- a/src/modules/list_users_in_group/app/list_users_in_group_usecase.py +++ b/src/modules/list_users_in_group/app/list_users_in_group_usecase.py @@ -19,6 +19,6 @@ def __call__(self, group: GROUPS, request_user_role: ROLE, request_user_groups: if group not in request_user_groups: raise ForbiddenAction("Usuário não tem permissão para buscar usuários deste grupo") - users_response = self.repo.get_users_in_group(group=group) + users_response = self.repo.get_users_in_system(group=group) return users_response \ No newline at end of file diff --git a/src/shared/domain/repositories/user_repository_interface.py b/src/shared/domain/repositories/user_repository_interface.py index 831902d..c69a033 100644 --- a/src/shared/domain/repositories/user_repository_interface.py +++ b/src/shared/domain/repositories/user_repository_interface.py @@ -20,7 +20,7 @@ def get_user_by_email(self, email: str) -> User: pass @abstractmethod - def get_users_in_group(self, system: str) -> List[User]: + def get_users_in_system(self, system: str) -> List[User]: pass @abstractmethod diff --git a/src/shared/infra/repositories/user_repository_cognito.py b/src/shared/infra/repositories/user_repository_cognito.py index ed76812..ce1d80e 100644 --- a/src/shared/infra/repositories/user_repository_cognito.py +++ b/src/shared/infra/repositories/user_repository_cognito.py @@ -49,7 +49,7 @@ def get_all_users(self) -> List[User]: all_users = [UserCognitoDTO.from_cognito(user).to_entity() for user in all_users] for user in all_users: - user.systems = self.get_groups_for_user(user.email) + user.systems = self.get_systems_for_user(user.email) return all_users @@ -59,14 +59,14 @@ def get_all_users(self) -> List[User]: except self.client.exceptions.InvalidParameterException as e: raise EntityError(e.response.get('Error').get('Message')) - def get_groups_for_user(self, email: str) -> List[str]: + def get_systems_for_user(self, email: str) -> List[str]: try: response = self.client.admin_list_groups_for_user( Username=email, UserPoolId=self.user_pool_id ) - groups = [group.get('GroupName') for group in response.get('Groups')] - return groups + systems = [group.get('GroupName') for group in response.get('Groups')] + return systems except self.client.exceptions.UserNotFoundException as e: raise EntityError(e.response.get('Error').get('Message')) @@ -81,7 +81,7 @@ def get_user_by_email(self, email: str) -> User: return None user = UserCognitoDTO.from_cognito(response).to_entity() - user.systems = self.get_groups_for_user(email) + user.systems = self.get_systems_for_user(email) return user @@ -145,7 +145,7 @@ def create_user(self, email: str, name: str, role: ROLE, systems: List[str]) -> except self.client.exceptions.InvalidParameterException as e: raise EntityError(e.response.get('Error').get('Message')) - def get_users_in_group(self, system: str) -> List[User]: + def get_users_in_system(self, system: str) -> List[User]: try: users = [] response = self.client.list_users_in_group( @@ -155,7 +155,7 @@ def get_users_in_group(self, system: str) -> List[User]: for user in response.get('Users'): user = UserCognitoDTO.from_cognito(user).to_entity() - user.systems = self.get_groups_for_user(user.email) + user.systems = self.get_systems_for_user(user.email) users.append(user) return users @@ -177,11 +177,11 @@ def update_user(self, user_email: str, kvp_to_update: dict, addSystems: List[str if addSystems is not None: for system in addSystems: - self.add_user_to_group(user_email, system) + self.add_user_to_system(user_email, system) if removeSystems is not None: for system in removeSystems: - self.remove_user_from_group(user_email, system) + self.remove_user_from_system(user_email, system) user = self.get_user_by_email(user_email) @@ -225,7 +225,7 @@ def disable_user(self, user_email: str) -> None: except self.client.exceptions.InvalidParameterException as e: raise EntityError(e.response.get('Error').get('Message')) - def add_user_to_group(self, user_email: str, system: str) -> None: + def add_user_to_system(self, user_email: str, system: str) -> None: try: self.client.admin_add_user_to_group( UserPoolId=self.user_pool_id, @@ -238,7 +238,7 @@ def add_user_to_group(self, user_email: str, system: str) -> None: except self.client.exceptions.InvalidParameterException as e: raise EntityError(e.response.get('Error').get('Message')) - def remove_user_from_group(self, user_email: str, system: str) -> None: + def remove_user_from_system(self, user_email: str, system: str) -> None: try: self.client.admin_remove_user_from_group( UserPoolId=self.user_pool_id, diff --git a/src/shared/infra/repositories/user_repository_mock.py b/src/shared/infra/repositories/user_repository_mock.py index e41f03b..911e3f8 100644 --- a/src/shared/infra/repositories/user_repository_mock.py +++ b/src/shared/infra/repositories/user_repository_mock.py @@ -37,7 +37,7 @@ def get_user_by_email(self, email: str) -> User: return userx return None - def get_users_in_group(self, system: str) -> List[User]: + def get_users_in_system(self, system: str) -> List[User]: users: List[User] = [] for user in self.users: if system in user.systems: diff --git a/tests/shared/infra/repositories/test_user_repository_cognito.py b/tests/shared/infra/repositories/test_user_repository_cognito.py index 3c20c6c..906e443 100644 --- a/tests/shared/infra/repositories/test_user_repository_cognito.py +++ b/tests/shared/infra/repositories/test_user_repository_cognito.py @@ -6,7 +6,7 @@ class Test_UserRepositoryCognito: @pytest.mark.skip("Can't test it locally") def test_list_groups(self): repo = UserRepositoryCognito() - repo.get_users_in_group('GAIA') + repo.get_users_in_system('GAIA') @pytest.mark.skip("Can't test it locally") def test_get_user_by_email(self): diff --git a/tests/shared/infra/repositories/test_user_repository_mock.py b/tests/shared/infra/repositories/test_user_repository_mock.py index ebe9a47..34285b3 100644 --- a/tests/shared/infra/repositories/test_user_repository_mock.py +++ b/tests/shared/infra/repositories/test_user_repository_mock.py @@ -46,7 +46,7 @@ def test_create_user_duplicated(self): def test_get_users_in_group(self): repo = UserRepositoryMock() - users = repo.get_users_in_group('GAIA') + users = repo.get_users_in_system('GAIA') assert len(users) == 1 assert type(users[0]) == User