Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support editing setter return global error #598

Merged
merged 4 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/docsrc/examples/examples_presets/editing.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ func PresetsEditingSetter(b *presets.Builder, db *gorm.DB) (
if c.Name == "" {
return errors.New("name must not be empty")
}
if c.Name == "global" {
return web.ValidationGlobalError(errors.New(`You can not use global as name`))
}

return
})
eb.Field("Name").LazyWrapSetterFunc(func(in presets.FieldSetterFunc) presets.FieldSetterFunc {
Expand Down
12 changes: 12 additions & 0 deletions docs/docsrc/examples/examples_presets/editing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ func TestPresetsEditingSetter(t *testing.T) {
},
ExpectPortalUpdate0ContainsInOrder: []string{`You can not use \"system\" as name`},
},
{
Name: "setter return global error",
Debug: true,
ReqFunc: func() *http.Request {
companyData.TruncatePut(SqlDB)
return multipartestutils.NewMultipartBuilder().
PageURL("/companies?__execute_event__=presets_Update").
AddField("Name", "global").
BuildEventFuncRequest()
},
ExpectPortalUpdate0ContainsInOrder: []string{"You can not use global as name"},
},
}

for _, c := range cases {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/pquerna/otp v1.4.0
github.com/qor/oss v0.0.0-20240729105053-88484a799a79
github.com/qor5/web v1.3.2
github.com/qor5/web/v3 v3.0.8
github.com/qor5/web/v3 v3.0.9-0.20240925032527-e126c3282af2
github.com/qor5/x/v3 v3.0.10-0.20240925021357-ed67be38075d
github.com/samber/lo v1.47.0
github.com/shurcooL/sanitized_anchor_name v1.0.0
Expand Down
10 changes: 2 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,8 @@ github.com/qor/oss v0.0.0-20240729105053-88484a799a79 h1:MXQCoxxGj15XjuOSdhkLrPs
github.com/qor/oss v0.0.0-20240729105053-88484a799a79/go.mod h1:FDxJAVwmZ1j8ITcKJExFlzkTYuUor1dBKZgNVWqEqlM=
github.com/qor5/web v1.3.2 h1:zw796YJeDLe8vRwGR1cM+uS1ZuSkPutchBEXv2GgOhI=
github.com/qor5/web v1.3.2/go.mod h1:LszskQJbFQDJwOeZC6j6afOiHxxyjrzz8B3zuBwfgKQ=
github.com/qor5/web/v3 v3.0.8 h1:Fgr36QtGTK9Sb0YXU705a+oL7UoybfeBQ8FESXnTDSk=
github.com/qor5/web/v3 v3.0.8/go.mod h1:32vdHHcZb2JimlcaclW9hLUyimdXjrllZDHTh3rl6d0=
github.com/qor5/x/v3 v3.0.10-0.20240923031926-4715a7497269 h1:4CS1Fug99k+kyjfULtIQ05ROtPcJLQJS9Cr2bX6jedI=
github.com/qor5/x/v3 v3.0.10-0.20240923031926-4715a7497269/go.mod h1:ebg7TORMQLVRlZyDyZbAsxbQoiN4wMBVhyFHdYxv6Tw=
github.com/qor5/x/v3 v3.0.10-0.20240923055518-106596f5c644 h1:J0E/cE5nLtS4/tR9o+eHlww6wvCsxfaS0Tb4Nv024ZU=
github.com/qor5/x/v3 v3.0.10-0.20240923055518-106596f5c644/go.mod h1:ebg7TORMQLVRlZyDyZbAsxbQoiN4wMBVhyFHdYxv6Tw=
github.com/qor5/x/v3 v3.0.10-0.20240924084242-ac9f2e5bf1a7 h1:cv6ZBvQ1qTUhbn5CtcMKv39T7WArYR+M3UVez8G1ZHk=
github.com/qor5/x/v3 v3.0.10-0.20240924084242-ac9f2e5bf1a7/go.mod h1:ebg7TORMQLVRlZyDyZbAsxbQoiN4wMBVhyFHdYxv6Tw=
github.com/qor5/web/v3 v3.0.9-0.20240925032527-e126c3282af2 h1:M19hKQryK3MM7UQdb9Mwg5y/NO1hjooH9aptPpWWX2w=
github.com/qor5/web/v3 v3.0.9-0.20240925032527-e126c3282af2/go.mod h1:32vdHHcZb2JimlcaclW9hLUyimdXjrllZDHTh3rl6d0=
github.com/qor5/x/v3 v3.0.10-0.20240925021357-ed67be38075d h1:V1avyyGkhHH+Z3RKhU+wfAeywWCyfLtdrynQc9GUqvQ=
github.com/qor5/x/v3 v3.0.10-0.20240925021357-ed67be38075d/go.mod h1:ebg7TORMQLVRlZyDyZbAsxbQoiN4wMBVhyFHdYxv6Tw=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
Expand Down
6 changes: 5 additions & 1 deletion presets/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,11 @@ func (b *FieldsBuilder) SetObjectFields(fromObj interface{}, toObj interface{},
Label: b.getLabel(f.NameLabel),
}, ctx)
if err1 != nil {
vErr.FieldError(f.name, err1.Error())
if web.IsValidationGlobalError(err1) {
vErr.GlobalError(err1.Error())
} else {
vErr.FieldError(f.name, err1.Error())
}
}
}
return
Expand Down
Loading