Set usable password when canceling user retirement

This commit is contained in:
Bill DeRusha
2018-09-20 12:27:17 -04:00
parent 44c6936ecb
commit b43b174fdd
4 changed files with 20 additions and 5 deletions

View File

@@ -8,6 +8,7 @@ from __future__ import print_function
import logging
from django.core.management.base import BaseCommand, CommandError
from openedx.core.djangoapps.user_api.accounts.utils import generate_password
from openedx.core.djangoapps.user_api.models import UserRetirementStatus
@@ -50,6 +51,7 @@ class Command(BaseCommand):
# Load the user record using the retired email address -and- change the email address back.
retirement_status.user.email = email_address
retirement_status.user.set_password(generate_password(length=25))
retirement_status.user.save()
# Delete the user retirement status record.

View File

@@ -2,6 +2,7 @@
Test the cancel_user_retirement_request management command
"""
import pytest
from django.contrib.auth.hashers import UNUSABLE_PASSWORD_PREFIX
from django.contrib.auth.models import User
from django.core.management import CommandError, call_command
@@ -28,7 +29,9 @@ def test_successful_cancellation(setup_retirement_states, logged_out_retirement_
with pytest.raises(UserRetirementRequest.DoesNotExist):
UserRetirementRequest.objects.get(user=logged_out_retirement_request.user)
# Ensure user can be retrieved using the original email address.
User.objects.get(email=logged_out_retirement_request.original_email)
user = User.objects.get(email=logged_out_retirement_request.original_email)
# Ensure the user has a usable password so they can go through the reset flow
assert not user.password.startswith(UNUSABLE_PASSWORD_PREFIX)
assert "Successfully cancelled retirement request for user with email address" in output
assert logged_out_retirement_request.original_email in output