make scheckbuch user behave as previously, but in own file
This commit is contained in:
parent
876451fc02
commit
7604678d4a
@ -552,7 +552,7 @@ mod test {
|
|||||||
|
|
||||||
let trip_details = TripDetails::find_by_id(&pool, 1).await.unwrap();
|
let trip_details = TripDetails::find_by_id(&pool, 1).await.unwrap();
|
||||||
|
|
||||||
let admin = EventUser::new(&pool, User::find_by_id(&pool, 1).await.unwrap())
|
let admin = EventUser::new(&pool, &User::find_by_id(&pool, 1).await.unwrap())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Event::create(&pool, &admin, "new-event".into(), 2, false, &trip_details).await;
|
Event::create(&pool, &admin, "new-event".into(), 2, false, &trip_details).await;
|
||||||
|
@ -256,7 +256,7 @@ mod test {
|
|||||||
let trip_details = TripDetails::find_by_id(&pool, tripdetails_id)
|
let trip_details = TripDetails::find_by_id(&pool, tripdetails_id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let user = EventUser::new(&pool, User::find_by_id(&pool, 1).await.unwrap())
|
let user = EventUser::new(&pool, &User::find_by_id(&pool, 1).await.unwrap())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Event::create(&pool, &user, "new-event".into(), 2, false, &trip_details).await;
|
Event::create(&pool, &user, "new-event".into(), 2, false, &trip_details).await;
|
||||||
@ -269,7 +269,7 @@ mod test {
|
|||||||
UserTrip::create(&pool, &rower, &trip_details, None)
|
UserTrip::create(&pool, &rower, &trip_details, None)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let cox = SteeringUser::new(&pool, User::find_by_name(&pool, "cox").await.unwrap())
|
let cox = SteeringUser::new(&pool, &User::find_by_name(&pool, "cox").await.unwrap())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Trip::new_join(&pool, &cox, &event).await.unwrap();
|
Trip::new_join(&pool, &cox, &event).await.unwrap();
|
||||||
@ -284,7 +284,7 @@ mod test {
|
|||||||
is_locked: event.is_locked,
|
is_locked: event.is_locked,
|
||||||
trip_type_id: None,
|
trip_type_id: None,
|
||||||
};
|
};
|
||||||
event.update(&pool, &cancel_update).await;
|
event.update(&pool, &user, &cancel_update).await;
|
||||||
|
|
||||||
// Rower received notification
|
// Rower received notification
|
||||||
let notifications = Notification::for_user(&pool, &rower).await;
|
let notifications = Notification::for_user(&pool, &rower).await;
|
||||||
@ -314,12 +314,12 @@ mod test {
|
|||||||
is_locked: event.is_locked,
|
is_locked: event.is_locked,
|
||||||
trip_type_id: None,
|
trip_type_id: None,
|
||||||
};
|
};
|
||||||
event.update(&pool, &update).await;
|
event.update(&pool, &user, &update).await;
|
||||||
assert!(Notification::for_user(&pool, &rower).await.is_empty());
|
assert!(Notification::for_user(&pool, &rower).await.is_empty());
|
||||||
assert!(Notification::for_user(&pool, &cox.user).await.is_empty());
|
assert!(Notification::for_user(&pool, &cox.user).await.is_empty());
|
||||||
|
|
||||||
// Cancel event again
|
// Cancel event again
|
||||||
event.update(&pool, &cancel_update).await;
|
event.update(&pool, &user, &cancel_update).await;
|
||||||
|
|
||||||
// Rower is removed if notification is accepted
|
// Rower is removed if notification is accepted
|
||||||
assert!(event.is_rower_registered(&pool, &rower).await);
|
assert!(event.is_rower_registered(&pool, &rower).await);
|
||||||
|
@ -532,7 +532,7 @@ mod test {
|
|||||||
|
|
||||||
let cox = SteeringUser::new(
|
let cox = SteeringUser::new(
|
||||||
&pool,
|
&pool,
|
||||||
User::find_by_name(&pool, "cox".into()).await.unwrap(),
|
&User::find_by_name(&pool, "cox".into()).await.unwrap(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -549,7 +549,7 @@ mod test {
|
|||||||
let pool = testdb!();
|
let pool = testdb!();
|
||||||
let cox = SteeringUser::new(
|
let cox = SteeringUser::new(
|
||||||
&pool,
|
&pool,
|
||||||
User::find_by_name(&pool, "cox".into()).await.unwrap(),
|
&User::find_by_name(&pool, "cox".into()).await.unwrap(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -558,7 +558,7 @@ mod test {
|
|||||||
|
|
||||||
let cox2 = SteeringUser::new(
|
let cox2 = SteeringUser::new(
|
||||||
&pool,
|
&pool,
|
||||||
User::find_by_name(&pool, "cox2".into()).await.unwrap(),
|
&User::find_by_name(&pool, "cox2".into()).await.unwrap(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -587,7 +587,7 @@ mod test {
|
|||||||
|
|
||||||
let cox = SteeringUser::new(
|
let cox = SteeringUser::new(
|
||||||
&pool,
|
&pool,
|
||||||
User::find_by_name(&pool, "cox2".into()).await.unwrap(),
|
&User::find_by_name(&pool, "cox2".into()).await.unwrap(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -603,7 +603,7 @@ mod test {
|
|||||||
|
|
||||||
let cox = SteeringUser::new(
|
let cox = SteeringUser::new(
|
||||||
&pool,
|
&pool,
|
||||||
User::find_by_name(&pool, "cox2".into()).await.unwrap(),
|
&User::find_by_name(&pool, "cox2".into()).await.unwrap(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -620,7 +620,7 @@ mod test {
|
|||||||
|
|
||||||
let cox = SteeringUser::new(
|
let cox = SteeringUser::new(
|
||||||
&pool,
|
&pool,
|
||||||
User::find_by_name(&pool, "cox".into()).await.unwrap(),
|
&User::find_by_name(&pool, "cox".into()).await.unwrap(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -648,7 +648,7 @@ mod test {
|
|||||||
|
|
||||||
let cox = SteeringUser::new(
|
let cox = SteeringUser::new(
|
||||||
&pool,
|
&pool,
|
||||||
User::find_by_name(&pool, "cox".into()).await.unwrap(),
|
&User::find_by_name(&pool, "cox".into()).await.unwrap(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -676,7 +676,7 @@ mod test {
|
|||||||
|
|
||||||
let cox = SteeringUser::new(
|
let cox = SteeringUser::new(
|
||||||
&pool,
|
&pool,
|
||||||
User::find_by_name(&pool, "cox2".into()).await.unwrap(),
|
&User::find_by_name(&pool, "cox2".into()).await.unwrap(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -701,7 +701,7 @@ mod test {
|
|||||||
|
|
||||||
let cox = SteeringUser::new(
|
let cox = SteeringUser::new(
|
||||||
&pool,
|
&pool,
|
||||||
User::find_by_name(&pool, "cox".into()).await.unwrap(),
|
&User::find_by_name(&pool, "cox".into()).await.unwrap(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -724,7 +724,7 @@ mod test {
|
|||||||
|
|
||||||
let cox = SteeringUser::new(
|
let cox = SteeringUser::new(
|
||||||
&pool,
|
&pool,
|
||||||
User::find_by_name(&pool, "cox".into()).await.unwrap(),
|
&User::find_by_name(&pool, "cox".into()).await.unwrap(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -742,7 +742,7 @@ mod test {
|
|||||||
|
|
||||||
let cox = SteeringUser::new(
|
let cox = SteeringUser::new(
|
||||||
&pool,
|
&pool,
|
||||||
User::find_by_name(&pool, "cox2".into()).await.unwrap(),
|
&User::find_by_name(&pool, "cox2".into()).await.unwrap(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -764,7 +764,7 @@ mod test {
|
|||||||
|
|
||||||
let cox = SteeringUser::new(
|
let cox = SteeringUser::new(
|
||||||
&pool,
|
&pool,
|
||||||
User::find_by_name(&pool, "cox".into()).await.unwrap(),
|
&User::find_by_name(&pool, "cox".into()).await.unwrap(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -27,6 +27,7 @@ use super::{
|
|||||||
Day,
|
Day,
|
||||||
};
|
};
|
||||||
use crate::{tera::admin::user::UserEditForm, AMOUNT_DAYS_TO_SHOW_TRIPS_AHEAD};
|
use crate::{tera::admin::user::UserEditForm, AMOUNT_DAYS_TO_SHOW_TRIPS_AHEAD};
|
||||||
|
use scheckbuch::ScheckbuchUser;
|
||||||
|
|
||||||
mod fee;
|
mod fee;
|
||||||
mod scheckbuch;
|
mod scheckbuch;
|
||||||
@ -112,6 +113,8 @@ impl User {
|
|||||||
.await?;
|
.await?;
|
||||||
} else if self.has_role(db, "schnupperant").await {
|
} else if self.has_role(db, "schnupperant").await {
|
||||||
self.send_welcome_mail_schnupper(db, mail, smtp_pw).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?;
|
||||||
} else {
|
} else {
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
"Could not send welcome mail, because user {} is not in Donau Linz or scheckbuch or schnupperant group",
|
"Could not send welcome mail, because user {} is not in Donau Linz or scheckbuch or schnupperant group",
|
||||||
@ -259,7 +262,7 @@ ASKÖ Ruderverein Donau Linz", self.name),
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn allowed_to_update_always_show_trip(&self, db: &SqlitePool) -> bool {
|
pub async fn allowed_to_update_always_show_trip(&self, db: &SqlitePool) -> bool {
|
||||||
AllowedToUpdateTripToAlwaysBeShownUser::new(db, self.clone())
|
AllowedToUpdateTripToAlwaysBeShownUser::new(db, &self)
|
||||||
.await
|
.await
|
||||||
.is_some()
|
.is_some()
|
||||||
}
|
}
|
||||||
@ -989,9 +992,9 @@ macro_rules! special_user {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl $name {
|
impl $name {
|
||||||
pub async fn new(db: &SqlitePool, user: User) -> Option<Self> {
|
pub async fn new(db: &SqlitePool, user: &User) -> Option<Self> {
|
||||||
if special_user!(@check_roles user, db, $($role)*) {
|
if special_user!(@check_roles user, db, $($role)*) {
|
||||||
Some($name { user })
|
Some($name { user: user.clone() })
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -30,16 +30,23 @@ impl ScheckbuchUser {
|
|||||||
user.add_role(db, &scheckbuch).await.unwrap();
|
user.add_role(db, &scheckbuch).await.unwrap();
|
||||||
|
|
||||||
// TODO: remove all other `membership_type` roles
|
// TODO: remove all other `membership_type` roles
|
||||||
|
let new_user = Self::new(db, &user).await.unwrap();
|
||||||
|
|
||||||
let new_user = Self::new(db, user).await.unwrap();
|
new_user.notify(db, mail, smtp_pw).await
|
||||||
|
}
|
||||||
|
|
||||||
new_user
|
pub(crate) async fn notify(
|
||||||
.send_welcome_mail_to_user(db, mail, smtp_pw)
|
&self,
|
||||||
.await?;
|
db: &SqlitePool,
|
||||||
new_user.notify_coxes_about_new_scheckbuch(db).await;
|
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;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn send_welcome_mail_to_user(
|
async fn send_welcome_mail_to_user(
|
||||||
&self,
|
&self,
|
||||||
db: &SqlitePool,
|
db: &SqlitePool,
|
||||||
|
@ -197,7 +197,7 @@ impl UserTrip {
|
|||||||
let mut add_info = "";
|
let mut add_info = "";
|
||||||
if let Some(trip) = &trip_to_delete {
|
if let Some(trip) = &trip_to_delete {
|
||||||
let cox = User::find_by_id(db, trip.cox_id as i32).await.unwrap();
|
let cox = User::find_by_id(db, trip.cox_id as i32).await.unwrap();
|
||||||
trip.delete(db, &SteeringUser::new(db, cox).await.unwrap())
|
trip.delete(db, &SteeringUser::new(db, &cox).await.unwrap())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
add_info = " Das war die letzte angemeldete Person. Nachdem nun alle Bescheid wissen, wird die Ausfahrt ab sofort nicht mehr angezeigt.";
|
add_info = " Das war die letzte angemeldete Person. Nachdem nun alle Bescheid wissen, wird die Ausfahrt ab sofort nicht mehr angezeigt.";
|
||||||
@ -355,7 +355,7 @@ mod test {
|
|||||||
|
|
||||||
let cox = SteeringUser::new(
|
let cox = SteeringUser::new(
|
||||||
&pool,
|
&pool,
|
||||||
User::find_by_name(&pool, "cox".into()).await.unwrap(),
|
&User::find_by_name(&pool, "cox".into()).await.unwrap(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -60,7 +60,7 @@ async fn index(
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let user: User = user.into_inner();
|
let user: User = user.into_inner();
|
||||||
let allowed_to_edit = ManageUserUser::new(db, user.clone()).await.is_some();
|
let allowed_to_edit = ManageUserUser::new(db, &user).await.is_some();
|
||||||
|
|
||||||
let users: Vec<UserWithRolesAndMembershipPdf> = join_all(user_futures).await;
|
let users: Vec<UserWithRolesAndMembershipPdf> = join_all(user_futures).await;
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ async fn index_admin(
|
|||||||
let users: Vec<UserWithRolesAndMembershipPdf> = join_all(user_futures).await;
|
let users: Vec<UserWithRolesAndMembershipPdf> = join_all(user_futures).await;
|
||||||
|
|
||||||
let user: User = user.user;
|
let user: User = user.user;
|
||||||
let allowed_to_edit = ManageUserUser::new(db, user.clone()).await.is_some();
|
let allowed_to_edit = ManageUserUser::new(db, &user).await.is_some();
|
||||||
|
|
||||||
let roles = Role::all(db).await;
|
let roles = Role::all(db).await;
|
||||||
let families = Family::all_with_members(db).await;
|
let families = Family::all_with_members(db).await;
|
||||||
|
@ -296,7 +296,7 @@ async fn create_kiosk(
|
|||||||
create_logbook(
|
create_logbook(
|
||||||
db,
|
db,
|
||||||
data,
|
data,
|
||||||
&DonauLinzUser::new(db, creator).await.unwrap(),
|
&DonauLinzUser::new(db, &creator).await.unwrap(),
|
||||||
&config.smtp_pw,
|
&config.smtp_pw,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@ -390,7 +390,7 @@ async fn home_kiosk(
|
|||||||
logbook_id,
|
logbook_id,
|
||||||
&DonauLinzUser::new(
|
&DonauLinzUser::new(
|
||||||
db,
|
db,
|
||||||
User::find_by_id(db, logbook.shipmaster as i32)
|
&User::find_by_id(db, logbook.shipmaster as i32)
|
||||||
.await
|
.await
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user