Fix network error when open/close organization/individual projects and redirect to project page (#30387) (#30465)
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> (cherry picked from commit 3735797b3366c983de5b199a50f4c1015e8cb807)
This commit is contained in:
parent
4fe72284fc
commit
fb91390b48
2 changed files with 6 additions and 11 deletions
|
@ -7,7 +7,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -195,14 +194,15 @@ func NewProjectPost(ctx *context.Context) {
|
||||||
|
|
||||||
// ChangeProjectStatus updates the status of a project between "open" and "close"
|
// ChangeProjectStatus updates the status of a project between "open" and "close"
|
||||||
func ChangeProjectStatus(ctx *context.Context) {
|
func ChangeProjectStatus(ctx *context.Context) {
|
||||||
toClose := false
|
var toClose bool
|
||||||
switch ctx.Params(":action") {
|
switch ctx.Params(":action") {
|
||||||
case "open":
|
case "open":
|
||||||
toClose = false
|
toClose = false
|
||||||
case "close":
|
case "close":
|
||||||
toClose = true
|
toClose = true
|
||||||
default:
|
default:
|
||||||
ctx.Redirect(ctx.ContextUser.HomeLink() + "/-/projects")
|
ctx.JSONRedirect(ctx.ContextUser.HomeLink() + "/-/projects")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
id := ctx.ParamsInt64(":id")
|
id := ctx.ParamsInt64(":id")
|
||||||
|
|
||||||
|
@ -210,7 +210,7 @@ func ChangeProjectStatus(ctx *context.Context) {
|
||||||
ctx.NotFoundOrServerError("ChangeProjectStatusByRepoIDAndID", project_model.IsErrProjectNotExist, err)
|
ctx.NotFoundOrServerError("ChangeProjectStatusByRepoIDAndID", project_model.IsErrProjectNotExist, err)
|
||||||
return
|
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
|
// DeleteProject delete a project
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
|
@ -180,14 +179,10 @@ func ChangeProjectStatus(ctx *context.Context) {
|
||||||
id := ctx.ParamsInt64(":id")
|
id := ctx.ParamsInt64(":id")
|
||||||
|
|
||||||
if err := project_model.ChangeProjectStatusByRepoIDAndID(ctx, ctx.Repo.Repository.ID, id, toClose); err != nil {
|
if err := project_model.ChangeProjectStatusByRepoIDAndID(ctx, ctx.Repo.Repository.ID, id, toClose); err != nil {
|
||||||
if project_model.IsErrProjectNotExist(err) {
|
ctx.NotFoundOrServerError("ChangeProjectStatusByRepoIDAndID", project_model.IsErrProjectNotExist, err)
|
||||||
ctx.NotFound("", err)
|
|
||||||
} else {
|
|
||||||
ctx.ServerError("ChangeProjectStatusByIDAndRepoID", err)
|
|
||||||
}
|
|
||||||
return
|
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
|
// DeleteProject delete a project
|
||||||
|
|
Loading…
Reference in a new issue