From f9eaa193c954e7578cb285a9360319811c10d0a1 Mon Sep 17 00:00:00 2001 From: Mira Date: Tue, 12 Mar 2024 12:41:48 +0100 Subject: [PATCH] Add migration to force slash after hostname in returnurl prefixes (#3948) * Add migration to force slash after hostname in returnurl prefixes * isort * add dependency to pretixbase --- .../returnurl/migrations/0001_initial.py | 12 ++++++ .../migrations/0002_auto_20240301_1355.py | 39 +++++++++++++++++++ .../plugins/returnurl/migrations/__init__.py | 0 3 files changed, 51 insertions(+) create mode 100644 src/pretix/plugins/returnurl/migrations/0001_initial.py create mode 100644 src/pretix/plugins/returnurl/migrations/0002_auto_20240301_1355.py create mode 100644 src/pretix/plugins/returnurl/migrations/__init__.py diff --git a/src/pretix/plugins/returnurl/migrations/0001_initial.py b/src/pretix/plugins/returnurl/migrations/0001_initial.py new file mode 100644 index 0000000000..781fb3dc0a --- /dev/null +++ b/src/pretix/plugins/returnurl/migrations/0001_initial.py @@ -0,0 +1,12 @@ +# Generated by Django 4.2.10 on 2024-03-01 13:55 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ] + + operations = [ + ] diff --git a/src/pretix/plugins/returnurl/migrations/0002_auto_20240301_1355.py b/src/pretix/plugins/returnurl/migrations/0002_auto_20240301_1355.py new file mode 100644 index 0000000000..2fcba8daf5 --- /dev/null +++ b/src/pretix/plugins/returnurl/migrations/0002_auto_20240301_1355.py @@ -0,0 +1,39 @@ +# Generated by Django 4.2.10 on 2024-03-01 13:55 +import re + +from django.core.cache import cache +from django.db import migrations + +MISSING_SLASH = re.compile(r"^https?://[^/]*$") + + +def force_slash_after_hostname(prefix): + prefix = prefix.strip() + if MISSING_SLASH.match(prefix): + return prefix + "/" + else: + return prefix + + +def update_returnurl_prefixes(app, schema_editor): + EventSettingsStore = app.get_model('pretixbase', 'Event_SettingsStore') + + for setting in EventSettingsStore.objects.filter(key='returnurl_prefix'): + prefixes = setting.value.split("\n") + new_prefixes = [force_slash_after_hostname(prefix) for prefix in prefixes] + new_value = "\n".join(new_prefixes) + setting.value = new_value + cache.delete('hierarkey_{}_{}'.format('event', setting.object_id)) + setting.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('returnurl', '0001_initial'), + ('pretixbase', '0257_item_default_price_not_null'), + ] + + operations = [ + migrations.RunPython(update_returnurl_prefixes, migrations.RunPython.noop) + ] diff --git a/src/pretix/plugins/returnurl/migrations/__init__.py b/src/pretix/plugins/returnurl/migrations/__init__.py new file mode 100644 index 0000000000..e69de29bb2