MCPcopy Index your code
hub / github.com/tiny-pilot/tinypilot / delete_account

Function delete_account

app/auth.py:158–179  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

156
157
158def 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
182def delete_all_accounts():

Callers

nothing calls this directly

Calls 4

get_all_accountsFunction · 0.85
deleteMethod · 0.80
info_sensitiveMethod · 0.80

Tested by

no test coverage detected