Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#4115] Forwardport Govmetric to master #4206

Merged
merged 3 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions src/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6570,17 +6570,29 @@ components:
AnalyticsToolsConfig:
type: object
properties:
govmetricSourceId:
govmetricSourceIdFormFinished:
type: string
description: Your GovMetric source ID - This is created by KLANTINFOCUS
when a list of questions is created. It is a numerical value that is unique
per set of questions.
description: Your GovMetric source ID for when a form is finished - This
is created by KLANTINFOCUS when a list of questions is created. It is
a numerical value that is unique per set of questions.
maxLength: 10
govmetricSecureGuid:
govmetricSourceIdFormAborted:
type: string
description: Your GovMetric secure GUID - This is an optional value. It
description: Your GovMetric source ID for when a form is aborted - This
is created by KLANTINFOCUS when a list of questions is created. It is
a string that is unique per set of questions.
a numerical value that is unique per set of questions.
maxLength: 10
govmetricSecureGuidFormFinished:
type: string
description: Your GovMetric secure GUID for when a form is finished - This
is an optional value. It is created by KLANTINFOCUS when a list of questions
is created. It is a string that is unique per set of questions.
maxLength: 50
govmetricSecureGuidFormAborted:
type: string
description: Your GovMetric secure GUID for when a form is aborted - This
is an optional value. It is created by KLANTINFOCUS when a list of questions
is created. It is a string that is unique per set of questions.
maxLength: 50
enableGovmetricAnalytics:
type: boolean
Expand Down
6 changes: 4 additions & 2 deletions src/openforms/analytics_tools/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ class AnalyticsToolsConfigurationAdmin(TranslationAdmin, SingletonModelAdmin):
_("Analytics: GovMetric"),
{
"fields": (
"govmetric_source_id",
"govmetric_secure_guid",
"govmetric_source_id_form_finished",
"govmetric_source_id_form_aborted",
"govmetric_secure_guid_form_finished",
"govmetric_secure_guid_form_aborted",
"enable_govmetric_analytics",
)
},
Expand Down
6 changes: 4 additions & 2 deletions src/openforms/analytics_tools/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class AnalyticsToolsConfigSerializer(serializers.ModelSerializer):
class Meta:
model = AnalyticsToolsConfiguration
fields = (
"govmetric_source_id",
"govmetric_secure_guid",
"govmetric_source_id_form_finished",
"govmetric_source_id_form_aborted",
"govmetric_secure_guid_form_finished",
"govmetric_secure_guid_form_aborted",
"enable_govmetric_analytics",
)
12 changes: 8 additions & 4 deletions src/openforms/analytics_tools/api/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ class TestAnalyticsToolsConfigViews(APITestCase):
def test_get_language_specific_govmetric_source_id(self, m_config):
m_config.return_value = AnalyticsToolsConfiguration(
enable_govmetric_analytics=True,
govmetric_source_id_en="1234",
govmetric_source_id_nl="4321",
govmetric_source_id_form_finished_en="1111",
govmetric_source_id_form_finished_nl="2222",
govmetric_source_id_form_aborted_en="3333",
govmetric_source_id_form_aborted_nl="4444",
)

with override_settings(LANGUAGE_CODE="en"):
Expand All @@ -30,5 +32,7 @@ def test_get_language_specific_govmetric_source_id(self, m_config):
data_en = response_en.json()
data_nl = response_nl.json()

self.assertEqual(data_en["govmetricSourceId"], "1234")
self.assertEqual(data_nl["govmetricSourceId"], "4321")
self.assertEqual(data_en["govmetricSourceIdFormFinished"], "1111")
self.assertEqual(data_en["govmetricSourceIdFormAborted"], "3333")
self.assertEqual(data_nl["govmetricSourceIdFormFinished"], "2222")
self.assertEqual(data_nl["govmetricSourceIdFormAborted"], "4444")
4 changes: 2 additions & 2 deletions src/openforms/analytics_tools/contrib/govmetric/cookies.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[
{
"name": "_pk_id.SOURCE_ID.DOMAIN_HASH",
"name": "_pk_id.SOURCE_ID_FORM_FINISHED.DOMAIN_HASH",
"path": "/"
},
{
"name": "_pk_ses.SOURCE_ID.DOMAIN_HASH",
"name": "_pk_ses.SOURCE_ID_FORM_FINISHED.DOMAIN_HASH",
"path": "/"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# Generated by Django 4.2.11 on 2024-04-12 08:43

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
(
"analytics_tools",
"0007_alter_analyticstoolsconfiguration_analytics_cookie_consent_group",
),
]

operations = [
migrations.AddField(
model_name="analyticstoolsconfiguration",
name="govmetric_secure_guid_form_aborted",
field=models.CharField(
blank=True,
help_text="Your GovMetric secure GUID for when a form is aborted - This is an optional value. It is created by KLANTINFOCUS when a list of questions is created. It is a string that is unique per set of questions.",
max_length=50,
verbose_name="GovMetric secure GUID form aborted",
),
),
migrations.AddField(
model_name="analyticstoolsconfiguration",
name="govmetric_secure_guid_form_finished",
field=models.CharField(
blank=True,
help_text="Your GovMetric secure GUID for when a form is finished - This is an optional value. It is created by KLANTINFOCUS when a list of questions is created. It is a string that is unique per set of questions.",
max_length=50,
verbose_name="GovMetric secure GUID form finished",
),
),
migrations.AddField(
model_name="analyticstoolsconfiguration",
name="govmetric_source_id_form_aborted",
field=models.CharField(
blank=True,
help_text="Your GovMetric source ID for when a form is aborted - This is created by KLANTINFOCUS when a list of questions is created. It is a numerical value that is unique per set of questions.",
max_length=10,
verbose_name="GovMetric source ID form aborted",
),
),
migrations.AddField(
model_name="analyticstoolsconfiguration",
name="govmetric_source_id_form_finished",
field=models.CharField(
blank=True,
help_text="Your GovMetric source ID for when a form is finished - This is created by KLANTINFOCUS when a list of questions is created. It is a numerical value that is unique per set of questions.",
max_length=10,
verbose_name="GovMetric source ID form finished",
),
),
migrations.AddField(
model_name="analyticstoolsconfiguration",
name="govmetric_secure_guid_form_aborted_en",
field=models.CharField(
blank=True,
help_text="Your GovMetric secure GUID for when a form is aborted - This is an optional value. It is created by KLANTINFOCUS when a list of questions is created. It is a string that is unique per set of questions.",
max_length=50,
null=True,
verbose_name="GovMetric secure GUID form aborted",
),
),
migrations.AddField(
model_name="analyticstoolsconfiguration",
name="govmetric_secure_guid_form_aborted_nl",
field=models.CharField(
blank=True,
help_text="Your GovMetric secure GUID for when a form is aborted - This is an optional value. It is created by KLANTINFOCUS when a list of questions is created. It is a string that is unique per set of questions.",
max_length=50,
null=True,
verbose_name="GovMetric secure GUID form aborted",
),
),
migrations.AddField(
model_name="analyticstoolsconfiguration",
name="govmetric_secure_guid_form_finished_en",
field=models.CharField(
blank=True,
help_text="Your GovMetric secure GUID for when a form is finished - This is an optional value. It is created by KLANTINFOCUS when a list of questions is created. It is a string that is unique per set of questions.",
max_length=50,
null=True,
verbose_name="GovMetric secure GUID form finished",
),
),
migrations.AddField(
model_name="analyticstoolsconfiguration",
name="govmetric_secure_guid_form_finished_nl",
field=models.CharField(
blank=True,
help_text="Your GovMetric secure GUID for when a form is finished - This is an optional value. It is created by KLANTINFOCUS when a list of questions is created. It is a string that is unique per set of questions.",
max_length=50,
null=True,
verbose_name="GovMetric secure GUID form finished",
),
),
migrations.AddField(
model_name="analyticstoolsconfiguration",
name="govmetric_source_id_form_aborted_en",
field=models.CharField(
blank=True,
help_text="Your GovMetric source ID for when a form is aborted - This is created by KLANTINFOCUS when a list of questions is created. It is a numerical value that is unique per set of questions.",
max_length=10,
null=True,
verbose_name="GovMetric source ID form aborted",
),
),
migrations.AddField(
model_name="analyticstoolsconfiguration",
name="govmetric_source_id_form_aborted_nl",
field=models.CharField(
blank=True,
help_text="Your GovMetric source ID for when a form is aborted - This is created by KLANTINFOCUS when a list of questions is created. It is a numerical value that is unique per set of questions.",
max_length=10,
null=True,
verbose_name="GovMetric source ID form aborted",
),
),
migrations.AddField(
model_name="analyticstoolsconfiguration",
name="govmetric_source_id_form_finished_en",
field=models.CharField(
blank=True,
help_text="Your GovMetric source ID for when a form is finished - This is created by KLANTINFOCUS when a list of questions is created. It is a numerical value that is unique per set of questions.",
max_length=10,
null=True,
verbose_name="GovMetric source ID form finished",
),
),
migrations.AddField(
model_name="analyticstoolsconfiguration",
name="govmetric_source_id_form_finished_nl",
field=models.CharField(
blank=True,
help_text="Your GovMetric source ID for when a form is finished - This is created by KLANTINFOCUS when a list of questions is created. It is a numerical value that is unique per set of questions.",
max_length=10,
null=True,
verbose_name="GovMetric source ID form finished",
),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Generated by Django 4.2.11 on 2024-04-12 08:43

from django.db import migrations

from openforms.translations.utils import get_language_codes


def add_extra_source_id_govmetric(apps, schema_editor):
AnalyticsToolsConfiguration = apps.get_model(
"analytics_tools", "AnalyticsToolsConfiguration"
)

config = AnalyticsToolsConfiguration.objects.first()
if not config:
return

language_codes = get_language_codes()

for language_code in language_codes:
if old_id := getattr(config, f"govmetric_source_id_{language_code}"):
setattr(config, f"govmetric_source_id_form_aborted_{language_code}", old_id)
setattr(
config, f"govmetric_source_id_form_finished_{language_code}", old_id
)

if old_guid := getattr(config, f"govmetric_secure_guid_{language_code}"):
setattr(
config, f"govmetric_secure_guid_form_aborted_{language_code}", old_guid
)
setattr(
config, f"govmetric_secure_guid_form_finished_{language_code}", old_guid
)

config.save()


def remove_extra_source_id_govmetric(apps, schema_editor):
AnalyticsToolsConfiguration = apps.get_model(
"analytics_tools", "AnalyticsToolsConfiguration"
)

config = AnalyticsToolsConfiguration.objects.first()
if not config:
return

language_codes = get_language_codes()

for language_code in language_codes:
new_id = getattr(
config, f"govmetric_source_id_form_finished_{language_code}"
) or getattr(config, f"govmetric_source_id_form_aborted_{language_code}")
if new_id:
setattr(config, f"govmetric_source_id_{language_code}", new_id)

new_guid = getattr(
config, f"govmetric_secure_guid_form_finished_{language_code}"
) or getattr(config, f"govmetric_secure_guid_form_aborted_{language_code}")
if new_guid:
setattr(config, f"govmetric_secure_guid_{language_code}", new_guid)

config.save()


class Migration(migrations.Migration):
dependencies = [
(
"analytics_tools",
"0008_analyticstoolsconfiguration_govmetric_secure_guid_form_abort_and_more",
),
]

operations = [
migrations.RunPython(
add_extra_source_id_govmetric, remove_extra_source_id_govmetric
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Generated by Django 4.2.11 on 2024-04-12 09:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("analytics_tools", "0009_convert_ids_govmetric"),
]

operations = [
migrations.RemoveField(
model_name="analyticstoolsconfiguration",
name="govmetric_secure_guid",
),
migrations.RemoveField(
model_name="analyticstoolsconfiguration",
name="govmetric_secure_guid_en",
),
migrations.RemoveField(
model_name="analyticstoolsconfiguration",
name="govmetric_secure_guid_nl",
),
migrations.RemoveField(
model_name="analyticstoolsconfiguration",
name="govmetric_source_id",
),
migrations.RemoveField(
model_name="analyticstoolsconfiguration",
name="govmetric_source_id_en",
),
migrations.RemoveField(
model_name="analyticstoolsconfiguration",
name="govmetric_source_id_nl",
),
]
Loading
Loading