allow external cox; Fix #650

This commit is contained in:
2024-07-28 07:29:44 +02:00
parent c13dfdaa77
commit bf4ea502d3
2 changed files with 25 additions and 1 deletions

View File

@ -127,6 +127,7 @@ pub enum LogbookUpdateError {
OnlyAllowedToEndTripsEndingToday,
TooFast(i64, i64),
AlreadyFinalized,
ExternalSteeringPersonMustSteer,
}
#[derive(Debug, PartialEq)]
@ -152,6 +153,7 @@ pub enum LogbookCreateError {
CantChangeHandoperatableStatusForThisBoat,
TooFast(i64, i64),
AlreadyFinalized,
ExternalSteeringPersonMustSteer,
}
impl From<LogbookUpdateError> for LogbookCreateError {
@ -177,6 +179,9 @@ impl From<LogbookUpdateError> for LogbookCreateError {
}
LogbookUpdateError::TooFast(km, min) => LogbookCreateError::TooFast(km, min),
LogbookUpdateError::AlreadyFinalized => LogbookCreateError::AlreadyFinalized,
LogbookUpdateError::ExternalSteeringPersonMustSteer => {
LogbookCreateError::ExternalSteeringPersonMustSteer
}
}
}
}
@ -414,6 +419,14 @@ ORDER BY departure DESC
if user.on_water(db).await {
return Err(LogbookCreateError::RowerAlreadyOnWater(Box::new(user)));
}
if user.name == "Externe Steuerperson" {
if let Some(steering_id) = log.steering_person {
if steering_id != user.id {
return Err(LogbookCreateError::ExternalSteeringPersonMustSteer);
}
}
}
}
if !boat.shipmaster_allowed(db, created_by_user).await {
@ -609,6 +622,13 @@ ORDER BY departure DESC
self.remove_rowers(db).await;
for rower in &log.rowers {
if user.name == "Externe Steuerperson" {
if let Some(steering_id) = log.steering_person {
if steering_id != user.id {
return Err(LogbookUpdateError::ExternalSteeringPersonMustSteer);
}
}
}
Rower::create(db, self.id, *rower)
.await
.map_err(|e| LogbookUpdateError::RowerCreateError(*rower, e.to_string()))?;