Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: RoleCache.has_role should be case-insensitive #35

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clear!

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)
Loading