From d4c8a1f26a014629f0256041097670fe6b2a5e71 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 15 May 2023 13:47:53 +0200 Subject: ✨ media_find_missing_files command: add no-media-dir-verification option in order to pass this verification for set-empty-image or set-alt-media-dir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../management/commands/media_find_missing_files.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'ishtar_common/management/commands/media_find_missing_files.py') diff --git a/ishtar_common/management/commands/media_find_missing_files.py b/ishtar_common/management/commands/media_find_missing_files.py index f2cf8e7f6..61a7919e2 100644 --- a/ishtar_common/management/commands/media_find_missing_files.py +++ b/ishtar_common/management/commands/media_find_missing_files.py @@ -60,6 +60,11 @@ class Command(BaseCommand): parser.add_argument( '--set-alt-media-dir', dest='set-alt-media-dir', default=False, help='Try to set link from an alt directory for missing media.') + parser.add_argument( + '--no-media-dir-verification', dest='no-media-dir-verification', action='store_true', + default=False, + help="For set-alt-media-dir or set-empty-image do not verify media dir. WARNING: do only if you are aware " + "of what you are doing this could led to security issue.") def handle(self, *args, **options): exclude = options['exclude'].split(',') if options['exclude'] else [] @@ -69,6 +74,7 @@ class Command(BaseCommand): hard = options['hard'] set_alt_media_dir = options["set-alt-media-dir"] set_empty_image = options["set-empty-image"] + no_dir_verification = options["no-media-dir-verification"] if set_alt_media_dir and not os.path.isdir(set_alt_media_dir): self.stdout.write(f'set-alt-media-dir: "{set_alt_media_dir}" is not a valid path.\n') return @@ -84,6 +90,9 @@ class Command(BaseCommand): if hard and not (try_fix or find_fix): self.stdout.write("hard option has no effect if try-fix or " "find-fix are not set.\n") + if no_dir_verification and (not set_alt_media_dir and not set_alt_media_dir): + self.stdout.write("no-media-dir-verification option has no effect if set-empty-image or " + "set-alt-media-dir are not set.\n") if try_fix: # first try to fix broken links @@ -116,7 +125,7 @@ class Command(BaseCommand): total = 0 for f in missing: f = os.path.abspath(f) - if not f.startswith(settings.MEDIA_ROOT): + if not no_dir_verification and not f.startswith(settings.MEDIA_ROOT): continue dest = os.path.join(set_alt_media_dir, f[len(settings.MEDIA_ROOT):]) if not os.path.isfile(dest): @@ -140,7 +149,7 @@ class Command(BaseCommand): total = 0 for f in missing: f = os.path.abspath(f) - if not f.startswith(settings.MEDIA_ROOT): + if not no_dir_verification and not f.startswith(settings.MEDIA_ROOT): continue if f.lower().endswith(".jpg") or f.lower().endswith(".jpeg"): cempty_image = empty_image + ".jpg" -- cgit v1.2.3