Compare commits

..

No commits in common. "d59b3f43454da5a63c1078c62c5ce414f566a2e4" and "0dd10e1dd67881d5f13d12e05db39cf60222ce51" have entirely different histories.

2 changed files with 30 additions and 51 deletions

View File

@ -1,6 +1,6 @@
use std::ops::DerefMut;
use chrono::{Datelike, Duration, Local, NaiveDateTime};
use chrono::{Datelike, Local, NaiveDateTime};
use rocket::FromForm;
use serde::Serialize;
use sqlx::{FromRow, Sqlite, SqlitePool, Transaction};
@ -110,20 +110,6 @@ pub struct LogbookWithBoatAndRowers {
pub rowers: Vec<User>,
}
impl LogbookWithBoatAndRowers {
pub(crate) async fn from(db: &SqlitePool, log: Logbook) -> Self {
Self {
rowers: Rower::for_log(db, &log).await,
boat: Boat::find_by_id(db, log.boat_id as i32).await.unwrap(),
shipmaster_user: User::find_by_id(db, log.shipmaster as i32).await.unwrap(),
steering_user: User::find_by_id(db, log.steering_person as i32)
.await
.unwrap(),
logbook: log,
}
}
}
#[derive(Debug, PartialEq)]
pub enum LogbookAdminUpdateError {
NotAllowed,
@ -262,7 +248,15 @@ ORDER BY departure DESC
let mut ret = Vec::new();
for log in logs {
ret.push(LogbookWithBoatAndRowers::from(db, log).await);
ret.push(LogbookWithBoatAndRowers {
rowers: Rower::for_log(db, &log).await,
boat: Boat::find_by_id(db, log.boat_id as i32).await.unwrap(),
shipmaster_user: User::find_by_id(db, log.shipmaster as i32).await.unwrap(),
steering_user: User::find_by_id(db, log.steering_person as i32)
.await
.unwrap(),
logbook: log,
});
}
ret
}
@ -286,7 +280,15 @@ ORDER BY departure DESC
let mut ret = Vec::new();
for log in logs {
ret.push(LogbookWithBoatAndRowers::from(db, log).await);
ret.push(LogbookWithBoatAndRowers {
rowers: Rower::for_log(db, &log).await,
boat: Boat::find_by_id(db, log.boat_id as i32).await.unwrap(),
shipmaster_user: User::find_by_id(db, log.shipmaster as i32).await.unwrap(),
steering_user: User::find_by_id(db, log.steering_person as i32)
.await
.unwrap(),
logbook: log,
});
}
ret
}
@ -311,7 +313,15 @@ ORDER BY departure DESC
let mut ret = Vec::new();
for log in logs {
ret.push(LogbookWithBoatAndRowers::from(db, log).await);
ret.push(LogbookWithBoatAndRowers {
rowers: Rower::for_log(db, &log).await,
boat: Boat::find_by_id(db, log.boat_id as i32).await.unwrap(),
shipmaster_user: User::find_by_id(db, log.shipmaster as i32).await.unwrap(),
steering_user: User::find_by_id(db, log.steering_person as i32)
.await
.unwrap(),
logbook: log,
});
}
ret
}
@ -703,37 +713,6 @@ ORDER BY departure DESC
|| user.has_role(db, "Vorstand").await
|| user.id == self.shipmaster
{
let now = Local::now().naive_local();
let difference = now - self.departure;
if difference > Duration::hours(1) {
let vorstand = Role::find_by_name(db, "Vorstand").await.unwrap();
let logbook = LogbookWithBoatAndRowers::from(db, self.clone()).await;
let mut msg = format!("{} hat folgenden Logbuch-Eintrag jetzt gelöscht, welcher bereits vor über einer Stunde begonnen wurde: Schiffsführer: {}, Steuerperson: {}, Abfahrt: {}", user.name, logbook.steering_user.name, logbook.steering_user.name, logbook.logbook.departure.format("%Y-%m-%d %H:%M"));
if let Some(destination) = logbook.logbook.destination {
msg.push_str(&format!(", Ziel: {}", destination));
} else {
msg.push_str(", kein Ziel eingegeben");
}
msg.push_str(", Ruderer: ");
let mut it = logbook.rowers.clone().into_iter().peekable();
while let Some(rower) = it.next() {
msg.push_str(&rower.name);
if it.peek().is_some() {
msg.push_str(" + ");
}
}
Notification::create_for_role(
db,
&vorstand,
&msg,
"Ungewöhnliches Verhalten",
None,
None,
)
.await;
}
sqlx::query!("DELETE FROM logbook WHERE id=?", self.id)
.execute(db)
.await

View File

@ -311,12 +311,12 @@ async fn update(
Flash::success(
Redirect::to("/log/show"),
"Logbucheintrag erfolgreich bearbeitet".to_string(),
format!("Logbucheintrag erfolgreich bearbeitet"),
)
}
Err(LogbookAdminUpdateError::NotAllowed) => Flash::error(
Redirect::to("/log/show"),
"Du hast keine Erlaubnis, diesen Logbucheintrag zu bearbeiten!".to_string(),
format!("Du hast keine Erlaubnis, diesen Logbucheintrag zu bearbeiten!"),
),
}
}