@@ -138,7 +138,7 @@ impl Team {
138138
139139 let org_id = team. organization . id ;
140140
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 ? {
142142 return Err ( custom (
143143 StatusCode :: FORBIDDEN ,
144144 "only members of a team or organization owners can add it as an owner" ,
@@ -166,11 +166,13 @@ impl Team {
166166 pub async fn contains_user (
167167 & self ,
168168 gh_client : & dyn GitHubClient ,
169- user : & User ,
169+ gh_login : & str ,
170+ token : & AccessToken ,
170171 ) -> Result < bool , GitHubError > {
171172 match self . org_id {
172173 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
174176 }
175177 // This means we don't have an org_id on file for the `self` team. It much
176178 // probably was deleted from github by the time we backfilled the database.
@@ -199,39 +201,37 @@ async fn can_add_team(
199201 gh_client : & dyn GitHubClient ,
200202 org_id : i32 ,
201203 team_id : i32 ,
202- user : & User ,
204+ gh_login : & str ,
205+ token : & AccessToken ,
203206) -> Result < bool , GitHubError > {
204207 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 ?,
207210 )
208211}
209212
210213async fn is_gh_org_owner (
211214 gh_client : & dyn GitHubClient ,
212215 org_id : i32 ,
213- user : & User ,
216+ gh_login : & str ,
217+ token : & AccessToken ,
214218) -> 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 ?;
220220 Ok ( membership. is_some_and ( |m| m. state == "active" && m. role == "admin" ) )
221221}
222222
223223async fn team_with_gh_id_contains_user (
224224 gh_client : & dyn GitHubClient ,
225225 github_org_id : i32 ,
226226 github_team_id : i32 ,
227- user : & User ,
227+ gh_login : & str ,
228+ token : & AccessToken ,
228229) -> Result < bool , GitHubError > {
229230 // GET /organizations/:org_id/team/:team_id/memberships/:username
230231 // check that "state": "active"
231232
232- let token = AccessToken :: new ( user. gh_access_token . expose_secret ( ) . to_string ( ) ) ;
233233 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)
235235 . await ?;
236236
237237 // There is also `state: pending` for which we could possibly give
0 commit comments