feat: Add enrollments v2 list endpoint#38155
feat: Add enrollments v2 list endpoint#38155brianjbuck-wgu wants to merge 2 commits intoopenedx:masterfrom
Conversation
|
Thanks for the pull request, @brianjbuck-wgu! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. 🔘 Update the status of your PRYour PR is currently marked as a draft. After completing the steps above, update its status by clicking "Ready for Review", or removing "WIP" from the title, as appropriate. Where can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
There was a problem hiding this comment.
Pull request overview
Adds a new list_course_enrollments endpoint and enhances the existing list_course_role_members endpoint with search and pagination support for the instructor dashboard MFE.
Changes:
- New
ListCourseEnrollmentsViewwith DB-level search filtering and pagination for active course enrollments - Enhanced
ListCourseRoleMembersViewwith optionalsearch,page, andpage_sizeparameters (backward compatible) - New serializers and comprehensive test coverage for both endpoints
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| lms/djangoapps/instructor/views/api.py | New ListCourseEnrollmentsView and search/pagination for ListCourseRoleMembersView |
| lms/djangoapps/instructor/views/api_urls.py | Registers the new list_course_enrollments URL |
| lms/djangoapps/instructor/views/serializer.py | New EnrollmentListSerializer and extended RoleNameSerializer with search/pagination fields |
| lms/djangoapps/instructor/tests/test_enrollment_list_api.py | Comprehensive tests for both endpoints |
| lms/djangoapps/instructor/tests/test_api.py | Updates existing tests to include new pagination metadata fields |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| """ | ||
| course_key = CourseKey.from_string(course_id) | ||
| course = get_course_with_access( | ||
| request.user, 'instructor', course_key, depth=None |
There was a problem hiding this comment.
Bug: get_course_with_access is called with 'instructor' access level, but permission_name is set to permissions.VIEW_ENROLLMENTS which corresponds to HasAccessRule('staff'). This means course staff users will pass the permission check but then get a 404 from get_course_with_access since they don't have instructor-level access. This should use 'staff' instead of 'instructor' to be consistent with the permission, or match what the ListCourseRoleMembersView does (which uses EDIT_COURSE_ACCESS permission with 'instructor' access level).
| request.user, 'instructor', course_key, depth=None | |
| request.user, 'staff', course_key, depth=None |
Description
Adds two capabilities needed by the new Enrollments screen in the instructor dashboard MFE:
New
list_course_enrollmentsendpoint — A newPOST /courses/{course_id}/instructor/api/list_course_enrollmentsendpoint that returns a paginated, searchable list of all active course enrollments. Returns user data (username, email, first_name, last_name) with total count and pagination metadata.Search and pagination for
list_course_role_members— Enhances the existingPOST /courses/{course_id}/instructor/api/list_course_role_membersendpoint with optionalsearch,page, andpage_sizeparameters while maintaining full backward compatibility.Changes:
api.py: AddedListCourseEnrollmentsViewwithVIEW_ENROLLMENTSpermission (HasAccessRule('staff')). EnhancedListCourseRoleMembersViewwith search filtering and pagination support.api_urls.py: Registered the newlist_course_enrollmentsURL pattern.serializer.py: AddedEnrollmentListSerializerfor request validation. ExtendedRoleNameSerializerwith optionalsearch,page, andpage_sizefields.Shared features across both endpoints:
page_size(default: 20, max: 100)count,num_pages, andcurrent_pagemetadataUser roles impacted: Course Staff, Course Instructors, Developers building against the instructor API.
Supporting information
Testing instructions
List Course Enrollments
POST /courses/{course_id}/instructor/api/list_course_enrollmentswith an empty body{}.course_id,enrollments(list of user objects),count,num_pages, andcurrent_page.{"search": "partial_username"}and verify filtered results.{"page": 1, "page_size": 5}and verify correct page size and metadata.{"page": 0}and{"page_size": 0}should return 400.List Course Role Members (search/pagination)
POST /courses/{course_id}/instructor/api/list_course_role_memberswith{"rolename": "beta"}.count,num_pages, andcurrent_pagefields.search,page, andpage_sizereturns paginated results with defaults (page 1, page_size 20).{"rolename": "beta", "search": "username"}and verify filtered results.{"rolename": "beta", "page": 2, "page_size": 10}and verify correct paging.Deadline
None
Other information
ListCourseEnrollmentsViewuses theVIEW_ENROLLMENTSpermission (HasAccessRule('staff')) to allow course staff and instructors access, consistent with other enrollment-viewing endpoints.list_course_role_memberschanges are fully backward compatible — existing callers without the new parameters will receive the same data, now paginated with defaults.Qobjects) for search, while the role members endpoint uses in-memory filtering sincelist_with_levelreturns a Python list.