This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git
The following commit(s) were added to refs/heads/develop by this push:
new cefc4a9 AIRAVATA-3537 Fix resending email verification link
cefc4a9 is described below
commit cefc4a97b86894c7bb45850f57b92d040e11e72b
Author: Marcus Christie <[email protected]>
AuthorDate: Fri Nov 5 17:40:10 2021 -0400
AIRAVATA-3537 Fix resending email verification link
---
.../0009_alter_emailverification_next.py | 18 ++++++++
django_airavata/apps/auth/models.py | 2 +-
django_airavata/apps/auth/tests/test_views.py | 52 ++++++++++++++++++++++
django_airavata/apps/auth/views.py | 2 +-
4 files changed, 72 insertions(+), 2 deletions(-)
diff --git
a/django_airavata/apps/auth/migrations/0009_alter_emailverification_next.py
b/django_airavata/apps/auth/migrations/0009_alter_emailverification_next.py
new file mode 100644
index 0000000..0b554e9
--- /dev/null
+++ b/django_airavata/apps/auth/migrations/0009_alter_emailverification_next.py
@@ -0,0 +1,18 @@
+# Generated by Django 3.2.8 on 2021-11-05 21:22
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('django_airavata_auth', '0008_auto_20210422_1838'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='emailverification',
+ name='next',
+ field=models.CharField(max_length=255, null=True),
+ ),
+ ]
diff --git a/django_airavata/apps/auth/models.py
b/django_airavata/apps/auth/models.py
index c8c0da3..b2c7b17 100644
--- a/django_airavata/apps/auth/models.py
+++ b/django_airavata/apps/auth/models.py
@@ -16,7 +16,7 @@ class EmailVerification(models.Model):
max_length=36, unique=True, default=uuid.uuid4)
created_date = models.DateTimeField(auto_now_add=True)
verified = models.BooleanField(default=False)
- next = models.CharField(max_length=255, blank=True)
+ next = models.CharField(max_length=255, null=True)
class EmailTemplate(models.Model):
diff --git a/django_airavata/apps/auth/tests/test_views.py
b/django_airavata/apps/auth/tests/test_views.py
index cb69338..384dfcf 100644
--- a/django_airavata/apps/auth/tests/test_views.py
+++ b/django_airavata/apps/auth/tests/test_views.py
@@ -2,6 +2,7 @@ from unittest.mock import patch
from urllib.parse import urlencode
from airavata.model.user.ttypes import UserProfile
+from django.contrib import messages
from django.contrib.auth.models import AnonymousUser
from django.contrib.messages.middleware import MessageMiddleware
from django.contrib.sessions.middleware import SessionMiddleware
@@ -246,3 +247,54 @@ class VerifyEmailViewTestCase(TestCase):
self.assertEqual(mail.outbox[0].from_email, f'"{PORTAL_TITLE}"
<{SERVER_EMAIL}>')
self.assertEqual(len(mail.outbox[0].to), 1)
self.assertEqual(mail.outbox[0].to[0], '"Gateway Admin"
<[email protected]>')
+
+
+@override_settings(
+ GATEWAY_ID=GATEWAY_ID,
+ PORTAL_TITLE=PORTAL_TITLE,
+ SERVER_EMAIL=SERVER_EMAIL,
+ PORTAL_ADMINS=[('Gateway Admin', '[email protected]')]
+)
+class ResendEmailLinkTestCase(TestCase):
+
+ def setUp(self):
+ self.factory = RequestFactory()
+
+ @patch('django_airavata.apps.auth.views.iam_admin_client')
+ def test_resend_email_link(self, views_iam_admin_client):
+ data = {
+ 'username': 'testuser',
+ }
+ request =
self.factory.post(reverse('django_airavata_auth:resend_email_link'), data)
+ request.user = AnonymousUser()
+
+ views_iam_admin_client.is_user_exist.return_value = True
+ user_profile = UserProfile(
+ airavataInternalUserId=f"testuser@{GATEWAY_ID}",
+ userId="testuser",
+ firstName="Test",
+ lastName="User1",
+ emails=["[email protected]"]
+ )
+ views_iam_admin_client.get_user.return_value = user_profile
+
+ # RequestFactory doesn't load middleware so have to manually call
+ # SessionMiddleware and MessageMiddleware since create_account uses
+ # 'messages' framework
+ response = SessionMiddleware(MessageMiddleware(
+ lambda r: views.resend_email_link(r)
+ ))(request)
+
+ email_verification = models.EmailVerification.objects.get(
+ username="testuser")
+ self.assertFalse(email_verification.verified)
+ self.assertEqual(len(mail.outbox), 1)
+
+ self.assertIsInstance(response, HttpResponseRedirect)
+ self.assertEqual(reverse('django_airavata_auth:resend_email_link'),
response.url)
+
+ self.assertEqual(len(messages.get_messages(request)), 1)
+ # get the first/only message
+ for message in messages.get_messages(request):
+ pass
+ self.assertIn('Email verification link sent successfully',
str(message))
diff --git a/django_airavata/apps/auth/views.py
b/django_airavata/apps/auth/views.py
index 977f604..1817879 100644
--- a/django_airavata/apps/auth/views.py
+++ b/django_airavata/apps/auth/views.py
@@ -323,7 +323,7 @@ def resend_email_link(request):
def _create_and_send_email_verification_link(
- request, username, email, first_name, last_name, next):
+ request, username, email, first_name, last_name, next=None):
email_verification = models.EmailVerification(
username=username, next=next)