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

Function change_role

app/auth.py:132–155  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

130
131
132def 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
158def delete_account(username):

Callers

nothing calls this directly

Calls 4

get_all_accountsFunction · 0.85
change_roleMethod · 0.80
info_sensitiveMethod · 0.80

Tested by

no test coverage detected