Giter Club home page Giter Club logo

django-user-roles's Introduction

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/

django-user-roles's People

Contributors

j4mie avatar nvlaarhoven avatar timstimpson avatar tomchristie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-user-roles's Issues

Support display names for roles

For displaying roles to users of the application. Example:

You have received a new message from {{ user.get_profile.full_name }}. This user is an {{ user.role.display_name }}.

(display_name might not be the best naming..)

Should work just like model choices. User role names can (optionally) be tuples:

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

Authentication backend for roles

I appreciate the effort you put in this pip package. This suits for my use case with some changes in code. I added an authentication backend to the project that I am currently working in so that a role can be assigned to a user at the time of logging in. I think it would be nice if this functionality can be added in django-user-roles too.

Mixin for role_required

Hi,

It would be nice to have a mixin for the role_required decorator to use on class based views.

Cheers,
Matt Stevens

No instance of package in pypi

pip install does not locate the package.

pip install django-user-roles
Downloading/unpacking django-user-roles
Could not find any downloads that satisfy the requirement django-user-roles
No distributions at all found for django-user-roles

Remove the user role

Is there a way to remove the user role?
I tried:

set_user_role(user_to_change, None)

and if there is a way, can you document it

(by the way, nice app!)

role in request.user

I try this in a view in views.py:

if request.user.role in ('somerole',):

and it does not seem to work...

Is it correct, the reuqest.user doe snot work with role?

if so of course there is a workaround use request.user.id and get the user with that....

Multiple roles per user

Hi, I am new to role based development.

Can a user be assigned multiple roles using this app?

django 1.9 support

I Am using this package in some of my sites. In django 1.8 I get this warning:

django_user_roles-0.1.0-py2.7.egg/userroles/init.py:3: RemovedInDjango19Warning: django.utils.importlib will be removed in Django 1.9.
from django.utils import importlib

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.