From a31bacb3e12932a7e53fcc210f307f2642695da6 Mon Sep 17 00:00:00 2001 From: philipp Date: Mon, 19 Aug 2024 13:39:22 +0200 Subject: [PATCH 1/4] create notification if a new event with 'always_show' is entered --- src/model/event.rs | 18 +++++++++++++++++- templates/planned.html.tera | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/model/event.rs b/src/model/event.rs index e4c2dbc..bbb6e6e 100644 --- a/src/model/event.rs +++ b/src/model/event.rs @@ -8,7 +8,10 @@ use ics::{ use serde::Serialize; use sqlx::{FromRow, Row, SqlitePool}; -use super::{notification::Notification, tripdetails::TripDetails, triptype::TripType, user::User}; +use super::{ + notification::Notification, role::Role, tripdetails::TripDetails, triptype::TripType, + user::User, +}; #[derive(Serialize, Clone, FromRow, Debug, PartialEq)] pub struct Event { @@ -219,6 +222,19 @@ WHERE trip_details.id=? planned_amount_cox: i32, trip_details: &TripDetails, ) { + if trip_details.always_show { + let donau = Role::find_by_name(db, "Donau Linz").await.unwrap(); + Notification::create_for_role( + db, + &donau, + &format!("Am {} um {} wurde ein neues Event angelegt: {} Wir freuen uns wenn du dabei mitmachst, die Anmeldung ist ab sofort offen :-)", trip_details.day, trip_details.planned_starting_time, name), + "Neues Event", + Some(&format!("/planned#{}", trip_details.day)), + None, + ) + .await; + } + sqlx::query!( "INSERT INTO planned_event(name, planned_amount_cox, trip_details_id) VALUES(?, ?, ?)", name, diff --git a/templates/planned.html.tera b/templates/planned.html.tera index 0dfab7c..0cccb5e 100644 --- a/templates/planned.html.tera +++ b/templates/planned.html.tera @@ -67,7 +67,7 @@ {% endif %} {% endfor %} {% endif %} -
Date: Mon, 19 Aug 2024 13:50:08 +0200 Subject: [PATCH 2/4] create notification if a new event with 'always_show' is updated --- src/model/event.rs | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/src/model/event.rs b/src/model/event.rs index bbb6e6e..3581810 100644 --- a/src/model/event.rs +++ b/src/model/event.rs @@ -9,7 +9,11 @@ use serde::Serialize; use sqlx::{FromRow, Row, SqlitePool}; use super::{ - notification::Notification, role::Role, tripdetails::TripDetails, triptype::TripType, + notification::Notification, + role::Role, + trip, + tripdetails::{self, TripDetails}, + triptype::TripType, user::User, }; @@ -216,6 +220,19 @@ WHERE trip_details.id=? .ok() } + async fn advertise(db: &SqlitePool, day: &str, planned_starting_time: &str, name: &str) { + let donau = Role::find_by_name(db, "Donau Linz").await.unwrap(); + Notification::create_for_role( + db, + &donau, + &format!("Am {} um {} wurde ein neues Event angelegt: {} Wir freuen uns wenn du dabei mitmachst, die Anmeldung ist ab sofort offen :-)", day, planned_starting_time, name), + "Neues Event", + Some(&format!("/planned#{day}")), + None, + ) + .await; + } + pub async fn create( db: &SqlitePool, name: &str, @@ -223,14 +240,11 @@ WHERE trip_details.id=? trip_details: &TripDetails, ) { if trip_details.always_show { - let donau = Role::find_by_name(db, "Donau Linz").await.unwrap(); - Notification::create_for_role( + Self::advertise( db, - &donau, - &format!("Am {} um {} wurde ein neues Event angelegt: {} Wir freuen uns wenn du dabei mitmachst, die Anmeldung ist ab sofort offen :-)", trip_details.day, trip_details.planned_starting_time, name), - "Neues Event", - Some(&format!("/planned#{}", trip_details.day)), - None, + &trip_details.day, + &trip_details.planned_starting_time, + name, ) .await; } @@ -274,6 +288,16 @@ WHERE trip_details.id=? .await .unwrap(); //Okay, as planned_event can only be created with proper DB backing + if !tripdetails.always_show && update.always_show { + Self::advertise( + db, + &tripdetails.day, + &tripdetails.planned_starting_time, + update.name, + ) + .await; + } + if update.max_people == 0 && !was_already_cancelled { let coxes = Registration::all_cox(db, self.id).await; for user in coxes { -- 2.45.2 From cf9b79e56e175eab2feedb5d3dfc59958772ca3a Mon Sep 17 00:00:00 2001 From: philipp Date: Wed, 21 Aug 2024 16:14:54 +0200 Subject: [PATCH 3/4] care about einschreibgebuehr --- seeds.sql | 1 + src/model/user.rs | 12 ++++++++++++ src/tera/admin/user.rs | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/seeds.sql b/seeds.sql index 0331795..1c42ed3 100644 --- a/seeds.sql +++ b/seeds.sql @@ -10,6 +10,7 @@ INSERT INTO "role" (name) VALUES ('Vorstand'); INSERT INTO "role" (name) VALUES ('Bootsführer'); INSERT INTO "role" (name) VALUES ('schnupperant'); INSERT INTO "role" (name) VALUES ('kassier'); +INSERT INTO "role" (name) VALUES ('no-einschreibgebuehr'); INSERT INTO "user" (name, pw) VALUES('admin', '$argon2id$v=19$m=19456,t=2,p=1$dS/X5/sPEKTj4Rzs/CuvzQ$4P4NCw4Ukhv80/eQYTsarHhnw61JuL1KMx/L9dm82YM'); INSERT INTO "user_role" (user_id, role_id) VALUES(1,1); INSERT INTO "user_role" (user_id, role_id) VALUES(1,2); diff --git a/src/model/user.rs b/src/model/user.rs index 6f25d7c..94bdd75 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -29,6 +29,7 @@ const REGULAR: i32 = 22000; const UNTERSTUETZEND: i32 = 2500; const FOERDERND: i32 = 8500; pub const SCHECKBUCH: i32 = 3000; +const EINSCHREIBGEBUEHR: i32 = 3500; #[derive(FromRow, Serialize, Deserialize, Clone, Debug, Eq, Hash, PartialEq)] pub struct User { @@ -361,6 +362,17 @@ ASKÖ Ruderverein Donau Linz", self.name), ); } + if let Some(member_since_date) = &self.member_since_date { + if let Ok(member_since_date) = NaiveDate::parse_from_str(member_since_date, "%Y-%m-%d") + { + if member_since_date.year() == Local::now().year() + && !self.has_role(db, "no-einschreibgebuehr").await + { + fee.add("Einschreibgebühr".into(), EINSCHREIBGEBUEHR); + } + } + } + let halfprice = if let Some(member_since_date) = &self.member_since_date { if let Ok(member_since_date) = NaiveDate::parse_from_str(member_since_date, "%Y-%m-%d") { diff --git a/src/tera/admin/user.rs b/src/tera/admin/user.rs index 3a98508..c9382e1 100644 --- a/src/tera/admin/user.rs +++ b/src/tera/admin/user.rs @@ -437,6 +437,10 @@ async fn schnupper_to_scheckbuch( let scheckbuch = Role::find_by_name(db, "scheckbuch").await.unwrap(); user.add_role(db, &scheckbuch).await; + if let Some(noEinschreibgebuehr) = Role::find_by_name(db, "no-einschreibgebuehr").await { + user.add_role(db, &noEinschreibgebuehr).await; + } + user.send_welcome_email(db, &config.smtp_pw).await.unwrap(); Log::create( -- 2.45.2 From d971c1504c658f666e6e733ac03f932c1972361a Mon Sep 17 00:00:00 2001 From: philipp Date: Wed, 21 Aug 2024 16:16:07 +0200 Subject: [PATCH 4/4] clippy --- src/model/event.rs | 6 +----- src/tera/admin/user.rs | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/model/event.rs b/src/model/event.rs index 3581810..3a34ad4 100644 --- a/src/model/event.rs +++ b/src/model/event.rs @@ -9,11 +9,7 @@ use serde::Serialize; use sqlx::{FromRow, Row, SqlitePool}; use super::{ - notification::Notification, - role::Role, - trip, - tripdetails::{self, TripDetails}, - triptype::TripType, + notification::Notification, role::Role, tripdetails::TripDetails, triptype::TripType, user::User, }; diff --git a/src/tera/admin/user.rs b/src/tera/admin/user.rs index c9382e1..29f88e7 100644 --- a/src/tera/admin/user.rs +++ b/src/tera/admin/user.rs @@ -437,8 +437,8 @@ async fn schnupper_to_scheckbuch( let scheckbuch = Role::find_by_name(db, "scheckbuch").await.unwrap(); user.add_role(db, &scheckbuch).await; - if let Some(noEinschreibgebuehr) = Role::find_by_name(db, "no-einschreibgebuehr").await { - user.add_role(db, &noEinschreibgebuehr).await; + if let Some(no_einschreibgebuehr) = Role::find_by_name(db, "no-einschreibgebuehr").await { + user.add_role(db, &no_einschreibgebuehr).await; } user.send_welcome_email(db, &config.smtp_pw).await.unwrap(); -- 2.45.2