loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

authored by

wxiaoguang and committed by
GitHub
dcd3a631 338d03ce

+75 -196
-12
modules/context/base.go
··· 136 136 } 137 137 } 138 138 139 - func (b *Base) JSONRedirect(redirect string) { 140 - b.JSON(http.StatusOK, map[string]any{"redirect": redirect}) 141 - } 142 - 143 - func (b *Base) JSONOK() { 144 - b.JSON(http.StatusOK, map[string]any{"ok": true}) // this is only a dummy response, frontend seldom uses it 145 - } 146 - 147 - func (b *Base) JSONError(msg string) { 148 - b.JSON(http.StatusBadRequest, map[string]any{"errorMessage": msg}) 149 - } 150 - 151 139 // RemoteAddr returns the client machine ip address 152 140 func (b *Base) RemoteAddr() string { 153 141 return b.Req.RemoteAddr
+12
modules/context/context.go
··· 226 226 } 227 227 return msg 228 228 } 229 + 230 + func (ctx *Context) JSONRedirect(redirect string) { 231 + ctx.JSON(http.StatusOK, map[string]any{"redirect": redirect}) 232 + } 233 + 234 + func (ctx *Context) JSONOK() { 235 + ctx.JSON(http.StatusOK, map[string]any{"ok": true}) // this is only a dummy response, frontend seldom uses it 236 + } 237 + 238 + func (ctx *Context) JSONError(msg string) { 239 + ctx.JSON(http.StatusBadRequest, map[string]any{"errorMessage": msg}) 240 + }
+2 -6
routers/web/admin/auths.go
··· 454 454 } else { 455 455 ctx.Flash.Error(fmt.Sprintf("auth_service.DeleteSource: %v", err)) 456 456 } 457 - ctx.JSON(http.StatusOK, map[string]any{ 458 - "redirect": setting.AppSubURL + "/admin/auths/" + url.PathEscape(ctx.Params(":authid")), 459 - }) 457 + ctx.JSONRedirect(setting.AppSubURL + "/admin/auths/" + url.PathEscape(ctx.Params(":authid"))) 460 458 return 461 459 } 462 460 log.Trace("Authentication deleted by admin(%s): %d", ctx.Doer.Name, source.ID) 463 461 464 462 ctx.Flash.Success(ctx.Tr("admin.auths.deletion_success")) 465 - ctx.JSON(http.StatusOK, map[string]any{ 466 - "redirect": setting.AppSubURL + "/admin/auths", 467 - }) 463 + ctx.JSONRedirect(setting.AppSubURL + "/admin/auths") 468 464 }
+1 -3
routers/web/admin/config.go
··· 179 179 func ChangeConfig(ctx *context.Context) { 180 180 key := strings.TrimSpace(ctx.FormString("key")) 181 181 if key == "" { 182 - ctx.JSON(http.StatusOK, map[string]string{ 183 - "redirect": ctx.Req.URL.String(), 184 - }) 182 + ctx.JSONRedirect(ctx.Req.URL.String()) 185 183 return 186 184 } 187 185 value := ctx.FormString("value")
+1 -3
routers/web/admin/hooks.go
··· 67 67 ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success")) 68 68 } 69 69 70 - ctx.JSON(http.StatusOK, map[string]any{ 71 - "redirect": setting.AppSubURL + "/admin/hooks", 72 - }) 70 + ctx.JSONRedirect(setting.AppSubURL + "/admin/hooks") 73 71 }
+1 -3
routers/web/admin/packages.go
··· 97 97 } 98 98 99 99 ctx.Flash.Success(ctx.Tr("packages.settings.delete.success")) 100 - ctx.JSON(http.StatusOK, map[string]any{ 101 - "redirect": setting.AppSubURL + "/admin/packages?page=" + url.QueryEscape(ctx.FormString("page")) + "&q=" + url.QueryEscape(ctx.FormString("q")) + "&type=" + url.QueryEscape(ctx.FormString("type")), 102 - }) 100 + ctx.JSONRedirect(setting.AppSubURL + "/admin/packages?page=" + url.QueryEscape(ctx.FormString("page")) + "&q=" + url.QueryEscape(ctx.FormString("q")) + "&type=" + url.QueryEscape(ctx.FormString("type"))) 103 101 }
+1 -3
routers/web/admin/repos.go
··· 58 58 log.Trace("Repository deleted: %s", repo.FullName()) 59 59 60 60 ctx.Flash.Success(ctx.Tr("repo.settings.deletion_success")) 61 - ctx.JSON(http.StatusOK, map[string]any{ 62 - "redirect": setting.AppSubURL + "/admin/repos?page=" + url.QueryEscape(ctx.FormString("page")) + "&sort=" + url.QueryEscape(ctx.FormString("sort")), 63 - }) 61 + ctx.JSONRedirect(setting.AppSubURL + "/admin/repos?page=" + url.QueryEscape(ctx.FormString("page")) + "&sort=" + url.QueryEscape(ctx.FormString("sort"))) 64 62 } 65 63 66 64 // UnadoptedRepos lists the unadopted repositories
+1 -3
routers/web/admin/stacktrace.go
··· 42 42 func StacktraceCancel(ctx *context.Context) { 43 43 pid := ctx.Params("pid") 44 44 process.GetManager().Cancel(process.IDType(pid)) 45 - ctx.JSON(http.StatusOK, map[string]any{ 46 - "redirect": setting.AppSubURL + "/admin/monitor/stacktrace", 47 - }) 45 + ctx.JSONRedirect(setting.AppSubURL + "/admin/monitor/stacktrace") 48 46 }
+1 -1
routers/web/auth/webauthn.go
··· 154 154 } 155 155 _ = ctx.Session.Delete("twofaUid") 156 156 157 - ctx.JSON(http.StatusOK, map[string]string{"redirect": redirect}) 157 + ctx.JSONRedirect(redirect) 158 158 }
+3 -9
routers/web/org/members.go
··· 101 101 err = models.RemoveOrgUser(org.ID, uid) 102 102 if organization.IsErrLastOrgOwner(err) { 103 103 ctx.Flash.Error(ctx.Tr("form.last_org_owner")) 104 - ctx.JSON(http.StatusOK, map[string]any{ 105 - "redirect": ctx.Org.OrgLink + "/members", 106 - }) 104 + ctx.JSONRedirect(ctx.Org.OrgLink + "/members") 107 105 return 108 106 } 109 107 case "leave": ··· 115 113 }) 116 114 } else if organization.IsErrLastOrgOwner(err) { 117 115 ctx.Flash.Error(ctx.Tr("form.last_org_owner")) 118 - ctx.JSON(http.StatusOK, map[string]any{ 119 - "redirect": ctx.Org.OrgLink + "/members", 120 - }) 116 + ctx.JSONRedirect(ctx.Org.OrgLink + "/members") 121 117 } else { 122 118 log.Error("RemoveOrgUser(%d,%d): %v", org.ID, ctx.Doer.ID, err) 123 119 } ··· 138 134 redirect = setting.AppSubURL + "/" 139 135 } 140 136 141 - ctx.JSON(http.StatusOK, map[string]any{ 142 - "redirect": redirect, 143 - }) 137 + ctx.JSONRedirect(redirect) 144 138 }
+1 -3
routers/web/org/org_labels.go
··· 90 90 ctx.Flash.Success(ctx.Tr("repo.issues.label_deletion_success")) 91 91 } 92 92 93 - ctx.JSON(http.StatusOK, map[string]any{ 94 - "redirect": ctx.Org.OrgLink + "/settings/labels", 95 - }) 93 + ctx.JSONRedirect(ctx.Org.OrgLink + "/settings/labels") 96 94 } 97 95 98 96 // InitializeLabels init labels for an organization
+8 -24
routers/web/org/projects.go
··· 219 219 ctx.Flash.Success(ctx.Tr("repo.projects.deletion_success")) 220 220 } 221 221 222 - ctx.JSON(http.StatusOK, map[string]any{ 223 - "redirect": ctx.ContextUser.HomeLink() + "/-/projects", 224 - }) 222 + ctx.JSONRedirect(ctx.ContextUser.HomeLink() + "/-/projects") 225 223 } 226 224 227 225 // RenderEditProject allows a project to be edited ··· 449 447 } 450 448 } 451 449 452 - ctx.JSON(http.StatusOK, map[string]any{ 453 - "ok": true, 454 - }) 450 + ctx.JSONOK() 455 451 } 456 452 457 453 // DeleteProjectBoard allows for the deletion of a project board ··· 497 493 return 498 494 } 499 495 500 - ctx.JSON(http.StatusOK, map[string]any{ 501 - "ok": true, 502 - }) 496 + ctx.JSONOK() 503 497 } 504 498 505 499 // AddBoardToProjectPost allows a new board to be added to a project. ··· 526 520 return 527 521 } 528 522 529 - ctx.JSON(http.StatusOK, map[string]any{ 530 - "ok": true, 531 - }) 523 + ctx.JSONOK() 532 524 } 533 525 534 526 // CheckProjectBoardChangePermissions check permission ··· 594 586 return 595 587 } 596 588 597 - ctx.JSON(http.StatusOK, map[string]any{ 598 - "ok": true, 599 - }) 589 + ctx.JSONOK() 600 590 } 601 591 602 592 // SetDefaultProjectBoard set default board for uncategorized issues/pulls ··· 611 601 return 612 602 } 613 603 614 - ctx.JSON(http.StatusOK, map[string]any{ 615 - "ok": true, 616 - }) 604 + ctx.JSONOK() 617 605 } 618 606 619 607 // UnsetDefaultProjectBoard unset default board for uncategorized issues/pulls ··· 628 616 return 629 617 } 630 618 631 - ctx.JSON(http.StatusOK, map[string]any{ 632 - "ok": true, 633 - }) 619 + ctx.JSONOK() 634 620 } 635 621 636 622 // MoveIssues moves or keeps issues in a column and sorts them inside that column ··· 730 716 return 731 717 } 732 718 733 - ctx.JSON(http.StatusOK, map[string]any{ 734 - "ok": true, 735 - }) 719 + ctx.JSONOK() 736 720 }
+1 -3
routers/web/org/setting.go
··· 219 219 ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success")) 220 220 } 221 221 222 - ctx.JSON(http.StatusOK, map[string]any{ 223 - "redirect": ctx.Org.OrgLink + "/settings/hooks", 224 - }) 222 + ctx.JSONRedirect(ctx.Org.OrgLink + "/settings/hooks") 225 223 } 226 224 227 225 // Labels render organization labels page
+2 -6
routers/web/org/teams.go
··· 256 256 } 257 257 258 258 if action == "addall" || action == "removeall" { 259 - ctx.JSON(http.StatusOK, map[string]any{ 260 - "redirect": ctx.Org.OrgLink + "/teams/" + url.PathEscape(ctx.Org.Team.LowerName) + "/repositories", 261 - }) 259 + ctx.JSONRedirect(ctx.Org.OrgLink + "/teams/" + url.PathEscape(ctx.Org.Team.LowerName) + "/repositories") 262 260 return 263 261 } 264 262 ctx.Redirect(ctx.Org.OrgLink + "/teams/" + url.PathEscape(ctx.Org.Team.LowerName) + "/repositories") ··· 530 528 ctx.Flash.Success(ctx.Tr("org.teams.delete_team_success")) 531 529 } 532 530 533 - ctx.JSON(http.StatusOK, map[string]any{ 534 - "redirect": ctx.Org.OrgLink + "/teams", 535 - }) 531 + ctx.JSONRedirect(ctx.Org.OrgLink + "/teams") 536 532 } 537 533 538 534 // TeamInvite renders the team invite page
+1 -3
routers/web/repo/branch.go
··· 162 162 } 163 163 164 164 func redirect(ctx *context.Context) { 165 - ctx.JSON(http.StatusOK, map[string]any{ 166 - "redirect": ctx.Repo.RepoLink + "/branches?page=" + url.QueryEscape(ctx.FormString("page")), 167 - }) 165 + ctx.JSONRedirect(ctx.Repo.RepoLink + "/branches?page=" + url.QueryEscape(ctx.FormString("page"))) 168 166 } 169 167 170 168 // CreateBranch creates new branch in repository
+3 -9
routers/web/repo/issue.go
··· 2221 2221 } 2222 2222 } 2223 2223 2224 - ctx.JSON(http.StatusOK, map[string]any{ 2225 - "ok": true, 2226 - }) 2224 + ctx.JSONOK() 2227 2225 } 2228 2226 2229 2227 // UpdateIssueAssignee change issue's or pull's assignee ··· 2267 2265 } 2268 2266 } 2269 2267 } 2270 - ctx.JSON(http.StatusOK, map[string]any{ 2271 - "ok": true, 2272 - }) 2268 + ctx.JSONOK() 2273 2269 } 2274 2270 2275 2271 // UpdatePullReviewRequest add or remove review request ··· 2392 2388 } 2393 2389 } 2394 2390 2395 - ctx.JSON(http.StatusOK, map[string]any{ 2396 - "ok": true, 2397 - }) 2391 + ctx.JSONOK() 2398 2392 } 2399 2393 2400 2394 // SearchIssues searches for issues across the repositories that the user has access to
+2 -6
routers/web/repo/issue_label.go
··· 157 157 ctx.Flash.Success(ctx.Tr("repo.issues.label_deletion_success")) 158 158 } 159 159 160 - ctx.JSON(http.StatusOK, map[string]any{ 161 - "redirect": ctx.Repo.RepoLink + "/labels", 162 - }) 160 + ctx.JSONRedirect(ctx.Repo.RepoLink + "/labels") 163 161 } 164 162 165 163 // UpdateIssueLabel change issue's labels ··· 226 224 return 227 225 } 228 226 229 - ctx.JSON(http.StatusOK, map[string]any{ 230 - "ok": true, 231 - }) 227 + ctx.JSONOK() 232 228 }
+1 -3
routers/web/repo/milestone.go
··· 255 255 ctx.Flash.Success(ctx.Tr("repo.milestones.deletion_success")) 256 256 } 257 257 258 - ctx.JSON(http.StatusOK, map[string]any{ 259 - "redirect": ctx.Repo.RepoLink + "/milestones", 260 - }) 258 + ctx.JSONRedirect(ctx.Repo.RepoLink + "/milestones") 261 259 } 262 260 263 261 // MilestoneIssuesAndPulls lists all the issues and pull requests of the milestone
+8 -24
routers/web/repo/projects.go
··· 203 203 ctx.Flash.Success(ctx.Tr("repo.projects.deletion_success")) 204 204 } 205 205 206 - ctx.JSON(http.StatusOK, map[string]any{ 207 - "redirect": ctx.Repo.RepoLink + "/projects", 208 - }) 206 + ctx.JSONRedirect(ctx.Repo.RepoLink + "/projects") 209 207 } 210 208 211 209 // RenderEditProject allows a project to be edited ··· 397 395 } 398 396 } 399 397 400 - ctx.JSON(http.StatusOK, map[string]any{ 401 - "ok": true, 402 - }) 398 + ctx.JSONOK() 403 399 } 404 400 405 401 // DeleteProjectBoard allows for the deletion of a project board ··· 452 448 return 453 449 } 454 450 455 - ctx.JSON(http.StatusOK, map[string]any{ 456 - "ok": true, 457 - }) 451 + ctx.JSONOK() 458 452 } 459 453 460 454 // AddBoardToProjectPost allows a new board to be added to a project. ··· 487 481 return 488 482 } 489 483 490 - ctx.JSON(http.StatusOK, map[string]any{ 491 - "ok": true, 492 - }) 484 + ctx.JSONOK() 493 485 } 494 486 495 487 func checkProjectBoardChangePermissions(ctx *context.Context) (*project_model.Project, *project_model.Board) { ··· 561 553 return 562 554 } 563 555 564 - ctx.JSON(http.StatusOK, map[string]any{ 565 - "ok": true, 566 - }) 556 + ctx.JSONOK() 567 557 } 568 558 569 559 // SetDefaultProjectBoard set default board for uncategorized issues/pulls ··· 578 568 return 579 569 } 580 570 581 - ctx.JSON(http.StatusOK, map[string]any{ 582 - "ok": true, 583 - }) 571 + ctx.JSONOK() 584 572 } 585 573 586 574 // UnSetDefaultProjectBoard unset default board for uncategorized issues/pulls ··· 595 583 return 596 584 } 597 585 598 - ctx.JSON(http.StatusOK, map[string]any{ 599 - "ok": true, 600 - }) 586 + ctx.JSONOK() 601 587 } 602 588 603 589 // MoveIssues moves or keeps issues in a column and sorts them inside that column ··· 699 685 return 700 686 } 701 687 702 - ctx.JSON(http.StatusOK, map[string]any{ 703 - "ok": true, 704 - }) 688 + ctx.JSONOK() 705 689 }
+1 -3
routers/web/repo/pull.go
··· 1423 1423 } 1424 1424 1425 1425 defer func() { 1426 - ctx.JSON(http.StatusOK, map[string]any{ 1427 - "redirect": issue.Link(), 1428 - }) 1426 + ctx.JSONRedirect(issue.Link()) 1429 1427 }() 1430 1428 1431 1429 // Check if branch has no new commits
+1 -3
routers/web/repo/pull_review.go
··· 156 156 renderConversation(ctx, comment) 157 157 return 158 158 } 159 - ctx.JSON(http.StatusOK, map[string]any{ 160 - "ok": true, 161 - }) 159 + ctx.JSONOK() 162 160 } 163 161 164 162 func renderConversation(ctx *context.Context, comment *issues_model.Comment) {
+2 -6
routers/web/repo/release.go
··· 628 628 } 629 629 630 630 if isDelTag { 631 - ctx.JSON(http.StatusOK, map[string]any{ 632 - "redirect": ctx.Repo.RepoLink + "/tags", 633 - }) 631 + ctx.JSONRedirect(ctx.Repo.RepoLink + "/tags") 634 632 return 635 633 } 636 634 637 - ctx.JSON(http.StatusOK, map[string]any{ 638 - "redirect": ctx.Repo.RepoLink + "/releases", 639 - }) 635 + ctx.JSONRedirect(ctx.Repo.RepoLink + "/releases") 640 636 }
+2 -6
routers/web/repo/setting/collaboration.go
··· 133 133 ctx.Flash.Success(ctx.Tr("repo.settings.remove_collaborator_success")) 134 134 } 135 135 136 - ctx.JSON(http.StatusOK, map[string]any{ 137 - "redirect": ctx.Repo.RepoLink + "/settings/collaboration", 138 - }) 136 + ctx.JSONRedirect(ctx.Repo.RepoLink + "/settings/collaboration") 139 137 } 140 138 141 139 // AddTeamPost response for adding a team to a repository ··· 204 202 } 205 203 206 204 ctx.Flash.Success(ctx.Tr("repo.settings.remove_team_success")) 207 - ctx.JSON(http.StatusOK, map[string]any{ 208 - "redirect": ctx.Repo.RepoLink + "/settings/collaboration", 209 - }) 205 + ctx.JSONRedirect(ctx.Repo.RepoLink + "/settings/collaboration") 210 206 }
+1 -3
routers/web/repo/setting/deploy_key.go
··· 105 105 ctx.Flash.Success(ctx.Tr("repo.settings.deploy_key_deletion_success")) 106 106 } 107 107 108 - ctx.JSON(http.StatusOK, map[string]any{ 109 - "redirect": ctx.Repo.RepoLink + "/settings/keys", 110 - }) 108 + ctx.JSONRedirect(ctx.Repo.RepoLink + "/settings/keys") 111 109 }
+5 -15
routers/web/repo/setting/protected_branch.go
··· 318 318 ruleID := ctx.ParamsInt64("id") 319 319 if ruleID <= 0 { 320 320 ctx.Flash.Error(ctx.Tr("repo.settings.remove_protected_branch_failed", fmt.Sprintf("%d", ruleID))) 321 - ctx.JSON(http.StatusOK, map[string]any{ 322 - "redirect": fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink), 323 - }) 321 + ctx.JSONRedirect(fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink)) 324 322 return 325 323 } 326 324 327 325 rule, err := git_model.GetProtectedBranchRuleByID(ctx, ctx.Repo.Repository.ID, ruleID) 328 326 if err != nil { 329 327 ctx.Flash.Error(ctx.Tr("repo.settings.remove_protected_branch_failed", fmt.Sprintf("%d", ruleID))) 330 - ctx.JSON(http.StatusOK, map[string]any{ 331 - "redirect": fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink), 332 - }) 328 + ctx.JSONRedirect(fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink)) 333 329 return 334 330 } 335 331 336 332 if rule == nil { 337 333 ctx.Flash.Error(ctx.Tr("repo.settings.remove_protected_branch_failed", fmt.Sprintf("%d", ruleID))) 338 - ctx.JSON(http.StatusOK, map[string]any{ 339 - "redirect": fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink), 340 - }) 334 + ctx.JSONRedirect(fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink)) 341 335 return 342 336 } 343 337 344 338 if err := git_model.DeleteProtectedBranch(ctx, ctx.Repo.Repository.ID, ruleID); err != nil { 345 339 ctx.Flash.Error(ctx.Tr("repo.settings.remove_protected_branch_failed", rule.RuleName)) 346 - ctx.JSON(http.StatusOK, map[string]any{ 347 - "redirect": fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink), 348 - }) 340 + ctx.JSONRedirect(fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink)) 349 341 return 350 342 } 351 343 352 344 ctx.Flash.Success(ctx.Tr("repo.settings.remove_protected_branch_success", rule.RuleName)) 353 - ctx.JSON(http.StatusOK, map[string]any{ 354 - "redirect": fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink), 355 - }) 345 + ctx.JSONRedirect(fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink)) 356 346 } 357 347 358 348 // RenameBranchPost responses for rename a branch
+1 -3
routers/web/repo/setting/webhook.go
··· 729 729 ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success")) 730 730 } 731 731 732 - ctx.JSON(http.StatusOK, map[string]any{ 733 - "redirect": ctx.Repo.RepoLink + "/settings/hooks", 734 - }) 732 + ctx.JSONRedirect(ctx.Repo.RepoLink + "/settings/hooks") 735 733 }
+1 -3
routers/web/repo/wiki.go
··· 790 790 791 791 notification.NotifyDeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, string(wikiName)) 792 792 793 - ctx.JSON(http.StatusOK, map[string]any{ 794 - "redirect": ctx.Repo.RepoLink + "/wiki/", 795 - }) 793 + ctx.JSONRedirect(ctx.Repo.RepoLink + "/wiki/") 796 794 }
+2 -7
routers/web/shared/actions/runners.go
··· 5 5 6 6 import ( 7 7 "errors" 8 - "net/http" 9 8 10 9 actions_model "code.gitea.io/gitea/models/actions" 11 10 "code.gitea.io/gitea/models/db" ··· 160 159 log.Warn("DeleteRunnerPost.UpdateRunner failed: %v, url: %s", err, ctx.Req.URL) 161 160 ctx.Flash.Warning(ctx.Tr("actions.runners.delete_runner_failed")) 162 161 163 - ctx.JSON(http.StatusOK, map[string]any{ 164 - "redirect": failedRedirectTo, 165 - }) 162 + ctx.JSONRedirect(failedRedirectTo) 166 163 return 167 164 } 168 165 ··· 170 167 171 168 ctx.Flash.Success(ctx.Tr("actions.runners.delete_runner_success")) 172 169 173 - ctx.JSON(http.StatusOK, map[string]any{ 174 - "redirect": successRedirectTo, 175 - }) 170 + ctx.JSONRedirect(successRedirectTo) 176 171 }
+1 -3
routers/web/user/setting/account.go
··· 227 227 log.Trace("Email address deleted: %s", ctx.Doer.Name) 228 228 229 229 ctx.Flash.Success(ctx.Tr("settings.email_deletion_success")) 230 - ctx.JSON(http.StatusOK, map[string]any{ 231 - "redirect": setting.AppSubURL + "/user/settings/account", 232 - }) 230 + ctx.JSONRedirect(setting.AppSubURL + "/user/settings/account") 233 231 } 234 232 235 233 // DeleteAccount render user suicide page and response for delete user himself
+1 -3
routers/web/user/setting/applications.go
··· 83 83 ctx.Flash.Success(ctx.Tr("settings.delete_token_success")) 84 84 } 85 85 86 - ctx.JSON(http.StatusOK, map[string]any{ 87 - "redirect": setting.AppSubURL + "/user/settings/applications", 88 - }) 86 + ctx.JSONRedirect(setting.AppSubURL + "/user/settings/applications") 89 87 } 90 88 91 89 func loadApplicationsData(ctx *context.Context) {
+1 -3
routers/web/user/setting/keys.go
··· 256 256 ctx.Flash.Warning("Function not implemented") 257 257 ctx.Redirect(setting.AppSubURL + "/user/settings/keys") 258 258 } 259 - ctx.JSON(http.StatusOK, map[string]any{ 260 - "redirect": setting.AppSubURL + "/user/settings/keys", 261 - }) 259 + ctx.JSONRedirect(setting.AppSubURL + "/user/settings/keys") 262 260 } 263 261 264 262 func loadKeysData(ctx *context.Context) {
+2 -2
routers/web/user/setting/oauth2_common.go
··· 138 138 } 139 139 140 140 ctx.Flash.Success(ctx.Tr("settings.remove_oauth2_application_success")) 141 - ctx.JSON(http.StatusOK, map[string]any{"redirect": oa.BasePathList}) 141 + ctx.JSONRedirect(oa.BasePathList) 142 142 } 143 143 144 144 // RevokeGrant revokes the grant ··· 149 149 } 150 150 151 151 ctx.Flash.Success(ctx.Tr("settings.revoke_oauth2_grant_success")) 152 - ctx.JSON(http.StatusOK, map[string]any{"redirect": oa.BasePathList}) 152 + ctx.JSONRedirect(oa.BasePathList) 153 153 }
+1 -3
routers/web/user/setting/security/openid.go
··· 112 112 log.Trace("OpenID address deleted: %s", ctx.Doer.Name) 113 113 114 114 ctx.Flash.Success(ctx.Tr("settings.openid_deletion_success")) 115 - ctx.JSON(http.StatusOK, map[string]any{ 116 - "redirect": setting.AppSubURL + "/user/settings/security", 117 - }) 115 + ctx.JSONRedirect(setting.AppSubURL + "/user/settings/security") 118 116 } 119 117 120 118 // ToggleOpenIDVisibility response for toggle visibility of user's openid
+1 -3
routers/web/user/setting/security/security.go
··· 48 48 } 49 49 } 50 50 51 - ctx.JSON(http.StatusOK, map[string]any{ 52 - "redirect": setting.AppSubURL + "/user/settings/security", 53 - }) 51 + ctx.JSONRedirect(setting.AppSubURL + "/user/settings/security") 54 52 } 55 53 56 54 func loadSecurityData(ctx *context.Context) {
+1 -3
routers/web/user/setting/security/webauthn.go
··· 116 116 ctx.ServerError("GetWebAuthnCredentialByID", err) 117 117 return 118 118 } 119 - ctx.JSON(http.StatusOK, map[string]any{ 120 - "redirect": setting.AppSubURL + "/user/settings/security", 121 - }) 119 + ctx.JSONRedirect(setting.AppSubURL + "/user/settings/security") 122 120 }
+1 -3
routers/web/user/setting/webhooks.go
··· 42 42 ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success")) 43 43 } 44 44 45 - ctx.JSON(http.StatusOK, map[string]any{ 46 - "redirect": setting.AppSubURL + "/user/settings/hooks", 47 - }) 45 + ctx.JSONRedirect(setting.AppSubURL + "/user/settings/hooks") 48 46 }