fix: allow users to update language preference#1782
Conversation
Greptile SummaryThis PR fixes a permission error for regular users changing their UI language by introducing a new
Confidence Score: 5/5Safe to merge — the self-service update path is correctly scoped to the authenticated user and restricted to non-privileged profile fields. The user ID is extracted from the authenticated context before RunWithSystemBypass replaces the principal, so there is no path for a user to update another user's record. The field allowlist in UpdateOwnProfile excludes all admin-only fields (email, isOwner, scopes, roles). Password changes still require the old password to be verified at the resolver layer before reaching the service. The pattern mirrors how WithSystemBypass is already used elsewhere in the codebase. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant UpdateMe Resolver
participant UpdateOwnProfile
participant RunWithSystemBypass
participant Ent DB
Client->>UpdateMe Resolver: updateMe(input)
UpdateMe Resolver->>UpdateMe Resolver: contexts.GetUser(ctx) → nil check
UpdateMe Resolver->>UpdateOwnProfile: UpdateOwnProfile(ctx, input)
UpdateOwnProfile->>UpdateOwnProfile: contexts.GetUser(ctx) → capture id
UpdateOwnProfile->>RunWithSystemBypass: RunWithSystemBypass(ctx, "update-own-profile", fn)
RunWithSystemBypass->>RunWithSystemBypass: NewSystemContext(ctx) → system principal
RunWithSystemBypass->>Ent DB: UpdateOneID(id).Set*(fields).Save(bypassCtx)
Ent DB-->>RunWithSystemBypass: updated user
RunWithSystemBypass-->>UpdateOwnProfile: user
UpdateOwnProfile->>UpdateOwnProfile: invalidateUserCache(ctx, id)
UpdateOwnProfile-->>UpdateMe Resolver: user
UpdateMe Resolver-->>Client: User
Reviews (2): Last reviewed commit: "fix: allow users to update language pref..." | Re-trigger Greptile |
* fix: allow users to update language preference * fix: allow users to update language preference --------- Co-authored-by: evan <1095533987@qq.com>
Summary
This PR fixes a permission error that occurred when regular users changed their UI language.
Changes
updateMeresolver to use the self-service profile update path.firstName,lastName,preferLanguage,avatar, andpassword.UpdateUserpermission checks unchanged.Motivation
Changing the language preference calls the
updateMemutation withpreferLanguage.Previously,
updateMereused the admin user update service, which requires user management permissions. Regular users do not have those permissions, so saving the language preference failed withpermission denied.This change separates self-profile updates from admin user management updates, allowing users to update their own language preference safely.
Verification
Ran targeted backend tests:
go test ./internal/server/biz ./internal/server/gql Both packages passed.