Skip to main content

Utilities for defining fine-grained permissions in the Django Rest Framework based API views

Project description

DRF fancy permissions

example workflow Coverage Status

About

This package provides utilities for defining fine-grained permissions in the Django Rest Framework based API views.

Install

pip install drf-fancy-permissions

Usage

Use the fancy_permissions.model_action_permission_factory, fancy_permissions.object_action_permission_factory and fancy_permissions.parent_object_action_permission_factory functions in order to define authorization rules.

from rest_framework.mixins import (
    CreateModelMixin,
    ListModelMixin,
    RetrieveModelMixin,
    UpdateModelMixin,
)
from rest_framework.viewsets import ViewSet

from fancy_permissions import (
    model_action_permission_factory,
    object_action_permission_factory,
    parent_object_action_permission_factory,
)


class SomeViewSet(
    CreateModelMixin,
    RetrieveModelMixin,
    UpdateModelMixin,
    ListModelMixin,
    ViewSet,
):
    serializer_class = SomeModelSerializer
    permission_classes = [
        model_action_permission_factory(
            create=['some_app.add_somemodel'],
            retrieve=None,  # open for all users
            partial_update=['some_app.change_somemodel'],
            list=None,  # open for all users,
        ),
        object_action_permission_factory(
            create=None,
            retrieve=None,
            partial_update=[lambda obj, user: obj.status == 'SOME_STATUS' and not obj.has_something_meaningful()],
            list=None,
            close=None,
        ),
        parent_object_action_permission_factory(
            create=[lambda obj, user: obj.can_create_children()],
            retrieve=None,
            partial_update=[lambda obj, user: obj.can_update_children()],
            list=None,
            close=None,
        ),
    ]
    queryset = SomeModel.objects.all()

License

The Django Wicked Historian package is licensed under the FreeBSD License.

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

drf-fancy-permissions-1.0.0.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

drf_fancy_permissions-1.0.0-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file drf-fancy-permissions-1.0.0.tar.gz.

File metadata

  • Download URL: drf-fancy-permissions-1.0.0.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for drf-fancy-permissions-1.0.0.tar.gz
Algorithm Hash digest
SHA256 15fd5f05544c791575cf3ca7a360e64e3c4726c4184969d47224ca4fda944685
MD5 a12a030aad42ce1e7946cecf8278b132
BLAKE2b-256 b7da181bb413485dd64fd44650fe853503234c435acc9bad290b2ee5c2f6318c

See more details on using hashes here.

File details

Details for the file drf_fancy_permissions-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: drf_fancy_permissions-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for drf_fancy_permissions-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c64fe27eecec5056b7e958f194643db14e61f794a8a4ff322a9bc154c7303526
MD5 ba166b6a233191046547f7a9f74953a5
BLAKE2b-256 f6f2449a0070dbd110dbfa9dcb6d461c0510eb25aa1c4f999d582660bc774602

See more details on using hashes here.

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