mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-29 02:04:15 +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:
@@ -0,0 +1,28 @@
|
|||||||
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package structs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"gitea.dev/modules/reqctx"
|
||||||
|
"gitea.dev/modules/translation/i18n"
|
||||||
|
|
||||||
|
"gitea.com/go-chi/binding"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ValidateContext is a special context for form validation middleware
|
||||||
|
type ValidateContext struct {
|
||||||
|
Locale i18n.LocaleTranslation
|
||||||
|
Data reqctx.ContextData
|
||||||
|
Req *http.Request
|
||||||
|
Resp http.ResponseWriter
|
||||||
|
}
|
||||||
|
|
||||||
|
type FormDefaultValidator struct{}
|
||||||
|
|
||||||
|
func (FormDefaultValidator) Validate(ctx *ValidateContext, errs binding.Errors) binding.Errors {
|
||||||
|
// this default validator only needs to return the errs as is because the "binding" function has already validated
|
||||||
|
return errs
|
||||||
|
}
|
||||||
@@ -21,6 +21,7 @@ type SearchError struct {
|
|||||||
|
|
||||||
// MarkupOption markup options
|
// MarkupOption markup options
|
||||||
type MarkupOption struct {
|
type MarkupOption struct {
|
||||||
|
FormDefaultValidator
|
||||||
// Text markup to render
|
// Text markup to render
|
||||||
//
|
//
|
||||||
// in: body
|
// in: body
|
||||||
|
|||||||
@@ -19,6 +19,18 @@ type Locale interface {
|
|||||||
HasKey(trKey string) bool
|
HasKey(trKey string) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LocaleTranslation represents an interface to translation
|
||||||
|
type LocaleTranslation interface {
|
||||||
|
Language() string
|
||||||
|
HasKey(trKey string) bool
|
||||||
|
TrString(string, ...any) string
|
||||||
|
|
||||||
|
Tr(key string, args ...any) template.HTML
|
||||||
|
TrN(cnt any, key1, keyN string, args ...any) template.HTML
|
||||||
|
|
||||||
|
PrettyNumber(v any) string
|
||||||
|
}
|
||||||
|
|
||||||
// LocaleStore provides the functions common to all locale stores
|
// LocaleStore provides the functions common to all locale stores
|
||||||
type LocaleStore interface {
|
type LocaleStore interface {
|
||||||
io.Closer
|
io.Closer
|
||||||
@@ -31,7 +43,7 @@ type LocaleStore interface {
|
|||||||
Locale(langName string) (Locale, bool)
|
Locale(langName string) (Locale, bool)
|
||||||
// HasLang returns whether a given language is present in the store
|
// HasLang returns whether a given language is present in the store
|
||||||
HasLang(langName string) bool
|
HasLang(langName string) bool
|
||||||
// AddLocaleByIni adds a new language to the store
|
// AddLocaleByJSON adds a new language to the store
|
||||||
AddLocaleByJSON(langName, langDesc string, source, moreSource []byte) error
|
AddLocaleByJSON(langName, langDesc string, source, moreSource []byte) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ type MockLocale struct {
|
|||||||
Lang, LangName string // these fields are used directly in templates: ctx.Locale.Lang
|
Lang, LangName string // these fields are used directly in templates: ctx.Locale.Lang
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l MockLocale) HasKey(trKey string) bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
var _ Locale = (*MockLocale)(nil)
|
var _ Locale = (*MockLocale)(nil)
|
||||||
|
|
||||||
func (l MockLocale) Language() string {
|
func (l MockLocale) Language() string {
|
||||||
|
|||||||
@@ -25,16 +25,7 @@ type contextKey struct{}
|
|||||||
|
|
||||||
var ContextKey any = &contextKey{}
|
var ContextKey any = &contextKey{}
|
||||||
|
|
||||||
// Locale represents an interface to translation
|
type Locale = i18n.LocaleTranslation
|
||||||
type Locale interface {
|
|
||||||
Language() string
|
|
||||||
TrString(string, ...any) string
|
|
||||||
|
|
||||||
Tr(key string, args ...any) template.HTML
|
|
||||||
TrN(cnt any, key1, keyN string, args ...any) template.HTML
|
|
||||||
|
|
||||||
PrettyNumber(v any) string
|
|
||||||
}
|
|
||||||
|
|
||||||
// LangType represents a lang type
|
// LangType represents a lang type
|
||||||
type LangType struct {
|
type LangType struct {
|
||||||
|
|||||||
@@ -37,13 +37,7 @@ func performValidationTest(t *testing.T, testCase validationTestCase) {
|
|||||||
m := chi.NewRouter()
|
m := chi.NewRouter()
|
||||||
|
|
||||||
m.Post(testRoute, func(resp http.ResponseWriter, req *http.Request) {
|
m.Post(testRoute, func(resp http.ResponseWriter, req *http.Request) {
|
||||||
actual := binding.Validate(req, testCase.data)
|
assert.Equal(t, testCase.expectedErrors, binding.Validate(req, testCase.data))
|
||||||
// see https://github.com/stretchr/testify/issues/435
|
|
||||||
if actual == nil {
|
|
||||||
actual = binding.Errors{}
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.Equal(t, testCase.expectedErrors, actual)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
req, err := http.NewRequest(http.MethodPost, testRoute, nil)
|
req, err := http.NewRequest(http.MethodPost, testRoute, nil)
|
||||||
|
|||||||
@@ -29,14 +29,12 @@ func Test_GlobPatternValidation(t *testing.T) {
|
|||||||
data: TestForm{
|
data: TestForm{
|
||||||
GlobPattern: "",
|
GlobPattern: "",
|
||||||
},
|
},
|
||||||
expectedErrors: binding.Errors{},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "Valid glob",
|
description: "Valid glob",
|
||||||
data: TestForm{
|
data: TestForm{
|
||||||
GlobPattern: "{master,release*}",
|
GlobPattern: "{master,release*}",
|
||||||
},
|
},
|
||||||
expectedErrors: binding.Errors{},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,21 +17,18 @@ func Test_GitRefNameValidation(t *testing.T) {
|
|||||||
data: TestForm{
|
data: TestForm{
|
||||||
BranchName: "test",
|
BranchName: "test",
|
||||||
},
|
},
|
||||||
expectedErrors: binding.Errors{},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "Reference name contains single slash",
|
description: "Reference name contains single slash",
|
||||||
data: TestForm{
|
data: TestForm{
|
||||||
BranchName: "feature/test",
|
BranchName: "feature/test",
|
||||||
},
|
},
|
||||||
expectedErrors: binding.Errors{},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "Reference name has allowed special characters",
|
description: "Reference name has allowed special characters",
|
||||||
data: TestForm{
|
data: TestForm{
|
||||||
BranchName: "debian/1%1.6.0-2",
|
BranchName: "debian/1%1.6.0-2",
|
||||||
},
|
},
|
||||||
expectedErrors: binding.Errors{},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "Reference name contains backslash",
|
description: "Reference name contains backslash",
|
||||||
|
|||||||
@@ -26,14 +26,12 @@ func Test_RegexPatternValidation(t *testing.T) {
|
|||||||
data: TestForm{
|
data: TestForm{
|
||||||
RegexPattern: "",
|
RegexPattern: "",
|
||||||
},
|
},
|
||||||
expectedErrors: binding.Errors{},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "Valid regex",
|
description: "Valid regex",
|
||||||
data: TestForm{
|
data: TestForm{
|
||||||
RegexPattern: `(\d{1,3})+`,
|
RegexPattern: `(\d{1,3})+`,
|
||||||
},
|
},
|
||||||
expectedErrors: binding.Errors{},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,35 +18,30 @@ func Test_ValidURLValidation(t *testing.T) {
|
|||||||
data: TestForm{
|
data: TestForm{
|
||||||
URL: "",
|
URL: "",
|
||||||
},
|
},
|
||||||
expectedErrors: binding.Errors{},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "URL without port",
|
description: "URL without port",
|
||||||
data: TestForm{
|
data: TestForm{
|
||||||
URL: "http://test.lan/",
|
URL: "http://test.lan/",
|
||||||
},
|
},
|
||||||
expectedErrors: binding.Errors{},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "URL with port",
|
description: "URL with port",
|
||||||
data: TestForm{
|
data: TestForm{
|
||||||
URL: "http://test.lan:3000/",
|
URL: "http://test.lan:3000/",
|
||||||
},
|
},
|
||||||
expectedErrors: binding.Errors{},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "URL with IPv6 address without port",
|
description: "URL with IPv6 address without port",
|
||||||
data: TestForm{
|
data: TestForm{
|
||||||
URL: "http://[::1]/",
|
URL: "http://[::1]/",
|
||||||
},
|
},
|
||||||
expectedErrors: binding.Errors{},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "URL with IPv6 address with port",
|
description: "URL with IPv6 address with port",
|
||||||
data: TestForm{
|
data: TestForm{
|
||||||
URL: "http://[::1]:3000/",
|
URL: "http://[::1]:3000/",
|
||||||
},
|
},
|
||||||
expectedErrors: binding.Errors{},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "Invalid URL",
|
description: "Invalid URL",
|
||||||
|
|||||||
@@ -5,12 +5,11 @@
|
|||||||
package middleware
|
package middleware
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gitea.dev/modules/reqctx"
|
|
||||||
"gitea.dev/modules/setting"
|
"gitea.dev/modules/setting"
|
||||||
|
"gitea.dev/modules/structs"
|
||||||
"gitea.dev/modules/translation"
|
"gitea.dev/modules/translation"
|
||||||
"gitea.dev/modules/util"
|
"gitea.dev/modules/util"
|
||||||
"gitea.dev/modules/validation"
|
"gitea.dev/modules/validation"
|
||||||
@@ -18,17 +17,13 @@ import (
|
|||||||
"gitea.com/go-chi/binding"
|
"gitea.com/go-chi/binding"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ValidateContext is a special context for form validation middleware. It may be different from other contexts.
|
type (
|
||||||
type ValidateContext struct {
|
ValidateContext = structs.ValidateContext
|
||||||
Locale translation.Locale
|
FormDefaultValidator = structs.FormDefaultValidator
|
||||||
Data reqctx.ContextData
|
)
|
||||||
Req *http.Request
|
|
||||||
Resp http.ResponseWriter
|
|
||||||
}
|
|
||||||
|
|
||||||
// Form form binding interface
|
|
||||||
type Form interface {
|
type Form interface {
|
||||||
binding.Validator
|
Validate(ctx *ValidateContext, errs binding.Errors) binding.Errors
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -84,9 +79,17 @@ func getFieldDisplayNameForMessage(f Form, l translation.Locale, fieldNames []st
|
|||||||
typ = typ.Elem()
|
typ = typ.Elem()
|
||||||
}
|
}
|
||||||
|
|
||||||
field, fieldExists := typ.FieldByName(fieldNames[0])
|
fieldName := fieldNames[0]
|
||||||
|
field, fieldExists := typ.FieldByName(fieldName)
|
||||||
if !fieldExists {
|
if !fieldExists {
|
||||||
return field, false, ""
|
for tryField := range typ.Fields() {
|
||||||
|
if util.ToSnakeCase(tryField.Name) == fieldName || tryField.Tag.Get("form") == fieldName {
|
||||||
|
field, fieldExists = tryField, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !fieldExists {
|
||||||
|
return field, false, ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if field.Tag.Get("form") == "-" {
|
if field.Tag.Get("form") == "-" {
|
||||||
@@ -95,8 +98,9 @@ func getFieldDisplayNameForMessage(f Form, l translation.Locale, fieldNames []st
|
|||||||
|
|
||||||
trKeyFallback := "form." + field.Name
|
trKeyFallback := "form." + field.Name
|
||||||
trKey := util.IfZero(field.Tag.Get("locale"), trKeyFallback)
|
trKey := util.IfZero(field.Tag.Get("locale"), trKeyFallback)
|
||||||
displayName = l.TrString(trKey)
|
if l.HasKey(trKey) {
|
||||||
if displayName == trKeyFallback {
|
displayName = l.TrString(trKey)
|
||||||
|
} else {
|
||||||
displayName = field.Name
|
displayName = field.Name
|
||||||
}
|
}
|
||||||
return field, true, displayName
|
return field, true, displayName
|
||||||
@@ -156,7 +160,7 @@ func BuildValidationErrorForUser(f Form, l translation.Locale, bindingErrs bindi
|
|||||||
case validation.ErrInvalidBadgeSlug:
|
case validation.ErrInvalidBadgeSlug:
|
||||||
errorMessage = l.TrString("form.invalid_slug_error", fieldDisplayName)
|
errorMessage = l.TrString("form.invalid_slug_error", fieldDisplayName)
|
||||||
default:
|
default:
|
||||||
setting.PanicInDevOrTesting("unknown binding error classification: %v", classification)
|
setting.PanicInDevOrTesting("unknown binding error classification for field %T.%s: %v, err: %s", f, errorFieldName, classification, bindingErrMsg)
|
||||||
var msg string
|
var msg string
|
||||||
if classification != "" && bindingErrMsg != "" {
|
if classification != "" && bindingErrMsg != "" {
|
||||||
msg = classification + ": " + bindingErrMsg
|
msg = classification + ": " + bindingErrMsg
|
||||||
@@ -171,33 +175,3 @@ func BuildValidationErrorForUser(f Form, l translation.Locale, bindingErrs bindi
|
|||||||
}
|
}
|
||||||
return errorMessage, errorFieldName, fieldNames
|
return errorMessage, errorFieldName, fieldNames
|
||||||
}
|
}
|
||||||
|
|
||||||
type contextKeySkipTmplFormValidationErrorType struct{}
|
|
||||||
|
|
||||||
var contextKeySkipTmplFormValidationError contextKeySkipTmplFormValidationErrorType
|
|
||||||
|
|
||||||
func SkipTmplFormValidationError(ctx reqctx.RequestContext) {
|
|
||||||
ctx.SetContextValue(contextKeySkipTmplFormValidationError, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Validate(ctx *ValidateContext, errs binding.Errors, f Form) binding.Errors {
|
|
||||||
if ctx.Req.Context().Value(contextKeySkipTmplFormValidationError) == true {
|
|
||||||
// if it is not using tmpl-based validation error handling, just return the errors
|
|
||||||
// for example: when using "form-fetch-action", the validation error can be handled by GetFetchActionForm
|
|
||||||
return errs
|
|
||||||
}
|
|
||||||
errorMessage, errorFieldName, _ := BuildValidationErrorForUser(f, ctx.Locale, errs)
|
|
||||||
if errorMessage == "" {
|
|
||||||
return errs
|
|
||||||
}
|
|
||||||
|
|
||||||
// Legacy template error handling: try to restore the form's values as much as possible,
|
|
||||||
// especially for RenderWithErrDeprecated to re-render the form with errors.
|
|
||||||
AssignForm(f, ctx.Data)
|
|
||||||
ctx.Data["HasError"] = true
|
|
||||||
ctx.Data["ErrorMsg"] = errorMessage
|
|
||||||
if errorFieldName != "" {
|
|
||||||
ctx.Data["Err_"+errorFieldName] = true
|
|
||||||
}
|
|
||||||
return errs
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -15,17 +15,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type testRangeForm struct {
|
type testRangeForm struct {
|
||||||
|
FormDefaultValidator
|
||||||
Hours int `binding:"Range(0,1000)"`
|
Hours int `binding:"Range(0,1000)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *testRangeForm) Validate(_ *http.Request, errs binding.Errors) binding.Errors { return errs }
|
|
||||||
|
|
||||||
func TestBuildValidationErrorForUser(t *testing.T) {
|
func TestBuildValidationErrorForUser(t *testing.T) {
|
||||||
// an out-of-range value must reach its own message instead of the panicking "default" branch
|
// an out-of-range value must reach its own message instead of the panicking "default" branch
|
||||||
form := &testRangeForm{Hours: 2000}
|
form := &testRangeForm{Hours: 2000}
|
||||||
errs := binding.Validate(httptest.NewRequest(http.MethodPost, "/", nil), form)
|
errs := binding.Validate(httptest.NewRequest(http.MethodPost, "/", nil), form)
|
||||||
errorMessage, errorFieldName, fieldNames := BuildValidationErrorForUser(form, translation.MockLocale{}, errs)
|
errorMessage, errorFieldName, fieldNames := BuildValidationErrorForUser(form, translation.MockLocale{}, errs)
|
||||||
assert.Equal(t, "form.range_error:Hours,0,1000", errorMessage)
|
assert.Equal(t, "form.range_error:form.Hours,0,1000", errorMessage)
|
||||||
assert.Equal(t, "Hours", errorFieldName)
|
assert.Equal(t, "Hours", errorFieldName)
|
||||||
assert.Equal(t, []string{"Hours"}, fieldNames)
|
assert.Equal(t, []string{"Hours"}, fieldNames)
|
||||||
}
|
}
|
||||||
|
|||||||
+28
-7
@@ -14,6 +14,7 @@ import (
|
|||||||
"gitea.dev/modules/public"
|
"gitea.dev/modules/public"
|
||||||
"gitea.dev/modules/reqctx"
|
"gitea.dev/modules/reqctx"
|
||||||
"gitea.dev/modules/setting"
|
"gitea.dev/modules/setting"
|
||||||
|
"gitea.dev/modules/translation"
|
||||||
"gitea.dev/modules/web/middleware"
|
"gitea.dev/modules/web/middleware"
|
||||||
"gitea.dev/modules/web/types"
|
"gitea.dev/modules/web/types"
|
||||||
|
|
||||||
@@ -21,14 +22,34 @@ import (
|
|||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Bind binding an obj to a handler's context data
|
// Bind binding the request form to a form object and assign context data
|
||||||
func Bind[T any](_ T) http.HandlerFunc {
|
func Bind[T interface {
|
||||||
|
*E
|
||||||
|
middleware.Form
|
||||||
|
}, E any]() http.HandlerFunc {
|
||||||
return func(resp http.ResponseWriter, req *http.Request) {
|
return func(resp http.ResponseWriter, req *http.Request) {
|
||||||
theObj := new(T) // create a new form obj for every request but not use obj directly
|
ctx := reqctx.FromContext(req.Context())
|
||||||
data := middleware.GetContextData(req.Context())
|
data := ctx.GetData()
|
||||||
_ = binding.Bind(req, theObj) // no need to handle "errs" here, the errors are handled in our middleware.Validate (binding.go)
|
locale := ctx.Value(translation.ContextKey).(translation.Locale) //nolint:forcetypeassert // must exist
|
||||||
SetForm(data, theObj)
|
|
||||||
middleware.AssignForm(theObj, data)
|
obj := new(E)
|
||||||
|
var form T = obj
|
||||||
|
vctx := &middleware.ValidateContext{Locale: locale, Data: data, Req: req, Resp: resp}
|
||||||
|
errs := binding.Bind(req, obj)
|
||||||
|
errs = form.Validate(vctx, errs)
|
||||||
|
SetForm(data, obj)
|
||||||
|
|
||||||
|
// Legacy template error handling: try to restore the form's values as much as possible,
|
||||||
|
// especially for RenderWithErrDeprecated to re-render the form with errors.
|
||||||
|
middleware.AssignForm(obj, data)
|
||||||
|
errorMessage, errorFieldName, _ := middleware.BuildValidationErrorForUser(form, locale, errs)
|
||||||
|
if errorMessage != "" {
|
||||||
|
data["HasError"] = true
|
||||||
|
data["ErrorMsg"] = errorMessage
|
||||||
|
if errorFieldName != "" {
|
||||||
|
data["Err_"+errorFieldName] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ func Routes() *web.Router {
|
|||||||
r.AfterRouting(common.MustInitSessioner(), installContexter())
|
r.AfterRouting(common.MustInitSessioner(), installContexter())
|
||||||
|
|
||||||
r.Get("/", Install) // it must be on the root, because the "install.js" use the window.location to replace the "localhost" AppURL
|
r.Get("/", Install) // it must be on the root, because the "install.js" use the window.location to replace the "localhost" AppURL
|
||||||
r.Post("/", web.Bind(forms.InstallForm{}), SubmitInstall)
|
r.Post("/", web.Bind[*forms.InstallForm](), SubmitInstall)
|
||||||
r.Get("/post-install", InstallDone)
|
r.Get("/post-install", InstallDone)
|
||||||
|
|
||||||
r.Get("/-/web-theme/list", misc.WebThemeList)
|
r.Get("/-/web-theme/list", misc.WebThemeList)
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"gitea.dev/models/auth"
|
"gitea.dev/models/auth"
|
||||||
user_model "gitea.dev/models/user"
|
user_model "gitea.dev/models/user"
|
||||||
@@ -26,7 +25,6 @@ import (
|
|||||||
"gitea.dev/services/forms"
|
"gitea.dev/services/forms"
|
||||||
"gitea.dev/services/oauth2_provider"
|
"gitea.dev/services/oauth2_provider"
|
||||||
|
|
||||||
"gitea.com/go-chi/binding"
|
|
||||||
jwt "github.com/golang-jwt/jwt/v5"
|
jwt "github.com/golang-jwt/jwt/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -225,16 +223,6 @@ func AuthorizeOAuth(ctx *context.Context) {
|
|||||||
if !oauthDoerAuthorizePreCheck(ctx, form.State) {
|
if !oauthDoerAuthorizePreCheck(ctx, form.State) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
errs := binding.Errors{}
|
|
||||||
errs = form.Validate(ctx.Req, errs)
|
|
||||||
if len(errs) > 0 {
|
|
||||||
var errstring strings.Builder
|
|
||||||
for _, e := range errs {
|
|
||||||
errstring.WriteString(e.Error() + "\n")
|
|
||||||
}
|
|
||||||
ctx.ServerError("AuthorizeOAuth: Validate: ", fmt.Errorf("errors occurred during validation: %s", errstring.String()))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
app, err := auth.GetOAuth2ApplicationByClientID(ctx, form.ClientID)
|
app, err := auth.GetOAuth2ApplicationByClientID(ctx, form.ClientID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import (
|
|||||||
"gitea.dev/modules/translation"
|
"gitea.dev/modules/translation"
|
||||||
"gitea.dev/modules/util"
|
"gitea.dev/modules/util"
|
||||||
"gitea.dev/modules/web"
|
"gitea.dev/modules/web"
|
||||||
|
"gitea.dev/modules/web/middleware"
|
||||||
"gitea.dev/routers/common"
|
"gitea.dev/routers/common"
|
||||||
actions_service "gitea.dev/services/actions"
|
actions_service "gitea.dev/services/actions"
|
||||||
context_module "gitea.dev/services/context"
|
context_module "gitea.dev/services/context"
|
||||||
@@ -277,6 +278,7 @@ type LogCursor struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ViewRequest struct {
|
type ViewRequest struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
LogCursors []LogCursor `json:"logCursors"`
|
LogCursors []LogCursor `json:"logCursors"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+134
-134
@@ -329,9 +329,9 @@ var optSignInFromAnyOrigin = verifyAuthWithOptions(&common.VerifyOptions{Disable
|
|||||||
func addProjectBoardRoutes(m *web.Router) {
|
func addProjectBoardRoutes(m *web.Router) {
|
||||||
// TODO: improper name. Others are "delete project", "edit project", but this one is "move columns"
|
// TODO: improper name. Others are "delete project", "edit project", but this one is "move columns"
|
||||||
m.Post("/move", project.MoveColumns)
|
m.Post("/move", project.MoveColumns)
|
||||||
m.Post("/columns/new", web.Bind(forms.EditProjectColumnForm{}), project.AddColumnToProjectPost)
|
m.Post("/columns/new", web.Bind[*forms.EditProjectColumnForm](), project.AddColumnToProjectPost)
|
||||||
m.Group("/{columnID}", func() {
|
m.Group("/{columnID}", func() {
|
||||||
m.Put("", web.Bind(forms.EditProjectColumnForm{}), project.EditProjectColumn)
|
m.Put("", web.Bind[*forms.EditProjectColumnForm](), project.EditProjectColumn)
|
||||||
m.Delete("", project.DeleteProjectColumn)
|
m.Delete("", project.DeleteProjectColumn)
|
||||||
m.Post("/default", project.SetDefaultProjectColumn)
|
m.Post("/default", project.SetDefaultProjectColumn)
|
||||||
m.Post("/move", project.MoveIssues)
|
m.Post("/move", project.MoveIssues)
|
||||||
@@ -458,38 +458,38 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
|
|
||||||
addWebhookAddRoutes := func() {
|
addWebhookAddRoutes := func() {
|
||||||
m.Get("/{type}/new", repo_setting.WebhooksNew)
|
m.Get("/{type}/new", repo_setting.WebhooksNew)
|
||||||
m.Post("/gitea/new", web.Bind(forms.NewWebhookForm{}), repo_setting.GiteaHooksNewPost)
|
m.Post("/gitea/new", web.Bind[*forms.NewWebhookForm](), repo_setting.GiteaHooksNewPost)
|
||||||
m.Post("/gogs/new", web.Bind(forms.NewGogshookForm{}), repo_setting.GogsHooksNewPost)
|
m.Post("/gogs/new", web.Bind[*forms.NewGogshookForm](), repo_setting.GogsHooksNewPost)
|
||||||
m.Post("/slack/new", web.Bind(forms.NewSlackHookForm{}), repo_setting.SlackHooksNewPost)
|
m.Post("/slack/new", web.Bind[*forms.NewSlackHookForm](), repo_setting.SlackHooksNewPost)
|
||||||
m.Post("/discord/new", web.Bind(forms.NewDiscordHookForm{}), repo_setting.DiscordHooksNewPost)
|
m.Post("/discord/new", web.Bind[*forms.NewDiscordHookForm](), repo_setting.DiscordHooksNewPost)
|
||||||
m.Post("/dingtalk/new", web.Bind(forms.NewDingtalkHookForm{}), repo_setting.DingtalkHooksNewPost)
|
m.Post("/dingtalk/new", web.Bind[*forms.NewDingtalkHookForm](), repo_setting.DingtalkHooksNewPost)
|
||||||
m.Post("/telegram/new", web.Bind(forms.NewTelegramHookForm{}), repo_setting.TelegramHooksNewPost)
|
m.Post("/telegram/new", web.Bind[*forms.NewTelegramHookForm](), repo_setting.TelegramHooksNewPost)
|
||||||
m.Post("/matrix/new", web.Bind(forms.NewMatrixHookForm{}), repo_setting.MatrixHooksNewPost)
|
m.Post("/matrix/new", web.Bind[*forms.NewMatrixHookForm](), repo_setting.MatrixHooksNewPost)
|
||||||
m.Post("/msteams/new", web.Bind(forms.NewMSTeamsHookForm{}), repo_setting.MSTeamsHooksNewPost)
|
m.Post("/msteams/new", web.Bind[*forms.NewMSTeamsHookForm](), repo_setting.MSTeamsHooksNewPost)
|
||||||
m.Post("/feishu/new", web.Bind(forms.NewFeishuHookForm{}), repo_setting.FeishuHooksNewPost)
|
m.Post("/feishu/new", web.Bind[*forms.NewFeishuHookForm](), repo_setting.FeishuHooksNewPost)
|
||||||
m.Post("/wechatwork/new", web.Bind(forms.NewWechatWorkHookForm{}), repo_setting.WechatworkHooksNewPost)
|
m.Post("/wechatwork/new", web.Bind[*forms.NewWechatWorkHookForm](), repo_setting.WechatworkHooksNewPost)
|
||||||
m.Post("/packagist/new", web.Bind(forms.NewPackagistHookForm{}), repo_setting.PackagistHooksNewPost)
|
m.Post("/packagist/new", web.Bind[*forms.NewPackagistHookForm](), repo_setting.PackagistHooksNewPost)
|
||||||
}
|
}
|
||||||
|
|
||||||
addWebhookEditRoutes := func() {
|
addWebhookEditRoutes := func() {
|
||||||
m.Post("/gitea/{id}", web.Bind(forms.NewWebhookForm{}), repo_setting.GiteaHooksEditPost)
|
m.Post("/gitea/{id}", web.Bind[*forms.NewWebhookForm](), repo_setting.GiteaHooksEditPost)
|
||||||
m.Post("/gogs/{id}", web.Bind(forms.NewGogshookForm{}), repo_setting.GogsHooksEditPost)
|
m.Post("/gogs/{id}", web.Bind[*forms.NewGogshookForm](), repo_setting.GogsHooksEditPost)
|
||||||
m.Post("/slack/{id}", web.Bind(forms.NewSlackHookForm{}), repo_setting.SlackHooksEditPost)
|
m.Post("/slack/{id}", web.Bind[*forms.NewSlackHookForm](), repo_setting.SlackHooksEditPost)
|
||||||
m.Post("/discord/{id}", web.Bind(forms.NewDiscordHookForm{}), repo_setting.DiscordHooksEditPost)
|
m.Post("/discord/{id}", web.Bind[*forms.NewDiscordHookForm](), repo_setting.DiscordHooksEditPost)
|
||||||
m.Post("/dingtalk/{id}", web.Bind(forms.NewDingtalkHookForm{}), repo_setting.DingtalkHooksEditPost)
|
m.Post("/dingtalk/{id}", web.Bind[*forms.NewDingtalkHookForm](), repo_setting.DingtalkHooksEditPost)
|
||||||
m.Post("/telegram/{id}", web.Bind(forms.NewTelegramHookForm{}), repo_setting.TelegramHooksEditPost)
|
m.Post("/telegram/{id}", web.Bind[*forms.NewTelegramHookForm](), repo_setting.TelegramHooksEditPost)
|
||||||
m.Post("/matrix/{id}", web.Bind(forms.NewMatrixHookForm{}), repo_setting.MatrixHooksEditPost)
|
m.Post("/matrix/{id}", web.Bind[*forms.NewMatrixHookForm](), repo_setting.MatrixHooksEditPost)
|
||||||
m.Post("/msteams/{id}", web.Bind(forms.NewMSTeamsHookForm{}), repo_setting.MSTeamsHooksEditPost)
|
m.Post("/msteams/{id}", web.Bind[*forms.NewMSTeamsHookForm](), repo_setting.MSTeamsHooksEditPost)
|
||||||
m.Post("/feishu/{id}", web.Bind(forms.NewFeishuHookForm{}), repo_setting.FeishuHooksEditPost)
|
m.Post("/feishu/{id}", web.Bind[*forms.NewFeishuHookForm](), repo_setting.FeishuHooksEditPost)
|
||||||
m.Post("/wechatwork/{id}", web.Bind(forms.NewWechatWorkHookForm{}), repo_setting.WechatworkHooksEditPost)
|
m.Post("/wechatwork/{id}", web.Bind[*forms.NewWechatWorkHookForm](), repo_setting.WechatworkHooksEditPost)
|
||||||
m.Post("/packagist/{id}", web.Bind(forms.NewPackagistHookForm{}), repo_setting.PackagistHooksEditPost)
|
m.Post("/packagist/{id}", web.Bind[*forms.NewPackagistHookForm](), repo_setting.PackagistHooksEditPost)
|
||||||
}
|
}
|
||||||
|
|
||||||
addSettingsVariablesRoutes := func() {
|
addSettingsVariablesRoutes := func() {
|
||||||
m.Group("/variables", func() {
|
m.Group("/variables", func() {
|
||||||
m.Get("", shared_actions.Variables)
|
m.Get("", shared_actions.Variables)
|
||||||
m.Post("/new", web.Bind(forms.EditVariableForm{}), shared_actions.VariableCreate)
|
m.Post("/new", web.Bind[*forms.EditVariableForm](), shared_actions.VariableCreate)
|
||||||
m.Post("/{variable_id}/edit", web.Bind(forms.EditVariableForm{}), shared_actions.VariableUpdate)
|
m.Post("/{variable_id}/edit", web.Bind[*forms.EditVariableForm](), shared_actions.VariableUpdate)
|
||||||
m.Post("/{variable_id}/delete", shared_actions.VariableDelete)
|
m.Post("/{variable_id}/delete", shared_actions.VariableDelete)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -497,7 +497,7 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
addSettingsSecretsRoutes := func() {
|
addSettingsSecretsRoutes := func() {
|
||||||
m.Group("/secrets", func() {
|
m.Group("/secrets", func() {
|
||||||
m.Get("", repo_setting.Secrets)
|
m.Get("", repo_setting.Secrets)
|
||||||
m.Post("", web.Bind(forms.AddSecretForm{}), repo_setting.SecretsPost)
|
m.Post("", web.Bind[*forms.AddSecretForm](), repo_setting.SecretsPost)
|
||||||
m.Post("/delete", repo_setting.SecretsDelete)
|
m.Post("/delete", repo_setting.SecretsDelete)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -506,7 +506,7 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
m.Group("/runners", func() {
|
m.Group("/runners", func() {
|
||||||
m.Get("", shared_actions.Runners)
|
m.Get("", shared_actions.Runners)
|
||||||
m.Combo("/{runnerid}").Get(shared_actions.RunnersEdit).
|
m.Combo("/{runnerid}").Get(shared_actions.RunnersEdit).
|
||||||
Post(web.Bind(forms.EditRunnerForm{}), shared_actions.RunnersEditPost)
|
Post(web.Bind[*forms.EditRunnerForm](), shared_actions.RunnersEditPost)
|
||||||
m.Post("/{runnerid}/update-runner", shared_actions.RunnerUpdatePost)
|
m.Post("/{runnerid}/update-runner", shared_actions.RunnerUpdatePost)
|
||||||
m.Post("/{runnerid}/delete", shared_actions.RunnerDeletePost)
|
m.Post("/{runnerid}/delete", shared_actions.RunnerDeletePost)
|
||||||
m.Post("/reset_registration_token", shared_actions.ResetRunnerRegistrationToken)
|
m.Post("/reset_registration_token", shared_actions.ResetRunnerRegistrationToken)
|
||||||
@@ -540,7 +540,7 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
m.Methods("GET, HEAD", "/*", public.FileHandlerFunc())
|
m.Methods("GET, HEAD", "/*", public.FileHandlerFunc())
|
||||||
}, optionsCorsHandler())
|
}, optionsCorsHandler())
|
||||||
|
|
||||||
m.Post("/-/markup", reqSignIn, web.Bind(structs.MarkupOption{}), misc.Markup)
|
m.Post("/-/markup", reqSignIn, web.Bind[*structs.MarkupOption](), misc.Markup)
|
||||||
m.Post("/-/web-banner/dismiss", misc.WebBannerDismiss)
|
m.Post("/-/web-banner/dismiss", misc.WebBannerDismiss)
|
||||||
m.Get("/-/web-theme/list", misc.WebThemeList)
|
m.Get("/-/web-theme/list", misc.WebThemeList)
|
||||||
m.Post("/-/web-theme/apply", optSignIn, misc.WebThemeApply)
|
m.Post("/-/web-theme/apply", optSignIn, misc.WebThemeApply)
|
||||||
@@ -575,32 +575,32 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
// "user/login" doesn't need signOut, then logged-in users can still access this route for redirection purposes by "/user/login?redirec_to=..."
|
// "user/login" doesn't need signOut, then logged-in users can still access this route for redirection purposes by "/user/login?redirec_to=..."
|
||||||
m.Get("/user/login", auth.SignIn)
|
m.Get("/user/login", auth.SignIn)
|
||||||
m.Group("/user", func() {
|
m.Group("/user", func() {
|
||||||
m.Post("/login", web.Bind(forms.SignInForm{}), auth.SignInPost)
|
m.Post("/login", web.Bind[*forms.SignInForm](), auth.SignInPost)
|
||||||
m.Group("", func() {
|
m.Group("", func() {
|
||||||
m.Combo("/login/openid").
|
m.Combo("/login/openid").
|
||||||
Get(auth.SignInOpenID).
|
Get(auth.SignInOpenID).
|
||||||
Post(web.Bind(forms.SignInOpenIDForm{}), auth.SignInOpenIDPost)
|
Post(web.Bind[*forms.SignInOpenIDForm](), auth.SignInOpenIDPost)
|
||||||
}, openIDSignInEnabled)
|
}, openIDSignInEnabled)
|
||||||
m.Group("/openid", func() {
|
m.Group("/openid", func() {
|
||||||
m.Combo("/connect").
|
m.Combo("/connect").
|
||||||
Get(auth.ConnectOpenID).
|
Get(auth.ConnectOpenID).
|
||||||
Post(web.Bind(forms.ConnectOpenIDForm{}), auth.ConnectOpenIDPost)
|
Post(web.Bind[*forms.ConnectOpenIDForm](), auth.ConnectOpenIDPost)
|
||||||
m.Group("/register", func() {
|
m.Group("/register", func() {
|
||||||
m.Combo("").
|
m.Combo("").
|
||||||
Get(auth.RegisterOpenID, openIDSignUpEnabled).
|
Get(auth.RegisterOpenID, openIDSignUpEnabled).
|
||||||
Post(web.Bind(forms.SignUpOpenIDForm{}), auth.RegisterOpenIDPost)
|
Post(web.Bind[*forms.SignUpOpenIDForm](), auth.RegisterOpenIDPost)
|
||||||
}, openIDSignUpEnabled)
|
}, openIDSignUpEnabled)
|
||||||
}, openIDSignInEnabled)
|
}, openIDSignInEnabled)
|
||||||
m.Get("/sign_up", auth.SignUp)
|
m.Get("/sign_up", auth.SignUp)
|
||||||
m.Post("/sign_up", web.Bind(forms.RegisterForm{}), auth.SignUpPost)
|
m.Post("/sign_up", web.Bind[*forms.RegisterForm](), auth.SignUpPost)
|
||||||
m.Get("/link_account", auth.LinkAccount)
|
m.Get("/link_account", auth.LinkAccount)
|
||||||
m.Post("/link_account_signin", web.Bind(forms.SignInForm{}), auth.LinkAccountPostSignIn)
|
m.Post("/link_account_signin", web.Bind[*forms.SignInForm](), auth.LinkAccountPostSignIn)
|
||||||
m.Post("/link_account_signup", web.Bind(forms.RegisterForm{}), auth.LinkAccountPostRegister)
|
m.Post("/link_account_signup", web.Bind[*forms.RegisterForm](), auth.LinkAccountPostRegister)
|
||||||
m.Group("/two_factor", func() {
|
m.Group("/two_factor", func() {
|
||||||
m.Get("", auth.TwoFactor)
|
m.Get("", auth.TwoFactor)
|
||||||
m.Post("", web.Bind(forms.TwoFactorAuthForm{}), auth.TwoFactorPost)
|
m.Post("", web.Bind[*forms.TwoFactorAuthForm](), auth.TwoFactorPost)
|
||||||
m.Get("/scratch", auth.TwoFactorScratch)
|
m.Get("/scratch", auth.TwoFactorScratch)
|
||||||
m.Post("/scratch", web.Bind(forms.TwoFactorScratchAuthForm{}), auth.TwoFactorScratchPost)
|
m.Post("/scratch", web.Bind[*forms.TwoFactorScratchAuthForm](), auth.TwoFactorScratchPost)
|
||||||
})
|
})
|
||||||
m.Group("/webauthn", func() {
|
m.Group("/webauthn", func() {
|
||||||
m.Get("", auth.WebAuthn)
|
m.Get("", auth.WebAuthn)
|
||||||
@@ -615,39 +615,39 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
|
|
||||||
m.Group("/login/oauth", func() {
|
m.Group("/login/oauth", func() {
|
||||||
m.Group("", func() {
|
m.Group("", func() {
|
||||||
m.Get("/authorize", web.Bind(forms.AuthorizationForm{}), auth.AuthorizeOAuth)
|
m.Get("/authorize", web.Bind[*forms.AuthorizationForm](), auth.AuthorizeOAuth)
|
||||||
m.Post("/grant", web.Bind(forms.GrantApplicationForm{}), auth.GrantApplicationOAuth)
|
m.Post("/grant", web.Bind[*forms.GrantApplicationForm](), auth.GrantApplicationOAuth)
|
||||||
// TODO manage redirection
|
// TODO manage redirection
|
||||||
m.Post("/authorize", web.Bind(forms.AuthorizationForm{}), auth.AuthorizeOAuth)
|
m.Post("/authorize", web.Bind[*forms.AuthorizationForm](), auth.AuthorizeOAuth)
|
||||||
}, reqSignIn)
|
}, reqSignIn)
|
||||||
|
|
||||||
m.Group("", func() {
|
m.Group("", func() {
|
||||||
m.Methods("GET, POST, OPTIONS", "/userinfo", auth.InfoOAuth)
|
m.Methods("GET, POST, OPTIONS", "/userinfo", auth.InfoOAuth)
|
||||||
m.Methods("POST, OPTIONS", "/access_token", web.Bind(forms.AccessTokenForm{}), auth.AccessTokenOAuth)
|
m.Methods("POST, OPTIONS", "/access_token", web.Bind[*forms.AccessTokenForm](), auth.AccessTokenOAuth)
|
||||||
m.Methods("GET, OPTIONS", "/keys", auth.OIDCKeys)
|
m.Methods("GET, OPTIONS", "/keys", auth.OIDCKeys)
|
||||||
m.Methods("POST, OPTIONS", "/introspect", web.Bind(forms.IntrospectTokenForm{}), auth.IntrospectOAuth)
|
m.Methods("POST, OPTIONS", "/introspect", web.Bind[*forms.IntrospectTokenForm](), auth.IntrospectOAuth)
|
||||||
}, optionsCorsHandler(), webAuth.AllowOAuth2, optSignInFromAnyOrigin)
|
}, optionsCorsHandler(), webAuth.AllowOAuth2, optSignInFromAnyOrigin)
|
||||||
}, oauth2Enabled)
|
}, oauth2Enabled)
|
||||||
|
|
||||||
m.Group("/user/settings", func() {
|
m.Group("/user/settings", func() {
|
||||||
m.Get("", user_setting.Profile)
|
m.Get("", user_setting.Profile)
|
||||||
m.Post("", web.Bind(forms.UpdateProfileForm{}), user_setting.ProfilePost)
|
m.Post("", web.Bind[*forms.UpdateProfileForm](), user_setting.ProfilePost)
|
||||||
m.Post("/update_preferences", user_setting.UpdatePreferences)
|
m.Post("/update_preferences", user_setting.UpdatePreferences)
|
||||||
m.Get("/change_password", auth.MustChangePassword)
|
m.Get("/change_password", auth.MustChangePassword)
|
||||||
m.Post("/change_password", web.Bind(forms.MustChangePasswordForm{}), auth.MustChangePasswordPost)
|
m.Post("/change_password", web.Bind[*forms.MustChangePasswordForm](), auth.MustChangePasswordPost)
|
||||||
m.Post("/avatar", web.Bind(forms.AvatarForm{}), user_setting.AvatarPost)
|
m.Post("/avatar", web.Bind[*forms.AvatarForm](), user_setting.AvatarPost)
|
||||||
m.Post("/avatar/delete", user_setting.DeleteAvatar)
|
m.Post("/avatar/delete", user_setting.DeleteAvatar)
|
||||||
m.Group("/account", func() {
|
m.Group("/account", func() {
|
||||||
m.Combo("").Get(user_setting.Account).Post(web.Bind(forms.ChangePasswordForm{}), user_setting.AccountPost)
|
m.Combo("").Get(user_setting.Account).Post(web.Bind[*forms.ChangePasswordForm](), user_setting.AccountPost)
|
||||||
m.Post("/email", web.Bind(forms.AddEmailForm{}), user_setting.EmailPost)
|
m.Post("/email", web.Bind[*forms.AddEmailForm](), user_setting.EmailPost)
|
||||||
m.Post("/email/delete", user_setting.DeleteEmail)
|
m.Post("/email/delete", user_setting.DeleteEmail)
|
||||||
m.Post("/delete", user_setting.DeleteAccount)
|
m.Post("/delete", user_setting.DeleteAccount)
|
||||||
})
|
})
|
||||||
m.Group("/appearance", func() {
|
m.Group("/appearance", func() {
|
||||||
m.Get("", user_setting.Appearance)
|
m.Get("", user_setting.Appearance)
|
||||||
m.Post("/language", web.Bind(forms.UpdateLanguageForm{}), user_setting.UpdateUserLang)
|
m.Post("/language", web.Bind[*forms.UpdateLanguageForm](), user_setting.UpdateUserLang)
|
||||||
m.Post("/hidden_comments", user_setting.UpdateUserHiddenComments)
|
m.Post("/hidden_comments", user_setting.UpdateUserHiddenComments)
|
||||||
m.Post("/theme", web.Bind(forms.UpdateThemeForm{}), user_setting.UpdateUIThemePost)
|
m.Post("/theme", web.Bind[*forms.UpdateThemeForm](), user_setting.UpdateUIThemePost)
|
||||||
})
|
})
|
||||||
m.Group("/notifications", func() {
|
m.Group("/notifications", func() {
|
||||||
m.Get("", user_setting.Notifications)
|
m.Get("", user_setting.Notifications)
|
||||||
@@ -660,15 +660,15 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
m.Post("/regenerate_scratch", security.RegenerateScratchTwoFactor)
|
m.Post("/regenerate_scratch", security.RegenerateScratchTwoFactor)
|
||||||
m.Post("/disable", security.DisableTwoFactor)
|
m.Post("/disable", security.DisableTwoFactor)
|
||||||
m.Get("/enroll", security.EnrollTwoFactor)
|
m.Get("/enroll", security.EnrollTwoFactor)
|
||||||
m.Post("/enroll", web.Bind(forms.TwoFactorAuthForm{}), security.EnrollTwoFactorPost)
|
m.Post("/enroll", web.Bind[*forms.TwoFactorAuthForm](), security.EnrollTwoFactorPost)
|
||||||
})
|
})
|
||||||
m.Group("/webauthn", func() {
|
m.Group("/webauthn", func() {
|
||||||
m.Post("/request_register", web.Bind(forms.WebauthnRegistrationForm{}), security.WebAuthnRegister)
|
m.Post("/request_register", web.Bind[*forms.WebauthnRegistrationForm](), security.WebAuthnRegister)
|
||||||
m.Post("/register", security.WebauthnRegisterPost)
|
m.Post("/register", security.WebauthnRegisterPost)
|
||||||
m.Post("/delete", security.WebauthnDelete)
|
m.Post("/delete", security.WebauthnDelete)
|
||||||
})
|
})
|
||||||
m.Group("/openid", func() {
|
m.Group("/openid", func() {
|
||||||
m.Post("", web.Bind(forms.AddOpenIDForm{}), security.OpenIDPost)
|
m.Post("", web.Bind[*forms.AddOpenIDForm](), security.OpenIDPost)
|
||||||
m.Post("/delete", security.DeleteOpenID)
|
m.Post("/delete", security.DeleteOpenID)
|
||||||
m.Post("/toggle_visibility", security.ToggleOpenIDVisibility)
|
m.Post("/toggle_visibility", security.ToggleOpenIDVisibility)
|
||||||
}, openIDSignInEnabled)
|
}, openIDSignInEnabled)
|
||||||
@@ -679,32 +679,32 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
// oauth2 applications
|
// oauth2 applications
|
||||||
m.Group("/oauth2", func() {
|
m.Group("/oauth2", func() {
|
||||||
m.Get("/{id}", user_setting.OAuth2ApplicationShow)
|
m.Get("/{id}", user_setting.OAuth2ApplicationShow)
|
||||||
m.Post("/{id}", web.Bind(forms.EditOAuth2ApplicationForm{}), user_setting.OAuthApplicationsEdit)
|
m.Post("/{id}", web.Bind[*forms.EditOAuth2ApplicationForm](), user_setting.OAuthApplicationsEdit)
|
||||||
m.Post("/{id}/regenerate_secret", user_setting.OAuthApplicationsRegenerateSecret)
|
m.Post("/{id}/regenerate_secret", user_setting.OAuthApplicationsRegenerateSecret)
|
||||||
m.Post("", web.Bind(forms.EditOAuth2ApplicationForm{}), user_setting.OAuthApplicationsPost)
|
m.Post("", web.Bind[*forms.EditOAuth2ApplicationForm](), user_setting.OAuthApplicationsPost)
|
||||||
m.Post("/{id}/delete", user_setting.DeleteOAuth2Application)
|
m.Post("/{id}/delete", user_setting.DeleteOAuth2Application)
|
||||||
m.Post("/{id}/revoke/{grantId}", user_setting.RevokeOAuth2Grant)
|
m.Post("/{id}/revoke/{grantId}", user_setting.RevokeOAuth2Grant)
|
||||||
}, oauth2Enabled)
|
}, oauth2Enabled)
|
||||||
|
|
||||||
// access token applications
|
// access token applications
|
||||||
m.Combo("").Get(user_setting.Applications).
|
m.Combo("").Get(user_setting.Applications).
|
||||||
Post(web.Bind(forms.NewAccessTokenForm{}), user_setting.ApplicationsPost)
|
Post(web.Bind[*forms.NewAccessTokenForm](), user_setting.ApplicationsPost)
|
||||||
m.Post("/delete", user_setting.DeleteApplication)
|
m.Post("/delete", user_setting.DeleteApplication)
|
||||||
})
|
})
|
||||||
|
|
||||||
m.Combo("/keys").Get(user_setting.Keys).
|
m.Combo("/keys").Get(user_setting.Keys).
|
||||||
Post(web.Bind(forms.AddKeyForm{}), user_setting.KeysPost)
|
Post(web.Bind[*forms.AddKeyForm](), user_setting.KeysPost)
|
||||||
m.Post("/keys/delete", user_setting.DeleteKey)
|
m.Post("/keys/delete", user_setting.DeleteKey)
|
||||||
m.Group("/packages", func() {
|
m.Group("/packages", func() {
|
||||||
m.Get("", user_setting.Packages)
|
m.Get("", user_setting.Packages)
|
||||||
m.Group("/rules", func() {
|
m.Group("/rules", func() {
|
||||||
m.Group("/add", func() {
|
m.Group("/add", func() {
|
||||||
m.Get("", user_setting.PackagesRuleAdd)
|
m.Get("", user_setting.PackagesRuleAdd)
|
||||||
m.Post("", web.Bind(forms.PackageCleanupRuleForm{}), user_setting.PackagesRuleAddPost)
|
m.Post("", web.Bind[*forms.PackageCleanupRuleForm](), user_setting.PackagesRuleAddPost)
|
||||||
})
|
})
|
||||||
m.Group("/{id}", func() {
|
m.Group("/{id}", func() {
|
||||||
m.Get("", user_setting.PackagesRuleEdit)
|
m.Get("", user_setting.PackagesRuleEdit)
|
||||||
m.Post("", web.Bind(forms.PackageCleanupRuleForm{}), user_setting.PackagesRuleEditPost)
|
m.Post("", web.Bind[*forms.PackageCleanupRuleForm](), user_setting.PackagesRuleEditPost)
|
||||||
m.Get("/preview", user_setting.PackagesRulePreview)
|
m.Get("/preview", user_setting.PackagesRulePreview)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -744,7 +744,7 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
|
|
||||||
m.Group("/blocked_users", func() {
|
m.Group("/blocked_users", func() {
|
||||||
m.Get("", user_setting.BlockedUsers)
|
m.Get("", user_setting.BlockedUsers)
|
||||||
m.Post("", web.Bind(forms.BlockUserForm{}), user_setting.BlockedUsersPost)
|
m.Post("", web.Bind[*forms.BlockUserForm](), user_setting.BlockedUsersPost)
|
||||||
})
|
})
|
||||||
}, reqSignIn, user_setting.SettingsCtxData)
|
}, reqSignIn, user_setting.SettingsCtxData)
|
||||||
|
|
||||||
@@ -775,7 +775,7 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
m.Group("/-/admin", func() {
|
m.Group("/-/admin", func() {
|
||||||
m.Get("", admin.Dashboard)
|
m.Get("", admin.Dashboard)
|
||||||
m.Get("/system_status", admin.SystemStatus)
|
m.Get("/system_status", admin.SystemStatus)
|
||||||
m.Post("", web.Bind(forms.AdminDashboardForm{}), admin.DashboardPost)
|
m.Post("", web.Bind[*forms.AdminDashboardForm](), admin.DashboardPost)
|
||||||
|
|
||||||
m.Get("/self_check", admin.SelfCheck)
|
m.Get("/self_check", admin.SelfCheck)
|
||||||
m.Post("/self_check", admin.SelfCheckPost)
|
m.Post("/self_check", admin.SelfCheckPost)
|
||||||
@@ -805,20 +805,20 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
|
|
||||||
m.Group("/users", func() {
|
m.Group("/users", func() {
|
||||||
m.Get("", admin.Users)
|
m.Get("", admin.Users)
|
||||||
m.Combo("/new").Get(admin.NewUser).Post(web.Bind(forms.AdminCreateUserForm{}), admin.NewUserPost)
|
m.Combo("/new").Get(admin.NewUser).Post(web.Bind[*forms.AdminCreateUserForm](), admin.NewUserPost)
|
||||||
m.Get("/{userid}", admin.ViewUser)
|
m.Get("/{userid}", admin.ViewUser)
|
||||||
m.Combo("/{userid}/edit").Get(admin.EditUser).Post(web.Bind(forms.AdminEditUserForm{}), admin.EditUserPost)
|
m.Combo("/{userid}/edit").Get(admin.EditUser).Post(web.Bind[*forms.AdminEditUserForm](), admin.EditUserPost)
|
||||||
m.Post("/{userid}/impersonate", admin.ImpersonateUser)
|
m.Post("/{userid}/impersonate", admin.ImpersonateUser)
|
||||||
m.Post("/{userid}/delete", admin.DeleteUser)
|
m.Post("/{userid}/delete", admin.DeleteUser)
|
||||||
m.Post("/{userid}/avatar", web.Bind(forms.AvatarForm{}), admin.AvatarPost)
|
m.Post("/{userid}/avatar", web.Bind[*forms.AvatarForm](), admin.AvatarPost)
|
||||||
m.Post("/{userid}/avatar/delete", admin.DeleteAvatar)
|
m.Post("/{userid}/avatar/delete", admin.DeleteAvatar)
|
||||||
})
|
})
|
||||||
|
|
||||||
m.Group("/badges", func() {
|
m.Group("/badges", func() {
|
||||||
m.Get("", admin.Badges)
|
m.Get("", admin.Badges)
|
||||||
m.Combo("/new").Get(admin.NewBadge).Post(web.Bind(forms.AdminCreateBadgeForm{}), admin.NewBadgePost)
|
m.Combo("/new").Get(admin.NewBadge).Post(web.Bind[*forms.AdminCreateBadgeForm](), admin.NewBadgePost)
|
||||||
m.Get("/slug/{badge_slug}", admin.ViewBadge)
|
m.Get("/slug/{badge_slug}", admin.ViewBadge)
|
||||||
m.Combo("/slug/{badge_slug}/edit").Get(admin.EditBadge).Post(web.Bind(forms.AdminEditBadgeForm{}), admin.EditBadgePost)
|
m.Combo("/slug/{badge_slug}/edit").Get(admin.EditBadge).Post(web.Bind[*forms.AdminEditBadgeForm](), admin.EditBadgePost)
|
||||||
m.Post("/slug/{badge_slug}/delete", admin.DeleteBadge)
|
m.Post("/slug/{badge_slug}/delete", admin.DeleteBadge)
|
||||||
m.Combo("/slug/{badge_slug}/users").Get(admin.BadgeUsers).Post(admin.BadgeUsersPost)
|
m.Combo("/slug/{badge_slug}/users").Get(admin.BadgeUsers).Post(admin.BadgeUsersPost)
|
||||||
m.Post("/slug/{badge_slug}/users/delete", admin.DeleteBadgeUser)
|
m.Post("/slug/{badge_slug}/users/delete", admin.DeleteBadgeUser)
|
||||||
@@ -862,9 +862,9 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
|
|
||||||
m.Group("/auths", func() {
|
m.Group("/auths", func() {
|
||||||
m.Get("", admin.Authentications)
|
m.Get("", admin.Authentications)
|
||||||
m.Combo("/new").Get(admin.NewAuthSource).Post(web.Bind(forms.AuthenticationForm{}), admin.NewAuthSourcePost)
|
m.Combo("/new").Get(admin.NewAuthSource).Post(web.Bind[*forms.AuthenticationForm](), admin.NewAuthSourcePost)
|
||||||
m.Combo("/{authid}").Get(admin.EditAuthSource).
|
m.Combo("/{authid}").Get(admin.EditAuthSource).
|
||||||
Post(web.Bind(forms.AuthenticationForm{}), admin.EditAuthSourcePost)
|
Post(web.Bind[*forms.AuthenticationForm](), admin.EditAuthSourcePost)
|
||||||
m.Post("/{authid}/delete", admin.DeleteAuthSource)
|
m.Post("/{authid}/delete", admin.DeleteAuthSource)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -876,9 +876,9 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
|
|
||||||
m.Group("/applications", func() {
|
m.Group("/applications", func() {
|
||||||
m.Get("", admin.Applications)
|
m.Get("", admin.Applications)
|
||||||
m.Post("/oauth2", web.Bind(forms.EditOAuth2ApplicationForm{}), admin.ApplicationsPost)
|
m.Post("/oauth2", web.Bind[*forms.EditOAuth2ApplicationForm](), admin.ApplicationsPost)
|
||||||
m.Group("/oauth2/{id}", func() {
|
m.Group("/oauth2/{id}", func() {
|
||||||
m.Combo("").Get(admin.EditApplication).Post(web.Bind(forms.EditOAuth2ApplicationForm{}), admin.EditApplicationPost)
|
m.Combo("").Get(admin.EditApplication).Post(web.Bind[*forms.EditOAuth2ApplicationForm](), admin.EditApplicationPost)
|
||||||
m.Post("/regenerate_secret", admin.ApplicationsRegenerateSecret)
|
m.Post("/regenerate_secret", admin.ApplicationsRegenerateSecret)
|
||||||
m.Post("/delete", admin.DeleteApplication)
|
m.Post("/delete", admin.DeleteApplication)
|
||||||
})
|
})
|
||||||
@@ -958,7 +958,7 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
m.Group("/org", func() {
|
m.Group("/org", func() {
|
||||||
m.Group("", func() {
|
m.Group("", func() {
|
||||||
m.Get("/create", org.Create)
|
m.Get("/create", org.Create)
|
||||||
m.Post("/create", web.Bind(forms.CreateOrgForm{}), org.CreatePost)
|
m.Post("/create", web.Bind[*forms.CreateOrgForm](), org.CreatePost)
|
||||||
})
|
})
|
||||||
|
|
||||||
m.Group("/invite/{token}", func() {
|
m.Group("/invite/{token}", func() {
|
||||||
@@ -997,23 +997,23 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
// require owner permission
|
// require owner permission
|
||||||
m.Group("/{org}", func() {
|
m.Group("/{org}", func() {
|
||||||
m.Get("/teams/new", org.NewTeam)
|
m.Get("/teams/new", org.NewTeam)
|
||||||
m.Post("/teams/new", web.Bind(forms.CreateTeamForm{}), org.NewTeamPost)
|
m.Post("/teams/new", web.Bind[*forms.CreateTeamForm](), org.NewTeamPost)
|
||||||
m.Get("/teams/{team}/edit", org.EditTeam)
|
m.Get("/teams/{team}/edit", org.EditTeam)
|
||||||
m.Post("/teams/{team}/edit", web.Bind(forms.CreateTeamForm{}), org.EditTeamPost)
|
m.Post("/teams/{team}/edit", web.Bind[*forms.CreateTeamForm](), org.EditTeamPost)
|
||||||
m.Post("/teams/{team}/delete", org.DeleteTeam)
|
m.Post("/teams/{team}/delete", org.DeleteTeam)
|
||||||
|
|
||||||
m.Get("/worktime", context.OrgAssignment(context.OrgAssignmentOptions{RequireOwner: true}), org.Worktime)
|
m.Get("/worktime", context.OrgAssignment(context.OrgAssignmentOptions{RequireOwner: true}), org.Worktime)
|
||||||
|
|
||||||
m.Group("/settings", func() {
|
m.Group("/settings", func() {
|
||||||
m.Combo("").Get(org.Settings).
|
m.Combo("").Get(org.Settings).
|
||||||
Post(web.Bind(forms.UpdateOrgSettingForm{}), org.SettingsPost)
|
Post(web.Bind[*forms.UpdateOrgSettingForm](), org.SettingsPost)
|
||||||
m.Post("/avatar", web.Bind(forms.AvatarForm{}), org.SettingsAvatar)
|
m.Post("/avatar", web.Bind[*forms.AvatarForm](), org.SettingsAvatar)
|
||||||
m.Post("/avatar/delete", org.SettingsDeleteAvatar)
|
m.Post("/avatar/delete", org.SettingsDeleteAvatar)
|
||||||
m.Group("/applications", func() {
|
m.Group("/applications", func() {
|
||||||
m.Get("", org.Applications)
|
m.Get("", org.Applications)
|
||||||
m.Post("/oauth2", web.Bind(forms.EditOAuth2ApplicationForm{}), org.OAuthApplicationsPost)
|
m.Post("/oauth2", web.Bind[*forms.EditOAuth2ApplicationForm](), org.OAuthApplicationsPost)
|
||||||
m.Group("/oauth2/{id}", func() {
|
m.Group("/oauth2/{id}", func() {
|
||||||
m.Combo("").Get(org.OAuth2ApplicationShow).Post(web.Bind(forms.EditOAuth2ApplicationForm{}), org.OAuth2ApplicationEdit)
|
m.Combo("").Get(org.OAuth2ApplicationShow).Post(web.Bind[*forms.EditOAuth2ApplicationForm](), org.OAuth2ApplicationEdit)
|
||||||
m.Post("/regenerate_secret", org.OAuthApplicationsRegenerateSecret)
|
m.Post("/regenerate_secret", org.OAuthApplicationsRegenerateSecret)
|
||||||
m.Post("/delete", org.DeleteOAuth2Application)
|
m.Post("/delete", org.DeleteOAuth2Application)
|
||||||
})
|
})
|
||||||
@@ -1032,10 +1032,10 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
|
|
||||||
m.Group("/labels", func() {
|
m.Group("/labels", func() {
|
||||||
m.Get("", org.RetrieveLabels, org.Labels)
|
m.Get("", org.RetrieveLabels, org.Labels)
|
||||||
m.Post("/new", web.Bind(forms.CreateLabelForm{}), org.NewLabel)
|
m.Post("/new", web.Bind[*forms.CreateLabelForm](), org.NewLabel)
|
||||||
m.Post("/edit", web.Bind(forms.CreateLabelForm{}), org.UpdateLabel)
|
m.Post("/edit", web.Bind[*forms.CreateLabelForm](), org.UpdateLabel)
|
||||||
m.Post("/delete", org.DeleteLabel)
|
m.Post("/delete", org.DeleteLabel)
|
||||||
m.Post("/initialize", web.Bind(forms.InitializeLabelsForm{}), org.InitializeLabels)
|
m.Post("/initialize", web.Bind[*forms.InitializeLabelsForm](), org.InitializeLabels)
|
||||||
})
|
})
|
||||||
|
|
||||||
m.Group("/actions", func() {
|
m.Group("/actions", func() {
|
||||||
@@ -1050,7 +1050,7 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
addSettingsScopedWorkflowsRoutes()
|
addSettingsScopedWorkflowsRoutes()
|
||||||
}, actions.MustEnableActions)
|
}, actions.MustEnableActions)
|
||||||
|
|
||||||
m.Post("/rename", web.Bind(forms.RenameOrgForm{}), org.SettingsRenamePost)
|
m.Post("/rename", web.Bind[*forms.RenameOrgForm](), org.SettingsRenamePost)
|
||||||
m.Post("/delete", org.SettingsDeleteOrgPost)
|
m.Post("/delete", org.SettingsDeleteOrgPost)
|
||||||
m.Post("/visibility", org.SettingsChangeVisibilityPost)
|
m.Post("/visibility", org.SettingsChangeVisibilityPost)
|
||||||
|
|
||||||
@@ -1059,11 +1059,11 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
m.Group("/rules", func() {
|
m.Group("/rules", func() {
|
||||||
m.Group("/add", func() {
|
m.Group("/add", func() {
|
||||||
m.Get("", org.PackagesRuleAdd)
|
m.Get("", org.PackagesRuleAdd)
|
||||||
m.Post("", web.Bind(forms.PackageCleanupRuleForm{}), org.PackagesRuleAddPost)
|
m.Post("", web.Bind[*forms.PackageCleanupRuleForm](), org.PackagesRuleAddPost)
|
||||||
})
|
})
|
||||||
m.Group("/{id}", func() {
|
m.Group("/{id}", func() {
|
||||||
m.Get("", org.PackagesRuleEdit)
|
m.Get("", org.PackagesRuleEdit)
|
||||||
m.Post("", web.Bind(forms.PackageCleanupRuleForm{}), org.PackagesRuleEditPost)
|
m.Post("", web.Bind[*forms.PackageCleanupRuleForm](), org.PackagesRuleEditPost)
|
||||||
m.Get("/preview", org.PackagesRulePreview)
|
m.Get("/preview", org.PackagesRulePreview)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -1075,7 +1075,7 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
|
|
||||||
m.Group("/blocked_users", func() {
|
m.Group("/blocked_users", func() {
|
||||||
m.Get("", org.BlockedUsers)
|
m.Get("", org.BlockedUsers)
|
||||||
m.Post("", web.Bind(forms.BlockUserForm{}), org.BlockedUsersPost)
|
m.Post("", web.Bind[*forms.BlockUserForm](), org.BlockedUsersPost)
|
||||||
})
|
})
|
||||||
}, ctxDataSet(reqctx.ContextData{"EnableOAuth2": setting.OAuth2.Enabled, "EnablePackages": setting.Packages.Enabled, "PageIsOrgSettings": true}))
|
}, ctxDataSet(reqctx.ContextData{"EnableOAuth2": setting.OAuth2.Enabled, "EnablePackages": setting.Packages.Enabled, "PageIsOrgSettings": true}))
|
||||||
}, context.OrgAssignment(context.OrgAssignmentOptions{RequireOwner: true}))
|
}, context.OrgAssignment(context.OrgAssignmentOptions{RequireOwner: true}))
|
||||||
@@ -1084,9 +1084,9 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
|
|
||||||
m.Group("/repo", func() {
|
m.Group("/repo", func() {
|
||||||
m.Get("/create", repo.Create)
|
m.Get("/create", repo.Create)
|
||||||
m.Post("/create", web.Bind(forms.CreateRepoForm{}), repo.CreatePost)
|
m.Post("/create", web.Bind[*forms.CreateRepoForm](), repo.CreatePost)
|
||||||
m.Get("/migrate", repo.Migrate)
|
m.Get("/migrate", repo.Migrate)
|
||||||
m.Post("/migrate", web.Bind(forms.MigrateRepoForm{}), repo.MigratePost)
|
m.Post("/migrate", web.Bind[*forms.MigrateRepoForm](), repo.MigratePost)
|
||||||
m.Get("/search", repo.SearchRepo)
|
m.Get("/search", repo.SearchRepo)
|
||||||
}, reqSignIn)
|
}, reqSignIn)
|
||||||
// end "/repo": create, migrate, search
|
// end "/repo": create, migrate, search
|
||||||
@@ -1111,7 +1111,7 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
})
|
})
|
||||||
m.Group("/settings/{type}/{name}", func() {
|
m.Group("/settings/{type}/{name}", func() {
|
||||||
m.Get("", user.PackageSettings)
|
m.Get("", user.PackageSettings)
|
||||||
m.Post("", web.Bind(forms.PackageSettingForm{}), user.PackageSettingsPost)
|
m.Post("", web.Bind[*forms.PackageSettingForm](), user.PackageSettingsPost)
|
||||||
}, reqPackageAccess(perm.AccessModeWrite))
|
}, reqPackageAccess(perm.AccessModeWrite))
|
||||||
}, context.PackageAssignment(), reqPackageAccess(perm.AccessModeRead))
|
}, context.PackageAssignment(), reqPackageAccess(perm.AccessModeRead))
|
||||||
}
|
}
|
||||||
@@ -1129,12 +1129,12 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
}, reqUnitAccess(unit.TypeProjects, perm.AccessModeRead, true))
|
}, reqUnitAccess(unit.TypeProjects, perm.AccessModeRead, true))
|
||||||
m.Group("", func() {
|
m.Group("", func() {
|
||||||
m.Get("/new", org.RenderNewProject)
|
m.Get("/new", org.RenderNewProject)
|
||||||
m.Post("/new", web.Bind(forms.CreateProjectForm{}), org.NewProjectPost)
|
m.Post("/new", web.Bind[*forms.CreateProjectForm](), org.NewProjectPost)
|
||||||
m.Group("/{id}", func() {
|
m.Group("/{id}", func() {
|
||||||
m.Post("/delete", org.DeleteProject)
|
m.Post("/delete", org.DeleteProject)
|
||||||
|
|
||||||
m.Get("/edit", org.RenderEditProject)
|
m.Get("/edit", org.RenderEditProject)
|
||||||
m.Post("/edit", web.Bind(forms.CreateProjectForm{}), org.EditProjectPost)
|
m.Post("/edit", web.Bind[*forms.CreateProjectForm](), org.EditProjectPost)
|
||||||
m.Post("/{action:open|close}", org.ChangeProjectStatus)
|
m.Post("/{action:open|close}", org.ChangeProjectStatus)
|
||||||
|
|
||||||
addProjectBoardRoutes(m)
|
addProjectBoardRoutes(m)
|
||||||
@@ -1168,9 +1168,9 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
m.Group("/{username}/{reponame}/settings", func() {
|
m.Group("/{username}/{reponame}/settings", func() {
|
||||||
m.Group("", func() {
|
m.Group("", func() {
|
||||||
m.Combo("").Get(repo_setting.Settings).
|
m.Combo("").Get(repo_setting.Settings).
|
||||||
Post(web.Bind(forms.RepoSettingForm{}), repo_setting.SettingsPost)
|
Post(web.Bind[*forms.RepoSettingForm](), repo_setting.SettingsPost)
|
||||||
}, repo_setting.SettingsCtxData)
|
}, repo_setting.SettingsCtxData)
|
||||||
m.Post("/avatar", web.Bind(forms.AvatarForm{}), repo_setting.SettingsAvatar)
|
m.Post("/avatar", web.Bind[*forms.AvatarForm](), repo_setting.SettingsAvatar)
|
||||||
m.Post("/avatar/delete", repo_setting.SettingsDeleteAvatar)
|
m.Post("/avatar/delete", repo_setting.SettingsDeleteAvatar)
|
||||||
|
|
||||||
m.Combo("/public_access").Get(repo_setting.PublicAccess).Post(repo_setting.PublicAccessPost)
|
m.Combo("/public_access").Get(repo_setting.PublicAccess).Post(repo_setting.PublicAccessPost)
|
||||||
@@ -1192,17 +1192,17 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
m.Group("/branches", func() {
|
m.Group("/branches", func() {
|
||||||
m.Get("/", repo_setting.ProtectedBranchRules)
|
m.Get("/", repo_setting.ProtectedBranchRules)
|
||||||
m.Combo("/edit").Get(repo_setting.SettingsProtectedBranch).
|
m.Combo("/edit").Get(repo_setting.SettingsProtectedBranch).
|
||||||
Post(web.Bind(forms.ProtectBranchForm{}), context.RepoMustNotBeArchived(), repo_setting.SettingsProtectedBranchPost)
|
Post(web.Bind[*forms.ProtectBranchForm](), context.RepoMustNotBeArchived(), repo_setting.SettingsProtectedBranchPost)
|
||||||
m.Post("/{id}/delete", repo_setting.DeleteProtectedBranchRulePost)
|
m.Post("/{id}/delete", repo_setting.DeleteProtectedBranchRulePost)
|
||||||
m.Post("/priority", context.RepoMustNotBeArchived(), repo_setting.UpdateBranchProtectionPriories)
|
m.Post("/priority", context.RepoMustNotBeArchived(), repo_setting.UpdateBranchProtectionPriories)
|
||||||
})
|
})
|
||||||
|
|
||||||
m.Group("/tags", func() {
|
m.Group("/tags", func() {
|
||||||
m.Get("", repo_setting.ProtectedTags)
|
m.Get("", repo_setting.ProtectedTags)
|
||||||
m.Post("", web.Bind(forms.ProtectTagForm{}), context.RepoMustNotBeArchived(), repo_setting.NewProtectedTagPost)
|
m.Post("", web.Bind[*forms.ProtectTagForm](), context.RepoMustNotBeArchived(), repo_setting.NewProtectedTagPost)
|
||||||
m.Post("/delete", context.RepoMustNotBeArchived(), repo_setting.DeleteProtectedTagPost)
|
m.Post("/delete", context.RepoMustNotBeArchived(), repo_setting.DeleteProtectedTagPost)
|
||||||
m.Get("/{id}", repo_setting.EditProtectedTag)
|
m.Get("/{id}", repo_setting.EditProtectedTag)
|
||||||
m.Post("/{id}", web.Bind(forms.ProtectTagForm{}), context.RepoMustNotBeArchived(), repo_setting.EditProtectedTagPost)
|
m.Post("/{id}", web.Bind[*forms.ProtectTagForm](), context.RepoMustNotBeArchived(), repo_setting.EditProtectedTagPost)
|
||||||
})
|
})
|
||||||
|
|
||||||
m.Group("/hooks/git", func() {
|
m.Group("/hooks/git", func() {
|
||||||
@@ -1273,7 +1273,7 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
// user/org home, including rss feeds like "/{username}/{reponame}.rss"
|
// user/org home, including rss feeds like "/{username}/{reponame}.rss"
|
||||||
m.Get("/{username}/{reponame}", optSignIn, webAuth.AllowBasic, context.RepoAssignment, context.RepoRefByType(git.RefTypeBranch), repo.SetEditorconfigIfExists, repo.Home)
|
m.Get("/{username}/{reponame}", optSignIn, webAuth.AllowBasic, context.RepoAssignment, context.RepoRefByType(git.RefTypeBranch), repo.SetEditorconfigIfExists, repo.Home)
|
||||||
|
|
||||||
m.Post("/{username}/{reponame}/markup", optSignIn, context.RepoAssignment, reqUnitsWithMarkdown, web.Bind(structs.MarkupOption{}), misc.Markup)
|
m.Post("/{username}/{reponame}/markup", optSignIn, context.RepoAssignment, reqUnitsWithMarkdown, web.Bind[*structs.MarkupOption](), misc.Markup)
|
||||||
|
|
||||||
m.Group("/{username}/{reponame}", func() {
|
m.Group("/{username}/{reponame}", func() {
|
||||||
m.Group("/tree-list", func() {
|
m.Group("/tree-list", func() {
|
||||||
@@ -1291,7 +1291,7 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
g.MatchPath("GET", "/<basehead:*>.diff", repo.MustBeNotEmpty, repo.DownloadCompareDiff)
|
g.MatchPath("GET", "/<basehead:*>.diff", repo.MustBeNotEmpty, repo.DownloadCompareDiff)
|
||||||
g.MatchPath("GET", "/<basehead:*>.patch", repo.MustBeNotEmpty, repo.DownloadComparePatch)
|
g.MatchPath("GET", "/<basehead:*>.patch", repo.MustBeNotEmpty, repo.DownloadComparePatch)
|
||||||
g.MatchPath("GET", "/<*:*>", repo.MustBeNotEmpty, repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.CompareDiff)
|
g.MatchPath("GET", "/<*:*>", repo.MustBeNotEmpty, repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.CompareDiff)
|
||||||
g.MatchPath("POST", "/<*:*>", repo.MustBeNotEmpty, repo.SetEditorconfigIfExists, reqSignIn, context.RepoMustNotBeArchived(), reqUnitPullsReader, repo.MustAllowPulls, web.Bind(forms.CreateIssueForm{}), repo.SetWhitespaceBehavior, repo.CompareAndPullRequestPost)
|
g.MatchPath("POST", "/<*:*>", repo.MustBeNotEmpty, repo.SetEditorconfigIfExists, reqSignIn, context.RepoMustNotBeArchived(), reqUnitPullsReader, repo.MustAllowPulls, web.Bind[*forms.CreateIssueForm](), repo.SetWhitespaceBehavior, repo.CompareAndPullRequestPost)
|
||||||
})
|
})
|
||||||
m.Get("/pulls/new/*", repo.PullsNewRedirect)
|
m.Get("/pulls/new/*", repo.PullsNewRedirect)
|
||||||
}, optSignIn, context.RepoAssignment, reqUnitCodeReader)
|
}, optSignIn, context.RepoAssignment, reqUnitCodeReader)
|
||||||
@@ -1335,7 +1335,7 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
m.Group("/issues", func() {
|
m.Group("/issues", func() {
|
||||||
m.Group("/new", func() {
|
m.Group("/new", func() {
|
||||||
m.Combo("").Get(repo.NewIssue).
|
m.Combo("").Get(repo.NewIssue).
|
||||||
Post(web.Bind(forms.CreateIssueForm{}), repo.NewIssuePost)
|
Post(web.Bind[*forms.CreateIssueForm](), repo.NewIssuePost)
|
||||||
m.Get("/choose", repo.NewIssueChooseTemplate)
|
m.Get("/choose", repo.NewIssueChooseTemplate)
|
||||||
})
|
})
|
||||||
m.Get("/search", repo.SearchRepoIssuesJSON)
|
m.Get("/search", repo.SearchRepoIssuesJSON)
|
||||||
@@ -1355,9 +1355,9 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
m.Post("/add", repo.AddDependency)
|
m.Post("/add", repo.AddDependency)
|
||||||
m.Post("/delete", repo.RemoveDependency)
|
m.Post("/delete", repo.RemoveDependency)
|
||||||
})
|
})
|
||||||
m.Combo("/comments").Post(repo.MustAllowUserComment, web.Bind(forms.CreateCommentForm{}), repo.NewComment)
|
m.Combo("/comments").Post(repo.MustAllowUserComment, web.Bind[*forms.CreateCommentForm](), repo.NewComment)
|
||||||
m.Group("/times", func() {
|
m.Group("/times", func() {
|
||||||
m.Post("/add", web.Bind(forms.AddTimeManuallyForm{}), repo.AddTimeManually)
|
m.Post("/add", web.Bind[*forms.AddTimeManuallyForm](), repo.AddTimeManually)
|
||||||
m.Post("/{timeid}/delete", repo.DeleteTime)
|
m.Post("/{timeid}/delete", repo.DeleteTime)
|
||||||
m.Group("/stopwatch", func() {
|
m.Group("/stopwatch", func() {
|
||||||
m.Post("/start", repo.IssueStartStopwatch)
|
m.Post("/start", repo.IssueStartStopwatch)
|
||||||
@@ -1366,8 +1366,8 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
m.Post("/time_estimate", repo.UpdateIssueTimeEstimate)
|
m.Post("/time_estimate", repo.UpdateIssueTimeEstimate)
|
||||||
m.Post("/reactions/{action}", web.Bind(forms.ReactionForm{}), repo.ChangeIssueReaction)
|
m.Post("/reactions/{action}", web.Bind[*forms.ReactionForm](), repo.ChangeIssueReaction)
|
||||||
m.Post("/lock", reqRepoIssuesOrPullsWriter, web.Bind(forms.IssueLockForm{}), repo.LockIssue)
|
m.Post("/lock", reqRepoIssuesOrPullsWriter, web.Bind[*forms.IssueLockForm](), repo.LockIssue)
|
||||||
m.Post("/unlock", reqRepoIssuesOrPullsWriter, repo.UnlockIssue)
|
m.Post("/unlock", reqRepoIssuesOrPullsWriter, repo.UnlockIssue)
|
||||||
m.Post("/delete", reqRepoAdmin, repo.DeleteIssue)
|
m.Post("/delete", reqRepoAdmin, repo.DeleteIssue)
|
||||||
m.Post("/content-history/soft-delete", repo.SoftDeleteContentHistory)
|
m.Post("/content-history/soft-delete", repo.SoftDeleteContentHistory)
|
||||||
@@ -1393,21 +1393,21 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
m.Group("/comments/{id}", func() {
|
m.Group("/comments/{id}", func() {
|
||||||
m.Post("", repo.UpdateCommentContent)
|
m.Post("", repo.UpdateCommentContent)
|
||||||
m.Post("/delete", repo.DeleteComment)
|
m.Post("/delete", repo.DeleteComment)
|
||||||
m.Post("/reactions/{action}", web.Bind(forms.ReactionForm{}), repo.ChangeCommentReaction)
|
m.Post("/reactions/{action}", web.Bind[*forms.ReactionForm](), repo.ChangeCommentReaction)
|
||||||
}, reqRepoIssuesOrPullsReader) // edit issue/pull comment
|
}, reqRepoIssuesOrPullsReader) // edit issue/pull comment
|
||||||
|
|
||||||
m.Group("/labels", func() {
|
m.Group("/labels", func() {
|
||||||
m.Post("/new", web.Bind(forms.CreateLabelForm{}), repo.NewLabel)
|
m.Post("/new", web.Bind[*forms.CreateLabelForm](), repo.NewLabel)
|
||||||
m.Post("/edit", web.Bind(forms.CreateLabelForm{}), repo.UpdateLabel)
|
m.Post("/edit", web.Bind[*forms.CreateLabelForm](), repo.UpdateLabel)
|
||||||
m.Post("/delete", repo.DeleteLabel)
|
m.Post("/delete", repo.DeleteLabel)
|
||||||
m.Post("/initialize", web.Bind(forms.InitializeLabelsForm{}), repo.InitializeLabels)
|
m.Post("/initialize", web.Bind[*forms.InitializeLabelsForm](), repo.InitializeLabels)
|
||||||
}, reqRepoIssuesOrPullsWriter)
|
}, reqRepoIssuesOrPullsWriter)
|
||||||
|
|
||||||
m.Group("/milestones", func() {
|
m.Group("/milestones", func() {
|
||||||
m.Combo("/new").Get(repo.NewMilestone).
|
m.Combo("/new").Get(repo.NewMilestone).
|
||||||
Post(web.Bind(forms.CreateMilestoneForm{}), repo.NewMilestonePost)
|
Post(web.Bind[*forms.CreateMilestoneForm](), repo.NewMilestonePost)
|
||||||
m.Get("/{id}/edit", repo.EditMilestone)
|
m.Get("/{id}/edit", repo.EditMilestone)
|
||||||
m.Post("/{id}/edit", web.Bind(forms.CreateMilestoneForm{}), repo.EditMilestonePost)
|
m.Post("/{id}/edit", web.Bind[*forms.CreateMilestoneForm](), repo.EditMilestonePost)
|
||||||
m.Post("/{id}/{action}", repo.ChangeMilestoneStatus)
|
m.Post("/{id}/{action}", repo.ChangeMilestoneStatus)
|
||||||
m.Post("/delete", repo.DeleteMilestone)
|
m.Post("/delete", repo.DeleteMilestone)
|
||||||
}, reqRepoIssuesOrPullsWriter)
|
}, reqRepoIssuesOrPullsWriter)
|
||||||
@@ -1415,7 +1415,7 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
// FIXME: many "pulls" requests are sent to "issues" endpoints incorrectly, need to move these routes to the proper place
|
// FIXME: many "pulls" requests are sent to "issues" endpoints incorrectly, need to move these routes to the proper place
|
||||||
m.Group("/issues", func() {
|
m.Group("/issues", func() {
|
||||||
m.Post("/request_review", repo.UpdatePullReviewRequest)
|
m.Post("/request_review", repo.UpdatePullReviewRequest)
|
||||||
m.Post("/dismiss_review", reqRepoAdmin, web.Bind(forms.DismissReviewForm{}), repo.DismissReview)
|
m.Post("/dismiss_review", reqRepoAdmin, web.Bind[*forms.DismissReviewForm](), repo.DismissReview)
|
||||||
m.Post("/resolve_conversation", repo.SetShowOutdatedComments, repo.UpdateResolveConversation)
|
m.Post("/resolve_conversation", repo.SetShowOutdatedComments, repo.UpdateResolveConversation)
|
||||||
}, reqUnitPullsReader)
|
}, reqUnitPullsReader)
|
||||||
m.Post("/pull/{index}/target_branch", reqUnitPullsReader, repo.UpdatePullRequestTarget)
|
m.Post("/pull/{index}/target_branch", reqUnitPullsReader, repo.UpdatePullRequestTarget)
|
||||||
@@ -1434,22 +1434,22 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
// the path params are used in PrepareCommitFormOptions to construct the correct form action URL
|
// the path params are used in PrepareCommitFormOptions to construct the correct form action URL
|
||||||
m.Combo("/{editor_action:_edit}/*").
|
m.Combo("/{editor_action:_edit}/*").
|
||||||
Get(repo.EditFile).
|
Get(repo.EditFile).
|
||||||
Post(web.Bind(forms.EditRepoFileForm{}), canWriteToBranch, repo.EditFilePost)
|
Post(web.Bind[*forms.EditRepoFileForm](), canWriteToBranch, repo.EditFilePost)
|
||||||
m.Combo("/{editor_action:_new}/*").
|
m.Combo("/{editor_action:_new}/*").
|
||||||
Get(repo.EditFile).
|
Get(repo.EditFile).
|
||||||
Post(web.Bind(forms.EditRepoFileForm{}), canWriteToBranch, repo.EditFilePost)
|
Post(web.Bind[*forms.EditRepoFileForm](), canWriteToBranch, repo.EditFilePost)
|
||||||
m.Combo("/{editor_action:_delete}/*").
|
m.Combo("/{editor_action:_delete}/*").
|
||||||
Get(repo.DeleteFile).
|
Get(repo.DeleteFile).
|
||||||
Post(web.Bind(forms.DeleteRepoFileForm{}), canWriteToBranch, repo.DeleteFilePost)
|
Post(web.Bind[*forms.DeleteRepoFileForm](), canWriteToBranch, repo.DeleteFilePost)
|
||||||
m.Combo("/{editor_action:_upload}/*", repo.MustBeAbleToUpload).
|
m.Combo("/{editor_action:_upload}/*", repo.MustBeAbleToUpload).
|
||||||
Get(repo.UploadFile).
|
Get(repo.UploadFile).
|
||||||
Post(web.Bind(forms.UploadRepoFileForm{}), canWriteToBranch, repo.UploadFilePost)
|
Post(web.Bind[*forms.UploadRepoFileForm](), canWriteToBranch, repo.UploadFilePost)
|
||||||
m.Combo("/{editor_action:_diffpatch}/*").
|
m.Combo("/{editor_action:_diffpatch}/*").
|
||||||
Get(repo.NewDiffPatch).
|
Get(repo.NewDiffPatch).
|
||||||
Post(web.Bind(forms.EditRepoFileForm{}), canWriteToBranch, repo.NewDiffPatchPost)
|
Post(web.Bind[*forms.EditRepoFileForm](), canWriteToBranch, repo.NewDiffPatchPost)
|
||||||
m.Combo("/{editor_action:_cherrypick}/{sha:([a-f0-9]{7,64})}/*").
|
m.Combo("/{editor_action:_cherrypick}/{sha:([a-f0-9]{7,64})}/*").
|
||||||
Get(repo.CherryPick).
|
Get(repo.CherryPick).
|
||||||
Post(web.Bind(forms.CherryPickForm{}), canWriteToBranch, repo.CherryPickPost)
|
Post(web.Bind[*forms.CherryPickForm](), canWriteToBranch, repo.CherryPickPost)
|
||||||
}, context.RepoRefByType(git.RefTypeBranch), repo.WebGitOperationCommonData)
|
}, context.RepoRefByType(git.RefTypeBranch), repo.WebGitOperationCommonData)
|
||||||
m.Group("", func() {
|
m.Group("", func() {
|
||||||
m.Post("/upload-file", repo.UploadFileToServer)
|
m.Post("/upload-file", repo.UploadFileToServer)
|
||||||
@@ -1462,14 +1462,14 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
m.Post("/branch/*", context.RepoRefByType(git.RefTypeBranch), repo.CreateBranch)
|
m.Post("/branch/*", context.RepoRefByType(git.RefTypeBranch), repo.CreateBranch)
|
||||||
m.Post("/tag/*", context.RepoRefByType(git.RefTypeTag), repo.CreateBranch)
|
m.Post("/tag/*", context.RepoRefByType(git.RefTypeTag), repo.CreateBranch)
|
||||||
m.Post("/commit/*", context.RepoRefByType(git.RefTypeCommit), repo.CreateBranch)
|
m.Post("/commit/*", context.RepoRefByType(git.RefTypeCommit), repo.CreateBranch)
|
||||||
}, web.Bind(forms.NewBranchForm{}))
|
}, web.Bind[*forms.NewBranchForm]())
|
||||||
m.Post("/delete", repo.DeleteBranchPost)
|
m.Post("/delete", repo.DeleteBranchPost)
|
||||||
m.Post("/restore", repo.RestoreBranchPost)
|
m.Post("/restore", repo.RestoreBranchPost)
|
||||||
m.Post("/rename", web.Bind(forms.RenameBranchForm{}), repo_setting.RenameBranchPost)
|
m.Post("/rename", web.Bind[*forms.RenameBranchForm](), repo_setting.RenameBranchPost)
|
||||||
m.Post("/merge-upstream", repo.MergeUpstream)
|
m.Post("/merge-upstream", repo.MergeUpstream)
|
||||||
}, context.RepoMustNotBeArchived(), reqRepoCodeWriter, repo.MustBeNotEmpty)
|
}, context.RepoMustNotBeArchived(), reqRepoCodeWriter, repo.MustBeNotEmpty)
|
||||||
|
|
||||||
m.Combo("/fork").Get(repo.Fork).Post(web.Bind(forms.CreateRepoForm{}), repo.ForkPost)
|
m.Combo("/fork").Get(repo.Fork).Post(web.Bind[*forms.CreateRepoForm](), repo.ForkPost)
|
||||||
}, reqSignIn, context.RepoAssignment, reqUnitCodeReader)
|
}, reqSignIn, context.RepoAssignment, reqUnitCodeReader)
|
||||||
// end "/{username}/{reponame}": repo code
|
// end "/{username}/{reponame}": repo code
|
||||||
|
|
||||||
@@ -1496,10 +1496,10 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
m.Get("/releases/download/{vTag}/{fileName}", webAuth.AllowBasic, webAuth.AllowOAuth2, repo.RedirectDownload)
|
m.Get("/releases/download/{vTag}/{fileName}", webAuth.AllowBasic, webAuth.AllowOAuth2, repo.RedirectDownload)
|
||||||
m.Group("/releases", func() {
|
m.Group("/releases", func() {
|
||||||
m.Get("/new", repo.NewRelease)
|
m.Get("/new", repo.NewRelease)
|
||||||
m.Post("/new", web.Bind(forms.NewReleaseForm{}), repo.NewReleasePost)
|
m.Post("/new", web.Bind[*forms.NewReleaseForm](), repo.NewReleasePost)
|
||||||
m.Get("/edit/*", repo.EditRelease)
|
m.Get("/edit/*", repo.EditRelease)
|
||||||
m.Post("/edit/*", web.Bind(forms.EditReleaseForm{}), repo.EditReleasePost)
|
m.Post("/edit/*", web.Bind[*forms.EditReleaseForm](), repo.EditReleasePost)
|
||||||
m.Post("/generate-notes", web.Bind(forms.GenerateReleaseNotesForm{}), repo.GenerateReleaseNotes)
|
m.Post("/generate-notes", web.Bind[*forms.GenerateReleaseNotesForm](), repo.GenerateReleaseNotes)
|
||||||
m.Post("/delete", repo.DeleteRelease)
|
m.Post("/delete", repo.DeleteRelease)
|
||||||
m.Post("/attachments", repo.UploadReleaseAttachment)
|
m.Post("/attachments", repo.UploadReleaseAttachment)
|
||||||
m.Post("/attachments/remove", repo.DeleteAttachment)
|
m.Post("/attachments/remove", repo.DeleteAttachment)
|
||||||
@@ -1527,12 +1527,12 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
m.Get("/{id}", repo.ViewProject)
|
m.Get("/{id}", repo.ViewProject)
|
||||||
m.Group("", func() {
|
m.Group("", func() {
|
||||||
m.Get("/new", repo.RenderNewProject)
|
m.Get("/new", repo.RenderNewProject)
|
||||||
m.Post("/new", web.Bind(forms.CreateProjectForm{}), repo.NewProjectPost)
|
m.Post("/new", web.Bind[*forms.CreateProjectForm](), repo.NewProjectPost)
|
||||||
m.Group("/{id}", func() {
|
m.Group("/{id}", func() {
|
||||||
m.Post("/delete", repo.DeleteProject)
|
m.Post("/delete", repo.DeleteProject)
|
||||||
|
|
||||||
m.Get("/edit", repo.RenderEditProject)
|
m.Get("/edit", repo.RenderEditProject)
|
||||||
m.Post("/edit", web.Bind(forms.CreateProjectForm{}), repo.EditProjectPost)
|
m.Post("/edit", web.Bind[*forms.CreateProjectForm](), repo.EditProjectPost)
|
||||||
m.Post("/{action:open|close}", repo.ChangeProjectStatus)
|
m.Post("/{action:open|close}", repo.ChangeProjectStatus)
|
||||||
|
|
||||||
addProjectBoardRoutes(m)
|
addProjectBoardRoutes(m)
|
||||||
@@ -1552,16 +1552,16 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
m.Group("/runs/{run}", func() {
|
m.Group("/runs/{run}", func() {
|
||||||
m.Combo("").
|
m.Combo("").
|
||||||
Get(actions.View).
|
Get(actions.View).
|
||||||
Post(web.Bind(actions.ViewRequest{}), actions.ViewPost)
|
Post(web.Bind[*actions.ViewRequest](), actions.ViewPost)
|
||||||
m.Group("/attempts/{attempt}", func() {
|
m.Group("/attempts/{attempt}", func() {
|
||||||
m.Combo("").
|
m.Combo("").
|
||||||
Get(actions.View).
|
Get(actions.View).
|
||||||
Post(web.Bind(actions.ViewRequest{}), actions.ViewPost)
|
Post(web.Bind[*actions.ViewRequest](), actions.ViewPost)
|
||||||
})
|
})
|
||||||
m.Group("/jobs/{job}", func() {
|
m.Group("/jobs/{job}", func() {
|
||||||
m.Combo("").
|
m.Combo("").
|
||||||
Get(actions.View).
|
Get(actions.View).
|
||||||
Post(web.Bind(actions.ViewRequest{}), actions.ViewPost)
|
Post(web.Bind[*actions.ViewRequest](), actions.ViewPost)
|
||||||
m.Post("/rerun", reqRepoActionsWriter, actions.Rerun)
|
m.Post("/rerun", reqRepoActionsWriter, actions.Rerun)
|
||||||
m.Get("/logs", actions.Logs)
|
m.Get("/logs", actions.Logs)
|
||||||
})
|
})
|
||||||
@@ -1583,10 +1583,10 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
m.Group("/{username}/{reponame}/wiki", func() {
|
m.Group("/{username}/{reponame}/wiki", func() {
|
||||||
m.Combo("").
|
m.Combo("").
|
||||||
Get(repo.Wiki).
|
Get(repo.Wiki).
|
||||||
Post(context.RepoMustNotBeArchived(), reqSignIn, reqUnitWikiWriter, web.Bind(forms.NewWikiForm{}), repo.WikiPost)
|
Post(context.RepoMustNotBeArchived(), reqSignIn, reqUnitWikiWriter, web.Bind[*forms.NewWikiForm](), repo.WikiPost)
|
||||||
m.Combo("/*").
|
m.Combo("/*").
|
||||||
Get(repo.Wiki).
|
Get(repo.Wiki).
|
||||||
Post(context.RepoMustNotBeArchived(), reqSignIn, reqUnitWikiWriter, web.Bind(forms.NewWikiForm{}), repo.WikiPost)
|
Post(context.RepoMustNotBeArchived(), reqSignIn, reqUnitWikiWriter, web.Bind[*forms.NewWikiForm](), repo.WikiPost)
|
||||||
m.Get("/blob_excerpt/{sha}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.ExcerptBlob)
|
m.Get("/blob_excerpt/{sha}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.ExcerptBlob)
|
||||||
m.Get("/commit/{sha:[a-f0-9]{7,64}}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.Diff)
|
m.Get("/commit/{sha:[a-f0-9]{7,64}}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.Diff)
|
||||||
m.Get("/commit/{sha:[a-f0-9]{7,64}}.{ext:patch|diff}", repo.RawDiff)
|
m.Get("/commit/{sha:[a-f0-9]{7,64}}.{ext:patch|diff}", repo.RawDiff)
|
||||||
@@ -1634,18 +1634,18 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
m.Get("/list", repo.GetPullCommits)
|
m.Get("/list", repo.GetPullCommits)
|
||||||
m.Get("/{sha:[a-f0-9]{7,64}}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.SetShowOutdatedComments, repo.ViewPullFilesForSingleCommit)
|
m.Get("/{sha:[a-f0-9]{7,64}}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.SetShowOutdatedComments, repo.ViewPullFilesForSingleCommit)
|
||||||
})
|
})
|
||||||
m.Post("/merge", context.RepoMustNotBeArchived(), web.Bind(forms.MergePullRequestForm{}), repo.MergePullRequest)
|
m.Post("/merge", context.RepoMustNotBeArchived(), web.Bind[*forms.MergePullRequestForm](), repo.MergePullRequest)
|
||||||
m.Post("/cancel_auto_merge", context.RepoMustNotBeArchived(), repo.CancelAutoMergePullRequest)
|
m.Post("/cancel_auto_merge", context.RepoMustNotBeArchived(), repo.CancelAutoMergePullRequest)
|
||||||
m.Post("/update", repo.UpdatePullRequest)
|
m.Post("/update", repo.UpdatePullRequest)
|
||||||
m.Post("/set_allow_maintainer_edit", web.Bind(forms.UpdateAllowEditsForm{}), repo.SetAllowEdits)
|
m.Post("/set_allow_maintainer_edit", web.Bind[*forms.UpdateAllowEditsForm](), repo.SetAllowEdits)
|
||||||
m.Post("/cleanup", context.RepoMustNotBeArchived(), repo.CleanUpPullRequest)
|
m.Post("/cleanup", context.RepoMustNotBeArchived(), repo.CleanUpPullRequest)
|
||||||
m.Group("/files", func() {
|
m.Group("/files", func() {
|
||||||
m.Get("", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.SetShowOutdatedComments, repo.ViewPullFilesForAllCommitsOfPr)
|
m.Get("", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.SetShowOutdatedComments, repo.ViewPullFilesForAllCommitsOfPr)
|
||||||
m.Get("/{shaFrom:[a-f0-9]{7,64}}..{shaTo:[a-f0-9]{7,64}}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.SetShowOutdatedComments, repo.ViewPullFilesForRange)
|
m.Get("/{shaFrom:[a-f0-9]{7,64}}..{shaTo:[a-f0-9]{7,64}}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.SetShowOutdatedComments, repo.ViewPullFilesForRange)
|
||||||
m.Group("/reviews", func() {
|
m.Group("/reviews", func() {
|
||||||
m.Get("/new_comment", repo.RenderNewCodeCommentForm)
|
m.Get("/new_comment", repo.RenderNewCodeCommentForm)
|
||||||
m.Post("/comments", web.Bind(forms.CodeCommentForm{}), repo.SetShowOutdatedComments, repo.CreateCodeComment)
|
m.Post("/comments", web.Bind[*forms.CodeCommentForm](), repo.SetShowOutdatedComments, repo.CreateCodeComment)
|
||||||
m.Post("/submit", web.Bind(forms.SubmitReviewForm{}), repo.SubmitReview)
|
m.Post("/submit", web.Bind[*forms.SubmitReviewForm](), repo.SubmitReview)
|
||||||
}, context.RepoMustNotBeArchived())
|
}, context.RepoMustNotBeArchived())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -1777,9 +1777,9 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
|||||||
m.Get("/repo-action-view/runs/{run}", devtest.MockActionsView)
|
m.Get("/repo-action-view/runs/{run}", devtest.MockActionsView)
|
||||||
m.Get("/repo-action-view/runs/{run}/attempts/{attempt}", devtest.MockActionsView)
|
m.Get("/repo-action-view/runs/{run}/attempts/{attempt}", devtest.MockActionsView)
|
||||||
m.Get("/repo-action-view/runs/{run}/jobs/{job}", devtest.MockActionsView)
|
m.Get("/repo-action-view/runs/{run}/jobs/{job}", devtest.MockActionsView)
|
||||||
m.Post("/repo-action-view/runs/{run}", web.Bind(actions.ViewRequest{}), devtest.MockActionsRunsJobs)
|
m.Post("/repo-action-view/runs/{run}", web.Bind[*actions.ViewRequest](), devtest.MockActionsRunsJobs)
|
||||||
m.Post("/repo-action-view/runs/{run}/attempts/{attempt}", web.Bind(actions.ViewRequest{}), devtest.MockActionsRunsJobs)
|
m.Post("/repo-action-view/runs/{run}/attempts/{attempt}", web.Bind[*actions.ViewRequest](), devtest.MockActionsRunsJobs)
|
||||||
m.Post("/repo-action-view/runs/{run}/jobs/{job}", web.Bind(actions.ViewRequest{}), devtest.MockActionsRunsJobs)
|
m.Post("/repo-action-view/runs/{run}/jobs/{job}", web.Bind[*actions.ViewRequest](), devtest.MockActionsRunsJobs)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -296,7 +296,6 @@ func GetFetchActionForm[T interface {
|
|||||||
if web.IsFormSet(ctx) {
|
if web.IsFormSet(ctx) {
|
||||||
panic("don't mix fetch-action form validation with template-based form validation")
|
panic("don't mix fetch-action form validation with template-based form validation")
|
||||||
}
|
}
|
||||||
middleware.SkipTmplFormValidationError(ctx)
|
|
||||||
form := T(new(E))
|
form := T(new(E))
|
||||||
errs := binding.Bind(ctx.Req, form)
|
errs := binding.Bind(ctx.Req, form)
|
||||||
errorMessage, fieldName, _ := middleware.BuildValidationErrorForUser(form, ctx.Locale, errs)
|
errorMessage, fieldName, _ := middleware.BuildValidationErrorForUser(form, ctx.Locale, errs)
|
||||||
|
|||||||
+5
-35
@@ -4,17 +4,13 @@
|
|||||||
package forms
|
package forms
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"gitea.dev/modules/structs"
|
"gitea.dev/modules/structs"
|
||||||
"gitea.dev/modules/web/middleware"
|
"gitea.dev/modules/web/middleware"
|
||||||
"gitea.dev/services/context"
|
|
||||||
|
|
||||||
"gitea.com/go-chi/binding"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// AdminCreateUserForm form for admin to create user
|
// AdminCreateUserForm form for admin to create user
|
||||||
type AdminCreateUserForm struct {
|
type AdminCreateUserForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
LoginType string `binding:"Required"`
|
LoginType string `binding:"Required"`
|
||||||
LoginName string
|
LoginName string
|
||||||
UserName string `binding:"Required;Username;MaxSize(40)"`
|
UserName string `binding:"Required;Username;MaxSize(40)"`
|
||||||
@@ -27,6 +23,7 @@ type AdminCreateUserForm struct {
|
|||||||
|
|
||||||
// AdminCreateBadgeForm form for admin to create badge
|
// AdminCreateBadgeForm form for admin to create badge
|
||||||
type AdminCreateBadgeForm struct {
|
type AdminCreateBadgeForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Slug string `binding:"Required;BadgeSlug" locale:"admin.badges.slug"`
|
Slug string `binding:"Required;BadgeSlug" locale:"admin.badges.slug"`
|
||||||
Description string `binding:"Required" locale:"admin.badges.description"`
|
Description string `binding:"Required" locale:"admin.badges.description"`
|
||||||
ImageURL string `binding:"ValidUrl" locale:"admin.badges.image_url"`
|
ImageURL string `binding:"ValidUrl" locale:"admin.badges.image_url"`
|
||||||
@@ -34,30 +31,14 @@ type AdminCreateBadgeForm struct {
|
|||||||
|
|
||||||
// AdminEditBadgeForm form for admin to edit badge
|
// AdminEditBadgeForm form for admin to edit badge
|
||||||
type AdminEditBadgeForm struct {
|
type AdminEditBadgeForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Description string `binding:"Required" locale:"admin.badges.description"`
|
Description string `binding:"Required" locale:"admin.badges.description"`
|
||||||
ImageURL string `binding:"ValidUrl" locale:"admin.badges.image_url"`
|
ImageURL string `binding:"ValidUrl" locale:"admin.badges.image_url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates form fields
|
|
||||||
func (f *AdminCreateBadgeForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
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(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(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// AdminEditUserForm form for admin to create user
|
// AdminEditUserForm form for admin to create user
|
||||||
type AdminEditUserForm struct {
|
type AdminEditUserForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
LoginType string `binding:"Required"`
|
LoginType string `binding:"Required"`
|
||||||
UserName string `binding:"Username;MaxSize(40)"`
|
UserName string `binding:"Username;MaxSize(40)"`
|
||||||
LoginName string
|
LoginName string
|
||||||
@@ -79,20 +60,9 @@ type AdminEditUserForm struct {
|
|||||||
Visibility structs.VisibleType
|
Visibility structs.VisibleType
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates form fields
|
|
||||||
func (f *AdminEditUserForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// AdminDashboardForm form for admin dashboard operations
|
// AdminDashboardForm form for admin dashboard operations
|
||||||
type AdminDashboardForm struct {
|
type AdminDashboardForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Op string `binding:"required"`
|
Op string `binding:"required"`
|
||||||
From string
|
From string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates form fields
|
|
||||||
func (f *AdminDashboardForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,17 +3,11 @@
|
|||||||
|
|
||||||
package forms
|
package forms
|
||||||
|
|
||||||
import (
|
import "gitea.dev/modules/web/middleware"
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"gitea.dev/modules/web/middleware"
|
|
||||||
"gitea.dev/services/context"
|
|
||||||
|
|
||||||
"gitea.com/go-chi/binding"
|
|
||||||
)
|
|
||||||
|
|
||||||
// AuthenticationForm form for authentication
|
// AuthenticationForm form for authentication
|
||||||
type AuthenticationForm struct {
|
type AuthenticationForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Type int `binding:"Range(2,7)"`
|
Type int `binding:"Range(2,7)"`
|
||||||
Name string `binding:"Required;MaxSize(30)"`
|
Name string `binding:"Required;MaxSize(30)"`
|
||||||
TwoFactorPolicy string
|
TwoFactorPolicy string
|
||||||
@@ -96,9 +90,3 @@ type AuthenticationForm struct {
|
|||||||
SSPISeparatorReplacement string `binding:"AlphaDashDot;MaxSize(5)"`
|
SSPISeparatorReplacement string `binding:"AlphaDashDot;MaxSize(5)"`
|
||||||
SSPIDefaultLanguage string
|
SSPIDefaultLanguage string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates fields
|
|
||||||
func (f *AuthenticationForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|||||||
+4
-23
@@ -5,13 +5,8 @@
|
|||||||
package forms
|
package forms
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"gitea.dev/modules/structs"
|
"gitea.dev/modules/structs"
|
||||||
"gitea.dev/modules/web/middleware"
|
"gitea.dev/modules/web/middleware"
|
||||||
"gitea.dev/services/context"
|
|
||||||
|
|
||||||
"gitea.com/go-chi/binding"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ________ .__ __ .__
|
// ________ .__ __ .__
|
||||||
@@ -23,19 +18,15 @@ import (
|
|||||||
|
|
||||||
// CreateOrgForm form for creating organization
|
// CreateOrgForm form for creating organization
|
||||||
type CreateOrgForm struct {
|
type CreateOrgForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
OrgName string `binding:"Required;Username;MaxSize(40)" locale:"org.org_name_holder"`
|
OrgName string `binding:"Required;Username;MaxSize(40)" locale:"org.org_name_holder"`
|
||||||
Visibility structs.VisibleType
|
Visibility structs.VisibleType
|
||||||
RepoAdminChangeTeamAccess bool
|
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
|
// UpdateOrgSettingForm form for updating organization settings
|
||||||
type UpdateOrgSettingForm struct {
|
type UpdateOrgSettingForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
FullName *string `binding:"MaxSize(100)"`
|
FullName *string `binding:"MaxSize(100)"`
|
||||||
Email *string `binding:"MaxSize(255)"`
|
Email *string `binding:"MaxSize(255)"`
|
||||||
Description *string `binding:"MaxSize(255)"`
|
Description *string `binding:"MaxSize(255)"`
|
||||||
@@ -45,13 +36,8 @@ type UpdateOrgSettingForm struct {
|
|||||||
RepoAdminChangeTeamAccess *bool
|
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 {
|
type RenameOrgForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
OrgName string `binding:"Required"`
|
OrgName string `binding:"Required"`
|
||||||
NewOrgName string `binding:"Required;Username;MaxSize(40)" locale:"org.org_name_holder"`
|
NewOrgName string `binding:"Required;Username;MaxSize(40)" locale:"org.org_name_holder"`
|
||||||
}
|
}
|
||||||
@@ -65,6 +51,7 @@ type RenameOrgForm struct {
|
|||||||
|
|
||||||
// CreateTeamForm form for creating team
|
// CreateTeamForm form for creating team
|
||||||
type CreateTeamForm struct {
|
type CreateTeamForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
TeamName string `binding:"Required;AlphaDashDot;MaxSize(255)"`
|
TeamName string `binding:"Required;AlphaDashDot;MaxSize(255)"`
|
||||||
Description string `binding:"MaxSize(255)"`
|
Description string `binding:"MaxSize(255)"`
|
||||||
Permission string
|
Permission string
|
||||||
@@ -72,9 +59,3 @@ type CreateTeamForm struct {
|
|||||||
CanCreateOrgRepo bool
|
CanCreateOrgRepo bool
|
||||||
Visibility string `binding:"OmitEmpty;In(public,limited,private)"`
|
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)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,16 +3,10 @@
|
|||||||
|
|
||||||
package forms
|
package forms
|
||||||
|
|
||||||
import (
|
import "gitea.dev/modules/web/middleware"
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"gitea.dev/modules/web/middleware"
|
|
||||||
"gitea.dev/services/context"
|
|
||||||
|
|
||||||
"gitea.com/go-chi/binding"
|
|
||||||
)
|
|
||||||
|
|
||||||
type PackageCleanupRuleForm struct {
|
type PackageCleanupRuleForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
ID int64
|
ID int64
|
||||||
Enabled bool
|
Enabled bool
|
||||||
Type string `binding:"Required;In(alpine,arch,cargo,chef,composer,conan,conda,container,cran,debian,generic,go,helm,maven,npm,nuget,pub,pypi,rpm,rubygems,swift,terraform,vagrant)"`
|
Type string `binding:"Required;In(alpine,arch,cargo,chef,composer,conan,conda,container,cran,debian,generic,go,helm,maven,npm,nuget,pub,pypi,rpm,rubygems,swift,terraform,vagrant)"`
|
||||||
@@ -23,8 +17,3 @@ type PackageCleanupRuleForm struct {
|
|||||||
MatchFullName bool
|
MatchFullName bool
|
||||||
Action string `binding:"Required;In(save,remove)"`
|
Action string `binding:"Required;In(save,remove)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *PackageCleanupRuleForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,36 +3,19 @@
|
|||||||
|
|
||||||
package forms
|
package forms
|
||||||
|
|
||||||
import (
|
import "gitea.dev/modules/web/middleware"
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"gitea.dev/modules/web/middleware"
|
|
||||||
"gitea.dev/services/context"
|
|
||||||
|
|
||||||
"gitea.com/go-chi/binding"
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewBranchForm form for creating a new branch
|
// NewBranchForm form for creating a new branch
|
||||||
type NewBranchForm struct {
|
type NewBranchForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
NewBranchName string `binding:"Required;MaxSize(100);GitRefName"`
|
NewBranchName string `binding:"Required;MaxSize(100);GitRefName"`
|
||||||
CurrentPath string
|
CurrentPath string
|
||||||
CreateTag bool
|
CreateTag bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *NewBranchForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// RenameBranchForm form for rename a branch
|
// RenameBranchForm form for rename a branch
|
||||||
type RenameBranchForm struct {
|
type RenameBranchForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
From string `binding:"Required;MaxSize(100);GitRefName"`
|
From string `binding:"Required;MaxSize(100);GitRefName"`
|
||||||
To string `binding:"Required;MaxSize(100);GitRefName"`
|
To string `binding:"Required;MaxSize(100);GitRefName"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *RenameBranchForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|||||||
+37
-181
@@ -5,7 +5,6 @@
|
|||||||
package forms
|
package forms
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
issues_model "gitea.dev/models/issues"
|
issues_model "gitea.dev/models/issues"
|
||||||
@@ -14,7 +13,6 @@ import (
|
|||||||
"gitea.dev/modules/structs"
|
"gitea.dev/modules/structs"
|
||||||
"gitea.dev/modules/util"
|
"gitea.dev/modules/util"
|
||||||
"gitea.dev/modules/web/middleware"
|
"gitea.dev/modules/web/middleware"
|
||||||
"gitea.dev/services/context"
|
|
||||||
"gitea.dev/services/webhook"
|
"gitea.dev/services/webhook"
|
||||||
|
|
||||||
"gitea.com/go-chi/binding"
|
"gitea.com/go-chi/binding"
|
||||||
@@ -22,6 +20,7 @@ import (
|
|||||||
|
|
||||||
// CreateRepoForm form for creating repository
|
// CreateRepoForm form for creating repository
|
||||||
type CreateRepoForm struct {
|
type CreateRepoForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
UID int64 `binding:"Required"`
|
UID int64 `binding:"Required"`
|
||||||
RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
|
RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
|
||||||
Private bool
|
Private bool
|
||||||
@@ -47,15 +46,10 @@ type CreateRepoForm struct {
|
|||||||
ObjectFormatName string
|
ObjectFormatName string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *CreateRepoForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MigrateRepoForm form for migrating repository
|
// MigrateRepoForm form for migrating repository
|
||||||
// this is used to interact with web ui
|
// this is used to interact with web ui
|
||||||
type MigrateRepoForm struct {
|
type MigrateRepoForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
// required: true
|
// required: true
|
||||||
CloneAddr string `json:"clone_addr" binding:"Required"`
|
CloneAddr string `json:"clone_addr" binding:"Required"`
|
||||||
Service structs.GitServiceType `json:"service"`
|
Service structs.GitServiceType `json:"service"`
|
||||||
@@ -83,14 +77,9 @@ type MigrateRepoForm struct {
|
|||||||
AWSSecretAccessKey string `json:"aws_secret_access_key"`
|
AWSSecretAccessKey string `json:"aws_secret_access_key"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *MigrateRepoForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// RepoSettingForm form for changing repository settings
|
// RepoSettingForm form for changing repository settings
|
||||||
type RepoSettingForm struct {
|
type RepoSettingForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
|
RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
|
||||||
Description string `binding:"MaxSize(2048)"`
|
Description string `binding:"MaxSize(2048)"`
|
||||||
Website string `binding:"ValidUrl;MaxSize(1024)"`
|
Website string `binding:"ValidUrl;MaxSize(1024)"`
|
||||||
@@ -160,14 +149,9 @@ type RepoSettingForm struct {
|
|||||||
RequestReindexType string
|
RequestReindexType string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *RepoSettingForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ProtectBranchForm form for changing protected branch settings
|
// ProtectBranchForm form for changing protected branch settings
|
||||||
type ProtectBranchForm struct {
|
type ProtectBranchForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
RuleName string `binding:"Required"`
|
RuleName string `binding:"Required"`
|
||||||
RuleID int64
|
RuleID int64
|
||||||
EnablePush string
|
EnablePush string
|
||||||
@@ -202,14 +186,9 @@ type ProtectBranchForm struct {
|
|||||||
BlockAdminMergeOverride bool
|
BlockAdminMergeOverride bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *ProtectBranchForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// WebhookForm form for changing web hook
|
// WebhookForm form for changing web hook
|
||||||
type WebhookForm struct {
|
type WebhookForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Name string `binding:"MaxSize(255)"`
|
Name string `binding:"MaxSize(255)"`
|
||||||
Events string
|
Events string
|
||||||
Create bool
|
Create bool
|
||||||
@@ -259,31 +238,21 @@ func (f WebhookForm) ChooseEvents() bool {
|
|||||||
|
|
||||||
// NewWebhookForm form for creating web hook
|
// NewWebhookForm form for creating web hook
|
||||||
type NewWebhookForm struct {
|
type NewWebhookForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
PayloadURL string `binding:"Required;ValidUrl"`
|
PayloadURL string `binding:"Required;ValidUrl"`
|
||||||
HTTPMethod string `binding:"Required;In(POST,GET)"`
|
HTTPMethod string `binding:"Required;In(POST,GET)"`
|
||||||
ContentType int `binding:"Required"`
|
ContentType int `binding:"Required"`
|
||||||
WebhookForm
|
WebhookForm
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *NewWebhookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewGogshookForm form for creating gogs hook
|
// NewGogshookForm form for creating gogs hook
|
||||||
type NewGogshookForm struct {
|
type NewGogshookForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
PayloadURL string `binding:"Required;ValidUrl"`
|
PayloadURL string `binding:"Required;ValidUrl"`
|
||||||
ContentType int `binding:"Required"`
|
ContentType int `binding:"Required"`
|
||||||
WebhookForm
|
WebhookForm
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *NewGogshookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewSlackHookForm form for creating slack hook
|
// NewSlackHookForm form for creating slack hook
|
||||||
type NewSlackHookForm struct {
|
type NewSlackHookForm struct {
|
||||||
PayloadURL string `binding:"Required;ValidUrl"`
|
PayloadURL string `binding:"Required;ValidUrl"`
|
||||||
@@ -294,121 +263,80 @@ type NewSlackHookForm struct {
|
|||||||
WebhookForm
|
WebhookForm
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
func (f *NewSlackHookForm) Validate(ctx *middleware.ValidateContext, errs binding.Errors) binding.Errors {
|
||||||
func (f *NewSlackHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
if !webhook.IsValidSlackChannel(strings.TrimSpace(f.Channel)) {
|
if !webhook.IsValidSlackChannel(strings.TrimSpace(f.Channel)) {
|
||||||
errs = middleware.AddValidationError(errs, "Channel", 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(ctx, errs, f)
|
return errs
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDiscordHookForm form for creating discord hook
|
// NewDiscordHookForm form for creating discord hook
|
||||||
type NewDiscordHookForm struct {
|
type NewDiscordHookForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
PayloadURL string `binding:"Required;ValidUrl"`
|
PayloadURL string `binding:"Required;ValidUrl"`
|
||||||
Username string
|
Username string
|
||||||
IconURL string
|
IconURL string
|
||||||
WebhookForm
|
WebhookForm
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *NewDiscordHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewDingtalkHookForm form for creating dingtalk hook
|
// NewDingtalkHookForm form for creating dingtalk hook
|
||||||
type NewDingtalkHookForm struct {
|
type NewDingtalkHookForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
PayloadURL string `binding:"Required;ValidUrl"`
|
PayloadURL string `binding:"Required;ValidUrl"`
|
||||||
WebhookForm
|
WebhookForm
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *NewDingtalkHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewTelegramHookForm form for creating telegram hook
|
// NewTelegramHookForm form for creating telegram hook
|
||||||
type NewTelegramHookForm struct {
|
type NewTelegramHookForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
BotToken string `binding:"Required"`
|
BotToken string `binding:"Required"`
|
||||||
ChatID string `binding:"Required"`
|
ChatID string `binding:"Required"`
|
||||||
ThreadID string
|
ThreadID string
|
||||||
WebhookForm
|
WebhookForm
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *NewTelegramHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewMatrixHookForm form for creating Matrix hook
|
// NewMatrixHookForm form for creating Matrix hook
|
||||||
type NewMatrixHookForm struct {
|
type NewMatrixHookForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
HomeserverURL string `binding:"Required;ValidUrl"`
|
HomeserverURL string `binding:"Required;ValidUrl"`
|
||||||
RoomID string `binding:"Required"`
|
RoomID string `binding:"Required"`
|
||||||
MessageType int
|
MessageType int
|
||||||
WebhookForm
|
WebhookForm
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *NewMatrixHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewMSTeamsHookForm form for creating MS Teams hook
|
// NewMSTeamsHookForm form for creating MS Teams hook
|
||||||
type NewMSTeamsHookForm struct {
|
type NewMSTeamsHookForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
PayloadURL string `binding:"Required;ValidUrl"`
|
PayloadURL string `binding:"Required;ValidUrl"`
|
||||||
WebhookForm
|
WebhookForm
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *NewMSTeamsHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewFeishuHookForm form for creating feishu hook
|
// NewFeishuHookForm form for creating feishu hook
|
||||||
type NewFeishuHookForm struct {
|
type NewFeishuHookForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
PayloadURL string `binding:"Required;ValidUrl"`
|
PayloadURL string `binding:"Required;ValidUrl"`
|
||||||
WebhookForm
|
WebhookForm
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *NewFeishuHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewWechatWorkHookForm form for creating wechatwork hook
|
// NewWechatWorkHookForm form for creating wechatwork hook
|
||||||
type NewWechatWorkHookForm struct {
|
type NewWechatWorkHookForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
PayloadURL string `binding:"Required;ValidUrl"`
|
PayloadURL string `binding:"Required;ValidUrl"`
|
||||||
WebhookForm
|
WebhookForm
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *NewWechatWorkHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewPackagistHookForm form for creating packagist hook
|
// NewPackagistHookForm form for creating packagist hook
|
||||||
type NewPackagistHookForm struct {
|
type NewPackagistHookForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Username string `binding:"Required"`
|
Username string `binding:"Required"`
|
||||||
APIToken string `binding:"Required"`
|
APIToken string `binding:"Required"`
|
||||||
PackageURL string `binding:"Required;ValidUrl"`
|
PackageURL string `binding:"Required;ValidUrl"`
|
||||||
WebhookForm
|
WebhookForm
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *NewPackagistHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateIssueForm form for creating issue
|
// CreateIssueForm form for creating issue
|
||||||
type CreateIssueForm struct {
|
type CreateIssueForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Title string `binding:"Required;MaxSize(255)"`
|
Title string `binding:"Required;MaxSize(255)"`
|
||||||
AssigneeIDs string `form:"assignee_ids"`
|
AssigneeIDs string `form:"assignee_ids"`
|
||||||
ReviewerIDs string `form:"reviewer_ids"`
|
ReviewerIDs string `form:"reviewer_ids"`
|
||||||
@@ -419,49 +347,29 @@ type CreateIssueForm struct {
|
|||||||
AllowMaintainerEdit bool
|
AllowMaintainerEdit bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *CreateIssueForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateCommentForm form for creating comment
|
// CreateCommentForm form for creating comment
|
||||||
type CreateCommentForm struct {
|
type CreateCommentForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Content string
|
Content string
|
||||||
Status string `binding:"OmitEmpty;In(reopen,close)"`
|
Status string `binding:"OmitEmpty;In(reopen,close)"`
|
||||||
Files []string
|
Files []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *CreateCommentForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReactionForm form for adding and removing reaction
|
// ReactionForm form for adding and removing reaction
|
||||||
type ReactionForm struct {
|
type ReactionForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Content string `binding:"Required"`
|
Content string `binding:"Required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *ReactionForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// IssueLockForm form for locking an issue
|
// IssueLockForm form for locking an issue
|
||||||
type IssueLockForm struct {
|
type IssueLockForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Reason string `binding:"Required"`
|
Reason string `binding:"Required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *IssueLockForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateProjectForm form for creating a project
|
// CreateProjectForm form for creating a project
|
||||||
type CreateProjectForm struct {
|
type CreateProjectForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Title string `binding:"Required;MaxSize(100)"`
|
Title string `binding:"Required;MaxSize(100)"`
|
||||||
Content string
|
Content string
|
||||||
TemplateType project_model.TemplateType
|
TemplateType project_model.TemplateType
|
||||||
@@ -470,6 +378,7 @@ type CreateProjectForm struct {
|
|||||||
|
|
||||||
// EditProjectColumnForm is a form for editing a project column
|
// EditProjectColumnForm is a form for editing a project column
|
||||||
type EditProjectColumnForm struct {
|
type EditProjectColumnForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Title string `binding:"Required;MaxSize(100)"`
|
Title string `binding:"Required;MaxSize(100)"`
|
||||||
Sorting int8
|
Sorting int8
|
||||||
Color string `binding:"MaxSize(7)"`
|
Color string `binding:"MaxSize(7)"`
|
||||||
@@ -477,19 +386,15 @@ type EditProjectColumnForm struct {
|
|||||||
|
|
||||||
// CreateMilestoneForm form for creating milestone
|
// CreateMilestoneForm form for creating milestone
|
||||||
type CreateMilestoneForm struct {
|
type CreateMilestoneForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Title string `binding:"Required;MaxSize(50)"`
|
Title string `binding:"Required;MaxSize(50)"`
|
||||||
Content string
|
Content string
|
||||||
Deadline string
|
Deadline string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *CreateMilestoneForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateLabelForm form for creating label
|
// CreateLabelForm form for creating label
|
||||||
type CreateLabelForm struct {
|
type CreateLabelForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
ID int64
|
ID int64
|
||||||
Title string `binding:"Required;MaxSize(50)" locale:"repo.issues.label_title"`
|
Title string `binding:"Required;MaxSize(50)" locale:"repo.issues.label_title"`
|
||||||
Exclusive bool `form:"exclusive"`
|
Exclusive bool `form:"exclusive"`
|
||||||
@@ -499,26 +404,16 @@ type CreateLabelForm struct {
|
|||||||
Color string `binding:"Required;MaxSize(7)" locale:"repo.issues.label_color"`
|
Color string `binding:"Required;MaxSize(7)" locale:"repo.issues.label_color"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *CreateLabelForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// InitializeLabelsForm form for initializing labels
|
// InitializeLabelsForm form for initializing labels
|
||||||
type InitializeLabelsForm struct {
|
type InitializeLabelsForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
TemplateName string `binding:"Required"`
|
TemplateName string `binding:"Required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *InitializeLabelsForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MergePullRequestForm form for merging Pull Request
|
// MergePullRequestForm form for merging Pull Request
|
||||||
// swagger:model MergePullRequestOption
|
// swagger:model MergePullRequestOption
|
||||||
type MergePullRequestForm struct {
|
type MergePullRequestForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
// required: true
|
// required: true
|
||||||
// enum: ["merge","rebase","rebase-merge","squash","fast-forward-only","manually-merged"]
|
// enum: ["merge","rebase","rebase-merge","squash","fast-forward-only","manually-merged"]
|
||||||
Do string `json:"do" binding:"Required;In(merge,rebase,rebase-merge,squash,fast-forward-only,manually-merged)"`
|
Do string `json:"do" binding:"Required;In(merge,rebase,rebase-merge,squash,fast-forward-only,manually-merged)"`
|
||||||
@@ -564,14 +459,9 @@ func (f *MergePullRequestForm) UnmarshalJSON(b []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *MergePullRequestForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// CodeCommentForm form for adding code comments for PRs
|
// CodeCommentForm form for adding code comments for PRs
|
||||||
type CodeCommentForm struct {
|
type CodeCommentForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Origin string `binding:"Required;In(timeline,diff)"`
|
Origin string `binding:"Required;In(timeline,diff)"`
|
||||||
Content string `binding:"Required"`
|
Content string `binding:"Required"`
|
||||||
Side string `binding:"Required;In(previous,proposed)"`
|
Side string `binding:"Required;In(previous,proposed)"`
|
||||||
@@ -583,26 +473,15 @@ type CodeCommentForm struct {
|
|||||||
Files []string
|
Files []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *CodeCommentForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SubmitReviewForm for submitting a finished code review
|
// SubmitReviewForm for submitting a finished code review
|
||||||
type SubmitReviewForm struct {
|
type SubmitReviewForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Content string
|
Content string
|
||||||
Type string
|
Type string
|
||||||
CommitID string
|
CommitID string
|
||||||
Files []string
|
Files []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *SubmitReviewForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReviewType will return the corresponding ReviewType for type
|
// ReviewType will return the corresponding ReviewType for type
|
||||||
func (f SubmitReviewForm) ReviewType() issues_model.ReviewType {
|
func (f SubmitReviewForm) ReviewType() issues_model.ReviewType {
|
||||||
switch f.Type {
|
switch f.Type {
|
||||||
@@ -629,12 +508,14 @@ func (f SubmitReviewForm) HasEmptyContent() bool {
|
|||||||
|
|
||||||
// DismissReviewForm for dismissing stale review by repo admin
|
// DismissReviewForm for dismissing stale review by repo admin
|
||||||
type DismissReviewForm struct {
|
type DismissReviewForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
ReviewID int64 `binding:"Required"`
|
ReviewID int64 `binding:"Required"`
|
||||||
Message string
|
Message string
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateAllowEditsForm form for changing if PR allows edits from maintainers
|
// UpdateAllowEditsForm form for changing if PR allows edits from maintainers
|
||||||
type UpdateAllowEditsForm struct {
|
type UpdateAllowEditsForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
AllowMaintainerEdit bool
|
AllowMaintainerEdit bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -647,6 +528,7 @@ type UpdateAllowEditsForm struct {
|
|||||||
|
|
||||||
// NewReleaseForm form for creating release
|
// NewReleaseForm form for creating release
|
||||||
type NewReleaseForm struct {
|
type NewReleaseForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
TagName string `binding:"Required;GitRefName;MaxSize(255)"`
|
TagName string `binding:"Required;GitRefName;MaxSize(255)"`
|
||||||
Target string `form:"tag_target" binding:"Required;MaxSize(255)"`
|
Target string `form:"tag_target" binding:"Required;MaxSize(255)"`
|
||||||
Title string `binding:"MaxSize(255)"`
|
Title string `binding:"MaxSize(255)"`
|
||||||
@@ -658,27 +540,17 @@ type NewReleaseForm struct {
|
|||||||
Files []string
|
Files []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *NewReleaseForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GenerateReleaseNotesForm retrieves release notes recommendations.
|
// GenerateReleaseNotesForm retrieves release notes recommendations.
|
||||||
type GenerateReleaseNotesForm struct {
|
type GenerateReleaseNotesForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
TagName string `form:"tag_name" binding:"Required;GitRefName;MaxSize(255)"`
|
TagName string `form:"tag_name" binding:"Required;GitRefName;MaxSize(255)"`
|
||||||
TagTarget string `form:"tag_target" binding:"MaxSize(255)"`
|
TagTarget string `form:"tag_target" binding:"MaxSize(255)"`
|
||||||
PreviousTag string `form:"previous_tag" binding:"MaxSize(255)"`
|
PreviousTag string `form:"previous_tag" binding:"MaxSize(255)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *GenerateReleaseNotesForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// EditReleaseForm form for changing release
|
// EditReleaseForm form for changing release
|
||||||
type EditReleaseForm struct {
|
type EditReleaseForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Title string `form:"title" binding:"Required;MaxSize(255)"`
|
Title string `form:"title" binding:"Required;MaxSize(255)"`
|
||||||
Content string `form:"content"`
|
Content string `form:"content"`
|
||||||
Draft string `form:"draft"`
|
Draft string `form:"draft"`
|
||||||
@@ -686,12 +558,6 @@ type EditReleaseForm struct {
|
|||||||
Files []string
|
Files []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *EditReleaseForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// __ __.__ __ .__
|
// __ __.__ __ .__
|
||||||
// / \ / \__| | _|__|
|
// / \ / \__| | _|__|
|
||||||
// \ \/\/ / | |/ / |
|
// \ \/\/ / | |/ / |
|
||||||
@@ -701,18 +567,12 @@ func (f *EditReleaseForm) Validate(req *http.Request, errs binding.Errors) bindi
|
|||||||
|
|
||||||
// NewWikiForm form for creating wiki
|
// NewWikiForm form for creating wiki
|
||||||
type NewWikiForm struct {
|
type NewWikiForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Title string `binding:"Required"`
|
Title string `binding:"Required"`
|
||||||
Content string `binding:"Required"`
|
Content string `binding:"Required"`
|
||||||
Message string
|
Message string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
// 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(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ___________.__ ___________ __
|
// ___________.__ ___________ __
|
||||||
// \__ ___/|__| _____ ____ \__ ___/___________ ____ | | __ ___________
|
// \__ ___/|__| _____ ____ \__ ___/___________ ____ | | __ ___________
|
||||||
// | | | |/ \_/ __ \ | | \_ __ \__ \ _/ ___\| |/ // __ \_ __ \
|
// | | | |/ \_/ __ \ | | \_ __ \__ \ _/ ___\| |/ // __ \_ __ \
|
||||||
@@ -722,17 +582,13 @@ func (f *NewWikiForm) Validate(req *http.Request, errs binding.Errors) binding.E
|
|||||||
|
|
||||||
// AddTimeManuallyForm form that adds spent time manually.
|
// AddTimeManuallyForm form that adds spent time manually.
|
||||||
type AddTimeManuallyForm struct {
|
type AddTimeManuallyForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Hours int `binding:"Range(0,1000)"`
|
Hours int `binding:"Range(0,1000)"`
|
||||||
Minutes int `binding:"Range(0,1000)"`
|
Minutes int `binding:"Range(0,1000)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *AddTimeManuallyForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SaveTopicForm form for save topics for repository
|
// SaveTopicForm form for save topics for repository
|
||||||
type SaveTopicForm struct {
|
type SaveTopicForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Topics []string `binding:"topics;Required;"`
|
Topics []string `binding:"topics;Required;"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,16 +4,12 @@
|
|||||||
package forms
|
package forms
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"gitea.dev/modules/optional"
|
"gitea.dev/modules/optional"
|
||||||
"gitea.dev/modules/web/middleware"
|
"gitea.dev/modules/web/middleware"
|
||||||
"gitea.dev/services/context"
|
|
||||||
|
|
||||||
"gitea.com/go-chi/binding"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type CommitCommonForm struct {
|
type CommitCommonForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
TreePath string `binding:"MaxSize(500)"`
|
TreePath string `binding:"MaxSize(500)"`
|
||||||
CommitSummary string `binding:"MaxSize(100)"`
|
CommitSummary string `binding:"MaxSize(100)"`
|
||||||
CommitMessage string
|
CommitMessage string
|
||||||
@@ -24,11 +20,6 @@ type CommitCommonForm struct {
|
|||||||
CommitEmail string
|
CommitEmail string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *CommitCommonForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
type CommitCommonFormInterface interface {
|
type CommitCommonFormInterface interface {
|
||||||
GetCommitCommonForm() *CommitCommonForm
|
GetCommitCommonForm() *CommitCommonForm
|
||||||
}
|
}
|
||||||
@@ -38,20 +29,24 @@ func (f *CommitCommonForm) GetCommitCommonForm() *CommitCommonForm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type EditRepoFileForm struct {
|
type EditRepoFileForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
CommitCommonForm
|
CommitCommonForm
|
||||||
Content optional.Option[string]
|
Content optional.Option[string]
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeleteRepoFileForm struct {
|
type DeleteRepoFileForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
CommitCommonForm
|
CommitCommonForm
|
||||||
}
|
}
|
||||||
|
|
||||||
type UploadRepoFileForm struct {
|
type UploadRepoFileForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
CommitCommonForm
|
CommitCommonForm
|
||||||
Files []string
|
Files []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type CherryPickForm struct {
|
type CherryPickForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
CommitCommonForm
|
CommitCommonForm
|
||||||
Revert bool
|
Revert bool
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,24 +3,12 @@
|
|||||||
|
|
||||||
package forms
|
package forms
|
||||||
|
|
||||||
import (
|
import "gitea.dev/modules/web/middleware"
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"gitea.dev/modules/web/middleware"
|
|
||||||
"gitea.dev/services/context"
|
|
||||||
|
|
||||||
"gitea.com/go-chi/binding"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ProtectTagForm form for changing protected tag settings
|
// ProtectTagForm form for changing protected tag settings
|
||||||
type ProtectTagForm struct {
|
type ProtectTagForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
NamePattern string `binding:"Required;GlobOrRegexPattern"`
|
NamePattern string `binding:"Required;GlobOrRegexPattern"`
|
||||||
AllowlistUsers string
|
AllowlistUsers string
|
||||||
AllowlistTeams string
|
AllowlistTeams string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *ProtectTagForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,22 +3,10 @@
|
|||||||
|
|
||||||
package forms
|
package forms
|
||||||
|
|
||||||
import (
|
import "gitea.dev/modules/web/middleware"
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"gitea.dev/modules/web/middleware"
|
|
||||||
"gitea.dev/services/context"
|
|
||||||
|
|
||||||
"gitea.com/go-chi/binding"
|
|
||||||
)
|
|
||||||
|
|
||||||
// EditRunnerForm form for admin to create runner
|
// EditRunnerForm form for admin to create runner
|
||||||
type EditRunnerForm struct {
|
type EditRunnerForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Description string
|
Description string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates form fields
|
|
||||||
func (f *EditRunnerForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|||||||
+28
-150
@@ -6,7 +6,6 @@ package forms
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
user_model "gitea.dev/models/user"
|
user_model "gitea.dev/models/user"
|
||||||
@@ -15,13 +14,13 @@ import (
|
|||||||
"gitea.dev/modules/util"
|
"gitea.dev/modules/util"
|
||||||
"gitea.dev/modules/validation"
|
"gitea.dev/modules/validation"
|
||||||
"gitea.dev/modules/web/middleware"
|
"gitea.dev/modules/web/middleware"
|
||||||
"gitea.dev/services/context"
|
|
||||||
|
|
||||||
"gitea.com/go-chi/binding"
|
"gitea.com/go-chi/binding"
|
||||||
)
|
)
|
||||||
|
|
||||||
// InstallForm form for installation page
|
// InstallForm form for installation page
|
||||||
type InstallForm struct {
|
type InstallForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
DbType string `binding:"Required"`
|
DbType string `binding:"Required"`
|
||||||
DbHost string
|
DbHost string
|
||||||
DbUser string
|
DbUser string
|
||||||
@@ -74,12 +73,6 @@ type InstallForm struct {
|
|||||||
ReinstallConfirmThird bool
|
ReinstallConfirmThird bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *InstallForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// _____ ____ _________________ ___
|
// _____ ____ _________________ ___
|
||||||
// / _ \ | | \__ ___/ | \
|
// / _ \ | | \__ ___/ | \
|
||||||
// / /_\ \| | / | | / ~ \
|
// / /_\ \| | / | | / ~ \
|
||||||
@@ -89,18 +82,13 @@ func (f *InstallForm) Validate(req *http.Request, errs binding.Errors) binding.E
|
|||||||
|
|
||||||
// RegisterForm form for registering
|
// RegisterForm form for registering
|
||||||
type RegisterForm struct {
|
type RegisterForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
UserName string `binding:"Required;Username;MaxSize(40)"`
|
UserName string `binding:"Required;Username;MaxSize(40)"`
|
||||||
Email string `binding:"Required;MaxSize(254)"`
|
Email string `binding:"Required;MaxSize(254)"`
|
||||||
Password string `binding:"MaxSize(255)"`
|
Password string `binding:"MaxSize(255)"`
|
||||||
Retype string
|
Retype string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *RegisterForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsEmailDomainAllowed validates that the email address
|
// IsEmailDomainAllowed validates that the email address
|
||||||
// provided by the user matches what has been configured .
|
// provided by the user matches what has been configured .
|
||||||
// The email is marked as allowed if it matches any of the
|
// The email is marked as allowed if it matches any of the
|
||||||
@@ -113,34 +101,25 @@ func (f *RegisterForm) IsEmailDomainAllowed() bool {
|
|||||||
// MustChangePasswordForm form for updating your password after account creation
|
// MustChangePasswordForm form for updating your password after account creation
|
||||||
// by an admin
|
// by an admin
|
||||||
type MustChangePasswordForm struct {
|
type MustChangePasswordForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Password string `binding:"Required;MaxSize(255)"`
|
Password string `binding:"Required;MaxSize(255)"`
|
||||||
Retype string
|
Retype string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *MustChangePasswordForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SignInForm form for signing in with user/password
|
// SignInForm form for signing in with user/password
|
||||||
type SignInForm struct {
|
type SignInForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
UserName string `binding:"Required;MaxSize(254)"`
|
UserName string `binding:"Required;MaxSize(254)"`
|
||||||
// TODO remove required from password for SecondFactorAuthentication
|
// TODO remove required from password for SecondFactorAuthentication
|
||||||
Password string `binding:"Required;MaxSize(255)"`
|
Password string `binding:"Required;MaxSize(255)"`
|
||||||
Remember bool
|
Remember bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *SignInForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// AuthorizationForm form for authorizing oauth2 clients
|
// AuthorizationForm form for authorizing oauth2 clients
|
||||||
type AuthorizationForm struct {
|
type AuthorizationForm struct {
|
||||||
ResponseType string `binding:"Required;In(code)"`
|
middleware.FormDefaultValidator
|
||||||
ClientID string `binding:"Required"`
|
ResponseType string
|
||||||
|
ClientID string
|
||||||
RedirectURI string
|
RedirectURI string
|
||||||
State string
|
State string
|
||||||
Scope string
|
Scope string
|
||||||
@@ -151,14 +130,9 @@ type AuthorizationForm struct {
|
|||||||
CodeChallenge string
|
CodeChallenge string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *AuthorizationForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GrantApplicationForm form for authorizing oauth2 clients
|
// GrantApplicationForm form for authorizing oauth2 clients
|
||||||
type GrantApplicationForm struct {
|
type GrantApplicationForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
ClientID string `binding:"Required"`
|
ClientID string `binding:"Required"`
|
||||||
Granted bool
|
Granted bool
|
||||||
RedirectURI string
|
RedirectURI string
|
||||||
@@ -167,14 +141,9 @@ type GrantApplicationForm struct {
|
|||||||
Nonce string
|
Nonce string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *GrantApplicationForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// AccessTokenForm for issuing access tokens from authorization codes or refresh tokens
|
// AccessTokenForm for issuing access tokens from authorization codes or refresh tokens
|
||||||
type AccessTokenForm struct {
|
type AccessTokenForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
GrantType string `json:"grant_type"`
|
GrantType string `json:"grant_type"`
|
||||||
ClientID string `json:"client_id"`
|
ClientID string `json:"client_id"`
|
||||||
ClientSecret string `json:"client_secret"`
|
ClientSecret string `json:"client_secret"`
|
||||||
@@ -186,23 +155,12 @@ type AccessTokenForm struct {
|
|||||||
CodeVerifier string `json:"code_verifier"`
|
CodeVerifier string `json:"code_verifier"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *AccessTokenForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// IntrospectTokenForm for introspecting tokens
|
// IntrospectTokenForm for introspecting tokens
|
||||||
type IntrospectTokenForm struct {
|
type IntrospectTokenForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *IntrospectTokenForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// __________________________________________.___ _______ ________ _________
|
// __________________________________________.___ _______ ________ _________
|
||||||
// / _____/\_ _____/\__ ___/\__ ___/| |\ \ / _____/ / _____/
|
// / _____/\_ _____/\__ ___/\__ ___/| |\ \ / _____/ / _____/
|
||||||
// \_____ \ | __)_ | | | | | |/ | \/ \ ___ \_____ \
|
// \_____ \ | __)_ | | | | | |/ | \/ \ ___ \_____ \
|
||||||
@@ -212,6 +170,7 @@ func (f *IntrospectTokenForm) Validate(req *http.Request, errs binding.Errors) b
|
|||||||
|
|
||||||
// UpdateProfileForm form for updating profile
|
// UpdateProfileForm form for updating profile
|
||||||
type UpdateProfileForm struct {
|
type UpdateProfileForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Name string `binding:"Username;MaxSize(40)"`
|
Name string `binding:"Username;MaxSize(40)"`
|
||||||
FullName string `binding:"MaxSize(100)"`
|
FullName string `binding:"MaxSize(100)"`
|
||||||
KeepEmailPrivate bool
|
KeepEmailPrivate bool
|
||||||
@@ -222,86 +181,51 @@ type UpdateProfileForm struct {
|
|||||||
KeepActivityPrivate bool
|
KeepActivityPrivate bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *UpdateProfileForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateLanguageForm form for updating profile
|
// UpdateLanguageForm form for updating profile
|
||||||
type UpdateLanguageForm struct {
|
type UpdateLanguageForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Language string
|
Language string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *UpdateLanguageForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
const AvatarLocal = "local" // the AvatarForm.Source value that selects an uploaded avatar
|
const AvatarLocal = "local" // the AvatarForm.Source value that selects an uploaded avatar
|
||||||
|
|
||||||
// AvatarForm form for changing avatar
|
// AvatarForm form for changing avatar
|
||||||
type AvatarForm struct {
|
type AvatarForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Source string
|
Source string
|
||||||
Avatar *multipart.FileHeader
|
Avatar *multipart.FileHeader
|
||||||
Gravatar string `binding:"OmitEmpty;Email;MaxSize(254)"`
|
Gravatar string `binding:"OmitEmpty;Email;MaxSize(254)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *AvatarForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddEmailForm form for adding new email
|
// AddEmailForm form for adding new email
|
||||||
type AddEmailForm struct {
|
type AddEmailForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Email string `binding:"Required;Email;MaxSize(254)"`
|
Email string `binding:"Required;Email;MaxSize(254)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *AddEmailForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateThemeForm form for updating a users' theme
|
// UpdateThemeForm form for updating a users' theme
|
||||||
type UpdateThemeForm struct {
|
type UpdateThemeForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Theme string `binding:"Required;MaxSize(255)"`
|
Theme string `binding:"Required;MaxSize(255)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the field
|
|
||||||
func (f *UpdateThemeForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ChangePasswordForm form for changing password
|
// ChangePasswordForm form for changing password
|
||||||
type ChangePasswordForm struct {
|
type ChangePasswordForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
OldPassword string `form:"old_password" binding:"MaxSize(255)"`
|
OldPassword string `form:"old_password" binding:"MaxSize(255)"`
|
||||||
Password string `form:"password" binding:"Required;MaxSize(255)"`
|
Password string `form:"password" binding:"Required;MaxSize(255)"`
|
||||||
Retype string `form:"retype"`
|
Retype string `form:"retype"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *ChangePasswordForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddOpenIDForm is for changing openid uri
|
// AddOpenIDForm is for changing openid uri
|
||||||
type AddOpenIDForm struct {
|
type AddOpenIDForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Openid string `binding:"Required;MaxSize(256)"`
|
Openid string `binding:"Required;MaxSize(256)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *AddOpenIDForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddKeyForm form for adding SSH/GPG key
|
// AddKeyForm form for adding SSH/GPG key
|
||||||
type AddKeyForm struct {
|
type AddKeyForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Type string `binding:"OmitEmpty"`
|
Type string `binding:"OmitEmpty"`
|
||||||
Title string `binding:"Required;MaxSize(50)"`
|
Title string `binding:"Required;MaxSize(50)"`
|
||||||
Content string `binding:"Required"`
|
Content string `binding:"Required"`
|
||||||
@@ -311,47 +235,27 @@ type AddKeyForm struct {
|
|||||||
IsWritable bool
|
IsWritable bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *AddKeyForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddSecretForm for adding secrets
|
// AddSecretForm for adding secrets
|
||||||
type AddSecretForm struct {
|
type AddSecretForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Name string `binding:"Required;MaxSize(255)"`
|
Name string `binding:"Required;MaxSize(255)"`
|
||||||
Data string `binding:"Required;MaxSize(65535)"`
|
Data string `binding:"Required;MaxSize(65535)"`
|
||||||
Description string `binding:"MaxSize(65535)"`
|
Description string `binding:"MaxSize(65535)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *AddSecretForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
type EditVariableForm struct {
|
type EditVariableForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Name string `binding:"Required;MaxSize(255)"`
|
Name string `binding:"Required;MaxSize(255)"`
|
||||||
Data string `binding:"Required;MaxSize(65535)"`
|
Data string `binding:"Required;MaxSize(65535)"`
|
||||||
Description string `binding:"MaxSize(65535)"`
|
Description string `binding:"MaxSize(65535)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *EditVariableForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewAccessTokenForm form for creating access token
|
// NewAccessTokenForm form for creating access token
|
||||||
type NewAccessTokenForm struct {
|
type NewAccessTokenForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Name string `binding:"Required;MaxSize(255)" locale:"settings.token_name"`
|
Name string `binding:"Required;MaxSize(255)" locale:"settings.token_name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *NewAccessTokenForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// EditOAuth2ApplicationForm form for editing oauth2 applications
|
// EditOAuth2ApplicationForm form for editing oauth2 applications
|
||||||
type EditOAuth2ApplicationForm struct {
|
type EditOAuth2ApplicationForm struct {
|
||||||
Name string `binding:"Required;MaxSize(255)" form:"application_name"`
|
Name string `binding:"Required;MaxSize(255)" form:"application_name"`
|
||||||
@@ -371,68 +275,42 @@ func DetectInvalidOAuth2ApplicationRedirectURI(uris []string) (invalidURL string
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
func (f *EditOAuth2ApplicationForm) Validate(ctx *middleware.ValidateContext, errs binding.Errors) binding.Errors {
|
||||||
func (f *EditOAuth2ApplicationForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
invalidURI := DetectInvalidOAuth2ApplicationRedirectURI(util.SplitTrimSpace(f.RedirectURIs, "\n"))
|
invalidURI := DetectInvalidOAuth2ApplicationRedirectURI(util.SplitTrimSpace(f.RedirectURIs, "\n"))
|
||||||
if invalidURI != "" {
|
if invalidURI != "" {
|
||||||
errs = middleware.AddValidationError(errs, "RedirectURIs", "RedirectURIs: "+ctx.Locale.TrString("form.url_error", `"`+invalidURI+`"`))
|
errs = middleware.AddValidationError(errs, "RedirectURIs", "RedirectURIs: "+ctx.Locale.TrString("form.url_error", `"`+invalidURI+`"`))
|
||||||
}
|
}
|
||||||
return middleware.Validate(ctx, errs, f)
|
return errs
|
||||||
}
|
}
|
||||||
|
|
||||||
// TwoFactorAuthForm for logging in with 2FA token.
|
// TwoFactorAuthForm for logging in with 2FA token.
|
||||||
type TwoFactorAuthForm struct {
|
type TwoFactorAuthForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Passcode string `binding:"Required"`
|
Passcode string `binding:"Required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *TwoFactorAuthForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TwoFactorScratchAuthForm for logging in with 2FA scratch token.
|
// TwoFactorScratchAuthForm for logging in with 2FA scratch token.
|
||||||
type TwoFactorScratchAuthForm struct {
|
type TwoFactorScratchAuthForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Token string `binding:"Required"`
|
Token string `binding:"Required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *TwoFactorScratchAuthForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// WebauthnRegistrationForm for reserving an WebAuthn name
|
// WebauthnRegistrationForm for reserving an WebAuthn name
|
||||||
type WebauthnRegistrationForm struct {
|
type WebauthnRegistrationForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Name string `binding:"Required"`
|
Name string `binding:"Required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *WebauthnRegistrationForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// PackageSettingForm form for package settings
|
// PackageSettingForm form for package settings
|
||||||
type PackageSettingForm struct {
|
type PackageSettingForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Action string
|
Action string
|
||||||
RepoName string `form:"repo_name"`
|
RepoName string `form:"repo_name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *PackageSettingForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
type BlockUserForm struct {
|
type BlockUserForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Action string `binding:"Required;In(block,unblock,note)"`
|
Action string `binding:"Required;In(block,unblock,note)"`
|
||||||
Blockee string `binding:"Required"`
|
Blockee string `binding:"Required"`
|
||||||
Note string
|
Note string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *BlockUserForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,47 +3,25 @@
|
|||||||
|
|
||||||
package forms
|
package forms
|
||||||
|
|
||||||
import (
|
import "gitea.dev/modules/web/middleware"
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"gitea.dev/modules/web/middleware"
|
|
||||||
"gitea.dev/services/context"
|
|
||||||
|
|
||||||
"gitea.com/go-chi/binding"
|
|
||||||
)
|
|
||||||
|
|
||||||
// SignInOpenIDForm form for signing in with OpenID
|
// SignInOpenIDForm form for signing in with OpenID
|
||||||
type SignInOpenIDForm struct {
|
type SignInOpenIDForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
Openid string `binding:"Required;MaxSize(256)"`
|
Openid string `binding:"Required;MaxSize(256)"`
|
||||||
Remember bool
|
Remember bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *SignInOpenIDForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SignUpOpenIDForm form for signin up with OpenID
|
// SignUpOpenIDForm form for signin up with OpenID
|
||||||
type SignUpOpenIDForm struct {
|
type SignUpOpenIDForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
UserName string `binding:"Required;Username;MaxSize(40)"`
|
UserName string `binding:"Required;Username;MaxSize(40)"`
|
||||||
Email string `binding:"Required;Email;MaxSize(254)"`
|
Email string `binding:"Required;Email;MaxSize(254)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *SignUpOpenIDForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ConnectOpenIDForm form for connecting an existing account to an OpenID URI
|
// ConnectOpenIDForm form for connecting an existing account to an OpenID URI
|
||||||
type ConnectOpenIDForm struct {
|
type ConnectOpenIDForm struct {
|
||||||
|
middleware.FormDefaultValidator
|
||||||
UserName string `binding:"Required;MaxSize(254)"`
|
UserName string `binding:"Required;MaxSize(254)"`
|
||||||
Password string `binding:"Required;MaxSize(255)"`
|
Password string `binding:"Required;MaxSize(255)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *ConnectOpenIDForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(ctx, errs, f)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ func testLDAPAuthChange(t *testing.T) {
|
|||||||
bindDN, _ := doc.Find(`input[name="bind_dn"]`).Attr("value")
|
bindDN, _ := doc.Find(`input[name="bind_dn"]`).Attr("value")
|
||||||
assert.Equal(t, "uid=gitea,ou=service,dc=planetexpress,dc=com", bindDN)
|
assert.Equal(t, "uid=gitea,ou=service,dc=planetexpress,dc=com", bindDN)
|
||||||
|
|
||||||
req = NewRequestWithValues(t, "POST", hrefAuthSource, te.buildAuthSourcePayload(map[string]string{"group_team_map_removal": "off"}))
|
req = NewRequestWithValues(t, "POST", hrefAuthSource, te.buildAuthSourcePayload(map[string]string{"group_team_map_removal": ""}))
|
||||||
session.MakeRequest(t, req, http.StatusSeeOther)
|
session.MakeRequest(t, req, http.StatusSeeOther)
|
||||||
|
|
||||||
req = NewRequest(t, "GET", hrefAuthSource)
|
req = NewRequest(t, "GET", hrefAuthSource)
|
||||||
@@ -492,7 +492,7 @@ func testLDAPPreventInvalidGroupTeamMap(t *testing.T) {
|
|||||||
te := prepareLdapTestServerEnv()
|
te := prepareLdapTestServerEnv()
|
||||||
|
|
||||||
session := loginUser(t, "user1")
|
session := loginUser(t, "user1")
|
||||||
payload := te.buildAuthSourcePayload(map[string]string{"group_team_map": `{"NOT_A_VALID_JSON"["MISSING_DOUBLE_POINT"]}`, "group_team_map_removal": "off"})
|
payload := te.buildAuthSourcePayload(map[string]string{"group_team_map": `{"NOT_A_VALID_JSON"["MISSING_DOUBLE_POINT"]}`, "group_team_map_removal": ""})
|
||||||
req := NewRequestWithValues(t, "POST", "/-/admin/auths/new", payload)
|
req := NewRequestWithValues(t, "POST", "/-/admin/auths/new", payload)
|
||||||
session.MakeRequest(t, req, http.StatusOK) // StatusOK = failed, StatusSeeOther = ok
|
session.MakeRequest(t, req, http.StatusOK) // StatusOK = failed, StatusSeeOther = ok
|
||||||
}
|
}
|
||||||
@@ -509,7 +509,6 @@ func testLDAPEmailSignin(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
serverHost: "mock-host",
|
serverHost: "mock-host",
|
||||||
serverPort: "mock-port",
|
|
||||||
}
|
}
|
||||||
defer test.MockVariableValue(&ldap.MockedSearchEntry, func(source *ldap.Source, name, passwd string, directBind bool) *ldap.SearchResult {
|
defer test.MockVariableValue(&ldap.MockedSearchEntry, func(source *ldap.Source, name, passwd string, directBind bool) *ldap.SearchResult {
|
||||||
var u *ldapUser
|
var u *ldapUser
|
||||||
|
|||||||
Reference in New Issue
Block a user