steering-user #778

Merged
philipp merged 3 commits from steering-user into main 2024-10-25 20:14:07 +02:00
7 changed files with 46 additions and 21 deletions
Showing only changes of commit 779e1bbfb9 - Show all commits

View File

@ -119,7 +119,7 @@ impl Boat {
return true;
}
user.has_role(db, "cox").await
user.allowed_to_steer(db).await
}
pub async fn shipmaster_allowed_tx(
@ -135,7 +135,7 @@ impl Boat {
return true;
}
user.has_role_tx(db, "cox").await
user.allowed_to_steer_tx(db).await
}
pub async fn is_locked(&self, db: &SqlitePool) -> bool {
@ -260,7 +260,7 @@ ORDER BY
if user.has_role(db, "admin").await {
return Self::all(db).await;
}
let mut boats = if user.has_role(db, "cox").await {
let mut boats = if user.allowed_to_steer(db).await {
sqlx::query_as!(
Boat,
"

View File

@ -136,8 +136,7 @@ ORDER BY created_at DESC
.map_err(|e| e.to_string())?;
if !was_unusable_before && boat.is_locked(db).await {
let cox = Role::find_by_name(db, "cox").await.unwrap();
Notification::create_for_role(db, &cox, &format!("Liebe Steuerberechtigte, bitte beachten, dass {} bis auf weiteres aufgrund von Reparaturarbeiten gesperrt ist.", boat.name), "Boot gesperrt", None, None).await;
Notification::create_for_steering_people(db, &format!("Liebe Steuerberechtigte, bitte beachten, dass {} bis auf weiteres aufgrund von Reparaturarbeiten gesperrt ist.", boat.name), "Boot gesperrt", None, None).await;
}
let technicals =

View File

@ -89,6 +89,32 @@ impl Notification {
tx.commit().await.unwrap();
}
pub async fn create_for_steering_people_tx(
db: &mut Transaction<'_, Sqlite>,
message: &str,
category: &str,
link: Option<&str>,
action_after_reading: Option<&str>,
) {
let cox = Role::find_by_name_tx(db, "cox").await.unwrap();
Self::create_for_role_tx(db, &cox, message, category, link, action_after_reading).await;
let bootsf = Role::find_by_name_tx(db, "Bootsführer").await.unwrap();
Self::create_for_role_tx(db, &bootsf, message, category, link, action_after_reading).await;
}
pub async fn create_for_steering_people(
db: &SqlitePool,
message: &str,
category: &str,
link: Option<&str>,
action_after_reading: Option<&str>,
) {
let cox = Role::find_by_name(db, "cox").await.unwrap();
Self::create_for_role(db, &cox, message, category, link, action_after_reading).await;
let bootsf = Role::find_by_name(db, "Bootsführer").await.unwrap();
Self::create_for_role(db, &bootsf, message, category, link, action_after_reading).await;
}
pub async fn for_user(db: &SqlitePool, user: &User) -> Vec<Self> {
let rows = sqlx::query!(
"

View File

@ -146,7 +146,7 @@ WHERE day = ? AND planned_starting_time = ?
// User is a guest, no need to bother.
continue;
};
if !user.has_role(db, "cox").await {
if !user.allowed_to_steer(db).await {
// User is no cox, no need to bother
continue;
}

View File

@ -57,8 +57,8 @@ pub struct UserWithDetails {
impl UserWithDetails {
pub async fn from_user(user: User, db: &SqlitePool) -> Self {
let allowed_to_steer =
user.has_role(db, "cox").await || user.has_role(db, "Bootsführer").await;
let allowed_to_steer = user.allowed_to_steer(db).await;
Self {
on_water: user.on_water(db).await,
roles: user.roles(db).await,
@ -140,6 +140,14 @@ impl Fee {
}
impl User {
pub async fn allowed_to_steer(&self, db: &SqlitePool) -> bool {
self.has_role(db, "cox").await || self.has_role(db, "Bootsführer").await
}
pub async fn allowed_to_steer_tx(&self, db: &mut Transaction<'_, Sqlite>) -> bool {
self.has_role_tx(db, "cox").await || self.has_role_tx(db, "Bootsführer").await
}
pub async fn send_welcome_email(&self, db: &SqlitePool, smtp_pw: &str) -> Result<(), String> {
let Some(mail) = &self.mail else {
return Err(format!(
@ -239,10 +247,8 @@ ASKÖ Ruderverein Donau Linz", self.name, SCHECKBUCH/100),
).await?;
// 2. Notify all coxes
let coxes = Role::find_by_name(db, "cox").await.unwrap();
Notification::create_for_role(
Notification::create_for_steering_people(
db,
&coxes,
&format!(
"Liebe Steuerberechtigte, {} hat 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
@ -319,10 +325,8 @@ ASKÖ Ruderverein Donau Linz", self.name),
).await?;
// 2. Notify all coxes
let coxes = Role::find_by_name(db, "cox").await.unwrap();
Notification::create_for_role(
Notification::create_for_steering_people(
db,
&coxes,
&format!(
"Liebe Steuerberechtigte, seit {} gibt es ein neues Mitglied: {}",
self.member_since_date.clone().unwrap(),
@ -979,7 +983,7 @@ ORDER BY last_access DESC
}
pub(crate) async fn amount_days_to_show(&self, db: &SqlitePool) -> i64 {
if self.has_role(db, "cox").await {
if self.allowed_to_steer(db).await {
let end_of_year = NaiveDate::from_ymd_opt(Local::now().year(), 12, 31).unwrap(); //Ok,
//december
//has 31
@ -1031,10 +1035,8 @@ ORDER BY last_access DESC
if let Some(mail) = &self.mail {
let _ = self.send_end_mail_scheckbuch(db, mail, smtp_pw).await;
}
let coxes = Role::find_by_name_tx(db, "cox").await.unwrap();
Notification::create_for_role_tx(
Notification::create_for_steering_people_tx(
db,
&coxes,
&format!(
"Liebe Steuerberechtigte, {} hat alle Ausfahrten des Scheckbuchs absolviert. Hoffentlich können wir uns bald über ein neues Mitglied freuen :-)",
self.name

View File

@ -93,8 +93,6 @@ async fn steering(db: &State<SqlitePool>, user: User, flash: Option<FlashMessage
User::all_with_role(db, &Role::find_by_name(db, "Bootsführer").await.unwrap()).await;
let mut coxes = User::all_with_role(db, &Role::find_by_name(db, "cox").await.unwrap()).await;
coxes.retain(|user| !bootskundige.contains(user)); // Remove bootskundige from coxes list
coxes.retain(|user| user.name != "Externe Steuerperson");
context.insert("coxes", &coxes);

View File

@ -29,7 +29,7 @@ async fn index(
let mut context = Context::new();
if user.has_role(db, "cox").await || user.has_role(db, "manage_events").await {
if user.allowed_to_steer(db).await || user.has_role(db, "manage_events").await {
let triptypes = TripType::all(db).await;
context.insert("trip_types", &triptypes);
}