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)