Utility to handle django view access
Project description
django-view-permissions provides ways to control access for Django app views
Overview
Checks the incoming requests, to grant or deny access for views accoding to the permissions defined in the views. If permissions attribute is not defined in the view, normal django flow is followed. If permissions attribute is defined in view it checks and grants or denys access of the view.
Installation
Install the latest release using pypi:
pip3 install django-view-permissions
Add the application to the INSTALLED_APPS:
INSTALLED_APPS = (
...
# DjangoViewPermissions
'django_view_permissions',
)
Add the middleware to the configuration:
MIDDLEWARE_CLASSES = (
...
'django_view_permissions.middleware.DjangoViewPermissionsMiddleware',
)
Usage
Currently, 3 ways to define permissions are supported.
Attribute based permissions
Method based permissions
Class based permissions
Below is a Attribute based permission example. Where view will be only accessable to users whose attribute ‘is_staff’ is ‘True’.
class DummyView(View):
permissions = [
('attr', 'is_staff', True),
]
In Method based permissions, you will need to defind the method with a ‘request=None’ argument and a boolean return statement. All the requests for which method returns ‘True’ will be able to access the view.
class DummyView(View):
permissions = [
('method', permission_method),
]
In Class based permissions, you will need to defind a class with a ‘request=None’ argument in __init__ method. All the requests for which __call__ method returns ‘True’ will be able to access the view.
class DummyView(View):
permissions = [
('class', PermissionClass),
]
Note: It is recommended to define the permission methods or classes in a separate file.
Please check permissions.py for examples.
License
The code in this repository is licensed under the Apache Software License 2.0 unless otherwise noted.
Please see LICENSE for details.
How To Contribute
Contributions are very welcome.
Please read How To Contribute for details.
Reporting Security Issues
Please do not report security issues in public. Please email muhammadayubkhan6@gmail.com.
Getting Help
Feel free to create git issues in case of queries/issues/enhancements.
Change Log
Unreleased
Added
_
[0.0.2] - 19-03-2020
Added
Fix some documention and release issues.
[0.0.1] - 19-03-2020
Added
Automatic upload to PyPI on tags.
Documentation
[0.0.dev0] - 17-03-2020
Added
Attr based permissions
Method based permissions
Class based permissions
First release on PyPI.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django-view-permissions-0.0.2.tar.gz.
File metadata
- Download URL: django-view-permissions-0.0.2.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.5.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fcb6587b3df1141a1d38119230438bdc88a7dc88b3b611a89b624a7d9cbda021
|
|
| MD5 |
7b7207c4ef460b8bee7fe6356b697bce
|
|
| BLAKE2b-256 |
719c8bb7018f55cb0d771fcadfa6d6985ac42553a5ed522d060c8c44243c4e19
|
File details
Details for the file django_view_permissions-0.0.2-py2.py3-none-any.whl.
File metadata
- Download URL: django_view_permissions-0.0.2-py2.py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.5.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10e2842921de2ff6d30928ad3129d10e17da65a33f677360f15c56dc33d0b3ef
|
|
| MD5 |
a42ba6eb24ad3f3888dda2bfbbeb3b07
|
|
| BLAKE2b-256 |
1e91f8bc6425e225fdd25e6dcfc9bf12c39dee1b78f2ca7a39744f31caf840de
|