Skip to content
This repository has been archived by the owner on Dec 6, 2021. It is now read-only.
/ django-user-roles Public archive

DEPRECATED: Simple role-based user permissions for Django.

Notifications You must be signed in to change notification settings

dabapps/django-user-roles

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django User Roles

Simple role-based user permissions for Django.

django-user-roles is a simple, reusable app that allows you to create a set of user roles, which can be used to control which views each type of user has permission to view, and to customize how the site is presented to different types of user.

DEPRECATED

PLEASE NOTE: This repository is no longer actively maintained or regularly used by DabApps and therefore should be considered deprecated. Please find alternative packages for your needs or feel free to create and maintain your own fork.

Settings

Install using pip:

pip install django-user-roles

Add the USER_ROLES setting to your settings.py. For example:

USER_ROLES = (
    'manager',
    'moderator',
    'client',
)

Basic Usage

Setting the user role:

from userroles.models import set_user_role
from userroles import roles

set_user_role(self.user, roles.manager)

Checking the user role:

from userroles import roles

user.role == roles.manager
user.role in (roles.manager, roles.moderator)
user.role.is_moderator

The role_required decorator provides similar behavior to Django's login_required and permission_required decorators. If the user accessing the view does not have the required roles, they will be redirected to the login page:

from userroles.decorators import role_required
from userroles import roles

@role_required(roles.manager, roles.moderator)
def view(request):
    ...

Testing

./manage.py test userroles

Code of conduct

For guidelines regarding the code of conduct when contributing to this repository please review https://www.dabapps.com/open-source/code-of-conduct/

About

DEPRECATED: Simple role-based user permissions for Django.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages