mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-16 04:05:00 +00:00
refactor: form binding validation (#38832)
Make "form-fetch-action" highlight the invalid field as "error"
This commit is contained in:
+49
-14
@@ -26,6 +26,8 @@ import (
|
||||
"gitea.dev/modules/web"
|
||||
"gitea.dev/modules/web/middleware"
|
||||
web_types "gitea.dev/modules/web/types"
|
||||
|
||||
"gitea.com/go-chi/binding"
|
||||
)
|
||||
|
||||
// Render represents a template render
|
||||
@@ -81,17 +83,22 @@ func GetWebContext(ctx context.Context) *Context {
|
||||
return webCtx
|
||||
}
|
||||
|
||||
// ValidateContext is a special context for form validation middleware. It may be different from other contexts.
|
||||
type ValidateContext struct {
|
||||
*Base
|
||||
}
|
||||
|
||||
// GetValidateContext gets a context for middleware form validation
|
||||
func GetValidateContext(req *http.Request) (ctx *ValidateContext) {
|
||||
func GetValidateContext(req *http.Request) (ctx *middleware.ValidateContext) {
|
||||
if ctxAPI, ok := req.Context().Value(apiContextKey).(*APIContext); ok {
|
||||
ctx = &ValidateContext{Base: ctxAPI.Base}
|
||||
ctx = &middleware.ValidateContext{
|
||||
Data: ctxAPI.Data,
|
||||
Locale: ctxAPI.Locale,
|
||||
Req: ctxAPI.Req,
|
||||
Resp: ctxAPI.Resp,
|
||||
}
|
||||
} else if ctxWeb, ok := req.Context().Value(WebContextKey).(*Context); ok {
|
||||
ctx = &ValidateContext{Base: ctxWeb.Base}
|
||||
ctx = &middleware.ValidateContext{
|
||||
Data: ctxWeb.Data,
|
||||
Locale: ctxWeb.Locale,
|
||||
Req: ctxWeb.Req,
|
||||
Resp: ctxWeb.Resp,
|
||||
}
|
||||
} else {
|
||||
panic("invalid context, expect either APIContext or Context")
|
||||
}
|
||||
@@ -254,15 +261,24 @@ func (ctx *Context) JSONOK() {
|
||||
ctx.JSON(http.StatusOK, map[string]any{"ok": true}) // this is only a dummy response, frontend seldom uses it
|
||||
}
|
||||
|
||||
func (ctx *Context) JSONError(msg any) {
|
||||
func buildJsonErrorMap(msg any) map[string]any {
|
||||
switch v := msg.(type) {
|
||||
case string:
|
||||
ctx.JSON(http.StatusBadRequest, map[string]any{"errorMessage": v, "renderFormat": "text"})
|
||||
return map[string]any{"errorMessage": v, "renderFormat": "text"}
|
||||
case template.HTML:
|
||||
ctx.JSON(http.StatusBadRequest, map[string]any{"errorMessage": v, "renderFormat": "html"})
|
||||
default:
|
||||
panic(fmt.Sprintf("unsupported type: %T", msg))
|
||||
return map[string]any{"errorMessage": v, "renderFormat": "html"}
|
||||
}
|
||||
panic(fmt.Sprintf("unsupported type: %T", msg))
|
||||
}
|
||||
|
||||
func (ctx *Context) JSONError(msg any) {
|
||||
ctx.JSON(http.StatusBadRequest, buildJsonErrorMap(msg))
|
||||
}
|
||||
|
||||
func (ctx *Context) JSONErrorWithField(msg any, field string) {
|
||||
m := buildJsonErrorMap(msg)
|
||||
m["errorFields"] = []string{field}
|
||||
ctx.JSON(http.StatusBadRequest, m)
|
||||
}
|
||||
|
||||
func (ctx *Context) JSONErrorNotFound(optMsg ...string) {
|
||||
@@ -270,5 +286,24 @@ func (ctx *Context) JSONErrorNotFound(optMsg ...string) {
|
||||
if msg == "" {
|
||||
msg = ctx.Locale.TrString("error.not_found")
|
||||
}
|
||||
ctx.JSON(http.StatusNotFound, map[string]any{"errorMessage": msg, "renderFormat": "text"})
|
||||
ctx.JSON(http.StatusNotFound, buildJsonErrorMap(msg))
|
||||
}
|
||||
|
||||
func GetFetchActionForm[T interface {
|
||||
*E
|
||||
middleware.Form
|
||||
}, E any](ctx *Context) *E {
|
||||
if web.IsFormSet(ctx) {
|
||||
panic("don't mix fetch-action form validation with template-based form validation")
|
||||
}
|
||||
middleware.SkipTmplFormValidationError(ctx)
|
||||
form := T(new(E))
|
||||
errs := binding.Bind(ctx.Req, form)
|
||||
errorMessage, fieldName, _ := middleware.BuildValidationErrorForUser(form, ctx.Locale, errs)
|
||||
if errorMessage != "" {
|
||||
ctx.Resp.Header().Set("Content-Type", "application/json")
|
||||
ctx.JSONErrorWithField(errorMessage, fieldName)
|
||||
return nil
|
||||
}
|
||||
return form
|
||||
}
|
||||
|
||||
@@ -104,6 +104,12 @@ func MockPrivateContext(t *testing.T, reqPath string) (*context.PrivateContext,
|
||||
return ctx, resp
|
||||
}
|
||||
|
||||
func MockRequestPostForm(req *http.Request, formData url.Values) {
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
req.PostForm = formData
|
||||
maps.Copy(req.Form, formData)
|
||||
}
|
||||
|
||||
// LoadRepo load a repo into a test context.
|
||||
func LoadRepo(t *testing.T, ctx gocontext.Context, repoID int64) {
|
||||
var doer *user_model.User
|
||||
|
||||
@@ -41,19 +41,19 @@ type AdminEditBadgeForm struct {
|
||||
// Validate validates form fields
|
||||
func (f *AdminCreateBadgeForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// Validate validates form fields
|
||||
func (f *AdminEditBadgeForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// Validate validates form fields
|
||||
func (f *AdminCreateUserForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// AdminEditUserForm form for admin to create user
|
||||
@@ -82,7 +82,7 @@ type AdminEditUserForm struct {
|
||||
// Validate validates form fields
|
||||
func (f *AdminEditUserForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// AdminDashboardForm form for admin dashboard operations
|
||||
@@ -94,5 +94,5 @@ type AdminDashboardForm struct {
|
||||
// Validate validates form fields
|
||||
func (f *AdminDashboardForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
@@ -100,5 +100,5 @@ type AuthenticationForm struct {
|
||||
// Validate validates fields
|
||||
func (f *AuthenticationForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ type CreateOrgForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *CreateOrgForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// UpdateOrgSettingForm form for updating organization settings
|
||||
@@ -48,7 +48,7 @@ type UpdateOrgSettingForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *UpdateOrgSettingForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
type RenameOrgForm struct {
|
||||
@@ -76,5 +76,5 @@ type CreateTeamForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *CreateTeamForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
@@ -26,5 +26,5 @@ type PackageCleanupRuleForm struct {
|
||||
|
||||
func (f *PackageCleanupRuleForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ type NewBranchForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *NewBranchForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// RenameBranchForm form for rename a branch
|
||||
@@ -34,5 +34,5 @@ type RenameBranchForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *RenameBranchForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
+32
-36
@@ -50,7 +50,7 @@ type CreateRepoForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *CreateRepoForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// MigrateRepoForm form for migrating repository
|
||||
@@ -86,7 +86,7 @@ type MigrateRepoForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *MigrateRepoForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// RepoSettingForm form for changing repository settings
|
||||
@@ -163,7 +163,7 @@ type RepoSettingForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *RepoSettingForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// ProtectBranchForm form for changing protected branch settings
|
||||
@@ -205,7 +205,7 @@ type ProtectBranchForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *ProtectBranchForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// WebhookForm form for changing web hook
|
||||
@@ -268,7 +268,7 @@ type NewWebhookForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *NewWebhookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// NewGogshookForm form for creating gogs hook
|
||||
@@ -281,7 +281,7 @@ type NewGogshookForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *NewGogshookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// NewSlackHookForm form for creating slack hook
|
||||
@@ -298,13 +298,9 @@ type NewSlackHookForm struct {
|
||||
func (f *NewSlackHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
if !webhook.IsValidSlackChannel(strings.TrimSpace(f.Channel)) {
|
||||
errs = append(errs, binding.Error{
|
||||
FieldNames: []string{"Channel"},
|
||||
Classification: "",
|
||||
Message: ctx.Locale.TrString("repo.settings.add_webhook.invalid_channel_name"),
|
||||
})
|
||||
errs = middleware.AddValidationError(errs, "Channel", ctx.Locale.TrString("repo.settings.add_webhook.invalid_channel_name"))
|
||||
}
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// NewDiscordHookForm form for creating discord hook
|
||||
@@ -318,7 +314,7 @@ type NewDiscordHookForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *NewDiscordHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// NewDingtalkHookForm form for creating dingtalk hook
|
||||
@@ -330,7 +326,7 @@ type NewDingtalkHookForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *NewDingtalkHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// NewTelegramHookForm form for creating telegram hook
|
||||
@@ -344,7 +340,7 @@ type NewTelegramHookForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *NewTelegramHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// NewMatrixHookForm form for creating Matrix hook
|
||||
@@ -358,7 +354,7 @@ type NewMatrixHookForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *NewMatrixHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// NewMSTeamsHookForm form for creating MS Teams hook
|
||||
@@ -370,7 +366,7 @@ type NewMSTeamsHookForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *NewMSTeamsHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// NewFeishuHookForm form for creating feishu hook
|
||||
@@ -382,7 +378,7 @@ type NewFeishuHookForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *NewFeishuHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// NewWechatWorkHookForm form for creating wechatwork hook
|
||||
@@ -394,7 +390,7 @@ type NewWechatWorkHookForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *NewWechatWorkHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// NewPackagistHookForm form for creating packagist hook
|
||||
@@ -408,7 +404,7 @@ type NewPackagistHookForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *NewPackagistHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// CreateIssueForm form for creating issue
|
||||
@@ -426,7 +422,7 @@ type CreateIssueForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *CreateIssueForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// CreateCommentForm form for creating comment
|
||||
@@ -439,7 +435,7 @@ type CreateCommentForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *CreateCommentForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// ReactionForm form for adding and removing reaction
|
||||
@@ -450,7 +446,7 @@ type ReactionForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *ReactionForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// IssueLockForm form for locking an issue
|
||||
@@ -459,9 +455,9 @@ type IssueLockForm struct {
|
||||
}
|
||||
|
||||
// Validate validates the fields
|
||||
func (i *IssueLockForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
func (f *IssueLockForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, i, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// CreateProjectForm form for creating a project
|
||||
@@ -489,7 +485,7 @@ type CreateMilestoneForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *CreateMilestoneForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// CreateLabelForm form for creating label
|
||||
@@ -506,7 +502,7 @@ type CreateLabelForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *CreateLabelForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// InitializeLabelsForm form for initializing labels
|
||||
@@ -517,7 +513,7 @@ type InitializeLabelsForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *InitializeLabelsForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// MergePullRequestForm form for merging Pull Request
|
||||
@@ -571,7 +567,7 @@ func (f *MergePullRequestForm) UnmarshalJSON(b []byte) error {
|
||||
// Validate validates the fields
|
||||
func (f *MergePullRequestForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// CodeCommentForm form for adding code comments for PRs
|
||||
@@ -590,7 +586,7 @@ type CodeCommentForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *CodeCommentForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// SubmitReviewForm for submitting a finished code review
|
||||
@@ -604,7 +600,7 @@ type SubmitReviewForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *SubmitReviewForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// ReviewType will return the corresponding ReviewType for type
|
||||
@@ -665,7 +661,7 @@ type NewReleaseForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *NewReleaseForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// GenerateReleaseNotesForm retrieves release notes recommendations.
|
||||
@@ -678,7 +674,7 @@ type GenerateReleaseNotesForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *GenerateReleaseNotesForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// EditReleaseForm form for changing release
|
||||
@@ -693,7 +689,7 @@ type EditReleaseForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *EditReleaseForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// __ __.__ __ .__
|
||||
@@ -714,7 +710,7 @@ type NewWikiForm struct {
|
||||
// FIXME: use code generation to generate this method.
|
||||
func (f *NewWikiForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// ___________.__ ___________ __
|
||||
@@ -733,7 +729,7 @@ type AddTimeManuallyForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *AddTimeManuallyForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// SaveTopicForm form for save topics for repository
|
||||
|
||||
@@ -26,7 +26,7 @@ type CommitCommonForm struct {
|
||||
|
||||
func (f *CommitCommonForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
type CommitCommonFormInterface interface {
|
||||
|
||||
@@ -22,5 +22,5 @@ type ProtectTagForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *ProtectTagForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
@@ -20,5 +20,5 @@ type EditRunnerForm struct {
|
||||
// Validate validates form fields
|
||||
func (f *EditRunnerForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
+26
-26
@@ -77,7 +77,7 @@ type InstallForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *InstallForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// _____ ____ _________________ ___
|
||||
@@ -98,7 +98,7 @@ type RegisterForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *RegisterForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// IsEmailDomainAllowed validates that the email address
|
||||
@@ -120,7 +120,7 @@ type MustChangePasswordForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *MustChangePasswordForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// SignInForm form for signing in with user/password
|
||||
@@ -134,7 +134,7 @@ type SignInForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *SignInForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// AuthorizationForm form for authorizing oauth2 clients
|
||||
@@ -154,7 +154,7 @@ type AuthorizationForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *AuthorizationForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// GrantApplicationForm form for authorizing oauth2 clients
|
||||
@@ -170,7 +170,7 @@ type GrantApplicationForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *GrantApplicationForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// AccessTokenForm for issuing access tokens from authorization codes or refresh tokens
|
||||
@@ -189,7 +189,7 @@ type AccessTokenForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *AccessTokenForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// IntrospectTokenForm for introspecting tokens
|
||||
@@ -200,7 +200,7 @@ type IntrospectTokenForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *IntrospectTokenForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// __________________________________________.___ _______ ________ _________
|
||||
@@ -225,7 +225,7 @@ type UpdateProfileForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *UpdateProfileForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// UpdateLanguageForm form for updating profile
|
||||
@@ -236,7 +236,7 @@ type UpdateLanguageForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *UpdateLanguageForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// Avatar types
|
||||
@@ -256,7 +256,7 @@ type AvatarForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *AvatarForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// AddEmailForm form for adding new email
|
||||
@@ -267,7 +267,7 @@ type AddEmailForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *AddEmailForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// UpdateThemeForm form for updating a users' theme
|
||||
@@ -278,7 +278,7 @@ type UpdateThemeForm struct {
|
||||
// Validate validates the field
|
||||
func (f *UpdateThemeForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// ChangePasswordForm form for changing password
|
||||
@@ -291,7 +291,7 @@ type ChangePasswordForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *ChangePasswordForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// AddOpenIDForm is for changing openid uri
|
||||
@@ -302,7 +302,7 @@ type AddOpenIDForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *AddOpenIDForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// AddKeyForm form for adding SSH/GPG key
|
||||
@@ -319,7 +319,7 @@ type AddKeyForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *AddKeyForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// AddSecretForm for adding secrets
|
||||
@@ -332,7 +332,7 @@ type AddSecretForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *AddSecretForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
type EditVariableForm struct {
|
||||
@@ -343,7 +343,7 @@ type EditVariableForm struct {
|
||||
|
||||
func (f *EditVariableForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// NewAccessTokenForm form for creating access token
|
||||
@@ -354,7 +354,7 @@ type NewAccessTokenForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *NewAccessTokenForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// EditOAuth2ApplicationForm form for editing oauth2 applications
|
||||
@@ -381,9 +381,9 @@ func (f *EditOAuth2ApplicationForm) Validate(req *http.Request, errs binding.Err
|
||||
ctx := context.GetValidateContext(req)
|
||||
invalidURI := DetectInvalidOAuth2ApplicationRedirectURI(util.SplitTrimSpace(f.RedirectURIs, "\n"))
|
||||
if invalidURI != "" {
|
||||
errs = middleware.ReportValidationError(errs, ctx.Data, "RedirectURIs", binding.ERR_URL, ctx.Locale.TrString("form.url_error", invalidURI))
|
||||
errs = middleware.AddValidationError(errs, "RedirectURIs", "RedirectURIs: "+ctx.Locale.TrString("form.url_error", `"`+invalidURI+`"`))
|
||||
}
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// TwoFactorAuthForm for logging in with 2FA token.
|
||||
@@ -394,7 +394,7 @@ type TwoFactorAuthForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *TwoFactorAuthForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// TwoFactorScratchAuthForm for logging in with 2FA scratch token.
|
||||
@@ -405,7 +405,7 @@ type TwoFactorScratchAuthForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *TwoFactorScratchAuthForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// WebauthnRegistrationForm for reserving an WebAuthn name
|
||||
@@ -416,7 +416,7 @@ type WebauthnRegistrationForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *WebauthnRegistrationForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// PackageSettingForm form for package settings
|
||||
@@ -428,7 +428,7 @@ type PackageSettingForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *PackageSettingForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
type BlockUserForm struct {
|
||||
@@ -439,5 +439,5 @@ type BlockUserForm struct {
|
||||
|
||||
func (f *BlockUserForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ type SignInOpenIDForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *SignInOpenIDForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// SignUpOpenIDForm form for signin up with OpenID
|
||||
@@ -33,7 +33,7 @@ type SignUpOpenIDForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *SignUpOpenIDForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// ConnectOpenIDForm form for connecting an existing account to an OpenID URI
|
||||
@@ -45,5 +45,5 @@ type ConnectOpenIDForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *ConnectOpenIDForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user