membership-pdf-new #284

Merged
philipp merged 45 commits from membership-pdf-new into staging 2024-03-20 21:05:23 +01:00
2 changed files with 27 additions and 8 deletions
Showing only changes of commit 54058b0917 - Show all commits

View File

@ -6,6 +6,7 @@ use rocket::{post, FromForm};
use rocket_dyn_templates::{tera::Context, Template}; use rocket_dyn_templates::{tera::Context, Template};
use sqlx::SqlitePool; use sqlx::SqlitePool;
use crate::model::log::Log;
use crate::model::mail::Mail; use crate::model::mail::Mail;
use crate::model::role::Role; use crate::model::role::Role;
use crate::model::user::AdminUser; use crate::model::user::AdminUser;
@ -34,7 +35,8 @@ async fn index(
} }
#[get("/mail/fee")] #[get("/mail/fee")]
async fn fee(db: &State<SqlitePool>, _admin: AdminUser, config: &State<Config>) -> &'static str { async fn fee(db: &State<SqlitePool>, admin: AdminUser, config: &State<Config>) -> &'static str {
Log::create(db, format!("{admin:?} trying to send fee")).await;
Mail::fees(db, config.smtp_pw.clone()).await; Mail::fees(db, config.smtp_pw.clone()).await;
"SUCC" "SUCC"
} }
@ -42,9 +44,10 @@ async fn fee(db: &State<SqlitePool>, _admin: AdminUser, config: &State<Config>)
#[get("/mail/fee-final")] #[get("/mail/fee-final")]
async fn fee_final( async fn fee_final(
db: &State<SqlitePool>, db: &State<SqlitePool>,
_admin: AdminUser, admin: AdminUser,
config: &State<Config>, config: &State<Config>,
) -> &'static str { ) -> &'static str {
Log::create(db, format!("{admin:?} trying to send fee_final")).await;
Mail::fees_final(db, config.smtp_pw.clone()).await; Mail::fees_final(db, config.smtp_pw.clone()).await;
"SUCC" "SUCC"
} }
@ -62,12 +65,15 @@ async fn update(
db: &State<SqlitePool>, db: &State<SqlitePool>,
data: Form<MailToSend<'_>>, data: Form<MailToSend<'_>>,
config: &State<Config>, config: &State<Config>,
_admin: AdminUser, admin: AdminUser,
) -> Flash<Redirect> { ) -> Flash<Redirect> {
let d = data.into_inner(); 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 { 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") Flash::success(Redirect::to("/admin/mail"), "Mail versendet")
} else { } else {
Log::create(db, "Error sending the mail".into()).await;
Flash::error(Redirect::to("/admin/mail"), "Fehler") Flash::error(Redirect::to("/admin/mail"), "Fehler")
} }
} }

View File

@ -2,6 +2,7 @@ use std::collections::HashMap;
use crate::model::{ use crate::model::{
family::Family, family::Family,
log::Log,
logbook::Logbook, logbook::Logbook,
role::Role, role::Role,
user::{AdminUser, User, UserWithRoles, VorstandUser}, user::{AdminUser, User, UserWithRoles, VorstandUser},
@ -163,10 +164,15 @@ async fn scheckbuch(
#[get("/user/fees/paid?<user_ids>")] #[get("/user/fees/paid?<user_ids>")]
async fn fees_paid( async fn fees_paid(
db: &State<SqlitePool>, db: &State<SqlitePool>,
_admin: AdminUser, admin: AdminUser,
user_ids: Vec<i32>, user_ids: Vec<i32>,
referer: Referer, referer: Referer,
) -> Flash<Redirect> { ) -> Flash<Redirect> {
Log::create(
db,
format!("{admin:?} set fees paid for user_ids: {user_ids:?}"),
)
.await;
let mut res = String::new(); let mut res = String::new();
for user_id in user_ids { for user_id in user_ids {
let user = User::find_by_id(db, user_id).await.unwrap(); let user = User::find_by_id(db, user_id).await.unwrap();
@ -204,8 +210,9 @@ async fn resetpw(db: &State<SqlitePool>, _admin: AdminUser, user: i32) -> Flash<
} }
#[get("/user/<user>/delete")] #[get("/user/<user>/delete")]
async fn delete(db: &State<SqlitePool>, _admin: AdminUser, user: i32) -> Flash<Redirect> { async fn delete(db: &State<SqlitePool>, admin: AdminUser, user: i32) -> Flash<Redirect> {
let user = User::find_by_id(db, user).await; let user = User::find_by_id(db, user).await;
Log::create(db, format!("{admin:?} deleted user: {user:?}")).await;
match user { match user {
Some(user) => { Some(user) => {
user.delete(db).await; user.delete(db).await;
@ -239,9 +246,14 @@ pub struct UserEditForm {
async fn update( async fn update(
db: &State<SqlitePool>, db: &State<SqlitePool>,
data: Form<UserEditForm>, data: Form<UserEditForm>,
_admin: AdminUser, admin: AdminUser,
) -> Flash<Redirect> { ) -> Flash<Redirect> {
let user = User::find_by_id(db, data.id).await; 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 { let Some(user) = user else {
return Flash::error( return Flash::error(
Redirect::to("/admin/user"), Redirect::to("/admin/user"),
@ -254,7 +266,7 @@ async fn update(
Flash::success(Redirect::to("/admin/user"), "Successfully updated user") Flash::success(Redirect::to("/admin/user"), "Successfully updated user")
} }
#[derive(FromForm)] #[derive(FromForm, Debug)]
struct UserAddForm<'r> { struct UserAddForm<'r> {
name: &'r str, name: &'r str,
} }
@ -263,8 +275,9 @@ struct UserAddForm<'r> {
async fn create( async fn create(
db: &State<SqlitePool>, db: &State<SqlitePool>,
data: Form<UserAddForm<'_>>, data: Form<UserAddForm<'_>>,
_admin: AdminUser, admin: AdminUser,
) -> Flash<Redirect> { ) -> Flash<Redirect> {
Log::create(db, format!("{admin:?} created new user: {data:?}")).await;
if User::create(db, data.name).await { if User::create(db, data.name).await {
Flash::success(Redirect::to("/admin/user"), "Successfully created user") Flash::success(Redirect::to("/admin/user"), "Successfully created user")
} else { } else {