Skip to content

Commit

Permalink
Merge pull request #2096 from anastasia/registrar-requested-by
Browse files Browse the repository at this point in the history
Registrar requested by
  • Loading branch information
rebeccacremona authored Aug 11, 2017
2 parents cca2ddb + 19c18b0 commit cae4475
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
3 changes: 2 additions & 1 deletion perma_web/perma/templates/email/admin/registrar_request.txt
Original file line number Diff line number Diff line change
@@ -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}}
13 changes: 8 additions & 5 deletions perma_web/perma/tests/test_views_user_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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):
'''
Expand Down
15 changes: 11 additions & 4 deletions perma_web/perma/views/user_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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])
}
Expand Down

0 comments on commit cae4475

Please sign in to comment.