From 5ce151c93d75397cfd3fc921210fb23f3dede8ce Mon Sep 17 00:00:00 2001 From: Artur Gaspar Date: Wed, 8 Nov 2023 16:27:34 -0300 Subject: [PATCH] fix: hide instructor tab when masquerading as user role with no masquerade user --- .../instructor/tests/views/test_instructor_dashboard.py | 6 ++++++ lms/djangoapps/instructor/views/instructor_dashboard.py | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py b/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py index bdbffbde7f68..6572379b6eb9 100644 --- a/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py +++ b/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py @@ -26,6 +26,7 @@ from common.djangoapps.student.tests.factories import UserFactory from common.test.utils import XssTestMixin from lms.djangoapps.courseware.courses import get_studio_url +from lms.djangoapps.courseware.masquerade import CourseMasquerade from lms.djangoapps.courseware.tabs import get_course_tab_list from lms.djangoapps.courseware.tests.factories import StudentModuleFactory from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase @@ -121,6 +122,11 @@ def has_instructor_tab(user, course): staff = StaffFactory(course_key=self.course.id) assert has_instructor_tab(staff, self.course) + masquerade_staff = StaffFactory(course_key=self.course.id) + masquerade = CourseMasquerade(self.course.id, role='student') + masquerade_staff.masquerade_settings = {self.course.id: masquerade} + assert not has_instructor_tab(masquerade_staff, self.course) + student = UserFactory.create() assert not has_instructor_tab(student, self.course) diff --git a/lms/djangoapps/instructor/views/instructor_dashboard.py b/lms/djangoapps/instructor/views/instructor_dashboard.py index 9ff82a3e1c5d..25ec258aab4a 100644 --- a/lms/djangoapps/instructor/views/instructor_dashboard.py +++ b/lms/djangoapps/instructor/views/instructor_dashboard.py @@ -53,6 +53,7 @@ from lms.djangoapps.courseware.access import has_access from lms.djangoapps.courseware.courses import get_studio_url from lms.djangoapps.courseware.block_render import get_block_by_usage_id +from lms.djangoapps.courseware.masquerade import get_masquerade_role from lms.djangoapps.discussion.django_comment_client.utils import has_forum_access from lms.djangoapps.grades.api import is_writable_gradebook_enabled from lms.djangoapps.instructor.constants import INSTRUCTOR_DASHBOARD_PLUGIN_VIEW_NAME @@ -93,7 +94,9 @@ def is_enabled(cls, course, user=None): """ Returns true if the specified user has staff access. """ - return bool(user and user.is_authenticated and user.has_perm(permissions.VIEW_DASHBOARD, course.id)) + return bool(user and user.is_authenticated and + get_masquerade_role(user, course.id) != 'student' and + user.has_perm(permissions.VIEW_DASHBOARD, course.id)) def show_analytics_dashboard_message(course_key):