Skip to content

Commit d1a2780

Browse files
JakobDevGiteaBot
andcommitted
Redirect from {repo}/issues/new to {repo}/issues/new/choose when blank issues are disabled (go-gitea#26813)
You can currently visit `{repo}/issues/new` and create a blank issue, even if it's disabled. This PR fixes this, Fixes https://codeberg.org/forgejo/forgejo/issues/1356 Co-authored-by: Giteabot <teabot@gitea.io>
1 parent 93c36f3 commit d1a2780

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

routers/web/repo/issue.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -877,9 +877,17 @@ func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleFiles
877877

878878
// NewIssue render creating issue page
879879
func NewIssue(ctx *context.Context) {
880+
issueConfig, _ := issue_service.GetTemplateConfigFromDefaultBranch(ctx.Repo.Repository, ctx.Repo.GitRepo)
881+
hasTemplates := issue_service.HasTemplatesOrContactLinks(ctx.Repo.Repository, ctx.Repo.GitRepo)
882+
if !issueConfig.BlankIssuesEnabled && hasTemplates {
883+
// 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.
884+
ctx.Redirect(fmt.Sprintf("%s/issues/new/choose?%s", ctx.Repo.Repository.Link(), ctx.Req.URL.RawQuery), http.StatusSeeOther)
885+
return
886+
}
887+
880888
ctx.Data["Title"] = ctx.Tr("repo.issues.new")
881889
ctx.Data["PageIsIssueList"] = true
882-
ctx.Data["NewIssueChooseTemplate"] = issue_service.HasTemplatesOrContactLinks(ctx.Repo.Repository, ctx.Repo.GitRepo)
890+
ctx.Data["NewIssueChooseTemplate"] = hasTemplates
883891
ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
884892
title := ctx.FormString("title")
885893
ctx.Data["TitleQuery"] = title

0 commit comments

Comments
 (0)