diff --git a/src/models/team.rs b/src/models/team.rs index 62951689352..af72806a9e2 100644 --- a/src/models/team.rs +++ b/src/models/team.rs @@ -167,7 +167,7 @@ impl Team { &self, gh_client: &dyn GitHubClient, user: &User, - ) -> AppResult { + ) -> Result { match self.org_id { Some(org_id) => { team_with_gh_id_contains_user(gh_client, org_id, self.github_id, user).await @@ -200,7 +200,7 @@ async fn can_add_team( org_id: i32, team_id: i32, user: &User, -) -> AppResult { +) -> Result { Ok( team_with_gh_id_contains_user(gh_client, org_id, team_id, user).await? || is_gh_org_owner(gh_client, org_id, user).await?, @@ -211,7 +211,7 @@ async fn is_gh_org_owner( gh_client: &dyn GitHubClient, org_id: i32, user: &User, -) -> AppResult { +) -> Result { let token = AccessToken::new(user.gh_access_token.expose_secret().to_string()); match gh_client .org_membership(org_id, &user.gh_login, &token) @@ -219,7 +219,7 @@ async fn is_gh_org_owner( { Ok(membership) => Ok(membership.state == "active" && membership.role == "admin"), Err(GitHubError::NotFound(_)) => Ok(false), - Err(e) => Err(e.into()), + Err(e) => Err(e), } } @@ -228,7 +228,7 @@ async fn team_with_gh_id_contains_user( github_org_id: i32, github_team_id: i32, user: &User, -) -> AppResult { +) -> Result { // GET /organizations/:org_id/team/:team_id/memberships/:username // check that "state": "active" diff --git a/src/models/user.rs b/src/models/user.rs index f35fa654ffb..2852cd3afe8 100644 --- a/src/models/user.rs +++ b/src/models/user.rs @@ -7,12 +7,10 @@ use diesel::upsert::excluded; use diesel_async::{AsyncPgConnection, RunQueryDsl}; use secrecy::SecretString; -use crate::util::errors::AppResult; - use crate::models::{Crate, CrateOwner, Email, Owner, OwnerKind, Rights}; use crate::schema::{crate_owners, emails, users}; use crates_io_diesel_helpers::lower; -use crates_io_github::GitHubClient; +use crates_io_github::{GitHubClient, GitHubError}; /// The model representing a row in the `users` database table. #[derive(Clone, Debug, Queryable, Identifiable, Selectable)] @@ -69,7 +67,7 @@ impl User { &self, gh_client: &dyn GitHubClient, owners: &[Owner], - ) -> AppResult { + ) -> Result { let mut best = Rights::None; for owner in owners { match *owner {