[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>
This commit is contained in:
zowhoey
2023-03-06 09:30:19 +00:00
committed by GitHub
parent 24f6a447f3
commit f518f649f8
21 changed files with 2399 additions and 2 deletions

View File

@@ -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))