Skip to content

Commit 868fc52

Browse files
committed
address comments/nits
1 parent 2404284 commit 868fc52

File tree

5 files changed

+13
-11
lines changed

5 files changed

+13
-11
lines changed

coderd/database/dbmem/dbmem.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7754,10 +7754,10 @@ func (q *FakeQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg database.
77547754
w2 := workspaces[j]
77557755

77567756
// Order by: favorite first
7757-
if arg.OrderByFavorite == w1.OwnerID && w1.Favorite {
7757+
if arg.RequesterID == w1.OwnerID && w1.Favorite {
77587758
return true
77597759
}
7760-
if arg.OrderByFavorite == w2.OwnerID && w2.Favorite {
7760+
if arg.RequesterID == w2.OwnerID && w2.Favorite {
77617761
return false
77627762
}
77637763

coderd/database/modelqueries.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func (q *sqlQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg GetWorkspa
226226
arg.LastUsedBefore,
227227
arg.LastUsedAfter,
228228
arg.UsingActive,
229-
arg.OrderByFavorite,
229+
arg.RequesterID,
230230
arg.Offset,
231231
arg.Limit,
232232
)

coderd/database/queries.sql.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/workspaces.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ WHERE
267267
-- Authorize Filter clause will be injected below in GetAuthorizedWorkspaces
268268
-- @authorize_filter
269269
ORDER BY
270-
CASE WHEN workspaces.owner_id = @order_by_favorite AND workspaces.favorite THEN 0 ELSE 1 END ASC,
270+
-- To ensure that 'favorite' workspaces show up first in the list only for their owner.
271+
CASE WHEN workspaces.owner_id = @requester_id AND workspaces.favorite THEN 0 ELSE 1 END ASC,
271272
(latest_build.completed_at IS NOT NULL AND
272273
latest_build.canceled_at IS NULL AND
273274
latest_build.error IS NULL AND

coderd/workspaces.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ func (api *API) workspaces(rw http.ResponseWriter, r *http.Request) {
159159
return
160160
}
161161

162-
// To show the user's favorite workspaces first, we pass their userID and compare it to
163-
// column favorite_of when ordering the rows.
164-
filter.OrderByFavorite = apiKey.UserID
162+
// To show the requester's favorite workspaces first, we pass their userID and compare it to
163+
// the workspace owner_id when ordering the rows.
164+
filter.RequesterID = apiKey.UserID
165165

166166
workspaceRows, err := api.Database.GetAuthorizedWorkspaces(ctx, filter, prepared)
167167
if err != nil {
@@ -1049,7 +1049,7 @@ func (api *API) putFavoriteWorkspace(rw http.ResponseWriter, r *http.Request) {
10491049

10501050
if apiKey.UserID != workspace.OwnerID {
10511051
httpapi.Write(ctx, rw, http.StatusForbidden, codersdk.Response{
1052-
Message: "You can only favorite workspaces that you own",
1052+
Message: "You can only favorite workspaces that you own.",
10531053
})
10541054
return
10551055
}
@@ -1095,7 +1095,7 @@ func (api *API) deleteFavoriteWorkspace(rw http.ResponseWriter, r *http.Request)
10951095

10961096
if apiKey.UserID != workspace.OwnerID {
10971097
httpapi.Write(ctx, rw, http.StatusForbidden, codersdk.Response{
1098-
Message: "You can only un-favorite workspaces that you own",
1098+
Message: "You can only un-favorite workspaces that you own.",
10991099
})
11001100
return
11011101
}

0 commit comments

Comments
 (0)