Skip to main content

drf-permission-rules

permission rules for DRF base on drf access policy

Installation

pip install drf-permission-rules

Usage

ViewSet permissions

class UserViewSet(ModelViewSet, PermissionsActionMixin):
    ...

    @action(methods=["GET", "POST"], detail=False)
    def some_action(self, request, *args, **kwargs):
        ...


GET /api/users/permissions
Response:
{
    "create": true,
    "list": true,
    "some_action": false
}

Multiple ViewSet permissions

# views.py
class UserViewSet(ModelViewSet, PermissionsActionMixin):
    ...

class BookViewSet(ModelViewSet, PermissionsActionMixin):
    ...

class AuthorViewSet(ModelViewSet, PermissionsActionMixin):
    ...


# urls.py
urlpatterns = [
    ...
    path("api/", include("permission_rules.urls")),
]


GET /api/users/permissions
Response:
{
    "User": {
        "create": true
        "list": true,
        "some_action": false
    }
    "Book": {
        "create": true,
        "list": true
    },
    "Author": {
        "create": false,
        "list": true
    }
}

Speedup

You can get permissions from a file instead of a database.

# settings.py


PERMISSION_RULES_SETTINGS = {
    "use_file_instead_db": true,
    "permission_rules_file_path": "/path/to/permissions.json"
}

Download files

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

Source Distribution

drf_permission_rules-0.5.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

drf_permission_rules-0.5.0-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file drf_permission_rules-0.5.0.tar.gz.

File metadata

  • Download URL: drf_permission_rules-0.5.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.10.2 Linux/6.17.0-1018-azure

File hashes

Hashes for drf_permission_rules-0.5.0.tar.gz
Algorithm Hash digest
SHA256 efd21f2b08169bc7af7a4875d68b9f8b44002cfcab8a570482e61f5756df64d2
MD5 4355f72571037105fb0b1684f04d3d9d
BLAKE2b-256 5101795ff388cb159ac63d8cdc430b2ad0c45661f69b9ca2f1ccc947fddcf5d9

See more details on using hashes here.

File details

Details for the file drf_permission_rules-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: drf_permission_rules-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.10.2 Linux/6.17.0-1018-azure

File hashes

Hashes for drf_permission_rules-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9d30e899c970cf61551f9e8b41ef6355b5c47abcaa94ea17966dde6648dd4b01
MD5 16e523ca06511bda7125b740cbbff7d0
BLAKE2b-256 e5d4b0917e2052205dbcfc3e9428d84288d6de71a3bc904325d7de34b1dbdbdd

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 files

0.4.6

2 files

0.4.5

2 files

0.4.4

2 files

0.4.3

2 files

0.4.2

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page