Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cms/djangoapps/contentstore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 18 additions & 8 deletions lms/djangoapps/course_blocks/transformers/user_partitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Loading