Skip to content

Commit 4df908a

Browse files
Artur GasparAgrendalath
authored andcommitted
fix: hide instructor tab when masquerading as user role with no masquerade user
1 parent 0eef233 commit 4df908a

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from common.djangoapps.student.tests.factories import UserFactory
2727
from common.test.utils import XssTestMixin
2828
from lms.djangoapps.courseware.courses import get_studio_url
29+
from lms.djangoapps.courseware.masquerade import CourseMasquerade
2930
from lms.djangoapps.courseware.tabs import get_course_tab_list
3031
from lms.djangoapps.courseware.tests.factories import StudentModuleFactory
3132
from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase
@@ -121,6 +122,11 @@ def has_instructor_tab(user, course):
121122
staff = StaffFactory(course_key=self.course.id)
122123
assert has_instructor_tab(staff, self.course)
123124

125+
masquerade_staff = StaffFactory(course_key=self.course.id)
126+
masquerade = CourseMasquerade(self.course.id, role='student')
127+
masquerade_staff.masquerade_settings = {self.course.id: masquerade}
128+
assert not has_instructor_tab(masquerade_staff, self.course)
129+
124130
student = UserFactory.create()
125131
assert not has_instructor_tab(student, self.course)
126132

lms/djangoapps/instructor/views/instructor_dashboard.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
from lms.djangoapps.courseware.access import has_access
5454
from lms.djangoapps.courseware.courses import get_studio_url
5555
from lms.djangoapps.courseware.block_render import get_block_by_usage_id
56+
from lms.djangoapps.courseware.masquerade import get_masquerade_role
5657
from lms.djangoapps.discussion.django_comment_client.utils import has_forum_access
5758
from lms.djangoapps.grades.api import is_writable_gradebook_enabled
5859
from lms.djangoapps.instructor.constants import INSTRUCTOR_DASHBOARD_PLUGIN_VIEW_NAME
@@ -93,7 +94,9 @@ def is_enabled(cls, course, user=None):
9394
"""
9495
Returns true if the specified user has staff access.
9596
"""
96-
return bool(user and user.is_authenticated and user.has_perm(permissions.VIEW_DASHBOARD, course.id))
97+
return bool(user and user.is_authenticated and
98+
get_masquerade_role(user, course.id) != 'student' and
99+
user.has_perm(permissions.VIEW_DASHBOARD, course.id))
97100

98101

99102
def show_analytics_dashboard_message(course_key):

0 commit comments

Comments
 (0)