From 5087de1a5cea9789d5c89f679d31b4a7fb4c5220 Mon Sep 17 00:00:00 2001 From: Giteabot Date: Mon, 23 Oct 2023 21:52:30 +0800 Subject: [PATCH] Fix `link-action` redirect network error (#27734) (#27749) Backport #27734 by @lng2020 image Co-authored-by: Nanguan Lin <70063547+lng2020@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de> --- routers/web/repo/milestone.go | 7 ++++--- routers/web/repo/projects.go | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/routers/web/repo/milestone.go b/routers/web/repo/milestone.go index df52ca352..eb27c4b00 100644 --- a/routers/web/repo/milestone.go +++ b/routers/web/repo/milestone.go @@ -225,14 +225,15 @@ func EditMilestonePost(ctx *context.Context) { // ChangeMilestoneStatus response for change a milestone's status func ChangeMilestoneStatus(ctx *context.Context) { - toClose := false + var toClose bool switch ctx.Params(":action") { case "open": toClose = false case "close": toClose = true default: - ctx.Redirect(ctx.Repo.RepoLink + "/milestones") + ctx.JSONRedirect(ctx.Repo.RepoLink + "/milestones") + return } id := ctx.ParamsInt64(":id") @@ -244,7 +245,7 @@ func ChangeMilestoneStatus(ctx *context.Context) { } return } - ctx.Redirect(ctx.Repo.RepoLink + "/milestones?state=" + url.QueryEscape(ctx.Params(":action"))) + ctx.JSONRedirect(ctx.Repo.RepoLink + "/milestones?state=" + url.QueryEscape(ctx.Params(":action"))) } // DeleteMilestone delete a milestone diff --git a/routers/web/repo/projects.go b/routers/web/repo/projects.go index 33bc79d96..7a9248fe8 100644 --- a/routers/web/repo/projects.go +++ b/routers/web/repo/projects.go @@ -161,14 +161,15 @@ func NewProjectPost(ctx *context.Context) { // ChangeProjectStatus updates the status of a project between "open" and "close" func ChangeProjectStatus(ctx *context.Context) { - toClose := false + var toClose bool switch ctx.Params(":action") { case "open": toClose = false case "close": toClose = true default: - ctx.Redirect(ctx.Repo.RepoLink + "/projects") + ctx.JSONRedirect(ctx.Repo.RepoLink + "/projects") + return } id := ctx.ParamsInt64(":id") @@ -180,7 +181,7 @@ func ChangeProjectStatus(ctx *context.Context) { } return } - ctx.Redirect(ctx.Repo.RepoLink + "/projects?state=" + url.QueryEscape(ctx.Params(":action"))) + ctx.JSONRedirect(ctx.Repo.RepoLink + "/projects?state=" + url.QueryEscape(ctx.Params(":action"))) } // DeleteProject delete a project