RBAC with teams and DRF integration
Project description
Djvurn Rbac
RBAC with teams and DRF integration
Part of the djvurn package ecosystem.
Features
- 🎯 DRF-first - Complete REST API with ViewSets and serializers
- 🔐 JWT authentication - Works seamlessly with
djangorestframework-simplejwt - 📘 TypeScript support - Full type definitions (separate npm package)
- 🎨 Vue components - Ready-to-use UI components (separate npm package)
- 🧪 Well-tested - 90%+ test coverage
- 📚 Documented - Comprehensive guides and API reference
What This Wraps
This package wraps django-guardian with:
- DRF serializers, ViewSets, and permissions
- JWT authentication integration
- OpenAPI/Swagger schema generation
- Team/organization support
- Real-time updates (WebSocket)
If you're using the vanilla django-guardian, see the Migration Guide.
Installation
pip install djvurn-rbac
Or with Poetry:
poetry add djvurn-rbac
Quick Start
1. Add to INSTALLED_APPS
# settings.py
INSTALLED_APPS = [
# Django apps
'django.contrib.auth',
'django.contrib.contenttypes',
# ...
# Third-party apps
'rest_framework',
'rest_framework_simplejwt',
'django_guardian', # Base package
# djvurn packages
'djvurn_rbac', # This package
]
2. Configure REST Framework
# settings.py
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework_simplejwt.authentication.JWTAuthentication',
],
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.IsAuthenticated',
],
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.CursorPagination',
'PAGE_SIZE': 20,
}
3. Add URLs
# urls.py
from django.urls import path, include
from djvurn_rbac.api import router
urlpatterns = [
path('api/', include(router.urls)),
# ... other URLs
]
4. Run Migrations
python manage.py migrate
5. Start Using the API
# In your code
from djvurn_rbac import [TODO: Add usage example]
# Or via the API
# GET /api/[resource]/
# POST /api/[resource]/
API Documentation
Endpoints
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/[resource]/ |
List resources |
| POST | /api/[resource]/ |
Create resource |
| GET | /api/[resource]/{id}/ |
Retrieve resource |
| PUT | /api/[resource]/{id}/ |
Update resource |
| PATCH | /api/[resource]/{id}/ |
Partial update |
| DELETE | /api/[resource]/{id}/ |
Delete resource |
Example Requests
List Resources
curl -H "Authorization: Bearer YOUR_JWT_TOKEN" \
http://localhost:8000/api/[resource]/
Create Resource
curl -X POST \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{"field": "value"}' \
http://localhost:8000/api/[resource]/
For full API documentation, see API Reference.
Frontend Integration
TypeScript/JavaScript
Install the TypeScript package:
npm install @djvurn/rbac
Usage:
import { useResource } from '@djvurn/rbac'
const client = useResource({
baseURL: 'http://localhost:8000/api',
token: 'YOUR_JWT_TOKEN'
})
const items = await client.list()
Vue 3
<script setup lang="ts">
import { useResource } from '@djvurn/rbac'
const { items, loading, error, refresh } = useResource()
</script>
<template>
<div v-if="loading">Loading...</div>
<div v-else-if="error">Error: {{ error }}</div>
<div v-else>
<div v-for="item in items" :key="item.id">
{{ item.name }}
</div>
</div>
</template>
Configuration
Settings
# settings.py
# Djvurn Rbac settings
DJVURN_RBAC = {
# Add any package-specific settings here
}
Migration from Vanilla Package
If you're currently using django-guardian:
- Install this package alongside the base package
- Add to INSTALLED_APPS (keep both packages)
- Run migrations - No data migration needed
- Update your views to use DRF ViewSets
- Update your frontend to use the REST API
See Migration Guide for detailed steps.
Development
Setup
# Clone the mono-repo
git clone https://github.com/hmesfin/djvurn-packages.git
cd djvurn-packages/packages/djvurn-rbac
# Install dependencies
poetry install
# Run tests
poetry run pytest
# Run with coverage
poetry run pytest --cov
Running Tests
# All tests
poetry run pytest
# Specific test file
poetry run pytest tests/test_models.py
# With coverage report
poetry run pytest --cov --cov-report=html
open htmlcov/index.html
Code Quality
# Format code
poetry run black src/ tests/
poetry run ruff check --fix src/ tests/
# Type checking
poetry run mypy src/
Contributing
Contributions are welcome! See CONTRIBUTING.md for guidelines.
License
MIT License - see LICENSE file for details.
Credits
- Built on top of
django-guardian - Part of the djvurn package ecosystem
- Created by Gojjo Tech
Support
- Documentation: Read the docs
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file djvurn_rbac-0.1.0.tar.gz.
File metadata
- Download URL: djvurn_rbac-0.1.0.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.12.3 Linux/6.6.87.2-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7307cc485fbb82dcaf8e472d1455c6ba2ce77cef2565da609c6e6e06fe2f5378
|
|
| MD5 |
d467b9a27f04feecc7b087da6d78102d
|
|
| BLAKE2b-256 |
5b6395137e9c0b4d52555cd878b1ae5ded81d103977bfd86a32fe5866e7b802e
|
File details
Details for the file djvurn_rbac-0.1.0-py3-none-any.whl.
File metadata
- Download URL: djvurn_rbac-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.12.3 Linux/6.6.87.2-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c6da3e7357cc88e872b1a5db8b4a5327dc52bf886bf1f9e5f04c83d27712df1
|
|
| MD5 |
2160a1a749feb7c9fdc2b8b012957cff
|
|
| BLAKE2b-256 |
f219182608bfa8ce81035ea0fa95f8b7a771e2310648930558145c66429f56b8
|