summaryrefslogtreecommitdiffstats
path: root/routers/api/v1/repo
diff options
context:
space:
mode:
authorEthan Koenig <etk39@cornell.edu>2017-07-11 21:23:41 -0400
committerKim "BKC" Carlbäcker <kim.carlbacker@gmail.com>2017-07-12 03:23:41 +0200
commit93a1de48428c2f89502cf6bba80f3976c6f5839f (patch)
tree8d08276df62513a32f0c0573b3e388bb823454ef /routers/api/v1/repo
parentda89afda58e18700ee49f955de3f33fdc591c239 (diff)
downloadgitea-93a1de48428c2f89502cf6bba80f3976c6f5839f.tar.gz
gitea-93a1de48428c2f89502cf6bba80f3976c6f5839f.zip
Fix repo API bug (#2133)
Don't require token when not necessary
Diffstat (limited to 'routers/api/v1/repo')
-rw-r--r--routers/api/v1/repo/fork.go3
-rw-r--r--routers/api/v1/repo/release.go8
-rw-r--r--routers/api/v1/repo/repo.go8
-rw-r--r--routers/api/v1/repo/status.go7
4 files changed, 5 insertions, 21 deletions
diff --git a/routers/api/v1/repo/fork.go b/routers/api/v1/repo/fork.go
index 44b79a6fef..25464dbd78 100644
--- a/routers/api/v1/repo/fork.go
+++ b/routers/api/v1/repo/fork.go
@@ -9,6 +9,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
+ "code.gitea.io/gitea/routers/api/v1/utils"
)
// ListForks list a repository's forks
@@ -29,7 +30,7 @@ func ListForks(ctx *context.APIContext) {
}
apiForks := make([]*api.Repository, len(forks))
for i, fork := range forks {
- access, err := models.AccessLevel(ctx.User.ID, fork)
+ access, err := models.AccessLevel(utils.UserID(ctx), fork)
if err != nil {
ctx.Error(500, "AccessLevel", err)
return
diff --git a/routers/api/v1/repo/release.go b/routers/api/v1/repo/release.go
index ed5b8f4f78..302be8dbab 100644
--- a/routers/api/v1/repo/release.go
+++ b/routers/api/v1/repo/release.go
@@ -34,14 +34,8 @@ func GetRelease(ctx *context.APIContext) {
// ListReleases list a repository's releases
func ListReleases(ctx *context.APIContext) {
- access, err := models.AccessLevel(ctx.User.ID, ctx.Repo.Repository)
- if err != nil {
- ctx.Error(500, "AccessLevel", err)
- return
- }
-
releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, models.FindReleasesOptions{
- IncludeDrafts: access >= models.AccessModeWrite,
+ IncludeDrafts: ctx.Repo.AccessMode >= models.AccessModeWrite,
}, 1, 2147483647)
if err != nil {
ctx.Error(500, "GetReleasesByRepoID", err)
diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go
index 7fb828ddbc..178f1005e5 100644
--- a/routers/api/v1/repo/repo.go
+++ b/routers/api/v1/repo/repo.go
@@ -267,13 +267,7 @@ func Get(ctx *context.APIContext) {
// 200: Repository
// 500: error
- repo := ctx.Repo.Repository
- access, err := models.AccessLevel(ctx.User.ID, repo)
- if err != nil {
- ctx.Error(500, "GetRepository", err)
- return
- }
- ctx.JSON(200, repo.APIFormat(access))
+ ctx.JSON(200, ctx.Repo.Repository.APIFormat(ctx.Repo.AccessMode))
}
// GetByID returns a single Repository
diff --git a/routers/api/v1/repo/status.go b/routers/api/v1/repo/status.go
index d9b101df05..e4cc20a50b 100644
--- a/routers/api/v1/repo/status.go
+++ b/routers/api/v1/repo/status.go
@@ -103,15 +103,10 @@ func GetCombinedCommitStatus(ctx *context.APIContext) {
return
}
- acl, err := models.AccessLevel(ctx.User.ID, repo)
- if err != nil {
- ctx.Error(500, "AccessLevel", fmt.Errorf("AccessLevel[%d, %s]: %v", ctx.User.ID, repo.FullName(), err))
- return
- }
retStatus := &combinedCommitStatus{
SHA: sha,
TotalCount: len(statuses),
- Repo: repo.APIFormat(acl),
+ Repo: repo.APIFormat(ctx.Repo.AccessMode),
URL: "",
}