forked from Ruderverein-Donau-Linz/rowt
		
	don't allow to add entry which is not completed today
This commit is contained in:
		| @@ -1,4 +1,4 @@ | ||||
| use chrono::NaiveDateTime; | ||||
| use chrono::{NaiveDateTime, Utc}; | ||||
| use rocket::FromForm; | ||||
| use serde::Serialize; | ||||
| use sqlx::{FromRow, Sqlite, SqlitePool, Transaction}; | ||||
| @@ -99,6 +99,7 @@ pub enum LogbookUpdateError { | ||||
|     ShipmasterNotInRowers, | ||||
|     SteeringPersonNotInRowers, | ||||
|     UserNotAllowedToUseBoat, | ||||
|     OnlyAllowedToEndTripsEndingToday, | ||||
| } | ||||
|  | ||||
| #[derive(Debug, PartialEq)] | ||||
| @@ -120,6 +121,7 @@ pub enum LogbookCreateError { | ||||
|     ShipmasterNotInRowers, | ||||
|     NotYourEntry, | ||||
|     ArrivalSetButNotRemainingTwo, | ||||
|     OnlyAllowedToEndTripsEndingToday, | ||||
| } | ||||
|  | ||||
| impl From<LogbookUpdateError> for LogbookCreateError { | ||||
| @@ -140,6 +142,9 @@ impl From<LogbookUpdateError> for LogbookCreateError { | ||||
|             LogbookUpdateError::UserNotAllowedToUseBoat => { | ||||
|                 LogbookCreateError::UserNotAllowedToUseBoat | ||||
|             } | ||||
|             LogbookUpdateError::OnlyAllowedToEndTripsEndingToday => { | ||||
|                 LogbookCreateError::OnlyAllowedToEndTripsEndingToday | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -446,13 +451,8 @@ ORDER BY departure DESC | ||||
|         } | ||||
|  | ||||
|         if !boat.shipmaster_allowed(user).await && self.shipmaster != user.id { | ||||
|             //second part: | ||||
|             //shipmaster has | ||||
|             //entered a | ||||
|             //different user, | ||||
|             //then the user | ||||
|             //should be able | ||||
|             //to `home` it | ||||
|             //second part: shipmaster has entered a different user, then the user should be able to | ||||
|             //`home` it | ||||
|             return Err(LogbookUpdateError::UserNotAllowedToUseBoat); | ||||
|         } | ||||
|  | ||||
| @@ -468,6 +468,10 @@ ORDER BY departure DESC | ||||
|         if arr.timestamp() <= dep.timestamp() { | ||||
|             return Err(LogbookUpdateError::ArrivalNotAfterDeparture); | ||||
|         } | ||||
|         let today = Utc::now().date_naive(); | ||||
|         if arr.date() != today && !user.is_admin { | ||||
|             return Err(LogbookUpdateError::OnlyAllowedToEndTripsEndingToday); | ||||
|         } | ||||
|  | ||||
|         Log::create_with_tx(db, format!("New trip: {log:?}")).await; | ||||
|  | ||||
|   | ||||
| @@ -182,6 +182,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"), format!("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).")), | ||||
|  | ||||
|     } | ||||
| } | ||||
| @@ -251,6 +252,7 @@ async fn home_logbook( | ||||
|     match logbook.home(db, &user.user, data.into_inner()).await { | ||||
|         Ok(_) => Flash::success(Redirect::to("/log"), "Ausfahrt korrekt eingetragen"), | ||||
|         Err(LogbookUpdateError::TooManyRowers(expected, actual)) => Flash::error(Redirect::to("/log"), format!("Zu viele Ruderer (Boot fasst maximal {expected}, es wurden jedoch {actual} Ruderer ausgewählt)")), | ||||
|         Err(LogbookUpdateError::OnlyAllowedToEndTripsEndingToday) => Flash::error(Redirect::to("/log"), format!("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(e) => Flash::error( | ||||
|             Redirect::to("/log"), | ||||
|             format!("Eintrag {logbook_id} konnte nicht abgesendet werden (Fehler: {e:?})!"), | ||||
|   | ||||
		Reference in New Issue
	
	Block a user