From ab8bcccd01ac55d98f689f81efdecd3ef04e45c7 Mon Sep 17 00:00:00 2001 From: stvn Date: Mon, 13 Jul 2020 01:25:17 -0700 Subject: [PATCH 1/3] Normalize masquerade response data so that it's easier to work with on the frontend. --- lms/djangoapps/courseware/masquerade.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lms/djangoapps/courseware/masquerade.py b/lms/djangoapps/courseware/masquerade.py index 35c4e5f74b..8829f64a9a 100644 --- a/lms/djangoapps/courseware/masquerade.py +++ b/lms/djangoapps/courseware/masquerade.py @@ -103,7 +103,7 @@ class MasqueradeView(View): 'course_key': course_key_string, 'group_id': course.group_id, 'role': course.role, - 'user_name': course.user_name or ' ', + 'user_name': course.user_name or None, 'user_partition_id': course.user_partition_id, }, 'available': [ From 3fce917fce49117fb88ce5417a1c89a6bf12bce2 Mon Sep 17 00:00:00 2001 From: stvn Date: Sun, 12 Jul 2020 20:26:06 -0700 Subject: [PATCH 2/3] Fix masquerade message by removing the "escaped" username. I'm not sure why we this is done this way (it's displayed the same way in the existing experience. --- lms/djangoapps/courseware/masquerade.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lms/djangoapps/courseware/masquerade.py b/lms/djangoapps/courseware/masquerade.py index 8829f64a9a..93becb36d6 100644 --- a/lms/djangoapps/courseware/masquerade.py +++ b/lms/djangoapps/courseware/masquerade.py @@ -158,7 +158,7 @@ class MasqueradeView(View): return JsonResponse({ 'success': False, '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.' ).format( user_identifier=user_name, From d4f1c271aa1db662246cc8ba185e916441deed62 Mon Sep 17 00:00:00 2001 From: stvn Date: Mon, 13 Jul 2020 01:21:47 -0700 Subject: [PATCH 3/3] Add active group name to masquerade endpoint --- lms/djangoapps/courseware/masquerade.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lms/djangoapps/courseware/masquerade.py b/lms/djangoapps/courseware/masquerade.py index 93becb36d6..0639650d63 100644 --- a/lms/djangoapps/courseware/masquerade.py +++ b/lms/djangoapps/courseware/masquerade.py @@ -69,6 +69,23 @@ class CourseMasquerade(object): """ 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') class MasqueradeView(View): @@ -128,6 +145,7 @@ class MasqueradeView(View): } for group in partition.groups ]) + data['active']['group_name'] = course.get_active_group_name(data['available']) return JsonResponse(data) @method_decorator(expect_json)