diff options
author | oliverpool <3864879+oliverpool@users.noreply.github.com> | 2022-08-11 17:48:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-11 17:48:23 +0200 |
commit | c81b26b0e52f55fcdf94b50a14bca3dfc375e2a9 (patch) | |
tree | acccd4400733b5505a86ca668ceb4167119789fe /services/forms | |
parent | 2b4d43dd4d7388ff73e99c143008ad4663142e61 (diff) | |
download | gitea-c81b26b0e52f55fcdf94b50a14bca3dfc375e2a9.tar.gz gitea-c81b26b0e52f55fcdf94b50a14bca3dfc375e2a9.zip |
refactor webhook *NewPost (#20729)
* refactor webhook *NewPost
* remove empty values
* always show errs.Message
* remove utils.IsValidSlackChannel
* move IsValidSlackChannel to services/webhook package
* binding: handle empty Message case
* make IsValidSlackChannel more strict
Diffstat (limited to 'services/forms')
-rw-r--r-- | services/forms/repo_form.go | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/services/forms/repo_form.go b/services/forms/repo_form.go index afecc205f3..7a4a2123eb 100644 --- a/services/forms/repo_form.go +++ b/services/forms/repo_form.go @@ -17,7 +17,7 @@ import ( "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/web/middleware" - "code.gitea.io/gitea/routers/utils" + "code.gitea.io/gitea/services/webhook" "gitea.com/go-chi/binding" ) @@ -305,14 +305,16 @@ type NewSlackHookForm struct { // Validate validates the fields func (f *NewSlackHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors { ctx := context.GetContext(req) + if !webhook.IsValidSlackChannel(strings.TrimSpace(f.Channel)) { + errs = append(errs, binding.Error{ + FieldNames: []string{"Channel"}, + Classification: "", + Message: ctx.Tr("repo.settings.add_webhook.invalid_channel_name"), + }) + } return middleware.Validate(errs, ctx.Data, f, ctx.Locale) } -// HasInvalidChannel validates the channel name is in the right format -func (f NewSlackHookForm) HasInvalidChannel() bool { - return !utils.IsValidSlackChannel(f.Channel) -} - // NewDiscordHookForm form for creating discord hook type NewDiscordHookForm struct { PayloadURL string `binding:"Required;ValidUrl"` |