diff --git a/src/bot_api/json_processor.py b/src/bot_api/json_processor.py index e629258ecf..a0ea0ac159 100644 --- a/src/bot_api/json_processor.py +++ b/src/bot_api/json_processor.py @@ -16,12 +16,19 @@ class JSONProcessor: continue name = String.convert_to_camel_case(parameter.name) + name = name.replace('Dto', 'DTO') name_first_lower = String.first_to_lower(name) if name in values or name_first_lower in values: + value = '' if name in values: - args.append(values[name]) + value = values[name] else: - args.append(values[name_first_lower]) + value = values[name_first_lower] + + if isinstance(value, dict): + value = JSONProcessor.process(parameter.annotation, value) + + args.append(value) elif parameter.default != Parameter.empty: args.append(parameter.default) diff --git a/src/bot_api/model/update_auth_user_dto.py b/src/bot_api/model/update_auth_user_dto.py index 682f0122b4..9caa94738c 100644 --- a/src/bot_api/model/update_auth_user_dto.py +++ b/src/bot_api/model/update_auth_user_dto.py @@ -10,14 +10,14 @@ class UpdateAuthUserDTO(DtoABC): def __init__( self, - auth_user: AuthUserDTO, - new_auth_user: AuthUserDTO, + auth_user_dto: AuthUserDTO, + new_auth_user_dto: AuthUserDTO, change_password=False ): DtoABC.__init__(self) - self._auth_user = auth_user - self._new_auth_user = new_auth_user + self._auth_user = auth_user_dto + self._new_auth_user = new_auth_user_dto self._change_password = change_password @property diff --git a/src/bot_api/service/auth_service.py b/src/bot_api/service/auth_service.py index 07e750284c..ede6f15f18 100644 --- a/src/bot_api/service/auth_service.py +++ b/src/bot_api/service/auth_service.py @@ -191,12 +191,12 @@ class AuthService(AuthServiceABC): # update first name if update_user_dto.new_auth_user.first_name is not None and update_user_dto.auth_user.first_name != update_user_dto.new_auth_user.first_name: - user.FirstName = update_user_dto.new_auth_user.first_name + user.first_name = update_user_dto.new_auth_user.first_name # update last name if update_user_dto.new_auth_user.last_name is not None and update_user_dto.new_auth_user.last_name != '' and \ update_user_dto.auth_user.last_name != update_user_dto.new_auth_user.last_name: - user.LastName = update_user_dto.new_auth_user.last_name + user.last_name = update_user_dto.new_auth_user.last_name # update E-Mail if update_user_dto.new_auth_user.email is not None and update_user_dto.new_auth_user.email != '' and update_user_dto.auth_user.email != update_user_dto.new_auth_user.email: @@ -208,21 +208,22 @@ class AuthService(AuthServiceABC): is_existing_password_set = False is_new_password_set = False # hash passwords in DTOs - if update_user_dto.auth_user.Password is not None and update_user_dto.auth_user.Password != '': + if update_user_dto.auth_user.password is not None and update_user_dto.auth_user.password != '': is_existing_password_set = True - update_user_dto.auth_user.Password = self._hash_sha256(update_user_dto.auth_user.Password) + update_user_dto.auth_user.password = self._hash_sha256(update_user_dto.auth_user.password) - if update_user_dto.auth_user.Password != user.Password: + if update_user_dto.auth_user.password != user.password: raise ServiceException(ServiceErrorCode.InvalidUser, 'Wrong password') - if update_user_dto.new_auth_user.Password is not None and update_user_dto.new_auth_user.Password != '': + if update_user_dto.new_auth_user.password is not None and update_user_dto.new_auth_user.password != '': is_new_password_set = True - update_user_dto.new_auth_user.Password = self._hash_sha256(update_user_dto.new_auth_user.Password) + update_user_dto.new_auth_user.password = self._hash_sha256(update_user_dto.new_auth_user.password) # update password - if is_existing_password_set and is_new_password_set and update_user_dto.auth_user.Password != update_user_dto.new_auth_user.Password: - user.Password = update_user_dto.new_auth_user.Password + if is_existing_password_set and is_new_password_set and update_user_dto.auth_user.password != update_user_dto.new_auth_user.password: + user.password = update_user_dto.new_auth_user.password + self._auth_users.update_auth_user(user) self._db.save_changes() async def update_user_as_admin_async(self, update_user_dto: UpdateAuthUserDTO): @@ -242,31 +243,31 @@ class AuthService(AuthServiceABC): if user is None: raise ServiceException(ServiceErrorCode.InvalidUser, 'User not found') - if user.ConfirmationId is not None and update_user_dto.new_auth_user.is_confirmed: - user.ConfirmationId = None - elif user.ConfirmationId is None and not update_user_dto.new_auth_user.is_confirmed: + if user.confirmation_id is not None and update_user_dto.new_auth_user.is_confirmed: + user.confirmation_id = None + elif user.confirmation_id is None and not update_user_dto.new_auth_user.is_confirmed: user.confirmation_id = uuid.uuid4() # else # raise ServiceException(ServiceErrorCode.InvalidUser, 'E-Mail not confirmed') # update first name if update_user_dto.new_auth_user.first_name is not None and update_user_dto.auth_user.first_name != update_user_dto.new_auth_user.first_name: - user.FirstName = update_user_dto.new_auth_user.first_name + user.first_name = update_user_dto.new_auth_user.first_name # update last name if update_user_dto.new_auth_user.last_name is not None and update_user_dto.new_auth_user.last_name != '' and update_user_dto.auth_user.last_name != update_user_dto.new_auth_user.last_name: - user.LastName = update_user_dto.new_auth_user.last_name + user.last_name = update_user_dto.new_auth_user.last_name # update E-Mail if update_user_dto.new_auth_user.email is not None and update_user_dto.new_auth_user.email != '' and update_user_dto.auth_user.email != update_user_dto.new_auth_user.email: user_by_new_e_mail = self._auth_users.find_auth_user_by_email(update_user_dto.new_auth_user.email) if user_by_new_e_mail is not None: raise ServiceException(ServiceErrorCode.InvalidUser, 'User already exists') - user.EMail = update_user_dto.new_auth_user.email + user.email = update_user_dto.new_auth_user.email # update password if update_user_dto.change_password and update_user_dto.auth_user.password != update_user_dto.new_auth_user.password: - user.Password = self._hash_sha256(update_user_dto.new_auth_user.password) + user.password = self._hash_sha256(update_user_dto.new_auth_user.password) # update role if user.auth_role == update_user_dto.auth_user.auth_role and user.auth_role != update_user_dto.new_auth_user.auth_role: