Skip to content

feat(coderd): allow workspace owners to mark workspaces as favorite #11791

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

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
address comments/nits
  • Loading branch information
johnstcn committed Jan 24, 2024
commit 868fc521eeca62508e9fd1f95cc3f20934a2afc1
4 changes: 2 additions & 2 deletions coderd/database/dbmem/dbmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -7754,10 +7754,10 @@ func (q *FakeQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg database.
w2 := workspaces[j]

// Order by: favorite first
if arg.OrderByFavorite == w1.OwnerID && w1.Favorite {
if arg.RequesterID == w1.OwnerID && w1.Favorite {
return true
}
if arg.OrderByFavorite == w2.OwnerID && w2.Favorite {
if arg.RequesterID == w2.OwnerID && w2.Favorite {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion coderd/database/modelqueries.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (q *sqlQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg GetWorkspa
arg.LastUsedBefore,
arg.LastUsedAfter,
arg.UsingActive,
arg.OrderByFavorite,
arg.RequesterID,
arg.Offset,
arg.Limit,
)
Expand Down
5 changes: 3 additions & 2 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion coderd/database/queries/workspaces.sql
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ WHERE
-- Authorize Filter clause will be injected below in GetAuthorizedWorkspaces
-- @authorize_filter
ORDER BY
CASE WHEN workspaces.owner_id = @order_by_favorite AND workspaces.favorite THEN 0 ELSE 1 END ASC,
-- To ensure that 'favorite' workspaces show up first in the list only for their owner.
CASE WHEN workspaces.owner_id = @requester_id AND workspaces.favorite THEN 0 ELSE 1 END ASC,
(latest_build.completed_at IS NOT NULL AND
latest_build.canceled_at IS NULL AND
latest_build.error IS NULL AND
Expand Down
10 changes: 5 additions & 5 deletions coderd/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ func (api *API) workspaces(rw http.ResponseWriter, r *http.Request) {
return
}

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

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

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

if apiKey.UserID != workspace.OwnerID {
httpapi.Write(ctx, rw, http.StatusForbidden, codersdk.Response{
Message: "You can only un-favorite workspaces that you own",
Message: "You can only un-favorite workspaces that you own.",
})
return
}
Expand Down