Commit 50bdf5d4 authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg Committed by Thom Wiggers

Add resend confirmation email button to admin

parent 7934cff3
......@@ -5,6 +5,7 @@ from django.forms import Field
from django.utils.html import format_html
from django.utils.translation import ugettext_lazy as _
from members.models import Membership
from payments.widgets import PaymentWidget
from . import services
from .models import Entry, Registration, Renewal
......@@ -81,13 +82,22 @@ class RegistrationAdmin(admin.ModelAdmin):
Only allow when the entry has not been processed yet
"""
obj = None
can_review = False
can_resend = False
if (object_id is not None and
request.user.has_perm('registrations.review_entries')):
obj = Entry.objects.get(id=object_id)
if not (obj.status == Entry.STATUS_REVIEW):
obj = None
can_review = obj.status == Entry.STATUS_REVIEW
try:
can_resend = obj.registration.status == Entry.STATUS_CONFIRM
except Registration.DoesNotExist:
pass
return super().changeform_view(
request, object_id, form_url, {'entry': obj})
request, object_id, form_url, {
'entry': obj,
'can_review': can_review,
'can_resend': can_resend,
})
def get_actions(self, request):
"""
......
This diff was suppressed by a .gitattributes entry.
......@@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-09-28 14:01+0200\n"
"PO-Revision-Date: 2018-09-28 14:02+0200\n"
"POT-Creation-Date: 2018-10-03 19:39+0200\n"
"PO-Revision-Date: 2018-10-03 19:40+0200\n"
"Last-Translator: Sébastiaan Versteeg <se_bastiaan@outlook.com>\n"
"Language-Team: \n"
"Language: nl\n"
......@@ -264,14 +264,14 @@ msgstr ""
"Er bestaat al een gebruiker met dit studentnummer. Login met het bestaande "
"account en vernieuw het lidmaatschap in de accountinstellingen."
#: models.py
msgid "A user with that username already exists."
msgstr "Er bestaat al een gebruiker met deze gebruikersnaam."
#: models.py
msgid "This field is required."
msgstr "Dit veld is verplicht."
#: models.py
msgid "A user with that username already exists."
msgstr "Er bestaat al een gebruiker met deze gebruikersnaam."
#: models.py templates/registrations/confirm_email.html
#: templates/registrations/register_member.html
#: templates/registrations/register_success.html
......@@ -312,6 +312,10 @@ msgstr "verlenging"
msgid "renewals"
msgstr "verlenging"
#: templates/admin/registrations/change_form.html
msgid "Resend confirmation email"
msgstr "Verstuur bevestigingsmail opnieuw"
#: templates/admin/registrations/change_form.html
msgid "Accept"
msgstr "Goedkeuren"
......
......@@ -12,10 +12,15 @@
{% endblock %}
{% block submit_buttons_bottom %}
{% if entry %}
{% if can_resend or can_review %}
<div class="submit-row registrations-row">
<a data-href="{% url 'registrations:admin-process' pk=entry.pk %}" class="button accept" data-action="accept">{% trans "Accept" %}</a>
<a data-href="{% url 'registrations:admin-process' pk=entry.pk %}" class="button reject" data-action="reject">{% trans "Reject" %}</a>
{% if can_resend %}
<a data-href="{% url 'registrations:admin-process' pk=entry.pk %}" class="button" data-action="resend">{% trans "Resend confirmation email" %}</a>
{% endif %}
{% if can_review %}
<a data-href="{% url 'registrations:admin-process' pk=entry.pk %}" class="button accept" data-action="accept">{% trans "Accept" %}</a>
<a data-href="{% url 'registrations:admin-process' pk=entry.pk %}" class="button reject" data-action="reject">{% trans "Reject" %}</a>
{% endif %}
</div>
{% endif %}
......
......@@ -6,6 +6,7 @@ from django.contrib.admin import AdminSite
from django.contrib.admin.utils import model_ngettext
from django.http import HttpRequest
from django.test import SimpleTestCase, TestCase
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from members.models import Member
......@@ -45,6 +46,7 @@ class GlobalAdminTest(SimpleTestCase):
class RegistrationAdminTest(TestCase):
fixtures = ['members.json']
def setUp(self):
self.site = AdminSite()
......@@ -58,40 +60,90 @@ class RegistrationAdminTest(TestCase):
object_id = None
form_url = 'form://url'
entry = Entry(status=Entry.STATUS_REVIEW)
registration = Registration.objects.create(
status=Entry.STATUS_REVIEW,
birthday=timezone.now()
)
entry = registration.entry_ptr
entry_get.return_value = entry
self.admin.changeform_view(request, object_id, form_url)
self.assertFalse(entry_get.called)
super_method.assert_called_once_with(request, object_id, form_url, {
'entry': None
'entry': None,
'can_review': False,
'can_resend': False,
})
super_method.reset_mock()
entry_get.reset_mock()
request = _get_mock_request(perms=['registrations.review_entries'])
self.admin.changeform_view(request, object_id, form_url)
self.assertFalse(entry_get.called)
super_method.assert_called_once_with(request, object_id, form_url, {
'entry': None
'entry': None,
'can_review': False,
'can_resend': False,
})
super_method.reset_mock()
entry_get.reset_mock()
object_id = entry.pk
self.admin.changeform_view(request, object_id, form_url)
self.assertTrue(entry_get.called)
super_method.assert_called_once_with(request, object_id, form_url, {
'entry': entry,
'can_review': True,
'can_resend': False,
})
super_method.reset_mock()
object_id = 1
entry_get.reset_mock()
registration.status = Entry.STATUS_CONFIRM
registration.save()
entry = registration.entry_ptr
entry_get.return_value = entry
self.admin.changeform_view(request, object_id, form_url)
self.assertTrue(entry_get.called)
super_method.assert_called_once_with(request, object_id, form_url, {
'entry': entry
'entry': entry,
'can_review': False,
'can_resend': True,
})
super_method.reset_mock()
entry.status = Entry.STATUS_ACCEPTED
entry_get.reset_mock()
registration.status = Entry.STATUS_ACCEPTED
registration.save()
entry = registration.entry_ptr
entry_get.return_value = entry
self.admin.changeform_view(request, object_id, form_url)
self.assertTrue(entry_get.called)
super_method.assert_called_once_with(request, object_id, form_url, {
'entry': entry,
'can_review': False,
'can_resend': False,
})
super_method.reset_mock()
renewal = Renewal.objects.create(
status=Entry.STATUS_REVIEW,
member=Member.objects.filter(last_name="Wiggers").first()
)
entry = renewal.entry_ptr
entry_get.return_value = entry
object_id = entry.pk
self.admin.changeform_view(request, object_id, form_url)
self.assertTrue(entry_get.called)
super_method.assert_called_once_with(request, object_id, form_url, {
'entry': None
'entry': entry,
'can_review': True,
'can_resend': False,
})
@mock.patch('registrations.services.accept_entries')
......
......@@ -106,7 +106,7 @@ class EntryAdminViewTest(TestCase):
@mock.patch('registrations.services.check_unique_user')
@mock.patch('registrations.services.accept_entries')
@mock.patch('registrations.services.reject_entries')
def test_get_accept(self, reject_entries, accept_entries,
def test_post_accept(self, reject_entries, accept_entries,
check_unique_user):
self.view.action = 'accept'
for type, entry in {
......@@ -162,7 +162,7 @@ class EntryAdminViewTest(TestCase):
@mock.patch('registrations.services.accept_entries')
@mock.patch('registrations.services.reject_entries')
def test_get_reject(self, reject_entries, accept_entries):
def test_post_reject(self, reject_entries, accept_entries):
self.view.action = 'reject'
for type, entry in {
'registration': self.entry1,
......@@ -205,8 +205,39 @@ class EntryAdminViewTest(TestCase):
messages.ERROR, _('Could not reject %s.') %
model_ngettext(entry_qs.all()[0], 1), '')
@mock.patch('registrations.emails.send_registration_email_confirmation')
def test_post_resend(self, send_email):
self.view.action = 'resend'
for type, entry in {
'registration': self.entry1,
'renewal': self.entry2
}.items():
entry_qs = Entry.objects.filter(pk=entry.pk)
send_email.reset_mock()
send_email.return_value = None
with mock.patch('registrations.models.Entry.objects.filter') as qs_mock:
qs_mock.return_value = entry_qs
qs_mock.get = Mock(return_value=entry_qs.get())
request = _get_mock_request()
request.POST = {
'action': 'resend',
}
response = self.view.post(request, pk=entry.pk)
self.assertEqual(response.status_code, 302)
self.assertEqual(
response.url,
'/admin/registrations/%s/%s/change/' % (type, entry.pk)
)
if type == 'registration':
send_email.assert_called_once_with(entry)
elif type == 'renewal':
send_email.assert_not_called()
@mock.patch('registrations.models.Entry.objects.filter')
def test_get_not_exists(self, qs_mock):
def test_post_not_exists(self, qs_mock):
qs_mock.return_value = MagicMock(
get=Mock(
side_effect=Entry.DoesNotExist,
......@@ -222,7 +253,7 @@ class EntryAdminViewTest(TestCase):
@mock.patch('registrations.services.accept_entries')
@mock.patch('registrations.services.reject_entries')
def test_get_no_action(self, reject_entries, accept_entries):
def test_post_no_action(self, reject_entries, accept_entries):
self.view.action = None
for type, entry in {
'registration': self.entry1,
......
......@@ -40,7 +40,7 @@ class BecomeAMemberView(TemplateView):
name='dispatch', )
class EntryAdminView(View):
"""
View that handles the review processing of entries
View that handles the processing of entries
"""
def post(self, request, *args, **kwargs):
......@@ -69,6 +69,11 @@ class EntryAdminView(View):
else:
messages.error(request, _('Could not reject %s.') %
model_ngettext(entry, 1))
elif action == 'resend':
try:
emails.send_registration_email_confirmation(entry.registration)
except Registration.DoesNotExist:
pass
if entry_qs.filter(renewal=None).exists():
content_type = ContentType.objects.get_for_model(Registration)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment