MCPcopy Index your code
hub / github.com/rilldata/rill / UpdateUserPreferences

Method UpdateUserPreferences

admin/server/users.go:131–175  ·  view source on GitHub ↗
(ctx context.Context, req *adminv1.UpdateUserPreferencesRequest)

Source from the content-addressed store, hash-verified

129}
130
131func (s *Server) UpdateUserPreferences(ctx context.Context, req *adminv1.UpdateUserPreferencesRequest) (*adminv1.UpdateUserPreferencesResponse, error) {
132 claims := auth.GetClaims(ctx)
133
134 // Error if authenticated as anything other than a user
135 if claims.OwnerType() != auth.OwnerTypeUser {
136 return nil, status.Error(codes.Unauthenticated, "not authenticated as a user")
137 }
138
139 if req.Preferences.TimeZone != nil {
140 _, err := time.LoadLocation(*req.Preferences.TimeZone)
141 if err != nil {
142 return nil, status.Errorf(codes.InvalidArgument, "invalid time zone: %s", *req.Preferences.TimeZone)
143 }
144
145 observability.AddRequestAttributes(ctx, attribute.String("preferences_time_zone", *req.Preferences.TimeZone))
146 }
147
148 // Owner is a user
149 user, err := s.admin.DB.FindUser(ctx, claims.OwnerID())
150 if err != nil {
151 return nil, err
152 }
153
154 // Update user quota here
155 updatedUser, err := s.admin.DB.UpdateUser(ctx, user.ID, &database.UpdateUserOptions{
156 DisplayName: user.DisplayName,
157 PhotoURL: user.PhotoURL,
158 GithubUsername: user.GithubUsername,
159 GithubToken: user.GithubToken,
160 GithubTokenExpiresOn: user.GithubTokenExpiresOn,
161 GithubRefreshToken: user.GithubRefreshToken,
162 QuotaSingleuserOrgs: user.QuotaSingleuserOrgs,
163 QuotaTrialOrgs: user.QuotaTrialOrgs,
164 PreferenceTimeZone: valOrDefault(req.Preferences.TimeZone, user.PreferenceTimeZone),
165 })
166 if err != nil {
167 return nil, err
168 }
169
170 return &adminv1.UpdateUserPreferencesResponse{
171 Preferences: &adminv1.UserPreferences{
172 TimeZone: &updatedUser.PreferenceTimeZone,
173 },
174 }, nil
175}
176
177func (s *Server) ListUserAuthTokens(ctx context.Context, req *adminv1.ListUserAuthTokensRequest) (*adminv1.ListUserAuthTokensResponse, error) {
178 observability.AddRequestAttributes(ctx,

Callers

nothing calls this directly

Calls 10

GetClaimsFunction · 0.92
AddRequestAttributesFunction · 0.92
valOrDefaultFunction · 0.70
OwnerTypeMethod · 0.65
ErrorfMethod · 0.65
StringMethod · 0.65
FindUserMethod · 0.65
OwnerIDMethod · 0.65
UpdateUserMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected