Skip to content

feat: add event handler webhook for certificate generation#684

Merged
arslanashraf7 merged 3 commits intomainfrom
arslan/9693-create-certificates-integration
May 6, 2026
Merged

feat: add event handler webhook for certificate generation#684
arslanashraf7 merged 3 commits intomainfrom
arslan/9693-create-certificates-integration

Conversation

@arslanashraf7
Copy link
Copy Markdown
Contributor

@arslanashraf7 arslanashraf7 commented Jan 1, 2026

This pull request introduces support for handling certificate creation webhooks when a learner passes a course in the Open edX LMS. The main changes add a new signal handler for the COURSE_GRADE_NOW_PASSED event, which triggers a Celery task to notify an external system to create a certificate. Configuration options and tests for the new functionality are also included.

Certificate Webhook Integration:

Configuration and Documentation:

  • Introduced new settings (CERTIFICATE_WEBHOOK_URL, CERTIFICATE_WEBHOOK_ACCESS_TOKEN) with support for environment token overrides, and documented their usage in the README. (ol_openedx_events_handler/settings/common.py, [1]; ol_openedx_events_handler/settings/production.py, [2]; README.rst, [3]
  • Updated the changelog and project version to 0.2.0 to reflect the new functionality. (CHANGELOG.rst, [1]; pyproject.toml, [2]

Testing:

  • Added unit tests for both the signal receiver and the Celery task to ensure correct behavior under various conditions, including eligibility checks and error scenarios. (tests/test_certificate_passing_receiver.py, [1]; tests/test_certificate_passing_tasks.py, [2]

These changes enable automated certificate creation workflows integrated with external systems upon course completion.### What are the relevant tickets?
https://github.com/mitodl/hq/issues/9693, https://github.com/mitodl/hq/issues/10267

Description (What does it do?)

  • The PR adds a certificate event listener in edx instance
  • The listener then calls the MIT app's certificate generation API to generate the certificates

Screenshots (if appropriate):

  • Desktop screenshots
  • Mobile width screenshots

How can this be tested?

NOTE: Will be tested along with the counterpart mitodl/mitxonline#3459

  • Setup on this branch
  • Install the plugin ol_openedx_events_handler
  • Set up a course with a grading policy and units
  • Enroll a user in the paid course mode of this course
  • Set up the configuration values for CERTIFICATE_WEBHOOK_URL (This is the API URL of the API from MITx Online) and CERTIFICATE_WEBHOOK_ACCESS_TOKEN (This is the staff token from your MITx Online instance)
  • Set up the course to be self-paced and pass the user in a course, the webhook should be called, and a certificate should be created in MITx Online if validation passes
  • Set up the certificate display behavior to Immediately upon passing and pass the user in the course, the certificate webhook should be called, and a certificate should be created in MITx Online
  • Set up certificate display behavior to any value other than Immediately upon passing, and the webhook should not be called.

Additional Context

Will be tested along with the counterpart mitodl/mitxonline#3459

@arslanashraf7 arslanashraf7 force-pushed the arslan/9693-create-certificates-integration branch 2 times, most recently from 28a4c7c to a888144 Compare January 1, 2026 12:40
@arslanashraf7 arslanashraf7 force-pushed the arslan/9693-create-certificates-integration branch 2 times, most recently from 4147f90 to 10ebbf8 Compare March 13, 2026 11:03
@arslanashraf7 arslanashraf7 force-pushed the arslan/9693-create-certificates-integration branch from 10ebbf8 to 4dfb64e Compare April 17, 2026 12:46
@arslanashraf7 arslanashraf7 changed the title feat: add openedx mit apps events bridging feat: add event handler webhook for certificate generation Apr 21, 2026
@arslanashraf7 arslanashraf7 force-pushed the arslan/9693-create-certificates-integration branch from 597b018 to 1a95d49 Compare April 28, 2026 13:27
@arslanashraf7 arslanashraf7 force-pushed the arslan/9693-create-certificates-integration branch from 2e81fbf to 3ceb8a4 Compare April 29, 2026 16:14
@arslanashraf7 arslanashraf7 marked this pull request as ready for review April 29, 2026 16:14
@arslanashraf7 arslanashraf7 force-pushed the arslan/9693-create-certificates-integration branch 2 times, most recently from 85c6e80 to e0d4007 Compare April 30, 2026 10:19
@Anas12091101 Anas12091101 self-assigned this Apr 30, 2026
Copy link
Copy Markdown
Contributor

@Anas12091101 Anas12091101 left a comment

Choose a reason for hiding this comment

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

Tested E2E. LGTM 👍

Just a couple of small changes

Comment on lines +7 to +10
* Migrated certificate webhook handling from ``ol_openedx_event_bridge``.
* Added LMS receiver for ``COURSE_GRADE_NOW_PASSED`` to trigger certificate
creation callbacks in MIT systems.
* Added backward-compatible support for legacy certificate-related env tokens.
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.

I believe that only the second point is valid here.

"""
Determine whether certificate generation should be triggered.
"""
enrollment_mode, _ = CourseEnrollment.enrollment_mode_for_user(user, course_id)
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.

enrollment_mode_for_user also returns an is_active flag. We should include an is_active check here to ensure certificates are not created for inactive enrollments.

Suggested change
enrollment_mode, _ = CourseEnrollment.enrollment_mode_for_user(user, course_id)
enrollment_mode, is_active = CourseEnrollment.enrollment_mode_for_user(user, course_id)
if not is_active:
return False

@arslanashraf7 arslanashraf7 force-pushed the arslan/9693-create-certificates-integration branch from e0d4007 to c19b825 Compare May 5, 2026 14:54
@arslanashraf7
Copy link
Copy Markdown
Contributor Author

arslanashraf7 commented May 6, 2026

@Anas12091101 FYI, I've reduced the task retry count to 2, so the tasks will run a total of 3 times now. Once at start and twice at the retry. I've done this in e6fca7b. I'll merge the PR once the CI checks are green.

@arslanashraf7 arslanashraf7 merged commit 50f59f0 into main May 6, 2026
9 checks passed
@arslanashraf7 arslanashraf7 deleted the arslan/9693-create-certificates-integration branch May 6, 2026 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants