@@ -13,12 +13,7 @@ import (
13
13
14
14
// ListCollaborators list a repository's collaborators
15
15
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 () {
22
17
ctx .Error (403 , "" , "User does not have push access" )
23
18
return
24
19
}
@@ -36,12 +31,7 @@ func ListCollaborators(ctx *context.APIContext) {
36
31
37
32
// IsCollaborator check if a user is a collaborator of a repository
38
33
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 () {
45
35
ctx .Error (403 , "" , "User does not have push access" )
46
36
return
47
37
}
@@ -68,12 +58,7 @@ func IsCollaborator(ctx *context.APIContext) {
68
58
69
59
// AddCollaborator add a collaborator of a repository
70
60
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 () {
77
62
ctx .Error (403 , "" , "User does not have push access" )
78
63
return
79
64
}
@@ -104,12 +89,7 @@ func AddCollaborator(ctx *context.APIContext, form api.AddCollaboratorOption) {
104
89
105
90
// DeleteCollaborator delete a collaborator from a repository
106
91
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 () {
113
93
ctx .Error (403 , "" , "User does not have push access" )
114
94
return
115
95
}
0 commit comments