Skip to content

Commit

Permalink
fix: RoleCache.has_role should be case-insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
shadinaif committed Aug 15, 2024
1 parent e9609fb commit e7e5c93
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion common/djangoapps/student/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def has_role(self, role, course_id, org):
return any(
access_role.role in self.get_roles(role) and
access_role.course_id == course_id and
access_role.org == org
access_role.org.lower() == org.lower()
for access_role in self._roles
)

Expand Down
11 changes: 8 additions & 3 deletions common/djangoapps/student/tests/test_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,10 @@ class RoleCacheTestCase(TestCase): # lint-amnesty, pylint: disable=missing-clas

ROLES = (
(CourseStaffRole(IN_KEY), ('staff', IN_KEY, 'edX')),
(CourseStaffRole(IN_KEY), ('staff', IN_KEY, 'EDX')),
(CourseInstructorRole(IN_KEY), ('instructor', IN_KEY, 'edX')),
(OrgStaffRole(IN_KEY.org), ('staff', None, 'edX')),
(OrgStaffRole(IN_KEY.org), ('staff', None, 'EDX')),
(OrgInstructorRole(IN_KEY.org), ('instructor', None, 'edX')),
(CourseBetaTesterRole(IN_KEY), ('beta_testers', IN_KEY, 'edX')),
)
Expand All @@ -180,10 +182,13 @@ def test_only_in_role(self, role, target):
assert cache.has_role(*target)

for other_role, other_target in self.ROLES:
if other_role == role:
continue
expected_has_role = (
other_role.ROLE == role.ROLE and
other_role.org.lower() == role.org.lower() and
other_role.course_key == role.course_key
)

assert not cache.has_role(*other_target)
assert cache.has_role(*other_target) == expected_has_role

@ddt.data(*ROLES)
@ddt.unpack
Expand Down

0 comments on commit e7e5c93

Please sign in to comment.