mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-19 07:53:00 +00:00
always assign default roles on login
successful authentication of a user always grants 'user' role rather than only on first user creation in db
This commit is contained in:
@@ -771,8 +771,9 @@ class BaseHandler(RequestHandler):
|
|||||||
# Only set `admin` if the authenticator returned an explicit value.
|
# Only set `admin` if the authenticator returned an explicit value.
|
||||||
if admin is not None and admin != user.admin:
|
if admin is not None and admin != user.admin:
|
||||||
user.admin = admin
|
user.admin = admin
|
||||||
roles.assign_default_roles(self.db, entity=user)
|
# always ensure default roles ('user', 'admin' if admin) are assigned
|
||||||
self.db.commit()
|
# after a successful login
|
||||||
|
roles.assign_default_roles(self.db, entity=user)
|
||||||
# always set auth_state and commit,
|
# always set auth_state and commit,
|
||||||
# because there could be key-rotation or clearing of previous values
|
# because there could be key-rotation or clearing of previous values
|
||||||
# going on.
|
# going on.
|
||||||
|
@@ -1365,7 +1365,8 @@ async def test_login_default_role(app, username):
|
|||||||
user.roles = []
|
user.roles = []
|
||||||
app.db.commit()
|
app.db.commit()
|
||||||
|
|
||||||
# login *again*; user exists, shouldn't trigger change in roles
|
# login *again*; user exists,
|
||||||
|
# login should always trigger "user" role assignment
|
||||||
cookies = await app.login_user(username)
|
cookies = await app.login_user(username)
|
||||||
user = app.users[username]
|
user = app.users[username]
|
||||||
assert user.roles == []
|
assert [role.name for role in user.roles] == ["user"]
|
||||||
|
Reference in New Issue
Block a user