forked from Ruderverein-Donau-Linz/rowt
don't allow to add entry which is not completed today
This commit is contained in:
parent
bcd275fc3e
commit
a3c7461c2b
@ -1,4 +1,4 @@
|
|||||||
use chrono::NaiveDateTime;
|
use chrono::{NaiveDateTime, Utc};
|
||||||
use rocket::FromForm;
|
use rocket::FromForm;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use sqlx::{FromRow, Sqlite, SqlitePool, Transaction};
|
use sqlx::{FromRow, Sqlite, SqlitePool, Transaction};
|
||||||
@ -99,6 +99,7 @@ pub enum LogbookUpdateError {
|
|||||||
ShipmasterNotInRowers,
|
ShipmasterNotInRowers,
|
||||||
SteeringPersonNotInRowers,
|
SteeringPersonNotInRowers,
|
||||||
UserNotAllowedToUseBoat,
|
UserNotAllowedToUseBoat,
|
||||||
|
OnlyAllowedToEndTripsEndingToday,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
@ -120,6 +121,7 @@ pub enum LogbookCreateError {
|
|||||||
ShipmasterNotInRowers,
|
ShipmasterNotInRowers,
|
||||||
NotYourEntry,
|
NotYourEntry,
|
||||||
ArrivalSetButNotRemainingTwo,
|
ArrivalSetButNotRemainingTwo,
|
||||||
|
OnlyAllowedToEndTripsEndingToday,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<LogbookUpdateError> for LogbookCreateError {
|
impl From<LogbookUpdateError> for LogbookCreateError {
|
||||||
@ -140,6 +142,9 @@ impl From<LogbookUpdateError> for LogbookCreateError {
|
|||||||
LogbookUpdateError::UserNotAllowedToUseBoat => {
|
LogbookUpdateError::UserNotAllowedToUseBoat => {
|
||||||
LogbookCreateError::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 {
|
if !boat.shipmaster_allowed(user).await && self.shipmaster != user.id {
|
||||||
//second part:
|
//second part: shipmaster has entered a different user, then the user should be able to
|
||||||
//shipmaster has
|
//`home` it
|
||||||
//entered a
|
|
||||||
//different user,
|
|
||||||
//then the user
|
|
||||||
//should be able
|
|
||||||
//to `home` it
|
|
||||||
return Err(LogbookUpdateError::UserNotAllowedToUseBoat);
|
return Err(LogbookUpdateError::UserNotAllowedToUseBoat);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -468,6 +468,10 @@ ORDER BY departure DESC
|
|||||||
if arr.timestamp() <= dep.timestamp() {
|
if arr.timestamp() <= dep.timestamp() {
|
||||||
return Err(LogbookUpdateError::ArrivalNotAfterDeparture);
|
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;
|
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::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::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::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 {
|
match logbook.home(db, &user.user, data.into_inner()).await {
|
||||||
Ok(_) => Flash::success(Redirect::to("/log"), "Ausfahrt korrekt eingetragen"),
|
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::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(
|
Err(e) => Flash::error(
|
||||||
Redirect::to("/log"),
|
Redirect::to("/log"),
|
||||||
format!("Eintrag {logbook_id} konnte nicht abgesendet werden (Fehler: {e:?})!"),
|
format!("Eintrag {logbook_id} konnte nicht abgesendet werden (Fehler: {e:?})!"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user