diff --git a/src/openforms/analytics_tools/migrations/0007_alter_analyticstoolsconfiguration_analytics_cookie_consent_group.py b/src/openforms/analytics_tools/migrations/0007_alter_analyticstoolsconfiguration_analytics_cookie_consent_group.py new file mode 100644 index 0000000000..a848e5f2bf --- /dev/null +++ b/src/openforms/analytics_tools/migrations/0007_alter_analyticstoolsconfiguration_analytics_cookie_consent_group.py @@ -0,0 +1,25 @@ +# Generated by Django 4.2.11 on 2024-04-17 08:38 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ("cookie_consent", "0002_auto__add_logitem"), + ("analytics_tools", "0006_auto_20240112_1046"), + ] + + operations = [ + migrations.AlterField( + model_name="analyticstoolsconfiguration", + name="analytics_cookie_consent_group", + field=models.ForeignKey( + help_text="The cookie group used for analytical cookies. The analytics scripts are loaded only if this cookie group is accepted by the end-user.", + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to="cookie_consent.cookiegroup", + ), + ), + ] diff --git a/src/openforms/analytics_tools/models.py b/src/openforms/analytics_tools/models.py index 8e90244a9a..0db8217dd7 100644 --- a/src/openforms/analytics_tools/models.py +++ b/src/openforms/analytics_tools/models.py @@ -235,7 +235,7 @@ class AnalyticsToolsConfiguration(SingletonModel): "cookie_consent.CookieGroup", on_delete=models.SET_NULL, null=True, - blank=True, + blank=False, help_text=_( "The cookie group used for analytical cookies. The analytics scripts are " "loaded only if this cookie group is accepted by the end-user." diff --git a/src/openforms/analytics_tools/tests/test_admin.py b/src/openforms/analytics_tools/tests/test_admin.py index f2b0e65465..24e56c9f49 100644 --- a/src/openforms/analytics_tools/tests/test_admin.py +++ b/src/openforms/analytics_tools/tests/test_admin.py @@ -1,5 +1,6 @@ from django.urls import reverse +from cookie_consent.models import CookieGroup from django_webtest import WebTest from maykin_2fa.test import disable_admin_mfa @@ -8,6 +9,13 @@ @disable_admin_mfa() class AnalyticsConfigAdminTests(WebTest): + @classmethod + def setUpTestData(cls) -> None: + super().setUpTestData() + cls.cookie_group = CookieGroup.objects.create( + varname="test group", name="test group" + ) + def test_urls_cannot_have_trailing_slashes(self): superuser = SuperUserFactory.create() admin_url = reverse( @@ -20,6 +28,8 @@ def test_urls_cannot_have_trailing_slashes(self): change_page = self.app.get(admin_url, user=superuser) form = change_page.forms["analyticstoolsconfiguration_form"] form[field] = "https://example.com/" + # Options are loaded dynamically, so force value: + form["analytics_cookie_consent_group"].force_value(self.cookie_group.pk) response = form.submit() @@ -40,6 +50,8 @@ def test_urls_without_trailing_slash_ok(self): change_page = self.app.get(admin_url, user=superuser) form = change_page.forms["analyticstoolsconfiguration_form"] form[field] = "https://example.com" + # Options are loaded dynamically, so force value: + form["analytics_cookie_consent_group"].force_value(self.cookie_group.pk) response = form.submit()