From 39a8a1563c8592b0c3cbf7beef811007f27dec01 Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 19 Mar 2024 09:59:46 +0100 Subject: [PATCH] bit nicer logs --- src/tera/admin/user.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/tera/admin/user.rs b/src/tera/admin/user.rs index d505296..7a55d85 100644 --- a/src/tera/admin/user.rs +++ b/src/tera/admin/user.rs @@ -168,19 +168,24 @@ async fn fees_paid( user_ids: Vec, referer: Referer, ) -> Flash { - Log::create( - db, - format!("{admin:?} set fees paid for user_ids: {user_ids:?}"), - ) - .await; let mut res = String::new(); for user_id in user_ids { let user = User::find_by_id(db, user_id).await.unwrap(); res.push_str(&format!("{} + ", user.name)); if user.has_role(db, "paid").await { + Log::create( + db, + format!("{} set fees NOT paid for '{}'", admin.user.name, user.name), + ) + .await; user.remove_role(db, &Role::find_by_name(db, "paid").await.unwrap()) .await; } else { + Log::create( + db, + format!("{} set fees paid for '{}'", admin.user.name, user.name), + ) + .await; user.add_role(db, &Role::find_by_name(db, "paid").await.unwrap()) .await; } @@ -212,7 +217,7 @@ async fn resetpw(db: &State, _admin: AdminUser, user: i32) -> Flash< #[get("/user//delete")] async fn delete(db: &State, admin: AdminUser, user: i32) -> Flash { let user = User::find_by_id(db, user).await; - Log::create(db, format!("{admin:?} deleted user: {user:?}")).await; + Log::create(db, format!("{} deleted user: {user:?}", admin.user.name)).await; match user { Some(user) => { user.delete(db).await; @@ -251,7 +256,7 @@ async fn update( let user = User::find_by_id(db, data.id).await; Log::create( db, - format!("{admin:?} updated user from {user:?} to {data:?}"), + format!("{} updated user from {user:?} to {data:?}", admin.user.name), ) .await; let Some(user) = user else { @@ -277,8 +282,12 @@ async fn create( data: Form>, admin: AdminUser, ) -> Flash { - Log::create(db, format!("{admin:?} created new user: {data:?}")).await; if User::create(db, data.name).await { + Log::create( + db, + format!("{} created new user: {data:?}", admin.user.name), + ) + .await; Flash::success(Redirect::to("/admin/user"), "Successfully created user") } else { Flash::error(