Skip to content
Snippets Groups Projects
Commit 26e2b35b authored by stvn's avatar stvn
Browse files

Merge PR #24455 add/masquerade/as-specific-student

* Commits:
  Add active group name to masquerade endpoint
  Fix masquerade message
  Normalize masquerade response data
parents 6802b741 d4f1c271
No related branches found
No related tags found
No related merge requests found
...@@ -69,6 +69,23 @@ class CourseMasquerade(object): ...@@ -69,6 +69,23 @@ class CourseMasquerade(object):
""" """
self.__init__(**state) self.__init__(**state)
def get_active_group_name(self, available):
"""
Lookup the active group name, from available options
Returns: the corresponding group name, if exists,
else, return None
"""
if not (self.group_id and self.user_partition_id):
return None
for group in available:
if (
self.group_id == group.get('group_id') and
self.user_partition_id == group.get('user_partition_id')
):
return group.get('name')
return None
@method_decorator(login_required, name='dispatch') @method_decorator(login_required, name='dispatch')
class MasqueradeView(View): class MasqueradeView(View):
...@@ -103,7 +120,7 @@ class MasqueradeView(View): ...@@ -103,7 +120,7 @@ class MasqueradeView(View):
'course_key': course_key_string, 'course_key': course_key_string,
'group_id': course.group_id, 'group_id': course.group_id,
'role': course.role, 'role': course.role,
'user_name': course.user_name or ' ', 'user_name': course.user_name or None,
'user_partition_id': course.user_partition_id, 'user_partition_id': course.user_partition_id,
}, },
'available': [ 'available': [
...@@ -128,6 +145,7 @@ class MasqueradeView(View): ...@@ -128,6 +145,7 @@ class MasqueradeView(View):
} }
for group in partition.groups for group in partition.groups
]) ])
data['active']['group_name'] = course.get_active_group_name(data['available'])
return JsonResponse(data) return JsonResponse(data)
@method_decorator(expect_json) @method_decorator(expect_json)
...@@ -158,7 +176,7 @@ class MasqueradeView(View): ...@@ -158,7 +176,7 @@ class MasqueradeView(View):
return JsonResponse({ return JsonResponse({
'success': False, 'success': False,
'error': _( 'error': _(
u'There is no user with the username or email address u"{user_identifier}" ' u'There is no user with the username or email address "{user_identifier}" '
'enrolled in this course.' 'enrolled in this course.'
).format( ).format(
user_identifier=user_name, user_identifier=user_name,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment