Skip to content

Commit 3cae50e

Browse files
JakobDevGiteaBot
andauthored
Redirect from {repo}/issues/new to {repo}/issues/new/choose when blank issues are disabled (#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 <[email protected]>
1 parent d5703d4 commit 3cae50e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

routers/web/repo/issue.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,9 +902,17 @@ func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleFiles
902902

903903
// NewIssue render creating issue page
904904
func NewIssue(ctx *context.Context) {
905+
issueConfig, _ := issue_service.GetTemplateConfigFromDefaultBranch(ctx.Repo.Repository, ctx.Repo.GitRepo)
906+
hasTemplates := issue_service.HasTemplatesOrContactLinks(ctx.Repo.Repository, ctx.Repo.GitRepo)
907+
if !issueConfig.BlankIssuesEnabled && hasTemplates {
908+
// 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.
909+
ctx.Redirect(fmt.Sprintf("%s/issues/new/choose?%s", ctx.Repo.Repository.Link(), ctx.Req.URL.RawQuery), http.StatusSeeOther)
910+
return
911+
}
912+
905913
ctx.Data["Title"] = ctx.Tr("repo.issues.new")
906914
ctx.Data["PageIsIssueList"] = true
907-
ctx.Data["NewIssueChooseTemplate"] = issue_service.HasTemplatesOrContactLinks(ctx.Repo.Repository, ctx.Repo.GitRepo)
915+
ctx.Data["NewIssueChooseTemplate"] = hasTemplates
908916
ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
909917
title := ctx.FormString("title")
910918
ctx.Data["TitleQuery"] = title

0 commit comments

Comments
 (0)