Skip to content

feat: add validation to issue badge - #3007

Open
luisfelipec95 wants to merge 3 commits into
openedx:masterfrom
Pearson-Advance:lfc/issue-badge-validation
Open

luisfelipec95 wants to merge 3 commits into
openedx:masterfrom
Pearson-Advance:lfc/issue-badge-validation

Conversation

@luisfelipec95

Copy link
Copy Markdown
Contributor

Description

This change adds an optional, settings-driven badge issuance restriction check for Credly badges.

When enabled, the badge completion flow evaluates whether badge issuance is allowed by querying a configurable external API for each related course fulfillment before issuing the badge. If any exact course match indicates that badge issuance is restricted, the badge is not issued.

The restriction logic is kept separate from the signal handler, and authenticated requests use the existing SiteConfiguration.api_client and OAuthAPIClient implementation.

This feature is disabled by default and is designed to remain generic so it can support different integrations.

Changes

Added a new feature flag:

  • BADGES_ENABLE_ISSUANCE_RESTRICTIONS

Added configurable settings for the external restrictions check:

  • BADGES_ISSUANCE_RESTRICTIONS_API_URL
  • BADGES_ISSUANCE_RESTRICTIONS_FLAG_NAME

Added a course_key field to badge fulfillments:

  • stores the course identifier associated with the fulfillment
  • allows badge issuance checks to be evaluated in a course-specific context

Added a dedicated badge restriction utility:

  • keeps the external restriction check separate from handle_badge_completion
  • evaluates all relevant fulfillment course keys
  • matches the exact ccx_id returned by the external API
  • blocks issuance when the configured restriction flag is false
  • allows issuance by default when the feature is disabled or no restriction data is available

Updated handle_badge_completion to:

  • run the restriction check only for Credly badges
  • retrieve the user's badge progress and related fulfillments
  • query the external API using each fulfillment's course_key
  • use the existing SiteConfiguration.api_client for authenticated inter-service requests
  • skip badge issuance when the external API indicates that issuance is not allowed

Why

Some deployments need badge issuance to depend on external business rules. This change introduces a flexible mechanism to evaluate those rules at issuance time while keeping the default behavior unchanged for the community.

The course_key field is required so each fulfillment carries the course identifier needed to evaluate issuance restrictions on a per-course basis.

Reusing SiteConfiguration.api_client avoids duplicating OAuth2 client-credentials logic that is already provided by Credentials and edx-rest-api-client, including token handling and refresh behavior.

Default behavior

This feature is disabled by default.

When BADGES_ENABLE_ISSUANCE_RESTRICTIONS is disabled, or when no matching restriction data is returned by the external API, badge issuance continues as before.

@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @luisfelipec95!

This repository is currently maintained by @jajjibhai008.

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.

@GlugovGrGlib

Copy link
Copy Markdown
Member

@luisfelipec95 Thanks for the PR. Before I proceed with review can you please create a new Issue in the repository describing this as functionality request with business need details and acceptance criteria or definition of done.

Additionally, can you please include documentation updates into this PR because in other case this new feature is basically invisible for Open edX users.

@luisfelipec95

Copy link
Copy Markdown
Contributor Author

Hi @GlugovGrGlib, I create this issue #3011 and updated the PR, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

open-source-contribution PR author is not from Axim or 2U

Projects

Status: No status
Status: Ready for Review

Development

Successfully merging this pull request may close these issues.

3 participants