diff --git a/cms/djangoapps/contentstore/utils.py b/cms/djangoapps/contentstore/utils.py index 3ca1d20bf564..2cdecd6b17c3 100644 --- a/cms/djangoapps/contentstore/utils.py +++ b/cms/djangoapps/contentstore/utils.py @@ -909,6 +909,9 @@ def get_visibility_partition_info(xblock, course=None): team_user_partitions = get_user_partition_info(xblock, schemes=["team"], course=course) selectable_partitions += team_user_partitions + user_groups_partitions = get_user_partition_info(xblock, schemes=["user_group"], course=course) + selectable_partitions += user_groups_partitions + course_key = xblock.scope_ids.usage_id.course_key is_library = isinstance(course_key, LibraryLocator) if not is_library and ContentTypeGatingConfig.current(course_key=course_key).studio_override_enabled: diff --git a/lms/djangoapps/course_blocks/transformers/user_partitions.py b/lms/djangoapps/course_blocks/transformers/user_partitions.py index 087c6e5fc7e7..914dbe6b2177 100644 --- a/lms/djangoapps/course_blocks/transformers/user_partitions.py +++ b/lms/djangoapps/course_blocks/transformers/user_partitions.py @@ -250,24 +250,34 @@ def _intersection(*sets): def get_access_denying_partitions(self, user_groups): """ - Arguments: - dict[int: Group]: Given a user, a mapping from user - partition IDs to the group to which the user belongs in - each partition. + Get the partitions that are denying access to the user. + + Args: + dict[int: Union[Group, list[Group]]]: Given a user, a mapping from + user partition IDs to either a single Group or a list of Groups + to which the user belongs in each partition. Returns: list of ints: Which partition is denying access """ denied_access = [] for partition_id, allowed_group_ids in self.get_allowed_groups().items(): - # If the user is not assigned to a group for this partition, + # If the user is not assigned to any group for this partition, # return partition as one that would deny access. if partition_id not in user_groups: denied_access.append(partition_id) + continue + + user_partition_groups = user_groups[partition_id] + # Convert single group to list for consistent handling + if not isinstance(user_partition_groups, list): + user_partition_groups = [user_partition_groups] + + # Check if any of the user's groups in this partition are allowed + has_allowed_group = any(group.id in allowed_group_ids for group in user_partition_groups) - # If the user does not belong to one of the allowed groups for this - # partition, then return this partition as one that would deny access - elif user_groups[partition_id].id not in allowed_group_ids: + # If none of the user's groups are allowed, deny access + if not has_allowed_group: denied_access.append(partition_id) return denied_access diff --git a/openedx/core/djangoapps/content/learning_sequences/api/outlines.py b/openedx/core/djangoapps/content/learning_sequences/api/outlines.py index cd2b12d03f1c..15e2b10ccb01 100644 --- a/openedx/core/djangoapps/content/learning_sequences/api/outlines.py +++ b/openedx/core/djangoapps/content/learning_sequences/api/outlines.py @@ -19,6 +19,8 @@ from openedx.core.djangoapps.content.learning_sequences.api.processors.team_partition_groups \ import TeamPartitionGroupsOutlineProcessor +from openedx_user_groups.processors.user_group_partition_groups import UserGroupPartitionGroupsOutlineProcessor + from ..data import ( ContentErrorData, CourseLearningSequenceData, @@ -333,6 +335,7 @@ def _get_user_course_outline_and_processors(course_key: CourseKey, # lint-amnes ('enrollment_track_partitions', EnrollmentTrackPartitionGroupsOutlineProcessor), ('cohorts_partitions', CohortPartitionGroupsOutlineProcessor), ('teams_partitions', TeamPartitionGroupsOutlineProcessor), + ('user_groups_partitions', UserGroupPartitionGroupsOutlineProcessor), ] # Run each OutlineProcessor in order to figure out what items we have to