|
11 | 11 | from django.test import TestCase |
12 | 12 |
|
13 | 13 | from openedx_authz.api import * |
14 | | -from openedx_authz.api.data import ( |
15 | | - ActionData, |
16 | | - PermissionData, |
17 | | - RoleData, |
18 | | - ScopeData, |
19 | | - SubjectData, |
20 | | -) |
| 14 | +from openedx_authz.api.data import ActionData, PermissionData, RoleData, ScopeData, SubjectData |
21 | 15 | from openedx_authz.engine.enforcer import enforcer as global_enforcer |
22 | 16 | from openedx_authz.engine.utils import migrate_policy_from_file_to_db |
23 | 17 |
|
@@ -117,6 +111,11 @@ def setUpClass(cls): |
117 | 111 | "role_name": "library_collaborator", |
118 | 112 | "scope_name": "math_advanced", |
119 | 113 | }, |
| 114 | + { |
| 115 | + "subject_name": "Heidi", |
| 116 | + "role_name": "library_collaborator", |
| 117 | + "scope_name": "math_advanced", |
| 118 | + }, |
120 | 119 | # Hierarchical scope_id assignments - different specificity levels |
121 | 120 | { |
122 | 121 | "subject_name": "Ivy", |
@@ -971,3 +970,173 @@ def test_unassign_role_from_subject_in_scope( |
971 | 970 | ) |
972 | 971 | role_names = {assignment.role.name for assignment in user_roles} |
973 | 972 | self.assertNotIn(role, role_names) |
| 973 | + |
| 974 | + @ddt_data( |
| 975 | + ( |
| 976 | + "math_101", |
| 977 | + [ |
| 978 | + RoleAssignmentData( |
| 979 | + subject=SubjectData(name="alice"), |
| 980 | + role=RoleData( |
| 981 | + name="library_admin", |
| 982 | + permissions=[ |
| 983 | + PermissionData( |
| 984 | + action=ActionData(name="delete_library"), effect="allow" |
| 985 | + ), |
| 986 | + PermissionData( |
| 987 | + action=ActionData(name="publish_library"), |
| 988 | + effect="allow", |
| 989 | + ), |
| 990 | + PermissionData( |
| 991 | + action=ActionData(name="manage_library_team"), |
| 992 | + effect="allow", |
| 993 | + ), |
| 994 | + PermissionData( |
| 995 | + action=ActionData(name="manage_library_tags"), |
| 996 | + effect="allow", |
| 997 | + ), |
| 998 | + PermissionData( |
| 999 | + action=ActionData(name="delete_library_content"), |
| 1000 | + effect="allow", |
| 1001 | + ), |
| 1002 | + PermissionData( |
| 1003 | + action=ActionData(name="publish_library_content"), |
| 1004 | + effect="allow", |
| 1005 | + ), |
| 1006 | + PermissionData( |
| 1007 | + action=ActionData(name="delete_library_collection"), |
| 1008 | + effect="allow", |
| 1009 | + ), |
| 1010 | + PermissionData( |
| 1011 | + action=ActionData(name="create_library"), effect="allow" |
| 1012 | + ), |
| 1013 | + PermissionData( |
| 1014 | + action=ActionData(name="create_library_collection"), |
| 1015 | + effect="allow", |
| 1016 | + ), |
| 1017 | + ], |
| 1018 | + ), |
| 1019 | + scope=ScopeData(name="math_101"), |
| 1020 | + ) |
| 1021 | + ], |
| 1022 | + ), |
| 1023 | + ( |
| 1024 | + "history_201", |
| 1025 | + [ |
| 1026 | + RoleAssignmentData( |
| 1027 | + subject=SubjectData(name="bob"), |
| 1028 | + role=RoleData( |
| 1029 | + name="library_author", |
| 1030 | + permissions=[ |
| 1031 | + PermissionData( |
| 1032 | + action=ActionData(name="delete_library_content"), |
| 1033 | + effect="allow", |
| 1034 | + ), |
| 1035 | + PermissionData( |
| 1036 | + action=ActionData(name="publish_library_content"), |
| 1037 | + effect="allow", |
| 1038 | + ), |
| 1039 | + PermissionData( |
| 1040 | + action=ActionData(name="edit_library"), effect="allow" |
| 1041 | + ), |
| 1042 | + PermissionData( |
| 1043 | + action=ActionData(name="manage_library_tags"), |
| 1044 | + effect="allow", |
| 1045 | + ), |
| 1046 | + PermissionData( |
| 1047 | + action=ActionData(name="create_library_collection"), |
| 1048 | + effect="allow", |
| 1049 | + ), |
| 1050 | + PermissionData( |
| 1051 | + action=ActionData(name="edit_library_collection"), |
| 1052 | + effect="allow", |
| 1053 | + ), |
| 1054 | + PermissionData( |
| 1055 | + action=ActionData(name="delete_library_collection"), |
| 1056 | + effect="allow", |
| 1057 | + ), |
| 1058 | + ], |
| 1059 | + ), |
| 1060 | + scope=ScopeData(name="history_201"), |
| 1061 | + ) |
| 1062 | + ], |
| 1063 | + ), |
| 1064 | + ( |
| 1065 | + "science_301", |
| 1066 | + [ |
| 1067 | + RoleAssignmentData( |
| 1068 | + subject=SubjectData(name="carol"), |
| 1069 | + role=RoleData( |
| 1070 | + name="library_collaborator", |
| 1071 | + permissions=[ |
| 1072 | + PermissionData( |
| 1073 | + action=ActionData(name="edit_library"), effect="allow" |
| 1074 | + ), |
| 1075 | + PermissionData( |
| 1076 | + action=ActionData(name="delete_library_content"), |
| 1077 | + effect="allow", |
| 1078 | + ), |
| 1079 | + PermissionData( |
| 1080 | + action=ActionData(name="manage_library_tags"), |
| 1081 | + effect="allow", |
| 1082 | + ), |
| 1083 | + PermissionData( |
| 1084 | + action=ActionData(name="create_library_collection"), |
| 1085 | + effect="allow", |
| 1086 | + ), |
| 1087 | + PermissionData( |
| 1088 | + action=ActionData(name="edit_library_collection"), |
| 1089 | + effect="allow", |
| 1090 | + ), |
| 1091 | + PermissionData( |
| 1092 | + action=ActionData(name="delete_library_collection"), |
| 1093 | + effect="allow", |
| 1094 | + ), |
| 1095 | + ], |
| 1096 | + ), |
| 1097 | + scope=ScopeData(name="science_301"), |
| 1098 | + ) |
| 1099 | + ], |
| 1100 | + ), |
| 1101 | + ( |
| 1102 | + "english_101", |
| 1103 | + [ |
| 1104 | + RoleAssignmentData( |
| 1105 | + subject=SubjectData(name="dave"), |
| 1106 | + role=RoleData( |
| 1107 | + name="library_user", |
| 1108 | + permissions=[ |
| 1109 | + PermissionData( |
| 1110 | + action=ActionData(name="view_library"), effect="allow" |
| 1111 | + ), |
| 1112 | + PermissionData( |
| 1113 | + action=ActionData(name="view_library_team"), |
| 1114 | + effect="allow", |
| 1115 | + ), |
| 1116 | + PermissionData( |
| 1117 | + action=ActionData(name="reuse_library_content"), |
| 1118 | + effect="allow", |
| 1119 | + ), |
| 1120 | + ], |
| 1121 | + ), |
| 1122 | + scope=ScopeData(name="english_101"), |
| 1123 | + ) |
| 1124 | + ], |
| 1125 | + ), |
| 1126 | + ("non_existent_scope", []), |
| 1127 | + ) |
| 1128 | + @unpack |
| 1129 | + def test_get_all_role_assignments_in_scope(self, scope_name, expected_assignments): |
| 1130 | + """Test retrieving all role assignments in a specific scope. |
| 1131 | +
|
| 1132 | + Expected result: |
| 1133 | + - All role assignments in the specified scope are correctly retrieved. |
| 1134 | + - Each assignment includes the subject, role, and scope information with permissions. |
| 1135 | + """ |
| 1136 | + role_assignments = get_all_subject_role_assignments_in_scope( |
| 1137 | + ScopeData(name=scope_name) |
| 1138 | + ) |
| 1139 | + |
| 1140 | + self.assertEqual(len(role_assignments), len(expected_assignments)) |
| 1141 | + for assignment in role_assignments: |
| 1142 | + self.assertIn(assignment, expected_assignments) |
0 commit comments