fix(backend): use to-be-set custom preferences when validating fields, remove constants

This commit is contained in:
Sam 2023-04-21 16:35:13 +02:00
parent 6dd3478ff9
commit 5594463a09
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
4 changed files with 47 additions and 52 deletions

View file

@ -106,18 +106,6 @@ func (s *Server) patchUser(w http.ResponseWriter, r *http.Request) error {
}
}
if err := validateSlicePtr("name", req.Names, u.CustomPreferences); err != nil {
return *err
}
if err := validateSlicePtr("pronoun", req.Pronouns, u.CustomPreferences); err != nil {
return *err
}
if err := validateSlicePtr("field", req.Fields, u.CustomPreferences); err != nil {
return *err
}
// validate custom preferences
if req.CustomPreferences != nil {
if count := len(*req.CustomPreferences); count > db.MaxFields {
@ -134,6 +122,22 @@ func (s *Server) patchUser(w http.ResponseWriter, r *http.Request) error {
}
}
}
customPreferences := u.CustomPreferences
if req.CustomPreferences != nil {
customPreferences = *req.CustomPreferences
}
if err := validateSlicePtr("name", req.Names, customPreferences); err != nil {
return *err
}
if err := validateSlicePtr("pronoun", req.Pronouns, customPreferences); err != nil {
return *err
}
if err := validateSlicePtr("field", req.Fields, customPreferences); err != nil {
return *err
}
// update avatar
var avatarHash *string = nil