Skip to main content

Utility to handle django view access

Project description

PyPI Travis Documentation Status Codecov Supported Python versions License

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-view-permissions-0.0.2.tar.gz (5.9 kB view hashes)

Uploaded Source

Built Distribution

django_view_permissions-0.0.2-py2.py3-none-any.whl (11.6 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page