@@ -16,10 +16,6 @@ import (
16
16
// ListTeams list all the teams of an organization
17
17
func ListTeams (ctx * context.APIContext ) {
18
18
org := ctx .Org .Organization
19
- if ! org .IsOrgMember (ctx .User .ID ) {
20
- ctx .Error (403 , "" , "Must be a member of the organization" )
21
- return
22
- }
23
19
if err := org .GetTeams (); err != nil {
24
20
ctx .Error (500 , "GetTeams" , err )
25
21
return
@@ -34,40 +30,11 @@ func ListTeams(ctx *context.APIContext) {
34
30
35
31
// GetTeam api for get a team
36
32
func GetTeam (ctx * context.APIContext ) {
37
- if ! models .IsOrganizationMember (ctx .Org .Team .OrgID , ctx .User .ID ) {
38
- ctx .Status (404 )
39
- return
40
- }
41
33
ctx .JSON (200 , convert .ToTeam (ctx .Org .Team ))
42
34
}
43
35
44
- // GetTeamRepos api for get a team's repos
45
- func GetTeamRepos (ctx * context.APIContext ) {
46
- team := ctx .Org .Team
47
- if ! models .IsOrganizationMember (team .OrgID , ctx .User .ID ) {
48
- ctx .Status (404 )
49
- return
50
- }
51
- if err := team .GetRepositories (); err != nil {
52
- ctx .Error (500 , "GetTeamRepos" , err )
53
- }
54
- repos := make ([]* api.Repository , len (team .Repos ))
55
- for i , repo := range team .Repos {
56
- access , err := models .AccessLevel (ctx .User , repo )
57
- if err != nil {
58
- ctx .Error (500 , "GetTeamRepos" , err )
59
- return
60
- }
61
- repos [i ] = repo .APIFormat (access )
62
- }
63
- ctx .JSON (200 , repos )
64
- }
65
-
66
36
// CreateTeam api for create a team
67
37
func CreateTeam (ctx * context.APIContext , form api.CreateTeamOption ) {
68
- if ! ctx .Org .Organization .IsOrgMember (ctx .User .ID ) {
69
- ctx .Error (403 , "" , "Must be an organization member" )
70
- }
71
38
team := & models.Team {
72
39
OrgID : ctx .Org .Organization .ID ,
73
40
Name : form .Name ,
@@ -88,10 +55,6 @@ func CreateTeam(ctx *context.APIContext, form api.CreateTeamOption) {
88
55
89
56
// EditTeam api for edit a team
90
57
func EditTeam (ctx * context.APIContext , form api.EditTeamOption ) {
91
- if ! ctx .User .IsUserOrgOwner (ctx .Org .Team .OrgID ) {
92
- ctx .Error (403 , "" , "Must be an organization owner" )
93
- return
94
- }
95
58
team := & models.Team {
96
59
ID : ctx .Org .Team .ID ,
97
60
OrgID : ctx .Org .Team .OrgID ,
@@ -108,10 +71,6 @@ func EditTeam(ctx *context.APIContext, form api.EditTeamOption) {
108
71
109
72
// DeleteTeam api for delete a team
110
73
func DeleteTeam (ctx * context.APIContext ) {
111
- if ! ctx .User .IsUserOrgOwner (ctx .Org .Team .OrgID ) {
112
- ctx .Error (403 , "" , "Must be an organization owner" )
113
- return
114
- }
115
74
if err := models .DeleteTeam (ctx .Org .Team ); err != nil {
116
75
ctx .Error (500 , "DeleteTeam" , err )
117
76
return
@@ -139,10 +98,6 @@ func GetTeamMembers(ctx *context.APIContext) {
139
98
140
99
// AddTeamMember api for add a member to a team
141
100
func AddTeamMember (ctx * context.APIContext ) {
142
- if ! ctx .User .IsUserOrgOwner (ctx .Org .Team .OrgID ) {
143
- ctx .Error (403 , "" , "Must be an organization owner" )
144
- return
145
- }
146
101
u := user .GetUserByParams (ctx )
147
102
if ctx .Written () {
148
103
return
@@ -156,10 +111,6 @@ func AddTeamMember(ctx *context.APIContext) {
156
111
157
112
// RemoveTeamMember api for remove one member from a team
158
113
func RemoveTeamMember (ctx * context.APIContext ) {
159
- if ! ctx .User .IsUserOrgOwner (ctx .Org .Team .OrgID ) {
160
- ctx .Error (403 , "" , "Must be an organization owner" )
161
- return
162
- }
163
114
u := user .GetUserByParams (ctx )
164
115
if ctx .Written () {
165
116
return
@@ -171,3 +122,75 @@ func RemoveTeamMember(ctx *context.APIContext) {
171
122
}
172
123
ctx .Status (204 )
173
124
}
125
+
126
+ // GetTeamRepos api for get a team's repos
127
+ func GetTeamRepos (ctx * context.APIContext ) {
128
+ team := ctx .Org .Team
129
+ if err := team .GetRepositories (); err != nil {
130
+ ctx .Error (500 , "GetTeamRepos" , err )
131
+ }
132
+ repos := make ([]* api.Repository , len (team .Repos ))
133
+ for i , repo := range team .Repos {
134
+ access , err := models .AccessLevel (ctx .User , repo )
135
+ if err != nil {
136
+ ctx .Error (500 , "GetTeamRepos" , err )
137
+ return
138
+ }
139
+ repos [i ] = repo .APIFormat (access )
140
+ }
141
+ ctx .JSON (200 , repos )
142
+ }
143
+
144
+ // getRepositoryByParams get repository by a team's organization ID and repo name
145
+ func getRepositoryByParams (ctx * context.APIContext ) * models.Repository {
146
+ repo , err := models .GetRepositoryByName (ctx .Org .Team .OrgID , ctx .Params (":reponame" ))
147
+ if err != nil {
148
+ if models .IsErrRepoNotExist (err ) {
149
+ ctx .Status (404 )
150
+ } else {
151
+ ctx .Error (500 , "GetRepositoryByName" , err )
152
+ }
153
+ return nil
154
+ }
155
+ return repo
156
+ }
157
+
158
+ // AddTeamRepository api for adding a repository to a team
159
+ func AddTeamRepository (ctx * context.APIContext ) {
160
+ repo := getRepositoryByParams (ctx )
161
+ if ctx .Written () {
162
+ return
163
+ }
164
+ if access , err := models .AccessLevel (ctx .User , repo ); err != nil {
165
+ ctx .Error (500 , "AccessLevel" , err )
166
+ return
167
+ } else if access < models .AccessModeAdmin {
168
+ ctx .Error (403 , "" , "Must have admin-level access to the repository" )
169
+ return
170
+ }
171
+ if err := ctx .Org .Team .AddRepository (repo ); err != nil {
172
+ ctx .Error (500 , "AddRepository" , err )
173
+ return
174
+ }
175
+ ctx .Status (204 )
176
+ }
177
+
178
+ // RemoveTeamRepository api for removing a repository from a team
179
+ func RemoveTeamRepository (ctx * context.APIContext ) {
180
+ repo := getRepositoryByParams (ctx )
181
+ if ctx .Written () {
182
+ return
183
+ }
184
+ if access , err := models .AccessLevel (ctx .User , repo ); err != nil {
185
+ ctx .Error (500 , "AccessLevel" , err )
186
+ return
187
+ } else if access < models .AccessModeAdmin {
188
+ ctx .Error (403 , "" , "Must have admin-level access to the repository" )
189
+ return
190
+ }
191
+ if err := ctx .Org .Team .RemoveRepository (repo .ID ); err != nil {
192
+ ctx .Error (500 , "RemoveRepository" , err )
193
+ return
194
+ }
195
+ ctx .Status (204 )
196
+ }
0 commit comments