Skip to content

Commit

Permalink
change name repo
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielGodoy01 committed Aug 27, 2024
1 parent bfee992 commit 18ba236
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions src/shared/infra/repositories/user_repository_cognito.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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'))

Expand All @@ -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

Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/shared/infra/repositories/user_repository_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 18ba236

Please sign in to comment.