https://github.com/raiderrobert/django-dynaperms
https://github.com/raiderrobert/django-dynaperms
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/raiderrobert/django-dynaperms
- Owner: raiderrobert
- License: mit
- Created: 2019-05-14T12:39:48.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-08-07T19:23:46.000Z (almost 6 years ago)
- Last Synced: 2026-02-27T11:07:11.575Z (5 months ago)
- Language: Python
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Django Dynaperms
Django's [permissions](https://docs.djangoproject.com/en/3.0/topics/auth/default/#permissions-and-authorization) are very useful,
but sometimes authorizations to certain system features can rapidly change based on different needs or need a way to allow
easily expand the number of different ways to check if access should be granted.
Rather than creating/updating/deleting database records, let's just run a function to see if the return value is True or False.
## Example
In `debit_card.perms`, you define a function like below:
```
def have_valid_card(user: User) -> bool:
# Check some API or something
```
In your `settings.py` file
```
AUTHENTICATION_BACKENDS = (
...
'dynaperms.backends.DynamicBackend'
)
...
DYNA_PERMS = {
'active_payment_method': [
'credit_card.perms.have_valid_card',
'debit_card.perms.have_valid_card',
]
}
```
And elsewhere in your code, you can simply call:
```
if request.user.has_perm('active_payment_method'):
# Do something for authorized users.
else:
# Do something for authenticated users.
```