Skip to content

Commit

Permalink
Merge pull request #4702 from open-formulieren/issue/4701-fix-data-mi…
Browse files Browse the repository at this point in the history
…grations-for-config-and-zip-filetypes

[#4701] Add missing data migration for the global config and zip mimetypes
  • Loading branch information
sergei-maertens authored Sep 24, 2024
2 parents be301d2 + d8d3b4a commit 1c6a14c
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,27 @@
from django.db import migrations, models
import django_jsonform.models.fields

from openforms.config.constants import UploadFileType


def add_extra_zip_mimetypes(apps, _):
"""
Set up the correct zip mimetypes.
This ensures all the allowed mimetypes concerning zip files are included.
"""
GlobalConfiguration = apps.get_model("config", "GlobalConfiguration")
if not GlobalConfiguration.objects.exists():
return

config = GlobalConfiguration.objects.get()
if "application/zip" not in config.form_upload_default_file_types:
return

config.form_upload_default_file_types.remove("application/zip")
config.form_upload_default_file_types.append(UploadFileType.zip)
config.save(update_fields=("form_upload_default_file_types",))


class Migration(migrations.Migration):

Expand Down Expand Up @@ -59,4 +80,8 @@ class Migration(migrations.Migration):
verbose_name="Default allowed file upload types",
),
),
migrations.RunPython(
add_extra_zip_mimetypes,
migrations.RunPython.noop,
),
]

0 comments on commit 1c6a14c

Please sign in to comment.