Skip to main content

RBAC primitives — roles, permissions, @require_permission decorator, admin UI for simple_module

Project description

simple_module_permissions

Role-based access control (RBAC) for simple_module apps. Users get roles, roles carry permissions, and route handlers declare required permissions at the decorator or dependency layer.

Pre-wired into any app scaffolded with smpy new.

Install

pip install simple_module_permissions

What it provides

  • Role and Permission SQLModel tables, seeded from module-registered defaults.
  • RequiresPermission("...") FastAPI dependency that honours both role-based and direct user-level grants (the framework also exposes require_permission(...) from auth.deps).
  • Admin UI for assigning roles/permissions to users, reached through the users admin area at /users/admin; role and user editors live at /permissions/roles/{id}/edit and /permissions/users/{id}/edit.
  • register_permissions(self, registry) hook — every module declares its permission strings at boot via registry.add_group(...); the registry dedupes and persists them.

Usage

Declare permissions at module boot:

# modules/orders/orders/module.py
from simple_module_core.permissions import PermissionRegistry


class OrdersModule(ModuleBase):
    meta = ModuleMeta(name="orders")

    def register_permissions(self, registry: PermissionRegistry) -> None:
        registry.add_group("Orders", ["orders.read", "orders.write"])

Guard a route:

from fastapi import APIRouter, Depends
from permissions.deps import RequiresPermission   # type: ignore[import-not-found]

router = APIRouter()


@router.get("/orders", dependencies=[Depends(RequiresPermission("orders.read"))])
async def list_orders(): ...

Admin flow: navigate to /users/admin, create a role, assign permissions, assign the role to users.

Depends on

  • simple_module_core, simple_module_db, simple_module_hosting, simple_module_users

License

MIT — see 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

simple_module_permissions-0.0.19.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

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

simple_module_permissions-0.0.19-py3-none-any.whl (20.4 kB view details)

Uploaded Python 3

File details

Details for the file simple_module_permissions-0.0.19.tar.gz.

File metadata

File hashes

Hashes for simple_module_permissions-0.0.19.tar.gz
Algorithm Hash digest
SHA256 d7bbd08a0ef84feaf8c12c0b6975222684d8a0a3237304c0caa8ab62aec42984
MD5 366e439435084a376aa5e7fd849f6d20
BLAKE2b-256 fc00778346859598dad9cc4aa25a2220ec4995f131b7d8c2e06c5e5e99edaf01

See more details on using hashes here.

Provenance

The following attestation bundles were made for simple_module_permissions-0.0.19.tar.gz:

Publisher: release.yml on antosubash/simple_module_python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file simple_module_permissions-0.0.19-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_module_permissions-0.0.19-py3-none-any.whl
Algorithm Hash digest
SHA256 d92db18114d2ffe6d690b1aae5b569d97922f553068770bda943daa3a08e0621
MD5 1a742d71f8d1993ee5ce5d3b597c820b
BLAKE2b-256 9dd3f430db3df0d6ec302ea861bab983c616f4f8f1ea9cbc7325858aab444e20

See more details on using hashes here.

Provenance

The following attestation bundles were made for simple_module_permissions-0.0.19-py3-none-any.whl:

Publisher: release.yml on antosubash/simple_module_python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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