Skip to main content

A custom Django permissions package.

Project description

ACLVL Permissions

ACLVL Permissions is a Django package that provides an easy-to-use system for managing roles and access levels within your Django applications. It simplifies role-based access control (RBAC) by linking roles to access levels and associating them with views.


Features

  • Define roles and access levels for flexible and scalable RBAC.
  • Automatically create or retrieve AccessLevel objects from views with declared permissions.
  • Management commands to list views and synchronize access levels.
  • Django admin integration for managing roles and access levels.

Installation

  1. Install the package using pip:
pip install aclvl_permissions
  1. Add the app to your INSTALLED_APPS in settings.py:
INSTALLED_APPS = [
    # Other apps
    'aclvl_permissions',
]
  1. Run migrations to set up the database models:
python manage.py makemigrations aclvl_permissions
python manage.py migrate

Models

Role

The 'Role' model defines user roles within the system. Each role can be associated with multiple 'AccessLevel' objects.

ACLVL Permissions Models

The ACLVL Permissions package provides two primary models: Role and AccessLevel. These models form the backbone of the role-based access control (RBAC) system by defining roles and permissions within your application.


Models Overview

1. Role

The Role model represents a user role within the system. Roles are linked to AccessLevel objects to define what permissions a role has.

Fields

Field Type Description
name CharField Name of the role (e.g., "Admin", "Editor").
role_key CharField Unique identifier key for the role.
access_level ManyToManyField Relationship to the AccessLevel model.

2. AccessLevel

The 'AccessLevel' model represents an individual permission within the system. Access levels are linked to roles to grant specific permissions.

Fields

Field Type Description
name CharField Name of the role (e.g., "Admin", "Editor").
access_key CharField Unique identifier key for the access level.

Commands Overview

1. list_views

The list_views command lists all declared views in your Django project, displays their view_key and required_access_levels, and ensures that all AccessLevel objects for the specified required_access_levels are created in the database.

Features:

  • Lists all views with a view_key and required_access_levels.
  • Automatically creates or retrieves AccessLevel objects based on declared permissions.

Command Usage:

python manage.py aclvl_set_view_keys

Usage

In your Django project, you can use the custom permission as follows:

from aclvl_permissions.permissions import AccessLevelPermission

class MyView(APIView):
    permission_classes = [AccessLevelPermission]
    required_access_levels = ['view_all_model', 'view_owner_model', 'create_all_model']
    view_key = 'model'

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

aclvl_permissions-0.3.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

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

aclvl_permissions-0.3.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file aclvl_permissions-0.3.0.tar.gz.

File metadata

  • Download URL: aclvl_permissions-0.3.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.8.10

File hashes

Hashes for aclvl_permissions-0.3.0.tar.gz
Algorithm Hash digest
SHA256 ccb7f338427b7d045cad003d6b06bf14b9327c2cd692daa746a6c655837b8b22
MD5 8dc50104adc9c62bf5b37e70a56c90a1
BLAKE2b-256 b178d0340afe93ce429183f076477e82deaaf9e0c446a49206a47e62c8b0ff30

See more details on using hashes here.

File details

Details for the file aclvl_permissions-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for aclvl_permissions-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e63230ac24c70454ec89389c8587e325a46cb415a678b023f5a058f4b4e2c797
MD5 04c1b33c8a5eae0aa8c302b3d109b696
BLAKE2b-256 67a29a963a970c52fb9b672d83ecdf88ba72cc0588aac7b0db5d38efe7a08eb1

See more details on using hashes here.

Supported by

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