Don't update account recovery until after activation

Rather than to create or update the account recovery record when the
Account Settings page is updated, defer updating until the new
recovery email is confirmed

ENT-2607
This commit is contained in:
Mike O'Connell
2020-02-14 09:59:36 -05:00
parent bac070e8af
commit e5e96c9dde
4 changed files with 80 additions and 90 deletions

View File

@@ -15,30 +15,27 @@ from django.utils.translation import override as override_language
from django.utils.translation import ugettext as _
from pytz import UTC
from six import text_type # pylint: disable=ungrouped-imports
from openedx.core.djangoapps.user_api import accounts, errors, helpers
from openedx.core.djangoapps.user_api.config.waffle import PREVENT_AUTH_USER_WRITES, SYSTEM_MAINTENANCE_MSG, waffle
from openedx.core.djangoapps.user_api.errors import (
AccountUpdateError,
AccountValidationError,
PreferenceValidationError
)
from openedx.core.djangoapps.user_api.preferences.api import update_user_preferences
from openedx.core.lib.api.view_utils import add_serializer_errors
from openedx.core.djangoapps.user_authn.views.registration_form import validate_name, validate_username
from openedx.features.enterprise_support.utils import get_enterprise_readonly_account_fields
from student import views as student_views
from student.models import (
AccountRecovery,
Registration,
User,
UserProfile,
email_exists_or_retired,
username_exists_or_retired
)
from util.model_utils import emit_setting_changed_event
from util.password_policy_validators import normalize_password, validate_password
from util.password_policy_validators import validate_password
from openedx.core.djangoapps.user_api import accounts, errors, helpers
from openedx.core.djangoapps.user_api.errors import (
AccountUpdateError,
AccountValidationError,
PreferenceValidationError
)
from openedx.core.djangoapps.user_api.preferences.api import update_user_preferences
from openedx.core.djangoapps.user_authn.views.registration_form import validate_name, validate_username
from openedx.core.lib.api.view_utils import add_serializer_errors
from openedx.features.enterprise_support.utils import get_enterprise_readonly_account_fields
from .serializers import AccountLegacyProfileSerializer, AccountUserSerializer, UserReadOnlySerializer, _visible_fields
# Public access point for this function.
@@ -221,16 +218,13 @@ def _validate_secondary_email(user, data, field_errors):
if "secondary_email" not in data:
return
account_recovery = _get_account_recovery(user)
try:
student_views.validate_secondary_email(account_recovery, data["secondary_email"])
student_views.validate_secondary_email(user, data["secondary_email"])
except ValueError as err:
field_errors["secondary_email"] = {
"developer_message": u"Error thrown from validate_secondary_email: '{}'".format(text_type(err)),
"user_message": text_type(err)
}
else:
account_recovery.update_recovery_email(data["secondary_email"])
def _validate_name_change(user_profile, data, field_errors):
@@ -453,18 +447,6 @@ def _get_user_and_profile(username):
return existing_user, existing_user_profile
def _get_account_recovery(user):
"""
helper method to return the account recovery object based on user.
"""
try:
account_recovery = user.account_recovery
except ObjectDoesNotExist:
account_recovery = AccountRecovery(user=user)
return account_recovery
def _validate(validation_func, err, *args):
"""Generic validation function that returns default on
no errors, but the message associated with the err class