Skip to content

Commit

Permalink
fix: Query inconsistencies and mistakes in the vfolder share/change-o…
Browse files Browse the repository at this point in the history
…wnership API handlers (#1850)

Co-authored-by: Joongi Kim <[email protected]>
  • Loading branch information
mirageoasis and achimnol authored Jan 30, 2024
1 parent 7c2ab43 commit 9348389
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
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

0 comments on commit 9348389

Please sign in to comment.