Verified Commit a13abe14 authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Fix race condition in save

parent c19fde14
......@@ -155,6 +155,11 @@ class RegistrationAdmin(admin.ModelAdmin):
"""Does the user have the review permission?"""
return request.user.has_perm('registrations.review_entries')
def has_change_permission(self, request, obj=None):
if (obj and obj.status == Registration.STATUS_REVIEW) or not obj:
return super().has_change_permission(request, obj)
return False
@admin.register(Renewal)
class RenewalAdmin(RegistrationAdmin):
......
......@@ -202,17 +202,20 @@ class RegistrationTest(TestCase):
membership_type=Membership.MEMBER,
)
self.assertEqual(len(mail.outbox), 1)
confirm_url = '{}{}'.format('https://thalia.nu',
reverse('registrations:confirm-email',
args=[registration.pk]))
self.assertTrue(confirm_url in mail.outbox[0].body)
mail.outbox.clear()
registration.status = Entry.STATUS_REVIEW
registration.save()
self.assertEqual(len(mail.outbox), 0)
with self.subTest(f'Create confirmation mail'
f'on save with status confirm'):
self.assertEqual(len(mail.outbox), 1)
confirm_url = '{}{}'.format('https://thalia.nu',
reverse('registrations:confirm-email',
args=[registration.pk]))
self.assertTrue(confirm_url in mail.outbox[0].body)
mail.outbox.clear()
with self.subTest('No emails in outbox when status is not confirm'):
registration.status = Entry.STATUS_REVIEW
registration.save()
self.assertEqual(len(mail.outbox), 0)
class RenewalTest(TestCase):
......
Supports Markdown
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