From 6f36171218b9b682e30c59a0322189a108b569a9 Mon Sep 17 00:00:00 2001 From: anastasia Date: Thu, 10 Aug 2017 19:00:51 -0400 Subject: [PATCH 1/4] update - passing email of user that has requested a registrar account. Reworded email text to perma.cc for more clarity --- .../perma/templates/email/admin/registrar_request.txt | 3 ++- perma_web/perma/views/user_management.py | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/perma_web/perma/templates/email/admin/registrar_request.txt b/perma_web/perma/templates/email/admin/registrar_request.txt index 18c86e951..d7e348b36 100644 --- a/perma_web/perma/templates/email/admin/registrar_request.txt +++ b/perma_web/perma/templates/email/admin/registrar_request.txt @@ -1,3 +1,4 @@ -A new library account request from {{ name }} ({{ email }}) is awaiting review and approval. +A new library account request from pending registrar, named {{ name }} (at {{ email }}) is awaiting review and approval. +Requesting user's email: {{ requested_by_email }} http://{{ host }}{{ confirmation_route}} diff --git a/perma_web/perma/views/user_management.py b/perma_web/perma/views/user_management.py index 88e189780..25e6bc56a 100755 --- a/perma_web/perma/views/user_management.py +++ b/perma_web/perma/views/user_management.py @@ -1484,6 +1484,12 @@ def email_registrar_request(request, pending_registrar): Send email to Perma.cc admins when a library requests an account """ host = request.get_host() + try: + email = request.user.email + except AttributeError: + # User did not have an account + email = request.POST.get('a-email') + send_admin_email( "Perma.cc new library registrar account request", pending_registrar.email, @@ -1492,6 +1498,7 @@ def email_registrar_request(request, pending_registrar): { "name": pending_registrar.name, "email": pending_registrar.email, + "requested_by_email": email, "host": host, "confirmation_route": reverse('user_management_approve_pending_registrar', args=[pending_registrar.id]) } From 57b6b6b51227432410667776259fefa2341f6c0d Mon Sep 17 00:00:00 2001 From: anastasia Date: Thu, 10 Aug 2017 19:01:08 -0400 Subject: [PATCH 2/4] clean - spacing --- perma_web/perma/views/user_management.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/perma_web/perma/views/user_management.py b/perma_web/perma/views/user_management.py index 25e6bc56a..401c1b9ba 100755 --- a/perma_web/perma/views/user_management.py +++ b/perma_web/perma/views/user_management.py @@ -1235,12 +1235,12 @@ def libraries(request): request_data = request.session.get('request_data','') user_form = None if not request.user.is_authenticated(): - user_form = UserForm(prefix = "a") + user_form = UserForm(prefix="a") user_form.fields['email'].label = "Your email" if request_data: - registrar_form = LibraryRegistrarForm(request_data, prefix ="b") + registrar_form = LibraryRegistrarForm(request_data, prefix="b") else: - registrar_form = LibraryRegistrarForm(prefix ="b") + registrar_form = LibraryRegistrarForm(prefix="b") return render(request, "registration/sign-up-libraries.html", {'user_form':user_form, 'registrar_form':registrar_form}) From 94054b17a93d94d553433016ebb6db0466bf4e56 Mon Sep 17 00:00:00 2001 From: anastasia Date: Thu, 10 Aug 2017 19:50:21 -0400 Subject: [PATCH 3/4] add - test to make sure we're sending requesting user's email along to perma admin --- perma_web/perma/tests/test_views_user_management.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/perma_web/perma/tests/test_views_user_management.py b/perma_web/perma/tests/test_views_user_management.py index 468d03c91..1dc71aa6c 100644 --- a/perma_web/perma/tests/test_views_user_management.py +++ b/perma_web/perma/tests/test_views_user_management.py @@ -1009,7 +1009,7 @@ def check_lib_user_labels(self, soup): email_label = soup.find('label', {'for': 'id_a-email'}) self.assertEqual(email_label.text, "Your email") - def check_lib_email(self, message, new_lib): + def check_lib_email(self, message, new_lib, user): our_address = settings.DEFAULT_FROM_EMAIL self.assertIn(new_lib['name'], message.body) @@ -1017,6 +1017,7 @@ def check_lib_email(self, message, new_lib): id = Registrar.objects.get(email=new_lib['email']).id approve_url = "http://testserver{}".format(reverse('user_management_approve_pending_registrar', args=[id])) self.assertIn(approve_url, message.body) + self.assertIn(user['email'], message.body) self.assertEqual(message.subject, "Perma.cc new library registrar account request") self.assertEqual(message.from_email, our_address) self.assertEqual(message.recipients(), [our_address]) @@ -1120,7 +1121,7 @@ def test_new_library_submit_success(self): success_url=reverse('register_library_instructions')) expected_emails_sent += 2 self.assertEqual(len(mail.outbox), expected_emails_sent) - self.check_lib_email(mail.outbox[expected_emails_sent - 2], new_lib) + self.check_lib_email(mail.outbox[expected_emails_sent - 2], new_lib, new_lib_user) self.check_lib_user_email(mail.outbox[expected_emails_sent - 1], new_lib_user) # Not logged in, submit all fields including first and last name @@ -1136,7 +1137,7 @@ def test_new_library_submit_success(self): success_url=reverse('register_library_instructions')) expected_emails_sent += 2 self.assertEqual(len(mail.outbox), expected_emails_sent) - self.check_lib_email(mail.outbox[expected_emails_sent - 2], new_lib) + self.check_lib_email(mail.outbox[expected_emails_sent - 2], new_lib, new_lib_user) self.check_lib_user_email(mail.outbox[expected_emails_sent - 1], new_lib_user) # Logged in @@ -1150,7 +1151,7 @@ def test_new_library_submit_success(self): user=existing_lib_user['email']) expected_emails_sent += 1 self.assertEqual(len(mail.outbox), expected_emails_sent) - self.check_lib_email(mail.outbox[expected_emails_sent - 1], new_lib) + self.check_lib_email(mail.outbox[expected_emails_sent - 1], new_lib, existing_lib_user) def test_new_library_submit_failure(self): ''' From 19c18b0e066b47330b8dfc02b472e29da3411035 Mon Sep 17 00:00:00 2001 From: anastasia Date: Fri, 11 Aug 2017 10:20:12 -0400 Subject: [PATCH 4/4] fix - reply-to email is the requesting user's email instead of pending registrar's email --- perma_web/perma/tests/test_views_user_management.py | 6 ++++-- perma_web/perma/views/user_management.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/perma_web/perma/tests/test_views_user_management.py b/perma_web/perma/tests/test_views_user_management.py index 1dc71aa6c..2e3c0cf0e 100644 --- a/perma_web/perma/tests/test_views_user_management.py +++ b/perma_web/perma/tests/test_views_user_management.py @@ -1014,14 +1014,16 @@ def check_lib_email(self, message, new_lib, user): self.assertIn(new_lib['name'], message.body) self.assertIn(new_lib['email'], message.body) + + self.assertIn(user['email'], message.body) + id = Registrar.objects.get(email=new_lib['email']).id approve_url = "http://testserver{}".format(reverse('user_management_approve_pending_registrar', args=[id])) self.assertIn(approve_url, message.body) - self.assertIn(user['email'], message.body) self.assertEqual(message.subject, "Perma.cc new library registrar account request") self.assertEqual(message.from_email, our_address) self.assertEqual(message.recipients(), [our_address]) - self.assertDictEqual(message.extra_headers, {'Reply-To': new_lib['email']}) + self.assertDictEqual(message.extra_headers, {'Reply-To': user['email']}) def check_lib_user_email(self, message, new_lib_user): our_address = settings.DEFAULT_FROM_EMAIL diff --git a/perma_web/perma/views/user_management.py b/perma_web/perma/views/user_management.py index 401c1b9ba..e1828a238 100755 --- a/perma_web/perma/views/user_management.py +++ b/perma_web/perma/views/user_management.py @@ -1492,7 +1492,7 @@ def email_registrar_request(request, pending_registrar): send_admin_email( "Perma.cc new library registrar account request", - pending_registrar.email, + email, request, 'email/admin/registrar_request.txt', {