Skip to content

feat: validate B2C course eligibility for B2C programs#58

Open
rjv31 wants to merge 1 commit into
masterfrom
feat/program-b2c-course-validation
Open

feat: validate B2C course eligibility for B2C programs#58
rjv31 wants to merge 1 commit into
masterfrom
feat/program-b2c-course-validation

Conversation

@rjv31

@rjv31 rjv31 commented Jul 23, 2026

Copy link
Copy Markdown

This PR adds validation to ensure that Programs with b2c_subscription_inclusion=True can only contain Courses with b2c_subscription_inclusion=True.

Changes

  • Added validation in ProgramAdminForm to prevent saving a B2C Program containing non-B2C Courses.
  • Displayed a validation error listing the non-compliant Course(s) when validation fails.
  • Kept the existing Program validation behavior unchanged.
  • Refactored the form validation to use cleaned_data and queryset filtering for improved readability and maintainability.

Copilot AI review requested due to automatic review settings July 23, 2026 11:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds admin-form validation to ensure Programs marked b2c_subscription_inclusion=True only include Courses that are also b2c_subscription_inclusion=True, preventing invalid B2C subscription program configurations from being saved.

Changes:

  • Added B2C eligibility validation in ProgramAdminForm.clean() that rejects non-compliant course selections and surfaces a non-field validation error listing offending courses.
  • Refactored clean() to rely on cleaned_data and queryset filtering.
  • Added tests covering valid B2C programs, invalid mixed-course B2C programs, and non-B2C programs with mixed courses.

Reviewed changes

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

File Description
course_discovery/apps/course_metadata/forms.py Adds B2C course eligibility validation to ProgramAdminForm.clean().
course_discovery/apps/course_metadata/tests/test_forms.py Adds tests for B2C program validation behavior.

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

Comment thread course_discovery/apps/course_metadata/forms.py Outdated
Comment thread course_discovery/apps/course_metadata/tests/test_forms.py

@2usatishkumar 2usatishkumar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved!

Copilot AI review requested due to automatic review settings July 24, 2026 10:23
@rjv31
rjv31 force-pushed the feat/program-b2c-course-validation branch from 0e6e105 to 5a52714 Compare July 24, 2026 10:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

course_discovery/apps/course_metadata/forms.py:120

  • The courses value comes from cleaned_data for a ModelForm M2M field and should already be a QuerySet; the hasattr(courses, 'filter') branch and fallback query add complexity and make the validation harder to follow without providing value here.
            if hasattr(courses, 'filter'):
                invalid_titles = list(
                    courses.filter(b2c_subscription_inclusion=False)
                    .order_by('title')
                    .values_list('title', flat=True)
                )
            else:
                invalid_titles = list(
                    Course.objects.filter(
                        id__in=[course.id for course in courses],
                        b2c_subscription_inclusion=False,
                    ).order_by('title').values_list('title', flat=True)
                )

Comment thread course_discovery/apps/course_metadata/forms.py Outdated
@rjv31
rjv31 force-pushed the feat/program-b2c-course-validation branch from 5a52714 to fb04cde Compare July 24, 2026 10:43
Copilot AI review requested due to automatic review settings July 24, 2026 10:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants