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
+13 -3
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 {
session, _ := auth.GetSession(r)
data := session.Profile()
if err := utils.HttpJsonRequest(w, r, &data); err != nil {
profile := session.Profile()
if !profile.IsAdmin {
// 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 errors.Is(err, types.ErrSessionNotFound) {
return utils.HttpBadRequest("session does not exist")