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 18, 2024
1 parent e9609fb commit bdb520d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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: 11 additions & 0 deletions common/djangoapps/student/tests/test_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,14 @@ def test_only_in_role(self, role, target):
def test_empty_cache(self, role, target): # lint-amnesty, pylint: disable=unused-argument
cache = RoleCache(self.user)
assert not cache.has_role(*target)

@ddt.data(IN_KEY.org, 'edx', 'EDX', 'EdX')
def test_org_case_insensitive(self, compare_to_org):
org_role = OrgStaffRole(self.IN_KEY.org)
course_role = CourseInstructorRole(self.IN_KEY)
org_role.add_users(self.user)
course_role.add_users(self.user)

role_cache = RoleCache(self.user)
assert role_cache.has_role('staff', None, compare_to_org)
assert role_cache.has_role('instructor', self.IN_KEY, compare_to_org)

0 comments on commit bdb520d

Please sign in to comment.