membership-pdf-new #284

Merged
philipp merged 45 commits from membership-pdf-new into staging 2024-03-20 21:05:23 +01:00
Showing only changes of commit a1126e0509 - Show all commits

View File

@ -168,19 +168,24 @@ async fn fees_paid(
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();
res.push_str(&format!("{} + ", user.name)); res.push_str(&format!("{} + ", user.name));
if user.has_role(db, "paid").await { 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()) user.remove_role(db, &Role::find_by_name(db, "paid").await.unwrap())
.await; .await;
} else { } 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()) user.add_role(db, &Role::find_by_name(db, "paid").await.unwrap())
.await; .await;
} }
@ -212,7 +217,7 @@ 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; Log::create(db, format!("{} deleted user: {user:?}", admin.user.name)).await;
match user { match user {
Some(user) => { Some(user) => {
user.delete(db).await; user.delete(db).await;
@ -251,7 +256,7 @@ async fn update(
let user = User::find_by_id(db, data.id).await; let user = User::find_by_id(db, data.id).await;
Log::create( Log::create(
db, db,
format!("{admin:?} updated user from {user:?} to {data:?}"), format!("{} updated user from {user:?} to {data:?}", admin.user.name),
) )
.await; .await;
let Some(user) = user else { let Some(user) = user else {
@ -277,8 +282,12 @@ async fn create(
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 {
Log::create(
db,
format!("{} created new user: {data:?}", admin.user.name),
)
.await;
Flash::success(Redirect::to("/admin/user"), "Successfully created user") Flash::success(Redirect::to("/admin/user"), "Successfully created user")
} else { } else {
Flash::error( Flash::error(