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:
parent
338d03ce2f
commit
dcd3a63128
36 changed files with 75 additions and 196 deletions
|
@ -136,18 +136,6 @@ func (b *Base) JSON(status int, content any) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Base) JSONRedirect(redirect string) {
|
|
||||||
b.JSON(http.StatusOK, map[string]any{"redirect": redirect})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Base) JSONOK() {
|
|
||||||
b.JSON(http.StatusOK, map[string]any{"ok": true}) // this is only a dummy response, frontend seldom uses it
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Base) JSONError(msg string) {
|
|
||||||
b.JSON(http.StatusBadRequest, map[string]any{"errorMessage": msg})
|
|
||||||
}
|
|
||||||
|
|
||||||
// RemoteAddr returns the client machine ip address
|
// RemoteAddr returns the client machine ip address
|
||||||
func (b *Base) RemoteAddr() string {
|
func (b *Base) RemoteAddr() string {
|
||||||
return b.Req.RemoteAddr
|
return b.Req.RemoteAddr
|
||||||
|
|
|
@ -226,3 +226,15 @@ func (ctx *Context) GetErrMsg() string {
|
||||||
}
|
}
|
||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ctx *Context) JSONRedirect(redirect string) {
|
||||||
|
ctx.JSON(http.StatusOK, map[string]any{"redirect": redirect})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ctx *Context) JSONOK() {
|
||||||
|
ctx.JSON(http.StatusOK, map[string]any{"ok": true}) // this is only a dummy response, frontend seldom uses it
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ctx *Context) JSONError(msg string) {
|
||||||
|
ctx.JSON(http.StatusBadRequest, map[string]any{"errorMessage": msg})
|
||||||
|
}
|
||||||
|
|
|
@ -454,15 +454,11 @@ func DeleteAuthSource(ctx *context.Context) {
|
||||||
} else {
|
} else {
|
||||||
ctx.Flash.Error(fmt.Sprintf("auth_service.DeleteSource: %v", err))
|
ctx.Flash.Error(fmt.Sprintf("auth_service.DeleteSource: %v", err))
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(setting.AppSubURL + "/admin/auths/" + url.PathEscape(ctx.Params(":authid")))
|
||||||
"redirect": setting.AppSubURL + "/admin/auths/" + url.PathEscape(ctx.Params(":authid")),
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Trace("Authentication deleted by admin(%s): %d", ctx.Doer.Name, source.ID)
|
log.Trace("Authentication deleted by admin(%s): %d", ctx.Doer.Name, source.ID)
|
||||||
|
|
||||||
ctx.Flash.Success(ctx.Tr("admin.auths.deletion_success"))
|
ctx.Flash.Success(ctx.Tr("admin.auths.deletion_success"))
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(setting.AppSubURL + "/admin/auths")
|
||||||
"redirect": setting.AppSubURL + "/admin/auths",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,9 +179,7 @@ func Config(ctx *context.Context) {
|
||||||
func ChangeConfig(ctx *context.Context) {
|
func ChangeConfig(ctx *context.Context) {
|
||||||
key := strings.TrimSpace(ctx.FormString("key"))
|
key := strings.TrimSpace(ctx.FormString("key"))
|
||||||
if key == "" {
|
if key == "" {
|
||||||
ctx.JSON(http.StatusOK, map[string]string{
|
ctx.JSONRedirect(ctx.Req.URL.String())
|
||||||
"redirect": ctx.Req.URL.String(),
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
value := ctx.FormString("value")
|
value := ctx.FormString("value")
|
||||||
|
|
|
@ -67,7 +67,5 @@ func DeleteDefaultOrSystemWebhook(ctx *context.Context) {
|
||||||
ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success"))
|
ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success"))
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(setting.AppSubURL + "/admin/hooks")
|
||||||
"redirect": setting.AppSubURL + "/admin/hooks",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,5 @@ func DeletePackageVersion(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Flash.Success(ctx.Tr("packages.settings.delete.success"))
|
ctx.Flash.Success(ctx.Tr("packages.settings.delete.success"))
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(setting.AppSubURL + "/admin/packages?page=" + url.QueryEscape(ctx.FormString("page")) + "&q=" + url.QueryEscape(ctx.FormString("q")) + "&type=" + url.QueryEscape(ctx.FormString("type")))
|
||||||
"redirect": setting.AppSubURL + "/admin/packages?page=" + url.QueryEscape(ctx.FormString("page")) + "&q=" + url.QueryEscape(ctx.FormString("q")) + "&type=" + url.QueryEscape(ctx.FormString("type")),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,9 +58,7 @@ func DeleteRepo(ctx *context.Context) {
|
||||||
log.Trace("Repository deleted: %s", repo.FullName())
|
log.Trace("Repository deleted: %s", repo.FullName())
|
||||||
|
|
||||||
ctx.Flash.Success(ctx.Tr("repo.settings.deletion_success"))
|
ctx.Flash.Success(ctx.Tr("repo.settings.deletion_success"))
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(setting.AppSubURL + "/admin/repos?page=" + url.QueryEscape(ctx.FormString("page")) + "&sort=" + url.QueryEscape(ctx.FormString("sort")))
|
||||||
"redirect": setting.AppSubURL + "/admin/repos?page=" + url.QueryEscape(ctx.FormString("page")) + "&sort=" + url.QueryEscape(ctx.FormString("sort")),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnadoptedRepos lists the unadopted repositories
|
// UnadoptedRepos lists the unadopted repositories
|
||||||
|
|
|
@ -42,7 +42,5 @@ func Stacktrace(ctx *context.Context) {
|
||||||
func StacktraceCancel(ctx *context.Context) {
|
func StacktraceCancel(ctx *context.Context) {
|
||||||
pid := ctx.Params("pid")
|
pid := ctx.Params("pid")
|
||||||
process.GetManager().Cancel(process.IDType(pid))
|
process.GetManager().Cancel(process.IDType(pid))
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(setting.AppSubURL + "/admin/monitor/stacktrace")
|
||||||
"redirect": setting.AppSubURL + "/admin/monitor/stacktrace",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,5 +154,5 @@ func WebAuthnLoginAssertionPost(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
_ = ctx.Session.Delete("twofaUid")
|
_ = ctx.Session.Delete("twofaUid")
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]string{"redirect": redirect})
|
ctx.JSONRedirect(redirect)
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,9 +101,7 @@ func MembersAction(ctx *context.Context) {
|
||||||
err = models.RemoveOrgUser(org.ID, uid)
|
err = models.RemoveOrgUser(org.ID, uid)
|
||||||
if organization.IsErrLastOrgOwner(err) {
|
if organization.IsErrLastOrgOwner(err) {
|
||||||
ctx.Flash.Error(ctx.Tr("form.last_org_owner"))
|
ctx.Flash.Error(ctx.Tr("form.last_org_owner"))
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(ctx.Org.OrgLink + "/members")
|
||||||
"redirect": ctx.Org.OrgLink + "/members",
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case "leave":
|
case "leave":
|
||||||
|
@ -115,9 +113,7 @@ func MembersAction(ctx *context.Context) {
|
||||||
})
|
})
|
||||||
} else if organization.IsErrLastOrgOwner(err) {
|
} else if organization.IsErrLastOrgOwner(err) {
|
||||||
ctx.Flash.Error(ctx.Tr("form.last_org_owner"))
|
ctx.Flash.Error(ctx.Tr("form.last_org_owner"))
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(ctx.Org.OrgLink + "/members")
|
||||||
"redirect": ctx.Org.OrgLink + "/members",
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
log.Error("RemoveOrgUser(%d,%d): %v", org.ID, ctx.Doer.ID, err)
|
log.Error("RemoveOrgUser(%d,%d): %v", org.ID, ctx.Doer.ID, err)
|
||||||
}
|
}
|
||||||
|
@ -138,7 +134,5 @@ func MembersAction(ctx *context.Context) {
|
||||||
redirect = setting.AppSubURL + "/"
|
redirect = setting.AppSubURL + "/"
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(redirect)
|
||||||
"redirect": redirect,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,9 +90,7 @@ func DeleteLabel(ctx *context.Context) {
|
||||||
ctx.Flash.Success(ctx.Tr("repo.issues.label_deletion_success"))
|
ctx.Flash.Success(ctx.Tr("repo.issues.label_deletion_success"))
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(ctx.Org.OrgLink + "/settings/labels")
|
||||||
"redirect": ctx.Org.OrgLink + "/settings/labels",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitializeLabels init labels for an organization
|
// 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.Flash.Success(ctx.Tr("repo.projects.deletion_success"))
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(ctx.ContextUser.HomeLink() + "/-/projects")
|
||||||
"redirect": ctx.ContextUser.HomeLink() + "/-/projects",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RenderEditProject allows a project to be edited
|
// RenderEditProject allows a project to be edited
|
||||||
|
@ -449,9 +447,7 @@ func UpdateIssueProject(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONOK()
|
||||||
"ok": true,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteProjectBoard allows for the deletion of a project board
|
// DeleteProjectBoard allows for the deletion of a project board
|
||||||
|
@ -497,9 +493,7 @@ func DeleteProjectBoard(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONOK()
|
||||||
"ok": true,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddBoardToProjectPost allows a new board to be added to a project.
|
// AddBoardToProjectPost allows a new board to be added to a project.
|
||||||
|
@ -526,9 +520,7 @@ func AddBoardToProjectPost(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONOK()
|
||||||
"ok": true,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckProjectBoardChangePermissions check permission
|
// CheckProjectBoardChangePermissions check permission
|
||||||
|
@ -594,9 +586,7 @@ func EditProjectBoard(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONOK()
|
||||||
"ok": true,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDefaultProjectBoard set default board for uncategorized issues/pulls
|
// SetDefaultProjectBoard set default board for uncategorized issues/pulls
|
||||||
|
@ -611,9 +601,7 @@ func SetDefaultProjectBoard(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONOK()
|
||||||
"ok": true,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnsetDefaultProjectBoard unset default board for uncategorized issues/pulls
|
// UnsetDefaultProjectBoard unset default board for uncategorized issues/pulls
|
||||||
|
@ -628,9 +616,7 @@ func UnsetDefaultProjectBoard(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONOK()
|
||||||
"ok": true,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MoveIssues moves or keeps issues in a column and sorts them inside that column
|
// MoveIssues moves or keeps issues in a column and sorts them inside that column
|
||||||
|
@ -730,7 +716,5 @@ func MoveIssues(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONOK()
|
||||||
"ok": true,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -219,9 +219,7 @@ func DeleteWebhook(ctx *context.Context) {
|
||||||
ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success"))
|
ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success"))
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(ctx.Org.OrgLink + "/settings/hooks")
|
||||||
"redirect": ctx.Org.OrgLink + "/settings/hooks",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Labels render organization labels page
|
// Labels render organization labels page
|
||||||
|
|
|
@ -256,9 +256,7 @@ func TeamsRepoAction(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if action == "addall" || action == "removeall" {
|
if action == "addall" || action == "removeall" {
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(ctx.Org.OrgLink + "/teams/" + url.PathEscape(ctx.Org.Team.LowerName) + "/repositories")
|
||||||
"redirect": ctx.Org.OrgLink + "/teams/" + url.PathEscape(ctx.Org.Team.LowerName) + "/repositories",
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Redirect(ctx.Org.OrgLink + "/teams/" + url.PathEscape(ctx.Org.Team.LowerName) + "/repositories")
|
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.Flash.Success(ctx.Tr("org.teams.delete_team_success"))
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(ctx.Org.OrgLink + "/teams")
|
||||||
"redirect": ctx.Org.OrgLink + "/teams",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TeamInvite renders the team invite page
|
// TeamInvite renders the team invite page
|
||||||
|
|
|
@ -162,9 +162,7 @@ func RestoreBranchPost(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func redirect(ctx *context.Context) {
|
func redirect(ctx *context.Context) {
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(ctx.Repo.RepoLink + "/branches?page=" + url.QueryEscape(ctx.FormString("page")))
|
||||||
"redirect": ctx.Repo.RepoLink + "/branches?page=" + url.QueryEscape(ctx.FormString("page")),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateBranch creates new branch in repository
|
// CreateBranch creates new branch in repository
|
||||||
|
|
|
@ -2221,9 +2221,7 @@ func UpdateIssueMilestone(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONOK()
|
||||||
"ok": true,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateIssueAssignee change issue's or pull's assignee
|
// UpdateIssueAssignee change issue's or pull's assignee
|
||||||
|
@ -2267,9 +2265,7 @@ func UpdateIssueAssignee(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONOK()
|
||||||
"ok": true,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdatePullReviewRequest add or remove review request
|
// UpdatePullReviewRequest add or remove review request
|
||||||
|
@ -2392,9 +2388,7 @@ func UpdatePullReviewRequest(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONOK()
|
||||||
"ok": true,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SearchIssues searches for issues across the repositories that the user has access to
|
// SearchIssues searches for issues across the repositories that the user has access to
|
||||||
|
|
|
@ -157,9 +157,7 @@ func DeleteLabel(ctx *context.Context) {
|
||||||
ctx.Flash.Success(ctx.Tr("repo.issues.label_deletion_success"))
|
ctx.Flash.Success(ctx.Tr("repo.issues.label_deletion_success"))
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(ctx.Repo.RepoLink + "/labels")
|
||||||
"redirect": ctx.Repo.RepoLink + "/labels",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateIssueLabel change issue's labels
|
// UpdateIssueLabel change issue's labels
|
||||||
|
@ -226,7 +224,5 @@ func UpdateIssueLabel(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONOK()
|
||||||
"ok": true,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -255,9 +255,7 @@ func DeleteMilestone(ctx *context.Context) {
|
||||||
ctx.Flash.Success(ctx.Tr("repo.milestones.deletion_success"))
|
ctx.Flash.Success(ctx.Tr("repo.milestones.deletion_success"))
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(ctx.Repo.RepoLink + "/milestones")
|
||||||
"redirect": ctx.Repo.RepoLink + "/milestones",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MilestoneIssuesAndPulls lists all the issues and pull requests of the milestone
|
// MilestoneIssuesAndPulls lists all the issues and pull requests of the milestone
|
||||||
|
|
|
@ -203,9 +203,7 @@ func DeleteProject(ctx *context.Context) {
|
||||||
ctx.Flash.Success(ctx.Tr("repo.projects.deletion_success"))
|
ctx.Flash.Success(ctx.Tr("repo.projects.deletion_success"))
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(ctx.Repo.RepoLink + "/projects")
|
||||||
"redirect": ctx.Repo.RepoLink + "/projects",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RenderEditProject allows a project to be edited
|
// RenderEditProject allows a project to be edited
|
||||||
|
@ -397,9 +395,7 @@ func UpdateIssueProject(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONOK()
|
||||||
"ok": true,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteProjectBoard allows for the deletion of a project board
|
// DeleteProjectBoard allows for the deletion of a project board
|
||||||
|
@ -452,9 +448,7 @@ func DeleteProjectBoard(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONOK()
|
||||||
"ok": true,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddBoardToProjectPost allows a new board to be added to a project.
|
// AddBoardToProjectPost allows a new board to be added to a project.
|
||||||
|
@ -487,9 +481,7 @@ func AddBoardToProjectPost(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONOK()
|
||||||
"ok": true,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkProjectBoardChangePermissions(ctx *context.Context) (*project_model.Project, *project_model.Board) {
|
func checkProjectBoardChangePermissions(ctx *context.Context) (*project_model.Project, *project_model.Board) {
|
||||||
|
@ -561,9 +553,7 @@ func EditProjectBoard(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONOK()
|
||||||
"ok": true,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDefaultProjectBoard set default board for uncategorized issues/pulls
|
// SetDefaultProjectBoard set default board for uncategorized issues/pulls
|
||||||
|
@ -578,9 +568,7 @@ func SetDefaultProjectBoard(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONOK()
|
||||||
"ok": true,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnSetDefaultProjectBoard unset default board for uncategorized issues/pulls
|
// UnSetDefaultProjectBoard unset default board for uncategorized issues/pulls
|
||||||
|
@ -595,9 +583,7 @@ func UnSetDefaultProjectBoard(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONOK()
|
||||||
"ok": true,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MoveIssues moves or keeps issues in a column and sorts them inside that column
|
// MoveIssues moves or keeps issues in a column and sorts them inside that column
|
||||||
|
@ -699,7 +685,5 @@ func MoveIssues(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONOK()
|
||||||
"ok": true,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1423,9 +1423,7 @@ func CleanUpPullRequest(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(issue.Link())
|
||||||
"redirect": issue.Link(),
|
|
||||||
})
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Check if branch has no new commits
|
// Check if branch has no new commits
|
||||||
|
|
|
@ -156,9 +156,7 @@ func UpdateResolveConversation(ctx *context.Context) {
|
||||||
renderConversation(ctx, comment)
|
renderConversation(ctx, comment)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONOK()
|
||||||
"ok": true,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderConversation(ctx *context.Context, comment *issues_model.Comment) {
|
func renderConversation(ctx *context.Context, comment *issues_model.Comment) {
|
||||||
|
|
|
@ -628,13 +628,9 @@ func deleteReleaseOrTag(ctx *context.Context, isDelTag bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if isDelTag {
|
if isDelTag {
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(ctx.Repo.RepoLink + "/tags")
|
||||||
"redirect": ctx.Repo.RepoLink + "/tags",
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(ctx.Repo.RepoLink + "/releases")
|
||||||
"redirect": ctx.Repo.RepoLink + "/releases",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,9 +133,7 @@ func DeleteCollaboration(ctx *context.Context) {
|
||||||
ctx.Flash.Success(ctx.Tr("repo.settings.remove_collaborator_success"))
|
ctx.Flash.Success(ctx.Tr("repo.settings.remove_collaborator_success"))
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(ctx.Repo.RepoLink + "/settings/collaboration")
|
||||||
"redirect": ctx.Repo.RepoLink + "/settings/collaboration",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddTeamPost response for adding a team to a repository
|
// AddTeamPost response for adding a team to a repository
|
||||||
|
@ -204,7 +202,5 @@ func DeleteTeam(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Flash.Success(ctx.Tr("repo.settings.remove_team_success"))
|
ctx.Flash.Success(ctx.Tr("repo.settings.remove_team_success"))
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(ctx.Repo.RepoLink + "/settings/collaboration")
|
||||||
"redirect": ctx.Repo.RepoLink + "/settings/collaboration",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,5 @@ func DeleteDeployKey(ctx *context.Context) {
|
||||||
ctx.Flash.Success(ctx.Tr("repo.settings.deploy_key_deletion_success"))
|
ctx.Flash.Success(ctx.Tr("repo.settings.deploy_key_deletion_success"))
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(ctx.Repo.RepoLink + "/settings/keys")
|
||||||
"redirect": ctx.Repo.RepoLink + "/settings/keys",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -318,41 +318,31 @@ func DeleteProtectedBranchRulePost(ctx *context.Context) {
|
||||||
ruleID := ctx.ParamsInt64("id")
|
ruleID := ctx.ParamsInt64("id")
|
||||||
if ruleID <= 0 {
|
if ruleID <= 0 {
|
||||||
ctx.Flash.Error(ctx.Tr("repo.settings.remove_protected_branch_failed", fmt.Sprintf("%d", ruleID)))
|
ctx.Flash.Error(ctx.Tr("repo.settings.remove_protected_branch_failed", fmt.Sprintf("%d", ruleID)))
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink))
|
||||||
"redirect": fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink),
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rule, err := git_model.GetProtectedBranchRuleByID(ctx, ctx.Repo.Repository.ID, ruleID)
|
rule, err := git_model.GetProtectedBranchRuleByID(ctx, ctx.Repo.Repository.ID, ruleID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Flash.Error(ctx.Tr("repo.settings.remove_protected_branch_failed", fmt.Sprintf("%d", ruleID)))
|
ctx.Flash.Error(ctx.Tr("repo.settings.remove_protected_branch_failed", fmt.Sprintf("%d", ruleID)))
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink))
|
||||||
"redirect": fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink),
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if rule == nil {
|
if rule == nil {
|
||||||
ctx.Flash.Error(ctx.Tr("repo.settings.remove_protected_branch_failed", fmt.Sprintf("%d", ruleID)))
|
ctx.Flash.Error(ctx.Tr("repo.settings.remove_protected_branch_failed", fmt.Sprintf("%d", ruleID)))
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink))
|
||||||
"redirect": fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink),
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := git_model.DeleteProtectedBranch(ctx, ctx.Repo.Repository.ID, ruleID); err != nil {
|
if err := git_model.DeleteProtectedBranch(ctx, ctx.Repo.Repository.ID, ruleID); err != nil {
|
||||||
ctx.Flash.Error(ctx.Tr("repo.settings.remove_protected_branch_failed", rule.RuleName))
|
ctx.Flash.Error(ctx.Tr("repo.settings.remove_protected_branch_failed", rule.RuleName))
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink))
|
||||||
"redirect": fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink),
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Flash.Success(ctx.Tr("repo.settings.remove_protected_branch_success", rule.RuleName))
|
ctx.Flash.Success(ctx.Tr("repo.settings.remove_protected_branch_success", rule.RuleName))
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink))
|
||||||
"redirect": fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RenameBranchPost responses for rename a branch
|
// RenameBranchPost responses for rename a branch
|
||||||
|
|
|
@ -729,7 +729,5 @@ func DeleteWebhook(ctx *context.Context) {
|
||||||
ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success"))
|
ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success"))
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(ctx.Repo.RepoLink + "/settings/hooks")
|
||||||
"redirect": ctx.Repo.RepoLink + "/settings/hooks",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -790,7 +790,5 @@ func DeleteWikiPagePost(ctx *context.Context) {
|
||||||
|
|
||||||
notification.NotifyDeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, string(wikiName))
|
notification.NotifyDeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, string(wikiName))
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(ctx.Repo.RepoLink + "/wiki/")
|
||||||
"redirect": ctx.Repo.RepoLink + "/wiki/",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ package actions
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
|
||||||
|
|
||||||
actions_model "code.gitea.io/gitea/models/actions"
|
actions_model "code.gitea.io/gitea/models/actions"
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
|
@ -160,9 +159,7 @@ func RunnerDeletePost(ctx *context.Context, runnerID int64,
|
||||||
log.Warn("DeleteRunnerPost.UpdateRunner failed: %v, url: %s", err, ctx.Req.URL)
|
log.Warn("DeleteRunnerPost.UpdateRunner failed: %v, url: %s", err, ctx.Req.URL)
|
||||||
ctx.Flash.Warning(ctx.Tr("actions.runners.delete_runner_failed"))
|
ctx.Flash.Warning(ctx.Tr("actions.runners.delete_runner_failed"))
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(failedRedirectTo)
|
||||||
"redirect": failedRedirectTo,
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,7 +167,5 @@ func RunnerDeletePost(ctx *context.Context, runnerID int64,
|
||||||
|
|
||||||
ctx.Flash.Success(ctx.Tr("actions.runners.delete_runner_success"))
|
ctx.Flash.Success(ctx.Tr("actions.runners.delete_runner_success"))
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(successRedirectTo)
|
||||||
"redirect": successRedirectTo,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -227,9 +227,7 @@ func DeleteEmail(ctx *context.Context) {
|
||||||
log.Trace("Email address deleted: %s", ctx.Doer.Name)
|
log.Trace("Email address deleted: %s", ctx.Doer.Name)
|
||||||
|
|
||||||
ctx.Flash.Success(ctx.Tr("settings.email_deletion_success"))
|
ctx.Flash.Success(ctx.Tr("settings.email_deletion_success"))
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(setting.AppSubURL + "/user/settings/account")
|
||||||
"redirect": setting.AppSubURL + "/user/settings/account",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteAccount render user suicide page and response for delete user himself
|
// DeleteAccount render user suicide page and response for delete user himself
|
||||||
|
|
|
@ -83,9 +83,7 @@ func DeleteApplication(ctx *context.Context) {
|
||||||
ctx.Flash.Success(ctx.Tr("settings.delete_token_success"))
|
ctx.Flash.Success(ctx.Tr("settings.delete_token_success"))
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(setting.AppSubURL + "/user/settings/applications")
|
||||||
"redirect": setting.AppSubURL + "/user/settings/applications",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadApplicationsData(ctx *context.Context) {
|
func loadApplicationsData(ctx *context.Context) {
|
||||||
|
|
|
@ -256,9 +256,7 @@ func DeleteKey(ctx *context.Context) {
|
||||||
ctx.Flash.Warning("Function not implemented")
|
ctx.Flash.Warning("Function not implemented")
|
||||||
ctx.Redirect(setting.AppSubURL + "/user/settings/keys")
|
ctx.Redirect(setting.AppSubURL + "/user/settings/keys")
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(setting.AppSubURL + "/user/settings/keys")
|
||||||
"redirect": setting.AppSubURL + "/user/settings/keys",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadKeysData(ctx *context.Context) {
|
func loadKeysData(ctx *context.Context) {
|
||||||
|
|
|
@ -138,7 +138,7 @@ func (oa *OAuth2CommonHandlers) DeleteApp(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Flash.Success(ctx.Tr("settings.remove_oauth2_application_success"))
|
ctx.Flash.Success(ctx.Tr("settings.remove_oauth2_application_success"))
|
||||||
ctx.JSON(http.StatusOK, map[string]any{"redirect": oa.BasePathList})
|
ctx.JSONRedirect(oa.BasePathList)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RevokeGrant revokes the grant
|
// RevokeGrant revokes the grant
|
||||||
|
@ -149,5 +149,5 @@ func (oa *OAuth2CommonHandlers) RevokeGrant(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Flash.Success(ctx.Tr("settings.revoke_oauth2_grant_success"))
|
ctx.Flash.Success(ctx.Tr("settings.revoke_oauth2_grant_success"))
|
||||||
ctx.JSON(http.StatusOK, map[string]any{"redirect": oa.BasePathList})
|
ctx.JSONRedirect(oa.BasePathList)
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,9 +112,7 @@ func DeleteOpenID(ctx *context.Context) {
|
||||||
log.Trace("OpenID address deleted: %s", ctx.Doer.Name)
|
log.Trace("OpenID address deleted: %s", ctx.Doer.Name)
|
||||||
|
|
||||||
ctx.Flash.Success(ctx.Tr("settings.openid_deletion_success"))
|
ctx.Flash.Success(ctx.Tr("settings.openid_deletion_success"))
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(setting.AppSubURL + "/user/settings/security")
|
||||||
"redirect": setting.AppSubURL + "/user/settings/security",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToggleOpenIDVisibility response for toggle visibility of user's openid
|
// ToggleOpenIDVisibility response for toggle visibility of user's openid
|
||||||
|
|
|
@ -48,9 +48,7 @@ func DeleteAccountLink(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(setting.AppSubURL + "/user/settings/security")
|
||||||
"redirect": setting.AppSubURL + "/user/settings/security",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadSecurityData(ctx *context.Context) {
|
func loadSecurityData(ctx *context.Context) {
|
||||||
|
|
|
@ -116,7 +116,5 @@ func WebauthnDelete(ctx *context.Context) {
|
||||||
ctx.ServerError("GetWebAuthnCredentialByID", err)
|
ctx.ServerError("GetWebAuthnCredentialByID", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(setting.AppSubURL + "/user/settings/security")
|
||||||
"redirect": setting.AppSubURL + "/user/settings/security",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,5 @@ func DeleteWebhook(ctx *context.Context) {
|
||||||
ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success"))
|
ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success"))
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]any{
|
ctx.JSONRedirect(setting.AppSubURL + "/user/settings/hooks")
|
||||||
"redirect": setting.AppSubURL + "/user/settings/hooks",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue