Skip to content

Commit

Permalink
fix: hide instructor tab when masquerading as user role with no masqu…
Browse files Browse the repository at this point in the history
…erade user
  • Loading branch information
ArturGaspar authored and Agrendalath committed Nov 8, 2023
1 parent 0eef233 commit 5ce151c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
5 changes: 4 additions & 1 deletion lms/djangoapps/instructor/views/instructor_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 5ce151c

Please sign in to comment.