fix: [AA-893] Don't show View As Learner if partitions
Remove the option to masquerade as a generic learner if there are enrollment tracks or partition groups because the behavior is unpredictable and unhelpful. Fixes: AA-893
This commit is contained in:
@@ -128,17 +128,19 @@ class MasqueradeView(View):
|
||||
'name': 'Staff',
|
||||
'role': 'staff',
|
||||
},
|
||||
{
|
||||
'name': 'Learner',
|
||||
'role': 'student',
|
||||
},
|
||||
{
|
||||
'name': 'Specific Student...',
|
||||
'role': 'student',
|
||||
'user_name': course.user_name or '',
|
||||
},
|
||||
],
|
||||
}
|
||||
if len(partitions) == 0:
|
||||
data['available'].append( {
|
||||
'name': 'Learner',
|
||||
'role': 'student',
|
||||
})
|
||||
|
||||
data['available'].append({
|
||||
'name': 'Specific Student...',
|
||||
'role': 'student',
|
||||
'user_name': course.user_name or '',
|
||||
})
|
||||
for partition in partitions:
|
||||
if partition.active:
|
||||
data['available'].extend([
|
||||
|
||||
@@ -128,6 +128,18 @@ class MasqueradeTestCase(SharedModuleStoreTestCase, LoginEnrollmentTestCase, Mas
|
||||
)
|
||||
return self.client.get(url)
|
||||
|
||||
def get_available_masquerade_identities(self):
|
||||
"""
|
||||
Returns: the server response for masquerade options
|
||||
"""
|
||||
url = reverse(
|
||||
'masquerade_update',
|
||||
kwargs={
|
||||
'course_key_string': str(self.course.id),
|
||||
}
|
||||
)
|
||||
return self.client.get(url)
|
||||
|
||||
def verify_staff_debug_present(self, staff_debug_expected):
|
||||
"""
|
||||
Verifies that the staff debug control visibility is as expected (for staff only).
|
||||
@@ -159,6 +171,18 @@ class MasqueradeTestCase(SharedModuleStoreTestCase, LoginEnrollmentTestCase, Mas
|
||||
assert self.problem_display_name in problem_html
|
||||
assert show_answer_expected == ('Show answer' in problem_html)
|
||||
|
||||
def verify_learner_masquerade_available(self, learner_option_expected):
|
||||
"""
|
||||
Verifies if learner masquerade option is available
|
||||
Args:
|
||||
exists: True to test if Learner is in options, False to test it is NOT
|
||||
"""
|
||||
response = self.get_available_masquerade_identities()
|
||||
items = response.content.json['available'].items()
|
||||
is_it_there = (('name', 'Learner') in items)
|
||||
assert learner_option_expected == is_it_there
|
||||
assert learner_option_expected == (('name', 'Learner') in content.items())
|
||||
|
||||
def ensure_masquerade_as_group_member(self, partition_id, group_id):
|
||||
"""
|
||||
Installs a masquerade for the test_user and test course, to enable the
|
||||
@@ -209,6 +233,26 @@ class StaffMasqueradeTestCase(MasqueradeTestCase):
|
||||
return StaffFactory(course_key=self.course.id)
|
||||
|
||||
|
||||
class TestMasqueradeOptionsForNoPartitions(MasqueradeTestCase):
|
||||
"""
|
||||
Check that 'Learner' option is available if there are no groups or partitions
|
||||
"""
|
||||
@patch.dict('django.conf.settings.FEATURES', {'ENABLE_MASQUERADE': True})
|
||||
@patch.dict('django.conf.settings.FEATURES', {'ENABLE_ENROLLMENT_TRACK_USER_PARTITION': False})
|
||||
def test_masquerade_options_enrollment_track(self):
|
||||
self.verify_learner_masquerade_available(True)
|
||||
|
||||
|
||||
class TestMasqueradeOptionsForUserPartition(MasqueradeTestCase):
|
||||
"""
|
||||
Check that 'Learner' option is NOT available if there are no groups or partitions
|
||||
"""
|
||||
@ patch.dict('django.conf.settings.FEATURES', {'ENABLE_ENROLLMENT_TRACK_USER_PARTITION': True})
|
||||
@ patch.dict('django.conf.settings.FEATURES', {'ENABLE_MASQUERADE': True})
|
||||
def test_masquerade_options_no_cohort(self):
|
||||
self.verify_learner_masquerade_available(False)
|
||||
|
||||
|
||||
class TestStaffMasqueradeAsStudent(StaffMasqueradeTestCase):
|
||||
"""
|
||||
Check for staff being able to masquerade as student.
|
||||
|
||||
Reference in New Issue
Block a user