aboutsummaryrefslogtreecommitdiff
path: root/routers/api/v1/api.go
diff options
context:
space:
mode:
Diffstat (limited to 'routers/api/v1/api.go')
-rw-r--r--routers/api/v1/api.go54
1 files changed, 30 insertions, 24 deletions
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go
index 04b392fc..59625efd 100644
--- a/routers/api/v1/api.go
+++ b/routers/api/v1/api.go
@@ -14,7 +14,7 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
- "github.com/gogits/gogs/modules/middleware"
+ "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/routers/api/v1/admin"
"github.com/gogits/gogs/routers/api/v1/misc"
"github.com/gogits/gogs/routers/api/v1/org"
@@ -23,7 +23,7 @@ import (
)
func RepoAssignment() macaron.Handler {
- return func(ctx *middleware.Context) {
+ return func(ctx *context.APIContext) {
userName := ctx.Params(":username")
repoName := ctx.Params(":reponame")
@@ -39,9 +39,9 @@ func RepoAssignment() macaron.Handler {
owner, err = models.GetUserByName(userName)
if err != nil {
if models.IsErrUserNotExist(err) {
- ctx.Error(404)
+ ctx.Status(404)
} else {
- ctx.APIError(500, "GetUserByName", err)
+ ctx.Error(500, "GetUserByName", err)
}
return
}
@@ -52,27 +52,29 @@ func RepoAssignment() macaron.Handler {
repo, err := models.GetRepositoryByName(owner.Id, repoName)
if err != nil {
if models.IsErrRepoNotExist(err) {
- ctx.Error(404)
+ ctx.Status(404)
} else {
- ctx.APIError(500, "GetRepositoryByName", err)
+ ctx.Error(500, "GetRepositoryByName", err)
}
return
} else if err = repo.GetOwner(); err != nil {
- ctx.APIError(500, "GetOwner", err)
+ ctx.Error(500, "GetOwner", err)
return
}
- mode, err := models.AccessLevel(ctx.User, repo)
- if err != nil {
- ctx.APIError(500, "AccessLevel", err)
- return
+ if ctx.IsSigned && ctx.User.IsAdmin {
+ ctx.Repo.AccessMode = models.ACCESS_MODE_OWNER
+ } else {
+ mode, err := models.AccessLevel(ctx.User, repo)
+ if err != nil {
+ ctx.Error(500, "AccessLevel", err)
+ return
+ }
+ ctx.Repo.AccessMode = mode
}
- ctx.Repo.AccessMode = mode
-
- // Check access.
- if ctx.Repo.AccessMode == models.ACCESS_MODE_NONE {
- ctx.Error(404)
+ if !ctx.Repo.HasAccess() {
+ ctx.Status(404)
return
}
@@ -82,7 +84,7 @@ func RepoAssignment() macaron.Handler {
// Contexter middleware already checks token for user sign in process.
func ReqToken() macaron.Handler {
- return func(ctx *middleware.Context) {
+ return func(ctx *context.Context) {
if !ctx.IsSigned {
ctx.Error(401)
return
@@ -91,7 +93,7 @@ func ReqToken() macaron.Handler {
}
func ReqBasicAuth() macaron.Handler {
- return func(ctx *middleware.Context) {
+ return func(ctx *context.Context) {
if !ctx.IsBasicAuth {
ctx.Error(401)
return
@@ -100,7 +102,7 @@ func ReqBasicAuth() macaron.Handler {
}
func ReqAdmin() macaron.Handler {
- return func(ctx *middleware.Context) {
+ return func(ctx *context.Context) {
if !ctx.User.IsAdmin {
ctx.Error(403)
return
@@ -181,11 +183,11 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Combo("/hooks").Get(repo.ListHooks).
Post(bind(api.CreateHookOption{}), repo.CreateHook)
m.Patch("/hooks/:id:int", bind(api.EditHookOption{}), repo.EditHook)
- m.Get("/raw/*", middleware.RepoRef(), repo.GetRawFile)
+ m.Get("/raw/*", context.RepoRef(), repo.GetRawFile)
m.Get("/archive/*", repo.GetArchive)
m.Group("/branches", func() {
- m.Get("",repo.ListBranches)
- m.Get("/:branchname",repo.GetBranch)
+ m.Get("", repo.ListBranches)
+ m.Get("/:branchname", repo.GetBranch)
})
m.Group("/keys", func() {
m.Combo("").Get(repo.ListDeployKeys).
@@ -193,6 +195,10 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Combo("/:id").Get(repo.GetDeployKey).
Delete(repo.DeleteDeploykey)
})
+ m.Group("/issues", func() {
+ m.Combo("").Get(repo.ListIssues).Post(bind(api.CreateIssueOption{}), repo.CreateIssue)
+ m.Combo("/:index").Get(repo.GetIssue).Patch(bind(api.EditIssueOption{}), repo.EditIssue)
+ })
}, RepoAssignment())
}, ReqToken())
@@ -201,7 +207,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/users/:username/orgs", org.ListUserOrgs)
m.Combo("/orgs/:orgname").Get(org.Get).Patch(bind(api.EditOrgOption{}), org.Edit)
- m.Any("/*", func(ctx *middleware.Context) {
+ m.Any("/*", func(ctx *context.Context) {
ctx.Error(404)
})
@@ -218,5 +224,5 @@ func RegisterRoutes(m *macaron.Macaron) {
})
})
}, ReqAdmin())
- })
+ }, context.APIContexter())
}