in modular_api_cli/modular_handler/user_handler.py [0:0]
def delete_user_handler(self, username) -> CommandResponse:
"""
Deletes user from ModularUser table
:param username: Username that will be deleted from white list
:return: CommandResponse
"""
_LOG.info(f'Going to delete user \'{username}\'')
existing_user = self.user_service.describe_user(username=username)
if not existing_user:
_LOG.error('User does not exist')
raise ModularApiConfigurationException(
f'User \'{username}\' does not exist. Nothing to delete')
if existing_user.state != ACTIVATED_STATE:
_LOG.error('User already marked as deleted or blocked')
raise ModularApiBadRequestException(
f'User \'{username}\' is blocked or deleted.{line_sep}To get '
f'more detailed information please execute command:{line_sep}'
f'modular user describe --username {username}')
if self.user_service.calculate_user_hash(existing_user) != \
existing_user.hash:
click.confirm(
f'User \'{username}\' is compromised. Command execution '
f'leads to user entity hash sum recalculation. Are you sure?',
abort=True)
existing_user.state = REMOVED_STATE
existing_user.last_modification_date = utc_time_now().isoformat()
user_hash_sum = self.user_service.calculate_user_hash(existing_user)
existing_user.hash = user_hash_sum
self.user_service.save_user(user_item=existing_user)
_LOG.info('User successfully deleted')
return CommandResponse(
message=f'User {username} has been successfully deleted')