diff options
author | 6543 <6543@obermui.de> | 2021-04-05 17:30:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-05 11:30:52 -0400 |
commit | 16dea6cebd375fc274fc7a9c216dbcc9e22bd5c7 (patch) | |
tree | 75d47012e9899ca24408aeef7fa3adfcd4beaed1 /routers/admin | |
parent | e9fba18a26c9d0f8586254a83ef7afcd293a725a (diff) | |
download | gitea-16dea6cebd375fc274fc7a9c216dbcc9e22bd5c7.tar.gz gitea-16dea6cebd375fc274fc7a9c216dbcc9e22bd5c7.zip |
[refactor] replace int with httpStatusCodes (#15282)
* replace "200" (int) with "http.StatusOK" (const)
* ctx.Error & ctx.HTML
* ctx.JSON Part1
* ctx.JSON Part2
* ctx.JSON Part3
Diffstat (limited to 'routers/admin')
-rw-r--r-- | routers/admin/admin.go | 13 | ||||
-rw-r--r-- | routers/admin/auths.go | 21 | ||||
-rw-r--r-- | routers/admin/emails.go | 5 | ||||
-rw-r--r-- | routers/admin/hooks.go | 6 | ||||
-rw-r--r-- | routers/admin/notice.go | 3 | ||||
-rw-r--r-- | routers/admin/repos.go | 7 | ||||
-rw-r--r-- | routers/admin/users.go | 15 |
7 files changed, 39 insertions, 31 deletions
diff --git a/routers/admin/admin.go b/routers/admin/admin.go index 49f6a394a6..0ce3dfc05f 100644 --- a/routers/admin/admin.go +++ b/routers/admin/admin.go @@ -7,6 +7,7 @@ package admin import ( "fmt" + "net/http" "net/url" "os" "runtime" @@ -128,7 +129,7 @@ func Dashboard(ctx *context.Context) { updateSystemStatus() ctx.Data["SysStatus"] = sysStatus ctx.Data["SSH"] = setting.SSH - ctx.HTML(200, tplDashboard) + ctx.HTML(http.StatusOK, tplDashboard) } // DashboardPost run an admin operation @@ -315,7 +316,7 @@ func Config(ctx *context.Context) { ctx.Data["EnableXORMLog"] = setting.EnableXORMLog ctx.Data["LogSQL"] = setting.Database.LogSQL - ctx.HTML(200, tplConfig) + ctx.HTML(http.StatusOK, tplConfig) } // Monitor show admin monitor page @@ -326,14 +327,14 @@ func Monitor(ctx *context.Context) { ctx.Data["Processes"] = process.GetManager().Processes() ctx.Data["Entries"] = cron.ListTasks() ctx.Data["Queues"] = queue.GetManager().ManagedQueues() - ctx.HTML(200, tplMonitor) + ctx.HTML(http.StatusOK, tplMonitor) } // MonitorCancel cancels a process func MonitorCancel(ctx *context.Context) { pid := ctx.ParamsInt64("pid") process.GetManager().Cancel(pid) - ctx.JSON(200, map[string]interface{}{ + ctx.JSON(http.StatusOK, map[string]interface{}{ "redirect": setting.AppSubURL + "/admin/monitor", }) } @@ -350,7 +351,7 @@ func Queue(ctx *context.Context) { ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminMonitor"] = true ctx.Data["Queue"] = mq - ctx.HTML(200, tplQueue) + ctx.HTML(http.StatusOK, tplQueue) } // WorkerCancel cancels a worker group @@ -364,7 +365,7 @@ func WorkerCancel(ctx *context.Context) { pid := ctx.ParamsInt64("pid") mq.CancelWorkers(pid) ctx.Flash.Info(ctx.Tr("admin.monitor.queue.pool.cancelling")) - ctx.JSON(200, map[string]interface{}{ + ctx.JSON(http.StatusOK, map[string]interface{}{ "redirect": setting.AppSubURL + "/admin/monitor/queue/" + strconv.FormatInt(qid, 10), }) } diff --git a/routers/admin/auths.go b/routers/admin/auths.go index 12d0a2ccfa..790eecedb7 100644 --- a/routers/admin/auths.go +++ b/routers/admin/auths.go @@ -7,6 +7,7 @@ package admin import ( "errors" "fmt" + "net/http" "regexp" "code.gitea.io/gitea/models" @@ -49,7 +50,7 @@ func Authentications(ctx *context.Context) { } ctx.Data["Total"] = models.CountLoginSources() - ctx.HTML(200, tplAuths) + ctx.HTML(http.StatusOK, tplAuths) } type dropdownItem struct { @@ -109,7 +110,7 @@ func NewAuthSource(ctx *context.Context) { break } - ctx.HTML(200, tplAuthNew) + ctx.HTML(http.StatusOK, tplAuthNew) } func parseLDAPConfig(form auth.AuthenticationForm) *models.LDAPConfig { @@ -256,13 +257,13 @@ func NewAuthSourcePost(ctx *context.Context) { return } default: - ctx.Error(400) + ctx.Error(http.StatusBadRequest) return } ctx.Data["HasTLS"] = hasTLS if ctx.HasError() { - ctx.HTML(200, tplAuthNew) + ctx.HTML(http.StatusOK, tplAuthNew) return } @@ -310,7 +311,7 @@ func EditAuthSource(ctx *context.Context) { if source.IsOAuth2() { ctx.Data["CurrentOAuth2Provider"] = models.OAuth2Providers[source.OAuth2().Provider] } - ctx.HTML(200, tplAuthEdit) + ctx.HTML(http.StatusOK, tplAuthEdit) } // EditAuthSourcePost response for editing auth source @@ -333,7 +334,7 @@ func EditAuthSourcePost(ctx *context.Context) { ctx.Data["HasTLS"] = source.HasTLS() if ctx.HasError() { - ctx.HTML(200, tplAuthEdit) + ctx.HTML(http.StatusOK, tplAuthEdit) return } @@ -356,7 +357,7 @@ func EditAuthSourcePost(ctx *context.Context) { return } default: - ctx.Error(400) + ctx.Error(http.StatusBadRequest) return } @@ -367,7 +368,7 @@ func EditAuthSourcePost(ctx *context.Context) { if err := models.UpdateSource(source); err != nil { if models.IsErrOpenIDConnectInitialize(err) { ctx.Flash.Error(err.Error(), true) - ctx.HTML(200, tplAuthEdit) + ctx.HTML(http.StatusOK, tplAuthEdit) } else { ctx.ServerError("UpdateSource", err) } @@ -393,7 +394,7 @@ func DeleteAuthSource(ctx *context.Context) { } else { ctx.Flash.Error(fmt.Sprintf("DeleteSource: %v", err)) } - ctx.JSON(200, map[string]interface{}{ + ctx.JSON(http.StatusOK, map[string]interface{}{ "redirect": setting.AppSubURL + "/admin/auths/" + ctx.Params(":authid"), }) return @@ -401,7 +402,7 @@ func DeleteAuthSource(ctx *context.Context) { log.Trace("Authentication deleted by admin(%s): %d", ctx.User.Name, source.ID) ctx.Flash.Success(ctx.Tr("admin.auths.deletion_success")) - ctx.JSON(200, map[string]interface{}{ + ctx.JSON(http.StatusOK, map[string]interface{}{ "redirect": setting.AppSubURL + "/admin/auths", }) } diff --git a/routers/admin/emails.go b/routers/admin/emails.go index 4cc7253ca9..f7e8c97fb6 100644 --- a/routers/admin/emails.go +++ b/routers/admin/emails.go @@ -6,6 +6,7 @@ package admin import ( "bytes" + "net/http" "net/url" "code.gitea.io/gitea/models" @@ -96,7 +97,7 @@ func Emails(ctx *context.Context) { pager.SetDefaultParams(ctx) ctx.Data["Page"] = pager - ctx.HTML(200, tplEmails) + ctx.HTML(http.StatusOK, tplEmails) } var ( @@ -118,7 +119,7 @@ func ActivateEmail(ctx *context.Context) { activate, oka := truefalse[ctx.Query("activate")] if uid == 0 || len(email) == 0 || !okp || !oka { - ctx.Error(400) + ctx.Error(http.StatusBadRequest) return } diff --git a/routers/admin/hooks.go b/routers/admin/hooks.go index e233e8ac00..ff32260cc0 100644 --- a/routers/admin/hooks.go +++ b/routers/admin/hooks.go @@ -5,6 +5,8 @@ package admin import ( + "net/http" + "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" @@ -53,7 +55,7 @@ func DefaultOrSystemWebhooks(ctx *context.Context) { ctx.Data["DefaultWebhooks"] = def ctx.Data["SystemWebhooks"] = sys - ctx.HTML(200, tplAdminHooks) + ctx.HTML(http.StatusOK, tplAdminHooks) } // DeleteDefaultOrSystemWebhook handler to delete an admin-defined system or default webhook @@ -64,7 +66,7 @@ func DeleteDefaultOrSystemWebhook(ctx *context.Context) { ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success")) } - ctx.JSON(200, map[string]interface{}{ + ctx.JSON(http.StatusOK, map[string]interface{}{ "redirect": setting.AppSubURL + "/admin/hooks", }) } diff --git a/routers/admin/notice.go b/routers/admin/notice.go index 2ee1b59730..e2ebd0d917 100644 --- a/routers/admin/notice.go +++ b/routers/admin/notice.go @@ -6,6 +6,7 @@ package admin import ( + "net/http" "strconv" "code.gitea.io/gitea/models" @@ -42,7 +43,7 @@ func Notices(ctx *context.Context) { ctx.Data["Page"] = context.NewPagination(int(total), setting.UI.Admin.NoticePagingNum, page, 5) - ctx.HTML(200, tplNotices) + ctx.HTML(http.StatusOK, tplNotices) } // DeleteNotices delete the specific notices diff --git a/routers/admin/repos.go b/routers/admin/repos.go index 46d0b60f24..82b8cc1a7d 100644 --- a/routers/admin/repos.go +++ b/routers/admin/repos.go @@ -5,6 +5,7 @@ package admin import ( + "net/http" "net/url" "strconv" "strings" @@ -53,7 +54,7 @@ func DeleteRepo(ctx *context.Context) { log.Trace("Repository deleted: %s", repo.FullName()) ctx.Flash.Success(ctx.Tr("repo.settings.deletion_success")) - ctx.JSON(200, map[string]interface{}{ + ctx.JSON(http.StatusOK, map[string]interface{}{ "redirect": setting.AppSubURL + "/admin/repos?page=" + ctx.Query("page") + "&sort=" + ctx.Query("sort"), }) } @@ -85,7 +86,7 @@ func UnadoptedRepos(ctx *context.Context) { pager.SetDefaultParams(ctx) pager.AddParam(ctx, "search", "search") ctx.Data["Page"] = pager - ctx.HTML(200, tplUnadoptedRepos) + ctx.HTML(http.StatusOK, tplUnadoptedRepos) return } @@ -99,7 +100,7 @@ func UnadoptedRepos(ctx *context.Context) { pager.SetDefaultParams(ctx) pager.AddParam(ctx, "search", "search") ctx.Data["Page"] = pager - ctx.HTML(200, tplUnadoptedRepos) + ctx.HTML(http.StatusOK, tplUnadoptedRepos) } // AdoptOrDeleteRepository adopts or deletes a repository diff --git a/routers/admin/users.go b/routers/admin/users.go index e3f5692030..13609ac746 100644 --- a/routers/admin/users.go +++ b/routers/admin/users.go @@ -7,6 +7,7 @@ package admin import ( "fmt" + "net/http" "strconv" "strings" @@ -60,7 +61,7 @@ func NewUser(ctx *context.Context) { ctx.Data["Sources"] = sources ctx.Data["CanSendEmail"] = setting.MailService != nil - ctx.HTML(200, tplUserNew) + ctx.HTML(http.StatusOK, tplUserNew) } // NewUserPost response for adding a new user @@ -80,7 +81,7 @@ func NewUserPost(ctx *context.Context) { ctx.Data["CanSendEmail"] = setting.MailService != nil if ctx.HasError() { - ctx.HTML(200, tplUserNew) + ctx.HTML(http.StatusOK, tplUserNew) return } @@ -212,7 +213,7 @@ func EditUser(ctx *context.Context) { return } - ctx.HTML(200, tplUserEdit) + ctx.HTML(http.StatusOK, tplUserEdit) } // EditUserPost response for editting user @@ -229,7 +230,7 @@ func EditUserPost(ctx *context.Context) { } if ctx.HasError() { - ctx.HTML(200, tplUserEdit) + ctx.HTML(http.StatusOK, tplUserEdit) return } @@ -348,12 +349,12 @@ func DeleteUser(ctx *context.Context) { switch { case models.IsErrUserOwnRepos(err): ctx.Flash.Error(ctx.Tr("admin.users.still_own_repo")) - ctx.JSON(200, map[string]interface{}{ + ctx.JSON(http.StatusOK, map[string]interface{}{ "redirect": setting.AppSubURL + "/admin/users/" + ctx.Params(":userid"), }) case models.IsErrUserHasOrgs(err): ctx.Flash.Error(ctx.Tr("admin.users.still_has_org")) - ctx.JSON(200, map[string]interface{}{ + ctx.JSON(http.StatusOK, map[string]interface{}{ "redirect": setting.AppSubURL + "/admin/users/" + ctx.Params(":userid"), }) default: @@ -364,7 +365,7 @@ func DeleteUser(ctx *context.Context) { log.Trace("Account deleted by admin (%s): %s", ctx.User.Name, u.Name) ctx.Flash.Success(ctx.Tr("admin.users.deletion_success")) - ctx.JSON(200, map[string]interface{}{ + ctx.JSON(http.StatusOK, map[string]interface{}{ "redirect": setting.AppSubURL + "/admin/users", }) } |