Преглед на файлове

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
tags/v1.21.0-rc0
wxiaoguang преди 10 месеца
родител
ревизия
dcd3a63128
No account linked to committer's email address
променени са 36 файла, в които са добавени 75 реда и са изтрити 196 реда
  1. 0
    12
      modules/context/base.go
  2. 12
    0
      modules/context/context.go
  3. 2
    6
      routers/web/admin/auths.go
  4. 1
    3
      routers/web/admin/config.go
  5. 1
    3
      routers/web/admin/hooks.go
  6. 1
    3
      routers/web/admin/packages.go
  7. 1
    3
      routers/web/admin/repos.go
  8. 1
    3
      routers/web/admin/stacktrace.go
  9. 1
    1
      routers/web/auth/webauthn.go
  10. 3
    9
      routers/web/org/members.go
  11. 1
    3
      routers/web/org/org_labels.go
  12. 8
    24
      routers/web/org/projects.go
  13. 1
    3
      routers/web/org/setting.go
  14. 2
    6
      routers/web/org/teams.go
  15. 1
    3
      routers/web/repo/branch.go
  16. 3
    9
      routers/web/repo/issue.go
  17. 2
    6
      routers/web/repo/issue_label.go
  18. 1
    3
      routers/web/repo/milestone.go
  19. 8
    24
      routers/web/repo/projects.go
  20. 1
    3
      routers/web/repo/pull.go
  21. 1
    3
      routers/web/repo/pull_review.go
  22. 2
    6
      routers/web/repo/release.go
  23. 2
    6
      routers/web/repo/setting/collaboration.go
  24. 1
    3
      routers/web/repo/setting/deploy_key.go
  25. 5
    15
      routers/web/repo/setting/protected_branch.go
  26. 1
    3
      routers/web/repo/setting/webhook.go
  27. 1
    3
      routers/web/repo/wiki.go
  28. 2
    7
      routers/web/shared/actions/runners.go
  29. 1
    3
      routers/web/user/setting/account.go
  30. 1
    3
      routers/web/user/setting/applications.go
  31. 1
    3
      routers/web/user/setting/keys.go
  32. 2
    2
      routers/web/user/setting/oauth2_common.go
  33. 1
    3
      routers/web/user/setting/security/openid.go
  34. 1
    3
      routers/web/user/setting/security/security.go
  35. 1
    3
      routers/web/user/setting/security/webauthn.go
  36. 1
    3
      routers/web/user/setting/webhooks.go

+ 0
- 12
modules/context/base.go Целия файл

@@ -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

+ 12
- 0
modules/context/context.go Целия файл

@@ -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})
}

+ 2
- 6
routers/web/admin/auths.go Целия файл

@@ -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")
}

+ 1
- 3
routers/web/admin/config.go Целия файл

@@ -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")

+ 1
- 3
routers/web/admin/hooks.go Целия файл

@@ -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")
}

+ 1
- 3
routers/web/admin/packages.go Целия файл

@@ -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")))
}

+ 1
- 3
routers/web/admin/repos.go Целия файл

@@ -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

+ 1
- 3
routers/web/admin/stacktrace.go Целия файл

@@ -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")
}

+ 1
- 1
routers/web/auth/webauthn.go Целия файл

@@ -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)
}

+ 3
- 9
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)
}

+ 1
- 3
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

+ 8
- 24
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()
}

+ 1
- 3
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

+ 2
- 6
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

+ 1
- 3
routers/web/repo/branch.go Целия файл

@@ -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

+ 3
- 9
routers/web/repo/issue.go Целия файл

@@ -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

+ 2
- 6
routers/web/repo/issue_label.go Целия файл

@@ -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()
}

+ 1
- 3
routers/web/repo/milestone.go Целия файл

@@ -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

+ 8
- 24
routers/web/repo/projects.go Целия файл

@@ -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()
}

+ 1
- 3
routers/web/repo/pull.go Целия файл

@@ -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

+ 1
- 3
routers/web/repo/pull_review.go Целия файл

@@ -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) {

+ 2
- 6
routers/web/repo/release.go Целия файл

@@ -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")
}

+ 2
- 6
routers/web/repo/setting/collaboration.go Целия файл

@@ -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")
}

+ 1
- 3
routers/web/repo/setting/deploy_key.go Целия файл

@@ -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")
}

+ 5
- 15
routers/web/repo/setting/protected_branch.go Целия файл

@@ -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

+ 1
- 3
routers/web/repo/setting/webhook.go Целия файл

@@ -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")
}

+ 1
- 3
routers/web/repo/wiki.go Целия файл

@@ -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/")
}

+ 2
- 7
routers/web/shared/actions/runners.go Целия файл

@@ -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)
}

+ 1
- 3
routers/web/user/setting/account.go Целия файл

@@ -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

+ 1
- 3
routers/web/user/setting/applications.go Целия файл

@@ -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) {

+ 1
- 3
routers/web/user/setting/keys.go Целия файл

@@ -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) {

+ 2
- 2
routers/web/user/setting/oauth2_common.go Целия файл

@@ -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)
}

+ 1
- 3
routers/web/user/setting/security/openid.go Целия файл

@@ -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

+ 1
- 3
routers/web/user/setting/security/security.go Целия файл

@@ -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) {

+ 1
- 3
routers/web/user/setting/security/webauthn.go Целия файл

@@ -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")
}

+ 1
- 3
routers/web/user/setting/webhooks.go Целия файл

@@ -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…
Отказ
Запис