feat: add Course Membership API

The get_course_members API returns a dict of users associated with a course.
This is a potentially expensive operation on a large course, so there is a
control in place to limit its cost.  If a course has more than
settings.COURSE_MEMBER_API_ENROLLMENT_LIMIT enrollments, then the function
raises an OverEnrollmentLimitException.

This API was added to help implement the LTI 1.3 Names and Roles Provisioning
service.

Jira references: [BD-24] [BB-2726] [TNL-7330] 
Pull request: #25843
Co-authored-by: Giovanni Cimolin da Silva <giovannicimolin@gmail.com>
This commit is contained in:
Shimul Chowdhury
2021-06-03 19:38:13 +06:00
committed by GitHub
parent a0165e88b2
commit 2a8a58ae6b
6 changed files with 253 additions and 3 deletions

View File

@@ -2239,6 +2239,20 @@ class CourseEnrollment(models.Model):
"""
cache[(user_id, course_key)] = enrollment_state
@classmethod
def get_active_enrollments_in_course(cls, course_key):
"""
Retrieves active CourseEnrollments for a given course and
prefetches user information.
"""
return cls.objects.filter(
course_id=course_key,
is_active=True,
).select_related(
'user',
'user__profile',
)
@python_2_unicode_compatible
class FBEEnrollmentExclusion(models.Model):
@@ -2448,6 +2462,18 @@ class CourseAccessRole(models.Model):
"""
return (self.role, self.org, self.course_id, self.user_id)
@classmethod
def access_roles_in_course(cls, course_key):
"""
Returns all CourseAccessRole for a given course and prefetches user information.
"""
return cls.objects.filter(
course_id=course_key,
).select_related(
'user',
'user__profile'
)
def __eq__(self, other):
"""
Overriding eq b/c the django impl relies on the primary key which requires fetch. sometimes we