Skip to content

Commit 09656a3

Browse files
committed
models/team: Inline Team::contains_user() fn
1 parent 67d44ed commit 09656a3

File tree

2 files changed

+10
-21
lines changed

2 files changed

+10
-21
lines changed

src/models/team.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ use bon::Builder;
22
use diesel::prelude::*;
33
use diesel_async::{AsyncPgConnection, RunQueryDsl};
44

5-
use crates_io_github::{GitHubClient, GitHubError};
6-
use oauth2::AccessToken;
7-
85
use crate::models::{Crate, CrateOwner, Owner, OwnerKind};
96
use crate::schema::{crate_owners, teams};
107

@@ -54,22 +51,6 @@ impl NewTeam<'_> {
5451
}
5552

5653
impl Team {
57-
/// Phones home to Github to ask if this User is a member of the given team.
58-
/// Note that we're assuming that the given user is the one interested in
59-
/// the answer. If this is not the case, then we could accidentally leak
60-
/// private membership information here.
61-
pub async fn contains_user(
62-
&self,
63-
gh_client: &dyn GitHubClient,
64-
gh_login: &str,
65-
token: &AccessToken,
66-
) -> Result<bool, GitHubError> {
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()))
71-
}
72-
7354
pub async fn owning(krate: &Crate, conn: &mut AsyncPgConnection) -> QueryResult<Vec<Owner>> {
7455
let base_query = CrateOwner::belonging_to(krate).filter(crate_owners::deleted.eq(false));
7556
let teams = base_query

src/models/user.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,16 @@ impl User {
8080
}
8181
}
8282
Owner::Team(ref team) => {
83-
let gh_login = &self.gh_login;
84-
if team.contains_user(gh_client, gh_login, &token).await? {
83+
// Phones home to GitHub to ask if this User is a member of the given team.
84+
// Note that we're assuming that the given user is the one interested in
85+
// the answer. If this is not the case, then we could accidentally leak
86+
// private membership information here.
87+
let is_team_member = gh_client
88+
.team_membership(team.org_id, team.github_id, &self.gh_login, &token)
89+
.await?
90+
.is_some_and(|m| m.is_active());
91+
92+
if is_team_member {
8593
best = Rights::Publish;
8694
}
8795
}

0 commit comments

Comments
 (0)