aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorHesterG <hestergong@gmail.com>2023-06-14 16:01:37 +0800
committerGitHub <noreply@github.com>2023-06-14 16:01:37 +0800
commita43ea22479334ef3ac05fb8784223d45846b71a3 (patch)
treefbe1f53f1953fe827fed60cf80db5fffd952f805 /routers
parent6348823eaba35b0999ad6a2df445a7a9669ab09c (diff)
downloadgitea-a43ea22479334ef3ac05fb8784223d45846b71a3.tar.gz
gitea-a43ea22479334ef3ac05fb8784223d45846b71a3.zip
Change form actions to fetch for submit review box (#25219)
Co-author: @wxiaoguang Close #25096 The way to fix it in this PR is to change form submit to fetch using formData, and add flags to avoid post repeatedly. Should be able to apply to more forms that have the same issue after this PR. In the demo below, 'approve' is clicked several times, and then 'comment' is clicked several time after 'request changes' clicked. After: https://github.com/go-gitea/gitea/assets/17645053/beabeb1d-fe66-4b76-b048-4f022b4e83a0 Update: screenshots from /devtest > ![image](https://user-images.githubusercontent.com/2114189/245680011-ee4231e0-a53d-4c2a-a9c2-71ccd98005cc.png) > > ![image](https://user-images.githubusercontent.com/2114189/245680057-9215d348-63d8-406d-8828-17e171163aaa.png) > > ![image](https://user-images.githubusercontent.com/2114189/245680148-89d7b3d1-d7b6-442f-b69e-eadaee112482.png) --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'routers')
-rw-r--r--routers/web/devtest/devtest.go10
-rw-r--r--routers/web/repo/pull_review.go9
-rw-r--r--routers/web/web.go1
3 files changed, 15 insertions, 5 deletions
diff --git a/routers/web/devtest/devtest.go b/routers/web/devtest/devtest.go
index 48875e306d..64b732c035 100644
--- a/routers/web/devtest/devtest.go
+++ b/routers/web/devtest/devtest.go
@@ -32,6 +32,16 @@ func List(ctx *context.Context) {
ctx.HTML(http.StatusOK, "devtest/list")
}
+func FetchActionTest(ctx *context.Context) {
+ _ = ctx.Req.ParseForm()
+ ctx.Flash.Info(ctx.Req.Method + " " + ctx.Req.RequestURI + "<br>" +
+ "Form: " + ctx.Req.Form.Encode() + "<br>" +
+ "PostForm: " + ctx.Req.PostForm.Encode(),
+ )
+ time.Sleep(2 * time.Second)
+ ctx.JSONRedirect("")
+}
+
func Tmpl(ctx *context.Context) {
now := time.Now()
ctx.Data["TimeNow"] = now
diff --git a/routers/web/repo/pull_review.go b/routers/web/repo/pull_review.go
index 90cfd5bfcd..69d36ff4a4 100644
--- a/routers/web/repo/pull_review.go
+++ b/routers/web/repo/pull_review.go
@@ -193,7 +193,7 @@ func SubmitReview(ctx *context.Context) {
}
if ctx.HasError() {
ctx.Flash.Error(ctx.Data["ErrorMsg"].(string))
- ctx.Redirect(fmt.Sprintf("%s/pulls/%d/files", ctx.Repo.RepoLink, issue.Index))
+ ctx.JSONRedirect(fmt.Sprintf("%s/pulls/%d/files", ctx.Repo.RepoLink, issue.Index))
return
}
@@ -214,7 +214,7 @@ func SubmitReview(ctx *context.Context) {
}
ctx.Flash.Error(translated)
- ctx.Redirect(fmt.Sprintf("%s/pulls/%d/files", ctx.Repo.RepoLink, issue.Index))
+ ctx.JSONRedirect(fmt.Sprintf("%s/pulls/%d/files", ctx.Repo.RepoLink, issue.Index))
return
}
}
@@ -228,14 +228,13 @@ func SubmitReview(ctx *context.Context) {
if err != nil {
if issues_model.IsContentEmptyErr(err) {
ctx.Flash.Error(ctx.Tr("repo.issues.review.content.empty"))
- ctx.Redirect(fmt.Sprintf("%s/pulls/%d/files", ctx.Repo.RepoLink, issue.Index))
+ ctx.JSONRedirect(fmt.Sprintf("%s/pulls/%d/files", ctx.Repo.RepoLink, issue.Index))
} else {
ctx.ServerError("SubmitReview", err)
}
return
}
-
- ctx.Redirect(fmt.Sprintf("%s/pulls/%d#%s", ctx.Repo.RepoLink, issue.Index, comm.HashTag()))
+ ctx.JSONRedirect(fmt.Sprintf("%s/pulls/%d#%s", ctx.Repo.RepoLink, issue.Index, comm.HashTag()))
}
// DismissReview dismissing stale review by repo admin
diff --git a/routers/web/web.go b/routers/web/web.go
index 1e235a3c3c..8683ef221d 100644
--- a/routers/web/web.go
+++ b/routers/web/web.go
@@ -1411,6 +1411,7 @@ func registerRoutes(m *web.Route) {
if !setting.IsProd {
m.Any("/devtest", devtest.List)
+ m.Any("/devtest/fetch-action-test", devtest.FetchActionTest)
m.Any("/devtest/{sub}", devtest.Tmpl)
}