Skip to content

Commit fba0bb6

Browse files
yp05327GiteaBot
authored andcommitted
Fix network error when open/close organization/individual projects and redirect to project page (go-gitea#30387)
Follow go-gitea#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.
1 parent 846888f commit fba0bb6

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

routers/web/org/projects.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"errors"
88
"fmt"
99
"net/http"
10-
"net/url"
1110
"strconv"
1211
"strings"
1312

@@ -195,22 +194,23 @@ func NewProjectPost(ctx *context.Context) {
195194

196195
// ChangeProjectStatus updates the status of a project between "open" and "close"
197196
func ChangeProjectStatus(ctx *context.Context) {
198-
toClose := false
197+
var toClose bool
199198
switch ctx.Params(":action") {
200199
case "open":
201200
toClose = false
202201
case "close":
203202
toClose = true
204203
default:
205-
ctx.Redirect(ctx.ContextUser.HomeLink() + "/-/projects")
204+
ctx.JSONRedirect(ctx.ContextUser.HomeLink() + "/-/projects")
205+
return
206206
}
207207
id := ctx.ParamsInt64(":id")
208208

209209
if err := project_model.ChangeProjectStatusByRepoIDAndID(ctx, 0, id, toClose); err != nil {
210210
ctx.NotFoundOrServerError("ChangeProjectStatusByRepoIDAndID", project_model.IsErrProjectNotExist, err)
211211
return
212212
}
213-
ctx.Redirect(ctx.ContextUser.HomeLink() + "/-/projects?state=" + url.QueryEscape(ctx.Params(":action")))
213+
ctx.JSONRedirect(fmt.Sprintf("%s/-/projects/%d", ctx.ContextUser.HomeLink(), id))
214214
}
215215

216216
// DeleteProject delete a project

routers/web/repo/projects.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"errors"
88
"fmt"
99
"net/http"
10-
"net/url"
1110
"strings"
1211

1312
"code.gitea.io/gitea/models/db"
@@ -181,14 +180,10 @@ func ChangeProjectStatus(ctx *context.Context) {
181180
id := ctx.ParamsInt64(":id")
182181

183182
if err := project_model.ChangeProjectStatusByRepoIDAndID(ctx, ctx.Repo.Repository.ID, id, toClose); err != nil {
184-
if project_model.IsErrProjectNotExist(err) {
185-
ctx.NotFound("", err)
186-
} else {
187-
ctx.ServerError("ChangeProjectStatusByIDAndRepoID", err)
188-
}
183+
ctx.NotFoundOrServerError("ChangeProjectStatusByRepoIDAndID", project_model.IsErrProjectNotExist, err)
189184
return
190185
}
191-
ctx.JSONRedirect(ctx.Repo.RepoLink + "/projects?state=" + url.QueryEscape(ctx.Params(":action")))
186+
ctx.JSONRedirect(fmt.Sprintf("%s/projects/%d", ctx.Repo.RepoLink, id))
192187
}
193188

194189
// DeleteProject delete a project

0 commit comments

Comments
 (0)