openedx-authz 4.4.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.
Files changed (329) hide show
  1. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/CHANGELOG.rst +22 -0
  2. {openedx_authz-4.4.0/src/openedx_authz.egg-info → openedx_authz-4.6.0}/PKG-INFO +1 -1
  3. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/references/authorization-schema.rst +2 -1
  4. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/api/__init__.py +2 -0
  5. openedx_authz-4.6.0/src/openedx_authz/api/custom_roles.py +331 -0
  6. openedx_authz-4.6.0/src/openedx_authz/api/exceptions.py +52 -0
  7. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/api/roles.py +26 -0
  8. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/constants/__init__.py +6 -1
  9. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/policy.py +62 -1
  10. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/renderer.py +108 -64
  11. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/pipeline.py +6 -2
  12. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/validation.py +20 -1
  13. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/management/commands/load_authz_schema.py +79 -11
  14. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/models/engine.py +3 -3
  15. openedx_authz-4.6.0/src/openedx_authz/tests/api/test_custom_roles.py +662 -0
  16. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_apply.py +189 -10
  17. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_load_authz_schema_command.py +66 -2
  18. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_pipeline.py +17 -5
  19. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_validation.py +35 -0
  20. {openedx_authz-4.4.0 → openedx_authz-4.6.0/src/openedx_authz.egg-info}/PKG-INFO +1 -1
  21. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz.egg-info/SOURCES.txt +3 -0
  22. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz.egg-info/scm_file_list.json +3 -0
  23. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/.annotation_safe_list.yml +0 -0
  24. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/.editorconfig +0 -0
  25. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
  26. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/.github/dependabot.yml +0 -0
  27. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/.github/workflows/add-depr-ticket-to-depr-board.yml +0 -0
  28. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/.github/workflows/add-remove-label-on-comment.yml +0 -0
  29. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/.github/workflows/ci.yml +0 -0
  30. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/.github/workflows/commitlint.yml +0 -0
  31. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/.github/workflows/release.yml +0 -0
  32. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/.github/workflows/self-assign-issue.yml +0 -0
  33. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/.github/workflows/upgrade-python-requirements.yml +0 -0
  34. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/.gitignore +0 -0
  35. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/.pii_annotations.yml +0 -0
  36. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/.readthedocs.yaml +0 -0
  37. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/LICENSE +0 -0
  38. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/MANIFEST.in +0 -0
  39. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/Makefile +0 -0
  40. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/README.rst +0 -0
  41. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/catalog-info.yaml +0 -0
  42. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/codecov.yml +0 -0
  43. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/Makefile +0 -0
  44. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/_images/architecture-overview.png +0 -0
  45. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/_static/theme_overrides.css +0 -0
  46. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/changelog.rst +0 -0
  47. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/concepts/core_roles_and_permissions/content_library_roles.rst +0 -0
  48. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/concepts/core_roles_and_permissions/course_roles.rst +0 -0
  49. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/concepts/core_roles_and_permissions/index.rst +0 -0
  50. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/concepts/index.rst +0 -0
  51. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/conf.py +0 -0
  52. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0001-purpose-of-this-repo.rst +0 -0
  53. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0002-authorization-model-foundation.rst +0 -0
  54. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0003-jwt-usage.rst +0 -0
  55. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0004-technology-selection.rst +0 -0
  56. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0005-architecture-and-data-modeling.rst +0 -0
  57. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0007-enforcement-mechanisms-mfe.rst +0 -0
  58. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0008-compatibility-scheme.rst +0 -0
  59. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0009-authz-for-course-authoring.rst +0 -0
  60. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0010-course-authoring-flag.rst +0 -0
  61. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0011-course-authoring-migration-process.rst +0 -0
  62. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0012-auditability.rst +0 -0
  63. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0012-glob-support-for-role-assignments.rst +0 -0
  64. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0013-course-authoring-automatic-migration.rst +0 -0
  65. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0014-bulk-assignment-queries-without-casbin-enforce.rst +0 -0
  66. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0015-expose-course-authoring-waffle-flag-state-via-rest-api.rst +0 -0
  67. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0016-static-and-dynamic-roles.rst +0 -0
  68. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0017-static-authorization-schema.rst +0 -0
  69. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0018-authorization-schema-lifecycle.rst +0 -0
  70. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0019-authorization-schema-discovery.rst +0 -0
  71. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0020-authorization-schema-internationalization.rst +0 -0
  72. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0021-authorization-definition-api.rst +0 -0
  73. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0022-defer-authorization-implications.rst +0 -0
  74. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0023-extend-static-roles.rst +0 -0
  75. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0024-api-contract-for-user-grouped-role-assignments.rst +0 -0
  76. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0025-authorization-schema-source-tracking.rst +0 -0
  77. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0026-rest-api-domain-ownership-boundary.rst +0 -0
  78. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0027-cross-domain-filtering-via-openedx-filters.rst +0 -0
  79. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0028-api-contract-for-role-catalog.rst +0 -0
  80. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0029-paragon-icon-list-maintenance.rst +0 -0
  81. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0030-tutor-implementation-authz-schema-discovery.rst +0 -0
  82. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0031-priority-applies-to-role-extensions-only.rst +0 -0
  83. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0032-applets-for-built-in-authorization-capabilities.rst +0 -0
  84. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0033-shared-applet-for-course-team-roles.rst +0 -0
  85. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0034-permission-dependencies-in-authorization-schema.rst +0 -0
  86. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0035-custom-role-persistence.rst +0 -0
  87. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0036-api-contract-for-custom-roles.rst +0 -0
  88. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0037-custom-role-audit-trail.rst +0 -0
  89. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/0038-hidden-permission-categories-and-permissions.rst +0 -0
  90. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions/README.rst +0 -0
  91. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/decisions.rst +0 -0
  92. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/getting_started.rst +0 -0
  93. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/how-tos/index.rst +0 -0
  94. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/how-tos/use-built-in-constants.rst +0 -0
  95. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/index.rst +0 -0
  96. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/internationalization.rst +0 -0
  97. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/make.bat +0 -0
  98. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/quickstarts/index.rst +0 -0
  99. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/readme.rst +0 -0
  100. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/references/authorization-schema-json.rst +0 -0
  101. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/references/built-in-constants.rst +0 -0
  102. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/references/compiled-schema.rst +0 -0
  103. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/references/compiled-schema.yaml +0 -0
  104. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/references/index.rst +0 -0
  105. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/docs/testing.rst +0 -0
  106. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/manage.py +0 -0
  107. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/pylintrc +0 -0
  108. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/pylintrc_tweaks +0 -0
  109. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/pyproject.toml +0 -0
  110. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/ruff.toml +0 -0
  111. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/scripts/generate_compiled_schema.py +0 -0
  112. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/scripts/generate_paragon_icons.py +0 -0
  113. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/setup.cfg +0 -0
  114. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/__init__.py +0 -0
  115. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/admin.py +0 -0
  116. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/api/catalog.py +0 -0
  117. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/api/data.py +0 -0
  118. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/api/permissions.py +0 -0
  119. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/api/users.py +0 -0
  120. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/api/utils.py +0 -0
  121. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/__init__.py +0 -0
  122. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/content_libraries/README.rst +0 -0
  123. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/content_libraries/__init__.py +0 -0
  124. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/content_libraries/constants.py +0 -0
  125. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/content_libraries/schema/permissions.yaml +0 -0
  126. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/content_libraries/schema/roles.yaml +0 -0
  127. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/course_authoring/README.rst +0 -0
  128. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/course_authoring/__init__.py +0 -0
  129. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/course_authoring/constants.py +0 -0
  130. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/course_authoring/schema/permissions.yaml +0 -0
  131. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/course_authoring/schema/role_extensions.yaml +0 -0
  132. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/course_team_roles/README.rst +0 -0
  133. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/course_team_roles/__init__.py +0 -0
  134. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/course_team_roles/constants.py +0 -0
  135. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/course_team_roles/schema/legacy_permissions.yaml +0 -0
  136. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/course_team_roles/schema/roles.yaml +0 -0
  137. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/enrollments/README.rst +0 -0
  138. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/enrollments/__init__.py +0 -0
  139. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/enrollments/constants.py +0 -0
  140. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/enrollments/schema/permissions.yaml +0 -0
  141. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/enrollments/schema/role_extensions.yaml +0 -0
  142. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/learner_administration/README.rst +0 -0
  143. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/learner_administration/__init__.py +0 -0
  144. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/learner_administration/constants.py +0 -0
  145. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/learner_administration/schema/permissions.yaml +0 -0
  146. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/learner_administration/schema/role_extensions.yaml +0 -0
  147. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/learner_grading/README.rst +0 -0
  148. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/learner_grading/__init__.py +0 -0
  149. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/learner_grading/constants.py +0 -0
  150. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/learner_grading/schema/permissions.yaml +0 -0
  151. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/applets/learner_grading/schema/role_extensions.yaml +0 -0
  152. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/apps.py +0 -0
  153. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/authz/__init__.py +0 -0
  154. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/conf/locale/config.yaml +0 -0
  155. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/constants/permissions.py +0 -0
  156. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/constants/roles.py +0 -0
  157. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/constants/schema.py +0 -0
  158. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/data.py +0 -0
  159. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/__init__.py +0 -0
  160. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/adapter.py +0 -0
  161. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/apps.py +0 -0
  162. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/config/model.conf +0 -0
  163. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/enforcer.py +0 -0
  164. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/filter.py +0 -0
  165. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/matcher.py +0 -0
  166. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/__init__.py +0 -0
  167. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/authz-schema-v1.json +0 -0
  168. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/compilation.py +0 -0
  169. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/discovery.py +0 -0
  170. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/exceptions.py +0 -0
  171. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/issues.py +0 -0
  172. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/loading.py +0 -0
  173. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/paragon_icons.py +0 -0
  174. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/parsing.py +0 -0
  175. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/snapshot.py +0 -0
  176. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/syntax.py +0 -0
  177. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/translation.py +0 -0
  178. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/types/__init__.py +0 -0
  179. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/types/compilation.py +0 -0
  180. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/types/definitions.py +0 -0
  181. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/schema/types/loading.py +0 -0
  182. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/engine/utils.py +0 -0
  183. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/filters.py +0 -0
  184. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/handlers.py +0 -0
  185. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/management/__init__.py +0 -0
  186. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/management/commands/__init__.py +0 -0
  187. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/management/commands/authz_migrate_course_authoring.py +0 -0
  188. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/management/commands/authz_rollback_course_authoring.py +0 -0
  189. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/management/commands/enforcement.py +0 -0
  190. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/management/commands/extract_schema_translations.py +0 -0
  191. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/management/commands/load_policies.py +0 -0
  192. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/migrations/0001_add_casbin_dependency.py +0 -0
  193. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/migrations/0002_initial.py +0 -0
  194. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/migrations/0003_usersubject.py +0 -0
  195. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/migrations/0004_contentlibraryscope.py +0 -0
  196. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/migrations/0005_policycachecontrol.py +0 -0
  197. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/migrations/0006_migrate_legacy_permissions.py +0 -0
  198. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/migrations/0007_coursescope.py +0 -0
  199. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/migrations/0008_authzcourseauthoringmigrationrun.py +0 -0
  200. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/migrations/0009_roleassignmentaudit.py +0 -0
  201. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/migrations/0010_scope_external_key.py +0 -0
  202. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/migrations/0011_authz_schema_definitions.py +0 -0
  203. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/migrations/0012_move_builtin_schema_sources_to_applets.py +0 -0
  204. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/migrations/0013_add_hidden_to_categories_and_permissions.py +0 -0
  205. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/migrations/0014_add_custom_role_fields.py +0 -0
  206. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/migrations/__init__.py +0 -0
  207. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/models/__init__.py +0 -0
  208. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/models/authz_migration.py +0 -0
  209. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/models/base.py +0 -0
  210. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/models/core.py +0 -0
  211. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/models/schema.py +0 -0
  212. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/models/scopes.py +0 -0
  213. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/models/subjects.py +0 -0
  214. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/__init__.py +0 -0
  215. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/data.py +0 -0
  216. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/decorators.py +0 -0
  217. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/urls.py +0 -0
  218. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/utils.py +0 -0
  219. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/v1/__init__.py +0 -0
  220. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/v1/admin_console/__init__.py +0 -0
  221. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/v1/admin_console/filters.py +0 -0
  222. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/v1/admin_console/serializers.py +0 -0
  223. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/v1/admin_console/views.py +0 -0
  224. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/v1/course_authoring/__init__.py +0 -0
  225. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/v1/course_authoring/pipeline.py +0 -0
  226. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/v1/course_authoring/views.py +0 -0
  227. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/v1/fields.py +0 -0
  228. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/v1/paginators.py +0 -0
  229. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/v1/permissions.py +0 -0
  230. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/v1/serializers.py +0 -0
  231. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/v1/urls.py +0 -0
  232. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/rest_api/v1/views.py +0 -0
  233. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/settings/__init__.py +0 -0
  234. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/settings/common.py +0 -0
  235. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/settings/production.py +0 -0
  236. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/settings/test.py +0 -0
  237. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/templates/openedx_authz/base.html +0 -0
  238. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/__init__.py +0 -0
  239. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/api/__init__.py +0 -0
  240. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/api/test_catalog.py +0 -0
  241. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/api/test_data.py +0 -0
  242. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/api/test_roles.py +0 -0
  243. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/api/test_users.py +0 -0
  244. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/applets/__init__.py +0 -0
  245. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/applets/test_builtin_definitions.py +0 -0
  246. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/applets/test_instructor_dashboard_permissions.py +0 -0
  247. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/authz/__init__.py +0 -0
  248. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/authz/test_resources.py +0 -0
  249. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/__init__.py +0 -0
  250. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/conftest.py +0 -0
  251. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/fixtures/schema_pipeline/invalid_compiled/categories.yaml +0 -0
  252. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/fixtures/schema_pipeline/invalid_compiled/extensions.yaml +0 -0
  253. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/fixtures/schema_pipeline/invalid_compiled/permissions.yaml +0 -0
  254. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/fixtures/schema_pipeline/invalid_compiled/roles.yaml +0 -0
  255. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/fixtures/schema_pipeline/invalid_parse/malformed.yaml +0 -0
  256. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/fixtures/schema_pipeline/invalid_semantics/unknown_category.yaml +0 -0
  257. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/fixtures/schema_pipeline/invalid_structure/items.yml +0 -0
  258. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/fixtures/schema_pipeline/invalid_structure/priority.yaml +0 -0
  259. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/fixtures/schema_pipeline/valid/categories.yaml +0 -0
  260. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/fixtures/schema_pipeline/valid/extensions.yaml +0 -0
  261. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/fixtures/schema_pipeline/valid/permissions.yml +0 -0
  262. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/fixtures/schema_pipeline/valid/roles.yaml +0 -0
  263. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/test_handlers.py +0 -0
  264. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/test_models.py +0 -0
  265. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/test_schema_apply.py +0 -0
  266. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/test_schema_pipeline.py +0 -0
  267. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/integration/test_views.py +0 -0
  268. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/rest_api/__init__.py +0 -0
  269. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/rest_api/admin_console/__init__.py +0 -0
  270. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/rest_api/admin_console/test_filters.py +0 -0
  271. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/rest_api/admin_console/test_views.py +0 -0
  272. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/rest_api/course_authoring/__init__.py +0 -0
  273. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/rest_api/course_authoring/test_pipeline.py +0 -0
  274. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/rest_api/course_authoring/test_views.py +0 -0
  275. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/rest_api/mixins.py +0 -0
  276. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/rest_api/test_permissions.py +0 -0
  277. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/rest_api/test_utils.py +0 -0
  278. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/rest_api/test_views.py +0 -0
  279. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/role_permissions.py +0 -0
  280. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/__init__.py +0 -0
  281. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/factories.py +0 -0
  282. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_compilation.py +0 -0
  283. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_discovery.py +0 -0
  284. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_json_schema.py +0 -0
  285. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_loading.py +0 -0
  286. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_parsing.py +0 -0
  287. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_renderer.py +0 -0
  288. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_schema_models.py +0 -0
  289. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_snapshot.py +0 -0
  290. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_source_storage.py +0 -0
  291. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_syntax.py +0 -0
  292. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_translation.py +0 -0
  293. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/schema/test_types.py +0 -0
  294. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/stubs/__init__.py +0 -0
  295. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/stubs/apps.py +0 -0
  296. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/stubs/migrations/0001_initial.py +0 -0
  297. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/stubs/migrations/0002_learningpackage_contentlibrary_learning_package.py +0 -0
  298. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/stubs/migrations/0002_userprofile.py +0 -0
  299. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/stubs/models.py +0 -0
  300. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/test_commands.py +0 -0
  301. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/test_enforcement.py +0 -0
  302. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/test_enforcer.py +0 -0
  303. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/test_engine_utils.py +0 -0
  304. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/test_filter.py +0 -0
  305. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/test_handlers.py +0 -0
  306. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/test_imports.py +0 -0
  307. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/test_migrations.py +0 -0
  308. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/test_models.py +0 -0
  309. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/test_policy.py +0 -0
  310. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/tests/test_utils.py +0 -0
  311. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/urls.py +0 -0
  312. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz/utils.py +0 -0
  313. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz.egg-info/dependency_links.txt +0 -0
  314. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz.egg-info/entry_points.txt +0 -0
  315. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz.egg-info/requires.txt +0 -0
  316. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/src/openedx_authz.egg-info/top_level.txt +0 -0
  317. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/tox.ini +0 -0
  318. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/tutor/tutor-contrib-authz/.gitignore +0 -0
  319. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/tutor/tutor-contrib-authz/LICENSE.txt +0 -0
  320. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/tutor/tutor-contrib-authz/MANIFEST.in +0 -0
  321. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/tutor/tutor-contrib-authz/Makefile +0 -0
  322. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/tutor/tutor-contrib-authz/README.rst +0 -0
  323. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/tutor/tutor-contrib-authz/pyproject.toml +0 -0
  324. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/tutor/tutor-contrib-authz/tutor_authz/__about__.py +0 -0
  325. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/tutor/tutor-contrib-authz/tutor_authz/__init__.py +0 -0
  326. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/tutor/tutor-contrib-authz/tutor_authz/patches/openedx-common-settings +0 -0
  327. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/tutor/tutor-contrib-authz/tutor_authz/plugin.py +0 -0
  328. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/tutor/tutor-contrib-authz/tutor_authz/templates/apps/openedx/config/authz-schema.yml +0 -0
  329. {openedx_authz-4.4.0 → openedx_authz-4.6.0}/uv.lock +0 -0
@@ -21,6 +21,28 @@ Added
21
21
  ``0014_add_custom_role_fields``: a ``definition_kind`` (``static`` or ``user_defined``) and a
22
22
  ``removed_at`` time. Existing roles stay ``static``. The role catalog now returns the stored
23
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.
24
46
  * Added an optional ``hidden`` flag to permission categories and permissions in the authorization
25
47
  schema. Hidden permissions, and the permissions of hidden categories, are left out of the
26
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.4.0
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
@@ -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 *
@@ -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()
@@ -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
 
@@ -3,6 +3,11 @@ Defined here rather than in api.data so that models and other modules at the
3
3
  bottom of the import chain can use them without creating circular imports.
4
4
  """
5
5
 
6
- from openedx_authz.constants.schema import CUSTOM_ROLE_ID_PREFIX, DefinitionKind, SchemaOriginKind
6
+ from openedx_authz.constants.schema import (
7
+ CUSTOM_ROLE_ID_MAX_LENGTH,
8
+ CUSTOM_ROLE_ID_PREFIX,
9
+ DefinitionKind,
10
+ SchemaOriginKind,
11
+ )
7
12
 
8
13
  AUTHZ_POLICY_ATTRIBUTES_SEPARATOR = "^"
@@ -29,9 +29,13 @@ semantics remain the caller's responsibility.
29
29
 
30
30
  from __future__ import annotations
31
31
 
32
+ from collections.abc import Iterator
33
+ from contextlib import contextmanager
32
34
  from dataclasses import dataclass
33
35
  from typing import ClassVar
34
36
 
37
+ from django.db import transaction
38
+
35
39
  from openedx_authz.data import (
36
40
  ACTION_NAMESPACE,
37
41
  EFFECT_ALLOW,
@@ -43,8 +47,9 @@ from openedx_authz.data import (
43
47
  )
44
48
  from openedx_authz.data import AUTHZ_POLICY_ATTRIBUTES_SEPARATOR as SEP
45
49
  from openedx_authz.engine.enforcer import AuthzEnforcer
50
+ from openedx_authz.models.engine import PolicyCacheControl
46
51
 
47
- __all__ = ["PolicyRow", "GroupingRow", "PolicyStore"]
52
+ __all__ = ["PolicyRow", "GroupingRow", "PolicyStore", "policy_write_lock", "serialized_policy_update"]
48
53
 
49
54
 
50
55
  @dataclass(frozen=True)
@@ -211,3 +216,59 @@ class PolicyStore:
211
216
  contract and lets injected fakes model the reload.
212
217
  """
213
218
  self._resolved_enforcer.load_policy()
219
+
220
+
221
+ @contextmanager
222
+ def policy_write_lock() -> Iterator[None]:
223
+ """Open a transaction that holds the policy write lock (ADR 0018 §8, ADR 0035 §3).
224
+
225
+ Schema applies, custom role changes and assignments of custom roles all take it, so they
226
+ exclude each other. On entry it, in order:
227
+
228
+ 1. ``ensure_exists`` the lock row **before** the transaction opens — a
229
+ creating ``SELECT``/INSERT inside the transaction would be its first
230
+ read and, under InnoDB Repeatable Read, pin the consistent-read
231
+ snapshot before the lock is taken, leaving every post-lock read stale.
232
+ 2. opens ``transaction.atomic()``;
233
+ 3. takes the exclusive row lock as the transaction's first read, so a
234
+ second runner blocks until the first commits and this runner's reads
235
+ see the committed state.
236
+
237
+ The lock (a row lock) releases automatically when the transaction commits,
238
+ rolls back, or the connection dies, so no stale lock can outlive a crashed
239
+ writer.
240
+
241
+ Two accepted limitations, deferred (ADR 0018 §8):
242
+
243
+ * ``PolicyCacheControl`` (the lock) and the ``transaction.atomic()``
244
+ default to the ``default`` database, while the Casbin ``p`` rows live
245
+ in ``CASBIN_DB_ALIAS``. Serialization is only meaningful while those
246
+ coincide, which matches the engine's existing single-database policy
247
+ storage assumption. If ``CASBIN_DB_ALIAS`` is ever pointed at a
248
+ separate database, the lock must move there too.
249
+ * The lock wait is unbounded and silent: a second writer blocks with no
250
+ ``nowait``/timeout and no log line, so a blocked writer looks like a slow
251
+ one. Acceptable because schema applies run at deploy time and custom role
252
+ changes and assignments are short administrator actions.
253
+ """
254
+ PolicyCacheControl.ensure_exists()
255
+ with transaction.atomic():
256
+ PolicyCacheControl.lock()
257
+ yield
258
+
259
+
260
+ @contextmanager
261
+ def serialized_policy_update(policy_store: PolicyStore) -> Iterator[None]:
262
+ """Open the critical section for a writer that reads the in-memory policy before writing.
263
+
264
+ It takes :func:`policy_write_lock` and then reloads the enforcer, because the lock only makes
265
+ the *database* current — the version-gated in-memory model would otherwise still hold a prior
266
+ run's rows, so a ``get_policy`` read could be stale even with the lock held.
267
+
268
+ The caller does its read-diff-write inside the ``with`` block. Keeping the lock, reload, and
269
+ the cache-version bump the caller performs all within this one transaction is what makes the
270
+ critical section cohesive and leaves no committed-but-unversioned reader window.
271
+ """
272
+ with policy_write_lock():
273
+ policy_store.reload()
274
+ yield