[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:
@ -203,12 +203,12 @@ func (ctx *APIContext) CheckForOTP() {
|
||||
if models.IsErrTwoFactorNotEnrolled(err) {
|
||||
return // No 2FA enrollment for this user
|
||||
}
|
||||
ctx.Context.Error(500)
|
||||
ctx.Context.Error(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
ok, err := twofa.ValidateTOTP(otpHeader)
|
||||
if err != nil {
|
||||
ctx.Context.Error(500)
|
||||
ctx.Context.Error(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if !ok {
|
||||
@ -288,7 +288,7 @@ func ReferencesGitRepo(allowEmpty bool) func(http.Handler) http.Handler {
|
||||
repoPath := models.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
|
||||
gitRepo, err := git.OpenRepository(repoPath)
|
||||
if err != nil {
|
||||
ctx.Error(500, "RepoRef Invalid repo "+repoPath, err)
|
||||
ctx.Error(http.StatusInternalServerError, "RepoRef Invalid repo "+repoPath, err)
|
||||
return
|
||||
}
|
||||
ctx.Repo.GitRepo = gitRepo
|
||||
@ -324,7 +324,7 @@ func (ctx *APIContext) NotFound(objs ...interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
ctx.JSON(404, map[string]interface{}{
|
||||
ctx.JSON(http.StatusNotFound, map[string]interface{}{
|
||||
"message": message,
|
||||
"documentation_url": setting.API.SwaggerURL,
|
||||
"errors": errors,
|
||||
|
@ -6,6 +6,8 @@
|
||||
package context
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
@ -27,13 +29,13 @@ func Toggle(options *ToggleOptions) func(ctx *Context) {
|
||||
if ctx.IsSigned {
|
||||
if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
|
||||
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
|
||||
ctx.HTML(200, "user/auth/activate")
|
||||
ctx.HTML(http.StatusOK, "user/auth/activate")
|
||||
return
|
||||
}
|
||||
if !ctx.User.IsActive || ctx.User.ProhibitLogin {
|
||||
log.Info("Failed authentication attempt for %s from %s", ctx.User.Name, ctx.RemoteAddr())
|
||||
ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
|
||||
ctx.HTML(200, "user/auth/prohibit_login")
|
||||
ctx.HTML(http.StatusOK, "user/auth/prohibit_login")
|
||||
return
|
||||
}
|
||||
|
||||
@ -76,7 +78,7 @@ func Toggle(options *ToggleOptions) func(ctx *Context) {
|
||||
return
|
||||
} else if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
|
||||
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
|
||||
ctx.HTML(200, "user/auth/activate")
|
||||
ctx.HTML(http.StatusOK, "user/auth/activate")
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -93,7 +95,7 @@ func Toggle(options *ToggleOptions) func(ctx *Context) {
|
||||
|
||||
if options.AdminRequired {
|
||||
if !ctx.User.IsAdmin {
|
||||
ctx.Error(403)
|
||||
ctx.Error(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
ctx.Data["PageIsAdmin"] = true
|
||||
@ -108,7 +110,7 @@ func ToggleAPI(options *ToggleOptions) func(ctx *APIContext) {
|
||||
if ctx.IsSigned {
|
||||
if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
|
||||
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
|
||||
ctx.JSON(403, map[string]string{
|
||||
ctx.JSON(http.StatusForbidden, map[string]string{
|
||||
"message": "This account is not activated.",
|
||||
})
|
||||
return
|
||||
@ -116,14 +118,14 @@ func ToggleAPI(options *ToggleOptions) func(ctx *APIContext) {
|
||||
if !ctx.User.IsActive || ctx.User.ProhibitLogin {
|
||||
log.Info("Failed authentication attempt for %s from %s", ctx.User.Name, ctx.RemoteAddr())
|
||||
ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
|
||||
ctx.JSON(403, map[string]string{
|
||||
ctx.JSON(http.StatusForbidden, map[string]string{
|
||||
"message": "This account is prohibited from signing in, please contact your site administrator.",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if ctx.User.MustChangePassword {
|
||||
ctx.JSON(403, map[string]string{
|
||||
ctx.JSON(http.StatusForbidden, map[string]string{
|
||||
"message": "You must change your password. Change it at: " + setting.AppURL + "/user/change_password",
|
||||
})
|
||||
return
|
||||
@ -139,13 +141,13 @@ func ToggleAPI(options *ToggleOptions) func(ctx *APIContext) {
|
||||
if options.SignInRequired {
|
||||
if !ctx.IsSigned {
|
||||
// Restrict API calls with error message.
|
||||
ctx.JSON(403, map[string]string{
|
||||
ctx.JSON(http.StatusForbidden, map[string]string{
|
||||
"message": "Only signed in user is allowed to call APIs.",
|
||||
})
|
||||
return
|
||||
} else if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
|
||||
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
|
||||
ctx.HTML(200, "user/auth/activate")
|
||||
ctx.HTML(http.StatusOK, "user/auth/activate")
|
||||
return
|
||||
}
|
||||
if ctx.IsSigned && ctx.IsBasicAuth {
|
||||
@ -164,7 +166,7 @@ func ToggleAPI(options *ToggleOptions) func(ctx *APIContext) {
|
||||
return
|
||||
}
|
||||
if !ok {
|
||||
ctx.JSON(403, map[string]string{
|
||||
ctx.JSON(http.StatusForbidden, map[string]string{
|
||||
"message": "Only signed in user is allowed to call APIs.",
|
||||
})
|
||||
return
|
||||
@ -174,7 +176,7 @@ func ToggleAPI(options *ToggleOptions) func(ctx *APIContext) {
|
||||
|
||||
if options.AdminRequired {
|
||||
if !ctx.User.IsAdmin {
|
||||
ctx.JSON(403, map[string]string{
|
||||
ctx.JSON(http.StatusForbidden, map[string]string{
|
||||
"message": "You have no permission to request for this.",
|
||||
})
|
||||
return
|
||||
|
@ -213,7 +213,7 @@ func (ctx *Context) RenderWithErr(msg string, tpl base.TplName, form interface{}
|
||||
}
|
||||
ctx.Flash.ErrorMsg = msg
|
||||
ctx.Data["Flash"] = ctx.Flash
|
||||
ctx.HTML(200, tpl)
|
||||
ctx.HTML(http.StatusOK, tpl)
|
||||
}
|
||||
|
||||
// NotFound displays a 404 (Not Found) page and prints the given error, if any.
|
||||
|
@ -5,6 +5,7 @@
|
||||
package lfs
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@ -21,19 +22,19 @@ import (
|
||||
func checkIsValidRequest(ctx *context.Context) bool {
|
||||
if !setting.LFS.StartServer {
|
||||
log.Debug("Attempt to access LFS server but LFS server is disabled")
|
||||
writeStatus(ctx, 404)
|
||||
writeStatus(ctx, http.StatusNotFound)
|
||||
return false
|
||||
}
|
||||
if !MetaMatcher(ctx.Req) {
|
||||
log.Info("Attempt access LOCKs without accepting the correct media type: %s", metaMediaType)
|
||||
writeStatus(ctx, 400)
|
||||
writeStatus(ctx, http.StatusBadRequest)
|
||||
return false
|
||||
}
|
||||
if !ctx.IsSigned {
|
||||
user, _, _, err := parseToken(ctx.Req.Header.Get("Authorization"))
|
||||
if err != nil {
|
||||
ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs")
|
||||
writeStatus(ctx, 401)
|
||||
writeStatus(ctx, http.StatusUnauthorized)
|
||||
return false
|
||||
}
|
||||
ctx.User = user
|
||||
@ -44,23 +45,23 @@ func checkIsValidRequest(ctx *context.Context) bool {
|
||||
func handleLockListOut(ctx *context.Context, repo *models.Repository, lock *models.LFSLock, err error) {
|
||||
if err != nil {
|
||||
if models.IsErrLFSLockNotExist(err) {
|
||||
ctx.JSON(200, api.LFSLockList{
|
||||
ctx.JSON(http.StatusOK, api.LFSLockList{
|
||||
Locks: []*api.LFSLock{},
|
||||
})
|
||||
return
|
||||
}
|
||||
ctx.JSON(500, api.LFSLockError{
|
||||
ctx.JSON(http.StatusInternalServerError, api.LFSLockError{
|
||||
Message: "unable to list locks : Internal Server Error",
|
||||
})
|
||||
return
|
||||
}
|
||||
if repo.ID != lock.RepoID {
|
||||
ctx.JSON(200, api.LFSLockList{
|
||||
ctx.JSON(http.StatusOK, api.LFSLockList{
|
||||
Locks: []*api.LFSLock{},
|
||||
})
|
||||
return
|
||||
}
|
||||
ctx.JSON(200, api.LFSLockList{
|
||||
ctx.JSON(http.StatusOK, api.LFSLockList{
|
||||
Locks: []*api.LFSLock{convert.ToLFSLock(lock)},
|
||||
})
|
||||
}
|
||||
@ -86,7 +87,7 @@ func GetListLockHandler(ctx *context.Context) {
|
||||
authenticated := authenticate(ctx, repository, rv.Authorization, false)
|
||||
if !authenticated {
|
||||
ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs")
|
||||
ctx.JSON(401, api.LFSLockError{
|
||||
ctx.JSON(http.StatusUnauthorized, api.LFSLockError{
|
||||
Message: "You must have pull access to list locks",
|
||||
})
|
||||
return
|
||||
@ -106,7 +107,7 @@ func GetListLockHandler(ctx *context.Context) {
|
||||
if id != "" { //Case where we request a specific id
|
||||
v, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
ctx.JSON(400, api.LFSLockError{
|
||||
ctx.JSON(http.StatusBadRequest, api.LFSLockError{
|
||||
Message: "bad request : " + err.Error(),
|
||||
})
|
||||
return
|
||||
@ -133,7 +134,7 @@ func GetListLockHandler(ctx *context.Context) {
|
||||
lockList, err := models.GetLFSLockByRepoID(repository.ID, cursor, limit)
|
||||
if err != nil {
|
||||
log.Error("Unable to list locks for repository ID[%d]: Error: %v", repository.ID, err)
|
||||
ctx.JSON(500, api.LFSLockError{
|
||||
ctx.JSON(http.StatusInternalServerError, api.LFSLockError{
|
||||
Message: "unable to list locks : Internal Server Error",
|
||||
})
|
||||
return
|
||||
@ -146,7 +147,7 @@ func GetListLockHandler(ctx *context.Context) {
|
||||
if limit > 0 && len(lockList) == limit {
|
||||
next = strconv.Itoa(cursor + 1)
|
||||
}
|
||||
ctx.JSON(200, api.LFSLockList{
|
||||
ctx.JSON(http.StatusOK, api.LFSLockList{
|
||||
Locks: lockListAPI,
|
||||
Next: next,
|
||||
})
|
||||
@ -175,7 +176,7 @@ func PostLockHandler(ctx *context.Context) {
|
||||
authenticated := authenticate(ctx, repository, authorization, true)
|
||||
if !authenticated {
|
||||
ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs")
|
||||
ctx.JSON(401, api.LFSLockError{
|
||||
ctx.JSON(http.StatusUnauthorized, api.LFSLockError{
|
||||
Message: "You must have push access to create locks",
|
||||
})
|
||||
return
|
||||
@ -199,7 +200,7 @@ func PostLockHandler(ctx *context.Context) {
|
||||
})
|
||||
if err != nil {
|
||||
if models.IsErrLFSLockAlreadyExist(err) {
|
||||
ctx.JSON(409, api.LFSLockError{
|
||||
ctx.JSON(http.StatusConflict, api.LFSLockError{
|
||||
Lock: convert.ToLFSLock(lock),
|
||||
Message: "already created lock",
|
||||
})
|
||||
@ -207,18 +208,18 @@ func PostLockHandler(ctx *context.Context) {
|
||||
}
|
||||
if models.IsErrLFSUnauthorizedAction(err) {
|
||||
ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs")
|
||||
ctx.JSON(401, api.LFSLockError{
|
||||
ctx.JSON(http.StatusUnauthorized, api.LFSLockError{
|
||||
Message: "You must have push access to create locks : " + err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
log.Error("Unable to CreateLFSLock in repository %-v at %s for user %-v: Error: %v", repository, req.Path, ctx.User, err)
|
||||
ctx.JSON(500, api.LFSLockError{
|
||||
ctx.JSON(http.StatusInternalServerError, api.LFSLockError{
|
||||
Message: "internal server error : Internal Server Error",
|
||||
})
|
||||
return
|
||||
}
|
||||
ctx.JSON(201, api.LFSLockResponse{Lock: convert.ToLFSLock(lock)})
|
||||
ctx.JSON(http.StatusCreated, api.LFSLockResponse{Lock: convert.ToLFSLock(lock)})
|
||||
}
|
||||
|
||||
// VerifyLockHandler list locks for verification
|
||||
@ -244,7 +245,7 @@ func VerifyLockHandler(ctx *context.Context) {
|
||||
authenticated := authenticate(ctx, repository, authorization, true)
|
||||
if !authenticated {
|
||||
ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs")
|
||||
ctx.JSON(401, api.LFSLockError{
|
||||
ctx.JSON(http.StatusUnauthorized, api.LFSLockError{
|
||||
Message: "You must have push access to verify locks",
|
||||
})
|
||||
return
|
||||
@ -263,7 +264,7 @@ func VerifyLockHandler(ctx *context.Context) {
|
||||
lockList, err := models.GetLFSLockByRepoID(repository.ID, cursor, limit)
|
||||
if err != nil {
|
||||
log.Error("Unable to list locks for repository ID[%d]: Error: %v", repository.ID, err)
|
||||
ctx.JSON(500, api.LFSLockError{
|
||||
ctx.JSON(http.StatusInternalServerError, api.LFSLockError{
|
||||
Message: "unable to list locks : Internal Server Error",
|
||||
})
|
||||
return
|
||||
@ -281,7 +282,7 @@ func VerifyLockHandler(ctx *context.Context) {
|
||||
lockTheirsListAPI = append(lockTheirsListAPI, convert.ToLFSLock(l))
|
||||
}
|
||||
}
|
||||
ctx.JSON(200, api.LFSLockListVerify{
|
||||
ctx.JSON(http.StatusOK, api.LFSLockListVerify{
|
||||
Ours: lockOursListAPI,
|
||||
Theirs: lockTheirsListAPI,
|
||||
Next: next,
|
||||
@ -311,7 +312,7 @@ func UnLockHandler(ctx *context.Context) {
|
||||
authenticated := authenticate(ctx, repository, authorization, true)
|
||||
if !authenticated {
|
||||
ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs")
|
||||
ctx.JSON(401, api.LFSLockError{
|
||||
ctx.JSON(http.StatusUnauthorized, api.LFSLockError{
|
||||
Message: "You must have push access to delete locks",
|
||||
})
|
||||
return
|
||||
@ -332,16 +333,16 @@ func UnLockHandler(ctx *context.Context) {
|
||||
if err != nil {
|
||||
if models.IsErrLFSUnauthorizedAction(err) {
|
||||
ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs")
|
||||
ctx.JSON(401, api.LFSLockError{
|
||||
ctx.JSON(http.StatusUnauthorized, api.LFSLockError{
|
||||
Message: "You must have push access to delete locks : " + err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
log.Error("Unable to DeleteLFSLockByID[%d] by user %-v with force %t: Error: %v", ctx.ParamsInt64("lid"), ctx.User, req.Force, err)
|
||||
ctx.JSON(500, api.LFSLockError{
|
||||
ctx.JSON(http.StatusInternalServerError, api.LFSLockError{
|
||||
Message: "unable to delete lock : Internal Server Error",
|
||||
})
|
||||
return
|
||||
}
|
||||
ctx.JSON(200, api.LFSLockResponse{Lock: convert.ToLFSLock(lock)})
|
||||
ctx.JSON(http.StatusOK, api.LFSLockResponse{Lock: convert.ToLFSLock(lock)})
|
||||
}
|
||||
|
@ -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),
|
||||
})
|
||||
}
|
||||
|
@ -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",
|
||||
})
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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",
|
||||
})
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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",
|
||||
})
|
||||
}
|
||||
|
@ -538,7 +538,7 @@ func bind(obj interface{}) http.HandlerFunc {
|
||||
var theObj = reflect.New(tp).Interface() // create a new form obj for every request but not use obj directly
|
||||
errs := binding.Bind(ctx.Req, theObj)
|
||||
if len(errs) > 0 {
|
||||
ctx.Error(422, "validationError", errs[0].Error())
|
||||
ctx.Error(http.StatusUnprocessableEntity, "validationError", errs[0].Error())
|
||||
return
|
||||
}
|
||||
web.SetForm(ctx, theObj)
|
||||
|
@ -5,6 +5,8 @@
|
||||
package dev
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
@ -23,5 +25,5 @@ func TemplatePreview(ctx *context.Context) {
|
||||
ctx.Data["ResetPwdCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ResetPwdCodeLives, ctx.Locale.Language())
|
||||
ctx.Data["CurDbValue"] = ""
|
||||
|
||||
ctx.HTML(200, base.TplName(ctx.Params("*")))
|
||||
ctx.HTML(http.StatusOK, base.TplName(ctx.Params("*")))
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ package routers
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
@ -39,11 +40,11 @@ func Home(ctx *context.Context) {
|
||||
if ctx.IsSigned {
|
||||
if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
|
||||
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
|
||||
ctx.HTML(200, user.TplActivate)
|
||||
ctx.HTML(http.StatusOK, user.TplActivate)
|
||||
} else if !ctx.User.IsActive || ctx.User.ProhibitLogin {
|
||||
log.Info("Failed authentication attempt for %s from %s", ctx.User.Name, ctx.RemoteAddr())
|
||||
ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
|
||||
ctx.HTML(200, "user/auth/prohibit_login")
|
||||
ctx.HTML(http.StatusOK, "user/auth/prohibit_login")
|
||||
} else if ctx.User.MustChangePassword {
|
||||
ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
|
||||
ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/change_password"
|
||||
@ -68,7 +69,7 @@ func Home(ctx *context.Context) {
|
||||
|
||||
ctx.Data["PageIsHome"] = true
|
||||
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
|
||||
ctx.HTML(200, tplHome)
|
||||
ctx.HTML(http.StatusOK, tplHome)
|
||||
}
|
||||
|
||||
// RepoSearchOptions when calling search repositories
|
||||
@ -166,7 +167,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
|
||||
pager.AddParam(ctx, "topic", "TopicOnly")
|
||||
ctx.Data["Page"] = pager
|
||||
|
||||
ctx.HTML(200, opts.TplName)
|
||||
ctx.HTML(http.StatusOK, opts.TplName)
|
||||
}
|
||||
|
||||
// ExploreRepos render explore repositories page
|
||||
@ -243,7 +244,7 @@ func RenderUserSearch(ctx *context.Context, opts *models.SearchUserOptions, tplN
|
||||
pager.SetDefaultParams(ctx)
|
||||
ctx.Data["Page"] = pager
|
||||
|
||||
ctx.HTML(200, tplName)
|
||||
ctx.HTML(http.StatusOK, tplName)
|
||||
}
|
||||
|
||||
// ExploreUsers render explore users page
|
||||
@ -402,7 +403,7 @@ func ExploreCode(ctx *context.Context) {
|
||||
pager.AddParam(ctx, "l", "Language")
|
||||
ctx.Data["Page"] = pager
|
||||
|
||||
ctx.HTML(200, tplExploreCode)
|
||||
ctx.HTML(http.StatusOK, tplExploreCode)
|
||||
}
|
||||
|
||||
// NotFound render 404 page
|
||||
|
@ -146,7 +146,7 @@ func Install(ctx *context.Context) {
|
||||
form.PasswordAlgorithm = setting.PasswordHashAlgo
|
||||
|
||||
middleware.AssignForm(form, ctx.Data)
|
||||
ctx.HTML(200, tplInstall)
|
||||
ctx.HTML(http.StatusOK, tplInstall)
|
||||
}
|
||||
|
||||
// InstallPost response for submit install items
|
||||
@ -165,7 +165,7 @@ func InstallPost(ctx *context.Context) {
|
||||
ctx.Data["Err_Admin"] = true
|
||||
}
|
||||
|
||||
ctx.HTML(200, tplInstall)
|
||||
ctx.HTML(http.StatusOK, tplInstall)
|
||||
return
|
||||
}
|
||||
|
||||
@ -450,7 +450,7 @@ func InstallPost(ctx *context.Context) {
|
||||
ctx.Flash.Success(ctx.Tr("install.install_success"))
|
||||
|
||||
ctx.Header().Add("Refresh", "1; url="+setting.AppURL+"user/login")
|
||||
ctx.HTML(200, tplPostInstall)
|
||||
ctx.HTML(http.StatusOK, tplPostInstall)
|
||||
|
||||
// Now get the http.Server from this request and shut it down
|
||||
// NB: This is not our hammerable graceful shutdown this is http.Server.Shutdown
|
||||
|
@ -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(),
|
||||
})
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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",
|
||||
})
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ func HookPreReceive(ctx *gitea_context.PrivateContext) {
|
||||
protectBranch, err := models.GetProtectedBranchBy(repo.ID, branchName)
|
||||
if err != nil {
|
||||
log.Error("Unable to get protected branch: %s in %-v Error: %v", branchName, repo, err)
|
||||
ctx.JSON(500, map[string]interface{}{
|
||||
ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
|
||||
"err": err.Error(),
|
||||
})
|
||||
return
|
||||
|
@ -5,6 +5,7 @@
|
||||
package repo
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
@ -64,7 +65,7 @@ func Activity(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx.HTML(200, tplActivity)
|
||||
ctx.HTML(http.StatusOK, tplActivity)
|
||||
}
|
||||
|
||||
// ActivityAuthors renders JSON with top commit authors for given time period over all branches
|
||||
@ -98,5 +99,5 @@ func ActivityAuthors(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(200, authors)
|
||||
ctx.JSON(http.StatusOK, authors)
|
||||
}
|
||||
|
@ -29,13 +29,13 @@ func UploadReleaseAttachment(ctx *context.Context) {
|
||||
// UploadAttachment response for uploading attachments
|
||||
func uploadAttachment(ctx *context.Context, allowedTypes string) {
|
||||
if !setting.Attachment.Enabled {
|
||||
ctx.Error(404, "attachment is not enabled")
|
||||
ctx.Error(http.StatusNotFound, "attachment is not enabled")
|
||||
return
|
||||
}
|
||||
|
||||
file, header, err := ctx.Req.FormFile("file")
|
||||
if err != nil {
|
||||
ctx.Error(500, fmt.Sprintf("FormFile: %v", err))
|
||||
ctx.Error(http.StatusInternalServerError, fmt.Sprintf("FormFile: %v", err))
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
@ -48,7 +48,7 @@ func uploadAttachment(ctx *context.Context, allowedTypes string) {
|
||||
|
||||
err = upload.Verify(buf, header.Filename, allowedTypes)
|
||||
if err != nil {
|
||||
ctx.Error(400, err.Error())
|
||||
ctx.Error(http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
@ -57,12 +57,12 @@ func uploadAttachment(ctx *context.Context, allowedTypes string) {
|
||||
Name: header.Filename,
|
||||
}, buf, file)
|
||||
if err != nil {
|
||||
ctx.Error(500, fmt.Sprintf("NewAttachment: %v", err))
|
||||
ctx.Error(http.StatusInternalServerError, fmt.Sprintf("NewAttachment: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
log.Trace("New attachment uploaded: %s", attach.UUID)
|
||||
ctx.JSON(200, map[string]string{
|
||||
ctx.JSON(http.StatusOK, map[string]string{
|
||||
"uuid": attach.UUID,
|
||||
})
|
||||
}
|
||||
@ -72,19 +72,19 @@ func DeleteAttachment(ctx *context.Context) {
|
||||
file := ctx.Query("file")
|
||||
attach, err := models.GetAttachmentByUUID(file)
|
||||
if err != nil {
|
||||
ctx.Error(400, err.Error())
|
||||
ctx.Error(http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
if !ctx.IsSigned || (ctx.User.ID != attach.UploaderID) {
|
||||
ctx.Error(403)
|
||||
ctx.Error(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
err = models.DeleteAttachment(attach, true)
|
||||
if err != nil {
|
||||
ctx.Error(500, fmt.Sprintf("DeleteAttachment: %v", err))
|
||||
ctx.Error(http.StatusInternalServerError, fmt.Sprintf("DeleteAttachment: %v", err))
|
||||
return
|
||||
}
|
||||
ctx.JSON(200, map[string]string{
|
||||
ctx.JSON(http.StatusOK, map[string]string{
|
||||
"uuid": attach.UUID,
|
||||
})
|
||||
}
|
||||
@ -94,7 +94,7 @@ func GetAttachment(ctx *context.Context) {
|
||||
attach, err := models.GetAttachmentByUUID(ctx.Params(":uuid"))
|
||||
if err != nil {
|
||||
if models.IsErrAttachmentNotExist(err) {
|
||||
ctx.Error(404)
|
||||
ctx.Error(http.StatusNotFound)
|
||||
} else {
|
||||
ctx.ServerError("GetAttachmentByUUID", err)
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"fmt"
|
||||
"html"
|
||||
gotemplate "html/template"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
@ -184,7 +185,7 @@ func RefBlame(ctx *context.Context) {
|
||||
|
||||
renderBlame(ctx, blameParts, commitNames)
|
||||
|
||||
ctx.HTML(200, tplBlame)
|
||||
ctx.HTML(http.StatusOK, tplBlame)
|
||||
}
|
||||
|
||||
func renderBlame(ctx *context.Context, blameParts []git.BlamePart, commitNames map[string]models.UserCommit) {
|
||||
|
@ -7,6 +7,7 @@ package repo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
@ -75,7 +76,7 @@ func Branches(ctx *context.Context) {
|
||||
pager.SetDefaultParams(ctx)
|
||||
ctx.Data["Page"] = pager
|
||||
|
||||
ctx.HTML(200, tplBranch)
|
||||
ctx.HTML(http.StatusOK, tplBranch)
|
||||
}
|
||||
|
||||
// DeleteBranchPost responses for delete merged branch
|
||||
@ -163,7 +164,7 @@ func RestoreBranchPost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func redirect(ctx *context.Context) {
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"redirect": ctx.Repo.RepoLink + "/branches",
|
||||
})
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ package repo
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
@ -85,7 +86,7 @@ func Commits(ctx *context.Context) {
|
||||
pager.SetDefaultParams(ctx)
|
||||
ctx.Data["Page"] = pager
|
||||
|
||||
ctx.HTML(200, tplCommits)
|
||||
ctx.HTML(http.StatusOK, tplCommits)
|
||||
}
|
||||
|
||||
// Graph render commit graph - show commits from all branches.
|
||||
@ -167,11 +168,11 @@ func Graph(ctx *context.Context) {
|
||||
}
|
||||
ctx.Data["Page"] = paginator
|
||||
if ctx.QueryBool("div-only") {
|
||||
ctx.HTML(200, tplGraphDiv)
|
||||
ctx.HTML(http.StatusOK, tplGraphDiv)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.HTML(200, tplGraph)
|
||||
ctx.HTML(http.StatusOK, tplGraph)
|
||||
}
|
||||
|
||||
// SearchCommits render commits filtered by keyword
|
||||
@ -205,7 +206,7 @@ func SearchCommits(ctx *context.Context) {
|
||||
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
|
||||
ctx.Data["CommitCount"] = commits.Len()
|
||||
ctx.Data["Branch"] = ctx.Repo.BranchName
|
||||
ctx.HTML(200, tplCommits)
|
||||
ctx.HTML(http.StatusOK, tplCommits)
|
||||
}
|
||||
|
||||
// FileHistory show a file's reversions
|
||||
@ -253,7 +254,7 @@ func FileHistory(ctx *context.Context) {
|
||||
pager.SetDefaultParams(ctx)
|
||||
ctx.Data["Page"] = pager
|
||||
|
||||
ctx.HTML(200, tplCommits)
|
||||
ctx.HTML(http.StatusOK, tplCommits)
|
||||
}
|
||||
|
||||
// Diff show different from current commit to previous commit
|
||||
@ -372,7 +373,7 @@ func Diff(ctx *context.Context) {
|
||||
ctx.ServerError("commit.GetTagName", err)
|
||||
return
|
||||
}
|
||||
ctx.HTML(200, tplCommitPage)
|
||||
ctx.HTML(http.StatusOK, tplCommitPage)
|
||||
}
|
||||
|
||||
// RawDiff dumps diff results of repository in given commit ID to io.Writer
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"fmt"
|
||||
"html"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@ -632,7 +633,7 @@ func CompareDiff(ctx *context.Context) {
|
||||
} else {
|
||||
ctx.Data["HasPullRequest"] = true
|
||||
ctx.Data["PullRequest"] = pr
|
||||
ctx.HTML(200, tplCompareDiff)
|
||||
ctx.HTML(http.StatusOK, tplCompareDiff)
|
||||
return
|
||||
}
|
||||
|
||||
@ -660,7 +661,7 @@ func CompareDiff(ctx *context.Context) {
|
||||
|
||||
ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWrite(models.UnitTypePullRequests)
|
||||
|
||||
ctx.HTML(200, tplCompare)
|
||||
ctx.HTML(http.StatusOK, tplCompare)
|
||||
}
|
||||
|
||||
// ExcerptBlob render blob excerpt contents
|
||||
@ -679,7 +680,7 @@ func ExcerptBlob(ctx *context.Context) {
|
||||
chunkSize := gitdiff.BlobExcerptChunkSize
|
||||
commit, err := gitRepo.GetCommit(commitID)
|
||||
if err != nil {
|
||||
ctx.Error(500, "GetCommit")
|
||||
ctx.Error(http.StatusInternalServerError, "GetCommit")
|
||||
return
|
||||
}
|
||||
section := &gitdiff.DiffSection{
|
||||
@ -704,7 +705,7 @@ func ExcerptBlob(ctx *context.Context) {
|
||||
idxRight = lastRight
|
||||
}
|
||||
if err != nil {
|
||||
ctx.Error(500, "getExcerptLines")
|
||||
ctx.Error(http.StatusInternalServerError, "getExcerptLines")
|
||||
return
|
||||
}
|
||||
if idxRight > lastRight {
|
||||
@ -735,7 +736,7 @@ func ExcerptBlob(ctx *context.Context) {
|
||||
ctx.Data["fileName"] = filePath
|
||||
ctx.Data["AfterCommitID"] = commitID
|
||||
ctx.Data["Anchor"] = anchor
|
||||
ctx.HTML(200, tplBlobExcerpt)
|
||||
ctx.HTML(http.StatusOK, tplBlobExcerpt)
|
||||
}
|
||||
|
||||
func getExcerptLines(commit *git.Commit, filePath string, idxLeft int, idxRight int, chunkSize int) ([]*gitdiff.DiffLine, error) {
|
||||
|
@ -7,6 +7,7 @@ package repo
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
@ -149,7 +150,7 @@ func editFile(ctx *context.Context, isNewFile bool) {
|
||||
ctx.Data["PreviewableFileModes"] = strings.Join(setting.Repository.Editor.PreviewableFileModes, ",")
|
||||
ctx.Data["Editorconfig"] = GetEditorConfig(ctx, treePath)
|
||||
|
||||
ctx.HTML(200, tplEditFile)
|
||||
ctx.HTML(http.StatusOK, tplEditFile)
|
||||
}
|
||||
|
||||
// GetEditorConfig returns a editorconfig JSON string for given treePath or "null"
|
||||
@ -205,7 +206,7 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
|
||||
ctx.Data["Editorconfig"] = GetEditorConfig(ctx, form.TreePath)
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, tplEditFile)
|
||||
ctx.HTML(http.StatusOK, tplEditFile)
|
||||
return
|
||||
}
|
||||
|
||||
@ -263,10 +264,10 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
|
||||
case git.EntryModeBlob:
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.directory_is_a_file", fileErr.Path), tplEditFile, &form)
|
||||
default:
|
||||
ctx.Error(500, err.Error())
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
} else {
|
||||
ctx.Error(500, err.Error())
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
} else if models.IsErrRepoFileAlreadyExists(err) {
|
||||
ctx.Data["Err_TreePath"] = true
|
||||
@ -276,7 +277,7 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
|
||||
if branchErr, ok := err.(git.ErrBranchNotExist); ok {
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.branch_does_not_exist", branchErr.Name), tplEditFile, &form)
|
||||
} else {
|
||||
ctx.Error(500, err.Error())
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
} else if models.IsErrBranchAlreadyExists(err) {
|
||||
// For when a user specifies a new branch that already exists
|
||||
@ -284,7 +285,7 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
|
||||
if branchErr, ok := err.(models.ErrBranchAlreadyExists); ok {
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.branch_already_exists", branchErr.BranchName), tplEditFile, &form)
|
||||
} else {
|
||||
ctx.Error(500, err.Error())
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
} else if models.IsErrCommitIDDoesNotMatch(err) {
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.file_changed_while_editing", ctx.Repo.RepoLink+"/compare/"+form.LastCommit+"..."+ctx.Repo.CommitID), tplEditFile, &form)
|
||||
@ -344,22 +345,22 @@ func DiffPreviewPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*auth.EditPreviewDiffForm)
|
||||
treePath := cleanUploadFileName(ctx.Repo.TreePath)
|
||||
if len(treePath) == 0 {
|
||||
ctx.Error(500, "file name to diff is invalid")
|
||||
ctx.Error(http.StatusInternalServerError, "file name to diff is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(treePath)
|
||||
if err != nil {
|
||||
ctx.Error(500, "GetTreeEntryByPath: "+err.Error())
|
||||
ctx.Error(http.StatusInternalServerError, "GetTreeEntryByPath: "+err.Error())
|
||||
return
|
||||
} else if entry.IsDir() {
|
||||
ctx.Error(422)
|
||||
ctx.Error(http.StatusUnprocessableEntity)
|
||||
return
|
||||
}
|
||||
|
||||
diff, err := repofiles.GetDiffPreview(ctx.Repo.Repository, ctx.Repo.BranchName, treePath, form.Content)
|
||||
if err != nil {
|
||||
ctx.Error(500, "GetDiffPreview: "+err.Error())
|
||||
ctx.Error(http.StatusInternalServerError, "GetDiffPreview: "+err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
@ -369,7 +370,7 @@ func DiffPreviewPost(ctx *context.Context) {
|
||||
}
|
||||
ctx.Data["File"] = diff.Files[0]
|
||||
|
||||
ctx.HTML(200, tplEditDiffPreview)
|
||||
ctx.HTML(http.StatusOK, tplEditDiffPreview)
|
||||
}
|
||||
|
||||
// DeleteFile render delete file page
|
||||
@ -396,7 +397,7 @@ func DeleteFile(ctx *context.Context) {
|
||||
}
|
||||
ctx.Data["new_branch_name"] = GetUniquePatchBranchName(ctx)
|
||||
|
||||
ctx.HTML(200, tplDeleteFile)
|
||||
ctx.HTML(http.StatusOK, tplDeleteFile)
|
||||
}
|
||||
|
||||
// DeleteFilePost response for deleting file
|
||||
@ -418,7 +419,7 @@ func DeleteFilePost(ctx *context.Context) {
|
||||
ctx.Data["last_commit"] = ctx.Repo.CommitID
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, tplDeleteFile)
|
||||
ctx.HTML(http.StatusOK, tplDeleteFile)
|
||||
return
|
||||
}
|
||||
|
||||
@ -473,14 +474,14 @@ func DeleteFilePost(ctx *context.Context) {
|
||||
if branchErr, ok := err.(git.ErrBranchNotExist); ok {
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.branch_does_not_exist", branchErr.Name), tplDeleteFile, &form)
|
||||
} else {
|
||||
ctx.Error(500, err.Error())
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
} else if models.IsErrBranchAlreadyExists(err) {
|
||||
// For when a user specifies a new branch that already exists
|
||||
if branchErr, ok := err.(models.ErrBranchAlreadyExists); ok {
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.branch_already_exists", branchErr.BranchName), tplDeleteFile, &form)
|
||||
} else {
|
||||
ctx.Error(500, err.Error())
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
} else if models.IsErrCommitIDDoesNotMatch(err) || git.IsErrPushOutOfDate(err) {
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.file_changed_while_deleting", ctx.Repo.RepoLink+"/compare/"+form.LastCommit+"..."+ctx.Repo.CommitID), tplDeleteFile, &form)
|
||||
@ -560,7 +561,7 @@ func UploadFile(ctx *context.Context) {
|
||||
}
|
||||
ctx.Data["new_branch_name"] = GetUniquePatchBranchName(ctx)
|
||||
|
||||
ctx.HTML(200, tplUploadFile)
|
||||
ctx.HTML(http.StatusOK, tplUploadFile)
|
||||
}
|
||||
|
||||
// UploadFilePost response for uploading file
|
||||
@ -597,7 +598,7 @@ func UploadFilePost(ctx *context.Context) {
|
||||
ctx.Data["new_branch_name"] = branchName
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, tplUploadFile)
|
||||
ctx.HTML(http.StatusOK, tplUploadFile)
|
||||
return
|
||||
}
|
||||
|
||||
@ -672,7 +673,7 @@ func UploadFilePost(ctx *context.Context) {
|
||||
case git.EntryModeBlob:
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.directory_is_a_file", fileErr.Path), tplUploadFile, &form)
|
||||
default:
|
||||
ctx.Error(500, err.Error())
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
} else if models.IsErrRepoFileAlreadyExists(err) {
|
||||
ctx.Data["Err_TreePath"] = true
|
||||
@ -734,7 +735,7 @@ func cleanUploadFileName(name string) string {
|
||||
func UploadFileToServer(ctx *context.Context) {
|
||||
file, header, err := ctx.Req.FormFile("file")
|
||||
if err != nil {
|
||||
ctx.Error(500, fmt.Sprintf("FormFile: %v", err))
|
||||
ctx.Error(http.StatusInternalServerError, fmt.Sprintf("FormFile: %v", err))
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
@ -747,24 +748,24 @@ func UploadFileToServer(ctx *context.Context) {
|
||||
|
||||
err = upload.Verify(buf, header.Filename, setting.Repository.Upload.AllowedTypes)
|
||||
if err != nil {
|
||||
ctx.Error(400, err.Error())
|
||||
ctx.Error(http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
name := cleanUploadFileName(header.Filename)
|
||||
if len(name) == 0 {
|
||||
ctx.Error(500, "Upload file name is invalid")
|
||||
ctx.Error(http.StatusInternalServerError, "Upload file name is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
upload, err := models.NewUpload(name, buf, file)
|
||||
if err != nil {
|
||||
ctx.Error(500, fmt.Sprintf("NewUpload: %v", err))
|
||||
ctx.Error(http.StatusInternalServerError, fmt.Sprintf("NewUpload: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
log.Trace("New file uploaded: %s", upload.UUID)
|
||||
ctx.JSON(200, map[string]string{
|
||||
ctx.JSON(http.StatusOK, map[string]string{
|
||||
"uuid": upload.UUID,
|
||||
})
|
||||
}
|
||||
@ -778,7 +779,7 @@ func RemoveUploadFileFromServer(ctx *context.Context) {
|
||||
}
|
||||
|
||||
if err := models.DeleteUploadByUUID(form.File); err != nil {
|
||||
ctx.Error(500, fmt.Sprintf("DeleteUploadByUUID: %v", err))
|
||||
ctx.Error(http.StatusInternalServerError, fmt.Sprintf("DeleteUploadByUUID: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -393,7 +393,7 @@ func Issues(ctx *context.Context) {
|
||||
|
||||
ctx.Data["CanWriteIssuesOrPulls"] = ctx.Repo.CanWriteIssuesOrPulls(isPullList)
|
||||
|
||||
ctx.HTML(200, tplIssues)
|
||||
ctx.HTML(http.StatusOK, tplIssues)
|
||||
}
|
||||
|
||||
// RetrieveRepoMilestonesAndAssignees find all the milestones and assignees of a repository
|
||||
@ -819,7 +819,7 @@ func NewIssue(ctx *context.Context) {
|
||||
|
||||
ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWrite(models.UnitTypeIssues)
|
||||
|
||||
ctx.HTML(200, tplIssueNew)
|
||||
ctx.HTML(http.StatusOK, tplIssueNew)
|
||||
}
|
||||
|
||||
// NewIssueChooseTemplate render creating issue from template page
|
||||
@ -832,7 +832,7 @@ func NewIssueChooseTemplate(ctx *context.Context) {
|
||||
ctx.Data["NewIssueChooseTemplate"] = len(issueTemplates) > 0
|
||||
ctx.Data["IssueTemplates"] = issueTemplates
|
||||
|
||||
ctx.HTML(200, tplIssueChoose)
|
||||
ctx.HTML(http.StatusOK, tplIssueChoose)
|
||||
}
|
||||
|
||||
// ValidateRepoMetas check and returns repository's meta informations
|
||||
@ -960,7 +960,7 @@ func NewIssuePost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, tplIssueNew)
|
||||
ctx.HTML(http.StatusOK, tplIssueNew)
|
||||
return
|
||||
}
|
||||
|
||||
@ -981,7 +981,7 @@ func NewIssuePost(ctx *context.Context) {
|
||||
|
||||
if err := issue_service.NewIssue(repo, issue, labelIDs, attachments, assigneeIDs); err != nil {
|
||||
if models.IsErrUserDoesNotHaveAccessToRepo(err) {
|
||||
ctx.Error(400, "UserDoesNotHaveAccessToRepo", err.Error())
|
||||
ctx.Error(http.StatusBadRequest, "UserDoesNotHaveAccessToRepo", err.Error())
|
||||
return
|
||||
}
|
||||
ctx.ServerError("NewIssue", err)
|
||||
@ -1578,7 +1578,7 @@ func ViewIssue(ctx *context.Context) {
|
||||
ctx.Data["IsRepoAdmin"] = ctx.IsSigned && (ctx.Repo.IsAdmin() || ctx.User.IsAdmin)
|
||||
ctx.Data["LockReasons"] = setting.Repository.Issue.LockReasons
|
||||
ctx.Data["RefEndName"] = git.RefEndName(issue.Ref)
|
||||
ctx.HTML(200, tplIssueView)
|
||||
ctx.HTML(http.StatusOK, tplIssueView)
|
||||
}
|
||||
|
||||
// GetActionIssue will return the issue which is used in the context.
|
||||
@ -1650,13 +1650,13 @@ func UpdateIssueTitle(ctx *context.Context) {
|
||||
}
|
||||
|
||||
if !ctx.IsSigned || (!issue.IsPoster(ctx.User.ID) && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)) {
|
||||
ctx.Error(403)
|
||||
ctx.Error(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
title := ctx.QueryTrim("title")
|
||||
if len(title) == 0 {
|
||||
ctx.Error(204)
|
||||
ctx.Error(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
@ -1665,7 +1665,7 @@ func UpdateIssueTitle(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"title": issue.Title,
|
||||
})
|
||||
}
|
||||
@ -1678,7 +1678,7 @@ func UpdateIssueRef(ctx *context.Context) {
|
||||
}
|
||||
|
||||
if !ctx.IsSigned || (!issue.IsPoster(ctx.User.ID) && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)) || issue.IsPull {
|
||||
ctx.Error(403)
|
||||
ctx.Error(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
@ -1689,7 +1689,7 @@ func UpdateIssueRef(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"ref": ref,
|
||||
})
|
||||
}
|
||||
@ -1702,7 +1702,7 @@ func UpdateIssueContent(ctx *context.Context) {
|
||||
}
|
||||
|
||||
if !ctx.IsSigned || (ctx.User.ID != issue.PosterID && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)) {
|
||||
ctx.Error(403)
|
||||
ctx.Error(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
@ -1717,7 +1717,7 @@ func UpdateIssueContent(ctx *context.Context) {
|
||||
ctx.ServerError("UpdateAttachments", err)
|
||||
}
|
||||
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"content": string(markdown.Render([]byte(issue.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())),
|
||||
"attachments": attachmentsHTML(ctx, issue.Attachments, issue.Content),
|
||||
})
|
||||
@ -1743,7 +1743,7 @@ func UpdateIssueMilestone(ctx *context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"ok": true,
|
||||
})
|
||||
}
|
||||
@ -1789,7 +1789,7 @@ func UpdateIssueAssignee(ctx *context.Context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"ok": true,
|
||||
})
|
||||
}
|
||||
@ -1914,7 +1914,7 @@ func UpdatePullReviewRequest(ctx *context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"ok": true,
|
||||
})
|
||||
}
|
||||
@ -1954,7 +1954,7 @@ func UpdateIssueStatus(ctx *context.Context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"ok": true,
|
||||
})
|
||||
}
|
||||
@ -1986,7 +1986,7 @@ func NewComment(ctx *context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
ctx.Error(403)
|
||||
ctx.Error(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
@ -2109,17 +2109,17 @@ func UpdateCommentContent(ctx *context.Context) {
|
||||
}
|
||||
|
||||
if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.CanWriteIssuesOrPulls(comment.Issue.IsPull)) {
|
||||
ctx.Error(403)
|
||||
ctx.Error(http.StatusForbidden)
|
||||
return
|
||||
} else if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeCode {
|
||||
ctx.Error(204)
|
||||
ctx.Error(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
oldContent := comment.Content
|
||||
comment.Content = ctx.Query("content")
|
||||
if len(comment.Content) == 0 {
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"content": "",
|
||||
})
|
||||
return
|
||||
@ -2134,7 +2134,7 @@ func UpdateCommentContent(ctx *context.Context) {
|
||||
ctx.ServerError("UpdateAttachments", err)
|
||||
}
|
||||
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"content": string(markdown.Render([]byte(comment.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())),
|
||||
"attachments": attachmentsHTML(ctx, comment.Attachments, comment.Content),
|
||||
})
|
||||
@ -2154,10 +2154,10 @@ func DeleteComment(ctx *context.Context) {
|
||||
}
|
||||
|
||||
if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.CanWriteIssuesOrPulls(comment.Issue.IsPull)) {
|
||||
ctx.Error(403)
|
||||
ctx.Error(http.StatusForbidden)
|
||||
return
|
||||
} else if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeCode {
|
||||
ctx.Error(204)
|
||||
ctx.Error(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
@ -2196,7 +2196,7 @@ func ChangeIssueReaction(ctx *context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
ctx.Error(403)
|
||||
ctx.Error(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
@ -2244,7 +2244,7 @@ func ChangeIssueReaction(ctx *context.Context) {
|
||||
}
|
||||
|
||||
if len(issue.Reactions) == 0 {
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"empty": true,
|
||||
"html": "",
|
||||
})
|
||||
@ -2260,7 +2260,7 @@ func ChangeIssueReaction(ctx *context.Context) {
|
||||
ctx.ServerError("ChangeIssueReaction.HTMLString", err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"html": html,
|
||||
})
|
||||
}
|
||||
@ -2298,10 +2298,10 @@ func ChangeCommentReaction(ctx *context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
ctx.Error(403)
|
||||
ctx.Error(http.StatusForbidden)
|
||||
return
|
||||
} else if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeCode {
|
||||
ctx.Error(204)
|
||||
ctx.Error(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
@ -2344,7 +2344,7 @@ func ChangeCommentReaction(ctx *context.Context) {
|
||||
}
|
||||
|
||||
if len(comment.Reactions) == 0 {
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"empty": true,
|
||||
"html": "",
|
||||
})
|
||||
@ -2360,7 +2360,7 @@ func ChangeCommentReaction(ctx *context.Context) {
|
||||
ctx.ServerError("ChangeCommentReaction.HTMLString", err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"html": html,
|
||||
})
|
||||
}
|
||||
@ -2406,7 +2406,7 @@ func GetIssueAttachments(ctx *context.Context) {
|
||||
for i := 0; i < len(issue.Attachments); i++ {
|
||||
attachments[i] = convert.ToReleaseAttachment(issue.Attachments[i])
|
||||
}
|
||||
ctx.JSON(200, attachments)
|
||||
ctx.JSON(http.StatusOK, attachments)
|
||||
}
|
||||
|
||||
// GetCommentAttachments returns attachments for the comment
|
||||
@ -2426,7 +2426,7 @@ func GetCommentAttachments(ctx *context.Context) {
|
||||
attachments = append(attachments, convert.ToReleaseAttachment(comment.Attachments[i]))
|
||||
}
|
||||
}
|
||||
ctx.JSON(200, attachments)
|
||||
ctx.JSON(http.StatusOK, attachments)
|
||||
}
|
||||
|
||||
func updateAttachments(item interface{}, files []string) error {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user