mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-10 12:49:52 +01: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:
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
|
||||
func (b *Base) RemoteAddr() string {
|
||||
return b.Req.RemoteAddr
|
||||
|
|
|
@ -226,3 +226,15 @@ func (ctx *Context) GetErrMsg() string {
|
|||
}
|
||||
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 {
|
||||
ctx.Flash.Error(fmt.Sprintf("auth_service.DeleteSource: %v", err))
|
||||
}
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": setting.AppSubURL + "/admin/auths/" + url.PathEscape(ctx.Params(":authid")),
|
||||
})
|
||||
ctx.JSONRedirect(setting.AppSubURL + "/admin/auths/" + url.PathEscape(ctx.Params(":authid")))
|
||||
return
|
||||
}
|
||||
log.Trace("Authentication deleted by admin(%s): %d", ctx.Doer.Name, source.ID)
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("admin.auths.deletion_success"))
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": setting.AppSubURL + "/admin/auths",
|
||||
})
|
||||
ctx.JSONRedirect(setting.AppSubURL + "/admin/auths")
|
||||
}
|
||||
|
|
|
@ -179,9 +179,7 @@ func Config(ctx *context.Context) {
|
|||
func ChangeConfig(ctx *context.Context) {
|
||||
key := strings.TrimSpace(ctx.FormString("key"))
|
||||
if key == "" {
|
||||
ctx.JSON(http.StatusOK, map[string]string{
|
||||
"redirect": ctx.Req.URL.String(),
|
||||
})
|
||||
ctx.JSONRedirect(ctx.Req.URL.String())
|
||||
return
|
||||
}
|
||||
value := ctx.FormString("value")
|
||||
|
|
|
@ -67,7 +67,5 @@ func DeleteDefaultOrSystemWebhook(ctx *context.Context) {
|
|||
ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success"))
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": setting.AppSubURL + "/admin/hooks",
|
||||
})
|
||||
ctx.JSONRedirect(setting.AppSubURL + "/admin/hooks")
|
||||
}
|
||||
|
|
|
@ -97,7 +97,5 @@ func DeletePackageVersion(ctx *context.Context) {
|
|||
}
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("packages.settings.delete.success"))
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": setting.AppSubURL + "/admin/packages?page=" + url.QueryEscape(ctx.FormString("page")) + "&q=" + url.QueryEscape(ctx.FormString("q")) + "&type=" + url.QueryEscape(ctx.FormString("type")),
|
||||
})
|
||||
ctx.JSONRedirect(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())
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("repo.settings.deletion_success"))
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": setting.AppSubURL + "/admin/repos?page=" + url.QueryEscape(ctx.FormString("page")) + "&sort=" + url.QueryEscape(ctx.FormString("sort")),
|
||||
})
|
||||
ctx.JSONRedirect(setting.AppSubURL + "/admin/repos?page=" + url.QueryEscape(ctx.FormString("page")) + "&sort=" + url.QueryEscape(ctx.FormString("sort")))
|
||||
}
|
||||
|
||||
// UnadoptedRepos lists the unadopted repositories
|
||||
|
|
|
@ -42,7 +42,5 @@ func Stacktrace(ctx *context.Context) {
|
|||
func StacktraceCancel(ctx *context.Context) {
|
||||
pid := ctx.Params("pid")
|
||||
process.GetManager().Cancel(process.IDType(pid))
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": setting.AppSubURL + "/admin/monitor/stacktrace",
|
||||
})
|
||||
ctx.JSONRedirect(setting.AppSubURL + "/admin/monitor/stacktrace")
|
||||
}
|
||||
|
|
|
@ -154,5 +154,5 @@ func WebAuthnLoginAssertionPost(ctx *context.Context) {
|
|||
}
|
||||
_ = 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)
|
||||
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
|
||||
|
|
|
@ -162,9 +162,7 @@ func RestoreBranchPost(ctx *context.Context) {
|
|||
}
|
||||
|
||||
func redirect(ctx *context.Context) {
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": ctx.Repo.RepoLink + "/branches?page=" + url.QueryEscape(ctx.FormString("page")),
|
||||
})
|
||||
ctx.JSONRedirect(ctx.Repo.RepoLink + "/branches?page=" + url.QueryEscape(ctx.FormString("page")))
|
||||
}
|
||||
|
||||
// CreateBranch creates new branch in repository
|
||||
|
|
|
@ -2221,9 +2221,7 @@ func UpdateIssueMilestone(ctx *context.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"ok": true,
|
||||
})
|
||||
ctx.JSONOK()
|
||||
}
|
||||
|
||||
// UpdateIssueAssignee change issue's or pull's assignee
|
||||
|
@ -2267,9 +2265,7 @@ func UpdateIssueAssignee(ctx *context.Context) {
|
|||
}
|
||||
}
|
||||
}
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"ok": true,
|
||||
})
|
||||
ctx.JSONOK()
|
||||
}
|
||||
|
||||
// UpdatePullReviewRequest add or remove review request
|
||||
|
@ -2392,9 +2388,7 @@ func UpdatePullReviewRequest(ctx *context.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"ok": true,
|
||||
})
|
||||
ctx.JSONOK()
|
||||
}
|
||||
|
||||
// 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.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": ctx.Repo.RepoLink + "/labels",
|
||||
})
|
||||
ctx.JSONRedirect(ctx.Repo.RepoLink + "/labels")
|
||||
}
|
||||
|
||||
// UpdateIssueLabel change issue's labels
|
||||
|
@ -226,7 +224,5 @@ func UpdateIssueLabel(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"ok": true,
|
||||
})
|
||||
ctx.JSONOK()
|
||||
}
|
||||
|
|
|
@ -255,9 +255,7 @@ func DeleteMilestone(ctx *context.Context) {
|
|||
ctx.Flash.Success(ctx.Tr("repo.milestones.deletion_success"))
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": ctx.Repo.RepoLink + "/milestones",
|
||||
})
|
||||
ctx.JSONRedirect(ctx.Repo.RepoLink + "/milestones")
|
||||
}
|
||||
|
||||
// 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.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()
|
||||
}
|
||||
|
|
|
@ -1423,9 +1423,7 @@ func CleanUpPullRequest(ctx *context.Context) {
|
|||
}
|
||||
|
||||
defer func() {
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": issue.Link(),
|
||||
})
|
||||
ctx.JSONRedirect(issue.Link())
|
||||
}()
|
||||
|
||||
// Check if branch has no new commits
|
||||
|
|
|
@ -156,9 +156,7 @@ func UpdateResolveConversation(ctx *context.Context) {
|
|||
renderConversation(ctx, comment)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"ok": true,
|
||||
})
|
||||
ctx.JSONOK()
|
||||
}
|
||||
|
||||
func renderConversation(ctx *context.Context, comment *issues_model.Comment) {
|
||||
|
|
|
@ -628,13 +628,9 @@ func deleteReleaseOrTag(ctx *context.Context, isDelTag bool) {
|
|||
}
|
||||
|
||||
if isDelTag {
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": ctx.Repo.RepoLink + "/tags",
|
||||
})
|
||||
ctx.JSONRedirect(ctx.Repo.RepoLink + "/tags")
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": ctx.Repo.RepoLink + "/releases",
|
||||
})
|
||||
ctx.JSONRedirect(ctx.Repo.RepoLink + "/releases")
|
||||
}
|
||||
|
|
|
@ -133,9 +133,7 @@ func DeleteCollaboration(ctx *context.Context) {
|
|||
ctx.Flash.Success(ctx.Tr("repo.settings.remove_collaborator_success"))
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": ctx.Repo.RepoLink + "/settings/collaboration",
|
||||
})
|
||||
ctx.JSONRedirect(ctx.Repo.RepoLink + "/settings/collaboration")
|
||||
}
|
||||
|
||||
// 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.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": ctx.Repo.RepoLink + "/settings/collaboration",
|
||||
})
|
||||
ctx.JSONRedirect(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.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": ctx.Repo.RepoLink + "/settings/keys",
|
||||
})
|
||||
ctx.JSONRedirect(ctx.Repo.RepoLink + "/settings/keys")
|
||||
}
|
||||
|
|
|
@ -318,41 +318,31 @@ func DeleteProtectedBranchRulePost(ctx *context.Context) {
|
|||
ruleID := ctx.ParamsInt64("id")
|
||||
if ruleID <= 0 {
|
||||
ctx.Flash.Error(ctx.Tr("repo.settings.remove_protected_branch_failed", fmt.Sprintf("%d", ruleID)))
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink),
|
||||
})
|
||||
ctx.JSONRedirect(fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink))
|
||||
return
|
||||
}
|
||||
|
||||
rule, err := git_model.GetProtectedBranchRuleByID(ctx, ctx.Repo.Repository.ID, ruleID)
|
||||
if err != nil {
|
||||
ctx.Flash.Error(ctx.Tr("repo.settings.remove_protected_branch_failed", fmt.Sprintf("%d", ruleID)))
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink),
|
||||
})
|
||||
ctx.JSONRedirect(fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink))
|
||||
return
|
||||
}
|
||||
|
||||
if rule == nil {
|
||||
ctx.Flash.Error(ctx.Tr("repo.settings.remove_protected_branch_failed", fmt.Sprintf("%d", ruleID)))
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink),
|
||||
})
|
||||
ctx.JSONRedirect(fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink))
|
||||
return
|
||||
}
|
||||
|
||||
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.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink),
|
||||
})
|
||||
ctx.JSONRedirect(fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink))
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("repo.settings.remove_protected_branch_success", rule.RuleName))
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink),
|
||||
})
|
||||
ctx.JSONRedirect(fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink))
|
||||
}
|
||||
|
||||
// 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.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": ctx.Repo.RepoLink + "/settings/hooks",
|
||||
})
|
||||
ctx.JSONRedirect(ctx.Repo.RepoLink + "/settings/hooks")
|
||||
}
|
||||
|
|
|
@ -790,7 +790,5 @@ func DeleteWikiPagePost(ctx *context.Context) {
|
|||
|
||||
notification.NotifyDeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, string(wikiName))
|
||||
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": ctx.Repo.RepoLink + "/wiki/",
|
||||
})
|
||||
ctx.JSONRedirect(ctx.Repo.RepoLink + "/wiki/")
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ package actions
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
actions_model "code.gitea.io/gitea/models/actions"
|
||||
"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)
|
||||
ctx.Flash.Warning(ctx.Tr("actions.runners.delete_runner_failed"))
|
||||
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": failedRedirectTo,
|
||||
})
|
||||
ctx.JSONRedirect(failedRedirectTo)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -170,7 +167,5 @@ func RunnerDeletePost(ctx *context.Context, runnerID int64,
|
|||
|
||||
ctx.Flash.Success(ctx.Tr("actions.runners.delete_runner_success"))
|
||||
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": successRedirectTo,
|
||||
})
|
||||
ctx.JSONRedirect(successRedirectTo)
|
||||
}
|
||||
|
|
|
@ -227,9 +227,7 @@ func DeleteEmail(ctx *context.Context) {
|
|||
log.Trace("Email address deleted: %s", ctx.Doer.Name)
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("settings.email_deletion_success"))
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": setting.AppSubURL + "/user/settings/account",
|
||||
})
|
||||
ctx.JSONRedirect(setting.AppSubURL + "/user/settings/account")
|
||||
}
|
||||
|
||||
// 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.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": setting.AppSubURL + "/user/settings/applications",
|
||||
})
|
||||
ctx.JSONRedirect(setting.AppSubURL + "/user/settings/applications")
|
||||
}
|
||||
|
||||
func loadApplicationsData(ctx *context.Context) {
|
||||
|
|
|
@ -256,9 +256,7 @@ func DeleteKey(ctx *context.Context) {
|
|||
ctx.Flash.Warning("Function not implemented")
|
||||
ctx.Redirect(setting.AppSubURL + "/user/settings/keys")
|
||||
}
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": setting.AppSubURL + "/user/settings/keys",
|
||||
})
|
||||
ctx.JSONRedirect(setting.AppSubURL + "/user/settings/keys")
|
||||
}
|
||||
|
||||
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.JSON(http.StatusOK, map[string]any{"redirect": oa.BasePathList})
|
||||
ctx.JSONRedirect(oa.BasePathList)
|
||||
}
|
||||
|
||||
// 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.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)
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("settings.openid_deletion_success"))
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": setting.AppSubURL + "/user/settings/security",
|
||||
})
|
||||
ctx.JSONRedirect(setting.AppSubURL + "/user/settings/security")
|
||||
}
|
||||
|
||||
// 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{
|
||||
"redirect": setting.AppSubURL + "/user/settings/security",
|
||||
})
|
||||
ctx.JSONRedirect(setting.AppSubURL + "/user/settings/security")
|
||||
}
|
||||
|
||||
func loadSecurityData(ctx *context.Context) {
|
||||
|
|
|
@ -116,7 +116,5 @@ func WebauthnDelete(ctx *context.Context) {
|
|||
ctx.ServerError("GetWebAuthnCredentialByID", err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": setting.AppSubURL + "/user/settings/security",
|
||||
})
|
||||
ctx.JSONRedirect(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.JSON(http.StatusOK, map[string]any{
|
||||
"redirect": setting.AppSubURL + "/user/settings/hooks",
|
||||
})
|
||||
ctx.JSONRedirect(setting.AppSubURL + "/user/settings/hooks")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue