From 41dbce43be680456db0205e73d33842076dce31c Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Wed, 10 Apr 2024 07:49:39 +0000 Subject: [PATCH 1/4] fix --- routers/web/org/projects.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/routers/web/org/projects.go b/routers/web/org/projects.go index 596a370d2e551..1859fd47ce43e 100644 --- a/routers/web/org/projects.go +++ b/routers/web/org/projects.go @@ -202,15 +202,20 @@ func ChangeProjectStatus(ctx *context.Context) { case "close": toClose = true default: - ctx.Redirect(ctx.ContextUser.HomeLink() + "/-/projects") + ctx.JSONRedirect(ctx.ContextUser.HomeLink() + "/-/projects") + return } id := ctx.ParamsInt64(":id") if err := project_model.ChangeProjectStatusByRepoIDAndID(ctx, 0, id, toClose); err != nil { - ctx.NotFoundOrServerError("ChangeProjectStatusByRepoIDAndID", project_model.IsErrProjectNotExist, err) + if project_model.IsErrProjectNotExist(err) { + ctx.NotFound("", err) + } else { + ctx.ServerError("ChangeProjectStatusByRepoIDAndID", err) + } return } - ctx.Redirect(ctx.ContextUser.HomeLink() + "/-/projects?state=" + url.QueryEscape(ctx.Params(":action"))) + ctx.JSONRedirect(ctx.ContextUser.HomeLink() + "/-/projects?state=" + url.QueryEscape(ctx.Params(":action"))) } // DeleteProject delete a project From 600933068106261a2a3343fa630dfdc83dd55514 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Wed, 10 Apr 2024 07:52:43 +0000 Subject: [PATCH 2/4] fix --- routers/web/org/projects.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/web/org/projects.go b/routers/web/org/projects.go index 1859fd47ce43e..2dce45faec63e 100644 --- a/routers/web/org/projects.go +++ b/routers/web/org/projects.go @@ -195,7 +195,7 @@ 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 From 3348c8352cc19f9a33503df62b485306a050d31c Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Wed, 10 Apr 2024 23:41:45 +0000 Subject: [PATCH 3/4] fix --- routers/web/org/projects.go | 6 +----- routers/web/repo/projects.go | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/routers/web/org/projects.go b/routers/web/org/projects.go index 2dce45faec63e..5844a9f277299 100644 --- a/routers/web/org/projects.go +++ b/routers/web/org/projects.go @@ -208,11 +208,7 @@ func ChangeProjectStatus(ctx *context.Context) { id := ctx.ParamsInt64(":id") if err := project_model.ChangeProjectStatusByRepoIDAndID(ctx, 0, id, toClose); err != nil { - if project_model.IsErrProjectNotExist(err) { - ctx.NotFound("", err) - } else { - ctx.ServerError("ChangeProjectStatusByRepoIDAndID", err) - } + ctx.NotFoundOrServerError("ChangeProjectStatusByRepoIDAndID", project_model.IsErrProjectNotExist, err) return } ctx.JSONRedirect(ctx.ContextUser.HomeLink() + "/-/projects?state=" + url.QueryEscape(ctx.Params(":action"))) diff --git a/routers/web/repo/projects.go b/routers/web/repo/projects.go index a2db1fc770a5b..6b15f28b8c1e6 100644 --- a/routers/web/repo/projects.go +++ b/routers/web/repo/projects.go @@ -181,11 +181,7 @@ func ChangeProjectStatus(ctx *context.Context) { id := ctx.ParamsInt64(":id") if err := project_model.ChangeProjectStatusByRepoIDAndID(ctx, ctx.Repo.Repository.ID, id, toClose); err != nil { - if project_model.IsErrProjectNotExist(err) { - ctx.NotFound("", err) - } else { - ctx.ServerError("ChangeProjectStatusByIDAndRepoID", err) - } + ctx.NotFoundOrServerError("ChangeProjectStatusByRepoIDAndID", project_model.IsErrProjectNotExist, err) return } ctx.JSONRedirect(ctx.Repo.RepoLink + "/projects?state=" + url.QueryEscape(ctx.Params(":action"))) From c7fa9dcaf63eb45021f5d86f69d325121a5a05b8 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Wed, 10 Apr 2024 23:47:11 +0000 Subject: [PATCH 4/4] redirect to project page --- routers/web/org/projects.go | 3 +-- routers/web/repo/projects.go | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/routers/web/org/projects.go b/routers/web/org/projects.go index 5844a9f277299..d439b11cf926f 100644 --- a/routers/web/org/projects.go +++ b/routers/web/org/projects.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "net/http" - "net/url" "strconv" "strings" @@ -211,7 +210,7 @@ func ChangeProjectStatus(ctx *context.Context) { ctx.NotFoundOrServerError("ChangeProjectStatusByRepoIDAndID", project_model.IsErrProjectNotExist, err) return } - ctx.JSONRedirect(ctx.ContextUser.HomeLink() + "/-/projects?state=" + url.QueryEscape(ctx.Params(":action"))) + ctx.JSONRedirect(fmt.Sprintf("%s/-/projects/%d", ctx.ContextUser.HomeLink(), id)) } // DeleteProject delete a project diff --git a/routers/web/repo/projects.go b/routers/web/repo/projects.go index 6b15f28b8c1e6..9b765e89e877f 100644 --- a/routers/web/repo/projects.go +++ b/routers/web/repo/projects.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "net/http" - "net/url" "strings" "code.gitea.io/gitea/models/db" @@ -184,7 +183,7 @@ func ChangeProjectStatus(ctx *context.Context) { ctx.NotFoundOrServerError("ChangeProjectStatusByRepoIDAndID", project_model.IsErrProjectNotExist, err) return } - ctx.JSONRedirect(ctx.Repo.RepoLink + "/projects?state=" + url.QueryEscape(ctx.Params(":action"))) + ctx.JSONRedirect(fmt.Sprintf("%s/projects/%d", ctx.Repo.RepoLink, id)) } // DeleteProject delete a project