Deletes an account from the system. Args: username: (str) Raises: db.users.UserDoesNotExistError: If a user with the given username does not exist on the system. OneAdminRequiredError: If the user with the given username is the last remaining
(username)
| 156 | |
| 157 | |
| 158 | def delete_account(username): |
| 159 | """Deletes an account from the system. |
| 160 | |
| 161 | Args: |
| 162 | username: (str) |
| 163 | |
| 164 | Raises: |
| 165 | db.users.UserDoesNotExistError: If a user with the given username |
| 166 | does not exist on the system. |
| 167 | OneAdminRequiredError: If the user with the given username is the last |
| 168 | remaining admin while other users still exist on the system. |
| 169 | """ |
| 170 | users = get_all_accounts() |
| 171 | all_admins = [u for u in users if u.role == Role.ADMIN] |
| 172 | if len(users) > 1 and len( |
| 173 | all_admins) == 1 and all_admins[0].username == username: |
| 174 | raise OneAdminRequiredError( |
| 175 | 'Cannot delete last remaining admin user on the system.') |
| 176 | |
| 177 | db.users.Users().delete(username) |
| 178 | logger.info_sensitive('Deleted user %s', username) |
| 179 | video_service.restart() |
| 180 | |
| 181 | |
| 182 | def delete_all_accounts(): |
nothing calls this directly
no test coverage detected