]> source.dussan.org Git - gitea.git/commitdiff
Fix network error when open/close organization/individual projects and redirect to...
authorGiteabot <teabot@gitea.io>
Sat, 13 Apr 2024 17:53:14 +0000 (01:53 +0800)
committerGitHub <noreply@github.com>
Sat, 13 Apr 2024 17:53:14 +0000 (17:53 +0000)
Backport #30387 by @yp05327

Follow #27734

![image](https://github.com/go-gitea/gitea/assets/18380374/02ed6b9a-cbb6-4f49-a54a-ca76a0d052a9)

Updated:
Redirect to project page instead of project list page.

Co-authored-by: yp05327 <576951401@qq.com>
routers/web/org/projects.go
routers/web/repo/projects.go

index 596a370d2e551cf8a7eac627471f768c42a840b2..d439b11cf926f11bb418a7b74f8ce567633be39a 100644 (file)
@@ -7,7 +7,6 @@ import (
        "errors"
        "fmt"
        "net/http"
-       "net/url"
        "strconv"
        "strings"
 
@@ -195,14 +194,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.ContextUser.HomeLink() + "/-/projects")
+               ctx.JSONRedirect(ctx.ContextUser.HomeLink() + "/-/projects")
+               return
        }
        id := ctx.ParamsInt64(":id")
 
@@ -210,7 +210,7 @@ func ChangeProjectStatus(ctx *context.Context) {
                ctx.NotFoundOrServerError("ChangeProjectStatusByRepoIDAndID", project_model.IsErrProjectNotExist, err)
                return
        }
-       ctx.Redirect(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
index a2db1fc770a5b386cc607ecc1ed8f8f1ac1f4361..9b765e89e877fd06ce54931d3b6ba347d26962a9 100644 (file)
@@ -7,7 +7,6 @@ import (
        "errors"
        "fmt"
        "net/http"
-       "net/url"
        "strings"
 
        "code.gitea.io/gitea/models/db"
@@ -181,14 +180,10 @@ 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")))
+       ctx.JSONRedirect(fmt.Sprintf("%s/projects/%d", ctx.Repo.RepoLink, id))
 }
 
 // DeleteProject delete a project