Club role assignment logs

This commit is contained in:
sayali 2021-01-28 15:58:12 -08:00
parent ed57a5a45a
commit 20792dfe3a
2 changed files with 16 additions and 4 deletions

View File

@ -212,12 +212,16 @@ def update_user(user, profile, roles):
else: else:
# we add 'lemur' specific roles, so they do not get marked as removed # we add 'lemur' specific roles, so they do not get marked as removed
removed_roles = []
for ur in user.roles: for ur in user.roles:
if not ur.third_party: if not ur.third_party:
roles.append(ur) roles.append(ur)
else: elif ur not in roles:
log_service.audit_log("unassign_role", ur.name, f"Un-assigning the role for {user.name}") # This is a role assigned in lemur, but not returned by sso during current login
removed_roles.append(ur.name)
if removed_roles:
log_service.audit_log("unassign_role", user.name, f"Un-assigning roles {removed_roles}")
# update any changes to the user # update any changes to the user
user_service.update( user_service.update(
user.id, user.id,

View File

@ -68,21 +68,29 @@ def update_roles(user, roles):
:param user: :param user:
:param roles: :param roles:
""" """
removed_roles = []
for ur in user.roles: for ur in user.roles:
for r in roles: for r in roles:
if r.id == ur.id: if r.id == ur.id:
break break
else: else:
user.roles.remove(ur) user.roles.remove(ur)
log_service.audit_log("unassign_role", ur.name, f"Un-assigning the role for user {user.username}") removed_roles.append(ur.name)
if removed_roles:
log_service.audit_log("unassign_role", user.username, f"Un-assigning roles {removed_roles}")
added_roles = []
for r in roles: for r in roles:
for ur in user.roles: for ur in user.roles:
if r.id == ur.id: if r.id == ur.id:
break break
else: else:
user.roles.append(r) user.roles.append(r)
log_service.audit_log("assign_role", r.name, f"Assigning the role to user {user.username}") added_roles.append(r.name)
if added_roles:
log_service.audit_log("assign_role", user.username, f"Assigning roles {added_roles}")
def get(user_id): def get(user_id):