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.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 Distributions
Built Distribution
Hashes for django_view_permissions-0.0.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56df97dfb57db0b8ccb07670323c407b68fc2f7ef595d4e29e4f2e19c67c6c87 |
|
MD5 | 07a5b75f63b199409ed8e203356d023d |
|
BLAKE2b-256 | 82fff741ac5cae4da868743b8232a7c5f5e35abc1343732f543e64350832ea93 |