Skip to content

Add RPCs for user preferences#35139

Merged
gzdunek merged 16 commits intomasterfrom
gzdunek/user-preferences-handlers
Dec 13, 2023
Merged

Add RPCs for user preferences#35139
gzdunek merged 16 commits intomasterfrom
gzdunek/user-preferences-handlers

Conversation

@gzdunek
Copy link
Copy Markdown
Contributor

@gzdunek gzdunek commented Nov 29, 2023

Contributes to #30422
Frontend part: #35251

This PR adds to new handlers to tshd:

  • GetUserPreferences
  • UpdateUserPreferences

We will need to them to fetch and update pinned resources and the active tab in the unified view.

The most important things:

  • To limit code duplication, I imported some protos from teleport/userpreferences. They work with no changes in Go code, but for JS I had to generate them for the first time. I decided to generate the JS code only for api/proto/teleport/userpreferences/ since this is the only part we need.
  • I created our own UserPreferences message that contains only the fields that are relevant to Connect. My reasoning was that we don't need theme or onboarding params. Also, if I used the full preferences message, on the JS side I would have (and anyone else who adds a new field) to map all these fields to a gRPC message in createClient.updateUserPreferences().
    The main problem with that is if someone else adds a new field to the user preferences, there won't be any error if that field is not mapped the gRPC message in JS.
  • The way authClient.UpdateUserPreferences() work is that it expects a full preferences message. If any field is missing, it will be reset to the default value. Since we work on a subset in tshd, I need to fetch the previous preferences first and modify only the changed fields. This may seem a bit ineffective, but as I mentioned above, the only other way is to work on full preferences messages.

I will connect these APIs with the unified resources view in a separate PR.

@gzdunek gzdunek added the no-changelog Indicates that a PR does not require a changelog entry label Nov 29, 2023
@gzdunek gzdunek requested review from avatus and ravicious November 29, 2023 16:11
@gzdunek gzdunek force-pushed the gzdunek/user-preferences-handlers branch from 5887ba3 to d42490e Compare November 29, 2023 16:20
@avatus
Copy link
Copy Markdown
Contributor

avatus commented Nov 29, 2023

In the web, there is a this notion of "global" user preferences and then "cluster" user preferences. The difference is mostly one always pulls from the root cluster, and the other pulls from whatever cluster is being requested (root or leaf or whatever). Is there a distinction here?

@gzdunek
Copy link
Copy Markdown
Contributor Author

gzdunek commented Nov 30, 2023

Yeah, I'm aware of that distinction (view mode and active tab are always taken from the root cluster, while pinned resources are taken from the target root or leaf cluster). But it seemed to me that it should be transparent at the tshd level and handled in a JS service (which will be done in the upcoming PR).

Comment thread build.assets/genproto.sh
Comment thread proto/teleport/lib/teleterm/v1/service.proto Outdated
Comment thread proto/teleport/lib/teleterm/v1/service.proto
Comment on lines +887 to +890
updateUserPreferences(
params: api.UpdateUserPreferencesRequest.AsObject,
abortSignal?: types.TshAbortSignal
): Promise<void> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The way authClient.UpdateUserPreferences() work is that it expects a full preferences message. If any field is missing, it will be reset to the default value. Since we work on a subset in tshd, I need to fetch the previous preferences first and modify only the changed fields. This may seem a bit ineffective, but as I mentioned above, the only other way is to work on full preferences messages.

Where do you plan to do this? In the client or in tshd?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@avatus Are there plans to support optimistic locking in user preferences? #30416

We should definitely use it here if it's available.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Where do you plan to do this? In the client or in tshd?

I did it in tshd.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@avatus Are there plans to support optimistic locking in user preferences? #30416

We should definitely use it here if it's available.

I have no idea what optimistic locking is but sounds neat! I'll have to look into it when I get back on Monday

…nd leaf cluster preferences, return updated preferences after changing them on a server
@gzdunek gzdunek marked this pull request as draft December 1, 2023 15:21
@gzdunek gzdunek requested a review from ravicious December 1, 2023 15:21
Copy link
Copy Markdown
Member

@ravicious ravicious left a comment

Choose a reason for hiding this comment

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

I haven't ran the new code for userpreferences but it looks okay!

Comment thread lib/teleterm/daemon/daemon.go Outdated
Comment thread lib/teleterm/services/userpreferences/userpreferences.go
Comment thread lib/teleterm/services/userpreferences/userpreferences.go Outdated
Comment thread lib/teleterm/services/userpreferences/userpreferences.go Outdated
Comment thread lib/teleterm/services/userpreferences/userpreferences.go
Comment thread lib/teleterm/services/userpreferences/userpreferences.go
@gzdunek gzdunek marked this pull request as ready for review December 6, 2023 15:35
Comment on lines +35 to +38
preferences, err := leafClient.GetUserPreferences(ctx, &userpreferencesv1.GetUserPreferencesRequest{})
if err != nil {
return nil, trace.Wrap(err)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this conditional should only overwrite cluster prefs and not userprefs. preferences held in UserPreferences (from the root) are the settings we don't want to change like selected theme and what not

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agree, but I think we are only overwriting the cluster preferences, no?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh yes, my bad. Read it wrong

@ibeckermayer ibeckermayer removed their request for review December 7, 2023 02:29
@gzdunek
Copy link
Copy Markdown
Contributor Author

gzdunek commented Dec 12, 2023

Added support for labelsViewMode.

Comment thread lib/teleterm/services/userpreferences/userpreferences.go
Comment thread lib/teleterm/services/userpreferences/userpreferences_test.go Outdated
Comment thread lib/teleterm/services/userpreferences/userpreferences_test.go Outdated
Comment thread lib/teleterm/services/userpreferences/userpreferences_test.go Outdated
@gzdunek gzdunek enabled auto-merge December 13, 2023 13:23
@gzdunek gzdunek added this pull request to the merge queue Dec 13, 2023
Merged via the queue into master with commit ef65501 Dec 13, 2023
@gzdunek gzdunek deleted the gzdunek/user-preferences-handlers branch December 13, 2023 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog Indicates that a PR does not require a changelog entry size/md ui

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants