Skip to content

Commit 0d8b0f1

Browse files
committed
feat(poc): implement content restriction based on new user groups
1 parent 51bfd3f commit 0d8b0f1

3 files changed

Lines changed: 24 additions & 8 deletions

File tree

cms/djangoapps/contentstore/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,9 @@ def get_visibility_partition_info(xblock, course=None):
909909
team_user_partitions = get_user_partition_info(xblock, schemes=["team"], course=course)
910910
selectable_partitions += team_user_partitions
911911

912+
user_groups_partitions = get_user_partition_info(xblock, schemes=["user_group"], course=course)
913+
selectable_partitions += user_groups_partitions
914+
912915
course_key = xblock.scope_ids.usage_id.course_key
913916
is_library = isinstance(course_key, LibraryLocator)
914917
if not is_library and ContentTypeGatingConfig.current(course_key=course_key).studio_override_enabled:

lms/djangoapps/course_blocks/transformers/user_partitions.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,24 +250,34 @@ def _intersection(*sets):
250250

251251
def get_access_denying_partitions(self, user_groups):
252252
"""
253-
Arguments:
254-
dict[int: Group]: Given a user, a mapping from user
255-
partition IDs to the group to which the user belongs in
256-
each partition.
253+
Get the partitions that are denying access to the user.
254+
255+
Args:
256+
dict[int: Union[Group, list[Group]]]: Given a user, a mapping from
257+
user partition IDs to either a single Group or a list of Groups
258+
to which the user belongs in each partition.
257259
258260
Returns:
259261
list of ints: Which partition is denying access
260262
"""
261263
denied_access = []
262264
for partition_id, allowed_group_ids in self.get_allowed_groups().items():
263-
# If the user is not assigned to a group for this partition,
265+
# If the user is not assigned to any group for this partition,
264266
# return partition as one that would deny access.
265267
if partition_id not in user_groups:
266268
denied_access.append(partition_id)
269+
continue
270+
271+
user_partition_groups = user_groups[partition_id]
272+
# Convert single group to list for consistent handling
273+
if not isinstance(user_partition_groups, list):
274+
user_partition_groups = [user_partition_groups]
275+
276+
# Check if any of the user's groups in this partition are allowed
277+
has_allowed_group = any(group.id in allowed_group_ids for group in user_partition_groups)
267278

268-
# If the user does not belong to one of the allowed groups for this
269-
# partition, then return this partition as one that would deny access
270-
elif user_groups[partition_id].id not in allowed_group_ids:
279+
# If none of the user's groups are allowed, deny access
280+
if not has_allowed_group:
271281
denied_access.append(partition_id)
272282

273283
return denied_access

openedx/core/djangoapps/content/learning_sequences/api/outlines.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
from openedx.core.djangoapps.content.learning_sequences.api.processors.team_partition_groups \
2020
import TeamPartitionGroupsOutlineProcessor
2121

22+
from openedx_user_groups.processors.user_group_partition_groups import UserGroupPartitionGroupsOutlineProcessor
23+
2224
from ..data import (
2325
ContentErrorData,
2426
CourseLearningSequenceData,
@@ -333,6 +335,7 @@ def _get_user_course_outline_and_processors(course_key: CourseKey, # lint-amnes
333335
('enrollment_track_partitions', EnrollmentTrackPartitionGroupsOutlineProcessor),
334336
('cohorts_partitions', CohortPartitionGroupsOutlineProcessor),
335337
('teams_partitions', TeamPartitionGroupsOutlineProcessor),
338+
('user_groups_partitions', UserGroupPartitionGroupsOutlineProcessor),
336339
]
337340

338341
# Run each OutlineProcessor in order to figure out what items we have to

0 commit comments

Comments
 (0)