Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assign_role helper function #49

Closed
filipeximenes opened this issue Jun 23, 2016 · 0 comments
Closed

assign_role helper function #49

filipeximenes opened this issue Jun 23, 2016 · 0 comments

Comments

@filipeximenes
Copy link
Contributor

filipeximenes commented Jun 23, 2016

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
@filipeximenes filipeximenes changed the title assign_user_role helper function assign_role helper function Jun 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant