allow to change from schnupperant to scheckbuch
This commit is contained in:
		| @@ -124,7 +124,7 @@ impl User { | ||||
|         if self.has_role(db, "schnupperant").await { | ||||
|             self.send_welcome_mail_schnupper(db, mail, smtp_pw).await?; | ||||
|         } else if let Some(scheckbuch) = ScheckbuchUser::new(db, self).await { | ||||
|             scheckbuch.notify(db, mail, smtp_pw).await?; | ||||
|             scheckbuch.notify(db, smtp_pw).await?; | ||||
|         } else { | ||||
|             return Err(format!( | ||||
|                 "Could not send welcome mail, because user {} is not in Donau Linz or scheckbuch or schnupperant group", | ||||
|   | ||||
| @@ -189,27 +189,26 @@ impl ScheckbuchUser { | ||||
|     } | ||||
|  | ||||
|     // TODO: make private | ||||
|     pub(crate) async fn notify( | ||||
|         &self, | ||||
|         db: &SqlitePool, | ||||
|         mail: &str, | ||||
|         smtp_pw: &str, | ||||
|     ) -> Result<(), String> { | ||||
|         self.send_welcome_mail_to_user(db, mail, smtp_pw).await?; | ||||
|     pub(crate) async fn notify(&self, db: &SqlitePool, smtp_pw: &str) -> Result<(), String> { | ||||
|         self.notify_coxes_about_new_scheckbuch(db).await; | ||||
|         self.send_welcome_mail_to_user(db, smtp_pw).await?; | ||||
|  | ||||
|         Ok(()) | ||||
|     } | ||||
|  | ||||
|     async fn send_welcome_mail_to_user( | ||||
|     pub(crate) async fn send_welcome_mail_to_user( | ||||
|         &self, | ||||
|         db: &SqlitePool, | ||||
|         mail: &str, | ||||
|         smtp_pw: &str, | ||||
|     ) -> Result<(), String> { | ||||
|         let Some(mail) = &self.mail else { | ||||
|             return Err( | ||||
|                 "Kann Mail nicht versenden, weil der User keine Mailadresse hinterlegt hat.".into(), | ||||
|             ); | ||||
|         }; | ||||
|         Mail::send_single( | ||||
|             db, | ||||
|             mail, | ||||
|             &mail, | ||||
|             "ASKÖ Ruderverein Donau Linz | Dein Scheckbuch wartet auf Dich", | ||||
|             format!( | ||||
| "Hallo {0}, | ||||
|   | ||||
| @@ -1,5 +1,6 @@ | ||||
| use super::foerdernd::FoerderndUser; | ||||
| use super::regular::RegularUser; | ||||
| use super::scheckbuch::ScheckbuchUser; | ||||
| use super::unterstuetzend::UnterstuetzendUser; | ||||
| use super::{ManageUserUser, User}; | ||||
| use crate::model::role::Role; | ||||
| @@ -86,6 +87,34 @@ impl SchnupperantUser { | ||||
|         Ok(()) | ||||
|     } | ||||
|  | ||||
|     pub(crate) async fn move_to_scheckbook( | ||||
|         self, | ||||
|         db: &SqlitePool, | ||||
|         changed_by: &ManageUserUser, | ||||
|         smtp_pw: &str, | ||||
|     ) -> Result<(), String> { | ||||
|         let schnupperant = Role::find_by_name(db, "schnupperant").await.unwrap(); | ||||
|         let scheckbook = Role::find_by_name(db, "scheckbuch").await.unwrap(); | ||||
|         self.user.remove_role(db, changed_by, &schnupperant).await?; | ||||
|         self.user.add_role(db, changed_by, &scheckbook).await?; | ||||
|  | ||||
|         let scheckbook = ScheckbuchUser::new(db, &self.user).await.unwrap(); | ||||
|         scheckbook.send_welcome_mail_to_user(db, smtp_pw).await?; | ||||
|  | ||||
|         Notification::create_for_steering_people( | ||||
|             db, | ||||
|             &format!( | ||||
|                 "Liebe Steuerberechtigte, {} hat unseren Schnupperkurs absolviert und nun ein Scheckbuch. Wie immer, freuen wir uns wenn du uns beim A+F Rudern unterstützt oder selber Ausfahrten ausschreibst. Bitte beachte, dass Scheckbuch-Personen nur Ausfahrten sehen, bei denen 'Scheckbuch-Anmeldungen erlauben' ausgewählt wurde.", | ||||
|                 self.name | ||||
|             ), | ||||
|             "Neues Scheckbuch", | ||||
|             None,None | ||||
|         ) | ||||
|         .await; | ||||
|  | ||||
|         Ok(()) | ||||
|     } | ||||
|  | ||||
|     pub(crate) async fn convert_to_unterstuetzend_user( | ||||
|         self, | ||||
|         db: &SqlitePool, | ||||
| @@ -195,8 +224,8 @@ impl SchnupperantUser { | ||||
|         mail: &str, | ||||
|         smtp_pw: &str, | ||||
|     ) -> Result<(), String> { | ||||
|         self.send_welcome_mail_to_user(db, mail, smtp_pw).await?; | ||||
|         self.notify_coxes_about_new_scheckbuch(db).await; | ||||
|         self.send_welcome_mail_to_user(db, mail, smtp_pw).await?; | ||||
|  | ||||
|         Ok(()) | ||||
|     } | ||||
| @@ -226,10 +255,11 @@ ASKÖ Ruderverein Donau Linz", self.name), | ||||
|  | ||||
|     async fn notify_coxes_about_new_scheckbuch(&self, db: &SqlitePool) { | ||||
|         if let Some(role) = Role::find_by_name(db, "schnupper-betreuer").await { | ||||
|             Notification::create_for_steering_people( | ||||
|             Notification::create_for_role( | ||||
|                 db, | ||||
|                 &role, | ||||
|                 &format!( | ||||
|                     "Lieber Schnupperbetreuer, {} hat zum Schnupperkurz angemeldet.", | ||||
|                     "Lieber Schnupperbetreuer, {} hat sich zum Schnupperkurs angemeldet.", | ||||
|                     self.name | ||||
|                 ), | ||||
|                 "Neuer Schnupperant", | ||||
|   | ||||
| @@ -1100,6 +1100,36 @@ async fn change_membertype( | ||||
|     } | ||||
| } | ||||
|  | ||||
| #[get("/user/<id>/schnupperant-to-scheckbuch")] | ||||
| async fn schnupperant_to_scheckbook( | ||||
|     db: &State<SqlitePool>, | ||||
|     admin: ManageUserUser, | ||||
|     config: &State<Config>, | ||||
|     id: i32, | ||||
| ) -> Flash<Redirect> { | ||||
|     let Some(user) = User::find_by_id(db, id).await else { | ||||
|         return Flash::error( | ||||
|             Redirect::to("/admin/user"), | ||||
|             format!("User with ID {} does not exist!", id), | ||||
|         ); | ||||
|     }; | ||||
|  | ||||
|     let Some(user) = SchnupperantUser::new(&db, &user).await else { | ||||
|         return Flash::error( | ||||
|             Redirect::to(format!("/admin/user/{id}")), | ||||
|             format!("User {user} ist kein Schnupperant"), | ||||
|         ); | ||||
|     }; | ||||
|  | ||||
|     match user.move_to_scheckbook(db, &admin, &config.smtp_pw).await { | ||||
|         Ok(_) => Flash::success( | ||||
|             Redirect::to(format!("/admin/user/{}", id)), | ||||
|             "Mitgliedstyp umgewandelt und Infos versendet", | ||||
|         ), | ||||
|         Err(e) => Flash::error(Redirect::to(format!("/admin/user/{}", id)), e), | ||||
|     } | ||||
| } | ||||
|  | ||||
| pub fn routes() -> Vec<Route> { | ||||
|     routes![ | ||||
|         index, | ||||
| @@ -1130,6 +1160,7 @@ pub fn routes() -> Vec<Route> { | ||||
|         // | ||||
|         scheckbook_to_regular, | ||||
|         schnupperant_to_regular, | ||||
|         schnupperant_to_scheckbook, | ||||
|         change_membertype, | ||||
|     ] | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user