-
Notifications
You must be signed in to change notification settings - Fork 2
Release 1.144.5 #3454
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
Merged
Merged
Release 1.144.5 #3454
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9c73fb3
Refactor program cert generation to support new cert requirements (#3…
jkachel 1c1f5b7
fix: fall back to audit enrollment for non-upgradable runs in verifie…
Anas12091101 4a68740
Add test to the program enrollment dialog (#3445)
annagav 168c95f
[pre-commit.ci] pre-commit autoupdate (#3438)
pre-commit-ci[bot] b918de5
Merge branch 'release'
odlbot f8bfa01
chore: add drf-lint pre-commit hook with baseline (#3453)
blarghmatey ca2c787
Add management command to check/repair B2B program enrollments (#3449)
jkachel f842362
Release 1.144.5
odlbot 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
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
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
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,81 @@ | ||
| """Check and repair B2B program enrollments.""" | ||
|
|
||
| import logging | ||
|
|
||
| from django.core.management import BaseCommand | ||
| from django.db.models import Q | ||
|
|
||
| from b2b.models import ContractProgramItem | ||
| from courses.constants import ENROLL_CHANGE_STATUS_UNENROLLED | ||
| from courses.models import Program, ProgramEnrollment | ||
|
|
||
| log = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class Command(BaseCommand): | ||
| """Check and repair B2B program enrollments.""" | ||
|
|
||
| help = """Check and repair B2B program enrollments. | ||
|
|
||
| Unenroll users from B2B programs that belong to contracts that the user doesn't have an attachment for.""" | ||
|
|
||
| def add_arguments(self, parser): | ||
| """Add command line arguments.""" | ||
|
|
||
| parser.add_argument( | ||
| "--user", type=str, help="Check specified username or email." | ||
| ) | ||
| parser.add_argument( | ||
| "--commit", | ||
| action="store_true", | ||
| default=False, | ||
| help="Commit changes. Otherwise, this will produce output but won't make any changes.", | ||
| ) | ||
|
|
||
| def handle(self, *args, **kwargs): # noqa: ARG002 | ||
| """Perform check and repair operation.""" | ||
|
|
||
| specific_user = kwargs.pop("user", None) | ||
| commit = kwargs.pop("commit", False) | ||
|
|
||
| if not commit: | ||
| self.stdout.write( | ||
| self.style.WARNING("Commit flag not set - no changes will be made.") | ||
| ) | ||
|
|
||
| b2b_programs = Program.objects.filter( | ||
| b2b_only=True, | ||
| contract_memberships__isnull=False, | ||
| ).distinct() | ||
|
|
||
| for program in b2b_programs: | ||
| program_contract_ids = ContractProgramItem.objects.filter( | ||
| program=program | ||
| ).values_list("contract_id", flat=True) | ||
|
|
||
| extraneous_enrollments = ( | ||
| ProgramEnrollment.objects.filter(program=program) | ||
| .exclude(user__b2b_contracts__in=program_contract_ids) | ||
| .select_related("user", "program") | ||
| .distinct() | ||
| ) | ||
|
|
||
| if specific_user: | ||
| extraneous_enrollments = extraneous_enrollments.filter( | ||
| Q(user__email=specific_user) | Q(user__username=specific_user) | ||
| ) | ||
|
|
||
| count = extraneous_enrollments.count() | ||
| if count > 0: | ||
| self.stdout.write( | ||
| f"Program {program.readable_id}: unenrolling {count} user(s):" | ||
| ) | ||
|
|
||
| for enrollment in extraneous_enrollments: | ||
| self.stdout.write(f"\t{enrollment.user.email}") | ||
| if commit: | ||
| enrollment.deactivate_and_save( | ||
| ENROLL_CHANGE_STATUS_UNENROLLED, no_user=True | ||
| ) | ||
|
|
||
| self.stdout.write("\n") |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The new check for a verified
ProgramEnrollmentprevents returning existing certificates for users whose enrollments were auto-created with the default 'audit' mode by the old system.Severity: HIGH
Suggested Fix
The logic should be reordered. First, check if a valid
ProgramCertificatealready exists for the user. If it does, return it. Only if no certificate exists should the code proceed to check for a verifiedProgramEnrollmentas a condition for creating a new certificate. This ensures backward compatibility for users with existing certificates.Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.