BOM-1514 : Remove waffle switch PREVENT_AUTH_USER_WRITES (#23686)

* Remove waffle switch PREVENT_AUTH_USER_WRITES
This commit is contained in:
M Zulqarnain
2020-04-10 18:21:12 +05:00
committed by GitHub
parent 33242bbc00
commit 39dcc8b180
9 changed files with 0 additions and 90 deletions

View File

@@ -17,10 +17,6 @@ class StudentConfig(AppConfig):
name = 'student'
def ready(self):
from django.contrib.auth.models import update_last_login as django_update_last_login
user_logged_in.disconnect(django_update_last_login)
from .signals.receivers import update_last_login
user_logged_in.connect(update_last_login)
from django.contrib.auth.models import User
from .signals.receivers import on_user_updated

View File

@@ -4,24 +4,11 @@ Signal receivers for the "student" application.
from django.conf import settings
from django.utils import timezone
from openedx.core.djangoapps.user_api.config.waffle import PREVENT_AUTH_USER_WRITES, waffle
from student.helpers import USERNAME_EXISTS_MSG_FMT, AccountValidationError
from student.models import is_email_retired, is_username_retired
def update_last_login(sender, user, **kwargs): # pylint: disable=unused-argument
"""
Replacement for Django's ``user_logged_in`` signal handler that knows not
to attempt updating the ``last_login`` field when we're trying to avoid
writes to the ``auth_user`` table while running a migration.
"""
if not waffle().is_enabled(PREVENT_AUTH_USER_WRITES):
user.last_login = timezone.now()
user.save(update_fields=['last_login'])
def on_user_updated(sender, instance, **kwargs): # pylint: disable=unused-argument
"""
Check for retired usernames.

View File

@@ -11,7 +11,6 @@ from django.urls import reverse
from mock import patch
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from openedx.core.djangoapps.user_api.config.waffle import PREVENT_AUTH_USER_WRITES, SYSTEM_MAINTENANCE_MSG, waffle
from student.models import Registration
from student.tests.factories import UserFactory
@@ -136,14 +135,3 @@ class TestActivateAccount(TestCase):
response = self.client.get(reverse('activate', args=[uuid4().hex]), follow=True)
self.assertRedirects(response, login_page_url)
self.assertContains(response, 'Your account could not be activated')
def test_account_activation_prevent_auth_user_writes(self):
login_page_url = "{login_url}?next={redirect_url}".format(
login_url=reverse('signin_user'),
redirect_url=reverse('dashboard'),
)
with waffle().override(PREVENT_AUTH_USER_WRITES, True):
response = self.client.get(reverse('activate', args=[self.registration.activation_key]), follow=True)
self.assertRedirects(response, login_page_url)
self.assertContains(response, SYSTEM_MAINTENANCE_MSG)
self._assert_user_active_state(expected_active_state=False)

View File

@@ -21,7 +21,6 @@ from edxmako.shortcuts import marketing_link, render_to_string
from openedx.core.djangoapps.ace_common.tests.mixins import EmailTemplateTagMixin
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme
from openedx.core.djangoapps.user_api.config.waffle import PREVENT_AUTH_USER_WRITES, SYSTEM_MAINTENANCE_MSG, waffle
from openedx.core.djangolib.testing.utils import CacheIsolationMixin, CacheIsolationTestCase
from openedx.core.lib.request_utils import safe_get_host
from student.models import PendingEmailChange, Registration, UserProfile
@@ -513,14 +512,6 @@ class EmailChangeConfirmationTests(EmailTestMixin, EmailTemplateTagMixin, CacheI
)
self.assertEqual(0, PendingEmailChange.objects.count())
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', "Test only valid in LMS")
def test_prevent_auth_user_writes(self):
with waffle().override(PREVENT_AUTH_USER_WRITES, True):
self.check_confirm_email_change('email_change_failed.html', {
'err_msg': SYSTEM_MAINTENANCE_MSG
})
self.assertRolledBack()
@patch('student.views.PendingEmailChange.objects.get', Mock(side_effect=TestException))
def test_always_rollback(self):
connection = transaction.get_connection()

View File

@@ -49,7 +49,6 @@ from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY
from openedx.core.djangoapps.programs.models import ProgramsApiConfig
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from openedx.core.djangoapps.theming import helpers as theming_helpers
from openedx.core.djangoapps.user_api.config.waffle import PREVENT_AUTH_USER_WRITES, SYSTEM_MAINTENANCE_MSG, waffle
from openedx.core.djangoapps.user_api.preferences import api as preferences_api
from openedx.core.djangolib.markup import HTML, Text
from student.helpers import DISABLE_UNENROLL_CERT_STATES, cert_info, generate_activation_email_context
@@ -520,16 +519,6 @@ def activate_account(request, key):
),
extra_tags='account-activation aa-icon',
)
elif waffle().is_enabled(PREVENT_AUTH_USER_WRITES):
messages.error(
request,
HTML(u'{html_start}{message}{html_end}').format(
message=Text(SYSTEM_MAINTENANCE_MSG),
html_start=HTML('<p class="message-title">'),
html_end=HTML('</p>'),
),
extra_tags='account-activation aa-icon',
)
else:
registration.activate()
# Success message for logged in users.
@@ -572,9 +561,6 @@ def activate_account_studio(request, key):
user_logged_in = request.user.is_authenticated
already_active = True
if not registration.user.is_active:
if waffle().is_enabled(PREVENT_AUTH_USER_WRITES):
return render_to_response('registration/activation_invalid.html',
{'csrf': csrf(request)['csrf_token']})
registration.activate()
already_active = False
@@ -739,9 +725,6 @@ def confirm_email_change(request, key): # pylint: disable=unused-argument
User requested a new e-mail. This is called when the activation
link is clicked. We confirm with the old e-mail, and update
"""
if waffle().is_enabled(PREVENT_AUTH_USER_WRITES):
return render_to_response('email_change_failed.html', {'err_msg': SYSTEM_MAINTENANCE_MSG})
with transaction.atomic():
try:
pec = PendingEmailChange.objects.get(activation_key=key)

View File

@@ -11,7 +11,6 @@ SYSTEM_MAINTENANCE_MSG = _(u'System maintenance in progress. Please try again la
WAFFLE_NAMESPACE = u'user_api'
# Switches
PREVENT_AUTH_USER_WRITES = u'prevent_auth_user_writes'
ENABLE_MULTIPLE_USER_ENTERPRISES_FEATURE = u'enable_multiple_user_enterprises_feature'

View File

@@ -34,7 +34,6 @@ from openedx.core.djangoapps.site_configuration import helpers as configuration_
from openedx.core.djangoapps.theming.helpers import get_current_request, get_current_site
from openedx.core.djangoapps.user_api import accounts, errors, helpers
from openedx.core.djangoapps.user_api.accounts.utils import is_secondary_email_feature_enabled
from openedx.core.djangoapps.user_api.config.waffle import PREVENT_AUTH_USER_WRITES, SYSTEM_MAINTENANCE_MSG, waffle
from openedx.core.djangoapps.user_api.helpers import FormDescription
from openedx.core.djangoapps.user_api.models import UserRetirementRequest
from openedx.core.djangoapps.user_api.preferences.api import get_user_preference
@@ -367,22 +366,6 @@ class PasswordResetConfirmWrapper(PasswordResetConfirmView):
request, 'registration/password_reset_confirm.html', context
)
def _handle_system_unavailability(self, request):
"""
method to stop password reset process if system is under maintenance
"""
context = {
'validlink': False,
'form': None,
'title': _('Password reset unsuccessful'),
'err_msg': SYSTEM_MAINTENANCE_MSG,
}
context.update(self.platform_name)
return TemplateResponse(
request, 'registration/password_reset_confirm.html', context
)
def _validate_password(self, password, request):
try:
validate_password(password, user=self.user)
@@ -493,8 +476,6 @@ class PasswordResetConfirmWrapper(PasswordResetConfirmView):
return response
if UserRetirementRequest.has_user_requested_retirement(self.user):
return self._handle_retired_user(self.request)
if waffle().is_enabled(PREVENT_AUTH_USER_WRITES):
return self._handle_system_unavailability(self.request)
if self.request.method == 'POST':
return self.post(self.request, *args, **kwargs)

View File

@@ -25,7 +25,6 @@ from openedx.core.djangoapps.password_policy.compliance import (
NonCompliantPasswordException,
NonCompliantPasswordWarning
)
from openedx.core.djangoapps.user_api.config.waffle import PREVENT_AUTH_USER_WRITES, waffle
from openedx.core.djangoapps.user_api.accounts import EMAIL_MIN_LENGTH, EMAIL_MAX_LENGTH
from openedx.core.djangoapps.user_authn.cookies import jwt_cookies
from openedx.core.djangoapps.user_authn.views.login import (

View File

@@ -29,7 +29,6 @@ from six.moves import range
from openedx.core.djangoapps.oauth_dispatch.tests import factories as dot_factories
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from openedx.core.djangolib.testing.utils import skip_unless_lms
from openedx.core.djangoapps.user_api.config.waffle import PREVENT_AUTH_USER_WRITES, SYSTEM_MAINTENANCE_MSG, waffle
from openedx.core.djangoapps.user_api.models import UserRetirementRequest
from openedx.core.djangoapps.user_api.tests.test_views import UserAPITestCase
from openedx.core.djangoapps.user_api.accounts import EMAIL_MAX_LENGTH, EMAIL_MIN_LENGTH
@@ -384,19 +383,6 @@ class ResetPasswordTests(EventTestMixin, CacheIsolationTestCase):
self.assertEqual(resp.status_code, 200)
self.assertFalse(User.objects.get(pk=self.user.pk).is_active)
def test_password_reset_prevent_auth_user_writes(self):
with waffle().override(PREVENT_AUTH_USER_WRITES, True):
url = reverse(
"password_reset_confirm",
kwargs={"uidb36": self.uidb36, "token": self.token}
)
for request in [self.request_factory.get(url), self.request_factory.post(url)]:
request.user = self.user
response = PasswordResetConfirmWrapper.as_view()(request, uidb36=self.uidb36, token=self.token)
assert response.context_data['err_msg'] == SYSTEM_MAINTENANCE_MSG
self.user.refresh_from_db()
assert not self.user.is_active
def test_password_reset_normalize_password(self):
# pylint: disable=anomalous-unicode-escape-in-string
"""