Skip to content

buildingenergy/superperms

Repository files navigation

CircleCI Status

superperms

HappyTrees

Install

install superperms

pip install superperms

add superperms to your INSTALLED_APPS

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.flatpages',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.humanize',
    'django.contrib.admin',
    'south',
    'superperms.orgs',
)

Run migrations to create the database tables

python manage.py migrate superperms.orgs

Note: if your app uses a custom AUTH_USER_MODEL (a user model that is not django.contrib.auth.User), you will need to create the table for your user before you run the migrations for superperms. You can declare this dependency in the initial migration for the custom user as show below. This is necessary so that superperm organizations can have a foreign key to the custom user model.

class Migration(SchemaMigration):

    needed_by = (
        ('superperms.orgs', '0001_initial'),
    )

Configuration Options

  • ALLOW_SUPER_USER_PERMS: Allows Django super_user class accounts to bypass permissions checks. This is useful mainly for development, but defaults to True.

Example Usage

  • To limit views to people who have member-level roles and above, you could use the following decorator definiition. Users who are viewers will recieve a Django HttpRequestNotAuthorized response (e.g. a 403) without ever executing the code inside the view.
from superperms.orgs.decorators import has_perm #  Imports our decorator factory.

# This view will be protected against anybody whose account is "lower"
# than a member. Default role types include ['owner', 'member', 'viewer'].
@has_perm('requires_member')
def protected_view(request):
    pass

Development and Testing

clone the repo and install requirements

$ git clone git@github.com:buildingenergy/superperms.git
$ mkvirtualenv superperms
(superperms)$ cd superperms
(superperms)$ pip install -r requirements.txt

tests should pass, PEP8 is enforced

(superperms)$ ./test.sh

About

Who can do what? -- superperms is the one stop shop for NOPE.

Resources

License

Stars

Watchers

Forks

Packages

No packages published