disabled activation email

This commit is contained in:
irfanuddinahmad
2018-06-19 19:02:14 +05:00
parent cf6e2d9f89
commit ead8a78e29
2 changed files with 51 additions and 7 deletions

View File

@@ -150,6 +150,32 @@ class ActivationEmailTests(CacheIsolationTestCase):
for fragment in body_fragments:
self.assertIn(fragment, msg.body)
def test_do_not_send_email_and_do_activate(self):
"""
Tests that when an inactive user logs-in using the social auth,
an activation email is not sent.
"""
pipeline_partial = {
'kwargs': {
'social': {
'uid': 'fake uid'
}
}
}
user = UserFactory(is_active=False)
Registration().register(user)
request = RequestFactory().get(settings.SOCIAL_AUTH_INACTIVE_USER_URL)
request.user = user
with patch('student.views.management.compose_and_send_activation_email') as email:
with patch('third_party_auth.provider.Registry.get_from_pipeline') as reg:
with patch('third_party_auth.pipeline.get', return_value=pipeline_partial):
with patch('third_party_auth.pipeline.running', return_value=True):
with patch('third_party_auth.is_enabled', return_value=True):
reg.skip_email_verification = True
inactive_user_view(request)
self.assertEquals(user.is_active, True)
self.assertEquals(email.called, False, msg='method should not have been called')
@patch('student.tasks.log')
def test_send_email_to_inactive_user(self, mock_log):
"""
@@ -161,12 +187,13 @@ class ActivationEmailTests(CacheIsolationTestCase):
request = RequestFactory().get(settings.SOCIAL_AUTH_INACTIVE_USER_URL)
request.user = inactive_user
with patch('edxmako.request_context.get_current_request', return_value=request):
inactive_user_view(request)
mock_log.info.assert_called_with(
"Activation Email has been sent to User {user_email}".format(
user_email=inactive_user.email
with patch('third_party_auth.pipeline.running', return_value=False):
inactive_user_view(request)
mock_log.info.assert_called_with(
"Activation Email has been sent to User {user_email}".format(
user_email=inactive_user.email
)
)
)
@patch('student.views.login.render_to_string', Mock(side_effect=mock_render_to_string, autospec=True))

View File

@@ -12,6 +12,8 @@ from social_core.utils import setting_name
from student.models import UserProfile
from student.views import compose_and_send_activation_email
import third_party_auth
from third_party_auth import pipeline, provider
from .models import SAMLConfiguration, SAMLProviderConfig
@@ -27,12 +29,27 @@ def inactive_user_view(request):
The reason this view exists is that if we don't define this as the
SOCIAL_AUTH_INACTIVE_USER_URL, inactive users will get sent to LOGIN_ERROR_URL, which we
don't want.
If the third_party_provider.skip_email_verification is set then the user is activated
and verification email is not sent
"""
# 'next' may be set to '/account/finish_auth/.../' if this user needs to be auto-enrolled
# in a course. Otherwise, just redirect them to the dashboard, which displays a message
# about activating their account.
profile = UserProfile.objects.get(user=request.user)
compose_and_send_activation_email(request.user, profile)
user = request.user
profile = UserProfile.objects.get(user=user)
activated = user.is_active
# If the user is registering via 3rd party auth, track which provider they use
if third_party_auth.is_enabled() and pipeline.running(request):
running_pipeline = pipeline.get(request)
third_party_provider = provider.Registry.get_from_pipeline(running_pipeline)
if third_party_provider.skip_email_verification and not activated:
user.is_active = True
user.save()
activated = True
if not activated:
compose_and_send_activation_email(user, profile)
return redirect(request.GET.get('next', 'dashboard'))