[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:
+3
-2
@@ -5,6 +5,7 @@
|
||||
package org
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
@@ -106,7 +107,7 @@ func Home(ctx *context.Context) {
|
||||
if ctx.User != nil {
|
||||
isMember, err := org.IsOrgMember(ctx.User.ID)
|
||||
if err != nil {
|
||||
ctx.Error(500, "IsOrgMember")
|
||||
ctx.Error(http.StatusInternalServerError, "IsOrgMember")
|
||||
return
|
||||
}
|
||||
opts.PublicOnly = !isMember && !ctx.User.IsAdmin
|
||||
@@ -137,5 +138,5 @@ func Home(ctx *context.Context) {
|
||||
pager.SetDefaultParams(ctx)
|
||||
ctx.Data["Page"] = pager
|
||||
|
||||
ctx.HTML(200, tplOrgHome)
|
||||
ctx.HTML(http.StatusOK, tplOrgHome)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
package org
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
@@ -37,7 +39,7 @@ func Members(ctx *context.Context) {
|
||||
if ctx.User != nil {
|
||||
isMember, err := ctx.Org.Organization.IsOrgMember(ctx.User.ID)
|
||||
if err != nil {
|
||||
ctx.Error(500, "IsOrgMember")
|
||||
ctx.Error(http.StatusInternalServerError, "IsOrgMember")
|
||||
return
|
||||
}
|
||||
opts.PublicOnly = !isMember && !ctx.User.IsAdmin
|
||||
@@ -45,7 +47,7 @@ func Members(ctx *context.Context) {
|
||||
|
||||
total, err := models.CountOrgMembers(opts)
|
||||
if err != nil {
|
||||
ctx.Error(500, "CountOrgMembers")
|
||||
ctx.Error(http.StatusInternalServerError, "CountOrgMembers")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -63,7 +65,7 @@ func Members(ctx *context.Context) {
|
||||
ctx.Data["MembersIsUserOrgOwner"] = members.IsUserOrgOwner(org.ID)
|
||||
ctx.Data["MembersTwoFaStatus"] = members.GetTwoFaStatus()
|
||||
|
||||
ctx.HTML(200, tplMembers)
|
||||
ctx.HTML(http.StatusOK, tplMembers)
|
||||
}
|
||||
|
||||
// MembersAction response for operation to a member of organization
|
||||
@@ -79,19 +81,19 @@ func MembersAction(ctx *context.Context) {
|
||||
switch ctx.Params(":action") {
|
||||
case "private":
|
||||
if ctx.User.ID != uid && !ctx.Org.IsOwner {
|
||||
ctx.Error(404)
|
||||
ctx.Error(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
err = models.ChangeOrgUserStatus(org.ID, uid, false)
|
||||
case "public":
|
||||
if ctx.User.ID != uid && !ctx.Org.IsOwner {
|
||||
ctx.Error(404)
|
||||
ctx.Error(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
err = models.ChangeOrgUserStatus(org.ID, uid, true)
|
||||
case "remove":
|
||||
if !ctx.Org.IsOwner {
|
||||
ctx.Error(404)
|
||||
ctx.Error(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
err = org.RemoveMember(uid)
|
||||
@@ -111,7 +113,7 @@ func MembersAction(ctx *context.Context) {
|
||||
|
||||
if err != nil {
|
||||
log.Error("Action(%s): %v", ctx.Params(":action"), err)
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"ok": false,
|
||||
"err": err.Error(),
|
||||
})
|
||||
|
||||
+3
-2
@@ -7,6 +7,7 @@ package org
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
@@ -30,7 +31,7 @@ func Create(ctx *context.Context) {
|
||||
ctx.ServerError("Not allowed", errors.New(ctx.Tr("org.form.create_org_not_allowed")))
|
||||
return
|
||||
}
|
||||
ctx.HTML(200, tplCreateOrg)
|
||||
ctx.HTML(http.StatusOK, tplCreateOrg)
|
||||
}
|
||||
|
||||
// CreatePost response for create organization
|
||||
@@ -44,7 +45,7 @@ func CreatePost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, tplCreateOrg)
|
||||
ctx.HTML(http.StatusOK, tplCreateOrg)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
package org
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
auth "code.gitea.io/gitea/modules/forms"
|
||||
@@ -58,7 +60,7 @@ func UpdateLabel(ctx *context.Context) {
|
||||
if err != nil {
|
||||
switch {
|
||||
case models.IsErrOrgLabelNotExist(err):
|
||||
ctx.Error(404)
|
||||
ctx.Error(http.StatusNotFound)
|
||||
default:
|
||||
ctx.ServerError("UpdateLabel", err)
|
||||
}
|
||||
@@ -83,7 +85,7 @@ func DeleteLabel(ctx *context.Context) {
|
||||
ctx.Flash.Success(ctx.Tr("repo.issues.label_deletion_success"))
|
||||
}
|
||||
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"redirect": ctx.Org.OrgLink + "/settings/labels",
|
||||
})
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package org
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
@@ -35,7 +36,7 @@ func Settings(ctx *context.Context) {
|
||||
ctx.Data["PageIsSettingsOptions"] = true
|
||||
ctx.Data["CurrentVisibility"] = ctx.Org.Organization.Visibility
|
||||
ctx.Data["RepoAdminChangeTeamAccess"] = ctx.Org.Organization.RepoAdminChangeTeamAccess
|
||||
ctx.HTML(200, tplSettingsOptions)
|
||||
ctx.HTML(http.StatusOK, tplSettingsOptions)
|
||||
}
|
||||
|
||||
// SettingsPost response for settings change submited
|
||||
@@ -46,7 +47,7 @@ func SettingsPost(ctx *context.Context) {
|
||||
ctx.Data["CurrentVisibility"] = ctx.Org.Organization.Visibility
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, tplSettingsOptions)
|
||||
ctx.HTML(http.StatusOK, tplSettingsOptions)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -165,7 +166,7 @@ func SettingsDelete(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx.HTML(200, tplSettingsDelete)
|
||||
ctx.HTML(http.StatusOK, tplSettingsDelete)
|
||||
}
|
||||
|
||||
// Webhooks render webhook list page
|
||||
@@ -183,7 +184,7 @@ func Webhooks(ctx *context.Context) {
|
||||
}
|
||||
|
||||
ctx.Data["Webhooks"] = ws
|
||||
ctx.HTML(200, tplSettingsHooks)
|
||||
ctx.HTML(http.StatusOK, tplSettingsHooks)
|
||||
}
|
||||
|
||||
// DeleteWebhook response for delete webhook
|
||||
@@ -194,7 +195,7 @@ func DeleteWebhook(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": ctx.Org.OrgLink + "/settings/hooks",
|
||||
})
|
||||
}
|
||||
@@ -205,5 +206,5 @@ func Labels(ctx *context.Context) {
|
||||
ctx.Data["PageIsOrgSettingsLabels"] = true
|
||||
ctx.Data["RequireTribute"] = true
|
||||
ctx.Data["LabelTemplates"] = models.LabelTemplates
|
||||
ctx.HTML(200, tplSettingsLabels)
|
||||
ctx.HTML(http.StatusOK, tplSettingsLabels)
|
||||
}
|
||||
|
||||
+14
-14
@@ -44,7 +44,7 @@ func Teams(ctx *context.Context) {
|
||||
}
|
||||
ctx.Data["Teams"] = org.Teams
|
||||
|
||||
ctx.HTML(200, tplTeams)
|
||||
ctx.HTML(http.StatusOK, tplTeams)
|
||||
}
|
||||
|
||||
// TeamsAction response for join, leave, remove, add operations to team
|
||||
@@ -60,7 +60,7 @@ func TeamsAction(ctx *context.Context) {
|
||||
switch ctx.Params(":action") {
|
||||
case "join":
|
||||
if !ctx.Org.IsOwner {
|
||||
ctx.Error(404)
|
||||
ctx.Error(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
err = ctx.Org.Team.AddMember(ctx.User.ID)
|
||||
@@ -68,14 +68,14 @@ func TeamsAction(ctx *context.Context) {
|
||||
err = ctx.Org.Team.RemoveMember(ctx.User.ID)
|
||||
case "remove":
|
||||
if !ctx.Org.IsOwner {
|
||||
ctx.Error(404)
|
||||
ctx.Error(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
err = ctx.Org.Team.RemoveMember(uid)
|
||||
page = "team"
|
||||
case "add":
|
||||
if !ctx.Org.IsOwner {
|
||||
ctx.Error(404)
|
||||
ctx.Error(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
uname := utils.RemoveUsernameParameterSuffix(strings.ToLower(ctx.Query("uname")))
|
||||
@@ -111,7 +111,7 @@ func TeamsAction(ctx *context.Context) {
|
||||
ctx.Flash.Error(ctx.Tr("form.last_org_owner"))
|
||||
} else {
|
||||
log.Error("Action(%s): %v", ctx.Params(":action"), err)
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"ok": false,
|
||||
"err": err.Error(),
|
||||
})
|
||||
@@ -132,7 +132,7 @@ func TeamsAction(ctx *context.Context) {
|
||||
// TeamsRepoAction operate team's repository
|
||||
func TeamsRepoAction(ctx *context.Context) {
|
||||
if !ctx.Org.IsOwner {
|
||||
ctx.Error(404)
|
||||
ctx.Error(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ func TeamsRepoAction(ctx *context.Context) {
|
||||
}
|
||||
|
||||
if action == "addall" || action == "removeall" {
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"redirect": ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName + "/repositories",
|
||||
})
|
||||
return
|
||||
@@ -183,7 +183,7 @@ func NewTeam(ctx *context.Context) {
|
||||
ctx.Data["PageIsOrgTeamsNew"] = true
|
||||
ctx.Data["Team"] = &models.Team{}
|
||||
ctx.Data["Units"] = models.Units
|
||||
ctx.HTML(200, tplTeamNew)
|
||||
ctx.HTML(http.StatusOK, tplTeamNew)
|
||||
}
|
||||
|
||||
// NewTeamPost response for create new team
|
||||
@@ -218,7 +218,7 @@ func NewTeamPost(ctx *context.Context) {
|
||||
ctx.Data["Team"] = t
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, tplTeamNew)
|
||||
ctx.HTML(http.StatusOK, tplTeamNew)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ func TeamMembers(ctx *context.Context) {
|
||||
ctx.ServerError("GetMembers", err)
|
||||
return
|
||||
}
|
||||
ctx.HTML(200, tplTeamMembers)
|
||||
ctx.HTML(http.StatusOK, tplTeamMembers)
|
||||
}
|
||||
|
||||
// TeamRepositories show the repositories of team
|
||||
@@ -262,7 +262,7 @@ func TeamRepositories(ctx *context.Context) {
|
||||
ctx.ServerError("GetRepositories", err)
|
||||
return
|
||||
}
|
||||
ctx.HTML(200, tplTeamRepositories)
|
||||
ctx.HTML(http.StatusOK, tplTeamRepositories)
|
||||
}
|
||||
|
||||
// EditTeam render team edit page
|
||||
@@ -272,7 +272,7 @@ func EditTeam(ctx *context.Context) {
|
||||
ctx.Data["team_name"] = ctx.Org.Team.Name
|
||||
ctx.Data["desc"] = ctx.Org.Team.Description
|
||||
ctx.Data["Units"] = models.Units
|
||||
ctx.HTML(200, tplTeamNew)
|
||||
ctx.HTML(http.StatusOK, tplTeamNew)
|
||||
}
|
||||
|
||||
// EditTeamPost response for modify team information
|
||||
@@ -321,7 +321,7 @@ func EditTeamPost(ctx *context.Context) {
|
||||
t.CanCreateOrgRepo = form.CanCreateOrgRepo
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, tplTeamNew)
|
||||
ctx.HTML(http.StatusOK, tplTeamNew)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -351,7 +351,7 @@ func DeleteTeam(ctx *context.Context) {
|
||||
ctx.Flash.Success(ctx.Tr("org.teams.delete_team_success"))
|
||||
}
|
||||
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"redirect": ctx.Org.OrgLink + "/teams",
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user