-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#4321] Allow specific amount of submissions per form
- Loading branch information
Showing
21 changed files
with
531 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/openforms/forms/migrations/0107_form_submission_counter_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Generated by Django 4.2.16 on 2024-12-05 13:41 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("forms", "0106_convert_price_logic_rules"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="form", | ||
name="submission_counter", | ||
field=models.PositiveIntegerField( | ||
default=0, | ||
help_text="Counter to track how many submissions have been completed for the specific form. This works in combination with the maximum allowed submissions per form and can be reset via the frontend.", | ||
verbose_name="submissions counter", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="form", | ||
name="submission_maximum_allowed", | ||
field=models.PositiveIntegerField( | ||
blank=True, | ||
help_text="Maximum number of allowed submissions per form. Leave this empty if no limit is needed.", | ||
null=True, | ||
verbose_name="maximum allowed submissions", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
from django.contrib.auth.models import AnonymousUser | ||
from django.test import RequestFactory, TestCase | ||
from django.utils.translation import gettext as _ | ||
|
||
from hypothesis import given | ||
from hypothesis.extra.django import TestCase as HypothesisTestCase | ||
|
@@ -333,3 +334,47 @@ def test_patching_registrations_with_a_booboo(self): | |
self.assertEqual(backend2.name, "#2") | ||
self.assertEqual(backend2.backend, "email") | ||
self.assertEqual(backend2.options["to_emails"], ["[email protected]"]) | ||
|
||
def test_form_with_submission_max_and_submission_counter(self): | ||
context = {"request": None} | ||
|
||
with self.subTest("submission_max_allowed equal to submission_counter"): | ||
form = FormFactory.create( | ||
submission_maximum_allowed=2, submission_counter=2 | ||
) | ||
data = FormSerializer(context=context).to_representation(form) | ||
serializer = FormSerializer(instance=form, data=data) | ||
|
||
expected_error = _( | ||
"The maximum amount of allowed submissions must be bigger than the existing amount of submissions.Consider resetting the submissions counter." | ||
) | ||
|
||
self.assertFalse(serializer.is_valid()) | ||
self.assertIn("submission_maximum_allowed", serializer.errors) | ||
self.assertEqual( | ||
serializer.errors["submission_maximum_allowed"][0], expected_error | ||
) | ||
with self.subTest("submission_max_allowed bigger than submission_counter"): | ||
form = FormFactory.create( | ||
submission_maximum_allowed=2, submission_counter=1 | ||
) | ||
data = FormSerializer(context=context).to_representation(form) | ||
serializer = FormSerializer(instance=form, data=data) | ||
|
||
self.assertTrue(serializer.is_valid()) | ||
with self.subTest("submission_max_allowed smaller than submission_counter"): | ||
form = FormFactory.create( | ||
submission_maximum_allowed=1, submission_counter=2 | ||
) | ||
data = FormSerializer(context=context).to_representation(form) | ||
serializer = FormSerializer(instance=form, data=data) | ||
|
||
expected_error = _( | ||
"The maximum amount of allowed submissions must be bigger than the existing amount of submissions.Consider resetting the submissions counter." | ||
) | ||
|
||
self.assertFalse(serializer.is_valid()) | ||
self.assertIn("submission_maximum_allowed", serializer.errors) | ||
self.assertEqual( | ||
serializer.errors["submission_maximum_allowed"][0], expected_error | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.