Skip to content

Commit eea1e46

Browse files
committed
models/team: Inline can_add_team() fn
1 parent 100bcd9 commit eea1e46

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

src/controllers/krate/owners.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::controllers::krate::CratePath;
44
use crate::models::krate::OwnerRemoveError;
5-
use crate::models::team::can_add_team;
5+
use crate::models::team::{is_gh_org_owner, team_with_gh_id_contains_user};
66
use crate::models::{
77
krate::NewOwnerInvite, token::EndpointScope, CrateOwner, NewCrateOwnerInvitation,
88
NewCrateOwnerInvitationOutcome, NewTeam,
@@ -411,7 +411,11 @@ pub async fn create_or_update_github_team(
411411
let org_id = team.organization.id;
412412
let gh_login = &req_user.gh_login;
413413

414-
if !can_add_team(gh_client, org_id, team.id, gh_login, &token).await? {
414+
let can_add_team = team_with_gh_id_contains_user(gh_client, org_id, team.id, gh_login, &token)
415+
.await?
416+
|| is_gh_org_owner(gh_client, org_id, gh_login, &token).await?;
417+
418+
if !can_add_team {
415419
return Err(custom(
416420
StatusCode::FORBIDDEN,
417421
"only members of a team or organization owners can add it as an owner",

src/models/team.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,7 @@ impl Team {
8282
}
8383
}
8484

85-
pub async fn can_add_team(
86-
gh_client: &dyn GitHubClient,
87-
org_id: i32,
88-
team_id: i32,
89-
gh_login: &str,
90-
token: &AccessToken,
91-
) -> Result<bool, GitHubError> {
92-
Ok(
93-
team_with_gh_id_contains_user(gh_client, org_id, team_id, gh_login, token).await?
94-
|| is_gh_org_owner(gh_client, org_id, gh_login, token).await?,
95-
)
96-
}
97-
98-
async fn is_gh_org_owner(
85+
pub async fn is_gh_org_owner(
9986
gh_client: &dyn GitHubClient,
10087
org_id: i32,
10188
gh_login: &str,
@@ -105,7 +92,7 @@ async fn is_gh_org_owner(
10592
Ok(membership.is_some_and(|m| m.is_active_admin()))
10693
}
10794

108-
async fn team_with_gh_id_contains_user(
95+
pub async fn team_with_gh_id_contains_user(
10996
gh_client: &dyn GitHubClient,
11097
github_org_id: i32,
11198
github_team_id: i32,

0 commit comments

Comments
 (0)