Commit d009911c authored by Thom Wiggers's avatar Thom Wiggers 📐
Browse files

Merge branch 'tc/process-registrations-post' into 'master'

Change registrations processing to using POST

See merge request !915
parents 9147b8a4 a0ba97a7
function confirmRegChange(e) {
var confirmTxt = gettext("Are you sure you want to excecute this action? Be warned that this doesn't save the form.");
return confirm(confirmTxt);
}
django.jQuery(function () {
var $ = django.jQuery;
$(".registrations-row a").click(function(e) {
e.preventDefault();
var confirmTxt = gettext("Are you sure you want to excecute this action? Be warned that this doesn't save the form.");
var didConfirm = confirm(confirmTxt);
if(didConfirm) {
var action = $(e.target).data('action');
var href = $(e.target).data('href');
var form = $('<form></form>');
form.attr("method", "post");
form.attr("action", href);
var field = $('<input/>');
field.attr("type", "hidden");
field.attr("name", 'action');
field.attr("value", action);
form.append(field);
var csrf = $('<input/>');
csrf.attr("type", "hidden");
csrf.attr("name", 'csrfmiddlewaretoken');
csrf.attr("value", $("input[name='csrfmiddlewaretoken']").val());
form.append(csrf);
$(document.body).append(form);
form.submit();
}
return false;
});
});
......@@ -14,8 +14,8 @@
{% block submit_buttons_bottom %}
{% if entry %}
<div class="submit-row registrations-row">
<a href="{% url 'registrations:admin-accept' pk=entry.pk %}" class="button accept" onclick="return confirmRegChange();">{% trans "Accept" %}</a>
<a href="{% url 'registrations:admin-reject' pk=entry.pk %}" class="button reject" onclick="return confirmRegChange()">{% trans "Reject" %}</a>
<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>
</div>
{% endif %}
......
......@@ -90,14 +90,14 @@ class EntryAdminViewTest(TestCase):
self.client.force_login(self.user)
def test_permissions(self):
url = '/registration/admin/accept/{}/'.format(self.entry1.pk)
response = self.client.get(url)
url = '/registration/admin/process/{}/'.format(self.entry1.pk)
response = self.client.post(url)
self.assertRedirects(response, '/admin/login/?next=%s' % url)
self._give_user_permissions()
url = '/registration/admin/accept/{}/'.format(self.entry1.pk)
response = self.client.get(url)
url = '/registration/admin/process/{}/'.format(self.entry1.pk)
response = self.client.post(url)
self.assertRedirects(
response,
'/admin/registrations/registration/%s/change/' % self.entry1.pk
......@@ -126,7 +126,10 @@ class EntryAdminViewTest(TestCase):
qs_mock.get = Mock(return_value=entry_qs.get())
request = _get_mock_request()
response = self.view.get(request, pk=entry.pk)
request.POST = {
'action': 'accept',
}
response = self.view.post(request, pk=entry.pk)
self.assertEqual(response.status_code, 302)
self.assertEqual(
......@@ -142,7 +145,7 @@ class EntryAdminViewTest(TestCase):
model_ngettext(entry_qs.all()[0], 1), '')
accept_entries.return_value = 0
self.view.get(request, pk=entry.pk)
self.view.post(request, pk=entry.pk)
request._messages.add.assert_any_call(
messages.ERROR, _('Could not accept %s.') %
......@@ -150,7 +153,7 @@ class EntryAdminViewTest(TestCase):
accept_entries.return_value = 1
check_unique_user.return_value = False
self.view.get(request, pk=entry.pk)
self.view.post(request, pk=entry.pk)
request._messages.add.assert_any_call(
messages.ERROR, _('Could not accept %s. '
......@@ -176,7 +179,10 @@ class EntryAdminViewTest(TestCase):
qs_mock.get = Mock(return_value=entry_qs.get())
request = _get_mock_request()
response = self.view.get(request, pk=entry.pk)
request.POST = {
'action': 'reject',
}
response = self.view.post(request, pk=entry.pk)
self.assertEqual(response.status_code, 302)
......@@ -193,7 +199,7 @@ class EntryAdminViewTest(TestCase):
model_ngettext(entry_qs.all()[0], 1), '')
reject_entries.return_value = 0
self.view.get(request, pk=entry.pk)
self.view.post(request, pk=entry.pk)
request._messages.add.assert_any_call(
messages.ERROR, _('Could not reject %s.') %
......@@ -209,7 +215,7 @@ class EntryAdminViewTest(TestCase):
)
request = _get_mock_request()
response = self.view.get(request, pk=4)
response = self.view.post(request, pk=4)
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, reverse('admin:index'))
......@@ -233,7 +239,7 @@ class EntryAdminViewTest(TestCase):
qs_mock.get = Mock(return_value=entry_qs.get())
request = _get_mock_request()
response = self.view.get(request, pk=entry.pk)
response = self.view.post(request, pk=entry.pk)
self.assertFalse(reject_entries.called)
self.assertFalse(accept_entries.called)
......
......@@ -18,12 +18,8 @@ urlpatterns = [
path('renew/success/', TemplateView.as_view(
template_name='registrations/renewal_success.html'),
name='renew-success'),
path('admin/accept/<uuid:pk>/',
EntryAdminView.as_view(action='accept'),
name='admin-accept'),
path('admin/reject/<uuid:pk>/',
EntryAdminView.as_view(action='reject'),
name='admin-reject'),
path('admin/process/<uuid:pk>/', EntryAdminView.as_view(),
name='admin-process'),
path('confirm-email/<uuid:pk>/',
ConfirmEmailView.as_view(), name='confirm-email'),
]
......@@ -42,16 +42,16 @@ class EntryAdminView(View):
"""
View that handles the review processing of entries
"""
action = None
def get(self, request, *args, **kwargs):
def post(self, request, *args, **kwargs):
action = request.POST.get('action')
entry_qs = Entry.objects.filter(pk=kwargs['pk'])
try:
entry = entry_qs.get()
except Entry.DoesNotExist:
return redirect('admin:index')
if self.action == 'accept':
if action == 'accept':
if not services.check_unique_user(entry):
messages.error(request, _('Could not accept %s. '
'Username is not unique.') %
......@@ -62,7 +62,7 @@ class EntryAdminView(View):
else:
messages.error(request, _('Could not accept %s.') %
model_ngettext(entry, 1))
elif self.action == 'reject':
elif action == 'reject':
if services.reject_entries(entry_qs) > 0:
messages.success(request, _('Successfully rejected %s.') %
model_ngettext(entry, 1))
......
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