feat: add webhook endpoint for Open edX course staff enrollment#3372
feat: add webhook endpoint for Open edX course staff enrollment#3372Anas12091101 wants to merge 3 commits intomainfrom
Conversation
OpenAPI ChangesShow/hide ## Changes for v0.yaml:Unexpected changes? Ensure your branch is up-to-date with |
openedx/views.py
Outdated
| enrollments, edx_request_success = create_run_enrollments( | ||
| user, | ||
| [course_run], | ||
| keep_failed_enrollments=True, | ||
| ) |
There was a problem hiding this comment.
Bug: The webhook endpoint returns a success response even when the Open edX enrollment API call fails, because it ignores the edx_request_success flag.
Severity: HIGH
Suggested Fix
The webhook view should check the edx_request_success boolean returned from create_run_enrollments. If edx_request_success is False, the view should return an appropriate error response (e.g., HTTP 500 or 400) instead of an HTTP 200 success response. This will signal to the caller that the end-to-end operation failed and a retry may be needed.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: openedx/views.py#L119-L123
Potential issue: The webhook endpoint in `openedx/views.py` calls
`create_run_enrollments` and captures both the created `enrollments` and the
`edx_request_success` status flag. However, the code only checks if `enrollments` is
truthy before returning an HTTP 200 "Enrollment successful" response. It never inspects
the `edx_request_success` flag. This means if the external Open edX API call fails, a
local enrollment record is still created (with `edx_enrolled=False`), but the webhook
incorrectly reports success. This leads to data inconsistency, as the calling system
believes the user is fully enrolled when they are not.
Did we get this right? 👍 / 👎 to inform future reviews.
|
How/is this limited to course staff?
There are similar use cases for enrolling non-staff as auditors, for example a SPOC or beta-testers
|
e7a2816 to
c1a9944
Compare
| {enrollment.run.start_date | ||
| ? `Starts ${formatPrettyMonthDate( | ||
| parseDateString(enrollment.run.start_date) | ||
| )}` | ||
| : "Coming Soon"} |
There was a problem hiding this comment.
Enrollment in a course run with a null start date was breaking the dashboard page.
What are the relevant tickets?
https://github.com/mitodl/hq/issues/1209
Description (What does it do?)
This PR adds a webhook endpoint (/api/openedx_webhook/course_staff/) that receives course staff addition notifications from Open edX. When an instructor or staff member is added to a course in Open edX, the plugin POSTs the event to MITx Online, which then automatically enrolls the user as an auditor in the corresponding course run. The endpoint authenticates requests using a shared Bearer token (
OPENEDX_WEBHOOK_KEY) and handles user/course lookup, duplicate enrollment checks, and appropriate error responses. This enables seamless synchronization of course staff access between Open edX and MITx OnlineScreenshots (if appropriate):
How can this be tested?
Additional Context