Serious Django: Permissions
https://github.com/serioeseGmbH/serious-django-permissions
serious-django-permissions is a Django extension that makes it possible to define Permissions in each app, and Groups in a central place. It makes these Permissions import-able and checkable via user.has_perm:
from some_app.permissions import ChangeSomethingPermission
def change_something(something, user):
if not user.has_perm(ChangeSomethingPermission):
raise PermissionDenied("You can't change this something.)
else:
return something.change()
Both permissions and groups can then be created in the database with a single manage.py call (see Quick start below).
Quick start
Install the package with pip:
pip install serious-django-permissions
Add “serious_django_permissions” to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [ ... 'serious_django_permissions', ]Add serious_django_permissions.permissions.PermissionModelBackend to your AUTHENTICATION_BACKENDS setting. This enables you to do permission checks like user.has_perm(SomePermission):
AUTHENTICATION_BACKENDS = [ ... 'serious_django_permissions.permissions.PermissionModelBackend', ]In each app that should define a permission, import serious_django_permissions.permissions.Permission and create subclasses of it.
The name of your subclasses must end in Permission, and each subclass must define a description attribute. For instance, let’s say you have the file myapp/permissions.py:
from serious_django_permissions.permissions import Permission from .models import MyModel class MyPermission(Permission): model = 'MyModel' # should be a model inside myapp.models, or not defined for global permissions. description = 'A description for this permission'Run python manage.py create_permissions to create all defined permissions on the database level.
New in version 0.7: Create all permissions (including groups) programmatically by calling setup_permissions():
from serious_django_permissions.helpers import setup_permissions setup_permissions()
If you’d like to use the Groups feature as well:
Create a file named something like some_app/groups.py inside one of your apps, or in the folder where your settings live. An example:
from serious_django_permissions.groups import Group from app_one.permissions import\ AppOnePermissionA, AppOnePermissionB from app_two.permissions import\ AppTwoPermission class GroupA(Group): permissions = [ AppOnePermissionA, AppTwoPermission ] class GroupB(Group): permissions = [ AppOnePermissionB, AppTwoPermission ]Reference the defined groups file in your settings:
DEFAULT_GROUPS_MODULE = 'some_app.groups'
Run python manage.py create_groups to create all permissions and assign them to the groups.
Metadata
Release files for serious-django-permissions 0.17
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| serious-django-permissions-0.17.tar.gz | 6.7 kB | Without provenance | Details for serious-django-permissions-0.17.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| serious_django_permissions-0.17-py3-none-any.whl | Python 3 | none | any | Details for serious_django_permissions-0.17-py3-none-any.whl |
Total release size: 16.9 kB
Release files / serious-django-permissions-0.17.tar.gz
| Download URL | serious-django-permissions-0.17.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0ada9866392476ac707e00f984ae3d45f5a164a9afc3ef7c024d67077792c415
|
|
BLAKE2b-256 checksum How to use checksums |
6765ef1afe3e16ec15076bcf4967c6633a9d32162f7f2a076744abdcb052d658
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.7.6
|
Release files / serious_django_permissions-0.17-py3-none-any.whl
| Download URL | serious_django_permissions-0.17-py3-none-any.whl |
|---|---|
| Size | 10.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bfd339ba1fffd39dda84575684f1876860f56a5096d49757a7ef0a864842b9bc
|
|
BLAKE2b-256 checksum How to use checksums |
60edee2a37b6aeea696ae6c7754bf9a02e5311f4c4544c4cc4f31248f17223e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.7.6
|
Security for serious-django-permissions 0.17
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.