From f518f649f800e52d32fe53580c528ffa042f7154 Mon Sep 17 00:00:00 2001 From: zowhoey <11893985+zowhoey@users.noreply.github.com> Date: Mon, 6 Mar 2023 09:30:19 +0000 Subject: [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> --- internal/processing/account/update.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'internal/processing') 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)) -- cgit v1.2.3