openedx-authz 4.3.0__tar.gz → 4.6.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.
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/.github/workflows/ci.yml +1 -1
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/CHANGELOG.rst +26 -0
- {openedx_authz-4.3.0/src/openedx_authz.egg-info → openedx_authz-4.6.0}/PKG-INFO +1 -1
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0035-custom-role-persistence.rst +39 -2
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/references/authorization-schema.rst +2 -1
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/api/__init__.py +2 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/api/catalog.py +9 -4
- openedx_authz-4.6.0/src/openedx_authz/api/custom_roles.py +331 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/api/data.py +2 -7
- openedx_authz-4.6.0/src/openedx_authz/api/exceptions.py +52 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/api/roles.py +26 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/constants/__init__.py +6 -1
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/constants/schema.py +16 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/policy.py +62 -1
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/renderer.py +108 -64
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/pipeline.py +6 -2
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/validation.py +20 -1
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/management/commands/load_authz_schema.py +79 -11
- openedx_authz-4.6.0/src/openedx_authz/migrations/0014_add_custom_role_fields.py +36 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/models/base.py +24 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/models/engine.py +3 -3
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/models/schema.py +97 -18
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/api/test_catalog.py +81 -0
- openedx_authz-4.6.0/src/openedx_authz/tests/api/test_custom_roles.py +662 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_apply.py +189 -10
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_load_authz_schema_command.py +66 -2
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_pipeline.py +17 -5
- openedx_authz-4.6.0/src/openedx_authz/tests/schema/test_schema_models.py +295 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_validation.py +35 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0/src/openedx_authz.egg-info}/PKG-INFO +1 -1
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz.egg-info/SOURCES.txt +4 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz.egg-info/scm_file_list.json +4 -0
- openedx_authz-4.3.0/src/openedx_authz/tests/schema/test_schema_models.py +0 -145
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/.annotation_safe_list.yml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/.editorconfig +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/.github/dependabot.yml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/.github/workflows/add-depr-ticket-to-depr-board.yml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/.github/workflows/add-remove-label-on-comment.yml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/.github/workflows/commitlint.yml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/.github/workflows/release.yml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/.github/workflows/self-assign-issue.yml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/.github/workflows/upgrade-python-requirements.yml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/.gitignore +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/.pii_annotations.yml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/.readthedocs.yaml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/LICENSE +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/MANIFEST.in +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/Makefile +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/README.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/catalog-info.yaml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/codecov.yml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/Makefile +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/_images/architecture-overview.png +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/_static/theme_overrides.css +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/changelog.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/concepts/core_roles_and_permissions/content_library_roles.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/concepts/core_roles_and_permissions/course_roles.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/concepts/core_roles_and_permissions/index.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/concepts/index.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/conf.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0001-purpose-of-this-repo.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0002-authorization-model-foundation.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0003-jwt-usage.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0004-technology-selection.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0005-architecture-and-data-modeling.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0007-enforcement-mechanisms-mfe.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0008-compatibility-scheme.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0009-authz-for-course-authoring.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0010-course-authoring-flag.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0011-course-authoring-migration-process.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0012-auditability.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0012-glob-support-for-role-assignments.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0013-course-authoring-automatic-migration.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0014-bulk-assignment-queries-without-casbin-enforce.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0015-expose-course-authoring-waffle-flag-state-via-rest-api.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0016-static-and-dynamic-roles.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0017-static-authorization-schema.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0018-authorization-schema-lifecycle.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0019-authorization-schema-discovery.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0020-authorization-schema-internationalization.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0021-authorization-definition-api.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0022-defer-authorization-implications.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0023-extend-static-roles.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0024-api-contract-for-user-grouped-role-assignments.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0025-authorization-schema-source-tracking.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0026-rest-api-domain-ownership-boundary.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0027-cross-domain-filtering-via-openedx-filters.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0028-api-contract-for-role-catalog.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0029-paragon-icon-list-maintenance.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0030-tutor-implementation-authz-schema-discovery.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0031-priority-applies-to-role-extensions-only.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0032-applets-for-built-in-authorization-capabilities.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0033-shared-applet-for-course-team-roles.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0034-permission-dependencies-in-authorization-schema.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0036-api-contract-for-custom-roles.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0037-custom-role-audit-trail.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/0038-hidden-permission-categories-and-permissions.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions/README.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/decisions.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/getting_started.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/how-tos/index.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/how-tos/use-built-in-constants.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/index.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/internationalization.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/make.bat +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/quickstarts/index.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/readme.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/references/authorization-schema-json.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/references/built-in-constants.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/references/compiled-schema.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/references/compiled-schema.yaml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/references/index.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/docs/testing.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/manage.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/pylintrc +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/pylintrc_tweaks +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/pyproject.toml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/ruff.toml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/scripts/generate_compiled_schema.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/scripts/generate_paragon_icons.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/setup.cfg +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/admin.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/api/permissions.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/api/users.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/api/utils.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/content_libraries/README.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/content_libraries/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/content_libraries/constants.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/content_libraries/schema/permissions.yaml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/content_libraries/schema/roles.yaml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/course_authoring/README.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/course_authoring/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/course_authoring/constants.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/course_authoring/schema/permissions.yaml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/course_authoring/schema/role_extensions.yaml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/course_team_roles/README.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/course_team_roles/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/course_team_roles/constants.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/course_team_roles/schema/legacy_permissions.yaml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/course_team_roles/schema/roles.yaml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/enrollments/README.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/enrollments/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/enrollments/constants.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/enrollments/schema/permissions.yaml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/enrollments/schema/role_extensions.yaml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/learner_administration/README.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/learner_administration/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/learner_administration/constants.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/learner_administration/schema/permissions.yaml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/learner_administration/schema/role_extensions.yaml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/learner_grading/README.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/learner_grading/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/learner_grading/constants.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/learner_grading/schema/permissions.yaml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/learner_grading/schema/role_extensions.yaml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/apps.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/authz/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/conf/locale/config.yaml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/constants/permissions.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/constants/roles.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/data.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/adapter.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/apps.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/config/model.conf +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/enforcer.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/filter.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/matcher.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/authz-schema-v1.json +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/compilation.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/discovery.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/exceptions.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/issues.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/loading.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/paragon_icons.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/parsing.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/snapshot.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/syntax.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/translation.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/types/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/types/compilation.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/types/definitions.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/types/loading.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/utils.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/filters.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/handlers.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/management/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/management/commands/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/management/commands/authz_migrate_course_authoring.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/management/commands/authz_rollback_course_authoring.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/management/commands/enforcement.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/management/commands/extract_schema_translations.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/management/commands/load_policies.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/migrations/0001_add_casbin_dependency.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/migrations/0002_initial.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/migrations/0003_usersubject.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/migrations/0004_contentlibraryscope.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/migrations/0005_policycachecontrol.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/migrations/0006_migrate_legacy_permissions.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/migrations/0007_coursescope.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/migrations/0008_authzcourseauthoringmigrationrun.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/migrations/0009_roleassignmentaudit.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/migrations/0010_scope_external_key.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/migrations/0011_authz_schema_definitions.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/migrations/0012_move_builtin_schema_sources_to_applets.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/migrations/0013_add_hidden_to_categories_and_permissions.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/migrations/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/models/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/models/authz_migration.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/models/core.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/models/scopes.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/models/subjects.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/data.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/decorators.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/urls.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/utils.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/v1/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/v1/admin_console/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/v1/admin_console/filters.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/v1/admin_console/serializers.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/v1/admin_console/views.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/v1/course_authoring/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/v1/course_authoring/pipeline.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/v1/course_authoring/views.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/v1/fields.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/v1/paginators.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/v1/permissions.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/v1/serializers.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/v1/urls.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/v1/views.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/settings/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/settings/common.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/settings/production.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/settings/test.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/templates/openedx_authz/base.html +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/api/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/api/test_data.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/api/test_roles.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/api/test_users.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/applets/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/applets/test_builtin_definitions.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/applets/test_instructor_dashboard_permissions.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/authz/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/authz/test_resources.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/conftest.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/fixtures/schema_pipeline/invalid_compiled/categories.yaml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/fixtures/schema_pipeline/invalid_compiled/extensions.yaml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/fixtures/schema_pipeline/invalid_compiled/permissions.yaml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/fixtures/schema_pipeline/invalid_compiled/roles.yaml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/fixtures/schema_pipeline/invalid_parse/malformed.yaml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/fixtures/schema_pipeline/invalid_semantics/unknown_category.yaml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/fixtures/schema_pipeline/invalid_structure/items.yml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/fixtures/schema_pipeline/invalid_structure/priority.yaml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/fixtures/schema_pipeline/valid/categories.yaml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/fixtures/schema_pipeline/valid/extensions.yaml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/fixtures/schema_pipeline/valid/permissions.yml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/fixtures/schema_pipeline/valid/roles.yaml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/test_handlers.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/test_models.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/test_schema_apply.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/test_schema_pipeline.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/test_views.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/rest_api/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/rest_api/admin_console/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/rest_api/admin_console/test_filters.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/rest_api/admin_console/test_views.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/rest_api/course_authoring/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/rest_api/course_authoring/test_pipeline.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/rest_api/course_authoring/test_views.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/rest_api/mixins.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/rest_api/test_permissions.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/rest_api/test_utils.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/rest_api/test_views.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/role_permissions.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/factories.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_compilation.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_discovery.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_json_schema.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_loading.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_parsing.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_renderer.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_snapshot.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_source_storage.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_syntax.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_translation.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_types.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/stubs/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/stubs/apps.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/stubs/migrations/0001_initial.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/stubs/migrations/0002_learningpackage_contentlibrary_learning_package.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/stubs/migrations/0002_userprofile.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/stubs/models.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/test_commands.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/test_enforcement.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/test_enforcer.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/test_engine_utils.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/test_filter.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/test_handlers.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/test_imports.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/test_migrations.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/test_models.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/test_policy.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/test_utils.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/urls.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz/utils.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz.egg-info/dependency_links.txt +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz.egg-info/entry_points.txt +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz.egg-info/requires.txt +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/src/openedx_authz.egg-info/top_level.txt +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/tox.ini +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/tutor/tutor-contrib-authz/.gitignore +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/tutor/tutor-contrib-authz/LICENSE.txt +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/tutor/tutor-contrib-authz/MANIFEST.in +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/tutor/tutor-contrib-authz/Makefile +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/tutor/tutor-contrib-authz/README.rst +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/tutor/tutor-contrib-authz/pyproject.toml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/tutor/tutor-contrib-authz/tutor_authz/__about__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/tutor/tutor-contrib-authz/tutor_authz/__init__.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/tutor/tutor-contrib-authz/tutor_authz/patches/openedx-common-settings +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/tutor/tutor-contrib-authz/tutor_authz/plugin.py +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/tutor/tutor-contrib-authz/tutor_authz/templates/apps/openedx/config/authz-schema.yml +0 -0
- {openedx_authz-4.3.0 → openedx_authz-4.6.0}/uv.lock +0 -0
|
@@ -21,7 +21,7 @@ jobs:
|
|
|
21
21
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
22
22
|
|
|
23
23
|
- name: Install uv
|
|
24
|
-
uses: astral-sh/setup-uv@
|
|
24
|
+
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
|
|
25
25
|
with:
|
|
26
26
|
enable-cache: true
|
|
27
27
|
python-version: ${{ matrix.python-version }}
|
|
@@ -17,6 +17,32 @@ Unreleased
|
|
|
17
17
|
Added
|
|
18
18
|
=====
|
|
19
19
|
|
|
20
|
+
* Added the storage for custom roles in the role definition table (ADR 0035), in migration
|
|
21
|
+
``0014_add_custom_role_fields``: a ``definition_kind`` (``static`` or ``user_defined``) and a
|
|
22
|
+
``removed_at`` time. Existing roles stay ``static``. The role catalog now returns the stored
|
|
23
|
+
definition kind of each role and leaves out removed custom roles.
|
|
24
|
+
* The ``load_authz_schema`` command and the schema applier now leave custom roles alone: they do
|
|
25
|
+
not create, update, prune or report them (ADR 0035). Schema validation rejects a static role ID
|
|
26
|
+
that starts with the reserved ``custom_`` prefix and names the file that declares it.
|
|
27
|
+
* Added ``--drop-custom-role-permissions`` to ``load_authz_schema``. When a release removes a
|
|
28
|
+
permission that a custom role grants, the deployment stops before any write and lists each
|
|
29
|
+
affected grant. Run the command with this option to drop those grants and their policy rows in
|
|
30
|
+
the same deployment; a custom role left with no permissions keeps its assignments, and the
|
|
31
|
+
report lists it. Releases that remove a permission must say so in their operator release notes
|
|
32
|
+
and name this option.
|
|
33
|
+
* Added ``create_custom_role``, ``update_custom_role`` and ``remove_custom_role`` to the public
|
|
34
|
+
API (ADR 0035). Each change updates the role definition, its grants and its policy rows in one
|
|
35
|
+
transaction, under the same lock as schema deployments, and reaches every holder of the role
|
|
36
|
+
right away. A custom role ID is ``custom_`` followed by the display name and never changes.
|
|
37
|
+
Removing a role keeps its definition marked as removed, so the ID is not reused, and deletes its
|
|
38
|
+
grants, policy rows and assignments; a role that still has assignments needs
|
|
39
|
+
``delete_assignments=True``. A display name is stored without surrounding whitespace and must not
|
|
40
|
+
be used by another role that has not been removed, ignoring case, and custom roles cannot grant
|
|
41
|
+
hidden permissions or permissions in hidden categories. The errors these operations raise are in
|
|
42
|
+
``openedx_authz.api.exceptions``.
|
|
43
|
+
* ``assign_role_to_subject_in_scope`` now raises ``CustomRoleNotFoundError`` for a custom role that
|
|
44
|
+
does not exist or was removed. It assigns custom roles under the same lock as removing them, so
|
|
45
|
+
an assignment cannot outlive a concurrent removal. Static role assignments are unchanged.
|
|
20
46
|
* Added an optional ``hidden`` flag to permission categories and permissions in the authorization
|
|
21
47
|
schema. Hidden permissions, and the permissions of hidden categories, are left out of the
|
|
22
48
|
role and permission catalog, including each role's permission list, but keep their role grants
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: openedx-authz
|
|
3
|
-
Version: 4.
|
|
3
|
+
Version: 4.6.0
|
|
4
4
|
Summary: Open edX AuthZ provides the architecture and foundations of the authorization framework.
|
|
5
5
|
Author-email: Open edX Project <oscm@openedx.org>
|
|
6
6
|
License-Expression: AGPL-3.0-or-later
|
|
@@ -50,8 +50,9 @@ longer needed is removed instead (section 4).
|
|
|
50
50
|
==============================
|
|
51
51
|
|
|
52
52
|
Custom roles are global to the instance. Their IDs use the reserved prefix ``custom_`` followed by
|
|
53
|
-
the display name converted to the role ID format (``[a-z][a-z0-9_]*``). The ID
|
|
54
|
-
never
|
|
53
|
+
the display name converted to the role ID format (``[a-z][a-z0-9_]*``). The ID and the display name
|
|
54
|
+
are set at creation and never change. Editing a custom role changes only its description and
|
|
55
|
+
permissions, matching `ADR 0036`_.
|
|
55
56
|
|
|
56
57
|
The name is converted with the Python standard library, so no transliteration dependency is needed:
|
|
57
58
|
|
|
@@ -145,6 +146,32 @@ those grants and their ``p`` rows in the same deployment. A release that removes
|
|
|
145
146
|
say so in its operator release notes and name this option. A custom role left with no permissions
|
|
146
147
|
remains, so its assignments are kept.
|
|
147
148
|
|
|
149
|
+
6. Where the rules are enforced
|
|
150
|
+
===============================
|
|
151
|
+
|
|
152
|
+
Each kind of role has one writer: the schema loader writes static roles and the custom role API
|
|
153
|
+
writes custom roles. Each rule is enforced by the layer that owns the write it applies to:
|
|
154
|
+
|
|
155
|
+
.. list-table::
|
|
156
|
+
:header-rows: 1
|
|
157
|
+
|
|
158
|
+
* - Rule
|
|
159
|
+
- Enforced by
|
|
160
|
+
* - Role IDs are unique.
|
|
161
|
+
- The database, with a unique constraint on the role ID.
|
|
162
|
+
* - Static role IDs do not start with ``custom_``.
|
|
163
|
+
- Schema validation, before any database change.
|
|
164
|
+
* - Custom role IDs start with ``custom_``, and the ID and display name never change.
|
|
165
|
+
- The custom role API, which builds the ID and only edits the description and permissions.
|
|
166
|
+
* - Custom roles are never hidden.
|
|
167
|
+
- The custom role API, which never sets ``hidden``. The schema loader does not write custom
|
|
168
|
+
roles (section 5).
|
|
169
|
+
* - Only custom roles are removed.
|
|
170
|
+
- The custom role API, which is the only code that sets the removal time.
|
|
171
|
+
|
|
172
|
+
A new rule goes in the layer that writes the data it constrains. The database only enforces
|
|
173
|
+
integrity that every writer needs, such as uniqueness.
|
|
174
|
+
|
|
148
175
|
Consequences
|
|
149
176
|
************
|
|
150
177
|
|
|
@@ -183,6 +210,14 @@ Infer custom roles from missing source links
|
|
|
183
210
|
A role with no source links could also be a leftover or the result of an incomplete write. An
|
|
184
211
|
explicit definition kind avoids the guesswork and is the value the catalog already returns.
|
|
185
212
|
|
|
213
|
+
Database check constraints for the custom role rules
|
|
214
|
+
====================================================
|
|
215
|
+
|
|
216
|
+
Check constraints would reject a row that breaks a rule even if it came from outside the two
|
|
217
|
+
writers. Each kind of role has a single writer that already enforces its rules, and every change to
|
|
218
|
+
a constraint needs a migration that works with the rows already stored. Keeping the rules in the
|
|
219
|
+
writers keeps them in one place per kind of role.
|
|
220
|
+
|
|
186
221
|
References
|
|
187
222
|
**********
|
|
188
223
|
|
|
@@ -193,6 +228,7 @@ References
|
|
|
193
228
|
* `ADR 0023`_
|
|
194
229
|
* `ADR 0025`_
|
|
195
230
|
* `ADR 0028`_
|
|
231
|
+
* `ADR 0036`_
|
|
196
232
|
* `Issue #467`_
|
|
197
233
|
|
|
198
234
|
.. _ADR 0012: 0012-auditability.rst
|
|
@@ -202,4 +238,5 @@ References
|
|
|
202
238
|
.. _ADR 0023: 0023-extend-static-roles.rst
|
|
203
239
|
.. _ADR 0025: 0025-authorization-schema-source-tracking.rst
|
|
204
240
|
.. _ADR 0028: 0028-api-contract-for-role-catalog.rst
|
|
241
|
+
.. _ADR 0036: 0036-api-contract-for-custom-roles.rst
|
|
205
242
|
.. _Issue #467: https://github.com/openedx/openedx-authz/issues/467
|
|
@@ -190,7 +190,7 @@ Roles
|
|
|
190
190
|
A role contains these fields:
|
|
191
191
|
|
|
192
192
|
``id``
|
|
193
|
-
The stable role identifier. It uses lowercase snake case, such as ``course_admin``, ``course_editor``, or ``library_author``. Role IDs do not include a product namespace because authorization uses the role within its supported scopes.
|
|
193
|
+
The stable role identifier. It uses lowercase snake case, such as ``course_admin``, ``course_editor``, or ``library_author``. Role IDs do not include a product namespace because authorization uses the role within its supported scopes. The ``custom_`` prefix is reserved for roles that administrators create, so a schema role ID cannot start with it and validation reports the file that declares it.
|
|
194
194
|
|
|
195
195
|
``display_name``
|
|
196
196
|
The source-language name shown to users.
|
|
@@ -292,6 +292,7 @@ The following values are invalid:
|
|
|
292
292
|
act^courses.view_course # internal Casbin namespace
|
|
293
293
|
course content # space
|
|
294
294
|
role^course_editor # internal Casbin namespace
|
|
295
|
+
custom_course_editor # role ID prefix reserved for custom roles
|
|
295
296
|
|
|
296
297
|
Scope namespaces follow the spelling registered by their ``ScopeData`` type and may contain a hyphen. Do not apply the snake-case identifier rule to values such as ``course-v1`` or ``ccx-v1``.
|
|
297
298
|
|
|
@@ -6,7 +6,9 @@ provide a simpler interface for other services in the Open edX ecosystem.
|
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
8
|
from openedx_authz.api.catalog import *
|
|
9
|
+
from openedx_authz.api.custom_roles import *
|
|
9
10
|
from openedx_authz.api.data import *
|
|
11
|
+
from openedx_authz.api.exceptions import *
|
|
10
12
|
from openedx_authz.api.permissions import *
|
|
11
13
|
from openedx_authz.api.roles import *
|
|
12
14
|
from openedx_authz.api.users import *
|
|
@@ -4,7 +4,6 @@ The catalog is read from the authz schema models, the same data the Casbin polic
|
|
|
4
4
|
rendered from, using a constant number of queries (see ADR 0028).
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
|
-
from openedx_authz.api.data import DefinitionKind
|
|
8
7
|
from openedx_authz.models.schema import (
|
|
9
8
|
AuthzPermissionCategory,
|
|
10
9
|
AuthzPermissionDefinition,
|
|
@@ -61,7 +60,8 @@ def get_role_catalog(scope_types: list[str]) -> list[dict]:
|
|
|
61
60
|
not hidden. Hidden permissions, and permissions in hidden categories, are left out of
|
|
62
61
|
``permissions``. Roles and their grants are read only from the stored schema definitions, never
|
|
63
62
|
from the Casbin policy, so a role without a stored definition is not listed. Hidden roles are
|
|
64
|
-
never included, even if they are assigned to users.
|
|
63
|
+
never included, even if they are assigned to users. A custom role left with no permissions is
|
|
64
|
+
still listed by its stored resource type, with empty ``permissions``.
|
|
65
65
|
|
|
66
66
|
Args:
|
|
67
67
|
scope_types (list[str]): The scope types (e.g., ['course-v1', 'lib']).
|
|
@@ -81,7 +81,12 @@ def get_role_catalog(scope_types: list[str]) -> list[dict]:
|
|
|
81
81
|
- ``updated_at``: When a custom role last changed. Always ``None`` here, because static roles
|
|
82
82
|
have no meaningful edit date.
|
|
83
83
|
"""
|
|
84
|
-
|
|
84
|
+
visible_roles = AuthzRoleDefinition.objects.visible()
|
|
85
|
+
# A custom role left with no grants is matched by its resource type, so an administrator can still
|
|
86
|
+
# add permissions to it or remove it (ADR 0035, ADR 0036).
|
|
87
|
+
roles = (
|
|
88
|
+
visible_roles.with_grants_in_scope_types(scope_types) | visible_roles.user_defined_in_scope_types(scope_types)
|
|
89
|
+
).prefetch_grants_in_scope_types(scope_types)
|
|
85
90
|
return [
|
|
86
91
|
{
|
|
87
92
|
"role": role.role_id,
|
|
@@ -94,7 +99,7 @@ def get_role_catalog(scope_types: list[str]) -> list[dict]:
|
|
|
94
99
|
"display_name": role.display_name,
|
|
95
100
|
"description": role.description,
|
|
96
101
|
"icon": role.icon,
|
|
97
|
-
"definition_kind":
|
|
102
|
+
"definition_kind": role.definition_kind,
|
|
98
103
|
"permissions": sorted({grant.permission.identifier for grant in role.grants}),
|
|
99
104
|
"scope_types": sorted(set(role.scopes) & set(scope_types)),
|
|
100
105
|
# TODO: set correct value for ``updated_at`` when custom roles arrive.
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
"""Create, edit and remove custom roles (ADR 0035).
|
|
2
|
+
|
|
3
|
+
A custom role is stored like a static one: a row in the role definition table, one row per granted
|
|
4
|
+
permission, and the matching Casbin ``p`` rows. Every change updates those three together in one
|
|
5
|
+
transaction, under the same lock as schema deployments, and takes effect for every holder of the
|
|
6
|
+
role as soon as the policy cache is invalidated.
|
|
7
|
+
|
|
8
|
+
This module only changes definitions. Who may call it, the REST contract and the audit trail of
|
|
9
|
+
role changes are decided elsewhere.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import re
|
|
13
|
+
import unicodedata
|
|
14
|
+
from collections.abc import Collection, Iterator, Sequence
|
|
15
|
+
from contextlib import contextmanager
|
|
16
|
+
|
|
17
|
+
from django.utils import timezone
|
|
18
|
+
|
|
19
|
+
from openedx_authz.api.data import RoleData
|
|
20
|
+
from openedx_authz.api.exceptions import (
|
|
21
|
+
CustomRoleError,
|
|
22
|
+
CustomRoleHasAssignmentsError,
|
|
23
|
+
CustomRoleNameTakenError,
|
|
24
|
+
CustomRoleNotFoundError,
|
|
25
|
+
InvalidCustomRoleError,
|
|
26
|
+
StaticRoleError,
|
|
27
|
+
)
|
|
28
|
+
from openedx_authz.api.roles import get_role_assignments, unassign_role_from_subject_in_scope
|
|
29
|
+
from openedx_authz.constants import CUSTOM_ROLE_ID_MAX_LENGTH, CUSTOM_ROLE_ID_PREFIX, DefinitionKind
|
|
30
|
+
from openedx_authz.engine.enforcer import AuthzEnforcer
|
|
31
|
+
from openedx_authz.engine.policy import PolicyRow, PolicyStore, serialized_policy_update
|
|
32
|
+
from openedx_authz.models.schema import AuthzPermissionDefinition, AuthzRoleDefinition, AuthzRolePermission
|
|
33
|
+
|
|
34
|
+
__all__ = [
|
|
35
|
+
"create_custom_role",
|
|
36
|
+
"remove_custom_role",
|
|
37
|
+
"update_custom_role",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
FALLBACK_ROLE_SLUG = "role"
|
|
41
|
+
DISPLAY_NAME_MAX_LENGTH = AuthzRoleDefinition._meta.get_field("display_name").max_length
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def slugify_role_name(display_name: str) -> str:
|
|
45
|
+
"""Convert a display name to the lowercase letters, digits and underscores of a role ID.
|
|
46
|
+
|
|
47
|
+
Accents are dropped by decomposing the name and discarding what is not ASCII, so no
|
|
48
|
+
transliteration dependency is needed. A name written only in a non-Latin script gives an
|
|
49
|
+
empty result.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
display_name (str): The name as the administrator entered it.
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
str: The converted name, without leading or trailing underscores.
|
|
56
|
+
"""
|
|
57
|
+
ascii_name = unicodedata.normalize("NFKD", display_name).encode("ascii", "ignore").decode("ascii")
|
|
58
|
+
return re.sub(r"[^a-z0-9]+", "_", ascii_name.lower()).strip("_")
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def build_custom_role_id(display_name: str, taken_ids: Collection[str]) -> str:
|
|
62
|
+
"""Return the first free custom role ID for a display name.
|
|
63
|
+
|
|
64
|
+
The ID is the reserved prefix followed by the converted name. When it is taken, a numeric
|
|
65
|
+
suffix starting at 2 is added. The converted name is cut so the whole ID, suffix included,
|
|
66
|
+
fits the maximum length, and underscores left at the end of the cut are dropped.
|
|
67
|
+
|
|
68
|
+
Args:
|
|
69
|
+
display_name (str): The name as the administrator entered it.
|
|
70
|
+
taken_ids (Collection[str]): Every ID that cannot be reused, including removed roles.
|
|
71
|
+
|
|
72
|
+
Returns:
|
|
73
|
+
str: An ID that is not in ``taken_ids``.
|
|
74
|
+
"""
|
|
75
|
+
base = f"{CUSTOM_ROLE_ID_PREFIX}{slugify_role_name(display_name) or FALLBACK_ROLE_SLUG}"
|
|
76
|
+
candidate = base[:CUSTOM_ROLE_ID_MAX_LENGTH].rstrip("_")
|
|
77
|
+
number = 1
|
|
78
|
+
while candidate in taken_ids:
|
|
79
|
+
number += 1
|
|
80
|
+
suffix = f"_{number}"
|
|
81
|
+
candidate = f"{base[: CUSTOM_ROLE_ID_MAX_LENGTH - len(suffix)].rstrip('_')}{suffix}"
|
|
82
|
+
return candidate
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def create_custom_role(
|
|
86
|
+
display_name: str,
|
|
87
|
+
description: str,
|
|
88
|
+
scope_type: str,
|
|
89
|
+
permissions: Sequence[str],
|
|
90
|
+
) -> AuthzRoleDefinition:
|
|
91
|
+
"""Create a custom role that grants the given permissions in one scope type.
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
display_name (str): The name shown to administrators. It is stored without surrounding
|
|
95
|
+
whitespace, so names that differ only in it count as the same name.
|
|
96
|
+
description (str): Free text, which may be empty.
|
|
97
|
+
scope_type (str): The resource type the role applies to (e.g., ``course-v1`` or ``lib``).
|
|
98
|
+
permissions (Sequence[str]): Complete IDs of the permissions the role grants. Each must
|
|
99
|
+
exist and support the scope type.
|
|
100
|
+
|
|
101
|
+
Returns:
|
|
102
|
+
AuthzRoleDefinition: The new role, with an ID derived from the display name.
|
|
103
|
+
|
|
104
|
+
Raises:
|
|
105
|
+
InvalidCustomRoleError: If an argument has the wrong type, the name is blank or too long,
|
|
106
|
+
or the permissions are empty, unknown, hidden or do not support the scope type.
|
|
107
|
+
CustomRoleNameTakenError: If another role that has not been removed uses the name.
|
|
108
|
+
"""
|
|
109
|
+
_validate_text("display name", display_name)
|
|
110
|
+
_validate_text("description", description)
|
|
111
|
+
_validate_text("scope type", scope_type)
|
|
112
|
+
display_name = display_name.strip()
|
|
113
|
+
_validate_display_name(display_name)
|
|
114
|
+
with _writing_custom_roles() as policy_store:
|
|
115
|
+
_check_display_name_is_free(display_name)
|
|
116
|
+
resolved = _resolve_permissions(permissions, [scope_type])
|
|
117
|
+
role = AuthzRoleDefinition.objects.create(
|
|
118
|
+
role_id=build_custom_role_id(display_name, _taken_role_ids()),
|
|
119
|
+
display_name=display_name,
|
|
120
|
+
description=description,
|
|
121
|
+
scopes=[scope_type],
|
|
122
|
+
definition_kind=DefinitionKind.USER_DEFINED.value,
|
|
123
|
+
)
|
|
124
|
+
_add_grants(policy_store, role, resolved)
|
|
125
|
+
return role
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def update_custom_role(
|
|
129
|
+
role_id: str,
|
|
130
|
+
*,
|
|
131
|
+
description: str | None = None,
|
|
132
|
+
permissions: Sequence[str] | None = None,
|
|
133
|
+
) -> AuthzRoleDefinition:
|
|
134
|
+
"""Change the description or the permissions of a custom role.
|
|
135
|
+
|
|
136
|
+
The role ID, name and scope type stay as they were. Permissions that are added or dropped
|
|
137
|
+
reach every holder of the role right away. Any edit, including a permissions-only one, sets
|
|
138
|
+
the role's ``updated_at``.
|
|
139
|
+
|
|
140
|
+
Args:
|
|
141
|
+
role_id (str): The ID of the custom role.
|
|
142
|
+
description (str | None): The new description, or ``None`` to keep the current one.
|
|
143
|
+
permissions (Sequence[str] | None): The complete new list of permission IDs, or ``None``
|
|
144
|
+
to keep the current ones.
|
|
145
|
+
|
|
146
|
+
Returns:
|
|
147
|
+
AuthzRoleDefinition: The updated role.
|
|
148
|
+
|
|
149
|
+
Raises:
|
|
150
|
+
CustomRoleNotFoundError: If there is no such custom role, or it was removed.
|
|
151
|
+
StaticRoleError: If the role is a static role.
|
|
152
|
+
InvalidCustomRoleError: If nothing is given to change, an argument has the wrong type, or
|
|
153
|
+
the permissions are empty, unknown, hidden or unsupported by the role.
|
|
154
|
+
"""
|
|
155
|
+
if description is None and permissions is None:
|
|
156
|
+
raise InvalidCustomRoleError("Give a description or permissions to change.")
|
|
157
|
+
if description is not None:
|
|
158
|
+
_validate_text("description", description)
|
|
159
|
+
with _writing_custom_roles() as policy_store:
|
|
160
|
+
role = _get_active_custom_role(role_id)
|
|
161
|
+
if permissions is not None:
|
|
162
|
+
_replace_grants(policy_store, role, _resolve_permissions(permissions, role.scopes))
|
|
163
|
+
if description is not None:
|
|
164
|
+
role.description = description
|
|
165
|
+
role.save(update_fields=["description", "updated_at"])
|
|
166
|
+
return role
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def remove_custom_role(role_id: str, *, delete_assignments: bool = False) -> None:
|
|
170
|
+
"""Remove a custom role, its grants and its assignments.
|
|
171
|
+
|
|
172
|
+
The role definition stays in the table, marked as removed, so its ID is never reused and
|
|
173
|
+
audit records can still name it. The role no longer grants any access.
|
|
174
|
+
|
|
175
|
+
Args:
|
|
176
|
+
role_id (str): The ID of the custom role.
|
|
177
|
+
delete_assignments (bool): Must be true to remove a role that still has assignments.
|
|
178
|
+
|
|
179
|
+
Raises:
|
|
180
|
+
CustomRoleNotFoundError: If there is no such custom role, or it was removed already.
|
|
181
|
+
StaticRoleError: If the role is a static role.
|
|
182
|
+
CustomRoleHasAssignmentsError: If the role has assignments and ``delete_assignments`` is false.
|
|
183
|
+
"""
|
|
184
|
+
with _writing_custom_roles() as policy_store:
|
|
185
|
+
role = _get_active_custom_role(role_id)
|
|
186
|
+
assignments = get_role_assignments(role=RoleData(external_key=role_id))
|
|
187
|
+
if assignments and not delete_assignments:
|
|
188
|
+
raise CustomRoleHasAssignmentsError(role_id, len(assignments))
|
|
189
|
+
for assignment in assignments:
|
|
190
|
+
unassign_role_from_subject_in_scope(assignment.subject, assignment.roles[0], assignment.scope)
|
|
191
|
+
_remove_grants(policy_store, role, list(role.role_permissions.select_related("permission")))
|
|
192
|
+
role.removed_at = timezone.now()
|
|
193
|
+
role.save(update_fields=["removed_at", "updated_at"])
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
@contextmanager
|
|
197
|
+
def _writing_custom_roles() -> Iterator[PolicyStore]:
|
|
198
|
+
"""Run a custom role change under the policy write lock and publish it on success.
|
|
199
|
+
|
|
200
|
+
Yields the policy store the change writes its ``p`` rows through.
|
|
201
|
+
|
|
202
|
+
The cache is invalidated inside the transaction, so the new version commits together with the
|
|
203
|
+
rows. If the change fails for any other reason than an invalid request, the in-memory policy
|
|
204
|
+
may already hold rows the database rolled back, so the cache is invalidated again after the
|
|
205
|
+
rollback to force a reload (ADR 0018 §5).
|
|
206
|
+
"""
|
|
207
|
+
policy_store = PolicyStore()
|
|
208
|
+
try:
|
|
209
|
+
with serialized_policy_update(policy_store):
|
|
210
|
+
yield policy_store
|
|
211
|
+
AuthzEnforcer.invalidate_policy_cache()
|
|
212
|
+
except CustomRoleError:
|
|
213
|
+
raise
|
|
214
|
+
except Exception:
|
|
215
|
+
AuthzEnforcer.invalidate_policy_cache()
|
|
216
|
+
raise
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def _validate_text(field: str, value: object) -> None:
|
|
220
|
+
"""Reject a value that is not a string, so a missing field is reported instead of failing in the database."""
|
|
221
|
+
if not isinstance(value, str):
|
|
222
|
+
raise InvalidCustomRoleError(f"The {field} must be a string.")
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def _validate_permission_ids(permission_ids: object) -> None:
|
|
226
|
+
"""Reject anything but a sequence of permission ID strings.
|
|
227
|
+
|
|
228
|
+
A single string is rejected too, since iterating it would treat each character as an ID.
|
|
229
|
+
"""
|
|
230
|
+
if (
|
|
231
|
+
isinstance(permission_ids, str)
|
|
232
|
+
or not isinstance(permission_ids, Sequence)
|
|
233
|
+
or not all(isinstance(permission_id, str) for permission_id in permission_ids)
|
|
234
|
+
):
|
|
235
|
+
raise InvalidCustomRoleError("The permissions must be a list of permission ID strings.")
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def _validate_display_name(display_name: str) -> None:
|
|
239
|
+
"""Reject a display name that is blank or longer than its column."""
|
|
240
|
+
if not display_name:
|
|
241
|
+
raise InvalidCustomRoleError("The display name cannot be blank.")
|
|
242
|
+
if len(display_name) > DISPLAY_NAME_MAX_LENGTH:
|
|
243
|
+
raise InvalidCustomRoleError(f"The display name cannot be longer than {DISPLAY_NAME_MAX_LENGTH} characters.")
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def _check_display_name_is_free(display_name: str) -> None:
|
|
247
|
+
"""Reject a display name used by another role that has not been removed, static or custom.
|
|
248
|
+
|
|
249
|
+
Names are compared ignoring case. A static role is compared by its stored name, not its
|
|
250
|
+
translation.
|
|
251
|
+
"""
|
|
252
|
+
if AuthzRoleDefinition.objects.active().filter(display_name__iexact=display_name).exists():
|
|
253
|
+
raise CustomRoleNameTakenError(f"A role named {display_name!r} already exists.")
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def _taken_role_ids() -> set[str]:
|
|
257
|
+
"""Return every custom role ID in use, including removed roles, whose IDs stay reserved."""
|
|
258
|
+
return set(AuthzRoleDefinition.objects.user_defined().values_list("role_id", flat=True))
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def _get_active_custom_role(role_id: str) -> AuthzRoleDefinition:
|
|
262
|
+
"""Return a custom role that has not been removed, or explain why there is none."""
|
|
263
|
+
role = AuthzRoleDefinition.objects.filter(role_id=role_id).first()
|
|
264
|
+
if role is None or role.removed_at is not None:
|
|
265
|
+
raise CustomRoleNotFoundError(f"There is no custom role {role_id!r}.")
|
|
266
|
+
if role.definition_kind != DefinitionKind.USER_DEFINED.value:
|
|
267
|
+
raise StaticRoleError(f"Role {role_id!r} is a static role and is read-only.")
|
|
268
|
+
return role
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
def _resolve_permissions(permission_ids: Sequence[str], scope_types: Sequence[str]) -> list[AuthzPermissionDefinition]:
|
|
272
|
+
"""Return the permission definitions for the IDs, if each can be granted by a custom role.
|
|
273
|
+
|
|
274
|
+
Each permission must exist, be visible and support every scope type. Hidden permissions, and
|
|
275
|
+
permissions in hidden categories, are reserved for static roles. Duplicate IDs are ignored and
|
|
276
|
+
the order of the first occurrence is kept.
|
|
277
|
+
"""
|
|
278
|
+
_validate_permission_ids(permission_ids)
|
|
279
|
+
requested = list(dict.fromkeys(permission_ids))
|
|
280
|
+
if not requested:
|
|
281
|
+
raise InvalidCustomRoleError("A custom role must grant at least one permission.")
|
|
282
|
+
|
|
283
|
+
found = {
|
|
284
|
+
permission.identifier: permission
|
|
285
|
+
for permission in AuthzPermissionDefinition.objects.with_identifiers(requested)
|
|
286
|
+
}
|
|
287
|
+
unknown = [pid for pid in requested if pid not in found]
|
|
288
|
+
if unknown:
|
|
289
|
+
raise InvalidCustomRoleError(f"Unknown permissions: {', '.join(unknown)}.")
|
|
290
|
+
|
|
291
|
+
visible = {
|
|
292
|
+
permission.identifier for permission in AuthzPermissionDefinition.objects.with_identifiers(requested).visible()
|
|
293
|
+
}
|
|
294
|
+
hidden = [pid for pid in requested if pid not in visible]
|
|
295
|
+
if hidden:
|
|
296
|
+
raise InvalidCustomRoleError(f"Hidden permissions cannot be granted by a custom role: {', '.join(hidden)}.")
|
|
297
|
+
|
|
298
|
+
unsupported = [pid for pid in requested if not set(scope_types) <= set(found[pid].scopes)]
|
|
299
|
+
if unsupported:
|
|
300
|
+
raise InvalidCustomRoleError(
|
|
301
|
+
f"Permissions that do not support {', '.join(scope_types)}: {', '.join(unsupported)}."
|
|
302
|
+
)
|
|
303
|
+
return [found[pid] for pid in requested]
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
def _replace_grants(
|
|
307
|
+
policy_store: PolicyStore, role: AuthzRoleDefinition, permissions: Sequence[AuthzPermissionDefinition]
|
|
308
|
+
) -> None:
|
|
309
|
+
"""Make the role grant exactly the given permissions, changing only what differs."""
|
|
310
|
+
current = list(role.role_permissions.select_related("permission"))
|
|
311
|
+
wanted = {permission.pk for permission in permissions}
|
|
312
|
+
granted = {grant.permission_id for grant in current}
|
|
313
|
+
_remove_grants(policy_store, role, [grant for grant in current if grant.permission_id not in wanted])
|
|
314
|
+
_add_grants(policy_store, role, [permission for permission in permissions if permission.pk not in granted])
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def _add_grants(
|
|
318
|
+
policy_store: PolicyStore, role: AuthzRoleDefinition, permissions: Sequence[AuthzPermissionDefinition]
|
|
319
|
+
) -> None:
|
|
320
|
+
"""Store a grant and its ``p`` row for each permission in each of the role's scope types."""
|
|
321
|
+
for permission in permissions:
|
|
322
|
+
for scope_type in role.scopes:
|
|
323
|
+
AuthzRolePermission.objects.create(role=role, permission=permission, scope=scope_type)
|
|
324
|
+
policy_store.add_policy_row(PolicyRow.from_grant(role.role_id, permission.identifier, scope_type))
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
def _remove_grants(policy_store: PolicyStore, role: AuthzRoleDefinition, grants: Sequence[AuthzRolePermission]) -> None:
|
|
328
|
+
"""Delete the grants and their ``p`` rows."""
|
|
329
|
+
for grant in grants:
|
|
330
|
+
policy_store.remove_policy_row(PolicyRow.from_grant(role.role_id, grant.permission.identifier, grant.scope))
|
|
331
|
+
grant.delete()
|
|
@@ -20,6 +20,7 @@ from openedx_authz.authz import (
|
|
|
20
20
|
MANAGE_LIBRARY_TEAM,
|
|
21
21
|
VIEW_LIBRARY_TEAM,
|
|
22
22
|
)
|
|
23
|
+
from openedx_authz.constants.schema import DefinitionKind
|
|
23
24
|
from openedx_authz.data import (
|
|
24
25
|
AUTHZ_POLICY_ATTRIBUTES_SEPARATOR,
|
|
25
26
|
ActionData,
|
|
@@ -41,6 +42,7 @@ __all__ = [
|
|
|
41
42
|
"AuthzBaseClass",
|
|
42
43
|
"ContentLibraryData",
|
|
43
44
|
"CourseOverviewData",
|
|
45
|
+
"DefinitionKind",
|
|
44
46
|
"GroupingPolicyIndex",
|
|
45
47
|
"OrgCourseOverviewGlobData",
|
|
46
48
|
"OrgGlobData",
|
|
@@ -64,13 +66,6 @@ GLOBAL_SCOPE_WILDCARD = "*"
|
|
|
64
66
|
NAMESPACED_KEY_PATTERN = rf"^.+{re.escape(AUTHZ_POLICY_ATTRIBUTES_SEPARATOR)}.+$"
|
|
65
67
|
|
|
66
68
|
|
|
67
|
-
class DefinitionKind(str, Enum):
|
|
68
|
-
"""How a role is defined: ``STATIC`` roles come from the authz schema; ``USER_DEFINED`` is reserved (ADR 0028)."""
|
|
69
|
-
|
|
70
|
-
STATIC = "static"
|
|
71
|
-
USER_DEFINED = "user_defined"
|
|
72
|
-
|
|
73
|
-
|
|
74
69
|
class ScopeMeta(type):
|
|
75
70
|
"""Metaclass for ScopeData to handle dynamic subclass instantiation based on namespace."""
|
|
76
71
|
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""Errors raised by the custom role API (ADR 0035).
|
|
2
|
+
|
|
3
|
+
They live in their own module because both the custom role operations and the role assignment
|
|
4
|
+
API raise them, and the custom role operations already depend on the assignment API.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"CustomRoleError",
|
|
9
|
+
"CustomRoleHasAssignmentsError",
|
|
10
|
+
"CustomRoleNameTakenError",
|
|
11
|
+
"CustomRoleNotFoundError",
|
|
12
|
+
"InvalidCustomRoleError",
|
|
13
|
+
"StaticRoleError",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class CustomRoleError(Exception):
|
|
18
|
+
"""Base class for the errors raised when changing or assigning custom roles."""
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class CustomRoleNotFoundError(CustomRoleError):
|
|
22
|
+
"""No custom role with this ID exists, or it has been removed."""
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class StaticRoleError(CustomRoleError):
|
|
26
|
+
"""The role is a static role, which cannot be edited or removed through custom role operations."""
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class InvalidCustomRoleError(CustomRoleError):
|
|
30
|
+
"""The requested name or permissions cannot make a valid custom role."""
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class CustomRoleNameTakenError(CustomRoleError):
|
|
34
|
+
"""Another role that has not been removed already uses the display name, ignoring case."""
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class CustomRoleHasAssignmentsError(CustomRoleError):
|
|
38
|
+
"""The role still has assignments and the caller did not ask to delete them."""
|
|
39
|
+
|
|
40
|
+
def __init__(self, role_id: str, assignment_count: int) -> None:
|
|
41
|
+
"""Keep the role and its number of assignments so callers can report them.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
role_id (str): The ID of the custom role that was not removed.
|
|
45
|
+
assignment_count (int): How many assignments the role still has.
|
|
46
|
+
"""
|
|
47
|
+
super().__init__(
|
|
48
|
+
f"Custom role {role_id!r} has {assignment_count} assignment(s); "
|
|
49
|
+
"removing it requires explicitly deleting them."
|
|
50
|
+
)
|
|
51
|
+
self.role_id = role_id
|
|
52
|
+
self.assignment_count = assignment_count
|
|
@@ -26,10 +26,14 @@ from openedx_authz.api.data import (
|
|
|
26
26
|
ScopeData,
|
|
27
27
|
SubjectData,
|
|
28
28
|
)
|
|
29
|
+
from openedx_authz.api.exceptions import CustomRoleNotFoundError
|
|
29
30
|
from openedx_authz.api.permissions import get_permission_from_policy
|
|
31
|
+
from openedx_authz.constants import CUSTOM_ROLE_ID_PREFIX
|
|
30
32
|
from openedx_authz.engine.enforcer import AuthzEnforcer
|
|
33
|
+
from openedx_authz.engine.policy import policy_write_lock
|
|
31
34
|
from openedx_authz.models import ExtendedCasbinRule
|
|
32
35
|
from openedx_authz.models.core import RoleAssignmentAudit
|
|
36
|
+
from openedx_authz.models.schema import AuthzRoleDefinition
|
|
33
37
|
|
|
34
38
|
__all__ = [
|
|
35
39
|
"assign_role_to_subject_in_scope",
|
|
@@ -210,6 +214,10 @@ def assign_role_to_subject_in_scope(subject: SubjectData, role: RoleData, scope:
|
|
|
210
214
|
creating an ExtendedCasbinRule for auditing purposes. It also sends a ROLE_ASSIGNMENT_CREATED event
|
|
211
215
|
after the transaction commits.
|
|
212
216
|
|
|
217
|
+
A custom role must exist and not be removed (ADR 0035). It is checked and assigned under the
|
|
218
|
+
policy write lock, which removing a custom role also holds, so an assignment cannot slip in
|
|
219
|
+
while the role is being removed.
|
|
220
|
+
|
|
213
221
|
Args:
|
|
214
222
|
subject: The ID of the subject.
|
|
215
223
|
role: The role to assign.
|
|
@@ -217,7 +225,25 @@ def assign_role_to_subject_in_scope(subject: SubjectData, role: RoleData, scope:
|
|
|
217
225
|
|
|
218
226
|
Returns:
|
|
219
227
|
bool: True if the role was assigned successfully, False otherwise.
|
|
228
|
+
|
|
229
|
+
Raises:
|
|
230
|
+
CustomRoleNotFoundError: If the role is a custom role that does not exist or was removed.
|
|
220
231
|
"""
|
|
232
|
+
if not role.external_key.startswith(CUSTOM_ROLE_ID_PREFIX):
|
|
233
|
+
return _add_role_assignment(subject, role, scope)
|
|
234
|
+
with policy_write_lock():
|
|
235
|
+
_ensure_active_custom_role(role)
|
|
236
|
+
return _add_role_assignment(subject, role, scope)
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
def _ensure_active_custom_role(role: RoleData) -> None:
|
|
240
|
+
"""Reject a custom role that has no definition or has been removed."""
|
|
241
|
+
if not AuthzRoleDefinition.objects.user_defined().active().filter(role_id=role.external_key).exists():
|
|
242
|
+
raise CustomRoleNotFoundError(f"There is no custom role {role.external_key!r}.")
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def _add_role_assignment(subject: SubjectData, role: RoleData, scope: ScopeData) -> bool:
|
|
246
|
+
"""Add the grouping policy and its ExtendedCasbinRule, and send ROLE_ASSIGNMENT_CREATED on commit."""
|
|
221
247
|
enforcer = AuthzEnforcer.get_enforcer()
|
|
222
248
|
adapter = AuthzEnforcer.get_adapter()
|
|
223
249
|
|