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/tests/test_views_user_management.py b/perma_web/perma/tests/test_views_user_management.py index 468d03c91..2e3c0cf0e 100644 --- a/perma_web/perma/tests/test_views_user_management.py +++ b/perma_web/perma/tests/test_views_user_management.py @@ -1009,18 +1009,21 @@ 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) 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.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 @@ -1120,7 +1123,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 +1139,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 +1153,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): ''' diff --git a/perma_web/perma/views/user_management.py b/perma_web/perma/views/user_management.py index 88e189780..e1828a238 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}) @@ -1484,14 +1484,21 @@ 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, + email, request, 'email/admin/registrar_request.txt', { "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]) }