-
Notifications
You must be signed in to change notification settings - Fork 4.2k
docs: create schema for enrollment api #37846
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
Open
wgu-jesse-stewart
wants to merge
10
commits into
openedx:master
Choose a base branch
from
WGU-Open-edX:37813/v2-enrollment-api-schema
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8dbd3db
feat: create schema for enrollment api
wgu-jesse-stewart 1f9d5bc
docs: pr feedback
wgu-jesse-stewart 82c5ef8
fix: pr feedback. rename to enrollment api
wgu-jesse-stewart b73c30b
fix: pr feedback
wgu-jesse-stewart 430bf00
feat: create schema for enrollment api
wgu-jesse-stewart 3de03a9
docs: pr feedback
wgu-jesse-stewart 35bae41
fix: pr feedback. rename to enrollment api
wgu-jesse-stewart 6bb7419
docs: update enrollment API spec with full_name and beta_tester fields
wgu-jesse-stewart a98605c
Merge branch '37813/v2-enrollment-api-schema' of https://github.com/W…
wgu-jesse-stewart e4cdfde
docs: delete lms/djangoapps/instructor/docs/decisions/0003-instructor…
wgu-jesse-stewart File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
164 changes: 164 additions & 0 deletions
164
lms/djangoapps/instructor/docs/decisions/0004-instructor-enrollment-api-spec.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| Enrollment API v2 Specification | ||
| -------------------------------- | ||
|
|
||
| Status | ||
| ====== | ||
|
|
||
| **Draft** | ||
|
|
||
| This ADR will move to **Provisional** status once the OpenAPI specification is approved and implementation begins. It will move to **Accepted** status once the API is fully implemented and deployed. | ||
|
|
||
| Context | ||
| ======= | ||
|
|
||
| The existing enrollment API (v1) has several limitations that make it difficult to use in modern applications. A new v2 enrollment API is needed to support the instructor dashboard MFE migration and other enrollment management use cases across the platform. The current implementation provides enrollment operations (enroll, unenroll, list enrollments) through legacy endpoints in ``lms/djangoapps/instructor/enrollment.py`` and the v1 enrollment API at ``/api/enrollment/v1/``. | ||
|
|
||
| Decisions | ||
| ========= | ||
|
|
||
| #. **RESTful Resource-Oriented Design** | ||
|
|
||
| Use resource-oriented URLs: ``/api/enrollment/v2/courses/{course_key}/enrollments`` | ||
|
|
||
| Use appropriate HTTP methods per Open edX REST API Conventions: | ||
|
|
||
| * ``GET`` for read operations (list enrollments, get enrollment details) | ||
| * ``POST`` for enrollments (enroll one or more learners) | ||
| * ``DELETE`` for unenrollments (unenroll a single learner) | ||
|
|
||
| #. **Synchronous vs Asynchronous Execution** | ||
|
|
||
| * Operations targeting a single learner execute synchronously and return ``200 OK`` | ||
| with immediate results (< 5s typical, typically 100-500ms) | ||
| * Operations targeting multiple learners queue a background task and return | ||
| ``202 Accepted`` with task tracking information | ||
| * Task monitoring uses shared Task API endpoint: | ||
| ``GET /api/enrollment/v2/courses/{course_key}/tasks/{task_id}`` | ||
| (defined in separate Task API specification) | ||
|
|
||
| #. **Enrollment State Model** | ||
|
|
||
| * Support both active enrollments (``CourseEnrollment``) and pre-enrollments | ||
| (``CourseEnrollmentAllowed``) | ||
| * Track enrollment state transitions with before/after snapshots | ||
| * Handle cases where user doesn't exist yet (creates CourseEnrollmentAllowed) | ||
| * Support auto-enrollment upon user registration | ||
| * Support multiple enrollment modes (audit, honor, verified, professional, etc.) | ||
|
|
||
| #. **Pagination and Performance** | ||
|
|
||
| * Use DRF standard pagination format with ``next``, ``previous``, ``count``, | ||
| ``num_pages``, and ``results`` fields (not nested pagination) | ||
| * Default page size of 25, maximum of 100 per page | ||
| * 1-indexed page numbers for consistency with DRF defaults | ||
| * Return basic enrollment data by default to optimize performance | ||
|
|
||
| #. **Optional Fields via requested_fields Parameter** | ||
|
|
||
| * Support ``requested_fields`` query parameter per Open edX conventions | ||
| * Available optional fields: ``beta_tester``, ``profile_image`` | ||
| * Comma-delimited list format: ``?requested_fields=beta_tester,profile_image`` | ||
| * Reduces database queries and improves performance when optional data not needed | ||
|
|
||
| #. **Authentication and Authorization** | ||
|
|
||
| * Support both OAuth2 (for mobile clients and micro-services) and | ||
| Session-based authentication (for mobile webviews and browser clients) | ||
| * Require appropriate permissions based on operation scope: | ||
|
|
||
| * Course staff or instructor: Can manage enrollments within their courses | ||
| * Global staff: Can manage enrollments across all courses | ||
| * Self-enrollment: Learners can enroll/unenroll themselves (future consideration) | ||
|
|
||
| * Follow separation of filtering and authorization (explicit filtering in URLs) | ||
|
|
||
| #. **Error Handling** | ||
|
|
||
| * Follow Open edX REST API Conventions error format | ||
| * Include ``error_code`` (machine-readable), ``developer_message``, | ||
| ``user_message`` (internationalized), and ``status_code`` | ||
| * Support ``field_errors`` object for field-specific validation errors | ||
| * Use appropriate HTTP status codes: 200, 202, 400, 401, 403, 404 | ||
|
|
||
| #. **Date/Time Serialization** | ||
|
|
||
| * Serialize all dates and timestamps to ISO 8601 format with explicit timezone offsets | ||
| * Prefer UTC timestamps | ||
| * Example format: ``2024-01-15T10:30:00Z`` | ||
|
|
||
| #. **Email Notifications** | ||
|
|
||
| * Support optional email notifications via ``email_students`` parameter | ||
| * Use different message types based on user state: | ||
|
|
||
| * ``enrolled_enroll``: User already registered, being enrolled | ||
| * ``allowed_enroll``: User not yet registered, pre-enrollment created | ||
| * ``enrolled_unenroll``: User being unenrolled | ||
| * ``allowed_unenroll``: Pre-enrollment being removed | ||
|
|
||
| * Support optional ``reason`` parameter included in notification emails | ||
|
|
||
| #. **OpenAPI Specification** | ||
|
|
||
| Maintain an OpenAPI specification at ``../references/enrollment-v2-api-spec.yaml`` | ||
| to guide implementation. This static specification serves as a reference during development, | ||
| but ``/api-docs/`` is the source of truth for what is actually deployed. Once implementation | ||
| is complete and the endpoints are live in ``/api-docs/``, the static spec file will be | ||
| deleted to avoid maintaining outdated documentation. | ||
|
|
||
| Consequences | ||
| ============ | ||
|
|
||
| Positive | ||
| ~~~~~~~~ | ||
|
|
||
| * Consistent URL patterns following Open edX conventions make the API predictable | ||
| * Explicit sync/async behavior based on operation scope allows proper UI feedback | ||
| * Pagination support efficiently handles courses with thousands of enrollments | ||
| * Optional fields optimize performance by avoiding unnecessary database queries | ||
| * OpenAPI specification enables automated validation, testing, and type-safe client generation | ||
| * Resource-oriented design makes it easy to add new operations | ||
| * Support for both enrollments and pre-enrollments handles all use cases | ||
| * Before/after state tracking provides clear audit trail of changes | ||
| * Email notification support maintains current functionality for learner communication | ||
|
|
||
| Negative | ||
| ~~~~~~~~ | ||
|
|
||
| * Existing clients using legacy enrollment endpoints need to be updated | ||
| * Dual maintenance during transition period | ||
| * Developers familiar with legacy endpoints need to learn new patterns | ||
| * Optional fields via ``requested_fields`` add complexity to serialization logic | ||
| * Async operations require additional task monitoring implementation | ||
|
|
||
| Alternatives Considered | ||
| ======================= | ||
|
|
||
| #. **Separate Endpoints for Enroll/Unenroll** | ||
|
|
||
| Considered ``POST /enrollments`` for enroll and ``POST /unenrollments`` for unenroll, | ||
| but using ``DELETE /enrollments/{id}`` is more RESTful and follows HTTP verb semantics. | ||
|
|
||
| #. **Nested Pagination Format** | ||
|
|
||
| Considered nesting pagination metadata under a ``pagination`` key (per Cliff Dyer's | ||
| proposal), but chose DRF standard flat format (``next``, ``previous``, ``count``, | ||
| ``num_pages``, ``results`` at top level) as it's the established convention | ||
| documented in Open edX REST API Conventions. | ||
|
|
||
| #. **Expand Parameter Instead of requested_fields** | ||
|
|
||
| Considered using ``expand`` parameter for related objects, but ``requested_fields`` | ||
| is more appropriate for optional fields that are not separate resources. Using | ||
| ``expand`` would imply these are related resources with their own endpoints, | ||
| which is not the case for beta tester status or profile images in this context. | ||
|
|
||
| References | ||
| ========== | ||
|
|
||
| * OpenAPI Specification: ``../references/enrollment-v2-api-spec.yaml`` | ||
| * Live API Documentation: ``/api-docs/`` | ||
| * Existing v1 Enrollment API: ``https://master.openedx.io/api-docs/#/enrollment`` | ||
| * Legacy Implementation: ``lms/djangoapps/instructor/enrollment.py`` | ||
| * `Open edX REST API Conventions <https://openedx.atlassian.net/wiki/spaces/AC/pages/18350757/Open+edX+REST+API+Conventions>` | ||
| * `Optional Fields and API Versioning: https://openedx.atlassian.net/wiki/spaces/AC/pages/40862782/Optional+Fields+and+API+Versioning` | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.