[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
This commit is contained in:
6543 2021-04-05 17:30:52 +02:00 committed by GitHub
parent e9fba18a26
commit 16dea6cebd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
64 changed files with 504 additions and 441 deletions

View file

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