Skip to content

Commit 2776663

Browse files
committed
refactor: update content library permissions to use namespaced identifiers
1 parent c5ce1d1 commit 2776663

14 files changed

Lines changed: 238 additions & 161 deletions

File tree

docs/concepts/core_roles_and_permissions/content_library_roles.rst

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,46 +28,46 @@ The following permissions are associated with the content library roles:
2828
Library Permissions
2929
=======================
3030

31-
- **View the library** (``view_library``): Allows users to view the content library.
32-
- **Manage library tags** (``manage_library_tags``): Allows users to manage the tags associated with library items.
33-
- **Delete the library** (``delete_library``): Allows users to delete the entire content library.
31+
- **View the library** (``content_libraries.view_library``): Allows users to view the content library.
32+
- **Manage library tags** (``content_libraries.manage_library_tags``): Allows users to manage the tags associated with library items.
33+
- **Delete the library** (``content_libraries.delete_library``): Allows users to delete the entire content library.
3434

3535

3636
Library Content Permissions
3737
===============================
3838

39-
- **Edit library content** (``edit_library_content``): Allows users to edit existing content within the library.
40-
- **Publish library content** (``publish_library_content``): Allows users to publish content to or from the library.
41-
- **Reuse library content** (``reuse_library_content``): Allows users to reuse content from the library in other contexts.
39+
- **Edit library content** (``content_libraries.edit_library_content``): Allows users to edit existing content within the library.
40+
- **Publish library content** (``content_libraries.publish_library_content``): Allows users to publish content to or from the library.
41+
- **Reuse library content** (``content_libraries.reuse_library_content``): Allows users to reuse content from the library in other contexts.
4242

4343

4444
Library Team Permissions
4545
=============================
4646

47-
- **View the library team** (``view_library_team``): Allows users to view the list of users or roles associated with the library.
48-
- **Manage the library team** (``manage_library_team``): Allows users to add, remove, or change the roles of users in the library team.
47+
- **View the library team** (``content_libraries.view_library_team``): Allows users to view the list of users or roles associated with the library.
48+
- **Manage the library team** (``content_libraries.manage_library_team``): Allows users to add, remove, or change the roles of users in the library team.
4949

5050

5151
Library Collections Permissions
5252
===================================
5353

54-
- **Create library collections** (``create_library_collection``): Allows users to create new collections within the library.
55-
- **Edit library collections** (``edit_library_collection``): Allows users to modify existing collections within the library.
56-
- **Delete library collections** (``delete_library_collection``): Allows users to delete collections within the library.
54+
- **Create library collections** (``content_libraries.create_library_collection``): Allows users to create new collections within the library.
55+
- **Edit library collections** (``content_libraries.edit_library_collection``): Allows users to modify existing collections within the library.
56+
- **Delete library collections** (``content_libraries.delete_library_collection``): Allows users to delete collections within the library.
5757

5858
Permissions Inheritance
5959
========================
6060

61-
* **Managing library tags** (``manage_library_tags``) implies **editing library content** (``edit_library_content``).
62-
* **Deleting the library** (``delete_library``) implies **editing library content** (``edit_library_content``).
63-
* **Publishing library content** (``publish_library_content``) implies **editing library content** (``edit_library_content``).
64-
* **Editing library content** (``edit_library_content``) implies **viewing the library** (``view_library``).
65-
* **Reusing library content** (``reuse_library_content``) implies **viewing the library** (``view_library``).
66-
* **Publishing library content** (``publish_library_content``) implies **viewing the library** (``view_library``).
67-
* **Managing the library team** (``manage_library_team``) implies **viewing the library team** (``view_library_team``).
68-
* **Deleting a library collection** (``delete_library_collection``) implies **editing a library collection** (``edit_library_collection``).
69-
* **Creating a library collection** (``create_library_collection``) implies **editing a library collection** (``edit_library_collection``).
70-
* **Editing a library collection** (``edit_library_collection``) implies **viewing the library** (``view_library``).
61+
* **Managing library tags** (``content_libraries.manage_library_tags``) implies **editing library content** (``content_libraries.edit_library_content``).
62+
* **Deleting the library** (``content_libraries.delete_library``) implies **editing library content** (``content_libraries.edit_library_content``).
63+
* **Publishing library content** (``content_libraries.publish_library_content``) implies **editing library content** (``content_libraries.edit_library_content``).
64+
* **Editing library content** (``content_libraries.edit_library_content``) implies **viewing the library** (``content_libraries.view_library``).
65+
* **Reusing library content** (``content_libraries.reuse_library_content``) implies **viewing the library** (``content_libraries.view_library``).
66+
* **Publishing library content** (``content_libraries.publish_library_content``) implies **viewing the library** (``content_libraries.view_library``).
67+
* **Managing the library team** (``content_libraries.manage_library_team``) implies **viewing the library team** (``content_libraries.view_library_team``).
68+
* **Deleting a library collection** (``content_libraries.delete_library_collection``) implies **editing a library collection** (``content_libraries.edit_library_collection``).
69+
* **Creating a library collection** (``content_libraries.create_library_collection``) implies **editing a library collection** (``content_libraries.edit_library_collection``).
70+
* **Editing a library collection** (``content_libraries.edit_library_collection``) implies **viewing the library** (``content_libraries.view_library``).
7171

7272

7373
Roles and Permissions Summary Table
@@ -76,25 +76,29 @@ Roles and Permissions Summary Table
7676
.. table:: Matrix of Content Library Roles and Permissions
7777
:widths: auto
7878

79-
============================= ================= ================ ===================== ==============
80-
Permissions Library Admin Library Author Library Contributor Library User
81-
============================= ================= ================ ===================== ==============
79+
============================================= ================= ================ ===================== ==============
80+
Permissions Library Admin Library Author Library Contributor Library User
81+
============================================= ================= ================ ===================== ==============
8282
**Library**
83-
view_library ✅ ✅ ✅ ✅
84-
manage_library_tags ✅ ✅ ✅ ❌
85-
delete_library ✅ ❌ ❌ ❌
83+
--------------------------------------------- ----------------- ---------------- --------------------- --------------
84+
content_libraries.view_library ✅ ✅ ✅ ✅
85+
content_libraries.manage_library_tags ✅ ✅ ✅ ❌
86+
content_libraries.delete_library ✅ ❌ ❌ ❌
8687
**Content**
87-
edit_library_content ✅ ✅ ✅ ❌
88-
publish_library_content ✅ ✅ ❌ ❌
89-
reuse_library_content ✅ ✅ ✅ ✅
88+
--------------------------------------------- ----------------- ---------------- --------------------- --------------
89+
content_libraries.edit_library_content ✅ ✅ ✅ ❌
90+
content_libraries.publish_library_content ✅ ✅ ❌ ❌
91+
content_libraries.reuse_library_content ✅ ✅ ✅ ✅
9092
**Team**
91-
view_library_team ✅ ✅ ✅ ✅
92-
manage_library_team ✅ ❌ ❌ ❌
93+
--------------------------------------------- ----------------- ---------------- --------------------- --------------
94+
content_libraries.view_library_team ✅ ✅ ✅ ✅
95+
content_libraries.manage_library_team ✅ ❌ ❌ ❌
9396
**Collections**
94-
create_library_collection ✅ ✅ ✅ ❌
95-
edit_library_collection ✅ ✅ ✅ ❌
96-
delete_library_collection ✅ ✅ ✅ ❌
97-
============================= ================= ================ ===================== ==============
97+
--------------------------------------------- ----------------- ---------------- --------------------- --------------
98+
content_libraries.create_library_collection ✅ ✅ ✅ ❌
99+
content_libraries.edit_library_collection ✅ ✅ ✅ ❌
100+
content_libraries.delete_library_collection ✅ ✅ ✅ ❌
101+
============================================= ================= ================ ===================== ==============
98102

99103

100104
**Maintenance chart**

openedx_authz/api/data.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -600,29 +600,29 @@ class ActionData(AuthZData):
600600
601601
Attributes:
602602
NAMESPACE: 'act' for actions.
603-
external_key: The action identifier (e.g., 'read', 'write', 'delete_library').
604-
namespaced_key: The action identifier with namespace (e.g., 'act^read', 'act^delete_library').
605-
name: Property that returns a human-readable action name (e.g., 'Read', 'Delete Library').
603+
external_key: The action identifier (e.g., 'content_libraries.view_library').
604+
namespaced_key: The action identifier with namespace (e.g., 'act^content_libraries.view_library').
605+
name: Property that returns a human-readable action name (e.g., 'Content Libraries.View Library').
606606
607607
Examples:
608-
>>> action = ActionData(external_key='delete_library')
608+
>>> action = ActionData(external_key='content_libraries.delete_library')
609609
>>> action.namespaced_key
610-
'act^delete_library'
610+
'act^content_libraries.delete_library'
611611
>>> action.name
612-
'Delete Library'
612+
'Content Libraries.Delete Library'
613613
"""
614614

615615
NAMESPACE: ClassVar[str] = "act"
616616

617617
@property
618618
def name(self) -> str:
619-
"""The human-readable name of the action (e.g., 'Delete Library', 'Edit Content').
619+
"""The human-readable name of the action (e.g., 'Content Libraries.Delete Library').
620620
621621
This property transforms the external_key into a human-readable display name
622622
by replacing underscores with spaces and capitalizing each word.
623623
624624
Returns:
625-
str: The human-readable action name (e.g., 'Delete Library').
625+
str: The human-readable action name (e.g., 'Content Libraries.Delete Library').
626626
"""
627627
return self.external_key.replace("_", " ").title()
628628

@@ -665,7 +665,7 @@ def identifier(self) -> str:
665665
"""Get the permission identifier.
666666
667667
Returns:
668-
str: The permission identifier (e.g., 'delete_library').
668+
str: The permission identifier (e.g., 'content_libraries.delete_library').
669669
"""
670670
return self.action.external_key
671671

@@ -753,7 +753,8 @@ def get_permission_identifiers(self) -> list[str]:
753753
"""Get the technical identifiers for all permissions in this role.
754754
755755
Returns:
756-
list[str]: Permission identifiers (e.g., ['delete_library', 'edit_content']).
756+
list[str]: Permission identifiers
757+
(e.g., ['content_libraries.delete_library', 'content_libraries.edit_library_content']).
757758
"""
758759
return [permission.identifier for permission in self.permissions]
759760

openedx_authz/constants/permissions.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,51 @@
55
from openedx_authz.api.data import ActionData, PermissionData
66

77
# Content Library Permissions
8+
9+
CONTENT_LIBRARIES_NAMESPACE = "content_libraries"
10+
811
VIEW_LIBRARY = PermissionData(
9-
action=ActionData(external_key="view_library"),
12+
action=ActionData(external_key=f"{CONTENT_LIBRARIES_NAMESPACE}.view_library"),
1013
effect="allow",
1114
)
1215
MANAGE_LIBRARY_TAGS = PermissionData(
13-
action=ActionData(external_key="manage_library_tags"),
16+
action=ActionData(external_key=f"{CONTENT_LIBRARIES_NAMESPACE}.manage_library_tags"),
1417
effect="allow",
1518
)
1619
DELETE_LIBRARY = PermissionData(
17-
action=ActionData(external_key="delete_library"),
20+
action=ActionData(external_key=f"{CONTENT_LIBRARIES_NAMESPACE}.delete_library"),
1821
effect="allow",
1922
)
2023
EDIT_LIBRARY_CONTENT = PermissionData(
21-
action=ActionData(external_key="edit_library_content"),
24+
action=ActionData(external_key=f"{CONTENT_LIBRARIES_NAMESPACE}.edit_library_content"),
2225
effect="allow",
2326
)
2427
PUBLISH_LIBRARY_CONTENT = PermissionData(
25-
action=ActionData(external_key="publish_library_content"),
28+
action=ActionData(external_key=f"{CONTENT_LIBRARIES_NAMESPACE}.publish_library_content"),
2629
effect="allow",
2730
)
2831
REUSE_LIBRARY_CONTENT = PermissionData(
29-
action=ActionData(external_key="reuse_library_content"),
32+
action=ActionData(external_key=f"{CONTENT_LIBRARIES_NAMESPACE}.reuse_library_content"),
3033
effect="allow",
3134
)
3235
VIEW_LIBRARY_TEAM = PermissionData(
33-
action=ActionData(external_key="view_library_team"),
36+
action=ActionData(external_key=f"{CONTENT_LIBRARIES_NAMESPACE}.view_library_team"),
3437
effect="allow",
3538
)
3639
MANAGE_LIBRARY_TEAM = PermissionData(
37-
action=ActionData(external_key="manage_library_team"),
40+
action=ActionData(external_key=f"{CONTENT_LIBRARIES_NAMESPACE}.manage_library_team"),
3841
effect="allow",
3942
)
4043

4144
CREATE_LIBRARY_COLLECTION = PermissionData(
42-
action=ActionData(external_key="create_library_collection"),
45+
action=ActionData(external_key=f"{CONTENT_LIBRARIES_NAMESPACE}.create_library_collection"),
4346
effect="allow",
4447
)
4548
EDIT_LIBRARY_COLLECTION = PermissionData(
46-
action=ActionData(external_key="edit_library_collection"),
49+
action=ActionData(external_key=f"{CONTENT_LIBRARIES_NAMESPACE}.edit_library_collection"),
4750
effect="allow",
4851
)
4952
DELETE_LIBRARY_COLLECTION = PermissionData(
50-
action=ActionData(external_key="delete_library_collection"),
53+
action=ActionData(external_key=f"{CONTENT_LIBRARIES_NAMESPACE}.delete_library_collection"),
5154
effect="allow",
5255
)

0 commit comments

Comments
 (0)