django-clearance 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- django_clearance-0.1.0/.gitignore +28 -0
- django_clearance-0.1.0/CHANGELOG.fa.md +37 -0
- django_clearance-0.1.0/CHANGELOG.md +38 -0
- django_clearance-0.1.0/LICENSE +28 -0
- django_clearance-0.1.0/PKG-INFO +139 -0
- django_clearance-0.1.0/README.fa.md +105 -0
- django_clearance-0.1.0/README.md +104 -0
- django_clearance-0.1.0/docs/design.fa.md +1245 -0
- django_clearance-0.1.0/docs/design.md +1247 -0
- django_clearance-0.1.0/docs/guide.fa.md +516 -0
- django_clearance-0.1.0/docs/guide.md +514 -0
- django_clearance-0.1.0/example/README.fa.md +89 -0
- django_clearance-0.1.0/example/README.md +87 -0
- django_clearance-0.1.0/example/config/__init__.py +0 -0
- django_clearance-0.1.0/example/config/access.py +44 -0
- django_clearance-0.1.0/example/config/settings.py +88 -0
- django_clearance-0.1.0/example/config/urls.py +9 -0
- django_clearance-0.1.0/example/manage.py +11 -0
- django_clearance-0.1.0/example/shop/__init__.py +0 -0
- django_clearance-0.1.0/example/shop/admin.py +24 -0
- django_clearance-0.1.0/example/shop/api.py +32 -0
- django_clearance-0.1.0/example/shop/apps.py +9 -0
- django_clearance-0.1.0/example/shop/management/__init__.py +0 -0
- django_clearance-0.1.0/example/shop/management/commands/__init__.py +0 -0
- django_clearance-0.1.0/example/shop/management/commands/example_data.py +75 -0
- django_clearance-0.1.0/example/shop/migrations/0001_initial.py +224 -0
- django_clearance-0.1.0/example/shop/migrations/__init__.py +0 -0
- django_clearance-0.1.0/example/shop/models.py +77 -0
- django_clearance-0.1.0/example/shop/policies.py +23 -0
- django_clearance-0.1.0/example/shop/querysets.py +23 -0
- django_clearance-0.1.0/example/shop/templates/shop/base.html +8 -0
- django_clearance-0.1.0/example/shop/templates/shop/order_form.html +9 -0
- django_clearance-0.1.0/example/shop/templates/shop/orders.html +14 -0
- django_clearance-0.1.0/example/shop/tests.py +136 -0
- django_clearance-0.1.0/example/shop/urls.py +25 -0
- django_clearance-0.1.0/example/shop/views.py +25 -0
- django_clearance-0.1.0/pyproject.toml +138 -0
- django_clearance-0.1.0/src/clearance/__init__.py +0 -0
- django_clearance-0.1.0/src/clearance/actions.py +237 -0
- django_clearance-0.1.0/src/clearance/admin/__init__.py +0 -0
- django_clearance-0.1.0/src/clearance/admin/actions.py +188 -0
- django_clearance-0.1.0/src/clearance/admin/apps.py +22 -0
- django_clearance-0.1.0/src/clearance/admin/checks.py +41 -0
- django_clearance-0.1.0/src/clearance/admin/discovery.py +39 -0
- django_clearance-0.1.0/src/clearance/admin/options.py +327 -0
- django_clearance-0.1.0/src/clearance/admin/protection.py +91 -0
- django_clearance-0.1.0/src/clearance/admin/scopes.py +272 -0
- django_clearance-0.1.0/src/clearance/admin/sites.py +73 -0
- django_clearance-0.1.0/src/clearance/admin/standing.py +261 -0
- django_clearance-0.1.0/src/clearance/admin/views.py +384 -0
- django_clearance-0.1.0/src/clearance/apps.py +50 -0
- django_clearance-0.1.0/src/clearance/backends.py +51 -0
- django_clearance-0.1.0/src/clearance/checks.py +286 -0
- django_clearance-0.1.0/src/clearance/conf.py +74 -0
- django_clearance-0.1.0/src/clearance/declared.py +520 -0
- django_clearance-0.1.0/src/clearance/decorators.py +59 -0
- django_clearance-0.1.0/src/clearance/discovery.py +189 -0
- django_clearance-0.1.0/src/clearance/drf/__init__.py +0 -0
- django_clearance-0.1.0/src/clearance/drf/checks.py +93 -0
- django_clearance-0.1.0/src/clearance/drf/discovery.py +58 -0
- django_clearance-0.1.0/src/clearance/drf/permissions.py +167 -0
- django_clearance-0.1.0/src/clearance/drf/serializers.py +121 -0
- django_clearance-0.1.0/src/clearance/drf/viewsets.py +50 -0
- django_clearance-0.1.0/src/clearance/fields.py +191 -0
- django_clearance-0.1.0/src/clearance/forms.py +97 -0
- django_clearance-0.1.0/src/clearance/grants.py +139 -0
- django_clearance-0.1.0/src/clearance/health.py +242 -0
- django_clearance-0.1.0/src/clearance/labels.py +70 -0
- django_clearance-0.1.0/src/clearance/limits.py +64 -0
- django_clearance-0.1.0/src/clearance/locale/fa/LC_MESSAGES/django.mo +0 -0
- django_clearance-0.1.0/src/clearance/locale/fa/LC_MESSAGES/django.po +601 -0
- django_clearance-0.1.0/src/clearance/management/__init__.py +0 -0
- django_clearance-0.1.0/src/clearance/management/commands/__init__.py +0 -0
- django_clearance-0.1.0/src/clearance/management/commands/clearance_check.py +34 -0
- django_clearance-0.1.0/src/clearance/management/commands/clearance_sync.py +72 -0
- django_clearance-0.1.0/src/clearance/migrations/0001_initial.py +168 -0
- django_clearance-0.1.0/src/clearance/migrations/0002_scoperule.py +66 -0
- django_clearance-0.1.0/src/clearance/migrations/0003_protectedfield.py +49 -0
- django_clearance-0.1.0/src/clearance/migrations/0004_statusaction.py +56 -0
- django_clearance-0.1.0/src/clearance/migrations/0005_declared.py +47 -0
- django_clearance-0.1.0/src/clearance/migrations/0006_rows_not_json.py +224 -0
- django_clearance-0.1.0/src/clearance/migrations/__init__.py +0 -0
- django_clearance-0.1.0/src/clearance/models.py +597 -0
- django_clearance-0.1.0/src/clearance/permissions.py +394 -0
- django_clearance-0.1.0/src/clearance/policies.py +261 -0
- django_clearance-0.1.0/src/clearance/protocols.py +38 -0
- django_clearance-0.1.0/src/clearance/py.typed +0 -0
- django_clearance-0.1.0/src/clearance/querysets.py +281 -0
- django_clearance-0.1.0/src/clearance/registry.py +103 -0
- django_clearance-0.1.0/src/clearance/roles/__init__.py +0 -0
- django_clearance-0.1.0/src/clearance/roles/admin.py +9 -0
- django_clearance-0.1.0/src/clearance/roles/apps.py +35 -0
- django_clearance-0.1.0/src/clearance/roles/checks.py +70 -0
- django_clearance-0.1.0/src/clearance/roles/declared.py +168 -0
- django_clearance-0.1.0/src/clearance/roles/limits.py +36 -0
- django_clearance-0.1.0/src/clearance/roles/locale/fa/LC_MESSAGES/django.mo +0 -0
- django_clearance-0.1.0/src/clearance/roles/locale/fa/LC_MESSAGES/django.po +188 -0
- django_clearance-0.1.0/src/clearance/roles/migrations/0001_initial.py +170 -0
- django_clearance-0.1.0/src/clearance/roles/migrations/__init__.py +0 -0
- django_clearance-0.1.0/src/clearance/roles/models.py +93 -0
- django_clearance-0.1.0/src/clearance/roles/pages.py +211 -0
- django_clearance-0.1.0/src/clearance/roles/resolvers.py +109 -0
- django_clearance-0.1.0/src/clearance/roles/services.py +288 -0
- django_clearance-0.1.0/src/clearance/roles/signals.py +17 -0
- django_clearance-0.1.0/src/clearance/roles/templates/clearance/roles/role.html +60 -0
- django_clearance-0.1.0/src/clearance/roles/templates/clearance/roles/role_add.html +16 -0
- django_clearance-0.1.0/src/clearance/roles/templates/clearance/roles/role_delete.html +11 -0
- django_clearance-0.1.0/src/clearance/roles/templates/clearance/roles/roles.html +24 -0
- django_clearance-0.1.0/src/clearance/rules.py +327 -0
- django_clearance-0.1.0/src/clearance/safety.py +186 -0
- django_clearance-0.1.0/src/clearance/services.py +688 -0
- django_clearance-0.1.0/src/clearance/signals.py +42 -0
- django_clearance-0.1.0/src/clearance/static/clearance/admin.css +17 -0
- django_clearance-0.1.0/src/clearance/static/clearance/rules.js +51 -0
- django_clearance-0.1.0/src/clearance/templates/clearance/admin/action.html +44 -0
- django_clearance-0.1.0/src/clearance/templates/clearance/admin/action_delete.html +11 -0
- django_clearance-0.1.0/src/clearance/templates/clearance/admin/actions.html +41 -0
- django_clearance-0.1.0/src/clearance/templates/clearance/admin/base.html +12 -0
- django_clearance-0.1.0/src/clearance/templates/clearance/admin/bundle.html +48 -0
- django_clearance-0.1.0/src/clearance/templates/clearance/admin/bundle_delete.html +12 -0
- django_clearance-0.1.0/src/clearance/templates/clearance/admin/bundles.html +22 -0
- django_clearance-0.1.0/src/clearance/templates/clearance/admin/cell.html +5 -0
- django_clearance-0.1.0/src/clearance/templates/clearance/admin/fields.html +17 -0
- django_clearance-0.1.0/src/clearance/templates/clearance/admin/fields_of.html +23 -0
- django_clearance-0.1.0/src/clearance/templates/clearance/admin/overview.html +24 -0
- django_clearance-0.1.0/src/clearance/templates/clearance/admin/people.html +25 -0
- django_clearance-0.1.0/src/clearance/templates/clearance/admin/permissions.html +20 -0
- django_clearance-0.1.0/src/clearance/templates/clearance/admin/person.html +73 -0
- django_clearance-0.1.0/src/clearance/templates/clearance/admin/scope.html +52 -0
- django_clearance-0.1.0/src/clearance/templates/clearance/admin/scope_delete.html +15 -0
- django_clearance-0.1.0/src/clearance/templates/clearance/admin/scopes.html +28 -0
- django_clearance-0.1.0/src/clearance/templatetags/__init__.py +0 -0
- django_clearance-0.1.0/src/clearance/templatetags/clearance.py +18 -0
- django_clearance-0.1.0/src/clearance/translations/__init__.py +0 -0
- django_clearance-0.1.0/src/clearance/translations/admin.py +9 -0
- django_clearance-0.1.0/src/clearance/translations/apps.py +33 -0
- django_clearance-0.1.0/src/clearance/translations/checks.py +38 -0
- django_clearance-0.1.0/src/clearance/translations/labels.py +73 -0
- django_clearance-0.1.0/src/clearance/translations/locale/fa/LC_MESSAGES/django.mo +0 -0
- django_clearance-0.1.0/src/clearance/translations/locale/fa/LC_MESSAGES/django.po +54 -0
- django_clearance-0.1.0/src/clearance/translations/migrations/0001_initial.py +55 -0
- django_clearance-0.1.0/src/clearance/translations/migrations/__init__.py +0 -0
- django_clearance-0.1.0/src/clearance/translations/models.py +34 -0
- django_clearance-0.1.0/src/clearance/translations/pages.py +92 -0
- django_clearance-0.1.0/src/clearance/translations/services.py +68 -0
- django_clearance-0.1.0/src/clearance/translations/signals.py +6 -0
- django_clearance-0.1.0/src/clearance/translations/templates/clearance/translations/names.html +23 -0
- django_clearance-0.1.0/src/clearance/views.py +249 -0
- django_clearance-0.1.0/src/clearance/writes.py +53 -0
- django_clearance-0.1.0/tests/__init__.py +0 -0
- django_clearance-0.1.0/tests/conftest.py +88 -0
- django_clearance-0.1.0/tests/project/__init__.py +0 -0
- django_clearance-0.1.0/tests/project/accounts/__init__.py +0 -0
- django_clearance-0.1.0/tests/project/accounts/admin.py +8 -0
- django_clearance-0.1.0/tests/project/accounts/migrations/0001_initial.py +121 -0
- django_clearance-0.1.0/tests/project/accounts/migrations/__init__.py +0 -0
- django_clearance-0.1.0/tests/project/accounts/models.py +16 -0
- django_clearance-0.1.0/tests/project/autofield_settings.py +5 -0
- django_clearance-0.1.0/tests/project/backends.py +21 -0
- django_clearance-0.1.0/tests/project/lending/__init__.py +0 -0
- django_clearance-0.1.0/tests/project/lending/admin.py +40 -0
- django_clearance-0.1.0/tests/project/lending/api.py +66 -0
- django_clearance-0.1.0/tests/project/lending/migrations/0001_initial.py +137 -0
- django_clearance-0.1.0/tests/project/lending/migrations/__init__.py +0 -0
- django_clearance-0.1.0/tests/project/lending/models.py +85 -0
- django_clearance-0.1.0/tests/project/lending/policies.py +24 -0
- django_clearance-0.1.0/tests/project/lending/querysets.py +28 -0
- django_clearance-0.1.0/tests/project/lending/templates/lending/loan_detail.html +1 -0
- django_clearance-0.1.0/tests/project/lending/templates/lending/loan_form.html +1 -0
- django_clearance-0.1.0/tests/project/lending/templates/lending/loan_list.html +2 -0
- django_clearance-0.1.0/tests/project/lending/templates/lending/payment_list.html +2 -0
- django_clearance-0.1.0/tests/project/lending/templates/lending/statement_detail.html +1 -0
- django_clearance-0.1.0/tests/project/lending/urls.py +16 -0
- django_clearance-0.1.0/tests/project/lending/views.py +68 -0
- django_clearance-0.1.0/tests/project/settings.py +89 -0
- django_clearance-0.1.0/tests/project/sync_settings.py +17 -0
- django_clearance-0.1.0/tests/project/urls.py +18 -0
- django_clearance-0.1.0/tests/test_a_bundle_gives_and_a_revocation_takes_away.py +117 -0
- django_clearance-0.1.0/tests/test_a_django_view_asks_the_policy.py +227 -0
- django_clearance-0.1.0/tests/test_a_field_is_protected_under_the_safety_rules.py +270 -0
- django_clearance-0.1.0/tests/test_a_model_declares_its_permissions.py +133 -0
- django_clearance-0.1.0/tests/test_a_name_reads_in_the_readers_language.py +299 -0
- django_clearance-0.1.0/tests/test_a_person_reaches_only_their_rows.py +269 -0
- django_clearance-0.1.0/tests/test_a_policy_decides_by_permission_and_object.py +237 -0
- django_clearance-0.1.0/tests/test_a_protected_field_is_left_out_for_whoever_lacks_it.py +305 -0
- django_clearance-0.1.0/tests/test_a_role_limits_and_starts_what_a_person_holds.py +302 -0
- django_clearance-0.1.0/tests/test_a_status_action_alone_writes_its_values.py +474 -0
- django_clearance-0.1.0/tests/test_access_changes_obey_the_safety_rules.py +410 -0
- django_clearance-0.1.0/tests/test_access_written_as_code_is_applied_by_sync.py +558 -0
- django_clearance-0.1.0/tests/test_an_action_found_in_the_code_gets_its_permission.py +213 -0
- django_clearance-0.1.0/tests/test_an_administrator_builds_a_scope_from_rules.py +511 -0
- django_clearance-0.1.0/tests/test_an_api_asks_the_policy_and_guards_what_is_written.py +503 -0
- django_clearance-0.1.0/tests/test_clearance_check_says_what_the_database_holds_wrong.py +125 -0
- django_clearance-0.1.0/tests/test_conditions_and_values_are_rows_of_their_own.py +215 -0
- django_clearance-0.1.0/tests/test_each_action_needs_its_models_permission.py +96 -0
- django_clearance-0.1.0/tests/test_each_resource_has_one_policy.py +91 -0
- django_clearance-0.1.0/tests/test_managing_access_has_permissions_of_its_own.py +44 -0
- django_clearance-0.1.0/tests/test_misconfiguration_fails_at_start_up.py +221 -0
- django_clearance-0.1.0/tests/test_roles_change_only_under_the_safety_rules.py +516 -0
- django_clearance-0.1.0/tests/test_the_access_pages_change_access_under_the_safety_rules.py +444 -0
- django_clearance-0.1.0/tests/test_the_admin_site_asks_the_library.py +344 -0
- django_clearance-0.1.0/tests/test_the_admin_site_builds_scopes_fields_and_actions.py +440 -0
- django_clearance-0.1.0/tests/test_the_example_project_works.py +34 -0
- django_clearance-0.1.0/tests/test_the_library_installs_into_a_project.py +69 -0
- django_clearance-0.1.0/tests/test_the_library_speaks_persian.py +147 -0
- django_clearance-0.1.0/tests/test_the_pages_work_in_a_browser.py +141 -0
- django_clearance-0.1.0/tests/test_the_source_is_written_in_english.py +25 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
|
|
5
|
+
# Packaging
|
|
6
|
+
build/
|
|
7
|
+
dist/
|
|
8
|
+
*.egg-info/
|
|
9
|
+
|
|
10
|
+
# Environments
|
|
11
|
+
.venv/
|
|
12
|
+
.nox/
|
|
13
|
+
|
|
14
|
+
# Tool caches and reports
|
|
15
|
+
.pytest_cache/
|
|
16
|
+
.mypy_cache/
|
|
17
|
+
.ruff_cache/
|
|
18
|
+
.coverage
|
|
19
|
+
.coverage.*
|
|
20
|
+
coverage.xml
|
|
21
|
+
htmlcov/
|
|
22
|
+
|
|
23
|
+
# Editors
|
|
24
|
+
.idea/
|
|
25
|
+
.vscode/
|
|
26
|
+
|
|
27
|
+
# The example project's database
|
|
28
|
+
example/db.sqlite3
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# تغییرات
|
|
2
|
+
|
|
3
|
+
[English](CHANGELOG.md)
|
|
4
|
+
|
|
5
|
+
## 0.1.0 - نخستین انتشار
|
|
6
|
+
|
|
7
|
+
Alpha: همهی بخشها ساخته و تست شدهاند، ولی هنوز در پروژهای با مدلهای واقعی به
|
|
8
|
+
کار نرفتهاند، پس API ممکن است پیش از 1.0 عوض شود.
|
|
9
|
+
|
|
10
|
+
* **بستهها** - همان گروههای Django، که هر مجوز در آنها با یک **دامنهی ردیف**
|
|
11
|
+
داده میشود؛ گرفتن یک مجوز از یک شخص، با دلیلش.
|
|
12
|
+
* **دامنههای ردیف** - در کد روی یک `ScopedQuerySet`، یا ساختهشده از قانونها در
|
|
13
|
+
پنل ادمین؛ `visible_to(user, action)` آنها را با تعداد ثابتی کوئری میخواند.
|
|
14
|
+
* **فیلدهای محافظتشده** - با یک مجوز خوانده و با مجوزی دیگر نوشته میشوند، در کد
|
|
15
|
+
یا در پنل ادمین، و از هر serializer، فرم، قالب، صفحهی ادمین و قانونی کنار
|
|
16
|
+
گذاشته میشوند.
|
|
17
|
+
* **اکشنها** - اکشنهای وضعیت که فقط خودشان مقدارهایشان را مینویسند؛ اکشنهایی که
|
|
18
|
+
در viewها، viewsetها و اکشنهای ادمین پیدا میشوند، با مجوزهایی که `migrate`
|
|
19
|
+
میسازد.
|
|
20
|
+
* **Policyها** - `BasePolicy` برای قانونهایی که هیچ مجوزی نمیتواند بگوید، و
|
|
21
|
+
`ModelPolicy` برای هر مدل دیگر.
|
|
22
|
+
* **viewهای Django و DRF** - `PolicyRequiredMixin`، `ScopedQuerySetMixin`،
|
|
23
|
+
`ProtectedFieldsViewMixin`، `policy_required`؛ `ModelPolicyPermission`،
|
|
24
|
+
`PolicyPermission`، `ScopedModelViewSet`، و رد کردن نوشتن، فیلد به فیلد.
|
|
25
|
+
* **پنل ادمین** - هر `ModelAdmin` از policyها میپرسد، و صفحههای دسترسی: نمای کلی،
|
|
26
|
+
بستهها به شکل جدول، افراد، مجوزها، سازندهی قانون، فیلدهای محافظتشده، اکشنها؛ به
|
|
27
|
+
فارسی راست به چپ.
|
|
28
|
+
* **قانونهای ایمنی** - هیچ کس به خودش بیشتر نمیدهد، چیزی را که ندارد نمیدهد، و
|
|
29
|
+
کاری نمیکند که هیچ کس نتواند دسترسی را مدیریت کند.
|
|
30
|
+
* **دسترسی به صورت کد** - فایل `ACCESS` و `clearance_sync`، با `--dry-run`،
|
|
31
|
+
`--check` و `SYNC_ON_MIGRATE`.
|
|
32
|
+
* **`clearance.roles`** - نقشها با بستههای آغازین و یک سقف.
|
|
33
|
+
* **`clearance.translations`** - اسم مجوزها، بستهها و نقشها در همهی زبانها.
|
|
34
|
+
* **بررسی** - system checkها موقع بالا آمدن پروژه، و `clearance_check` برای
|
|
35
|
+
چیزهایی که فقط پایگاه داده میتواند بگوید.
|
|
36
|
+
* **انگلیسی و فارسی** در همه جا؛ Python 3.11 تا 3.14، Django 5.2، 6.0 و 6.1، DRF
|
|
37
|
+
3.16 و بالاتر.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
[فارسی](CHANGELOG.fa.md)
|
|
4
|
+
|
|
5
|
+
## 0.1.0 - the first release
|
|
6
|
+
|
|
7
|
+
Alpha: every part is built and tested, but not yet used in a project with
|
|
8
|
+
real models, so the API may still change before 1.0.
|
|
9
|
+
|
|
10
|
+
* **Bundles** - Django's groups, each permission given with a **row scope**;
|
|
11
|
+
revocations, one permission taken from one person with the reason why.
|
|
12
|
+
* **Row scopes** - declared in code on a `ScopedQuerySet`, or built from
|
|
13
|
+
rules in the admin site; `visible_to(user, action)` reads them in a fixed
|
|
14
|
+
number of queries.
|
|
15
|
+
* **Protected fields** - read with one permission and written with another,
|
|
16
|
+
in code or in the admin site, left out of every serializer, form, template,
|
|
17
|
+
admin page and rule.
|
|
18
|
+
* **Actions** - status actions that alone write their values; actions found
|
|
19
|
+
in views, viewsets and admin actions, their permissions made on `migrate`.
|
|
20
|
+
* **Policies** - `BasePolicy` for the rules no permission can say, and
|
|
21
|
+
`ModelPolicy` for every other model.
|
|
22
|
+
* **Django views and DRF** - `PolicyRequiredMixin`, `ScopedQuerySetMixin`,
|
|
23
|
+
`ProtectedFieldsViewMixin`, `policy_required`; `ModelPolicyPermission`,
|
|
24
|
+
`PolicyPermission`, `ScopedModelViewSet`, writes refused field by field.
|
|
25
|
+
* **The admin site** - every `ModelAdmin` asking the policies, and the access
|
|
26
|
+
pages: overview, bundles as a grid, people, permissions, the rule builder,
|
|
27
|
+
protected fields, actions; right to left in Persian.
|
|
28
|
+
* **The safety rules** - nobody gives themselves more, gives what they do not
|
|
29
|
+
hold, or leaves nobody able to manage access.
|
|
30
|
+
* **Access as code** - the `ACCESS` file and `clearance_sync`, with
|
|
31
|
+
`--dry-run`, `--check` and `SYNC_ON_MIGRATE`.
|
|
32
|
+
* **`clearance.roles`** - roles with starting bundles and a ceiling.
|
|
33
|
+
* **`clearance.translations`** - names of permissions, bundles and roles in
|
|
34
|
+
every language.
|
|
35
|
+
* **Checking** - system checks at start-up, and `clearance_check` for what
|
|
36
|
+
only the database can tell.
|
|
37
|
+
* **English and Persian** throughout; Python 3.11 to 3.14, Django 5.2, 6.0
|
|
38
|
+
and 6.1, DRF 3.16 and later.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, amir mohammad kashanchian
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: django-clearance
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Role, policy and row-level access control for Django. Denied by default.
|
|
5
|
+
Project-URL: Repository, https://github.com/amirAI-dot/django-clearance
|
|
6
|
+
Project-URL: Changelog, https://github.com/amirAI-dot/django-clearance/blob/main/CHANGELOG.md
|
|
7
|
+
Project-URL: Guide, https://github.com/amirAI-dot/django-clearance/blob/main/docs/guide.md
|
|
8
|
+
Project-URL: Design, https://github.com/amirAI-dot/django-clearance/blob/main/docs/design.md
|
|
9
|
+
Author: amir mohammad kashanchian
|
|
10
|
+
License-Expression: BSD-3-Clause
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: abac,authorization,django,permissions,rbac,row-level security
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Environment :: Web Environment
|
|
15
|
+
Classifier: Framework :: Django
|
|
16
|
+
Classifier: Framework :: Django :: 5.2
|
|
17
|
+
Classifier: Framework :: Django :: 6.0
|
|
18
|
+
Classifier: Framework :: Django :: 6.1
|
|
19
|
+
Classifier: Intended Audience :: Developers
|
|
20
|
+
Classifier: Operating System :: OS Independent
|
|
21
|
+
Classifier: Programming Language :: Python
|
|
22
|
+
Classifier: Programming Language :: Python :: 3
|
|
23
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
27
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
28
|
+
Classifier: Topic :: Security
|
|
29
|
+
Classifier: Typing :: Typed
|
|
30
|
+
Requires-Python: >=3.11
|
|
31
|
+
Requires-Dist: django>=5.2
|
|
32
|
+
Provides-Extra: drf
|
|
33
|
+
Requires-Dist: djangorestframework>=3.16; extra == 'drf'
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# django-clearance
|
|
37
|
+
|
|
38
|
+
Role, policy and row-level access control for Django. Denied by default.
|
|
39
|
+
|
|
40
|
+
[فارسی](README.fa.md)
|
|
41
|
+
|
|
42
|
+
An administrator decides, in Django's admin site and with no code, who may
|
|
43
|
+
do what - and to which rows, and with which fields:
|
|
44
|
+
|
|
45
|
+
* **bundles** of permissions, each given with a **scope** - "their branch's
|
|
46
|
+
orders", "their own", or a rule built in the admin site;
|
|
47
|
+
* **protected fields**, read with one permission and written with another;
|
|
48
|
+
* **status actions** - only whoever may approve sets an order to *approved*;
|
|
49
|
+
* **roles**, optional, with a ceiling nobody with the role goes past.
|
|
50
|
+
|
|
51
|
+
Every door asks the same rules: Django's views and templates, DRF, the admin
|
|
52
|
+
site, and your own code. A change is refused when it would let somebody give
|
|
53
|
+
themselves more. The pages, messages and permissions come in English and
|
|
54
|
+
Persian, and read right to left in Persian.
|
|
55
|
+
|
|
56
|
+
## In a project
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pip install 'django-clearance[drf]'
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
INSTALLED_APPS = [
|
|
64
|
+
'clearance.admin.apps.ClearanceAdminConfig', # instead of 'django.contrib.admin'
|
|
65
|
+
...
|
|
66
|
+
'clearance',
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
AUTHENTICATION_BACKENDS = ['clearance.backends.ClearanceBackend']
|
|
70
|
+
|
|
71
|
+
REST_FRAMEWORK = {
|
|
72
|
+
'DEFAULT_PERMISSION_CLASSES': ['clearance.drf.permissions.ModelPolicyPermission'],
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
class OrderViewSet(ScopedModelViewSet): # the rows, the policy, the fields - asked
|
|
78
|
+
queryset = Order.objects.all()
|
|
79
|
+
serializer_class = OrderSerializer
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
Order.objects.visible_to(user, 'edit') # the orders this person may edit
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
* [The guide](docs/guide.md) - every part, how to use it.
|
|
86
|
+
* [The example shop](example/README.md) - a project using all of it, to run.
|
|
87
|
+
* [The design](docs/design.md) - why it is built the way it is.
|
|
88
|
+
|
|
89
|
+
Python 3.11 to 3.14; Django 5.2, 6.0 and 6.1; Django REST framework 3.16 and
|
|
90
|
+
later, optional; any database Django supports.
|
|
91
|
+
|
|
92
|
+
## Working on it
|
|
93
|
+
|
|
94
|
+
Every check runs through [nox](https://nox.thea.codes), the same sessions
|
|
95
|
+
locally and in CI. With [uv](https://docs.astral.sh/uv/) installed, a Python
|
|
96
|
+
that is missing is fetched for you.
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
uv tool install nox
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
nox -s lint
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
nox -s types
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
nox -s tests
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
`tests` runs every supported Python and Django; one combination is
|
|
115
|
+
`nox -s "tests(3.13-django6.1)"`, and `nox -l` lists them all. `browser`
|
|
116
|
+
runs the pages in a real browser, `messages` - with gettext installed -
|
|
117
|
+
checks that the catalogues hold every string the library marks, and
|
|
118
|
+
`package` builds the wheel and runs the example project on it.
|
|
119
|
+
|
|
120
|
+
The suite uses SQLite unless told otherwise. To run it on PostgreSQL, as CI
|
|
121
|
+
does, set `CLEARANCE_TEST_DATABASE=postgres`; the connection is read from the
|
|
122
|
+
standard `PGHOST`, `PGPORT`, `PGUSER`, `PGPASSWORD` and `PGDATABASE`
|
|
123
|
+
variables (defaults: `localhost`, `5432`, `postgres`, `postgres`,
|
|
124
|
+
`clearance`).
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
CLEARANCE_TEST_DATABASE=postgres nox -s tests
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
After marking a string, extract it with `nox -s messages`, translate what it
|
|
131
|
+
added in `locale/fa/LC_MESSAGES/django.po`, and compile:
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
cd src/clearance && django-admin compilemessages
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Licence
|
|
138
|
+
|
|
139
|
+
BSD 3-Clause - see [`LICENSE`](LICENSE).
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# django-clearance
|
|
2
|
+
|
|
3
|
+
کنترل دسترسی مبتنی بر نقش، سیاست (policy) و سطح ردیف برای جنگو. پیشفرض: رد.
|
|
4
|
+
|
|
5
|
+
[English](README.md)
|
|
6
|
+
|
|
7
|
+
مدیر سایت، در پنل ادمین Django و بدون هیچ کدی، تصمیم میگیرد چه کسی چه کاری
|
|
8
|
+
میتواند بکند - و روی کدام ردیفها، و با کدام فیلدها:
|
|
9
|
+
|
|
10
|
+
* **بستههای** مجوز، که هر مجوز با یک **دامنه** داده میشود - «سفارشهای شعبهی
|
|
11
|
+
خودشان»، «مال خودشان»، یا قانونی که در پنل ادمین ساخته شده؛
|
|
12
|
+
* **فیلدهای محافظتشده**، که با یک مجوز خوانده و با مجوزی دیگر نوشته میشوند؛
|
|
13
|
+
* **اکشنهای وضعیت** - فقط کسی که اجازهی تأیید دارد یک سفارش را *approved* میکند؛
|
|
14
|
+
* **نقشها**، به صورت اختیاری، با سقفی که هیچ کس با آن نقش از آن بالاتر نمیرود.
|
|
15
|
+
|
|
16
|
+
همهی درها همان قانونها را میپرسند: viewها و قالبهای Django، DRF، پنل ادمین، و
|
|
17
|
+
کد خودتان. هر تغییری که بگذارد کسی به خودش بیشتر بدهد رد میشود. صفحهها، پیامها
|
|
18
|
+
و مجوزها به انگلیسی و فارسی هستند، و به فارسی راست به چپ خوانده میشوند.
|
|
19
|
+
|
|
20
|
+
## در یک پروژه
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install 'django-clearance[drf]'
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
INSTALLED_APPS = [
|
|
28
|
+
'clearance.admin.apps.ClearanceAdminConfig', # instead of 'django.contrib.admin'
|
|
29
|
+
...
|
|
30
|
+
'clearance',
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
AUTHENTICATION_BACKENDS = ['clearance.backends.ClearanceBackend']
|
|
34
|
+
|
|
35
|
+
REST_FRAMEWORK = {
|
|
36
|
+
'DEFAULT_PERMISSION_CLASSES': ['clearance.drf.permissions.ModelPolicyPermission'],
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
class OrderViewSet(ScopedModelViewSet): # the rows, the policy, the fields - asked
|
|
42
|
+
queryset = Order.objects.all()
|
|
43
|
+
serializer_class = OrderSerializer
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
Order.objects.visible_to(user, 'edit') # the orders this person may edit
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
* [راهنما](docs/guide.fa.md) - همهی بخشها، و اینکه چطور به کارشان ببرید.
|
|
50
|
+
* [فروشگاه نمونه](example/README.fa.md) - پروژهای که همهاش را به کار میبرد، برای
|
|
51
|
+
اجرا کردن.
|
|
52
|
+
* [سند طراحی](docs/design.fa.md) - اینکه چرا اینطور ساخته شده.
|
|
53
|
+
|
|
54
|
+
Python 3.11 تا 3.14؛ Django 5.2، 6.0 و 6.1؛ Django REST framework 3.16 و بالاتر،
|
|
55
|
+
به صورت اختیاری؛ هر پایگاه دادهای که Django پشتیبانی میکند.
|
|
56
|
+
|
|
57
|
+
## کار روی پروژه
|
|
58
|
+
|
|
59
|
+
همهی بررسیها با [nox](https://nox.thea.codes) اجرا میشوند؛ همان sessionها
|
|
60
|
+
هم روی سیستم خودتان و هم در CI. اگر [uv](https://docs.astral.sh/uv/) نصب
|
|
61
|
+
باشد، هر نسخهای از پایتون که نصب نیست خودکار دانلود میشود.
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
uv tool install nox
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
nox -s lint
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
nox -s types
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
nox -s tests
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`tests` همهی نسخههای پشتیبانیشدهی پایتون و جنگو را اجرا میکند؛ برای
|
|
80
|
+
اجرای یک ترکیب: `nox -s "tests(3.13-django6.1)"`، و `nox -l` همه را فهرست
|
|
81
|
+
میکند. `browser` صفحهها را در یک مرورگر واقعی اجرا میکند، `messages` - با
|
|
82
|
+
gettext نصبشده - بررسی میکند که کاتالوگها همهی رشتههایی را که کتابخانه علامت
|
|
83
|
+
میزند داشته باشند، و `package` فایل wheel را میسازد و پروژهی نمونه را روی آن
|
|
84
|
+
اجرا میکند.
|
|
85
|
+
|
|
86
|
+
تستها بهطور پیشفرض روی SQLite اجرا میشوند. برای اجرا روی PostgreSQL،
|
|
87
|
+
مثل CI، متغیر `CLEARANCE_TEST_DATABASE=postgres` را تنظیم کنید؛ اطلاعات
|
|
88
|
+
اتصال از متغیرهای استاندارد `PGHOST`، `PGPORT`، `PGUSER`، `PGPASSWORD` و
|
|
89
|
+
`PGDATABASE` خوانده میشود (پیشفرضها: `localhost`، `5432`، `postgres`،
|
|
90
|
+
`postgres`، `clearance`).
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
CLEARANCE_TEST_DATABASE=postgres nox -s tests
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
بعد از علامت زدن یک رشته، با `nox -s messages` استخراجش کنید، آنچه اضافه شده را در
|
|
97
|
+
`locale/fa/LC_MESSAGES/django.po` ترجمه کنید، و کامپایل کنید:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
cd src/clearance && django-admin compilemessages
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## لایسنس
|
|
104
|
+
|
|
105
|
+
BSD 3-Clause - فایل [`LICENSE`](LICENSE) را ببینید.
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# django-clearance
|
|
2
|
+
|
|
3
|
+
Role, policy and row-level access control for Django. Denied by default.
|
|
4
|
+
|
|
5
|
+
[فارسی](README.fa.md)
|
|
6
|
+
|
|
7
|
+
An administrator decides, in Django's admin site and with no code, who may
|
|
8
|
+
do what - and to which rows, and with which fields:
|
|
9
|
+
|
|
10
|
+
* **bundles** of permissions, each given with a **scope** - "their branch's
|
|
11
|
+
orders", "their own", or a rule built in the admin site;
|
|
12
|
+
* **protected fields**, read with one permission and written with another;
|
|
13
|
+
* **status actions** - only whoever may approve sets an order to *approved*;
|
|
14
|
+
* **roles**, optional, with a ceiling nobody with the role goes past.
|
|
15
|
+
|
|
16
|
+
Every door asks the same rules: Django's views and templates, DRF, the admin
|
|
17
|
+
site, and your own code. A change is refused when it would let somebody give
|
|
18
|
+
themselves more. The pages, messages and permissions come in English and
|
|
19
|
+
Persian, and read right to left in Persian.
|
|
20
|
+
|
|
21
|
+
## In a project
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install 'django-clearance[drf]'
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
INSTALLED_APPS = [
|
|
29
|
+
'clearance.admin.apps.ClearanceAdminConfig', # instead of 'django.contrib.admin'
|
|
30
|
+
...
|
|
31
|
+
'clearance',
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
AUTHENTICATION_BACKENDS = ['clearance.backends.ClearanceBackend']
|
|
35
|
+
|
|
36
|
+
REST_FRAMEWORK = {
|
|
37
|
+
'DEFAULT_PERMISSION_CLASSES': ['clearance.drf.permissions.ModelPolicyPermission'],
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
class OrderViewSet(ScopedModelViewSet): # the rows, the policy, the fields - asked
|
|
43
|
+
queryset = Order.objects.all()
|
|
44
|
+
serializer_class = OrderSerializer
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
Order.objects.visible_to(user, 'edit') # the orders this person may edit
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
* [The guide](docs/guide.md) - every part, how to use it.
|
|
51
|
+
* [The example shop](example/README.md) - a project using all of it, to run.
|
|
52
|
+
* [The design](docs/design.md) - why it is built the way it is.
|
|
53
|
+
|
|
54
|
+
Python 3.11 to 3.14; Django 5.2, 6.0 and 6.1; Django REST framework 3.16 and
|
|
55
|
+
later, optional; any database Django supports.
|
|
56
|
+
|
|
57
|
+
## Working on it
|
|
58
|
+
|
|
59
|
+
Every check runs through [nox](https://nox.thea.codes), the same sessions
|
|
60
|
+
locally and in CI. With [uv](https://docs.astral.sh/uv/) installed, a Python
|
|
61
|
+
that is missing is fetched for you.
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
uv tool install nox
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
nox -s lint
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
nox -s types
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
nox -s tests
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`tests` runs every supported Python and Django; one combination is
|
|
80
|
+
`nox -s "tests(3.13-django6.1)"`, and `nox -l` lists them all. `browser`
|
|
81
|
+
runs the pages in a real browser, `messages` - with gettext installed -
|
|
82
|
+
checks that the catalogues hold every string the library marks, and
|
|
83
|
+
`package` builds the wheel and runs the example project on it.
|
|
84
|
+
|
|
85
|
+
The suite uses SQLite unless told otherwise. To run it on PostgreSQL, as CI
|
|
86
|
+
does, set `CLEARANCE_TEST_DATABASE=postgres`; the connection is read from the
|
|
87
|
+
standard `PGHOST`, `PGPORT`, `PGUSER`, `PGPASSWORD` and `PGDATABASE`
|
|
88
|
+
variables (defaults: `localhost`, `5432`, `postgres`, `postgres`,
|
|
89
|
+
`clearance`).
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
CLEARANCE_TEST_DATABASE=postgres nox -s tests
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
After marking a string, extract it with `nox -s messages`, translate what it
|
|
96
|
+
added in `locale/fa/LC_MESSAGES/django.po`, and compile:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
cd src/clearance && django-admin compilemessages
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Licence
|
|
103
|
+
|
|
104
|
+
BSD 3-Clause - see [`LICENSE`](LICENSE).
|