Merge pull request #8995 from open-craft/masquerade-cohorts

Allow previewing cohorted content when masquerading (SOL-1064)
This commit is contained in:
Braden MacDonald
2015-07-26 11:18:23 -07:00
4 changed files with 68 additions and 8 deletions

View File

@@ -4,7 +4,11 @@ Provides a UserPartition driver for cohorts.
import logging
from courseware import courses
from courseware.masquerade import get_masquerading_group_info
from courseware.masquerade import ( # pylint: disable=import-error
get_course_masquerade,
get_masquerading_group_info,
is_masquerading_as_specific_student,
)
from xmodule.partitions.partitions import NoSuchUserPartitionGroupError
from .cohorts import get_cohort, get_group_info_for_cohort
@@ -36,16 +40,19 @@ class CohortPartitionScheme(object):
If the user has no cohort mapping, or there is no (valid) cohort ->
partition group mapping found, the function returns None.
"""
# If the current user is masquerading as being in a group
# belonging to the specified user partition, return the
# masquerading group or None if the group can't be found.
group_id, user_partition_id = get_masquerading_group_info(user, course_key)
if user_partition_id == user_partition.id:
if group_id is not None:
# First, check if we have to deal with masquerading.
# If the current user is masquerading as a specific student, use the
# same logic as normal to return that student's group. If the current
# user is masquerading as a generic student in a specific group, then
# return that group.
if get_course_masquerade(user, course_key) and not is_masquerading_as_specific_student(user, course_key):
group_id, user_partition_id = get_masquerading_group_info(user, course_key)
if user_partition_id == user_partition.id and group_id is not None:
try:
return user_partition.get_group(group_id)
except NoSuchUserPartitionGroupError:
return None
# The user is masquerading as a generic student. We can't show any particular group.
return None
cohort = get_cohort(user, course_key, use_cached=use_cached)