mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-13 17:51:17 +00:00
chore: enable forcetypeassert linter, fix issues (#38804)
Enable [`forcetypeassert`](https://github.com/gostaticanalysis/forcetypeassert) linter to prevent unchecked type assertions. ~650 issues fixed, most fixes were clean, some use `setting.PanicInDevOrTesting`. The only behaviour changes are where code would previously send a 500 error or panic, a 4xx error is now emitted. Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -153,7 +153,7 @@ func SystemStatus(ctx *context.Context) {
|
||||
|
||||
// DashboardPost run an admin operation
|
||||
func DashboardPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.AdminDashboardForm)
|
||||
form := web.GetForm[*forms.AdminDashboardForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("admin.dashboard")
|
||||
ctx.Data["PageIsAdminDashboard"] = true
|
||||
updateSystemStatus()
|
||||
|
||||
+14
-18
@@ -235,7 +235,7 @@ func parseSSPIConfig(ctx *context.Context, form forms.AuthenticationForm) (*sspi
|
||||
|
||||
// NewAuthSourcePost response for adding an auth source
|
||||
func NewAuthSourcePost(ctx *context.Context) {
|
||||
form := *web.GetForm(ctx).(*forms.AuthenticationForm)
|
||||
form := *web.GetForm[*forms.AuthenticationForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("admin.auths.new")
|
||||
ctx.Data["PageIsAdminAuthentications"] = true
|
||||
|
||||
@@ -268,8 +268,8 @@ func NewAuthSourcePost(ctx *context.Context) {
|
||||
EmailDomain: form.PAMEmailDomain,
|
||||
}
|
||||
case auth.OAuth2:
|
||||
config = parseOAuth2Config(form)
|
||||
oauth2Config := config.(*oauth2.Source)
|
||||
oauth2Config := parseOAuth2Config(form)
|
||||
config = oauth2Config
|
||||
if oauth2Config.Provider == "openidConnect" {
|
||||
discoveryURL, err := url.Parse(oauth2Config.OpenIDConnectAutoDiscoveryURL)
|
||||
if err != nil || (discoveryURL.Scheme != "http" && discoveryURL.Scheme != "https") {
|
||||
@@ -310,13 +310,12 @@ func NewAuthSourcePost(ctx *context.Context) {
|
||||
TwoFactorPolicy: form.TwoFactorPolicy,
|
||||
Cfg: config,
|
||||
}); err != nil {
|
||||
if auth.IsErrSourceAlreadyExist(err) {
|
||||
if errExist, ok := errors.AsType[auth.ErrSourceAlreadyExist](err); ok {
|
||||
ctx.Data["Err_Name"] = true
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("admin.auths.login_source_exist", err.(auth.ErrSourceAlreadyExist).Name), tplAuthNew, form)
|
||||
} else if oauth2.IsErrOpenIDConnectInitialize(err) {
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("admin.auths.login_source_exist", errExist.Name), tplAuthNew, form)
|
||||
} else if errInit, ok := err.(oauth2.ErrOpenIDConnectInitialize); ok {
|
||||
ctx.Data["Err_DiscoveryURL"] = true
|
||||
unwrapped := err.(oauth2.ErrOpenIDConnectInitialize).Unwrap()
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("admin.auths.unable_to_initialize_openid", unwrapped), tplAuthNew, form)
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("admin.auths.unable_to_initialize_openid", errInit.Unwrap()), tplAuthNew, form)
|
||||
} else {
|
||||
ctx.ServerError("auth.CreateSource", err)
|
||||
}
|
||||
@@ -348,12 +347,9 @@ func EditAuthSource(ctx *context.Context) {
|
||||
ctx.Data["HasTLS"] = source.HasTLS()
|
||||
|
||||
if source.IsOAuth2() {
|
||||
type Named interface {
|
||||
Name() string
|
||||
}
|
||||
|
||||
oauth2Source := auth.MustSourceCfg[*oauth2.Source](source)
|
||||
for _, provider := range oauth2providers {
|
||||
if provider.Name() == source.Cfg.(Named).Name() {
|
||||
if provider.Name() == oauth2Source.Name() {
|
||||
ctx.Data["CurrentOAuth2Provider"] = provider
|
||||
break
|
||||
}
|
||||
@@ -365,7 +361,7 @@ func EditAuthSource(ctx *context.Context) {
|
||||
|
||||
// EditAuthSourcePost response for editing auth source
|
||||
func EditAuthSourcePost(ctx *context.Context) {
|
||||
form := *web.GetForm(ctx).(*forms.AuthenticationForm)
|
||||
form := *web.GetForm[*forms.AuthenticationForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("admin.auths.edit")
|
||||
ctx.Data["PageIsAdminAuthentications"] = true
|
||||
|
||||
@@ -398,8 +394,8 @@ func EditAuthSourcePost(ctx *context.Context) {
|
||||
EmailDomain: form.PAMEmailDomain,
|
||||
}
|
||||
case auth.OAuth2:
|
||||
config = parseOAuth2Config(form)
|
||||
oauth2Config := config.(*oauth2.Source)
|
||||
oauth2Config := parseOAuth2Config(form)
|
||||
config = oauth2Config
|
||||
if oauth2Config.Provider == "openidConnect" {
|
||||
discoveryURL, err := url.Parse(oauth2Config.OpenIDConnectAutoDiscoveryURL)
|
||||
if err != nil || (discoveryURL.Scheme != "http" && discoveryURL.Scheme != "https") {
|
||||
@@ -425,9 +421,9 @@ func EditAuthSourcePost(ctx *context.Context) {
|
||||
source.Cfg = config
|
||||
source.TwoFactorPolicy = form.TwoFactorPolicy
|
||||
if err := auth.UpdateSource(ctx, source); err != nil {
|
||||
if auth.IsErrSourceAlreadyExist(err) {
|
||||
if errExist, ok := errors.AsType[auth.ErrSourceAlreadyExist](err); ok {
|
||||
ctx.Data["Err_Name"] = true
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("admin.auths.login_source_exist", err.(auth.ErrSourceAlreadyExist).Name), tplAuthEdit, form)
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("admin.auths.login_source_exist", errExist.Name), tplAuthEdit, form)
|
||||
} else if oauth2.IsErrOpenIDConnectInitialize(err) {
|
||||
ctx.Flash.Error(err.Error(), true)
|
||||
ctx.Data["Err_DiscoveryURL"] = true
|
||||
|
||||
@@ -54,7 +54,7 @@ func NewBadge(ctx *context.Context) {
|
||||
|
||||
// NewBadgePost response for adding a new badge
|
||||
func NewBadgePost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.AdminCreateBadgeForm)
|
||||
form := web.GetForm[*forms.AdminCreateBadgeForm](ctx)
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.JSONError(ctx.GetErrMsg())
|
||||
@@ -100,12 +100,11 @@ func ViewBadge(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("admin.badges.details")
|
||||
ctx.Data["PageIsAdminBadges"] = true
|
||||
|
||||
prepareBadgeInfo(ctx)
|
||||
badge := prepareBadgeInfo(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
badge := ctx.Data["Badge"].(*user_model.Badge)
|
||||
opts := &user_model.GetBadgeUsersOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
Page: 1,
|
||||
@@ -143,7 +142,7 @@ func EditBadgePost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.AdminEditBadgeForm)
|
||||
form := web.GetForm[*forms.AdminEditBadgeForm](ctx)
|
||||
if ctx.HasError() {
|
||||
ctx.JSONError(ctx.GetErrMsg())
|
||||
return
|
||||
|
||||
@@ -103,7 +103,7 @@ func NewUser(ctx *context.Context) {
|
||||
|
||||
// NewUserPost response for adding a new user
|
||||
func NewUserPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.AdminCreateUserForm)
|
||||
form := web.GetForm[*forms.AdminCreateUserForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("admin.users.new_account")
|
||||
ctx.Data["PageIsAdminUsers"] = true
|
||||
ctx.Data["DefaultUserVisibilityMode"] = setting.Service.DefaultUserVisibilityMode
|
||||
@@ -171,6 +171,9 @@ func NewUserPost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
if err := user_model.AdminCreateUser(ctx, u, &user_model.Meta{}, overwriteDefault); err != nil {
|
||||
var errNameReserved db.ErrNameReserved
|
||||
var errNamePatternNotAllowed db.ErrNamePatternNotAllowed
|
||||
var errNameCharsNotAllowed db.ErrNameCharsNotAllowed
|
||||
switch {
|
||||
case user_model.IsErrUserAlreadyExist(err):
|
||||
ctx.Data["Err_UserName"] = true
|
||||
@@ -181,15 +184,15 @@ func NewUserPost(ctx *context.Context) {
|
||||
case user_model.IsErrEmailInvalid(err), user_model.IsErrEmailCharIsNotSupported(err):
|
||||
ctx.Data["Err_Email"] = true
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("form.email_invalid"), tplUserNew, &form)
|
||||
case db.IsErrNameReserved(err):
|
||||
case errors.As(err, &errNameReserved):
|
||||
ctx.Data["Err_UserName"] = true
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("user.form.name_reserved", err.(db.ErrNameReserved).Name), tplUserNew, &form)
|
||||
case db.IsErrNamePatternNotAllowed(err):
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("user.form.name_reserved", errNameReserved.Name), tplUserNew, &form)
|
||||
case errors.As(err, &errNamePatternNotAllowed):
|
||||
ctx.Data["Err_UserName"] = true
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("user.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tplUserNew, &form)
|
||||
case db.IsErrNameCharsNotAllowed(err):
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("user.form.name_pattern_not_allowed", errNamePatternNotAllowed.Pattern), tplUserNew, &form)
|
||||
case errors.As(err, &errNameCharsNotAllowed):
|
||||
ctx.Data["Err_UserName"] = true
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("user.form.name_chars_not_allowed", err.(db.ErrNameCharsNotAllowed).Name), tplUserNew, &form)
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("user.form.name_chars_not_allowed", errNameCharsNotAllowed.Name), tplUserNew, &form)
|
||||
default:
|
||||
ctx.ServerError("CreateUser", err)
|
||||
}
|
||||
@@ -336,7 +339,7 @@ func EditUserPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.AdminEditUserForm)
|
||||
form := web.GetForm[*forms.AdminEditUserForm](ctx)
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(http.StatusOK, tplUserEdit)
|
||||
return
|
||||
@@ -522,7 +525,7 @@ func AvatarPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.AvatarForm)
|
||||
form := web.GetForm[*forms.AvatarForm](ctx)
|
||||
if err := user_setting.UpdateAvatarSetting(ctx, form, u); err != nil {
|
||||
ctx.Flash.Error(err.Error())
|
||||
} else {
|
||||
|
||||
+8
-10
@@ -41,17 +41,16 @@ func TwoFactor(ctx *context.Context) {
|
||||
|
||||
// TwoFactorPost validates a user's two-factor authentication token.
|
||||
func TwoFactorPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.TwoFactorAuthForm)
|
||||
form := web.GetForm[*forms.TwoFactorAuthForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("twofa")
|
||||
|
||||
// Ensure user is in a 2FA session.
|
||||
idSess := ctx.Session.Get("twofaUid")
|
||||
if idSess == nil {
|
||||
id, hasSession := ctx.Session.Get("twofaUid").(int64)
|
||||
if !hasSession {
|
||||
ctx.ServerError("UserSignIn", errors.New("not in 2FA session"))
|
||||
return
|
||||
}
|
||||
|
||||
id := idSess.(int64)
|
||||
twofa, err := auth.GetTwoFactorByUID(ctx, id)
|
||||
if err != nil {
|
||||
ctx.ServerError("UserSignIn", err)
|
||||
@@ -66,7 +65,7 @@ func TwoFactorPost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
if ok {
|
||||
remember := ctx.Session.Get("twofaRemember").(bool)
|
||||
remember := ctx.Session.Get("twofaRemember").(bool) //nolint:forcetypeassert // must exist
|
||||
u, err := user_model.GetUserByID(ctx, id)
|
||||
if err != nil {
|
||||
ctx.ServerError("UserSignIn", err)
|
||||
@@ -105,17 +104,16 @@ func TwoFactorScratch(ctx *context.Context) {
|
||||
|
||||
// TwoFactorScratchPost validates and invalidates a user's two-factor scratch token.
|
||||
func TwoFactorScratchPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.TwoFactorScratchAuthForm)
|
||||
form := web.GetForm[*forms.TwoFactorScratchAuthForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("twofa_scratch")
|
||||
|
||||
// Ensure user is in a 2FA session.
|
||||
idSess := ctx.Session.Get("twofaUid")
|
||||
if idSess == nil {
|
||||
id, hasSession := ctx.Session.Get("twofaUid").(int64)
|
||||
if !hasSession {
|
||||
ctx.ServerError("UserSignIn", errors.New("not in 2FA session"))
|
||||
return
|
||||
}
|
||||
|
||||
id := idSess.(int64)
|
||||
twofa, err := auth.GetTwoFactorByUID(ctx, id)
|
||||
if err != nil {
|
||||
ctx.ServerError("UserSignIn", err)
|
||||
@@ -135,7 +133,7 @@ func TwoFactorScratchPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
remember := ctx.Session.Get("twofaRemember").(bool)
|
||||
remember := ctx.Session.Get("twofaRemember").(bool) //nolint:forcetypeassert // must exist
|
||||
u, err := user_model.GetUserByID(ctx, id)
|
||||
if err != nil {
|
||||
ctx.ServerError("UserSignIn", err)
|
||||
|
||||
@@ -293,7 +293,7 @@ func SignInPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.SignInForm)
|
||||
form := web.GetForm[*forms.SignInForm](ctx)
|
||||
|
||||
if setting.Service.EnableCaptcha && setting.Service.RequireCaptchaForLogin {
|
||||
context.VerifyCaptcha(ctx, tplSignIn, form)
|
||||
@@ -535,7 +535,7 @@ func SignUpPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.RegisterForm)
|
||||
form := web.GetForm[*forms.RegisterForm](ctx)
|
||||
|
||||
// Permission denied if DisableRegistration or AllowOnlyExternalRegistration options are true
|
||||
if setting.Service.DisableRegistration || setting.Service.AllowOnlyExternalRegistration {
|
||||
@@ -651,6 +651,9 @@ func createUserInContext(ctx *context.Context, tpl templates.TplName, form any,
|
||||
}
|
||||
|
||||
// handle error with template
|
||||
var errNameReserved db.ErrNameReserved
|
||||
var errNamePatternNotAllowed db.ErrNamePatternNotAllowed
|
||||
var errNameCharsNotAllowed db.ErrNameCharsNotAllowed
|
||||
switch {
|
||||
case user_model.IsErrUserAlreadyExist(err):
|
||||
ctx.Data["Err_UserName"] = true
|
||||
@@ -664,15 +667,15 @@ func createUserInContext(ctx *context.Context, tpl templates.TplName, form any,
|
||||
case user_model.IsErrEmailInvalid(err):
|
||||
ctx.Data["Err_Email"] = true
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("form.email_invalid"), tpl, form)
|
||||
case db.IsErrNameReserved(err):
|
||||
case errors.As(err, &errNameReserved):
|
||||
ctx.Data["Err_UserName"] = true
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("user.form.name_reserved", err.(db.ErrNameReserved).Name), tpl, form)
|
||||
case db.IsErrNamePatternNotAllowed(err):
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("user.form.name_reserved", errNameReserved.Name), tpl, form)
|
||||
case errors.As(err, &errNamePatternNotAllowed):
|
||||
ctx.Data["Err_UserName"] = true
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("user.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tpl, form)
|
||||
case db.IsErrNameCharsNotAllowed(err):
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("user.form.name_pattern_not_allowed", errNamePatternNotAllowed.Pattern), tpl, form)
|
||||
case errors.As(err, &errNameCharsNotAllowed):
|
||||
ctx.Data["Err_UserName"] = true
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("user.form.name_chars_not_allowed", err.(db.ErrNameCharsNotAllowed).Name), tpl, form)
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("user.form.name_chars_not_allowed", errNameCharsNotAllowed.Name), tpl, form)
|
||||
default:
|
||||
ctx.ServerError("CreateUser", err)
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ func handleSignInError(ctx *context.Context, userName string, ptrForm any, tmpl
|
||||
|
||||
// LinkAccountPostSignIn handle the coupling of external account with another account using signIn
|
||||
func LinkAccountPostSignIn(ctx *context.Context) {
|
||||
signInForm := web.GetForm(ctx).(*forms.SignInForm)
|
||||
signInForm := web.GetForm[*forms.SignInForm](ctx)
|
||||
|
||||
ctx.Data["LinkAccountModeSignIn"] = true
|
||||
|
||||
@@ -176,7 +176,7 @@ func oauth2LinkAccount(ctx *context.Context, u *user_model.User, linkAccountData
|
||||
|
||||
// LinkAccountPostRegister handle the creation of a new account for an external account using signUp
|
||||
func LinkAccountPostRegister(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.RegisterForm)
|
||||
form := web.GetForm[*forms.RegisterForm](ctx)
|
||||
|
||||
ctx.Data["LinkAccountModeRegister"] = true
|
||||
|
||||
@@ -253,7 +253,7 @@ func LinkAccountPostRegister(ctx *context.Context) {
|
||||
ctx.ServerError("GetSourceByID", err)
|
||||
return
|
||||
}
|
||||
source := authSource.Cfg.(*oauth2.Source)
|
||||
source := auth.MustSourceCfg[*oauth2.Source](authSource)
|
||||
if err := syncGroupsToTeams(ctx, source, &linkAccountData.GothUser, u); err != nil {
|
||||
ctx.ServerError("SyncGroupsToTeams", err)
|
||||
return
|
||||
|
||||
@@ -56,13 +56,15 @@ func SignInOAuth(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err = authSource.Cfg.(*oauth2.Source).Callout(ctx.Req, ctx.Resp); err != nil {
|
||||
oauth2Source := auth.MustSourceCfg[*oauth2.Source](authSource)
|
||||
|
||||
if err = oauth2Source.Callout(ctx.Req, ctx.Resp); err != nil {
|
||||
if strings.Contains(err.Error(), "no provider for ") {
|
||||
if err = oauth2.ResetOAuth2(ctx); err != nil {
|
||||
ctx.ServerError("SignIn", err)
|
||||
return
|
||||
}
|
||||
if err = authSource.Cfg.(*oauth2.Source).Callout(ctx.Req, ctx.Resp); err != nil {
|
||||
if err = oauth2Source.Callout(ctx.Req, ctx.Resp); err != nil {
|
||||
ctx.ServerError("SignIn", err)
|
||||
}
|
||||
return
|
||||
@@ -100,8 +102,7 @@ func SignInOAuthCallback(ctx *context.Context) {
|
||||
|
||||
u, gothUser, err := oAuth2UserLoginCallback(ctx, authSource, ctx.Req, ctx.Resp)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserProhibitLogin(err) {
|
||||
uplerr := err.(user_model.ErrUserProhibitLogin)
|
||||
if uplerr, ok := err.(user_model.ErrUserProhibitLogin); ok {
|
||||
log.Info("Failed authentication attempt for %s from %s: %v", uplerr.Name, ctx.RemoteAddr(), err)
|
||||
ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
|
||||
ctx.HTML(http.StatusOK, "user/auth/prohibit_login")
|
||||
@@ -188,7 +189,7 @@ func SignInOAuthCallback(ctx *context.Context) {
|
||||
IsActive: optional.Some(!setting.OAuth2Client.RegisterEmailConfirm && !setting.Service.RegisterManualConfirm),
|
||||
}
|
||||
|
||||
source := authSource.Cfg.(*oauth2.Source)
|
||||
source := auth.MustSourceCfg[*oauth2.Source](authSource)
|
||||
|
||||
linkAccountData := &LinkAccountData{authSource.ID, gothUser}
|
||||
if setting.OAuth2Client.AccountLinking == setting.OAuth2AccountLinkingDisabled {
|
||||
@@ -368,7 +369,8 @@ func handleOAuth2SignIn(ctx *context.Context, authSource *auth.Source, u *user_m
|
||||
}
|
||||
}
|
||||
|
||||
oauth2Source := authSource.Cfg.(*oauth2.Source)
|
||||
oauth2Source := auth.MustSourceCfg[*oauth2.Source](authSource)
|
||||
|
||||
groupTeamMapping, err := auth_module.UnmarshalGroupTeamMapping(oauth2Source.GroupTeamMap)
|
||||
if err != nil {
|
||||
ctx.ServerError("UnmarshalGroupTeamMapping", err)
|
||||
@@ -458,7 +460,7 @@ func handleOAuth2SignIn(ctx *context.Context, authSource *auth.Source, u *user_m
|
||||
// OAuth2UserLoginCallback attempts to handle the callback from the OAuth2 provider and if successful
|
||||
// login the user
|
||||
func oAuth2UserLoginCallback(ctx *context.Context, authSource *auth.Source, request *http.Request, response http.ResponseWriter) (*user_model.User, goth.User, error) {
|
||||
oauth2Source := authSource.Cfg.(*oauth2.Source)
|
||||
oauth2Source := auth.MustSourceCfg[*oauth2.Source](authSource)
|
||||
|
||||
// Make sure that the response is not an error response.
|
||||
errorName := request.FormValue("error")
|
||||
|
||||
@@ -172,7 +172,7 @@ func IntrospectOAuth(ctx *context.Context) {
|
||||
jwt.RegisteredClaims
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.IntrospectTokenForm)
|
||||
form := web.GetForm[*forms.IntrospectTokenForm](ctx)
|
||||
token, err := oauth2_provider.ParseToken(form.Token, oauth2_provider.DefaultSigningKey)
|
||||
if err != nil {
|
||||
// RFC 7662 returns inactive token metadata for invalid/unknown tokens.
|
||||
@@ -221,7 +221,7 @@ func oauthDoerAuthorizePreCheck(ctx *context.Context, formState string) bool {
|
||||
|
||||
// AuthorizeOAuth manages authorize requests
|
||||
func AuthorizeOAuth(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.AuthorizationForm)
|
||||
form := web.GetForm[*forms.AuthorizationForm](ctx)
|
||||
if !oauthDoerAuthorizePreCheck(ctx, form.State) {
|
||||
return
|
||||
}
|
||||
@@ -399,7 +399,7 @@ func AuthorizeOAuth(ctx *context.Context) {
|
||||
|
||||
// GrantApplicationOAuth manages the post request submitted when a user grants access to an application
|
||||
func GrantApplicationOAuth(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.GrantApplicationForm)
|
||||
form := web.GetForm[*forms.GrantApplicationForm](ctx)
|
||||
if !oauthDoerAuthorizePreCheck(ctx, form.State) {
|
||||
return
|
||||
}
|
||||
@@ -498,7 +498,7 @@ func OIDCKeys(ctx *context.Context) {
|
||||
|
||||
// AccessTokenOAuth manages all access token requests by the client
|
||||
func AccessTokenOAuth(ctx *context.Context) {
|
||||
form := *web.GetForm(ctx).(*forms.AccessTokenForm)
|
||||
form := *web.GetForm[*forms.AccessTokenForm](ctx)
|
||||
// if there is no ClientID or ClientSecret in the request body, fill these fields by the Authorization header and ensure the provided field matches the Authorization header
|
||||
if form.ClientID == "" || form.ClientSecret == "" {
|
||||
if authHeader := ctx.Req.Header.Get("Authorization"); authHeader != "" {
|
||||
|
||||
@@ -101,7 +101,7 @@ func allowedOpenIDURI(uri string) (err error) {
|
||||
|
||||
// SignInOpenIDPost response for openid sign in request
|
||||
func SignInOpenIDPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.SignInOpenIDForm)
|
||||
form := web.GetForm[*forms.SignInOpenIDForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("sign_in")
|
||||
ctx.Data["PageIsSignIn"] = true
|
||||
ctx.Data["PageIsLoginOpenID"] = true
|
||||
@@ -293,7 +293,7 @@ func ConnectOpenID(ctx *context.Context) {
|
||||
|
||||
// ConnectOpenIDPost handles submission of a form to connect an OpenID URI to an existing account
|
||||
func ConnectOpenIDPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.ConnectOpenIDForm)
|
||||
form := web.GetForm[*forms.ConnectOpenIDForm](ctx)
|
||||
oid := prepareConnectOpenIDPageData(ctx)
|
||||
if oid == "" {
|
||||
return
|
||||
@@ -366,7 +366,7 @@ func RegisterOpenIDPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.SignUpOpenIDForm)
|
||||
form := web.GetForm[*forms.SignUpOpenIDForm](ctx)
|
||||
|
||||
if setting.Service.AllowOnlyInternalRegistration {
|
||||
ctx.HTTPError(http.StatusForbidden)
|
||||
|
||||
@@ -265,7 +265,7 @@ func MustChangePassword(ctx *context.Context) {
|
||||
// MustChangePasswordPost response for updating a user's password after their
|
||||
// account was created by an admin
|
||||
func MustChangePasswordPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.MustChangePasswordForm)
|
||||
form := web.GetForm[*forms.MustChangePasswordForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
|
||||
ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/settings/change_password"
|
||||
if ctx.HasError() {
|
||||
|
||||
@@ -31,12 +31,13 @@ func WebAuthn(ctx *context.Context) {
|
||||
}
|
||||
|
||||
// Ensure user is in a 2FA session.
|
||||
if ctx.Session.Get("twofaUid") == nil {
|
||||
idSess, ok := ctx.Session.Get("twofaUid").(int64)
|
||||
if !ok {
|
||||
ctx.ServerError("UserSignIn", errors.New("not in WebAuthn session"))
|
||||
return
|
||||
}
|
||||
|
||||
hasTwoFactor, err := auth.HasTwoFactorByUID(ctx, ctx.Session.Get("twofaUid").(int64))
|
||||
hasTwoFactor, err := auth.HasTwoFactorByUID(ctx, idSess)
|
||||
if err != nil {
|
||||
ctx.ServerError("HasTwoFactorByUID", err)
|
||||
return
|
||||
@@ -265,7 +266,7 @@ func WebAuthnLoginAssertionPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
remember := ctx.Session.Get("twofaRemember").(bool)
|
||||
remember := ctx.Session.Get("twofaRemember").(bool) //nolint:forcetypeassert // must exist
|
||||
handleSignInFull(ctx, user, remember)
|
||||
_ = ctx.Session.Delete("twofaUid")
|
||||
ctx.JSONRedirect(consumeAuthRedirectLink(ctx))
|
||||
|
||||
@@ -522,7 +522,7 @@ func fillViewRunResponseCurrentJob(ctx *context.Context, resp *actions.ViewRespo
|
||||
}
|
||||
}
|
||||
|
||||
req := web.GetForm(ctx).(*actions.ViewRequest)
|
||||
req := web.GetForm[*actions.ViewRequest](ctx)
|
||||
var mockLogOptions []generateMockStepsLogOptions
|
||||
resp.State.CurrentJob.Steps = append(resp.State.CurrentJob.Steps, &actions.ViewJobStep{
|
||||
Summary: "step 0 (mock slow)",
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
|
||||
// Markup render markup document to HTML
|
||||
func Markup(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*api.MarkupOption)
|
||||
form := web.GetForm[*api.MarkupOption](ctx)
|
||||
mode := util.Iif(form.Wiki, "wiki", form.Mode) //nolint:staticcheck // form.Wiki is deprecated
|
||||
common.RenderMarkup(ctx.Base, ctx.Repo, mode, form.Text, form.Context, form.FilePath)
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ func Create(ctx *context.Context) {
|
||||
|
||||
// CreatePost response for create organization
|
||||
func CreatePost(ctx *context.Context) {
|
||||
form := *web.GetForm(ctx).(*forms.CreateOrgForm)
|
||||
form := *web.GetForm[*forms.CreateOrgForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("new_org")
|
||||
|
||||
if !ctx.Doer.CanCreateOrganization() {
|
||||
@@ -63,13 +63,15 @@ func CreatePost(ctx *context.Context) {
|
||||
|
||||
if err := organization.CreateOrganization(ctx, org, ctx.Doer); err != nil {
|
||||
ctx.Data["Err_OrgName"] = true
|
||||
var errNameReserved db.ErrNameReserved
|
||||
var errNamePatternNotAllowed db.ErrNamePatternNotAllowed
|
||||
switch {
|
||||
case user_model.IsErrUserAlreadyExist(err):
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("form.org_name_been_taken"), tplCreateOrg, &form)
|
||||
case db.IsErrNameReserved(err):
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("org.form.name_reserved", err.(db.ErrNameReserved).Name), tplCreateOrg, &form)
|
||||
case db.IsErrNamePatternNotAllowed(err):
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("org.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tplCreateOrg, &form)
|
||||
case errors.As(err, &errNameReserved):
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("org.form.name_reserved", errNameReserved.Name), tplCreateOrg, &form)
|
||||
case errors.As(err, &errNamePatternNotAllowed):
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("org.form.name_pattern_not_allowed", errNamePatternNotAllowed.Pattern), tplCreateOrg, &form)
|
||||
case organization.IsErrUserNotAllowedCreateOrg(err):
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("org.form.create_org_not_allowed"), tplCreateOrg, &form)
|
||||
default:
|
||||
|
||||
@@ -96,16 +96,15 @@ func DeleteLabel(ctx *context.Context) {
|
||||
|
||||
// InitializeLabels init labels for an organization
|
||||
func InitializeLabels(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.InitializeLabelsForm)
|
||||
form := web.GetForm[*forms.InitializeLabelsForm](ctx)
|
||||
if ctx.HasError() {
|
||||
ctx.Redirect(ctx.Org.OrgLink + "/labels")
|
||||
return
|
||||
}
|
||||
|
||||
if err := repo_module.InitializeLabels(ctx, ctx.Org.Organization.ID, form.TemplateName, true); err != nil {
|
||||
if label.IsErrTemplateLoad(err) {
|
||||
originalErr := err.(label.ErrTemplateLoad).OriginalError
|
||||
ctx.Flash.Error(ctx.Tr("repo.issues.label_templates.fail_to_load_file", form.TemplateName, originalErr))
|
||||
if errTemplateLoad, ok := err.(label.ErrTemplateLoad); ok {
|
||||
ctx.Flash.Error(ctx.Tr("repo.issues.label_templates.fail_to_load_file", form.TemplateName, errTemplateLoad.OriginalError))
|
||||
ctx.Redirect(ctx.Org.OrgLink + "/settings/labels")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ func RenderNewProject(ctx *context.Context) {
|
||||
|
||||
// NewProjectPost creates a new project
|
||||
func NewProjectPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.CreateProjectForm)
|
||||
form := web.GetForm[*forms.CreateProjectForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("repo.projects.new")
|
||||
if _, err := shared_user.RenderUserOrgHeader(ctx); err != nil {
|
||||
ctx.ServerError("RenderUserOrgHeader", err)
|
||||
@@ -253,7 +253,7 @@ func RenderEditProject(ctx *context.Context) {
|
||||
|
||||
// EditProjectPost response for editing a project
|
||||
func EditProjectPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.CreateProjectForm)
|
||||
form := web.GetForm[*forms.CreateProjectForm](ctx)
|
||||
projectID := ctx.PathParamInt64("id")
|
||||
ctx.Data["Title"] = ctx.Tr("repo.projects.edit")
|
||||
ctx.Data["PageIsEditProjects"] = true
|
||||
|
||||
@@ -58,7 +58,7 @@ func Settings(ctx *context.Context) {
|
||||
|
||||
// SettingsPost response for settings change submitted
|
||||
func SettingsPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.UpdateOrgSettingForm)
|
||||
form := web.GetForm[*forms.UpdateOrgSettingForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("org.settings")
|
||||
ctx.Data["PageIsOrgSettings"] = true
|
||||
ctx.Data["PageIsSettingsOptions"] = true
|
||||
@@ -103,7 +103,7 @@ func SettingsPost(ctx *context.Context) {
|
||||
|
||||
// SettingsAvatar response for change avatar on settings page
|
||||
func SettingsAvatar(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.AvatarForm)
|
||||
form := web.GetForm[*forms.AvatarForm](ctx)
|
||||
form.Source = forms.AvatarLocal
|
||||
if err := user_setting.UpdateAvatarSetting(ctx, form, ctx.Org.Organization.AsUser()); err != nil {
|
||||
ctx.Flash.Error(err.Error())
|
||||
@@ -198,7 +198,7 @@ func Labels(ctx *context.Context) {
|
||||
|
||||
// SettingsRenamePost response for renaming organization
|
||||
func SettingsRenamePost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.RenameOrgForm)
|
||||
form := web.GetForm[*forms.RenameOrgForm](ctx)
|
||||
if ctx.HasError() {
|
||||
ctx.JSONError(ctx.GetErrMsg())
|
||||
return
|
||||
|
||||
@@ -368,7 +368,7 @@ func getUnitPerms(forms url.Values, teamPermission perm.AccessMode) map[unit_mod
|
||||
|
||||
// NewTeamPost response for create new team
|
||||
func NewTeamPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.CreateTeamForm)
|
||||
form := web.GetForm[*forms.CreateTeamForm](ctx)
|
||||
includesAllRepositories := form.RepoAccess == "all"
|
||||
teamPermission := perm.ParseAccessMode(form.Permission, perm.AccessModeNone, perm.AccessModeAdmin)
|
||||
unitPerms := getUnitPerms(ctx.Req.Form, teamPermission)
|
||||
@@ -544,7 +544,7 @@ func EditTeam(ctx *context.Context) {
|
||||
|
||||
// EditTeamPost response for modify team information
|
||||
func EditTeamPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.CreateTeamForm)
|
||||
form := web.GetForm[*forms.CreateTeamForm](ctx)
|
||||
t := ctx.Org.Team
|
||||
teamPermission := perm.ParseAccessMode(form.Permission, perm.AccessModeNone, perm.AccessModeAdmin)
|
||||
unitPerms := getUnitPerms(ctx.Req.Form, teamPermission)
|
||||
|
||||
@@ -717,7 +717,7 @@ func fillViewRunResponseSummary(ctx *context_module.Context, resp *ViewResponse,
|
||||
}
|
||||
|
||||
func fillViewRunResponseCurrentJob(ctx *context_module.Context, resp *ViewResponse, run *actions_model.ActionRun, jobs []*actions_model.ActionRunJob) {
|
||||
req := web.GetForm(ctx).(*ViewRequest)
|
||||
req := web.GetForm[*ViewRequest](ctx)
|
||||
current, hasPathParam := findCurrentJobByPathParam(ctx, jobs)
|
||||
if current == nil {
|
||||
if hasPathParam {
|
||||
|
||||
@@ -176,7 +176,7 @@ func jsonRedirectBranches(ctx *context.Context) {
|
||||
|
||||
// CreateBranch creates new branch in repository
|
||||
func CreateBranch(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.NewBranchForm)
|
||||
form := web.GetForm[*forms.NewBranchForm](ctx)
|
||||
if !ctx.Repo.CanCreateBranch() {
|
||||
ctx.NotFound(nil)
|
||||
return
|
||||
@@ -208,8 +208,7 @@ func CreateBranch(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if release_service.IsErrTagAlreadyExists(err) {
|
||||
e := err.(release_service.ErrTagAlreadyExists)
|
||||
if e, ok := err.(release_service.ErrTagAlreadyExists); ok {
|
||||
ctx.Flash.Error(ctx.Tr("repo.branch.tag_collision", e.TagName))
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL())
|
||||
return
|
||||
@@ -219,14 +218,12 @@ func CreateBranch(ctx *context.Context) {
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL())
|
||||
return
|
||||
}
|
||||
if git_model.IsErrBranchNameConflict(err) {
|
||||
e := err.(git_model.ErrBranchNameConflict)
|
||||
if e, ok := err.(git_model.ErrBranchNameConflict); ok {
|
||||
ctx.Flash.Error(ctx.Tr("repo.branch.branch_name_conflict", form.NewBranchName, e.BranchName))
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL())
|
||||
return
|
||||
}
|
||||
if git.IsErrPushRejected(err) {
|
||||
e := err.(*git.ErrPushRejected)
|
||||
if e, ok := err.(*git.ErrPushRejected); ok {
|
||||
if len(e.Message) == 0 {
|
||||
ctx.Flash.Error(ctx.Tr("repo.editor.push_rejected_no_message"))
|
||||
} else {
|
||||
|
||||
@@ -112,7 +112,7 @@ func (f *preparedEditorCommitForm[T]) GetCommitMessage(defaultCommitMessage stri
|
||||
}
|
||||
|
||||
func prepareEditorCommitSubmittedForm[T forms.CommitCommonFormInterface](ctx *context.Context) *preparedEditorCommitForm[T] {
|
||||
form := web.GetForm(ctx).(T)
|
||||
form := web.GetForm[T](ctx)
|
||||
if ctx.HasError() {
|
||||
ctx.JSONError(ctx.GetErrMsg())
|
||||
return nil
|
||||
|
||||
@@ -135,7 +135,7 @@ func Fork(ctx *context.Context) {
|
||||
|
||||
// ForkPost response for forking a repository
|
||||
func ForkPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.CreateRepoForm)
|
||||
form := web.GetForm[*forms.CreateRepoForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("new_fork")
|
||||
|
||||
ctxUser := checkContextUser(ctx, form.UID)
|
||||
@@ -205,6 +205,8 @@ func ForkRepoTo(ctx *context.Context, owner *user_model.User, forkOpts repo_serv
|
||||
repo, err := repo_service.ForkRepository(ctx, ctx.Doer, owner, forkOpts)
|
||||
if err != nil {
|
||||
ctx.Data["Err_RepoName"] = true
|
||||
var errNameReserved db.ErrNameReserved
|
||||
var errNamePatternNotAllowed db.ErrNamePatternNotAllowed
|
||||
switch {
|
||||
case repo_model.IsErrReachLimitOfRepo(err):
|
||||
maxCreationLimit := owner.MaxCreationLimit()
|
||||
@@ -223,10 +225,10 @@ func ForkRepoTo(ctx *context.Context, owner *user_model.User, forkOpts repo_serv
|
||||
default:
|
||||
ctx.JSONError(ctx.Tr("form.repository_files_already_exist"))
|
||||
}
|
||||
case db.IsErrNameReserved(err):
|
||||
ctx.JSONError(ctx.Tr("repo.form.name_reserved", err.(db.ErrNameReserved).Name))
|
||||
case db.IsErrNamePatternNotAllowed(err):
|
||||
ctx.JSONError(ctx.Tr("repo.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern))
|
||||
case errors.As(err, &errNameReserved):
|
||||
ctx.JSONError(ctx.Tr("repo.form.name_reserved", errNameReserved.Name))
|
||||
case errors.As(err, &errNamePatternNotAllowed):
|
||||
ctx.JSONError(ctx.Tr("repo.form.name_pattern_not_allowed", errNamePatternNotAllowed.Pattern))
|
||||
case errors.Is(err, user_model.ErrBlockedUser):
|
||||
ctx.JSONError(ctx.Tr("repo.fork.blocked_user"))
|
||||
default:
|
||||
|
||||
@@ -480,7 +480,7 @@ func UpdateIssueAssignee(ctx *context.Context) {
|
||||
|
||||
// ChangeIssueReaction create a reaction for issue
|
||||
func ChangeIssueReaction(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.ReactionForm)
|
||||
form := web.GetForm[*forms.ReactionForm](ctx)
|
||||
issue := GetActionIssue(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
|
||||
@@ -41,7 +41,7 @@ func NewComment(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.CreateCommentForm)
|
||||
form := web.GetForm[*forms.CreateCommentForm](ctx)
|
||||
issueType := util.Iif(issue.IsPull, "pulls", "issues")
|
||||
|
||||
if !ctx.IsSigned || (ctx.Doer.ID != issue.PosterID && !ctx.Repo.Permission.CanReadIssuesOrPulls(issue.IsPull)) {
|
||||
@@ -306,7 +306,7 @@ func DeleteComment(ctx *context.Context) {
|
||||
|
||||
// ChangeCommentReaction create a reaction for comment
|
||||
func ChangeCommentReaction(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.ReactionForm)
|
||||
form := web.GetForm[*forms.ReactionForm](ctx)
|
||||
comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64("id"))
|
||||
if err != nil {
|
||||
ctx.NotFoundOrServerError("GetCommentByID", issues_model.IsErrCommentNotExist, err)
|
||||
|
||||
@@ -36,16 +36,15 @@ func Labels(ctx *context.Context) {
|
||||
|
||||
// InitializeLabels init labels for a repository
|
||||
func InitializeLabels(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.InitializeLabelsForm)
|
||||
form := web.GetForm[*forms.InitializeLabelsForm](ctx)
|
||||
if ctx.HasError() {
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/labels")
|
||||
return
|
||||
}
|
||||
|
||||
if err := repo_module.InitializeLabels(ctx, ctx.Repo.Repository.ID, form.TemplateName, false); err != nil {
|
||||
if label.IsErrTemplateLoad(err) {
|
||||
originalErr := err.(label.ErrTemplateLoad).OriginalError
|
||||
ctx.Flash.Error(ctx.Tr("repo.issues.label_templates.fail_to_load_file", form.TemplateName, originalErr))
|
||||
if errTemplateLoad, ok := err.(label.ErrTemplateLoad); ok {
|
||||
ctx.Flash.Error(ctx.Tr("repo.issues.label_templates.fail_to_load_file", form.TemplateName, errTemplateLoad.OriginalError))
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/labels")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
// LockIssue locks an issue. This would limit commenting abilities to
|
||||
// users with write access to the repo.
|
||||
func LockIssue(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.IssueLockForm)
|
||||
form := web.GetForm[*forms.IssueLockForm](ctx)
|
||||
issue := GetActionIssue(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
|
||||
@@ -322,7 +322,7 @@ func ValidateRepoMetasForNewIssue(ctx *context.Context, form forms.CreateIssueFo
|
||||
|
||||
// NewIssuePost response for creating new issue
|
||||
func NewIssuePost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.CreateIssueForm)
|
||||
form := web.GetForm[*forms.CreateIssueForm](ctx)
|
||||
|
||||
repo := ctx.Repo.Repository
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
|
||||
// AddTimeManually tracks time manually
|
||||
func AddTimeManually(c *context.Context) {
|
||||
form := web.GetForm(c).(*forms.AddTimeManuallyForm)
|
||||
form := web.GetForm[*forms.AddTimeManuallyForm](c)
|
||||
issue := GetActionIssue(c)
|
||||
if c.Written() {
|
||||
return
|
||||
|
||||
@@ -499,8 +499,8 @@ func (prInfo *pullRequestViewInfo) prepareMergeBoxCommitSigning(ctx *context.Con
|
||||
data.willSign = sign
|
||||
data.signingKeyMergeDisplay = asymkey_model.GetDisplaySigningKey(key)
|
||||
if err != nil {
|
||||
if asymkey_service.IsErrWontSign(err) {
|
||||
wontSignReason = string(err.(*asymkey_service.ErrWontSign).Reason)
|
||||
if errWontSign, ok := err.(*asymkey_service.ErrWontSign); ok {
|
||||
wontSignReason = string(errWontSign.Reason)
|
||||
} else {
|
||||
wontSignReason = "error"
|
||||
if !errors.Is(err, util.ErrNotExist) {
|
||||
@@ -560,8 +560,9 @@ func prepareIssueViewSidebarTimeTracker(ctx *context.Context, issue *issues_mode
|
||||
|
||||
if ctx.IsSigned {
|
||||
// Deal with the stopwatch
|
||||
ctx.Data["IsStopwatchRunning"] = issues_model.StopwatchExists(ctx, ctx.Doer.ID, issue.ID)
|
||||
if !ctx.Data["IsStopwatchRunning"].(bool) {
|
||||
isStopwatchRunning := issues_model.StopwatchExists(ctx, ctx.Doer.ID, issue.ID)
|
||||
ctx.Data["IsStopwatchRunning"] = isStopwatchRunning
|
||||
if !isStopwatchRunning {
|
||||
exists, _, swIssue, err := issues_model.HasUserStopwatch(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("HasUserStopwatch", err)
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
package repo
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
@@ -77,6 +78,8 @@ func handleMigrateError(ctx *context.Context, owner *user_model.User, err error,
|
||||
return
|
||||
}
|
||||
|
||||
var errNameReserved db.ErrNameReserved
|
||||
var errNamePatternNotAllowed db.ErrNamePatternNotAllowed
|
||||
switch {
|
||||
case migrations.IsRateLimitError(err):
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("form.visit_rate_limit"), tpl, form)
|
||||
@@ -101,12 +104,12 @@ func handleMigrateError(ctx *context.Context, owner *user_model.User, err error,
|
||||
default:
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("form.repository_files_already_exist"), tpl, form)
|
||||
}
|
||||
case db.IsErrNameReserved(err):
|
||||
case errors.As(err, &errNameReserved):
|
||||
ctx.Data["Err_RepoName"] = true
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("repo.form.name_reserved", err.(db.ErrNameReserved).Name), tpl, form)
|
||||
case db.IsErrNamePatternNotAllowed(err):
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("repo.form.name_reserved", errNameReserved.Name), tpl, form)
|
||||
case errors.As(err, &errNamePatternNotAllowed):
|
||||
ctx.Data["Err_RepoName"] = true
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("repo.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tpl, form)
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("repo.form.name_pattern_not_allowed", errNamePatternNotAllowed.Pattern), tpl, form)
|
||||
default:
|
||||
err = util.SanitizeErrorCredentialURLs(err)
|
||||
if strings.Contains(err.Error(), "Authentication failed") ||
|
||||
@@ -124,8 +127,7 @@ func handleMigrateError(ctx *context.Context, owner *user_model.User, err error,
|
||||
}
|
||||
|
||||
func handleMigrateRemoteAddrError(ctx *context.Context, err error, tpl templates.TplName, form *forms.MigrateRepoForm) {
|
||||
if git.IsErrInvalidCloneAddr(err) {
|
||||
addrErr := err.(*git.ErrInvalidCloneAddr)
|
||||
if addrErr, ok := err.(*git.ErrInvalidCloneAddr); ok {
|
||||
switch {
|
||||
case addrErr.IsProtocolInvalid:
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("repo.mirror_address_protocol_invalid"), tpl, form)
|
||||
@@ -151,7 +153,7 @@ func handleMigrateRemoteAddrError(ctx *context.Context, err error, tpl templates
|
||||
|
||||
// MigratePost response for migrating from external git repository
|
||||
func MigratePost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.MigrateRepoForm)
|
||||
form := web.GetForm[*forms.MigrateRepoForm](ctx)
|
||||
if setting.Repository.DisableMigrations {
|
||||
ctx.HTTPError(http.StatusForbidden, "MigratePost: the site administrator has disabled migrations")
|
||||
return
|
||||
|
||||
@@ -105,7 +105,7 @@ func NewMilestone(ctx *context.Context) {
|
||||
|
||||
// NewMilestonePost response for creating milestone
|
||||
func NewMilestonePost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.CreateMilestoneForm)
|
||||
form := web.GetForm[*forms.CreateMilestoneForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("repo.milestones.new")
|
||||
ctx.Data["PageIsIssueList"] = true
|
||||
ctx.Data["PageIsMilestones"] = true
|
||||
@@ -161,7 +161,7 @@ func EditMilestone(ctx *context.Context) {
|
||||
|
||||
// EditMilestonePost response for edting milestone
|
||||
func EditMilestonePost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.CreateMilestoneForm)
|
||||
form := web.GetForm[*forms.CreateMilestoneForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("repo.milestones.edit")
|
||||
ctx.Data["PageIsMilestones"] = true
|
||||
ctx.Data["PageIsEditMilestone"] = true
|
||||
|
||||
@@ -127,7 +127,7 @@ func RenderNewProject(ctx *context.Context) {
|
||||
|
||||
// NewProjectPost creates a new project
|
||||
func NewProjectPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.CreateProjectForm)
|
||||
form := web.GetForm[*forms.CreateProjectForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("repo.projects.new")
|
||||
|
||||
if ctx.HasError() {
|
||||
@@ -231,7 +231,7 @@ func RenderEditProject(ctx *context.Context) {
|
||||
|
||||
// EditProjectPost response for editing a project
|
||||
func EditProjectPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.CreateProjectForm)
|
||||
form := web.GetForm[*forms.CreateProjectForm](ctx)
|
||||
projectID := ctx.PathParamInt64("id")
|
||||
|
||||
ctx.Data["Title"] = ctx.Tr("repo.projects.edit")
|
||||
|
||||
+13
-19
@@ -1007,8 +1007,7 @@ func UpdatePullRequest(ctx *context.Context) {
|
||||
// The update process should not be canceled by the user
|
||||
// so we set the context to be a background context
|
||||
if err = pull_service.Update(graceful.GetManager().ShutdownContext(), issue.PullRequest, ctx.Doer, message, rebase); err != nil {
|
||||
if pull_service.IsErrMergeConflicts(err) {
|
||||
conflictError := err.(pull_service.ErrMergeConflicts)
|
||||
if conflictError, ok := err.(pull_service.ErrMergeConflicts); ok {
|
||||
flashError, err := ctx.RenderToHTML(tplAlertDetails, map[string]any{
|
||||
"Message": ctx.Tr("repo.pulls.merge_conflict"),
|
||||
"Summary": ctx.Tr("repo.pulls.merge_conflict_summary"),
|
||||
@@ -1020,8 +1019,7 @@ func UpdatePullRequest(ctx *context.Context) {
|
||||
}
|
||||
ctx.JSONError(flashError)
|
||||
return
|
||||
} else if pull_service.IsErrRebaseConflicts(err) {
|
||||
conflictError := err.(pull_service.ErrRebaseConflicts)
|
||||
} else if conflictError, ok := err.(pull_service.ErrRebaseConflicts); ok {
|
||||
flashError, err := ctx.RenderToHTML(tplAlertDetails, map[string]any{
|
||||
"Message": ctx.Tr("repo.pulls.rebase_conflict", utils.EscapeFlashErrorString(conflictError.CommitSHA)),
|
||||
"Summary": ctx.Tr("repo.pulls.rebase_conflict_summary"),
|
||||
@@ -1047,7 +1045,7 @@ func UpdatePullRequest(ctx *context.Context) {
|
||||
|
||||
// MergePullRequest response for merging pull request
|
||||
func MergePullRequest(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.MergePullRequestForm)
|
||||
form := web.GetForm[*forms.MergePullRequestForm](ctx)
|
||||
issue, ok := getPullInfo(ctx)
|
||||
if !ok {
|
||||
return
|
||||
@@ -1156,8 +1154,7 @@ func MergePullRequest(ctx *context.Context) {
|
||||
if err := pull_service.Merge(ctx, pr, ctx.Doer, repo_model.MergeStyle(form.Do), form.HeadCommitID, message, false); err != nil {
|
||||
if pull_service.IsErrInvalidMergeStyle(err) {
|
||||
ctx.JSONError(ctx.Tr("repo.pulls.invalid_merge_option"))
|
||||
} else if pull_service.IsErrMergeConflicts(err) {
|
||||
conflictError := err.(pull_service.ErrMergeConflicts)
|
||||
} else if conflictError, ok := err.(pull_service.ErrMergeConflicts); ok {
|
||||
flashError, err := ctx.RenderToHTML(tplAlertDetails, map[string]any{
|
||||
"Message": ctx.Tr("repo.editor.merge_conflict"),
|
||||
"Summary": ctx.Tr("repo.editor.merge_conflict_summary"),
|
||||
@@ -1169,8 +1166,7 @@ func MergePullRequest(ctx *context.Context) {
|
||||
}
|
||||
ctx.Flash.Error(flashError)
|
||||
ctx.JSONRedirect(issue.Link())
|
||||
} else if pull_service.IsErrRebaseConflicts(err) {
|
||||
conflictError := err.(pull_service.ErrRebaseConflicts)
|
||||
} else if conflictError, ok := err.(pull_service.ErrRebaseConflicts); ok {
|
||||
flashError, err := ctx.RenderToHTML(tplAlertDetails, map[string]any{
|
||||
"Message": ctx.Tr("repo.pulls.rebase_conflict", utils.EscapeFlashErrorString(conflictError.CommitSHA)),
|
||||
"Summary": ctx.Tr("repo.pulls.rebase_conflict_summary"),
|
||||
@@ -1194,9 +1190,8 @@ func MergePullRequest(ctx *context.Context) {
|
||||
log.Debug("MergeHeadOutOfDate error: %v", err)
|
||||
ctx.Flash.Error(ctx.Tr("repo.pulls.head_out_of_date"))
|
||||
ctx.JSONRedirect(issue.Link())
|
||||
} else if git.IsErrPushRejected(err) {
|
||||
} else if pushrejErr, ok := err.(*git.ErrPushRejected); ok {
|
||||
log.Debug("MergePushRejected error: %v", err)
|
||||
pushrejErr := err.(*git.ErrPushRejected)
|
||||
message := pushrejErr.Message
|
||||
if len(message) == 0 {
|
||||
ctx.Flash.Error(ctx.Tr("repo.pulls.push_rejected_no_message"))
|
||||
@@ -1322,7 +1317,7 @@ func PullsNewRedirect(ctx *context.Context) {
|
||||
|
||||
// CompareAndPullRequestPost response for creating pull request
|
||||
func CompareAndPullRequestPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.CreateIssueForm)
|
||||
form := web.GetForm[*forms.CreateIssueForm](ctx)
|
||||
repo := ctx.Repo.Repository
|
||||
comparePageInfo := newComparePageInfo()
|
||||
err := comparePageInfo.parseCompareInfo(ctx, ctx.PathParam("*"))
|
||||
@@ -1416,11 +1411,11 @@ func CompareAndPullRequestPost(ctx *context.Context) {
|
||||
ProjectIDs: projectIDs,
|
||||
}
|
||||
if err := pull_service.NewPullRequest(ctx, prOpts); err != nil {
|
||||
var pushrejErr *git.ErrPushRejected
|
||||
switch {
|
||||
case repo_model.IsErrUserDoesNotHaveAccessToRepo(err):
|
||||
ctx.HTTPError(http.StatusBadRequest, "UserDoesNotHaveAccessToRepo", err.Error())
|
||||
case git.IsErrPushRejected(err):
|
||||
pushrejErr := err.(*git.ErrPushRejected)
|
||||
case errors.As(err, &pushrejErr):
|
||||
message := pushrejErr.Message
|
||||
if len(message) == 0 {
|
||||
ctx.JSONError(ctx.Tr("repo.pulls.push_rejected_no_message"))
|
||||
@@ -1537,6 +1532,7 @@ func UpdatePullRequestTarget(ctx *context.Context) {
|
||||
}
|
||||
|
||||
if err := pull_service.ChangeTargetBranch(ctx, pr, ctx.Doer, targetBranch); err != nil {
|
||||
var prExistsErr issues_model.ErrPullRequestAlreadyExists
|
||||
switch {
|
||||
case git_model.IsErrBranchNotExist(err):
|
||||
errorMessage := ctx.Tr("form.target_branch_not_exist")
|
||||
@@ -1546,11 +1542,9 @@ func UpdatePullRequestTarget(ctx *context.Context) {
|
||||
"error": err.Error(),
|
||||
"user_error": errorMessage,
|
||||
})
|
||||
case issues_model.IsErrPullRequestAlreadyExists(err):
|
||||
err := err.(issues_model.ErrPullRequestAlreadyExists)
|
||||
|
||||
case errors.As(err, &prExistsErr):
|
||||
RepoRelPath := ctx.Repo.Owner.Name + "/" + ctx.Repo.Repository.Name
|
||||
errorMessage := ctx.Tr("repo.pulls.has_pull_request", html.EscapeString(ctx.Repo.RepoLink+"/pulls/"+strconv.FormatInt(err.IssueID, 10)), html.EscapeString(RepoRelPath), err.IssueID) // FIXME: Creates url inside locale string
|
||||
errorMessage := ctx.Tr("repo.pulls.has_pull_request", html.EscapeString(ctx.Repo.RepoLink+"/pulls/"+strconv.FormatInt(prExistsErr.IssueID, 10)), html.EscapeString(RepoRelPath), prExistsErr.IssueID) // FIXME: Creates url inside locale string
|
||||
|
||||
ctx.Flash.Error(errorMessage)
|
||||
ctx.JSON(http.StatusConflict, map[string]any{
|
||||
@@ -1595,7 +1589,7 @@ func UpdatePullRequestTarget(ctx *context.Context) {
|
||||
|
||||
// SetAllowEdits allow edits from maintainers to PRs
|
||||
func SetAllowEdits(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.UpdateAllowEditsForm)
|
||||
form := web.GetForm[*forms.UpdateAllowEditsForm](ctx)
|
||||
|
||||
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||
if err != nil {
|
||||
|
||||
@@ -62,7 +62,7 @@ func RenderNewCodeCommentForm(ctx *context.Context) {
|
||||
|
||||
// CreateCodeComment will create a code comment including an pending review if required
|
||||
func CreateCodeComment(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.CodeCommentForm)
|
||||
form := web.GetForm[*forms.CodeCommentForm](ctx)
|
||||
issue := GetActionIssue(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
@@ -221,7 +221,7 @@ func renderConversation(ctx *context.Context, comment *issues_model.Comment, ori
|
||||
|
||||
// SubmitReview creates a review out of the existing pending review or creates a new one if no pending review exist
|
||||
func SubmitReview(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.SubmitReviewForm)
|
||||
form := web.GetForm[*forms.SubmitReviewForm](ctx)
|
||||
issue := GetActionIssue(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
@@ -279,7 +279,7 @@ func SubmitReview(ctx *context.Context) {
|
||||
|
||||
// DismissReview dismissing stale review by repo admin
|
||||
func DismissReview(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.DismissReviewForm)
|
||||
form := web.GetForm[*forms.DismissReviewForm](ctx)
|
||||
comm, err := pull_service.DismissReview(ctx, form.ReviewID, ctx.Repo.Repository.ID, form.Message, ctx.Doer, true, true)
|
||||
if err != nil {
|
||||
if pull_service.IsErrDismissRequestOnClosedPR(err) {
|
||||
|
||||
@@ -48,8 +48,8 @@ func calReleaseNumCommitsBehind(ctx stdCtx.Context, repoCtx *context.Repository,
|
||||
if _, ok := countCache[target]; !ok {
|
||||
commit, err := repoCtx.GitRepo.GetBranchCommit(ctx, target)
|
||||
if err != nil {
|
||||
var errNotExist git.ErrNotExist
|
||||
if target == repoCtx.Repository.DefaultBranch || !errors.As(err, &errNotExist) {
|
||||
_, isNotExist := errors.AsType[git.ErrNotExist](err)
|
||||
if target == repoCtx.Repository.DefaultBranch || !isNotExist {
|
||||
return fmt.Errorf("GetBranchCommit: %w", err)
|
||||
}
|
||||
// fallback to default branch
|
||||
@@ -189,7 +189,7 @@ func Releases(ctx *context.Context) {
|
||||
|
||||
ctx.Data["Releases"] = releases
|
||||
|
||||
numReleases := ctx.Data["NumReleases"].(int64)
|
||||
numReleases := ctx.Data["NumReleases"].(int64) //nolint:forcetypeassert // must exist
|
||||
pager := context.NewPagination(numReleases, listOptions.PageSize, listOptions.Page, 5)
|
||||
pager.AddParamFromRequest(ctx.Req)
|
||||
ctx.Data["Page"] = pager
|
||||
@@ -387,7 +387,7 @@ func NewRelease(ctx *context.Context) {
|
||||
|
||||
// GenerateReleaseNotes builds release notes content for the given tag and base.
|
||||
func GenerateReleaseNotes(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.GenerateReleaseNotesForm)
|
||||
form := web.GetForm[*forms.GenerateReleaseNotesForm](ctx)
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.JSONError(ctx.GetErrMsg())
|
||||
@@ -418,7 +418,7 @@ func NewReleasePost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.NewReleaseForm)
|
||||
form := web.GetForm[*forms.NewReleaseForm](ctx)
|
||||
|
||||
// first, check whether the release exists, and prepare "ShowCreateTagOnlyButton"
|
||||
// the logic should be done before the form error check to make the tmpl has correct variables
|
||||
@@ -579,7 +579,7 @@ func EditReleasePost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.EditReleaseForm)
|
||||
form := web.GetForm[*forms.EditReleaseForm](ctx)
|
||||
|
||||
tagName := ctx.PathParam("*")
|
||||
rel, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, tagName)
|
||||
|
||||
@@ -165,6 +165,8 @@ func Create(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func handleCreateError(ctx *context.Context, owner *user_model.User, err error, name string, tpl templates.TplName, form any) {
|
||||
var errNameReserved db.ErrNameReserved
|
||||
var errNamePatternNotAllowed db.ErrNamePatternNotAllowed
|
||||
switch {
|
||||
case repo_model.IsErrReachLimitOfRepo(err):
|
||||
maxCreationLimit := owner.MaxCreationLimit()
|
||||
@@ -185,12 +187,12 @@ func handleCreateError(ctx *context.Context, owner *user_model.User, err error,
|
||||
default:
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("form.repository_files_already_exist"), tpl, form)
|
||||
}
|
||||
case db.IsErrNameReserved(err):
|
||||
case errors.As(err, &errNameReserved):
|
||||
ctx.Data["Err_RepoName"] = true
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("repo.form.name_reserved", err.(db.ErrNameReserved).Name), tpl, form)
|
||||
case db.IsErrNamePatternNotAllowed(err):
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("repo.form.name_reserved", errNameReserved.Name), tpl, form)
|
||||
case errors.As(err, &errNamePatternNotAllowed):
|
||||
ctx.Data["Err_RepoName"] = true
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("repo.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tpl, form)
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("repo.form.name_pattern_not_allowed", errNamePatternNotAllowed.Pattern), tpl, form)
|
||||
default:
|
||||
ctx.ServerError(name, err)
|
||||
}
|
||||
@@ -199,7 +201,7 @@ func handleCreateError(ctx *context.Context, owner *user_model.User, err error,
|
||||
// CreatePost response for creating repository
|
||||
func CreatePost(ctx *context.Context) {
|
||||
createCommon(ctx)
|
||||
form := web.GetForm(ctx).(*forms.CreateRepoForm)
|
||||
form := web.GetForm[*forms.CreateRepoForm](ctx)
|
||||
|
||||
ctxUser := checkContextUser(ctx, form.UID)
|
||||
if ctx.Written() {
|
||||
@@ -283,11 +285,12 @@ func CreatePost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func handleActionError(ctx *context.Context, err error) {
|
||||
var errLimitReached repo_service.LimitReachedError
|
||||
switch {
|
||||
case errors.Is(err, user_model.ErrBlockedUser):
|
||||
ctx.JSONError(ctx.Tr("repo.action.blocked_user"))
|
||||
case repo_service.IsRepositoryLimitReached(err):
|
||||
limit := err.(repo_service.LimitReachedError).Limit
|
||||
case errors.As(err, &errLimitReached):
|
||||
limit := errLimitReached.Limit
|
||||
ctx.JSONError(ctx.TrN(limit, "repo.form.reach_limit_of_creation_1", "repo.form.reach_limit_of_creation_n", limit))
|
||||
case errors.Is(err, util.ErrPermissionDenied):
|
||||
ctx.JSONError(ctx.Tr("error.permission_denied"))
|
||||
|
||||
@@ -57,7 +57,7 @@ func UpdateAvatarSetting(ctx *context.Context, form forms.AvatarForm) error {
|
||||
|
||||
// SettingsAvatar save new POSTed repository avatar
|
||||
func SettingsAvatar(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.AvatarForm)
|
||||
form := web.GetForm[*forms.AvatarForm](ctx)
|
||||
form.Source = forms.AvatarLocal
|
||||
if err := UpdateAvatarSetting(ctx, *form); err != nil {
|
||||
ctx.Flash.Error(err.Error())
|
||||
|
||||
@@ -34,7 +34,7 @@ func DeployKeys(ctx *context.Context) {
|
||||
|
||||
// DeployKeysPost response for adding a deploy key of a repository
|
||||
func DeployKeysPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.AddKeyForm)
|
||||
form := web.GetForm[*forms.AddKeyForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("repo.settings.deploy_keys")
|
||||
ctx.Data["PageIsSettingsKeys"] = true
|
||||
ctx.Data["DisableSSH"] = setting.SSH.Disabled
|
||||
|
||||
@@ -109,7 +109,7 @@ func SettingsProtectedBranch(c *context.Context) {
|
||||
|
||||
// SettingsProtectedBranchPost updates the protected branch settings
|
||||
func SettingsProtectedBranchPost(ctx *context.Context) {
|
||||
f := web.GetForm(ctx).(*forms.ProtectBranchForm)
|
||||
f := web.GetForm[*forms.ProtectBranchForm](ctx)
|
||||
var protectBranch *git_model.ProtectedBranch
|
||||
if f.RuleName == "" {
|
||||
ctx.Flash.Error(ctx.Tr("repo.settings.protected_branch_required_rule_name"))
|
||||
@@ -343,7 +343,7 @@ func UpdateBranchProtectionPriories(ctx *context.Context) {
|
||||
|
||||
// RenameBranchPost responses for rename a branch
|
||||
func RenameBranchPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.RenameBranchForm)
|
||||
form := web.GetForm[*forms.RenameBranchForm](ctx)
|
||||
|
||||
if !ctx.Repo.CanCreateBranch() {
|
||||
ctx.NotFound(nil)
|
||||
|
||||
@@ -46,7 +46,7 @@ func NewProtectedTagPost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
repo := ctx.Repo.Repository
|
||||
form := web.GetForm(ctx).(*forms.ProtectTagForm)
|
||||
form := web.GetForm[*forms.ProtectTagForm](ctx)
|
||||
|
||||
pt := &git_model.ProtectedTag{
|
||||
RepoID: repo.ID,
|
||||
@@ -107,7 +107,7 @@ func EditProtectedTagPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.ProtectTagForm)
|
||||
form := web.GetForm[*forms.ProtectTagForm](ctx)
|
||||
|
||||
pt.NamePattern = strings.TrimSpace(form.NamePattern)
|
||||
pt.AllowlistUserIDs, _ = base.StringsToInt64s(strings.Split(form.AllowlistUsers, ","))
|
||||
|
||||
@@ -198,7 +198,7 @@ func SettingsPost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func handleSettingsPostUpdate(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.RepoSettingForm)
|
||||
form := web.GetForm[*forms.RepoSettingForm](ctx)
|
||||
repo := ctx.Repo.Repository
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(http.StatusOK, tplSettingsOptions)
|
||||
@@ -215,11 +215,13 @@ func handleSettingsPostUpdate(ctx *context.Context) {
|
||||
}
|
||||
if err := repo_service.ChangeRepositoryName(ctx, ctx.Doer, repo, newRepoName); err != nil {
|
||||
ctx.Data["Err_RepoName"] = true
|
||||
var errNameReserved db.ErrNameReserved
|
||||
var errNamePatternNotAllowed db.ErrNamePatternNotAllowed
|
||||
switch {
|
||||
case repo_model.IsErrRepoAlreadyExist(err):
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("form.repo_name_been_taken"), tplSettingsOptions, &form)
|
||||
case db.IsErrNameReserved(err):
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("repo.form.name_reserved", err.(db.ErrNameReserved).Name), tplSettingsOptions, &form)
|
||||
case errors.As(err, &errNameReserved):
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("repo.form.name_reserved", errNameReserved.Name), tplSettingsOptions, &form)
|
||||
case repo_model.IsErrRepoFilesAlreadyExist(err):
|
||||
ctx.Data["Err_RepoName"] = true
|
||||
switch {
|
||||
@@ -232,8 +234,8 @@ func handleSettingsPostUpdate(ctx *context.Context) {
|
||||
default:
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("form.repository_files_already_exist"), tplSettingsOptions, form)
|
||||
}
|
||||
case db.IsErrNamePatternNotAllowed(err):
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("repo.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tplSettingsOptions, &form)
|
||||
case errors.As(err, &errNamePatternNotAllowed):
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("repo.form.name_pattern_not_allowed", errNamePatternNotAllowed.Pattern), tplSettingsOptions, &form)
|
||||
default:
|
||||
ctx.ServerError("ChangeRepositoryName", err)
|
||||
}
|
||||
@@ -260,7 +262,7 @@ func handleSettingsPostUpdate(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func handleSettingsPostMirror(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.RepoSettingForm)
|
||||
form := web.GetForm[*forms.RepoSettingForm](ctx)
|
||||
repo := ctx.Repo.Repository
|
||||
if !setting.Mirror.Enabled || !repo.IsMirror || repo.IsArchived {
|
||||
ctx.NotFound(nil)
|
||||
@@ -375,7 +377,7 @@ func handleSettingsPostMirrorSync(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func handleSettingsPostPushMirrorSync(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.RepoSettingForm)
|
||||
form := web.GetForm[*forms.RepoSettingForm](ctx)
|
||||
repo := ctx.Repo.Repository
|
||||
|
||||
if !setting.Mirror.Enabled {
|
||||
@@ -396,7 +398,7 @@ func handleSettingsPostPushMirrorSync(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func handleSettingsPostPushMirrorUpdate(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.RepoSettingForm)
|
||||
form := web.GetForm[*forms.RepoSettingForm](ctx)
|
||||
repo := ctx.Repo.Repository
|
||||
|
||||
if !setting.Mirror.Enabled || repo.IsArchived {
|
||||
@@ -438,7 +440,7 @@ func handleSettingsPostPushMirrorUpdate(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func handleSettingsPostPushMirrorRemove(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.RepoSettingForm)
|
||||
form := web.GetForm[*forms.RepoSettingForm](ctx)
|
||||
repo := ctx.Repo.Repository
|
||||
|
||||
if !setting.Mirror.Enabled || repo.IsArchived {
|
||||
@@ -471,7 +473,7 @@ func handleSettingsPostPushMirrorRemove(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func handleSettingsPostPushMirrorAdd(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.RepoSettingForm)
|
||||
form := web.GetForm[*forms.RepoSettingForm](ctx)
|
||||
repo := ctx.Repo.Repository
|
||||
|
||||
if setting.Mirror.DisableNewPush || repo.IsArchived {
|
||||
@@ -546,7 +548,7 @@ func newRepoUnit(repo *repo_model.Repository, unitType unit_model.Type, config c
|
||||
}
|
||||
|
||||
func handleSettingsPostAdvanced(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.RepoSettingForm)
|
||||
form := web.GetForm[*forms.RepoSettingForm](ctx)
|
||||
repo := ctx.Repo.Repository
|
||||
var repoChanged bool
|
||||
var units []repo_model.RepoUnit
|
||||
@@ -703,7 +705,7 @@ func handleSettingsPostAdvanced(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func handleSettingsPostSigning(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.RepoSettingForm)
|
||||
form := web.GetForm[*forms.RepoSettingForm](ctx)
|
||||
repo := ctx.Repo.Repository
|
||||
trustModel := repo_model.ToTrustModel(form.TrustModel)
|
||||
if trustModel != repo.TrustModel {
|
||||
@@ -726,7 +728,7 @@ func handleSettingsPostAdmin(ctx *context.Context) {
|
||||
}
|
||||
|
||||
repo := ctx.Repo.Repository
|
||||
form := web.GetForm(ctx).(*forms.RepoSettingForm)
|
||||
form := web.GetForm[*forms.RepoSettingForm](ctx)
|
||||
if repo.IsFsckEnabled != form.EnableHealthCheck {
|
||||
repo.IsFsckEnabled = form.EnableHealthCheck
|
||||
if err := repo_model.UpdateRepositoryColsNoAutoTime(ctx, repo, "is_fsck_enabled"); err != nil {
|
||||
@@ -741,7 +743,7 @@ func handleSettingsPostAdmin(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func handleSettingsPostAdminIndex(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.RepoSettingForm)
|
||||
form := web.GetForm[*forms.RepoSettingForm](ctx)
|
||||
repo := ctx.Repo.Repository
|
||||
if !ctx.Doer.IsAdmin {
|
||||
ctx.HTTPError(http.StatusForbidden)
|
||||
@@ -772,7 +774,7 @@ func handleSettingsPostAdminIndex(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func handleSettingsPostConvert(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.RepoSettingForm)
|
||||
form := web.GetForm[*forms.RepoSettingForm](ctx)
|
||||
repo := ctx.Repo.Repository
|
||||
if !ctx.Repo.Permission.IsOwner() {
|
||||
ctx.JSONErrorNotFound()
|
||||
@@ -802,7 +804,7 @@ func handleSettingsPostConvert(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func handleSettingsPostConvertFork(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.RepoSettingForm)
|
||||
form := web.GetForm[*forms.RepoSettingForm](ctx)
|
||||
repo := ctx.Repo.Repository
|
||||
if !ctx.Repo.Permission.IsOwner() {
|
||||
ctx.JSONErrorNotFound()
|
||||
@@ -842,7 +844,7 @@ func handleSettingsPostConvertFork(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func handleSettingsPostTransfer(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.RepoSettingForm)
|
||||
form := web.GetForm[*forms.RepoSettingForm](ctx)
|
||||
repo := ctx.Repo.Repository
|
||||
if !ctx.Repo.Permission.IsOwner() {
|
||||
ctx.JSONErrorNotFound()
|
||||
@@ -883,8 +885,8 @@ func handleSettingsPostTransfer(ctx *context.Context) {
|
||||
ctx.JSONError(ctx.Tr("repo.settings.new_owner_has_same_repo"))
|
||||
} else if repo_model.IsErrRepoTransferInProgress(err) {
|
||||
ctx.JSONError(ctx.Tr("repo.settings.transfer_in_progress"))
|
||||
} else if repo_service.IsRepositoryLimitReached(err) {
|
||||
limit := err.(repo_service.LimitReachedError).Limit
|
||||
} else if errLimitReached, ok := err.(repo_service.LimitReachedError); ok {
|
||||
limit := errLimitReached.Limit
|
||||
ctx.JSONError(ctx.TrN(limit, "repo.form.reach_limit_of_creation_1", "repo.form.reach_limit_of_creation_n", limit))
|
||||
} else if errors.Is(err, user_model.ErrBlockedUser) {
|
||||
ctx.JSONError(ctx.Tr("repo.settings.transfer.blocked_user"))
|
||||
@@ -934,7 +936,7 @@ func handleSettingsPostCancelTransfer(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func handleSettingsPostDelete(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.RepoSettingForm)
|
||||
form := web.GetForm[*forms.RepoSettingForm](ctx)
|
||||
repo := ctx.Repo.Repository
|
||||
if !ctx.Repo.Permission.IsOwner() {
|
||||
ctx.JSONErrorNotFound()
|
||||
@@ -961,7 +963,7 @@ func handleSettingsPostDelete(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func handleSettingsPostDeleteWiki(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.RepoSettingForm)
|
||||
form := web.GetForm[*forms.RepoSettingForm](ctx)
|
||||
repo := ctx.Repo.Repository
|
||||
if !ctx.Repo.Permission.IsOwner() {
|
||||
ctx.JSONErrorNotFound()
|
||||
@@ -1075,8 +1077,7 @@ func handleSettingsPostVisibility(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func handleSettingRemoteAddrError(ctx *context.Context, err error, form *forms.RepoSettingForm) {
|
||||
if git.IsErrInvalidCloneAddr(err) {
|
||||
addrErr := err.(*git.ErrInvalidCloneAddr)
|
||||
if addrErr, ok := err.(*git.ErrInvalidCloneAddr); ok {
|
||||
switch {
|
||||
case addrErr.IsProtocolInvalid:
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("repo.mirror_address_protocol_invalid"), tplSettingsOptions, form)
|
||||
|
||||
@@ -326,7 +326,7 @@ func GiteaHooksEditPost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func giteaHookParams(ctx *context.Context) webhookParams {
|
||||
form := web.GetForm(ctx).(*forms.NewWebhookForm)
|
||||
form := web.GetForm[*forms.NewWebhookForm](ctx)
|
||||
|
||||
contentType := webhook.ContentTypeJSON
|
||||
if webhook.HookContentType(form.ContentType) == webhook.ContentTypeForm {
|
||||
@@ -353,7 +353,7 @@ func GogsHooksEditPost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func gogsHookParams(ctx *context.Context) webhookParams {
|
||||
form := web.GetForm(ctx).(*forms.NewGogshookForm)
|
||||
form := web.GetForm[*forms.NewGogshookForm](ctx)
|
||||
|
||||
contentType := webhook.ContentTypeJSON
|
||||
if webhook.HookContentType(form.ContentType) == webhook.ContentTypeForm {
|
||||
@@ -379,7 +379,7 @@ func DiscordHooksEditPost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func discordHookParams(ctx *context.Context) webhookParams {
|
||||
form := web.GetForm(ctx).(*forms.NewDiscordHookForm)
|
||||
form := web.GetForm[*forms.NewDiscordHookForm](ctx)
|
||||
|
||||
return webhookParams{
|
||||
Type: webhook_module.DISCORD,
|
||||
@@ -404,7 +404,7 @@ func DingtalkHooksEditPost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func dingtalkHookParams(ctx *context.Context) webhookParams {
|
||||
form := web.GetForm(ctx).(*forms.NewDingtalkHookForm)
|
||||
form := web.GetForm[*forms.NewDingtalkHookForm](ctx)
|
||||
|
||||
return webhookParams{
|
||||
Type: webhook_module.DINGTALK,
|
||||
@@ -425,7 +425,7 @@ func TelegramHooksEditPost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func telegramHookParams(ctx *context.Context) webhookParams {
|
||||
form := web.GetForm(ctx).(*forms.NewTelegramHookForm)
|
||||
form := web.GetForm[*forms.NewTelegramHookForm](ctx)
|
||||
|
||||
return webhookParams{
|
||||
Type: webhook_module.TELEGRAM,
|
||||
@@ -459,7 +459,7 @@ func matrixRoomIDEncode(roomID string) string {
|
||||
}
|
||||
|
||||
func matrixHookParams(ctx *context.Context) webhookParams {
|
||||
form := web.GetForm(ctx).(*forms.NewMatrixHookForm)
|
||||
form := web.GetForm[*forms.NewMatrixHookForm](ctx)
|
||||
|
||||
// TODO: need to migrate to the latest (v3) API: https://spec.matrix.org/v1.18/client-server-api/
|
||||
return webhookParams{
|
||||
@@ -487,7 +487,7 @@ func MSTeamsHooksEditPost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func mSTeamsHookParams(ctx *context.Context) webhookParams {
|
||||
form := web.GetForm(ctx).(*forms.NewMSTeamsHookForm)
|
||||
form := web.GetForm[*forms.NewMSTeamsHookForm](ctx)
|
||||
|
||||
return webhookParams{
|
||||
Type: webhook_module.MSTEAMS,
|
||||
@@ -508,7 +508,7 @@ func SlackHooksEditPost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func slackHookParams(ctx *context.Context) webhookParams {
|
||||
form := web.GetForm(ctx).(*forms.NewSlackHookForm)
|
||||
form := web.GetForm[*forms.NewSlackHookForm](ctx)
|
||||
|
||||
return webhookParams{
|
||||
Type: webhook_module.SLACK,
|
||||
@@ -535,7 +535,7 @@ func FeishuHooksEditPost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func feishuHookParams(ctx *context.Context) webhookParams {
|
||||
form := web.GetForm(ctx).(*forms.NewFeishuHookForm)
|
||||
form := web.GetForm[*forms.NewFeishuHookForm](ctx)
|
||||
|
||||
return webhookParams{
|
||||
Type: webhook_module.FEISHU,
|
||||
@@ -556,7 +556,7 @@ func WechatworkHooksEditPost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func wechatworkHookParams(ctx *context.Context) webhookParams {
|
||||
form := web.GetForm(ctx).(*forms.NewWechatWorkHookForm)
|
||||
form := web.GetForm[*forms.NewWechatWorkHookForm](ctx)
|
||||
|
||||
return webhookParams{
|
||||
Type: webhook_module.WECHATWORK,
|
||||
@@ -577,7 +577,7 @@ func PackagistHooksEditPost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func packagistHookParams(ctx *context.Context) webhookParams {
|
||||
form := web.GetForm(ctx).(*forms.NewPackagistHookForm)
|
||||
form := web.GetForm[*forms.NewPackagistHookForm](ctx)
|
||||
|
||||
return webhookParams{
|
||||
Type: webhook_module.PACKAGIST,
|
||||
|
||||
@@ -655,7 +655,7 @@ func NewWiki(ctx *context.Context) {
|
||||
|
||||
// NewWikiPost response for wiki create request
|
||||
func NewWikiPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.NewWikiForm)
|
||||
form := web.GetForm[*forms.NewWikiForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page")
|
||||
|
||||
if ctx.HasError() {
|
||||
@@ -711,7 +711,7 @@ func EditWiki(ctx *context.Context) {
|
||||
|
||||
// EditWikiPost response for wiki modify request
|
||||
func EditWikiPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.NewWikiForm)
|
||||
form := web.GetForm[*forms.NewWikiForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page")
|
||||
|
||||
if ctx.HasError() {
|
||||
|
||||
@@ -251,7 +251,7 @@ func RunnersEditPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.EditRunnerForm)
|
||||
form := web.GetForm[*forms.EditRunnerForm](ctx)
|
||||
runner.Description = form.Description
|
||||
|
||||
err = actions_model.UpdateRunner(ctx, runner, "description")
|
||||
|
||||
@@ -122,7 +122,7 @@ func VariableCreate(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.EditVariableForm)
|
||||
form := web.GetForm[*forms.EditVariableForm](ctx)
|
||||
|
||||
v, err := actions_service.CreateVariable(ctx, vCtx.OwnerID, vCtx.RepoID, form.Name, form.Data, form.Description)
|
||||
if err != nil {
|
||||
@@ -154,7 +154,7 @@ func VariableUpdate(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.EditVariableForm)
|
||||
form := web.GetForm[*forms.EditVariableForm](ctx)
|
||||
variable.Name = form.Name
|
||||
variable.Data = form.Data
|
||||
variable.Description = form.Description
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func GetLabelEditForm(ctx *context.Context) *forms.CreateLabelForm {
|
||||
form := web.GetForm(ctx).(*forms.CreateLabelForm)
|
||||
form := web.GetForm[*forms.CreateLabelForm](ctx)
|
||||
if ctx.HasError() {
|
||||
ctx.JSONError(ctx.GetErrMsg())
|
||||
return nil
|
||||
|
||||
@@ -63,7 +63,7 @@ func PerformRuleEditPost(ctx *context.Context, owner *user_model.User, redirectU
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.PackageCleanupRuleForm)
|
||||
form := web.GetForm[*forms.PackageCleanupRuleForm](ctx)
|
||||
|
||||
if form.Action == "remove" {
|
||||
if err := packages_model.DeleteCleanupRuleByID(ctx, pcr.ID); err != nil {
|
||||
@@ -85,7 +85,7 @@ func performRuleEditPost(ctx *context.Context, owner *user_model.User, pcr *pack
|
||||
pcr = &packages_model.PackageCleanupRule{}
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.PackageCleanupRuleForm)
|
||||
form := web.GetForm[*forms.PackageCleanupRuleForm](ctx)
|
||||
|
||||
pcr.Enabled = form.Enabled
|
||||
pcr.OwnerID = owner.ID
|
||||
|
||||
@@ -78,7 +78,7 @@ func MoveColumns(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func AddColumnToProjectPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.EditProjectColumnForm)
|
||||
form := web.GetForm[*forms.EditProjectColumnForm](ctx)
|
||||
project := findProject(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
@@ -98,7 +98,7 @@ func AddColumnToProjectPost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func EditProjectColumn(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.EditProjectColumnForm)
|
||||
form := web.GetForm[*forms.EditProjectColumnForm](ctx)
|
||||
_, column := findColumn(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
|
||||
@@ -27,7 +27,7 @@ func SetSecretsContext(ctx *context.Context, ownerID, repoID int64) {
|
||||
}
|
||||
|
||||
func PerformSecretsPost(ctx *context.Context, ownerID, repoID int64, redirectURL string) {
|
||||
form := web.GetForm(ctx).(*forms.AddSecretForm)
|
||||
form := web.GetForm[*forms.AddSecretForm](ctx)
|
||||
|
||||
s, _, err := secret_service.CreateOrUpdateSecret(ctx, ownerID, repoID, form.Name, util.NormalizeStringEOL(form.Data), form.Description)
|
||||
if err != nil {
|
||||
|
||||
@@ -66,7 +66,7 @@ func BlockedUsersPost(ctx *context.Context, blocker *user_model.User, redirect s
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.BlockUserForm)
|
||||
form := web.GetForm[*forms.BlockUserForm](ctx)
|
||||
err := blockedUsersPost(ctx, form, blocker)
|
||||
if err == nil {
|
||||
ctx.JSONRedirect(redirect)
|
||||
|
||||
@@ -455,7 +455,7 @@ func PackageSettings(ctx *context.Context) {
|
||||
|
||||
// PackageSettingsPost updates the package settings
|
||||
func PackageSettingsPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.PackageSettingForm)
|
||||
form := web.GetForm[*forms.PackageSettingForm](ctx)
|
||||
switch form.Action {
|
||||
case "link":
|
||||
packageSettingsPostActionLink(ctx, form)
|
||||
|
||||
@@ -56,7 +56,7 @@ func AccountPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.ChangePasswordForm)
|
||||
form := web.GetForm[*forms.ChangePasswordForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("settings_title")
|
||||
ctx.Data["PageIsSettingsAccount"] = true
|
||||
ctx.Data["Email"] = ctx.Doer.Email
|
||||
@@ -106,7 +106,7 @@ func EmailPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.AddEmailForm)
|
||||
form := web.GetForm[*forms.AddEmailForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("settings_title")
|
||||
ctx.Data["PageIsSettingsAccount"] = true
|
||||
ctx.Data["Email"] = ctx.Doer.Email
|
||||
|
||||
@@ -34,7 +34,7 @@ func Applications(ctx *context.Context) {
|
||||
|
||||
// ApplicationsPost response for add user's access token
|
||||
func ApplicationsPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.NewAccessTokenForm)
|
||||
form := web.GetForm[*forms.NewAccessTokenForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("settings_title")
|
||||
ctx.Data["PageIsSettingsApplications"] = true
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ func Keys(ctx *context.Context) {
|
||||
|
||||
// KeysPost response for change user's SSH/GPG keys
|
||||
func KeysPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.AddKeyForm)
|
||||
form := web.GetForm[*forms.AddKeyForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("settings_title")
|
||||
ctx.Data["PageIsSettingsKeys"] = true
|
||||
ctx.Data["DisableSSH"] = setting.SSH.Disabled
|
||||
@@ -98,6 +98,8 @@ func KeysPost(ctx *context.Context) {
|
||||
}
|
||||
if err != nil {
|
||||
ctx.Data["HasGPGError"] = true
|
||||
var errInvalidTokenSignature asymkey_model.ErrGPGInvalidTokenSignature
|
||||
var errNoEmailFound asymkey_model.ErrGPGNoEmailFound
|
||||
switch {
|
||||
case asymkey_model.IsErrGPGKeyParsing(err):
|
||||
ctx.Flash.Error(ctx.Tr("form.invalid_gpg_key", err.Error()))
|
||||
@@ -107,20 +109,20 @@ func KeysPost(ctx *context.Context) {
|
||||
|
||||
ctx.Data["Err_Content"] = true
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("settings.gpg_key_id_used"), tplSettingsKeys, &form)
|
||||
case asymkey_model.IsErrGPGInvalidTokenSignature(err):
|
||||
case errors.As(err, &errInvalidTokenSignature):
|
||||
loadKeysData(ctx)
|
||||
ctx.Data["Err_Content"] = true
|
||||
ctx.Data["Err_Signature"] = true
|
||||
keyID := err.(asymkey_model.ErrGPGInvalidTokenSignature).ID
|
||||
keyID := errInvalidTokenSignature.ID
|
||||
ctx.Data["KeyID"] = keyID
|
||||
ctx.Data["PaddedKeyID"] = asymkey_model.PaddedKeyID(keyID)
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("settings.gpg_invalid_token_signature"), tplSettingsKeys, &form)
|
||||
case asymkey_model.IsErrGPGNoEmailFound(err):
|
||||
case errors.As(err, &errNoEmailFound):
|
||||
loadKeysData(ctx)
|
||||
|
||||
ctx.Data["Err_Content"] = true
|
||||
ctx.Data["Err_Signature"] = true
|
||||
keyID := err.(asymkey_model.ErrGPGNoEmailFound).ID
|
||||
keyID := errNoEmailFound.ID
|
||||
ctx.Data["KeyID"] = keyID
|
||||
ctx.Data["PaddedKeyID"] = asymkey_model.PaddedKeyID(keyID)
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("settings.gpg_no_key_email_found"), tplSettingsKeys, &form)
|
||||
@@ -149,12 +151,13 @@ func KeysPost(ctx *context.Context) {
|
||||
}
|
||||
if err != nil {
|
||||
ctx.Data["HasGPGVerifyError"] = true
|
||||
var errInvalidTokenSignature asymkey_model.ErrGPGInvalidTokenSignature
|
||||
switch {
|
||||
case asymkey_model.IsErrGPGInvalidTokenSignature(err):
|
||||
case errors.As(err, &errInvalidTokenSignature):
|
||||
loadKeysData(ctx)
|
||||
ctx.Data["VerifyingID"] = form.KeyID
|
||||
ctx.Data["Err_Signature"] = true
|
||||
keyID := err.(asymkey_model.ErrGPGInvalidTokenSignature).ID
|
||||
keyID := errInvalidTokenSignature.ID
|
||||
ctx.Data["KeyID"] = keyID
|
||||
ctx.Data["PaddedKeyID"] = asymkey_model.PaddedKeyID(keyID)
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("settings.gpg_invalid_token_signature"), tplSettingsKeys, &form)
|
||||
@@ -224,11 +227,12 @@ func KeysPost(ctx *context.Context) {
|
||||
}
|
||||
if err != nil {
|
||||
ctx.Data["HasSSHVerifyError"] = true
|
||||
var errInvalidTokenSignature asymkey_model.ErrSSHInvalidTokenSignature
|
||||
switch {
|
||||
case asymkey_model.IsErrSSHInvalidTokenSignature(err):
|
||||
case errors.As(err, &errInvalidTokenSignature):
|
||||
loadKeysData(ctx)
|
||||
ctx.Data["Err_Signature"] = true
|
||||
ctx.Data["Fingerprint"] = err.(asymkey_model.ErrSSHInvalidTokenSignature).Fingerprint
|
||||
ctx.Data["Fingerprint"] = errInvalidTokenSignature.Fingerprint
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("settings.ssh_invalid_token_signature"), tplSettingsKeys, &form)
|
||||
default:
|
||||
ctx.ServerError("VerifySSH", err)
|
||||
|
||||
@@ -23,8 +23,8 @@ type OAuth2CommonHandlers struct {
|
||||
TplAppEdit templates.TplName // the template for the application edit page
|
||||
}
|
||||
|
||||
func (oa *OAuth2CommonHandlers) renderEditPage(ctx *context.Context) {
|
||||
app := ctx.Data["App"].(*auth.OAuth2Application)
|
||||
func (oa *OAuth2CommonHandlers) renderEditPage(ctx *context.Context, app *auth.OAuth2Application) {
|
||||
ctx.Data["App"] = app
|
||||
ctx.Data["FormActionPath"] = fmt.Sprintf("%s/%d", oa.BasePathEditPrefix, app.ID)
|
||||
|
||||
if ctx.ContextUser != nil && ctx.ContextUser.IsOrganization() {
|
||||
@@ -39,7 +39,7 @@ func (oa *OAuth2CommonHandlers) renderEditPage(ctx *context.Context) {
|
||||
|
||||
// AddApp adds an oauth2 application
|
||||
func (oa *OAuth2CommonHandlers) AddApp(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.EditOAuth2ApplicationForm)
|
||||
form := web.GetForm[*forms.EditOAuth2ApplicationForm](ctx)
|
||||
if ctx.HasError() {
|
||||
ctx.Flash.Error(ctx.GetErrMsg())
|
||||
// go to the application list page
|
||||
@@ -61,14 +61,13 @@ func (oa *OAuth2CommonHandlers) AddApp(ctx *context.Context) {
|
||||
|
||||
// render the edit page with secret
|
||||
ctx.Flash.Success(ctx.Tr("settings.create_oauth2_application_success"), true)
|
||||
ctx.Data["App"] = app
|
||||
ctx.Data["ClientSecret"], err = app.GenerateClientSecret(ctx)
|
||||
if err != nil {
|
||||
ctx.ServerError("GenerateClientSecret", err)
|
||||
return
|
||||
}
|
||||
|
||||
oa.renderEditPage(ctx)
|
||||
oa.renderEditPage(ctx, app)
|
||||
}
|
||||
|
||||
// EditShow displays the given application
|
||||
@@ -86,13 +85,12 @@ func (oa *OAuth2CommonHandlers) EditShow(ctx *context.Context) {
|
||||
ctx.NotFound(nil)
|
||||
return
|
||||
}
|
||||
ctx.Data["App"] = app
|
||||
oa.renderEditPage(ctx)
|
||||
oa.renderEditPage(ctx, app)
|
||||
}
|
||||
|
||||
// EditSave saves the oauth2 application
|
||||
func (oa *OAuth2CommonHandlers) EditSave(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.EditOAuth2ApplicationForm)
|
||||
form := web.GetForm[*forms.EditOAuth2ApplicationForm](ctx)
|
||||
|
||||
if ctx.HasError() {
|
||||
app, err := auth.GetOAuth2ApplicationByID(ctx, ctx.PathParamInt64("id"))
|
||||
@@ -108,9 +106,7 @@ func (oa *OAuth2CommonHandlers) EditSave(ctx *context.Context) {
|
||||
ctx.NotFound(nil)
|
||||
return
|
||||
}
|
||||
ctx.Data["App"] = app
|
||||
|
||||
oa.renderEditPage(ctx)
|
||||
oa.renderEditPage(ctx, app)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -145,14 +141,13 @@ func (oa *OAuth2CommonHandlers) RegenerateSecret(ctx *context.Context) {
|
||||
ctx.NotFound(nil)
|
||||
return
|
||||
}
|
||||
ctx.Data["App"] = app
|
||||
ctx.Data["ClientSecret"], err = app.GenerateClientSecret(ctx)
|
||||
if err != nil {
|
||||
ctx.ServerError("GenerateClientSecret", err)
|
||||
return
|
||||
}
|
||||
ctx.Flash.Success(ctx.Tr("settings.update_oauth2_application_success"), true)
|
||||
oa.renderEditPage(ctx)
|
||||
oa.renderEditPage(ctx, app)
|
||||
}
|
||||
|
||||
// DeleteApp deletes the given oauth2 application
|
||||
|
||||
@@ -65,7 +65,7 @@ func ProfilePost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.UpdateProfileForm)
|
||||
form := web.GetForm[*forms.UpdateProfileForm](ctx)
|
||||
|
||||
if form.Name != "" {
|
||||
if user_model.IsFeatureDisabledWithLoginType(ctx.Doer, setting.UserFeatureChangeUsername) {
|
||||
@@ -175,7 +175,7 @@ func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser *
|
||||
|
||||
// AvatarPost response for change user's avatar request
|
||||
func AvatarPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.AvatarForm)
|
||||
form := web.GetForm[*forms.AvatarForm](ctx)
|
||||
if err := UpdateAvatarSetting(ctx, form, ctx.Doer); err != nil {
|
||||
ctx.Flash.Error(err.Error())
|
||||
} else {
|
||||
@@ -354,7 +354,7 @@ func Appearance(ctx *context.Context) {
|
||||
|
||||
// UpdateUIThemePost is used to update users' specific theme
|
||||
func UpdateUIThemePost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.UpdateThemeForm)
|
||||
form := web.GetForm[*forms.UpdateThemeForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("settings_title")
|
||||
ctx.Data["PageIsSettingsAppearance"] = true
|
||||
|
||||
@@ -384,7 +384,7 @@ func UpdateUIThemePost(ctx *context.Context) {
|
||||
|
||||
// UpdateUserLang update a user's language
|
||||
func UpdateUserLang(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.UpdateLanguageForm)
|
||||
form := web.GetForm[*forms.UpdateLanguageForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("settings_title")
|
||||
ctx.Data["PageIsSettingsAppearance"] = true
|
||||
|
||||
|
||||
@@ -100,9 +100,8 @@ func DisableTwoFactor(ctx *context.Context) {
|
||||
func twofaGenerateSecretAndQr(ctx *context.Context) bool {
|
||||
var otpKey *otp.Key
|
||||
var err error
|
||||
uri := ctx.Session.Get("twofaUri")
|
||||
if uri != nil {
|
||||
otpKey, err = otp.NewKeyFromURL(uri.(string))
|
||||
if uri, ok := ctx.Session.Get("twofaUri").(string); ok {
|
||||
otpKey, err = otp.NewKeyFromURL(uri)
|
||||
if err != nil {
|
||||
ctx.ServerError("SettingsTwoFactor: Failed NewKeyFromURL: ", err)
|
||||
return false
|
||||
@@ -193,7 +192,7 @@ func EnrollTwoFactorPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.TwoFactorAuthForm)
|
||||
form := web.GetForm[*forms.TwoFactorAuthForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("settings_title")
|
||||
ctx.Data["PageIsSettingsSecurity"] = true
|
||||
ctx.Data["ShowTwoFactorRequiredMessage"] = false
|
||||
@@ -218,14 +217,13 @@ func EnrollTwoFactorPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
secretRaw := ctx.Session.Get("twofaSecret")
|
||||
if secretRaw == nil {
|
||||
secret, ok := ctx.Session.Get("twofaSecret").(string)
|
||||
if !ok {
|
||||
ctx.Flash.Error(ctx.Tr("settings.twofa_failed_get_secret"))
|
||||
ctx.Redirect(setting.AppSubURL + "/user/settings/security/two_factor/enroll")
|
||||
return
|
||||
}
|
||||
|
||||
secret := secretRaw.(string)
|
||||
if !totp.Validate(form.Passcode, secret) {
|
||||
if !twofaGenerateSecretAndQr(ctx) {
|
||||
return
|
||||
|
||||
@@ -24,7 +24,7 @@ func OpenIDPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.AddOpenIDForm)
|
||||
form := web.GetForm[*forms.AddOpenIDForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("settings_title")
|
||||
ctx.Data["PageIsSettingsSecurity"] = true
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ func WebAuthnRegister(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.WebauthnRegistrationForm)
|
||||
form := web.GetForm[*forms.WebauthnRegistrationForm](ctx)
|
||||
if form.Name == "" {
|
||||
// Set name to the hexadecimal of the current time
|
||||
form.Name = strconv.FormatInt(time.Now().UnixNano(), 16)
|
||||
|
||||
+7
-9
@@ -244,11 +244,9 @@ func verifyAuthWithOptions(options *common.VerifyOptions) func(ctx *context.Cont
|
||||
}
|
||||
}
|
||||
|
||||
func ctxDataSet(args ...any) func(ctx *context.Context) {
|
||||
func ctxDataSet(data reqctx.ContextData) func(ctx *context.Context) {
|
||||
return func(ctx *context.Context) {
|
||||
for i := 0; i < len(args); i += 2 {
|
||||
ctx.Data[args[i].(string)] = args[i+1]
|
||||
}
|
||||
ctx.Data.MergeFrom(data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -893,7 +891,7 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
||||
addSettingsVariablesRoutes()
|
||||
addSettingsScopedWorkflowsRoutes()
|
||||
})
|
||||
}, adminReq, ctxDataSet("EnableOAuth2", setting.OAuth2.Enabled, "EnablePackages", setting.Packages.Enabled))
|
||||
}, adminReq, ctxDataSet(reqctx.ContextData{"EnableOAuth2": setting.OAuth2.Enabled, "EnablePackages": setting.Packages.Enabled}))
|
||||
// ***** END: Admin *****
|
||||
|
||||
m.Group("", func() {
|
||||
@@ -1079,7 +1077,7 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
||||
m.Get("", org.BlockedUsers)
|
||||
m.Post("", web.Bind(forms.BlockUserForm{}), org.BlockedUsersPost)
|
||||
})
|
||||
}, ctxDataSet("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}))
|
||||
}, reqSignIn)
|
||||
// end "/org": most org routes
|
||||
@@ -1268,7 +1266,7 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
||||
})
|
||||
},
|
||||
reqSignIn, context.RepoAssignment, reqRepoAdmin,
|
||||
ctxDataSet("PageIsRepoSettings", true, "LFSStartServer", setting.LFS.StartServer),
|
||||
ctxDataSet(reqctx.ContextData{"PageIsRepoSettings": true, "LFSStartServer": setting.LFS.StartServer}),
|
||||
)
|
||||
// end "/{username}/{reponame}/settings"
|
||||
|
||||
@@ -1481,7 +1479,7 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
||||
m.Get(".rss", webAuth.AllowBasic, feedEnabled, repo.TagsListFeedRSS)
|
||||
m.Get(".atom", webAuth.AllowBasic, feedEnabled, repo.TagsListFeedAtom)
|
||||
m.Get("/list", repo.GetTagList)
|
||||
}, ctxDataSet("EnableFeed", setting.Other.EnableFeed))
|
||||
}, ctxDataSet(reqctx.ContextData{"EnableFeed": setting.Other.EnableFeed}))
|
||||
m.Post("/tags/delete", reqSignIn, reqRepoCodeWriter, context.RepoMustNotBeArchived(), repo.DeleteTag)
|
||||
}, optSignIn, context.RepoAssignment, repo.MustBeNotEmpty, reqUnitCodeReader)
|
||||
// end "/{username}/{reponame}": repo tags
|
||||
@@ -1493,7 +1491,7 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
||||
m.Get(".atom", webAuth.AllowBasic, feedEnabled, repo.ReleasesFeedAtom)
|
||||
m.Get("/tag/*", repo.SingleRelease)
|
||||
m.Get("/latest", repo.LatestRelease)
|
||||
}, ctxDataSet("EnableFeed", setting.Other.EnableFeed))
|
||||
}, ctxDataSet(reqctx.ContextData{"EnableFeed": setting.Other.EnableFeed}))
|
||||
m.Get("/releases/attachments/{uuid}", webAuth.AllowBasic, webAuth.AllowOAuth2, repo.GetAttachment)
|
||||
m.Get("/releases/download/{vTag}/{fileName}", webAuth.AllowBasic, webAuth.AllowOAuth2, repo.RedirectDownload)
|
||||
m.Group("/releases", func() {
|
||||
|
||||
Reference in New Issue
Block a user