Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow admins to delete other user's vfolders #3137

Merged
merged 3 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/3137.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow admins to delete other users' vfolders by enabling vfolder fetching for precondition checks
25 changes: 21 additions & 4 deletions src/ai/backend/manager/api/vfolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ async def resolve_vfolder_rows(
folder_id_or_name: str | uuid.UUID,
*,
allowed_status_set: VFolderStatusSet | None = None,
allow_privileged_access: bool = False,
) -> Sequence[VFolderRow]:
"""
Checks if the target VFolder exists and is either:
Expand Down Expand Up @@ -255,6 +256,7 @@ async def resolve_vfolder_rows(
entries = await query_accessible_vfolders(
conn,
user_uuid,
allow_privileged_access=allow_privileged_access,
user_role=user_role,
domain_name=domain_name,
allowed_vfolder_types=allowed_vfolder_types,
Expand Down Expand Up @@ -2315,7 +2317,11 @@ async def delete_by_id(request: web.Request, params: DeleteRequestModel) -> web.
folder_id,
)

row = (await resolve_vfolder_rows(request, VFolderPermission.OWNER_PERM, folder_id))[0]
row = (
await resolve_vfolder_rows(
request, VFolderPermission.OWNER_PERM, folder_id, allow_privileged_access=True
)
)[0]
fregataa marked this conversation as resolved.
Show resolved Hide resolved
await check_vfolder_status(row, VFolderStatusSet.DELETABLE)
try:
await _delete(
Expand Down Expand Up @@ -2358,7 +2364,9 @@ async def delete_by_name(request: web.Request) -> web.Response:
folder_name,
)

rows = await resolve_vfolder_rows(request, VFolderPermission.OWNER_PERM, folder_name)
rows = await resolve_vfolder_rows(
request, VFolderPermission.OWNER_PERM, folder_name, allow_privileged_access=True
)
for row in rows:
try:
await check_vfolder_status(row, VFolderStatusSet.DELETABLE)
Expand Down Expand Up @@ -2415,6 +2423,7 @@ async def get_vfolder_id(request: web.Request, params: IDRequestModel) -> Compac
entries = await query_accessible_vfolders(
db_session.bind,
user_uuid,
allow_privileged_access=True,
user_role=user_role,
domain_name=domain_name,
allowed_vfolder_types=allowed_vfolder_types,
Expand Down Expand Up @@ -2466,7 +2475,11 @@ async def delete_from_trash_bin(
access_key,
folder_id,
)
row = (await resolve_vfolder_rows(request, VFolderPermission.OWNER_PERM, folder_id))[0]
row = (
await resolve_vfolder_rows(
request, VFolderPermission.OWNER_PERM, folder_id, allow_privileged_access=True
)
)[0]
await check_vfolder_status(row, VFolderStatusSet.PURGABLE)

async with root_ctx.db.begin_readonly() as conn:
Expand Down Expand Up @@ -2583,7 +2596,11 @@ async def restore(request: web.Request, params: RestoreRequestModel) -> web.Resp
folder_id,
)

row = (await resolve_vfolder_rows(request, VFolderPermission.OWNER_PERM, folder_id))[0]
row = (
await resolve_vfolder_rows(
request, VFolderPermission.OWNER_PERM, folder_id, allow_privileged_access=True
)
)[0]
await check_vfolder_status(row, VFolderStatusSet.RECOVERABLE)

async with root_ctx.db.begin() as conn:
Expand Down