fix(backend): use to-be-set custom preferences when validating fields, remove constants
This commit is contained in:
parent
6dd3478ff9
commit
5594463a09
4 changed files with 47 additions and 52 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue