fix audit logs

This commit is contained in:
Ruben Fiszel
2023-12-21 01:56:53 +01:00
parent 9694f01752
commit ebff484347
2 changed files with 13 additions and 7 deletions
+2 -2
View File
@@ -25,10 +25,10 @@ pub fn workspaced_service() -> Router {
async fn get_audit(
authed: ApiAuthed,
Extension(user_db): Extension<UserDB>,
Path(id): Path<i32>,
Path((w_id, id)): Path<(String, i32)>,
) -> JsonResult<AuditLog> {
let tx = user_db.begin(&authed).await?;
let audit = windmill_audit::get_audit(tx, id).await?;
let audit = windmill_audit::get_audit(tx, id, &w_id).await?;
Ok(Json(audit))
}
async fn list_audit(
+11 -5
View File
@@ -152,11 +152,17 @@ pub async fn list_audit(
Ok(rows)
}
pub async fn get_audit(mut tx: Transaction<'_, sqlx::Postgres>, id: i32) -> Result<AuditLog> {
let audit_o = sqlx::query_as::<_, AuditLog>("SELECT * FROM audit WHERE id = $1")
.bind(id)
.fetch_optional(&mut *tx)
.await?;
pub async fn get_audit(
mut tx: Transaction<'_, sqlx::Postgres>,
id: i32,
w_id: &str,
) -> Result<AuditLog> {
let audit_o =
sqlx::query_as::<_, AuditLog>("SELECT * FROM audit WHERE id = $1 AND workspace_id = $2")
.bind(id)
.bind(w_id)
.fetch_optional(&mut *tx)
.await?;
tx.commit().await?;
let audit = windmill_common::utils::not_found_if_none(audit_o, "AuditLog", &id.to_string())?;
Ok(audit)