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
4 changes: 2 additions & 2 deletions src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
return Ok(None);
};

let user = User::async_find(conn, id).await.map_err(|err| {
let user = User::find(conn, id).await.map_err(|err| {
parts.request_log().add("cause", err);
internal("user_id from cookie not found in database")
})?;
Expand Down Expand Up @@ -223,7 +223,7 @@
forbidden("authentication failed")
})?;

let user = User::async_find(conn, token.user_id).await.map_err(|err| {
let user = User::find(conn, token.user_id).await.map_err(|err| {

Check warning on line 226 in src/auth.rs

View check run for this annotation

Codecov / codecov/patch

src/auth.rs#L226

Added line #L226 was not covered by tests
parts.request_log().add("cause", err);
internal("user_id from token not found in database")
})?;
Expand Down
2 changes: 1 addition & 1 deletion src/bin/crates-admin/verify_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

let token = HashedToken::parse(&opts.api_token)?;
let token = ApiToken::find_by_api_token(&mut conn, &token).await?;
let user = User::async_find(&mut conn, token.user_id).await?;
let user = User::find(&mut conn, token.user_id).await?;

Check warning on line 25 in src/bin/crates-admin/verify_token.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/crates-admin/verify_token.rs#L25

Added line #L25 was not covered by tests
println!("The token belongs to user {}", user.gh_login);
Ok(())
}
2 changes: 1 addition & 1 deletion src/controllers/github/secret_scanning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ async fn send_notification_email(
state: &AppState,
conn: &mut AsyncPgConnection,
) -> anyhow::Result<()> {
let user = User::async_find(conn, token.user_id)
let user = User::find(conn, token.user_id)
.await
.context("Failed to find user")?;

Expand Down
8 changes: 1 addition & 7 deletions src/models/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,7 @@ pub struct User {
}

impl User {
pub fn find(conn: &mut impl Conn, id: i32) -> QueryResult<User> {
use diesel::RunQueryDsl;

users::table.find(id).first(conn)
}

pub async fn async_find(conn: &mut AsyncPgConnection, id: i32) -> QueryResult<User> {
pub async fn find(conn: &mut AsyncPgConnection, id: i32) -> QueryResult<User> {
use diesel_async::RunQueryDsl;

users::table.find(id).first(conn).await
Expand Down
2 changes: 1 addition & 1 deletion src/tests/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async fn updating_existing_user_doesnt_change_api_token() {
// Use the original API token to find the now updated user
let hashed_token = assert_ok!(HashedToken::parse(token.expose_secret()));
let api_token = assert_ok!(ApiToken::find_by_api_token(&mut conn, &hashed_token).await);
let user = assert_ok!(User::async_find(&mut conn, api_token.user_id).await);
let user = assert_ok!(User::find(&mut conn, api_token.user_id).await);

assert_eq!(user.gh_login, "bar");
assert_eq!(user.gh_access_token, "bar_token");
Expand Down
2 changes: 1 addition & 1 deletion src/worker/jobs/expiry_notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async fn handle_expiring_token(
emails: &Emails,
) -> Result<(), anyhow::Error> {
debug!("Looking up user {} for token {}…", token.user_id, token.id);
let user = User::async_find(conn, token.user_id).await?;
let user = User::find(conn, token.user_id).await?;

debug!("Looking up email address for user {}…", user.id);
let recipient = user.async_email(conn).await?;
Expand Down