|
@@ -10,6 +10,7 @@ import (
|
|
|
"gitote/gitote/routes/api/v1/org"
|
|
"gitote/gitote/routes/api/v1/org"
|
|
|
"gitote/gitote/routes/api/v1/repo"
|
|
"gitote/gitote/routes/api/v1/repo"
|
|
|
"gitote/gitote/routes/api/v1/user"
|
|
"gitote/gitote/routes/api/v1/user"
|
|
|
|
|
+ "net/http"
|
|
|
"strings"
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/go-macaron/binding"
|
|
"github.com/go-macaron/binding"
|
|
@@ -33,43 +34,34 @@ func repoAssignment() macaron.Handler {
|
|
|
} else {
|
|
} else {
|
|
|
owner, err = models.GetUserByName(userName)
|
|
owner, err = models.GetUserByName(userName)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- if errors.IsUserNotExist(err) {
|
|
|
|
|
- c.Status(404)
|
|
|
|
|
- } else {
|
|
|
|
|
- c.Error(500, "GetUserByName", err)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ c.NotFoundOrServerError("GetUserByName", errors.IsUserNotExist, err)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
c.Repo.Owner = owner
|
|
c.Repo.Owner = owner
|
|
|
|
|
|
|
|
- // Get repository.
|
|
|
|
|
repo, err := models.GetRepositoryByName(owner.ID, repoName)
|
|
repo, err := models.GetRepositoryByName(owner.ID, repoName)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- if errors.IsRepoNotExist(err) {
|
|
|
|
|
- c.Status(404)
|
|
|
|
|
- } else {
|
|
|
|
|
- c.Error(500, "GetRepositoryByName", err)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ c.NotFoundOrServerError("GetRepositoryByName", errors.IsRepoNotExist, err)
|
|
|
return
|
|
return
|
|
|
} else if err = repo.GetOwner(); err != nil {
|
|
} else if err = repo.GetOwner(); err != nil {
|
|
|
- c.Error(500, "GetOwner", err)
|
|
|
|
|
|
|
+ c.ServerError("GetOwner", err)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if c.IsTokenAuth && c.User.IsAdmin {
|
|
if c.IsTokenAuth && c.User.IsAdmin {
|
|
|
c.Repo.AccessMode = models.ACCESS_MODE_OWNER
|
|
c.Repo.AccessMode = models.ACCESS_MODE_OWNER
|
|
|
} else {
|
|
} else {
|
|
|
- mode, err := models.AccessLevel(c.User.ID, repo)
|
|
|
|
|
|
|
+ mode, err := models.AccessLevel(c.UserID(), repo)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- c.Error(500, "AccessLevel", err)
|
|
|
|
|
|
|
+ c.ServerError("AccessLevel", err)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
c.Repo.AccessMode = mode
|
|
c.Repo.AccessMode = mode
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if !c.Repo.HasAccess() {
|
|
if !c.Repo.HasAccess() {
|
|
|
- c.Status(404)
|
|
|
|
|
|
|
+ c.NotFound()
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -81,7 +73,7 @@ func repoAssignment() macaron.Handler {
|
|
|
func reqToken() macaron.Handler {
|
|
func reqToken() macaron.Handler {
|
|
|
return func(c *context.Context) {
|
|
return func(c *context.Context) {
|
|
|
if !c.IsTokenAuth {
|
|
if !c.IsTokenAuth {
|
|
|
- c.Error(401)
|
|
|
|
|
|
|
+ c.Error(http.StatusUnauthorized)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -90,7 +82,7 @@ func reqToken() macaron.Handler {
|
|
|
func reqBasicAuth() macaron.Handler {
|
|
func reqBasicAuth() macaron.Handler {
|
|
|
return func(c *context.Context) {
|
|
return func(c *context.Context) {
|
|
|
if !c.IsBasicAuth {
|
|
if !c.IsBasicAuth {
|
|
|
- c.Error(401)
|
|
|
|
|
|
|
+ c.Error(http.StatusUnauthorized)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -99,7 +91,7 @@ func reqBasicAuth() macaron.Handler {
|
|
|
func reqAdmin() macaron.Handler {
|
|
func reqAdmin() macaron.Handler {
|
|
|
return func(c *context.Context) {
|
|
return func(c *context.Context) {
|
|
|
if !c.IsLogged || !c.User.IsAdmin {
|
|
if !c.IsLogged || !c.User.IsAdmin {
|
|
|
- c.Error(403)
|
|
|
|
|
|
|
+ c.Error(http.StatusForbidden)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -108,7 +100,7 @@ func reqAdmin() macaron.Handler {
|
|
|
func reqRepoWriter() macaron.Handler {
|
|
func reqRepoWriter() macaron.Handler {
|
|
|
return func(c *context.Context) {
|
|
return func(c *context.Context) {
|
|
|
if !c.Repo.IsWriter() {
|
|
if !c.Repo.IsWriter() {
|
|
|
- c.Error(403)
|
|
|
|
|
|
|
+ c.Error(http.StatusForbidden)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -132,11 +124,7 @@ func orgAssignment(args ...bool) macaron.Handler {
|
|
|
if assignOrg {
|
|
if assignOrg {
|
|
|
c.Org.Organization, err = models.GetUserByName(c.Params(":orgname"))
|
|
c.Org.Organization, err = models.GetUserByName(c.Params(":orgname"))
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- if errors.IsUserNotExist(err) {
|
|
|
|
|
- c.Status(404)
|
|
|
|
|
- } else {
|
|
|
|
|
- c.Error(500, "GetUserByName", err)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ c.NotFoundOrServerError("GetUserByName", errors.IsUserNotExist, err)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -144,11 +132,7 @@ func orgAssignment(args ...bool) macaron.Handler {
|
|
|
if assignTeam {
|
|
if assignTeam {
|
|
|
c.Org.Team, err = models.GetTeamByID(c.ParamsInt64(":teamid"))
|
|
c.Org.Team, err = models.GetTeamByID(c.ParamsInt64(":teamid"))
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- if errors.IsUserNotExist(err) {
|
|
|
|
|
- c.Status(404)
|
|
|
|
|
- } else {
|
|
|
|
|
- c.Error(500, "GetTeamById", err)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ c.NotFoundOrServerError("GetTeamByID", errors.IsTeamNotExist, err)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -157,7 +141,7 @@ func orgAssignment(args ...bool) macaron.Handler {
|
|
|
|
|
|
|
|
func mustEnableIssues(c *context.APIContext) {
|
|
func mustEnableIssues(c *context.APIContext) {
|
|
|
if !c.Repo.Repository.EnableIssues || c.Repo.Repository.EnableExternalTracker {
|
|
if !c.Repo.Repository.EnableIssues || c.Repo.Repository.EnableExternalTracker {
|
|
|
- c.Status(404)
|
|
|
|
|
|
|
+ c.NotFound()
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -319,7 +303,7 @@ func RegisterRoutes(m *macaron.Macaron) {
|
|
|
}, orgAssignment(true))
|
|
}, orgAssignment(true))
|
|
|
|
|
|
|
|
m.Any("/*", func(c *context.Context) {
|
|
m.Any("/*", func(c *context.Context) {
|
|
|
- c.Error(404)
|
|
|
|
|
|
|
+ c.NotFound()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
m.Group("/admin", func() {
|
|
m.Group("/admin", func() {
|