Merge pull request 'Fixed authUser to user link #358' (#359) from #358 into support

Reviewed-on: sh-edraft.de/kd_discord_bot#359
This commit is contained in:
Sven Heidemann 2023-09-24 10:04:41 +02:00
commit 1e63baed97
3 changed files with 26 additions and 9 deletions

View File

@ -494,8 +494,14 @@ class AuthService(AuthServiceABC):
added_user = True added_user = True
db_user = self._auth_users.get_auth_user_by_email(user_dto.email) db_user = self._auth_users.get_auth_user_by_email(user_dto.email)
if db_user.users.count() == 0:
members.for_each(lambda x: self._auth_users.add_auth_user_user_rel(AuthUserUsersRelation(db_user, x))) auth_user_relation_ids = self._auth_users.get_auth_user_relation_ids(db_user)
for user in db_user.users:
if user.id in auth_user_relation_ids:
continue
self._auth_users.add_auth_user_user_rel(AuthUserUsersRelation(db_user, user))
if db_user.confirmation_id is not None and not added_user: if db_user.confirmation_id is not None and not added_user:
raise ServiceException(ServiceErrorCode.Forbidden, "E-Mail not verified") raise ServiceException(ServiceErrorCode.Forbidden, "E-Mail not verified")

View File

@ -14,6 +14,10 @@ class AuthUserRepositoryABC(ABC):
def __init__(self): def __init__(self):
pass pass
@abstractmethod
def get_auth_user_relation_ids(self, auth_user: AuthUser) -> List[int]:
pass
@abstractmethod @abstractmethod
def get_all_auth_users(self) -> List[AuthUser]: def get_all_auth_users(self) -> List[AuthUser]:
pass pass

View File

@ -50,13 +50,7 @@ class AuthUserRepositoryService(AuthUserRepositoryABC):
auth_user_id=self._get_value_from_result(au_result[0]), auth_user_id=self._get_value_from_result(au_result[0]),
) )
self._logger.trace( for user_id in self.get_auth_user_relation_ids(auth_user):
__name__,
f"Send SQL command: {auth_user.get_select_user_id_from_relations()}",
)
results = self._context.select(auth_user.get_select_user_id_from_relations())
for result in results:
user_id = self._get_value_from_result(result[0])
if user_id is None: if user_id is None:
continue continue
@ -65,6 +59,19 @@ class AuthUserRepositoryService(AuthUserRepositoryABC):
return auth_user return auth_user
def get_auth_user_relation_ids(self, auth_user: AuthUser) -> List[int]:
self._logger.trace(
__name__,
f"Send SQL command: {auth_user.get_select_user_id_from_relations()}",
)
relation_ids = List(int)
results = self._context.select(auth_user.get_select_user_id_from_relations())
for result in results:
self._logger.trace(__name__, f"Got auth user relation with id {result[0]}")
relation_ids.append(result[0])
return relation_ids
def get_all_auth_users(self) -> List[AuthUser]: def get_all_auth_users(self) -> List[AuthUser]:
users = List(AuthUser) users = List(AuthUser)
self._logger.trace(__name__, f"Send SQL command: {AuthUser.get_select_all_string()}") self._logger.trace(__name__, f"Send SQL command: {AuthUser.get_select_all_string()}")