]> source.dussan.org Git - gitea.git/commitdiff
Remove redundant query in collaborator API (#516)
authorEthan Koenig <etk39@cornell.edu>
Wed, 28 Dec 2016 01:09:54 +0000 (20:09 -0500)
committerLunny Xiao <xiaolunwen@gmail.com>
Wed, 28 Dec 2016 01:09:54 +0000 (09:09 +0800)
routers/api/v1/repo/collaborators.go

index 4ffb5554afb23f8c240317a93869c12983ede4a0..31cb9c6b21fd5510d55cba65d2bf1d1a115852a3 100644 (file)
@@ -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
        }