Skip to content

Commit

Permalink
fix: use correct field name in user put api (#2026)
Browse files Browse the repository at this point in the history
  • Loading branch information
o1egl committed Jul 5, 2022
1 parent 06d9c03 commit d94acdd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion http/users.go
Expand Up @@ -177,7 +177,7 @@ var userPutHandler = withSelfOrAdmin(func(w http.ResponseWriter, r *http.Request
}

for k, v := range req.Which {
v = cases.Title(language.English).String(v)
v = cases.Title(language.English, cases.NoLower).String(v)
req.Which[k] = v

if v == "Password" {
Expand Down
7 changes: 6 additions & 1 deletion storage/bolt/users.go
@@ -1,6 +1,7 @@
package bolt

import (
"fmt"
"reflect"

"github.com/asdine/storm/v3"
Expand Down Expand Up @@ -58,7 +59,11 @@ func (st usersBackend) Update(user *users.User, fields ...string) error {
}

for _, field := range fields {
val := reflect.ValueOf(user).Elem().FieldByName(field).Interface()
userField := reflect.ValueOf(user).Elem().FieldByName(field)
if !userField.IsValid() {
return fmt.Errorf("invalid field: %s", field)
}
val := userField.Interface()
if err := st.db.UpdateField(user, field, val); err != nil {
return err
}
Expand Down

0 comments on commit d94acdd

Please sign in to comment.