From f5bfb9fbdf0d80a29d36c3a764b635f524555053 Mon Sep 17 00:00:00 2001 From: philipp Date: Wed, 3 Jan 2024 09:59:09 +0100 Subject: [PATCH 1/4] fix weird iphone issue --- templates/includes/macros.html.tera | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/includes/macros.html.tera b/templates/includes/macros.html.tera index 09e5eff..3d4fbf3 100644 --- a/templates/includes/macros.html.tera +++ b/templates/includes/macros.html.tera @@ -153,7 +153,7 @@ {% macro input(label, name, type, required=false, class='rounded-md', value='', min='', hide_label=false, id='', autofocus=false, wrapper_class='', pattern='') %}
- +
{% endmacro input %} -- 2.45.2 From bada4deeddc3040f858b271befd4310db63c832a Mon Sep 17 00:00:00 2001 From: philipp Date: Thu, 4 Jan 2024 20:43:38 +0100 Subject: [PATCH 2/4] allow to add logbook entries up to a week late; show all boats in boatshouse; don't show guests for external boats --- src/model/boat.rs | 10 ++++++++++ src/model/logbook.rs | 7 ++++++- src/tera/log.rs | 4 ++-- templates/includes/forms/log.html.tera | 4 ++-- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/model/boat.rs b/src/model/boat.rs index 20077b1..5be09a0 100644 --- a/src/model/boat.rs +++ b/src/model/boat.rs @@ -4,6 +4,7 @@ use rocket::serde::{Deserialize, Serialize}; use rocket::FromForm; use sqlx::{FromRow, Sqlite, SqlitePool, Transaction}; +use super::location::Location; use super::user::User; #[derive(FromRow, Debug, Serialize, Deserialize)] @@ -94,6 +95,15 @@ impl Boat { return owner_id == user.id; } + if user.has_role(db, "Rennrudern").await { + let ottensheim = Location::find_by_name(db, "Ottensheim".into()) + .await + .unwrap(); + if self.location_id == ottensheim.id { + return true; + } + } + if self.amount_seats == 1 { return true; } diff --git a/src/model/logbook.rs b/src/model/logbook.rs index f0909fa..98d6c87 100644 --- a/src/model/logbook.rs +++ b/src/model/logbook.rs @@ -471,7 +471,12 @@ ORDER BY departure DESC return Err(LogbookUpdateError::ArrivalNotAfterDeparture); } let today = Utc::now().date_naive(); - if arr.date() != today && !user.has_role_tx(db, "admin").await { + let day_diff = today - arr.date(); + let day_diff = day_diff.num_days(); + if day_diff >= 7 && !user.has_role_tx(db, "admin").await { + return Err(LogbookUpdateError::OnlyAllowedToEndTripsEndingToday); + } + if day_diff < 0 && !user.has_role_tx(db, "admin").await { return Err(LogbookUpdateError::OnlyAllowedToEndTripsEndingToday); } diff --git a/src/tera/log.rs b/src/tera/log.rs index 3309688..bc11589 100644 --- a/src/tera/log.rs +++ b/src/tera/log.rs @@ -127,7 +127,7 @@ async fn kiosk( flash: Option>, kiosk: KioskCookie, ) -> Template { - let boats = Boat::all_at_location(db, kiosk.0).await; + let boats = Boat::all(db).await; let coxes: Vec = futures::future::join_all( User::cox(db) .await @@ -188,7 +188,7 @@ async fn create_logbook( Err(LogbookCreateError::ShipmasterNotInRowers) => Flash::error(Redirect::to("/log"), "Schiffsführer nicht in Liste der Ruderer!"), Err(LogbookCreateError::NotYourEntry) => Flash::error(Redirect::to("/log"), "Nicht deine Ausfahrt!"), Err(LogbookCreateError::ArrivalSetButNotRemainingTwo) => Flash::error(Redirect::to("/log"), "Ankunftszeit gesetzt aber nicht Distanz + Strecke"), - Err(LogbookCreateError::OnlyAllowedToEndTripsEndingToday) => Flash::error(Redirect::to("/log"), "Nur Ausfahrten, die heute enden dürfen eingetragen werden. Für einen Nachtrag schreibe alle Daten Philipp (Tel. nr. siehe Signal oder it@rudernlinz.at)."), + Err(LogbookCreateError::OnlyAllowedToEndTripsEndingToday) => Flash::error(Redirect::to("/log"), "Nur Ausfahrten, die in den letzten Woche enden dürfen eingetragen werden. Für einen Nachtrag schreibe alle Daten Philipp (Tel. nr. siehe Signal oder it@rudernlinz.at)."), } } diff --git a/templates/includes/forms/log.html.tera b/templates/includes/forms/log.html.tera index efeeee7..6707910 100644 --- a/templates/includes/forms/log.html.tera +++ b/templates/includes/forms/log.html.tera @@ -199,9 +199,9 @@
Ruderer: {% for rower in log.rowers %} - {{ rower.name }}{% if not loop.last or amount_guests > 0 %}, {% endif %} + {{ rower.name }}{% if not loop.last or amount_guests > 0 and log.boat.name != 'Externes Boot' %}, {% endif %} {% endfor %} - {% if amount_guests > 0 %} + {% if amount_guests > 0 and log.boat.name != 'Externes Boot' %} Gäste (ohne Account): {{ amount_guests }} {% endif %}
-- 2.45.2 From 1cfbb970345f487d15ae6ca3c2da8de200974e19 Mon Sep 17 00:00:00 2001 From: philipp Date: Thu, 4 Jan 2024 20:46:49 +0100 Subject: [PATCH 3/4] fix tests, as we now show all boats in kiosk mode --- src/tera/log.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tera/log.rs b/src/tera/log.rs index bc11589..566c874 100644 --- a/src/tera/log.rs +++ b/src/tera/log.rs @@ -424,7 +424,7 @@ mod test { assert!(text.contains("Logbuch")); assert!(text.contains("Neue Ausfahrt")); - assert!(!text.contains("Ottensheim Boot")); + //assert!(!text.contains("Ottensheim Boot")); } #[sqlx::test] @@ -610,7 +610,7 @@ mod test { assert!(text.contains("private_boat_from_rower")); //Doesn't see the one's in Ottensheim - assert!(!text.contains("Ottensheim Boot")); + //assert!(!text.contains("Ottensheim Boot")); } #[sqlx::test] -- 2.45.2 From 1c020da84f334b529adfcbc553341647d2d5b4bd Mon Sep 17 00:00:00 2001 From: philipp Date: Fri, 5 Jan 2024 20:37:40 +0100 Subject: [PATCH 4/4] fix stat --- src/model/stat.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/model/stat.rs b/src/model/stat.rs index 4009670..dcf66b8 100644 --- a/src/model/stat.rs +++ b/src/model/stat.rs @@ -66,7 +66,9 @@ SELECT CAST(SUM(l.distance_in_km) AS INTEGER) AS rowed_km FROM user u INNER JOIN rower r ON u.id = r.rower_id INNER JOIN logbook l ON r.logbook_id = l.id -WHERE u.is_guest = 1 AND l.distance_in_km IS NOT NULL AND l.arrival LIKE '{year}-%'; +INNER JOIN user_role ur ON u.id = ur.user_id +INNER JOIN role ro ON ur.role_id = ro.id +WHERE ro.name = 'scheckbuch' AND l.distance_in_km IS NOT NULL AND l.arrival LIKE '{year}-%'; " )) .fetch_one(db) @@ -89,10 +91,17 @@ WHERE u.is_guest = 1 AND l.distance_in_km IS NOT NULL AND l.arrival LIKE '{year} sqlx::query(&format!( " SELECT u.name, CAST(SUM(l.distance_in_km) AS INTEGER) AS rowed_km -FROM user u +FROM ( + SELECT * FROM user + WHERE id NOT IN ( + SELECT user_id FROM user_role + JOIN role ON user_role.role_id = role.id + WHERE role.name = 'scheckbuch' + ) +) u INNER JOIN rower r ON u.id = r.rower_id INNER JOIN logbook l ON r.logbook_id = l.id -WHERE u.is_guest = 0 AND l.distance_in_km IS NOT NULL AND l.arrival LIKE '{year}-%' +WHERE l.distance_in_km IS NOT NULL AND l.arrival LIKE '{year}-%' GROUP BY u.name ORDER BY rowed_km DESC; " -- 2.45.2