Skip to content

Commit 9fae9f0

Browse files
ethantkoeniglunny
authored andcommitted
Remove redundant query in collaborator API (#516)
1 parent 8f1c311 commit 9fae9f0

File tree

1 file changed

+4
-24
lines changed

1 file changed

+4
-24
lines changed

routers/api/v1/repo/collaborators.go

+4-24
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@ import (
1313

1414
// ListCollaborators list a repository's collaborators
1515
func ListCollaborators(ctx *context.APIContext) {
16-
access, err := models.AccessLevel(ctx.User, ctx.Repo.Repository)
17-
if err != nil {
18-
ctx.Error(500, "AccessLevel", err)
19-
return
20-
}
21-
if access < models.AccessModeWrite {
16+
if !ctx.Repo.IsWriter() {
2217
ctx.Error(403, "", "User does not have push access")
2318
return
2419
}
@@ -36,12 +31,7 @@ func ListCollaborators(ctx *context.APIContext) {
3631

3732
// IsCollaborator check if a user is a collaborator of a repository
3833
func IsCollaborator(ctx *context.APIContext) {
39-
access, err := models.AccessLevel(ctx.User, ctx.Repo.Repository)
40-
if err != nil {
41-
ctx.Error(500, "AccessLevel", err)
42-
return
43-
}
44-
if access < models.AccessModeWrite {
34+
if !ctx.Repo.IsWriter() {
4535
ctx.Error(403, "", "User does not have push access")
4636
return
4737
}
@@ -68,12 +58,7 @@ func IsCollaborator(ctx *context.APIContext) {
6858

6959
// AddCollaborator add a collaborator of a repository
7060
func AddCollaborator(ctx *context.APIContext, form api.AddCollaboratorOption) {
71-
access, err := models.AccessLevel(ctx.User, ctx.Repo.Repository)
72-
if err != nil {
73-
ctx.Error(500, "AccessLevel", err)
74-
return
75-
}
76-
if access < models.AccessModeWrite {
61+
if !ctx.Repo.IsWriter() {
7762
ctx.Error(403, "", "User does not have push access")
7863
return
7964
}
@@ -104,12 +89,7 @@ func AddCollaborator(ctx *context.APIContext, form api.AddCollaboratorOption) {
10489

10590
// DeleteCollaborator delete a collaborator from a repository
10691
func DeleteCollaborator(ctx *context.APIContext) {
107-
access, err := models.AccessLevel(ctx.User, ctx.Repo.Repository)
108-
if err != nil {
109-
ctx.Error(500, "AccessLevel", err)
110-
return
111-
}
112-
if access < models.AccessModeWrite {
92+
if !ctx.Repo.IsWriter() {
11393
ctx.Error(403, "", "User does not have push access")
11494
return
11595
}

0 commit comments

Comments
 (0)