Skip to content

Commit

Permalink
[#4701] Added missing data migration for the global config and zip mi…
Browse files Browse the repository at this point in the history
…metypes
  • Loading branch information
vaszig committed Sep 24, 2024
1 parent be301d2 commit 1d86939
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,35 @@
import django_jsonform.models.fields


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 current_mimetypes := config.form_upload_default_file_types:
needed_mime_types = (
"application/x-zip-compressed",
"application/zip-compressed",
)

def add_if_missing(current_list: list[str]):
for item in needed_mime_types:
if item not in current_list:
current_list.append(item)

if "application/zip" in current_mimetypes:
add_if_missing(current_mimetypes)

config.form_upload_default_file_types = current_mimetypes
config.save()


class Migration(migrations.Migration):

dependencies = [
Expand Down Expand Up @@ -59,4 +88,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 1d86939

Please sign in to comment.