Skip to content

Commit

Permalink
Return early to reduce indentation in retry_file_permission_set_attem…
Browse files Browse the repository at this point in the history
…pts command
  • Loading branch information
ababic committed Dec 13, 2024
1 parent b581823 commit 7f0de81
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cms/private_media/bulk_operations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import concurrent.futures
import logging
from collections.abc import Callable, Iterable
from collections.abc import Iterable
from typing import TYPE_CHECKING

from django.conf import settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,19 @@ def handle(self, *args: Any, **options: Any) -> None:
queryset = queryset.prefetch_related("renditions")
permissions_outdated = list(queryset)
self.stdout.write(f"{len(permissions_outdated)} {model.__name__} instances have outdated file permissions.")
if permissions_outdated:
make_private = []
make_public = []
for obj in permissions_outdated:
if obj.privacy is Privacy.PRIVATE:
make_private.append(obj)
elif obj.privacy is Privacy.PUBLIC:
make_public.append(obj)
if not permissions_outdated:
continue

self.update_file_permissions(model, make_private, Privacy.PRIVATE)
self.update_file_permissions(model, make_public, Privacy.PUBLIC)
make_private = []
make_public = []
for obj in permissions_outdated:
if obj.privacy is Privacy.PRIVATE:
make_private.append(obj)
elif obj.privacy is Privacy.PUBLIC:
make_public.append(obj)

self.update_file_permissions(model, make_private, Privacy.PRIVATE)
self.update_file_permissions(model, make_public, Privacy.PUBLIC)

def update_file_permissions(
self, model_class: type["PrivateMediaMixin"], items: list["PrivateMediaMixin"], privacy: Privacy
Expand Down

0 comments on commit 7f0de81

Please sign in to comment.