Skip to content

Commit

Permalink
fix: images resolver not filtering out image objects correctly (#2246)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregataa authored Jun 3, 2024
1 parent 220b420 commit 07ac9a7
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions src/ai/backend/manager/models/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,29 +710,41 @@ def matches_filter(
ctx: GraphQueryContext,
filters: set[ImageLoadFilter],
) -> bool:
"""
Determine if the image is filtered according to the `filters` parameter.
"""
user_role = ctx.user["role"]

if not filters:
return True

# If the image filtered by any of its labels, return False early.
# If the image is not filtered and is determiend to be valid by any of its labels, `is_valid = True`.
is_valid = False
for label in self.labels:
match label.key:
case "ai.backend.features" if "operation" in label.value and ImageLoadFilter.OPERATIONAL not in filters:
return False
case "ai.backend.features" if "operation" in label.value:
if ImageLoadFilter.OPERATIONAL in filters:
is_valid = True
else:
return False
case "ai.backend.customized-image.owner":
if (
(
ImageLoadFilter.CUSTOMIZED not in filters
and ImageLoadFilter.CUSTOMIZED_GLOBAL not in filters
)
or (
ImageLoadFilter.CUSTOMIZED_GLOBAL in filters
and user_role != UserRole.SUPERADMIN
)
or (
ImageLoadFilter.CUSTOMIZED in filters
and label.value != f"user:{ctx.user['uuid']}"
)
ImageLoadFilter.CUSTOMIZED not in filters
and ImageLoadFilter.CUSTOMIZED_GLOBAL not in filters
):
return False
return True
if ImageLoadFilter.CUSTOMIZED in filters:
if label.value == f"user:{ctx.user['uuid']}":
is_valid = True
else:
return False
if ImageLoadFilter.CUSTOMIZED_GLOBAL in filters:
if user_role == UserRole.SUPERADMIN:
is_valid = True
else:
return False
return is_valid


class ImageNode(graphene.ObjectType):
Expand Down

0 comments on commit 07ac9a7

Please sign in to comment.