Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/models/team.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl Team {
&self,
gh_client: &dyn GitHubClient,
user: &User,
) -> AppResult<bool> {
) -> Result<bool, GitHubError> {
match self.org_id {
Some(org_id) => {
team_with_gh_id_contains_user(gh_client, org_id, self.github_id, user).await
Expand Down Expand Up @@ -200,7 +200,7 @@ async fn can_add_team(
org_id: i32,
team_id: i32,
user: &User,
) -> AppResult<bool> {
) -> Result<bool, GitHubError> {
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?,
Expand All @@ -211,15 +211,15 @@ async fn is_gh_org_owner(
gh_client: &dyn GitHubClient,
org_id: i32,
user: &User,
) -> AppResult<bool> {
) -> Result<bool, GitHubError> {
let token = AccessToken::new(user.gh_access_token.expose_secret().to_string());
match gh_client
.org_membership(org_id, &user.gh_login, &token)
.await
{
Ok(membership) => Ok(membership.state == "active" && membership.role == "admin"),
Err(GitHubError::NotFound(_)) => Ok(false),
Err(e) => Err(e.into()),
Err(e) => Err(e),
}
}

Expand All @@ -228,7 +228,7 @@ async fn team_with_gh_id_contains_user(
github_org_id: i32,
github_team_id: i32,
user: &User,
) -> AppResult<bool> {
) -> Result<bool, GitHubError> {
// GET /organizations/:org_id/team/:team_id/memberships/:username
// check that "state": "active"

Expand Down
6 changes: 2 additions & 4 deletions src/models/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -69,7 +67,7 @@ impl User {
&self,
gh_client: &dyn GitHubClient,
owners: &[Owner],
) -> AppResult<Rights> {
) -> Result<Rights, GitHubError> {
let mut best = Rights::None;
for owner in owners {
match *owner {
Expand Down