mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-16 23:51:46 +00:00
refactor: clean up form binding & validation (#38873)
Clarify the "validation" and "error display" logic. All the copied&pasted `Validate` functions are removed.
This commit is contained in:
+4
-23
@@ -5,13 +5,8 @@
|
||||
package forms
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"gitea.dev/modules/structs"
|
||||
"gitea.dev/modules/web/middleware"
|
||||
"gitea.dev/services/context"
|
||||
|
||||
"gitea.com/go-chi/binding"
|
||||
)
|
||||
|
||||
// ________ .__ __ .__
|
||||
@@ -23,19 +18,15 @@ import (
|
||||
|
||||
// CreateOrgForm form for creating organization
|
||||
type CreateOrgForm struct {
|
||||
middleware.FormDefaultValidator
|
||||
OrgName string `binding:"Required;Username;MaxSize(40)" locale:"org.org_name_holder"`
|
||||
Visibility structs.VisibleType
|
||||
RepoAdminChangeTeamAccess bool
|
||||
}
|
||||
|
||||
// Validate validates the fields
|
||||
func (f *CreateOrgForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// UpdateOrgSettingForm form for updating organization settings
|
||||
type UpdateOrgSettingForm struct {
|
||||
middleware.FormDefaultValidator
|
||||
FullName *string `binding:"MaxSize(100)"`
|
||||
Email *string `binding:"MaxSize(255)"`
|
||||
Description *string `binding:"MaxSize(255)"`
|
||||
@@ -45,13 +36,8 @@ type UpdateOrgSettingForm struct {
|
||||
RepoAdminChangeTeamAccess *bool
|
||||
}
|
||||
|
||||
// Validate validates the fields
|
||||
func (f *UpdateOrgSettingForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
type RenameOrgForm struct {
|
||||
middleware.FormDefaultValidator
|
||||
OrgName string `binding:"Required"`
|
||||
NewOrgName string `binding:"Required;Username;MaxSize(40)" locale:"org.org_name_holder"`
|
||||
}
|
||||
@@ -65,6 +51,7 @@ type RenameOrgForm struct {
|
||||
|
||||
// CreateTeamForm form for creating team
|
||||
type CreateTeamForm struct {
|
||||
middleware.FormDefaultValidator
|
||||
TeamName string `binding:"Required;AlphaDashDot;MaxSize(255)"`
|
||||
Description string `binding:"MaxSize(255)"`
|
||||
Permission string
|
||||
@@ -72,9 +59,3 @@ type CreateTeamForm struct {
|
||||
CanCreateOrgRepo bool
|
||||
Visibility string `binding:"OmitEmpty;In(public,limited,private)"`
|
||||
}
|
||||
|
||||
// Validate validates the fields
|
||||
func (f *CreateTeamForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user