diff --git a/src/api/handlers/media_library.py b/src/api/handlers/media_library.py index d3b09c717..969b6c944 100644 --- a/src/api/handlers/media_library.py +++ b/src/api/handlers/media_library.py @@ -105,13 +105,13 @@ def fetch_content(self, request): """Fetches image content related communities that admins can browse through""" context: Context = request.context args: dict = context.args - self.validator.expect("community_ids", "str_list", is_required=True) + self.validator.expect("community_ids", "str_list", is_required=False) self.validator.expect("lower_limit", int, is_required=False) self.validator.expect("upper_limit", int, is_required=False) args, err = self.validator.verify(args, strict=True) if err: return err - images, error = self.service.fetch_content(args) + images, error = self.service.fetch_content(context, args) if error: return error return MassenergizeResponse(data=images) diff --git a/src/api/services/media_library.py b/src/api/services/media_library.py index c93b221a6..d53048574 100644 --- a/src/api/services/media_library.py +++ b/src/api/services/media_library.py @@ -40,8 +40,8 @@ def generate_hashes(self, args, context): return None, error return response, None - def fetch_content(self, args): - images, error = self.store.fetch_content(args) + def fetch_content(self, context, args): + images, error = self.store.fetch_content(context, args) if error: return None, error return self.organiseData(data=serialize_all(images, True), args=args), None diff --git a/src/api/store/media_library.py b/src/api/store/media_library.py index dca79027f..5009d6d42 100644 --- a/src/api/store/media_library.py +++ b/src/api/store/media_library.py @@ -182,11 +182,21 @@ def find_images(self, args, _): images = Media.objects.filter(pk__in=ids) return images, None - def fetch_content(self, args): + def fetch_content(self, context: Context, args): com_ids = args.get("community_ids") or [] upper_limit = args.get("upper_limit") lower_limit = args.get("lower_limit") images = None + + if not com_ids: + if context.user_is_community_admin: + communities, _ = get_admin_communities(context) + com_ids = [c.id for c in communities] + elif context.user_is_super_admin: + com_ids = [c.id for c in Community.objects.all()] + else: + com_ids = [] + if upper_limit and lower_limit: images = ( Media.objects.filter(