summaryrefslogtreecommitdiffstats
path: root/routers/api/v1/repo/collaborators.go
diff options
context:
space:
mode:
authorEthan Koenig <etk39@cornell.edu>2016-12-27 20:09:54 -0500
committerLunny Xiao <xiaolunwen@gmail.com>2016-12-28 09:09:54 +0800
commit9fae9f0dc21e95209491c96d2e809d8a50a94a21 (patch)
tree5efdcb9eab2b7ce10d93b273b854a46513adec41 /routers/api/v1/repo/collaborators.go
parent8f1c311b903ba72ad3eee1c180ee0567757bede4 (diff)
downloadgitea-9fae9f0dc21e95209491c96d2e809d8a50a94a21.tar.gz
gitea-9fae9f0dc21e95209491c96d2e809d8a50a94a21.zip
Remove redundant query in collaborator API (#516)
Diffstat (limited to 'routers/api/v1/repo/collaborators.go')
-rw-r--r--routers/api/v1/repo/collaborators.go28
1 files changed, 4 insertions, 24 deletions
diff --git a/routers/api/v1/repo/collaborators.go b/routers/api/v1/repo/collaborators.go
index 4ffb5554af..31cb9c6b21 100644
--- a/routers/api/v1/repo/collaborators.go
+++ b/routers/api/v1/repo/collaborators.go
@@ -13,12 +13,7 @@ import (
// ListCollaborators list a repository's collaborators
func ListCollaborators(ctx *context.APIContext) {
- access, err := models.AccessLevel(ctx.User, ctx.Repo.Repository)
- if err != nil {
- ctx.Error(500, "AccessLevel", err)
- return
- }
- if access < models.AccessModeWrite {
+ if !ctx.Repo.IsWriter() {
ctx.Error(403, "", "User does not have push access")
return
}
@@ -36,12 +31,7 @@ func ListCollaborators(ctx *context.APIContext) {
// IsCollaborator check if a user is a collaborator of a repository
func IsCollaborator(ctx *context.APIContext) {
- access, err := models.AccessLevel(ctx.User, ctx.Repo.Repository)
- if err != nil {
- ctx.Error(500, "AccessLevel", err)
- return
- }
- if access < models.AccessModeWrite {
+ if !ctx.Repo.IsWriter() {
ctx.Error(403, "", "User does not have push access")
return
}
@@ -68,12 +58,7 @@ func IsCollaborator(ctx *context.APIContext) {
// AddCollaborator add a collaborator of a repository
func AddCollaborator(ctx *context.APIContext, form api.AddCollaboratorOption) {
- access, err := models.AccessLevel(ctx.User, ctx.Repo.Repository)
- if err != nil {
- ctx.Error(500, "AccessLevel", err)
- return
- }
- if access < models.AccessModeWrite {
+ if !ctx.Repo.IsWriter() {
ctx.Error(403, "", "User does not have push access")
return
}
@@ -104,12 +89,7 @@ func AddCollaborator(ctx *context.APIContext, form api.AddCollaboratorOption) {
// DeleteCollaborator delete a collaborator from a repository
func DeleteCollaborator(ctx *context.APIContext) {
- access, err := models.AccessLevel(ctx.User, ctx.Repo.Repository)
- if err != nil {
- ctx.Error(500, "AccessLevel", err)
- return
- }
- if access < models.AccessModeWrite {
+ if !ctx.Repo.IsWriter() {
ctx.Error(403, "", "User does not have push access")
return
}