From a738c4f1fcf073d12b706683e282768e9ee3a974 Mon Sep 17 00:00:00 2001 From: Shadi Naif Date: Thu, 15 Aug 2024 14:44:40 +0300 Subject: [PATCH] fix: RoleCache.has_role should be case-insensitive --- common/djangoapps/student/roles.py | 2 +- common/djangoapps/student/tests/test_roles.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/common/djangoapps/student/roles.py b/common/djangoapps/student/roles.py index e61fafe89aa1..f96cc5f35375 100644 --- a/common/djangoapps/student/roles.py +++ b/common/djangoapps/student/roles.py @@ -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 ) diff --git a/common/djangoapps/student/tests/test_roles.py b/common/djangoapps/student/tests/test_roles.py index 6c344352a142..bde2da122f1f 100644 --- a/common/djangoapps/student/tests/test_roles.py +++ b/common/djangoapps/student/tests/test_roles.py @@ -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')), ) @@ -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[2].lower() == other_target[2].lower() + ) - assert not cache.has_role(*other_target) + assert cache.has_role(*other_target) == expected_has_role @ddt.data(*ROLES) @ddt.unpack