You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
def remove_role(user):
old_groups = user.groups.filter(name__in=registered_roles.keys())
for old_group in old_groups: # Normally there is only one, but remove all other role groups
role = RolesManager.retrieve_role(old_group.name)
permissions_to_remove = Permission.objects.filter(codename__in=role.permission_names_list()).all()
user.user_permissions.remove(*permissions_to_remove)
user.groups.remove(*old_groups)
def assign_role(user, role):
role_cls = retrieve_role(role)
remove_role(user)
if role_cls:
role_cls.assign_role_to_user(user)
return role_cls
The text was updated successfully, but these errors were encountered:
filipeximenes
changed the title
assign_user_role helper function
assign_role helper function
Jun 23, 2016
The text was updated successfully, but these errors were encountered: