Skip to content

Commit fe04b2a

Browse files
authored
models/team: Simplify fn return types (#10578)
We don't need an `AppResult` in most cases where a `Result<_, GitHubError>` is sufficient.
1 parent 15133c4 commit fe04b2a

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/models/team.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl Team {
167167
&self,
168168
gh_client: &dyn GitHubClient,
169169
user: &User,
170-
) -> AppResult<bool> {
170+
) -> Result<bool, GitHubError> {
171171
match self.org_id {
172172
Some(org_id) => {
173173
team_with_gh_id_contains_user(gh_client, org_id, self.github_id, user).await
@@ -200,7 +200,7 @@ async fn can_add_team(
200200
org_id: i32,
201201
team_id: i32,
202202
user: &User,
203-
) -> AppResult<bool> {
203+
) -> Result<bool, GitHubError> {
204204
Ok(
205205
team_with_gh_id_contains_user(gh_client, org_id, team_id, user).await?
206206
|| is_gh_org_owner(gh_client, org_id, user).await?,
@@ -211,15 +211,15 @@ async fn is_gh_org_owner(
211211
gh_client: &dyn GitHubClient,
212212
org_id: i32,
213213
user: &User,
214-
) -> AppResult<bool> {
214+
) -> Result<bool, GitHubError> {
215215
let token = AccessToken::new(user.gh_access_token.expose_secret().to_string());
216216
match gh_client
217217
.org_membership(org_id, &user.gh_login, &token)
218218
.await
219219
{
220220
Ok(membership) => Ok(membership.state == "active" && membership.role == "admin"),
221221
Err(GitHubError::NotFound(_)) => Ok(false),
222-
Err(e) => Err(e.into()),
222+
Err(e) => Err(e),
223223
}
224224
}
225225

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

src/models/user.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ use diesel::upsert::excluded;
77
use diesel_async::{AsyncPgConnection, RunQueryDsl};
88
use secrecy::SecretString;
99

10-
use crate::util::errors::AppResult;
11-
1210
use crate::models::{Crate, CrateOwner, Email, Owner, OwnerKind, Rights};
1311
use crate::schema::{crate_owners, emails, users};
1412
use crates_io_diesel_helpers::lower;
15-
use crates_io_github::GitHubClient;
13+
use crates_io_github::{GitHubClient, GitHubError};
1614

1715
/// The model representing a row in the `users` database table.
1816
#[derive(Clone, Debug, Queryable, Identifiable, Selectable)]
@@ -69,7 +67,7 @@ impl User {
6967
&self,
7068
gh_client: &dyn GitHubClient,
7169
owners: &[Owner],
72-
) -> AppResult<Rights> {
70+
) -> Result<Rights, GitHubError> {
7371
let mut best = Rights::None;
7472
for owner in owners {
7573
match *owner {

0 commit comments

Comments
 (0)