From a8a37fccd1b50acce99ca7e4b295664b059dde32 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Wed, 30 Aug 2023 08:52:50 +0200 Subject: [PATCH] Don't allow visting {repo}/issues/new when blank issues are disabled --- routers/web/repo/issue.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index b8b5a2dff26d5..f5e8f80ddfe2e 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -902,9 +902,17 @@ func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleFiles // NewIssue render creating issue page func NewIssue(ctx *context.Context) { + issueConfig, _ := issue_service.GetTemplateConfigFromDefaultBranch(ctx.Repo.Repository, ctx.Repo.GitRepo) + hasTemplates := issue_service.HasTemplatesOrContactLinks(ctx.Repo.Repository, ctx.Repo.GitRepo) + if !issueConfig.BlankIssuesEnabled && hasTemplates { + // The "issues/new" and "issues/new/choose" share the same query parameters "project" and "milestone", if blank issues are disabled, just redirect to the "issues/choose" page with these parameters. + ctx.Redirect(fmt.Sprintf("%s/issues/new/choose?%s", ctx.Repo.Repository.Link(), ctx.Req.URL.RawQuery), http.StatusSeeOther) + return + } + ctx.Data["Title"] = ctx.Tr("repo.issues.new") ctx.Data["PageIsIssueList"] = true - ctx.Data["NewIssueChooseTemplate"] = issue_service.HasTemplatesOrContactLinks(ctx.Repo.Repository, ctx.Repo.GitRepo) + ctx.Data["NewIssueChooseTemplate"] = hasTemplates ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes title := ctx.FormString("title") ctx.Data["TitleQuery"] = title