From c0687135727734a6267fd084421c70b91dce6cac Mon Sep 17 00:00:00 2001 From: philipp Date: Sat, 16 Mar 2024 20:42:41 +0100 Subject: [PATCH] add more logs --- src/tera/admin/mail.rs | 12 +++++++++--- src/tera/admin/user.rs | 23 ++++++++++++++++++----- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/tera/admin/mail.rs b/src/tera/admin/mail.rs index d1a6263..2afcd3a 100644 --- a/src/tera/admin/mail.rs +++ b/src/tera/admin/mail.rs @@ -6,6 +6,7 @@ use rocket::{post, FromForm}; use rocket_dyn_templates::{tera::Context, Template}; use sqlx::SqlitePool; +use crate::model::log::Log; use crate::model::mail::Mail; use crate::model::role::Role; use crate::model::user::AdminUser; @@ -34,7 +35,8 @@ async fn index( } #[get("/mail/fee")] -async fn fee(db: &State, _admin: AdminUser, config: &State) -> &'static str { +async fn fee(db: &State, admin: AdminUser, config: &State) -> &'static str { + Log::create(db, format!("{admin:?} trying to send fee")).await; Mail::fees(db, config.smtp_pw.clone()).await; "SUCC" } @@ -42,9 +44,10 @@ async fn fee(db: &State, _admin: AdminUser, config: &State) #[get("/mail/fee-final")] async fn fee_final( db: &State, - _admin: AdminUser, + admin: AdminUser, config: &State, ) -> &'static str { + Log::create(db, format!("{admin:?} trying to send fee_final")).await; Mail::fees_final(db, config.smtp_pw.clone()).await; "SUCC" } @@ -62,12 +65,15 @@ async fn update( db: &State, data: Form>, config: &State, - _admin: AdminUser, + admin: AdminUser, ) -> Flash { let d = data.into_inner(); + Log::create(db, format!("{admin:?} trying to send this mail: {d:?}")).await; if Mail::send(db, d, config.smtp_pw.clone()).await { + Log::create(db, "Mail successfully sent".into()).await; Flash::success(Redirect::to("/admin/mail"), "Mail versendet") } else { + Log::create(db, "Error sending the mail".into()).await; Flash::error(Redirect::to("/admin/mail"), "Fehler") } } diff --git a/src/tera/admin/user.rs b/src/tera/admin/user.rs index 82eb4e3..d505296 100644 --- a/src/tera/admin/user.rs +++ b/src/tera/admin/user.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use crate::model::{ family::Family, + log::Log, logbook::Logbook, role::Role, user::{AdminUser, User, UserWithRoles, VorstandUser}, @@ -163,10 +164,15 @@ async fn scheckbuch( #[get("/user/fees/paid?")] async fn fees_paid( db: &State, - _admin: AdminUser, + admin: AdminUser, 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(); @@ -204,8 +210,9 @@ async fn resetpw(db: &State, _admin: AdminUser, user: i32) -> Flash< } #[get("/user//delete")] -async fn delete(db: &State, _admin: AdminUser, user: i32) -> Flash { +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; match user { Some(user) => { user.delete(db).await; @@ -239,9 +246,14 @@ pub struct UserEditForm { async fn update( db: &State, data: Form, - _admin: AdminUser, + admin: AdminUser, ) -> Flash { let user = User::find_by_id(db, data.id).await; + Log::create( + db, + format!("{admin:?} updated user from {user:?} to {data:?}"), + ) + .await; let Some(user) = user else { return Flash::error( Redirect::to("/admin/user"), @@ -254,7 +266,7 @@ async fn update( Flash::success(Redirect::to("/admin/user"), "Successfully updated user") } -#[derive(FromForm)] +#[derive(FromForm, Debug)] struct UserAddForm<'r> { name: &'r str, } @@ -263,8 +275,9 @@ struct UserAddForm<'r> { async fn create( db: &State, data: Form>, - _admin: AdminUser, + admin: AdminUser, ) -> Flash { + Log::create(db, format!("{admin:?} created new user: {data:?}")).await; if User::create(db, data.name).await { Flash::success(Redirect::to("/admin/user"), "Successfully created user") } else {