diff --git a/src/tera/admin/user.rs b/src/tera/admin/user.rs index 2217cf6..3c5db86 100644 --- a/src/tera/admin/user.rs +++ b/src/tera/admin/user.rs @@ -7,8 +7,8 @@ use crate::{ logbook::Logbook, role::Role, user::{ - AdminUser, AllowedToEditPaymentStatusUser, User, UserWithDetails, - UserWithMembershipPdf, UserWithRolesAndMembershipPdf, VorstandUser, + AdminUser, AllowedToEditPaymentStatusUser, SchnupperBetreuerUser, User, + UserWithDetails, UserWithMembershipPdf, UserWithRolesAndMembershipPdf, VorstandUser, }, }, tera::Config, @@ -408,6 +408,48 @@ async fn create_scheckbuch( Flash::success(Redirect::to("/admin/user/scheckbuch"), &format!("Scheckbuch erfolgreich erstellt. Eine E-Mail in der alles erklärt wird, wurde an {mail} verschickt.")) } +#[get("/user/move/schnupperant//to/scheckbuch")] +async fn schnupper_to_scheckbuch( + db: &State, + id: i32, + admin: SchnupperBetreuerUser, + config: &State, +) -> Flash { + let Some(user) = User::find_by_id(db, id).await else { + return Flash::error( + Redirect::to("/admin/schnupper"), + format!("user id not found"), + ); + }; + + if !user.has_role(db, "schnupperant").await { + return Flash::error( + Redirect::to("/admin/schnupper"), + format!("kein schnupperant..."), + ); + } + + let schnupperant = Role::find_by_name(db, "schnupperant").await.unwrap(); + let paid = Role::find_by_name(db, "paid").await.unwrap(); + user.remove_role(db, &schnupperant).await; + user.remove_role(db, &paid).await; + + let scheckbuch = Role::find_by_name(db, "scheckbuch").await.unwrap(); + user.add_role(db, &scheckbuch).await; + + user.send_welcome_email(db, &config.smtp_pw).await.unwrap(); + + Log::create( + db, + format!( + "{} created new scheckbuch (from schnupperant): {}", + admin.name, user.name + ), + ) + .await; + Flash::success(Redirect::to("/admin/schnupper"), &format!("Scheckbuch erfolgreich erstellt. Eine E-Mail in der alles erklärt wird, wurde an {} verschickt.", user.mail.unwrap())) +} + pub fn routes() -> Vec { routes![ index, @@ -416,6 +458,7 @@ pub fn routes() -> Vec { update, create, create_scheckbuch, + schnupper_to_scheckbuch, delete, fees, fees_paid, diff --git a/templates/admin/schnupper/index.html.tera b/templates/admin/schnupper/index.html.tera index 1c3ddc1..2fd0437 100644 --- a/templates/admin/schnupper/index.html.tera +++ b/templates/admin/schnupper/index.html.tera @@ -12,7 +12,8 @@ {% for user in schnupperanten %}
  • - {{ user.name }} ({{ user.mail }} | {{ user.notes }}) + {{ user.name }} ({{ user.mail }} {% if user.notes %} | {{ user.notes }}{% endif %}) + Zu Scheckbuch umwandeln
  • {% endfor %}