Skip to content

Commit 67d44ed

Browse files
committed
models/team: Inline team_with_gh_id_contains_user() fn
1 parent d6fa6da commit 67d44ed

File tree

2 files changed

+10
-23
lines changed

2 files changed

+10
-23
lines changed

src/controllers/krate/owners.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
use crate::controllers::krate::CratePath;
44
use crate::models::krate::OwnerRemoveError;
5-
use crate::models::team::team_with_gh_id_contains_user;
65
use crate::models::{
76
krate::NewOwnerInvite, token::EndpointScope, CrateOwner, NewCrateOwnerInvitation,
87
NewCrateOwnerInvitationOutcome, NewTeam,
@@ -411,9 +410,13 @@ pub async fn create_or_update_github_team(
411410
let org_id = team.organization.id;
412411
let gh_login = &req_user.gh_login;
413412

414-
let can_add_team = team_with_gh_id_contains_user(gh_client, org_id, team.id, gh_login, &token)
413+
let is_team_member = gh_client
414+
.team_membership(org_id, team.id, gh_login, &token)
415415
.await?
416-
|| is_gh_org_owner(gh_client, org_id, gh_login, &token).await?;
416+
.is_some_and(|m| m.is_active());
417+
418+
let can_add_team =
419+
is_team_member || is_gh_org_owner(gh_client, org_id, gh_login, &token).await?;
417420

418421
if !can_add_team {
419422
return Err(custom(

src/models/team.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ impl Team {
6464
gh_login: &str,
6565
token: &AccessToken,
6666
) -> Result<bool, GitHubError> {
67-
team_with_gh_id_contains_user(gh_client, self.org_id, self.github_id, gh_login, token).await
67+
Ok(gh_client
68+
.team_membership(self.org_id, self.github_id, gh_login, token)
69+
.await?
70+
.is_some_and(|m| m.is_active()))
6871
}
6972

7073
pub async fn owning(krate: &Crate, conn: &mut AsyncPgConnection) -> QueryResult<Vec<Owner>> {
@@ -81,22 +84,3 @@ impl Team {
8184
Ok(teams.collect())
8285
}
8386
}
84-
85-
pub async fn team_with_gh_id_contains_user(
86-
gh_client: &dyn GitHubClient,
87-
github_org_id: i32,
88-
github_team_id: i32,
89-
gh_login: &str,
90-
token: &AccessToken,
91-
) -> Result<bool, GitHubError> {
92-
// GET /organizations/:org_id/team/:team_id/memberships/:username
93-
// check that "state": "active"
94-
95-
let membership = gh_client
96-
.team_membership(github_org_id, github_team_id, gh_login, token)
97-
.await?;
98-
99-
// There is also `state: pending` for which we could possibly give
100-
// some feedback, but it's not obvious how that should work.
101-
Ok(membership.is_some_and(|m| m.is_active()))
102-
}

0 commit comments

Comments
 (0)