More scoping by user ID at DB level.

This commit is contained in:
2026-10-12 11:20:41 +02:00
parent 793f71e32e
commit b40d686ef9
18 changed files with 235 additions and 188 deletions
+11 -17
View File
@@ -37,20 +37,22 @@ async fn list_account_members(
Path(account_id): Path<Uuid>,
Query(query): Query<QueryParams>,
) -> Result<Json<Vec<AccountMemberResponse>>, AppError> {
let user_id = auth.user_id();
let query = repository::account_members::Query {
account_id,
limit: Some(query.limit.unwrap_or(20)),
offset: query.offset,
};
let mut tx = pool.begin().await.map_err(RepositoryError::from)?;
ensure_account_access(&mut tx, auth.user_id(), account_id).await?;
let members = repository::account_members::list(&mut *tx, auth.user_id(), query)
repository::accounts::get_by_id(&pool, user_id, account_id)
.await?
.map(|_| ())
.ok_or(AppError::NotFound)?;
let members = repository::account_members::list(&pool, user_id, account_id, query)
.await?
.into_iter()
.map(AccountMemberResponse::from)
.collect();
tx.commit().await.map_err(RepositoryError::from)?;
Ok(Json(members))
}
@@ -103,14 +105,16 @@ async fn delete_account_member(
let user_id = auth.user_id();
let mut tx = pool.begin().await.map_err(RepositoryError::from)?;
repository::accounts::get_by_id_locking(&mut *tx, user_id, account_id)
.await?
.ok_or(AppError::NotFound)?;
let members = repository::account_members::list(
&mut *tx,
user_id,
account_id,
repository::account_members::Query {
account_id,
limit: Some(2),
offset: None,
},
@@ -123,20 +127,10 @@ async fn delete_account_member(
}
let deleted =
repository::account_members::delete_by_id(&mut *tx, user_id, account_id, member_id).await?;
tx.commit().await.map_err(RepositoryError::from)?;
deleted.ok_or(AppError::NotFound)?;
Ok(StatusCode::NO_CONTENT)
}
async fn ensure_account_access(
connection: &mut sqlx::PgConnection,
user_id: Uuid,
account_id: Uuid,
) -> Result<(), AppError> {
repository::accounts::get_by_id(&mut *connection, user_id, account_id)
.await?
.map(|_| ())
.ok_or(AppError::NotFound)
}