Move get_user_partition_groups to partition_services to call
from multiple contexts.
This commit is contained in:
@@ -41,6 +41,33 @@ def get_all_partitions_for_course(course, active_only=False):
|
||||
all_partitions = [partition for partition in all_partitions if partition.active]
|
||||
return all_partitions
|
||||
|
||||
def get_user_partition_groups(course_key, user):
|
||||
"""
|
||||
Collect group ID for each partition in this course for this user.
|
||||
|
||||
Arguments:
|
||||
course_key (CourseKey)
|
||||
user_partitions (list[UserPartition])
|
||||
user (User)
|
||||
|
||||
Returns:
|
||||
dict[int: Group]: Mapping from user partitions to the group to
|
||||
which the user belongs in each partition. If the user isn't
|
||||
in a group for a particular partition, then that partition's
|
||||
ID will not be in the dict.
|
||||
"""
|
||||
user_partitions = get_all_partitions_for_course(course)
|
||||
partition_groups = {}
|
||||
for partition in user_partitions:
|
||||
group = partition.scheme.get_group_for_user(
|
||||
course_key,
|
||||
user,
|
||||
partition,
|
||||
)
|
||||
if group is not None:
|
||||
partition_groups[partition.id] = group
|
||||
return partition_groups
|
||||
|
||||
|
||||
def _get_dynamic_partitions(course):
|
||||
"""
|
||||
|
||||
@@ -6,7 +6,7 @@ from openedx.core.djangoapps.content.block_structure.transformer import (
|
||||
BlockStructureTransformer,
|
||||
FilteringTransformerMixin
|
||||
)
|
||||
from xmodule.partitions.partitions_service import get_all_partitions_for_course
|
||||
from xmodule.partitions.partitions_service import get_user_partition_groups
|
||||
|
||||
from .split_test import SplitTestTransformer
|
||||
from .utils import get_field_on_block
|
||||
@@ -78,7 +78,7 @@ class UserPartitionTransformer(FilteringTransformerMixin, BlockStructureTransfor
|
||||
if not user_partitions:
|
||||
return [block_structure.create_universal_filter()]
|
||||
|
||||
user_groups = _get_user_partition_groups(usage_info.course_key, user_partitions, user)
|
||||
user_groups = get_user_partition_groups(usage_info.course_key, user_partitions, user)
|
||||
|
||||
group_access_filter = block_structure.create_removal_filter(
|
||||
lambda block_key: not (
|
||||
@@ -239,30 +239,3 @@ class _MergedGroupAccess(object):
|
||||
|
||||
# The user has access for every partition, grant access.
|
||||
return True
|
||||
|
||||
|
||||
def _get_user_partition_groups(course_key, user_partitions, user):
|
||||
"""
|
||||
Collect group ID for each partition in this course for this user.
|
||||
|
||||
Arguments:
|
||||
course_key (CourseKey)
|
||||
user_partitions (list[UserPartition])
|
||||
user (User)
|
||||
|
||||
Returns:
|
||||
dict[int: Group]: Mapping from user partitions to the group to
|
||||
which the user belongs in each partition. If the user isn't
|
||||
in a group for a particular partition, then that partition's
|
||||
ID will not be in the dict.
|
||||
"""
|
||||
partition_groups = {}
|
||||
for partition in user_partitions:
|
||||
group = partition.scheme.get_group_for_user(
|
||||
course_key,
|
||||
user,
|
||||
partition,
|
||||
)
|
||||
if group is not None:
|
||||
partition_groups[partition.id] = group
|
||||
return partition_groups
|
||||
|
||||
Reference in New Issue
Block a user