diff --git a/common/djangoapps/student/auth.py b/common/djangoapps/student/auth.py index 0a088aa2c2db..08b4255feeae 100644 --- a/common/djangoapps/student/auth.py +++ b/common/djangoapps/student/auth.py @@ -65,7 +65,6 @@ def user_has_role(user, role): if role.has_user(user): return True - return False # If not, then check inferred permissions if (isinstance(role, (CourseStaffRole, CourseBetaTesterRole)) and CourseInstructorRole(role.course_key).has_user(user)): diff --git a/common/djangoapps/student/roles.py b/common/djangoapps/student/roles.py index e3dc96b0b1c6..3a3d6b51ee88 100644 --- a/common/djangoapps/student/roles.py +++ b/common/djangoapps/student/roles.py @@ -6,7 +6,6 @@ import logging from abc import ABCMeta, abstractmethod -from collections import defaultdict from contextlib import contextmanager from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user diff --git a/openedx/core/djangoapps/enrollments/data.py b/openedx/core/djangoapps/enrollments/data.py index 1b81fd6a9959..8d11084421ce 100644 --- a/openedx/core/djangoapps/enrollments/data.py +++ b/openedx/core/djangoapps/enrollments/data.py @@ -347,9 +347,12 @@ def get_course_enrollment_info(course_id, include_expired=False): def get_user_roles(username, by_course_id=False): """ - Returns a list of all roles that this user has. + Returns a list of all roles that this user has as a set. + If you specify by_course_id=True, it will instead return a dictionary of course_id to roles, + which has a better lookup time if you are looking for specific course ids. :param username: The id of the selected user. - :return: All roles for all courses that this user has. + :return: A set of all roles for all courses that this user has + or a dictionary of course_id to roles with the key "no_course_id" for roles that are not course specific. """ # pylint: disable=protected-access user = _get_user(username)