Commit e2b3889f authored by Luko van der Maas's avatar Luko van der Maas
Browse files

Merge branch 'fix/make-registrations-readonly-on-completed' into 'master'

Make registrations readonly on completed

Closes #690

See merge request !948
parents 11e098fc e5f15219
......@@ -102,7 +102,8 @@ class RegistrationAdmin(admin.ModelAdmin):
def get_readonly_fields(self, request, obj=None):
if obj is None or not (obj.status == Entry.STATUS_REJECTED or
obj.status == Entry.STATUS_ACCEPTED):
obj.status == Entry.STATUS_ACCEPTED or
obj.status == Entry.STATUS_COMPLETED):
return ['status', 'created_at', 'updated_at']
else:
return [field.name for field in self.model._meta.get_fields()
......
......@@ -184,6 +184,21 @@ class RegistrationAdminTest(TestCase):
'membership', 'optin_mailinglist',
'optin_birthday'])
fields = self.admin.get_readonly_fields(request, Registration(
status=Entry.STATUS_COMPLETED
))
self.assertCountEqual(fields, ['created_at', 'updated_at', 'status',
'length', 'membership_type', 'remarks',
'entry_ptr', 'username',
'first_name', 'last_name',
'birthday', 'language', 'email',
'phone_number', 'student_number',
'programme', 'starting_year',
'address_street', 'address_street2',
'address_postal_code', 'address_city',
'membership', 'optin_mailinglist',
'optin_birthday'])
def test_get_actions(self):
actions = self.admin.get_actions(_get_mock_request([]))
self.assertCountEqual(actions, ['delete_selected'])
......
......@@ -5,7 +5,7 @@ from django.core import mail
from django.core.exceptions import ValidationError
from django.test import TestCase
from django.urls import reverse
from django.utils import timezone
from django.utils import timezone, translation
from django.utils.translation import ugettext_lazy as _
from members.models import Member, Membership, Profile
......@@ -83,6 +83,7 @@ class RegistrationTest(TestCase):
)
def setUp(self):
translation.activate('en')
self.registration.refresh_from_db()
def test_str(self):
......@@ -156,7 +157,7 @@ class RegistrationTest(TestCase):
self.registration.programme = None
with self.assertRaisesMessage(
ValidationError,
"{'programme': ['Dit veld is vereist.']}"
"{'programme': ['This field is required.']}"
):
self.registration.clean()
self.registration.membership_type = Membership.SUPPORTER
......@@ -166,7 +167,7 @@ class RegistrationTest(TestCase):
self.registration.starting_year = None
with self.assertRaisesMessage(
ValidationError,
"{'starting_year': ['Dit veld is vereist.']}"
"{'starting_year': ['This field is required.']}"
):
self.registration.clean()
self.registration.membership_type = Membership.SUPPORTER
......
......@@ -308,26 +308,14 @@ class ConfirmEmailViewTest(TestCase):
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, '/registration/register/')
with self.subTest('Redirect when registration does not exist'):
with self.subTest('Redirect when registration confirm gives error'):
confirm_entry.side_effect = ValidationError(message='Error')
board_mail.side_effect = Registration.DoesNotExist
response = self.client.get(reverse(
'registrations:confirm-email', args=(self.entry.pk,)))
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, '/registration/register/')
with self.subTest('Redirect when entry does not exist'):
confirm_entry.return_value = 0
qs_mock.get.side_effect = Entry.DoesNotExist
response = self.client.get(reverse(
'registrations:confirm-email',
args=('00000000-0000-0000-0000-000000000000',)
))
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, '/registration/register/')
with self.subTest('Redirect when no entries were processed'):
confirm_entry.return_value = 0
......
......@@ -99,10 +99,7 @@ class ConfirmEmailView(View, TemplateResponseMixin):
if processed == 0:
return redirect('registrations:register')
try:
emails.send_new_registration_board_message(entry.get())
except Entry.DoesNotExist:
pass
emails.send_new_registration_board_message(entry.get())
return self.render_to_response({})
......
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