Django module for converting regular django permissions to CASL-Style rules
Project description
CASL Django is an app that converts the usual Django permissions to CASL-Style rules.
CASL is an isomorphic authorization JavaScript library: https://github.com/stalniy/casl/
Example
Having a rule called my_app.change_item, will generate a CASL rule:
{
subject: 'my_app/item',
action: 'change'
}
If you have more than one rule for the same subject, for example:
my_app.change_item my_app.add_item my_app.remove_item
This will generate:
{
subject: 'my_app/item',
actions: ['add', 'change', 'remove']
}
Configuration
By default, the length for subject and action fields is 128 characters, you can increase the length of them by adding to your settings file:
CASL_DJANGO = {
'subject-length': 256,
'action-length': 256
}
Custom Permissions
Sometimes you’d like to have custom permissions for your users, given this, you can add to your user using the Permission’s add_permission class method:
from casl_django.casl.permissions import Permissions ... my_custom_permission = Permissions.create(subject="navigation", action="index") ... Permissions.set_user_permission(user=user, permission=my_custom_permission)
Or you can import casl_django.models.UserPermission and create objects as desired.
Filtering
The view by default filters subject with iexact and action with icontains, you can call the url with: ?subject=navigation&action=users-roles, this would return:
[
{"subject": "navigation", action: "user-roles-index"},
{"subject": "navigation", action: "user-roles-list"},
{"subject": "navigation", action: "user-roles-id"}
]
Quick start
Add “casl_django” to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [ ... 'casl_django', ]Use the included views to generate your desired urls:
from casl_django.views import UserPermissionsView ... url(r'/api/casl/user/', UserPermissionsView.as_view())
Run python manage.py migrate to create the models.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file casl-django-0.2.tar.gz.
File metadata
- Download URL: casl-django-0.2.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.7.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e22c2c8c6ff771c57da3eca150bb929fefc92170eb4d96e1693b416d349ac62b
|
|
| MD5 |
bad7593677e892f820b76b578caa5eb0
|
|
| BLAKE2b-256 |
488201b3b7cc2e0bd0e7b8d85b3375d3924d08614560a70c3638b1100690acc2
|