fix: add command to release a retired learner's email for reuse - #460
Merged
Conversation
naincy128
approved these changes
Sep 7, 2026
Alam-2U
approved these changes
Sep 7, 2026
robrap
reviewed
Sep 8, 2026
| # Mutually exclusive + required enforces "exactly one of the two" for us, | ||
| # so handle() doesn't need to re-validate that itself. | ||
| identifier = parser.add_mutually_exclusive_group(required=True) | ||
| identifier.add_argument('--username', type=str, help='Username of the retired learner to release.') |
There was a problem hiding this comment.
Why do we need this? Since it is a retired user, let's not use PII. Non-blocking, but we should fix before moving to openedx.
|
|
||
| user.refresh_from_db() | ||
| assert user.email == released_email | ||
| assert 'Successfully released email' in capsys.readouterr().out |
There was a problem hiding this comment.
Non-blocking: Wondering if mocking locker like in
is more common and a better practice. I can think of pros and cons of both.| return create_retirement_status(user, state=RetirementState.objects.get(state_name=state_name)) | ||
|
|
||
| def test_releases_email_when_retirement_complete(self): | ||
| user = UserFactory(email='retired__user_abc123@retired.invalid') |
There was a problem hiding this comment.
Is retired.invalid the value of {settings.RETIRED_EMAIL_DOMAIN}? The inconsistency in the test is a little confusing.
| from completion.models import BlockCompletion | ||
| from completion.waffle import ENABLE_COMPLETION_TRACKING_SWITCH | ||
| from django.conf import settings | ||
| from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user |
There was a problem hiding this comment.
Don't copy-past lint-amnesty. It will be removed from openedx altogether.
Suggested change
| from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user | |
| from django.contrib.auth.models import User # pylint: disable=imported-auth-user |
robrap
approved these changes
Sep 8, 2026
robrap
enabled auto-merge (squash)
September 8, 2026 16:41
|
Closing/re-opening to rerun tests. |
auto-merge was automatically disabled
September 8, 2026 16:47
Pull request was closed
robrap
enabled auto-merge (squash)
September 8, 2026 16:50
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
A retired learner's original email is permanently blocked from re-registration, because
is_email_retired()still finds a
Userrow whose email matches the retired-hash of that address.This adds
release_retired_learner_email(user)(accounts/utils.py), which replaces a fully-retired user'shashed email with a placeholder (
retired_email_<user_id>@<RETIRED_EMAIL_DOMAIN>), clearing that match so theoriginal address becomes reusable. The
UserRetirementStatusrow and retirement history are left untouched.Exposed via a new
release_retired_user_emailmanagement command (--usernameor--user_id) forOperator/Support use. No automatic trigger (waffle flag, API hook) is wired up so this is manual only, for now.
Supporting information
Testing instructions
COMPLETEstate.is_email_retired("learner@example.com")=>True../manage.py lms release_retired_user_email --username <retired_username>is_email_retired("learner@example.com")=>False; confirm re-registration succeeds.pytest openedx/core/djangoapps/user_api/accounts/tests/test_utils.py openedx/core/djangoapps/user_api/management/tests/test_release_retired_user_email.pyDeadline
None.
Other information
None.