diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-07-26 14:04:01 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-26 06:04:01 +0000 |
commit | dcd3a631288686a95cedbd4aa9cce245e896825d (patch) | |
tree | e8c726ec07c3cb54fc092d63d2713fee409ee7b4 /routers/web/org | |
parent | 338d03ce2f05fcc49a577b58a6cfa6beb7996fd1 (diff) | |
download | gitea-dcd3a631288686a95cedbd4aa9cce245e896825d.tar.gz gitea-dcd3a631288686a95cedbd4aa9cce245e896825d.zip |
Move web JSON functions to web context and simplify code (#26132)
The JSONRedirect/JSONOK/JSONError functions were put into "Base" context
incorrectly, it would cause abuse.
Actually, they are for "web context" only, so, move them to the correct
place.
And by the way, use them to simplify old code: +75 -196
Diffstat (limited to 'routers/web/org')
-rw-r--r-- | routers/web/org/members.go | 12 | ||||
-rw-r--r-- | routers/web/org/org_labels.go | 4 | ||||
-rw-r--r-- | routers/web/org/projects.go | 32 | ||||
-rw-r--r-- | routers/web/org/setting.go | 4 | ||||
-rw-r--r-- | routers/web/org/teams.go | 8 |
5 files changed, 15 insertions, 45 deletions
diff --git a/routers/web/org/members.go b/routers/web/org/members.go index 8da0f0b9fd..fae8b48128 100644 --- a/routers/web/org/members.go +++ b/routers/web/org/members.go @@ -101,9 +101,7 @@ func MembersAction(ctx *context.Context) { err = models.RemoveOrgUser(org.ID, uid) if organization.IsErrLastOrgOwner(err) { ctx.Flash.Error(ctx.Tr("form.last_org_owner")) - ctx.JSON(http.StatusOK, map[string]any{ - "redirect": ctx.Org.OrgLink + "/members", - }) + ctx.JSONRedirect(ctx.Org.OrgLink + "/members") return } case "leave": @@ -115,9 +113,7 @@ func MembersAction(ctx *context.Context) { }) } else if organization.IsErrLastOrgOwner(err) { ctx.Flash.Error(ctx.Tr("form.last_org_owner")) - ctx.JSON(http.StatusOK, map[string]any{ - "redirect": ctx.Org.OrgLink + "/members", - }) + ctx.JSONRedirect(ctx.Org.OrgLink + "/members") } else { log.Error("RemoveOrgUser(%d,%d): %v", org.ID, ctx.Doer.ID, err) } @@ -138,7 +134,5 @@ func MembersAction(ctx *context.Context) { redirect = setting.AppSubURL + "/" } - ctx.JSON(http.StatusOK, map[string]any{ - "redirect": redirect, - }) + ctx.JSONRedirect(redirect) } diff --git a/routers/web/org/org_labels.go b/routers/web/org/org_labels.go index 08566637a8..a9f9e963d4 100644 --- a/routers/web/org/org_labels.go +++ b/routers/web/org/org_labels.go @@ -90,9 +90,7 @@ func DeleteLabel(ctx *context.Context) { ctx.Flash.Success(ctx.Tr("repo.issues.label_deletion_success")) } - ctx.JSON(http.StatusOK, map[string]any{ - "redirect": ctx.Org.OrgLink + "/settings/labels", - }) + ctx.JSONRedirect(ctx.Org.OrgLink + "/settings/labels") } // InitializeLabels init labels for an organization diff --git a/routers/web/org/projects.go b/routers/web/org/projects.go index 50bb5591e5..ea6e7dff48 100644 --- a/routers/web/org/projects.go +++ b/routers/web/org/projects.go @@ -219,9 +219,7 @@ func DeleteProject(ctx *context.Context) { ctx.Flash.Success(ctx.Tr("repo.projects.deletion_success")) } - ctx.JSON(http.StatusOK, map[string]any{ - "redirect": ctx.ContextUser.HomeLink() + "/-/projects", - }) + ctx.JSONRedirect(ctx.ContextUser.HomeLink() + "/-/projects") } // RenderEditProject allows a project to be edited @@ -449,9 +447,7 @@ func UpdateIssueProject(ctx *context.Context) { } } - ctx.JSON(http.StatusOK, map[string]any{ - "ok": true, - }) + ctx.JSONOK() } // DeleteProjectBoard allows for the deletion of a project board @@ -497,9 +493,7 @@ func DeleteProjectBoard(ctx *context.Context) { return } - ctx.JSON(http.StatusOK, map[string]any{ - "ok": true, - }) + ctx.JSONOK() } // AddBoardToProjectPost allows a new board to be added to a project. @@ -526,9 +520,7 @@ func AddBoardToProjectPost(ctx *context.Context) { return } - ctx.JSON(http.StatusOK, map[string]any{ - "ok": true, - }) + ctx.JSONOK() } // CheckProjectBoardChangePermissions check permission @@ -594,9 +586,7 @@ func EditProjectBoard(ctx *context.Context) { return } - ctx.JSON(http.StatusOK, map[string]any{ - "ok": true, - }) + ctx.JSONOK() } // SetDefaultProjectBoard set default board for uncategorized issues/pulls @@ -611,9 +601,7 @@ func SetDefaultProjectBoard(ctx *context.Context) { return } - ctx.JSON(http.StatusOK, map[string]any{ - "ok": true, - }) + ctx.JSONOK() } // UnsetDefaultProjectBoard unset default board for uncategorized issues/pulls @@ -628,9 +616,7 @@ func UnsetDefaultProjectBoard(ctx *context.Context) { return } - ctx.JSON(http.StatusOK, map[string]any{ - "ok": true, - }) + ctx.JSONOK() } // MoveIssues moves or keeps issues in a column and sorts them inside that column @@ -730,7 +716,5 @@ func MoveIssues(ctx *context.Context) { return } - ctx.JSON(http.StatusOK, map[string]any{ - "ok": true, - }) + ctx.JSONOK() } diff --git a/routers/web/org/setting.go b/routers/web/org/setting.go index f63b2e9f06..5ae61c79be 100644 --- a/routers/web/org/setting.go +++ b/routers/web/org/setting.go @@ -219,9 +219,7 @@ func DeleteWebhook(ctx *context.Context) { ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success")) } - ctx.JSON(http.StatusOK, map[string]any{ - "redirect": ctx.Org.OrgLink + "/settings/hooks", - }) + ctx.JSONRedirect(ctx.Org.OrgLink + "/settings/hooks") } // Labels render organization labels page diff --git a/routers/web/org/teams.go b/routers/web/org/teams.go index aefadaf809..196d3e9bf0 100644 --- a/routers/web/org/teams.go +++ b/routers/web/org/teams.go @@ -256,9 +256,7 @@ func TeamsRepoAction(ctx *context.Context) { } if action == "addall" || action == "removeall" { - ctx.JSON(http.StatusOK, map[string]any{ - "redirect": ctx.Org.OrgLink + "/teams/" + url.PathEscape(ctx.Org.Team.LowerName) + "/repositories", - }) + ctx.JSONRedirect(ctx.Org.OrgLink + "/teams/" + url.PathEscape(ctx.Org.Team.LowerName) + "/repositories") return } ctx.Redirect(ctx.Org.OrgLink + "/teams/" + url.PathEscape(ctx.Org.Team.LowerName) + "/repositories") @@ -530,9 +528,7 @@ func DeleteTeam(ctx *context.Context) { ctx.Flash.Success(ctx.Tr("org.teams.delete_team_success")) } - ctx.JSON(http.StatusOK, map[string]any{ - "redirect": ctx.Org.OrgLink + "/teams", - }) + ctx.JSONRedirect(ctx.Org.OrgLink + "/teams") } // TeamInvite renders the team invite page |