diff options
author | 2023-03-06 09:30:19 +0000 | |
---|---|---|
committer | 2023-03-06 10:30:19 +0100 | |
commit | f518f649f800e52d32fe53580c528ffa042f7154 (patch) | |
tree | c14bb8b513008d1c1e7bab0908cfc99fe18f1507 /internal/processing/account/update.go | |
parent | [chore]: Bump github.com/jackc/pgx/v4 from 4.17.2 to 4.18.1 (#1595) (diff) | |
download | gotosocial-f518f649f800e52d32fe53580c528ffa042f7154.tar.xz |
[feature] Add support for profile fields (#1483)
* Add go-playground/form pkg
* [feature] Add support for profile fields
* Add field attributes test
* Validate profile fields form
* Add profile field validation tests
* Add Field Attributes definition to swagger
---------
Co-authored-by: tobi <31960611+tsmethurst@users.noreply.github.com>
Diffstat (limited to 'internal/processing/account/update.go')
-rw-r--r-- | internal/processing/account/update.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/internal/processing/account/update.go b/internal/processing/account/update.go index a96c17eeb..76f7a5a54 100644 --- a/internal/processing/account/update.go +++ b/internal/processing/account/update.go @@ -165,6 +165,26 @@ func (p *Processor) Update(ctx context.Context, account *gtsmodel.Account, form account.EnableRSS = form.EnableRSS } + if form.FieldsAttributes != nil && len(*form.FieldsAttributes) != 0 { + if err := validate.ProfileFieldsCount(*form.FieldsAttributes); err != nil { + return nil, gtserror.NewErrorBadRequest(err) + } + + account.Fields = make([]gtsmodel.Field, 0) // reset fields + for _, f := range *form.FieldsAttributes { + if f.Name != nil && f.Value != nil { + if *f.Name != "" && *f.Value != "" { + field := gtsmodel.Field{} + + field.Name = validate.ProfileField(f.Name) + field.Value = validate.ProfileField(f.Value) + + account.Fields = append(account.Fields, field) + } + } + } + } + err := p.state.DB.UpdateAccount(ctx, account) if err != nil { return nil, gtserror.NewErrorInternalError(fmt.Errorf("could not update account %s: %s", account.ID, err)) |