-
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.
Merge pull request #3927 from open-formulieren/chore/squash-migrations
Squashing migrations
- Loading branch information
Showing
48 changed files
with
2,890 additions
and
3,151 deletions.
There are no files selected for viewing
70 changes: 4 additions & 66 deletions
70
src/openforms/analytics_tools/migrations/0003_cspsetting_identifier.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 |
---|---|---|
@@ -1,78 +1,16 @@ | ||
# Generated by Django 3.2.21 on 2023-11-22 17:27 | ||
|
||
from django.db import migrations | ||
from django.db.migrations.state import StateApps | ||
from django.db.backends.base.schema import BaseDatabaseSchemaEditor | ||
|
||
from openforms.analytics_tools.constants import AnalyticsTools | ||
|
||
SITEIMPROVE_VALUES = [ | ||
"https://siteimproveanalytics.com", | ||
"https://siteimproveanalytics.com", | ||
"https://*.siteimproveanalytics.io", | ||
] | ||
GA_VALUES = ["https://www.googleanalytics.com", "https://www.googletagmanager.com"] | ||
|
||
FIELD_TO_IDENTIFIER = { | ||
"matomo_url": AnalyticsTools.matomo, | ||
"piwik_pro_url": AnalyticsTools.piwik_pro, | ||
"piwik_url": AnalyticsTools.piwik, | ||
} | ||
|
||
|
||
def set_identifier(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None: | ||
"""Set the corresponding analytic tool as the ``CSPSetting.identifier`` field. | ||
Depending on the analytic tool used, the ``CSPSetting.value`` field can be fixed | ||
(e.g. with GA or Siteimprove) or configured by the user. The latter requires more work, | ||
as we need to iterate over the ``AnalyticsToolsConfiguration`` fields to find the right match. | ||
""" | ||
|
||
AnalyticsToolsConfiguration = apps.get_model( | ||
"analytics_tools", "AnalyticsToolsConfiguration" | ||
) | ||
try: | ||
analytics_conf = AnalyticsToolsConfiguration.objects.get() | ||
except AnalyticsToolsConfiguration.DoesNotExist: | ||
return | ||
|
||
ContentType = apps.get_model("contenttypes", "ContentType") | ||
analytics_content_type = ContentType.objects.get_for_model( | ||
AnalyticsToolsConfiguration | ||
) | ||
|
||
CSPSetting = apps.get_model("config", "CSPSetting") | ||
|
||
set_content_type = False | ||
for csp_setting in CSPSetting.objects.filter(identifier="").iterator(): | ||
if csp_setting.value in SITEIMPROVE_VALUES: | ||
csp_setting.identifier = AnalyticsTools.siteimprove | ||
set_content_type = True | ||
elif csp_setting.value in GA_VALUES: | ||
csp_setting.identifier = AnalyticsTools.google_analytics | ||
set_content_type = True | ||
else: | ||
for field, identifier in FIELD_TO_IDENTIFIER.items(): | ||
if getattr(analytics_conf, field, None) == csp_setting.value: | ||
csp_setting.identifier = identifier | ||
set_content_type = True | ||
|
||
if set_content_type: | ||
# `content_object` is not available in migrations, | ||
# so we set `content_type` and `object_id` instead: | ||
csp_setting.content_type = analytics_content_type | ||
csp_setting.object_id = analytics_conf.id | ||
|
||
csp_setting.save() | ||
from django.db.migrations.state import StateApps | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("analytics_tools", "0002_auto_20230119_1500"), | ||
("config", "0063_auto_20231122_1816"), | ||
("config", "0053_v230_to_v250"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(set_identifier, migrations.RunPython.noop), | ||
] | ||
# RunPython operation is removed, it was executed as part of the 2.5.0 upgrade. | ||
operations = [] |
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
29 changes: 0 additions & 29 deletions
29
src/openforms/config/management/commands/create_csp_form_action_directives_from_config.py
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.