@@ -138,7 +138,7 @@ impl Team {
138
138
139
139
let org_id = team. organization . id ;
140
140
141
- if !can_add_team ( gh_client, org_id, team. id , req_user) . await ? {
141
+ if !can_add_team ( gh_client, org_id, team. id , & req_user. gh_login , & token ) . await ? {
142
142
return Err ( custom (
143
143
StatusCode :: FORBIDDEN ,
144
144
"only members of a team or organization owners can add it as an owner" ,
@@ -166,11 +166,13 @@ impl Team {
166
166
pub async fn contains_user (
167
167
& self ,
168
168
gh_client : & dyn GitHubClient ,
169
- user : & User ,
169
+ gh_login : & str ,
170
+ token : & AccessToken ,
170
171
) -> Result < bool , GitHubError > {
171
172
match self . org_id {
172
173
Some ( org_id) => {
173
- team_with_gh_id_contains_user ( gh_client, org_id, self . github_id , user) . await
174
+ team_with_gh_id_contains_user ( gh_client, org_id, self . github_id , gh_login, token)
175
+ . await
174
176
}
175
177
// This means we don't have an org_id on file for the `self` team. It much
176
178
// probably was deleted from github by the time we backfilled the database.
@@ -199,39 +201,37 @@ async fn can_add_team(
199
201
gh_client : & dyn GitHubClient ,
200
202
org_id : i32 ,
201
203
team_id : i32 ,
202
- user : & User ,
204
+ gh_login : & str ,
205
+ token : & AccessToken ,
203
206
) -> Result < bool , GitHubError > {
204
207
Ok (
205
- team_with_gh_id_contains_user ( gh_client, org_id, team_id, user ) . await ?
206
- || is_gh_org_owner ( gh_client, org_id, user ) . await ?,
208
+ team_with_gh_id_contains_user ( gh_client, org_id, team_id, gh_login , token ) . await ?
209
+ || is_gh_org_owner ( gh_client, org_id, gh_login , token ) . await ?,
207
210
)
208
211
}
209
212
210
213
async fn is_gh_org_owner (
211
214
gh_client : & dyn GitHubClient ,
212
215
org_id : i32 ,
213
- user : & User ,
216
+ gh_login : & str ,
217
+ token : & AccessToken ,
214
218
) -> Result < bool , GitHubError > {
215
- let token = AccessToken :: new ( user. gh_access_token . expose_secret ( ) . to_string ( ) ) ;
216
- let membership = gh_client
217
- . org_membership ( org_id, & user. gh_login , & token)
218
- . await ?;
219
-
219
+ let membership = gh_client. org_membership ( org_id, gh_login, token) . await ?;
220
220
Ok ( membership. is_some_and ( |m| m. state == "active" && m. role == "admin" ) )
221
221
}
222
222
223
223
async fn team_with_gh_id_contains_user (
224
224
gh_client : & dyn GitHubClient ,
225
225
github_org_id : i32 ,
226
226
github_team_id : i32 ,
227
- user : & User ,
227
+ gh_login : & str ,
228
+ token : & AccessToken ,
228
229
) -> Result < bool , GitHubError > {
229
230
// GET /organizations/:org_id/team/:team_id/memberships/:username
230
231
// check that "state": "active"
231
232
232
- let token = AccessToken :: new ( user. gh_access_token . expose_secret ( ) . to_string ( ) ) ;
233
233
let membership = gh_client
234
- . team_membership ( github_org_id, github_team_id, & user . gh_login , & token)
234
+ . team_membership ( github_org_id, github_team_id, gh_login, token)
235
235
. await ?;
236
236
237
237
// There is also `state: pending` for which we could possibly give
0 commit comments