diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2023-05-15 13:47:53 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2023-05-15 13:47:53 +0200 |
commit | d4c8a1f26a014629f0256041097670fe6b2a5e71 (patch) | |
tree | 30a5310dd4641027f79c21157442ed0e03cbc300 | |
parent | c2bfe16c1975c4e37df396df6096cfb17be177eb (diff) | |
download | Ishtar-d4c8a1f26a014629f0256041097670fe6b2a5e71.tar.bz2 Ishtar-d4c8a1f26a014629f0256041097670fe6b2a5e71.zip |
✨ 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
-rw-r--r-- | ishtar_common/management/commands/media_find_missing_files.py | 13 |
1 files changed, 11 insertions, 2 deletions
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" |