diff --git a/src/tera/auth.rs b/src/tera/auth.rs index 6ff2ddc..2918c01 100644 --- a/src/tera/auth.rs +++ b/src/tera/auth.rs @@ -11,7 +11,6 @@ use rocket::{ FromForm, Request, Route, State, }; use rocket_dyn_templates::{context, tera, Template}; -use serde_json::json; use sqlx::SqlitePool; use crate::model::{ diff --git a/src/tera/log.rs b/src/tera/log.rs index 9b7cfbb..c7deb34 100644 --- a/src/tera/log.rs +++ b/src/tera/log.rs @@ -246,7 +246,7 @@ async fn home( home_logbook(db, data, logbook_id, &user).await } -#[get("//delete")] +#[get("//delete", rank = 2)] async fn delete(db: &State, logbook_id: i32, user: User) -> Flash { let logbook = Logbook::find_by_id(db, logbook_id).await; if let Some(logbook) = logbook { @@ -268,6 +268,35 @@ async fn delete(db: &State, logbook_id: i32, user: User) -> Flash/delete")] +async fn delete_kiosk( + db: &State, + logbook_id: i32, + _kiosk: KioskCookie, +) -> Flash { + let logbook = Logbook::find_by_id(db, logbook_id).await; + if let Some(logbook) = logbook { + let cox = User::find_by_id(db, logbook.shipmaster as i32) + .await + .unwrap(); + match logbook.delete(db, &cox).await { + Ok(_) => Flash::success( + Redirect::to("/log"), + format!("Logbook with ID {} successfully deleted!", logbook_id), + ), + Err(LogbookDeleteError::NotYourEntry) => Flash::error( + Redirect::to("/log"), + "Du hast nicht die Berechtigung, den Eintrag zu löschen!", + ), + } + } else { + Flash::error( + Redirect::to("/log"), + format!("Logbook with ID {} could not be found!", logbook_id), + ) + } +} + pub fn routes() -> Vec { routes![ index, @@ -279,7 +308,8 @@ pub fn routes() -> Vec { new_kiosk, show, show_kiosk, - delete + delete, + delete_kiosk ] }