Prevent transferring files from priv/ to pub/ on event clone (#3956)

* Prevent transferring files from priv/ to pub/ on event clone

* Also detect file names with node prefix

* Only transfer files in explicitly declared file fields

* Update django-hierarkey

* Add note to documentation about the new behaviour
This commit is contained in:
Mira
2024-05-08 09:33:23 +02:00
committed by GitHub
parent 514f1def4d
commit 9dc5c1b266
3 changed files with 13 additions and 3 deletions

View File

@@ -45,6 +45,7 @@ from zoneinfo import ZoneInfo
import pytz_deprecation_shim
from django.conf import settings
from django.core.exceptions import ValidationError
from django.core.files import File
from django.core.files.storage import default_storage
from django.core.mail import get_connection
from django.core.validators import (
@@ -1025,7 +1026,7 @@ class Event(EventMixin, LoggedModel):
s.object = self
s.pk = None
if s.value.startswith('file://'):
if s.value.startswith('file://') and settings_hierarkey.get_declared_type(s.key) == File:
fi = default_storage.open(s.value[len('file://'):], 'rb')
nonce = get_random_string(length=8)
fname_base = clean_filename(os.path.basename(s.value))