Skip to content

Commit bbeec5d

Browse files
committed
feat: add PoC permission and role
1 parent d0a13a3 commit bbeec5d

5 files changed

Lines changed: 33 additions & 8 deletions

File tree

openedx_authz/constants/permissions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,12 @@
5353
action=ActionData(external_key=f"{CONTENT_LIBRARIES_NAMESPACE}.delete_library_collection"),
5454
effect="allow",
5555
)
56+
57+
# Course Permissions
58+
59+
COURSES_NAMESPACE = "courses"
60+
61+
MANAGE_ADVANCED_SETTINGS = PermissionData(
62+
action=ActionData(external_key=f"{COURSES_NAMESPACE}.manage_advanced_settings"),
63+
effect="allow",
64+
)

openedx_authz/constants/roles.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,13 @@
5656
LIBRARY_AUTHOR = RoleData(external_key="library_author", permissions=LIBRARY_AUTHOR_PERMISSIONS)
5757
LIBRARY_CONTRIBUTOR = RoleData(external_key="library_contributor", permissions=LIBRARY_CONTRIBUTOR_PERMISSIONS)
5858
LIBRARY_USER = RoleData(external_key="library_user", permissions=LIBRARY_USER_PERMISSIONS)
59+
60+
61+
# Course Roles and Permissions
62+
63+
64+
COURSE_STAFF_PERMISSIONS = [
65+
permissions.MANAGE_ADVANCED_SETTINGS,
66+
]
67+
68+
COURSE_STAFF = RoleData(external_key="course_staff", permissions=COURSE_STAFF_PERMISSIONS)

openedx_authz/engine/config/authz.policy

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,9 @@ g2, act^content_libraries.manage_library_team, act^content_libraries.view_librar
6868
g2, act^content_libraries.delete_library_collection, act^content_libraries.edit_library_collection
6969
g2, act^content_libraries.create_library_collection, act^content_libraries.edit_library_collection
7070
g2, act^content_libraries.edit_library_collection, act^content_libraries.view_library
71+
72+
73+
# Course Policies
74+
75+
# Course Staff Permissions
76+
p, role^course_staff, act^courses.manage_advanced_settings, course^*, allow

openedx_authz/tests/test_enforcer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ def test_multi_scope_filtering(self):
413413
org_count = len(global_enforcer.get_policy())
414414

415415
self.assertEqual(lib_count, expected_lib_count)
416-
self.assertEqual(course_count, 6)
416+
self.assertEqual(course_count, 7)
417417
self.assertEqual(org_count, 3)
418418

419419
global_enforcer.clear_policy()

openedx_authz/tests/test_engine_utils.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ def test_migrate_all_file_policies_to_database(self):
7676
7777
Expected Result:
7878
- All policies from the file are loaded into the database
79-
- The file contains 31 regular policies (p rules)
79+
- The file contains 32 regular policies (p rules)
8080
- Policy content matches expected file content
8181
"""
82-
expected_policy_count = 31
82+
expected_policy_count = 32
8383

8484
migrate_policy_between_enforcers(self.source_enforcer, self.target_enforcer)
8585
self.target_enforcer.load_policy()
@@ -216,7 +216,7 @@ def test_migrate_complete_file_contents(self):
216216

217217
self.assertEqual(
218218
len(self.target_enforcer.get_policy()),
219-
31,
219+
32,
220220
"Should have 31 regular policies from file",
221221
)
222222
self.assertEqual(
@@ -250,8 +250,8 @@ def test_migrate_partial_duplicates(self):
250250
target_policies = self.target_enforcer.get_policy()
251251
self.assertEqual(
252252
len(target_policies),
253-
31,
254-
"Should have 31 policies total, with no duplicates",
253+
32,
254+
"Should have 32 policies total, with no duplicates",
255255
)
256256

257257
duplicates = CasbinRule.objects.values("v0", "v1", "v2").annotate(total=Count("*")).filter(total__gt=1)
@@ -346,7 +346,7 @@ def test_migrate_preserves_existing_db_policies(self):
346346
migrate_policy_between_enforcers(self.source_enforcer, self.target_enforcer)
347347

348348
target_policies = self.target_enforcer.get_policy()
349-
self.assertEqual(len(target_policies), 32, "Should have 31 file policies + 1 custom policy")
349+
self.assertEqual(len(target_policies), 33, "Should have 32 file policies + 1 custom policy")
350350
self.assertIn(custom_policy, target_policies, "Custom database policy should be preserved")
351351

352352
def test_migrate_preserves_user_role_assignments_in_db(self):
@@ -382,4 +382,4 @@ def test_migrate_preserves_user_role_assignments_in_db(self):
382382
)
383383

384384
target_policies = self.target_enforcer.get_policy()
385-
self.assertEqual(len(target_policies), 31, "All 31 policies from file should be loaded")
385+
self.assertEqual(len(target_policies), 32, "All 32 policies from file should be loaded")

0 commit comments

Comments
 (0)