fix(api): update profile handling to ensure only the name field is modified.

This commit is contained in:
Miroslav Šedivý
2026-04-06 20:41:07 +02:00
parent 716c60af28
commit c54bcf1ee2
+14 -4
View File
@@ -84,15 +84,25 @@ func (api *ApiManagerCtx) Whoami(w http.ResponseWriter, r *http.Request) error {
}) })
} }
// TODO: Remove when legacy mode is removed as all sessions must be synced with their providers.
func (api *ApiManagerCtx) UpdateProfile(w http.ResponseWriter, r *http.Request) error { func (api *ApiManagerCtx) UpdateProfile(w http.ResponseWriter, r *http.Request) error {
session, _ := auth.GetSession(r) session, _ := auth.GetSession(r)
data := session.Profile() profile := session.Profile()
if err := utils.HttpJsonRequest(w, r, &data); err != nil { if !profile.IsAdmin {
return err // Name is the only updatable field in the profile for non-admins
var payload types.MemberProfile
if err := utils.HttpJsonRequest(w, r, &payload); err != nil {
return err
}
profile.Name = payload.Name
} else {
if err := utils.HttpJsonRequest(w, r, &profile); err != nil {
return err
}
} }
err := api.sessions.Update(session.ID(), data) err := api.sessions.Update(session.ID(), profile)
if err != nil { if err != nil {
if errors.Is(err, types.ErrSessionNotFound) { if errors.Is(err, types.ErrSessionNotFound) {
return utils.HttpBadRequest("session does not exist") return utils.HttpBadRequest("session does not exist")