mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
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
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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()
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user