Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
johnstcn merged 2 commits intomainfromcj/favorite-workspaces-redux
Jan 24, 2024

Conversation

johnstcn
Copy link
Member

@johnstcnjohnstcn commentedJan 24, 2024
edited
Loading

Part of#7912

Continues from#11673 and rebased on latest main

Notable changes:

  • favorite now a boolean
  • Workspaces can only be marked as 'favorite' by their owner. This can be migrated to its own table later if we need to allow favoriting other users' workspaces, but I suspect the rule of YAGNI may apply here. Migrating this data to a separate table in future should be a simple and reversible operation.

Comment on lines +7777 to +7782
ifstrings.Compare(preloadedUsers[w1.ID].Username, preloadedUsers[w2.ID].Username) < 0 {
returntrue
}

// Order by: workspace names
returnsort.StringsAreSorted([]string{w1.Name, w2.Name})
returnstrings.Compare(w1.Name, w2.Name) < 0
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

review: fixes pre-existing ordering issue in dbmem that diverges from postgres behaviour

Comment on lines 1051 to 1053
httpapi.Write(ctx, rw, http.StatusForbidden, codersdk.Response{
Message: "You can only favorite workspaces that you own",
})
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

review: open to changing this response code if forbidden is not what we want here

Comment on lines 162 to 164
// 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
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

review: this is part of how we ensure that 'favorite' workspaces only come up first for their respective owners.

mafredri reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think the naming is a bit confusing when read in query/code. I.e. "order by favorite" being the users ID.

How about something like(Prioritize|Order)FavoritesForUser?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

How about justRequesterID?

@johnstcnjohnstcn marked this pull request as ready for reviewJanuary 24, 2024 09:43
@johnstcnjohnstcn requested a review fromEmyrkJanuary 24, 2024 10:58
Copy link
Member

@mtojekmtojek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Minor comments or questions

Comment on lines +953 to +954
r.Put("/favorite", api.putFavoriteWorkspace)
r.Delete("/favorite", api.deleteFavoriteWorkspace)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

nit: as we modify a single record inworkspaces, I would consider single PATCH operation. This form is also correct but longer.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

What you say is correct. One can also make an argument for the simplicity of a handler that does one thing only instead of a complex handler that maybe does many things. I don't feel particularly strongly either way; the separate handler approach seems to be more in line with existing conventions.

mtojek reacted with thumbs up emoji
@@ -1366,7 +1471,7 @@ func (api *API) workspaceData(ctx context.Context, workspaces []database.Workspa
}, nil
}

func convertWorkspaces(workspaces []database.Workspace, data workspaceData) ([]codersdk.Workspace, error) {
func convertWorkspaces(requesterID uuid.UUID,workspaces []database.Workspace, data workspaceData) ([]codersdk.Workspace, error) {
buildByWorkspaceID := map[uuid.UUID]codersdk.WorkspaceBuild{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

What do you think about adding a precondition here to fail fast if uuid.UUID is empty/null/zero?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

What would be the purpose of this?

Copy link
Member

@mtojekmtojekJan 24, 2024
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

To catch misuse ofconvertWorkspaces where it is called without user context.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Will address in a follow-up PR.

Copy link
Member

@mafredrimafredri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I prefer this approach to the previous one, nice! A few small comments, and I wonder if we really need an own endpoint for the favorite, vs patching the workspace 🤔. Not a deal-breaker by any means.

mtojek reacted with thumbs up emoji
@@ -1315,6 +1316,25 @@ func (*FakeQuerier) DeleteTailnetTunnel(_ context.Context, arg database.DeleteTa
return database.DeleteTailnetTunnelRow{}, ErrUnimplemented
}

func (q *FakeQuerier) FavoriteWorkspace(_ context.Context, arg uuid.UUID) error {
err := validateDatabaseType(arg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Was this added by code gen? I thought we only add it for whenarg is a struct (i.e.database.*Params). If it works, I don't see any harm though, it's more complete with the check in-place.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I believe you're correct, it's auto-added by codegen.

@@ -7713,7 +7753,15 @@ func (q *FakeQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg database.
w1 := workspaces[i]
w2 := workspaces[j]

// Order by: running first
// Order by: favorite first
if arg.OrderByFavorite == w1.OwnerID && w1.Favorite {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

If both are favorite, this might not produce the desired order. 🤔

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yeah that's possible, but as it's justdbmem I'm going to defer caring about it until it makes a test fail ;-)

Comment on lines 162 to 164
// 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think the naming is a bit confusing when read in query/code. I.e. "order by favorite" being the users ID.

How about something like(Prioritize|Order)FavoritesForUser?

@johnstcnjohnstcn merged commitf92336c intomainJan 24, 2024
@johnstcnjohnstcn deleted the cj/favorite-workspaces-redux branchJanuary 24, 2024 13:39
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsJan 24, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@mafredrimafredrimafredri left review comments

@mtojekmtojekmtojek approved these changes

@EmyrkEmyrkAwaiting requested review from Emyrk

Assignees

@johnstcnjohnstcn

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@johnstcn@mafredri@mtojek

[8]ページ先頭

©2009-2025 Movatter.jp