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 9707186
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 = (
target[0] == other_target[0] and
(target[1] or '') == (other_target[1] or '') and
target[0].lower() == other_target[0].lower()
)

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 9707186

Please sign in to comment.