Skip to content
Permalink
Browse files

mgr/dashboard: Fix logout of user when `enabled` field is adapted

Fixes: ceph#29046

Signed-off-by: Patrick Nawracay <pnawracay@suse.com>
  • Loading branch information...
p-se committed Jul 15, 2019
1 parent 0e8a565 commit f73039fd82fa68072f6670b8d0e0c6771dfa3533
@@ -90,7 +90,7 @@ def set(self, username, password=None, name=None, email=None, roles=None,
user.name = name
user.email = email
if enabled is not None:
user.enabled = enabled
user.set_enabled(enabled)
user.set_roles(user_roles)
mgr.ACCESS_CTRL_DB.save()
return User._user_to_dict(user)
@@ -183,6 +183,10 @@ def __init__(self, username, password, name=None, email=None, roles=None,
self.lastUpdate = lastUpdate
self.enabled = enabled

def set_enabled(self, enabled=True):
self.enabled = enabled
self.refreshLastUpdate()

def refreshLastUpdate(self):
self.lastUpdate = int(time.time())

@@ -238,6 +242,7 @@ def to_dict(self):
def from_dict(cls, u_dict, roles):
# Ensure downward compatibility of `enabled`
enabled = u_dict['enabled'] if 'enabled' in u_dict else True

return User(u_dict['username'], u_dict['password'], u_dict['name'], u_dict['email'],
{roles[r]
for r in u_dict['roles']}, u_dict['lastUpdate'], enabled)
@@ -534,7 +539,7 @@ def ac_user_create_cmd(_, username, password=None, rolename=None, name=None,
def ac_user_enable(_, username):
try:
user = mgr.ACCESS_CTRL_DB.get_user(username)
user.enabled = True
user.set_enabled(True)

mgr.ACCESS_CTRL_DB.save()
return 0, json.dumps(user.to_dict()), ''
@@ -548,7 +553,7 @@ def ac_user_enable(_, username):
def ac_user_disable(_, username):
try:
user = mgr.ACCESS_CTRL_DB.get_user(username)
user.enabled = False
user.set_enabled(False)

mgr.ACCESS_CTRL_DB.save()
return 0, json.dumps(user.to_dict()), ''

0 comments on commit f73039f

Please sign in to comment.
You can’t perform that action at this time.