Changes the role of the account with the given username. Args: username: (str) new_role: (Role) Raises: db.users.UserDoesNotExistError: If a user with the given username does not exist on the system. OneAdminRequiredError: If the user with the gi
(username, new_role)
| 130 | |
| 131 | |
| 132 | def change_role(username, new_role): |
| 133 | """Changes the role of the account with the given username. |
| 134 | |
| 135 | Args: |
| 136 | username: (str) |
| 137 | new_role: (Role) |
| 138 | |
| 139 | Raises: |
| 140 | db.users.UserDoesNotExistError: If a user with the given username |
| 141 | does not exist on the system. |
| 142 | OneAdminRequiredError: If the user with the given username is the last |
| 143 | remaining admin on the system. |
| 144 | """ |
| 145 | all_admins = [u for u in get_all_accounts() if u.role == Role.ADMIN] |
| 146 | if len(all_admins) == 1 and all_admins[0].username == username: |
| 147 | raise OneAdminRequiredError( |
| 148 | 'Cannot change the role of last remaining admin user on the system.' |
| 149 | ) |
| 150 | |
| 151 | db.users.Users().change_role(username=username, |
| 152 | new_role=new_role, |
| 153 | credentials_change_time=utc.now()) |
| 154 | logger.info_sensitive('Changed role of user %s', username) |
| 155 | video_service.restart() |
| 156 | |
| 157 | |
| 158 | def delete_account(username): |
nothing calls this directly
no test coverage detected