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: Query inconsistencies and mistakes in the vfolder share/change-ownership API handlers #1850

Merged
merged 4 commits into from
Jan 30, 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/1850.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix mistakes on SQL queries in the manager's vfolder share API handler when checking target user's status and inconsistent where clauses in the vfolder ownership change API
11 changes: 8 additions & 3 deletions src/ai/backend/manager/api/vfolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2026,7 +2026,7 @@ async def share(request: web.Request, params: Any) -> web.Response:
(users.c.email.in_(params["emails"]))
& (users.c.email != request["user"]["email"])
& (agus.c.group_id == vf_info["group"])
& (users.c.status == ACTIVE_USER_STATUSES),
& (users.c.status.in_(ACTIVE_USER_STATUSES)),
)
)
result = await conn.execute(query)
Expand All @@ -2045,7 +2045,7 @@ async def share(request: web.Request, params: Any) -> web.Response:

# Do not share to users who have already been shared the folder.
query = (
sa.select([vfolder_permissions.c.user])
sa.select([vfolder_permissions])
.select_from(vfolder_permissions)
.where(
(vfolder_permissions.c.user.in_(users_to_share))
Expand Down Expand Up @@ -3212,7 +3212,12 @@ async def change_vfolder_ownership(request: web.Request, params: Any) -> web.Res
)
async with root_ctx.db.begin_readonly() as conn:
query = (
sa.select([vfolders.c.host]).select_from(vfolders).where(vfolders.c.id == vfolder_id)
sa.select([vfolders.c.host])
.select_from(vfolders)
.where(
(vfolders.c.id == vfolder_id)
& (vfolders.c.ownership_type == VFolderOwnershipType.USER)
)
)
folder_host = await conn.scalar(query)
if folder_host not in allowed_hosts_by_user:
Expand Down
Loading