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:
wxiaoguang
2023-07-26 14:04:01 +08:00
committed by GitHub
parent 338d03ce2f
commit dcd3a63128
36 changed files with 75 additions and 196 deletions

View File

@ -203,9 +203,7 @@ func DeleteProject(ctx *context.Context) {
ctx.Flash.Success(ctx.Tr("repo.projects.deletion_success"))
}
ctx.JSON(http.StatusOK, map[string]any{
"redirect": ctx.Repo.RepoLink + "/projects",
})
ctx.JSONRedirect(ctx.Repo.RepoLink + "/projects")
}
// RenderEditProject allows a project to be edited
@ -397,9 +395,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
@ -452,9 +448,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.
@ -487,9 +481,7 @@ func AddBoardToProjectPost(ctx *context.Context) {
return
}
ctx.JSON(http.StatusOK, map[string]any{
"ok": true,
})
ctx.JSONOK()
}
func checkProjectBoardChangePermissions(ctx *context.Context) (*project_model.Project, *project_model.Board) {
@ -561,9 +553,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
@ -578,9 +568,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
@ -595,9 +583,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
@ -699,7 +685,5 @@ func MoveIssues(ctx *context.Context) {
return
}
ctx.JSON(http.StatusOK, map[string]any{
"ok": true,
})
ctx.JSONOK()
}