Skip to content

feat: Add enrollments actions endpoints#38290

Merged
wgu-taylor-payne merged 2 commits into
openedx:masterfrom
WGU-Open-edX:feature/37537-enrollments-api-actions
Apr 17, 2026
Merged

feat: Add enrollments actions endpoints#38290
wgu-taylor-payne merged 2 commits into
openedx:masterfrom
WGU-Open-edX:feature/37537-enrollments-api-actions

Conversation

@brianjbuck-wgu
Copy link
Copy Markdown
Contributor

@brianjbuck-wgu brianjbuck-wgu commented Apr 6, 2026

Description

Adds two new v2 instructor API endpoints to support the Enrollments Actions tab in the Instructor Dashboard MFE, along with updated API spec documentation.

These endpoints provide structured JSON responses for MFE consumption, enabling bulk enroll/unenroll and beta tester management operations.

New Endpoints

1. POST /api/instructor/v2/courses/{course_id}/enrollments/modify

Enroll or unenroll one or more learners in a course by email or username.

  • Permission: CAN_ENROLL (course staff, instructors)
  • Accepts identifier (list of emails/usernames), action (enroll or unenroll), auto_enroll, email_students, and reason
  • Returns per-identifier before/after enrollment state (user, enrollment, allowed, auto_enroll)
  • Invalid identifiers return invalidIdentifier: true; errors return error: true
  • Creates ManualEnrollmentAudit records for traceability
{
    "action": "enroll",
    "auto_enroll": false,
    "results": [
        {
            "identifier": "learner@example.com",
            "before": {"user": true, "enrollment": false, "allowed": false, "auto_enroll": false},
            "after": {"user": true, "enrollment": true, "allowed": false, "auto_enroll": false}
        },
        {
            "identifier": "not-an-email",
            "invalidIdentifier": true
        }
    ]
}

2. POST /api/instructor/v2/courses/{course_id}/beta_testers/modify

Add or remove one or more beta testers for a course.

  • Permission: CAN_BETATEST (course staff, instructors)
  • Accepts identifier (list of emails/usernames), action (add or remove), email_students, and auto_enroll
  • Returns per-identifier results with error (bool) and userDoesNotExist (bool) fields
  • Optionally auto-enrolls users when adding as beta testers
{
    "action": "add",
    "results": [
        {"identifier": "learner@example.com", "error": false, "userDoesNotExist": false, "is_active": true},
        {"identifier": "nobody@example.com", "error": true, "userDoesNotExist": true, "is_active": null}
    ]
}

Other Changes

  • Updated enrollment-v2-api-spec.yaml to match the actual implemented API surface
  • Removed the EnrollmentStatusView endpoint (the existing v1 get_student_enrollment_status is sufficient)
  • Removed the ChangeEnrollmentModeView endpoint (mode changes will be handled through a different workflow)

Impacted Roles

  • Course Staff / Instructors: New API endpoints for enrollment and beta tester management
  • Developers: New v2 API surface for MFE integration

Supporting information

Testing instructions

  1. Enroll learners:

    • As course staff, POST /api/instructor/v2/courses/{course_id}/enrollments/modify with {"identifier": ["learner@example.com"], "action": "enroll"}
    • Verify before/after state shows enrollment change
    • Verify ManualEnrollmentAudit record is created
    • Test with non-existent email to verify CourseEnrollmentAllowed is created
    • Test with invalid identifier (e.g. "not-an-email") to verify invalidIdentifier: true
  2. Unenroll learners:

    • POST with "action": "unenroll" for an enrolled learner
    • Verify before.enrollment is true and after.enrollment is false
  3. Add beta testers:

    • POST /api/instructor/v2/courses/{course_id}/beta_testers/modify with {"identifier": ["learner@example.com"], "action": "add"}
    • Verify learner is added to beta tester role
    • Test with auto_enroll: true to verify auto-enrollment
    • Test with non-existent user to verify per-user error response
  4. Remove beta testers:

    • POST with "action": "remove" for an existing beta tester
    • Verify beta tester role is revoked

Deadline

None

Other information

  • No database migrations required
  • No breaking changes to existing endpoints
  • All operations are synchronous

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Apr 6, 2026
@openedx-webhooks
Copy link
Copy Markdown

openedx-webhooks commented Apr 6, 2026

Thanks for the pull request, @brianjbuck-wgu!

This repository is currently maintained by @openedx/wg-maintenance-openedx-platform.

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 approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To 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:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
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:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@github-project-automation github-project-automation Bot moved this to Needs Triage in Contributions Apr 6, 2026
@brianjbuck-wgu brianjbuck-wgu force-pushed the feature/37537-enrollments-api-actions branch 3 times, most recently from 7649a8b to b6e9ba3 Compare April 6, 2026 17:56
@brianjbuck-wgu brianjbuck-wgu requested a review from Copilot April 6, 2026 17:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds new Instructor API v2 endpoints to support the Instructor Dashboard MFE’s Enrollments Actions workflows by providing structured enrollment status lookup and enrollment mode change functionality.

Changes:

  • Added GET /api/instructor/v2/courses/{course_id}/enrollment_status with structured status/mode response (including pending via CourseEnrollmentAllowed).
  • Added POST /api/instructor/v2/courses/{course_id}/change_enrollment_mode to change a learner’s mode and create a ManualEnrollmentAudit record.
  • Registered both endpoints in the instructor v2 URLconf and added v2 API tests.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
lms/djangoapps/instructor/views/serializers_v2.py Adds request/response serializers for enrollment status lookup and mode change APIs.
lms/djangoapps/instructor/views/api_v2.py Implements the two new v2 endpoints (status lookup + mode change) and auditing.
lms/djangoapps/instructor/views/api_urls.py Wires new v2 routes for the endpoints.
lms/djangoapps/instructor/tests/test_api_v2.py Adds test coverage for both endpoints’ main success/error paths.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lms/djangoapps/instructor/views/serializers_v2.py Outdated
Comment thread lms/djangoapps/instructor/views/api_v2.py Outdated
Comment thread lms/djangoapps/instructor/views/api_v2.py Outdated
Comment thread lms/djangoapps/instructor/tests/test_api_v2.py Outdated
Comment thread lms/djangoapps/instructor/views/serializers_v2.py
@mphilbrick211 mphilbrick211 added the mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). label Apr 6, 2026
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Apr 6, 2026
@diana-villalvazo-wgu
Copy link
Copy Markdown
Contributor

do we really need to create a new endpoint for this GET /api/instructor/v2/courses/{course_id}/enrollment_status?
Im currently using courses/${courseId}/instructor/api/get_student_enrollment_status and i don't see any new attribute that is needed/mandatory for the new mocks 🤔

@diana-villalvazo-wgu
Copy link
Copy Markdown
Contributor

I think is missing POST apis for enroll and unenroll learners, also to add/remove beta testers

@brianjbuck-wgu brianjbuck-wgu force-pushed the feature/37537-enrollments-api-actions branch from 51c3f03 to 2406345 Compare April 14, 2026 18:47
@brianjbuck-wgu brianjbuck-wgu marked this pull request as ready for review April 14, 2026 18:55
@diana-villalvazo-wgu
Copy link
Copy Markdown
Contributor

tested it and works as expected 👍

Copy link
Copy Markdown
Contributor

@diana-villalvazo-wgu diana-villalvazo-wgu left a comment

Choose a reason for hiding this comment

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

Pls update the PR description with the last endpoints and changes

@brianjbuck-wgu brianjbuck-wgu force-pushed the feature/37537-enrollments-api-actions branch from c9508ab to aae2f39 Compare April 15, 2026 20:19
@brianjbuck-wgu brianjbuck-wgu force-pushed the feature/37537-enrollments-api-actions branch from aae2f39 to 84250fd Compare April 16, 2026 17:52
@brianjbuck-wgu brianjbuck-wgu force-pushed the feature/37537-enrollments-api-actions branch 2 times, most recently from d577495 to c301f44 Compare April 16, 2026 20:37
Copy link
Copy Markdown
Contributor

@wgu-taylor-payne wgu-taylor-payne left a comment

Choose a reason for hiding this comment

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

Overall looks good, some smaller questions/issues:

* email_students (optional): Send email notification (default: false)
* reason (optional): Reason for the change

**Response Values**
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please check that these fields and values match up with what is returned from this view.

* email_students (optional): Send email notification (default: false)
* auto_enroll (optional): Auto-enroll in the course (add action; default: false)

**Response Values**
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please check that these fields and values match up with what is returned from this view.

Comment thread lms/djangoapps/instructor/views/api_v2.py Outdated
Comment thread lms/djangoapps/instructor/views/api_v2.py Outdated
Comment thread lms/djangoapps/instructor/views/api_v2.py Outdated
@brianjbuck-wgu brianjbuck-wgu force-pushed the feature/37537-enrollments-api-actions branch from c301f44 to b688835 Compare April 17, 2026 14:47
@wgu-taylor-payne wgu-taylor-payne merged commit 408f947 into openedx:master Apr 17, 2026
42 checks passed
@github-project-automation github-project-automation Bot moved this from Waiting on Author to Done in Contributions Apr 17, 2026
@diana-villalvazo-wgu diana-villalvazo-wgu deleted the feature/37537-enrollments-api-actions branch April 17, 2026 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). open-source-contribution PR author is not from Axim or 2U

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Enrollments API - Actions

6 participants