allow deletion of trip in kiosk mode

This commit is contained in:
philipp 2023-10-23 21:32:44 +02:00
parent 6f9edfa23f
commit 51860ded27
2 changed files with 32 additions and 3 deletions

View File

@ -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::{

View File

@ -246,7 +246,7 @@ async fn home(
home_logbook(db, data, logbook_id, &user).await
}
#[get("/<logbook_id>/delete")]
#[get("/<logbook_id>/delete", rank = 2)]
async fn delete(db: &State<SqlitePool>, logbook_id: i32, user: User) -> Flash<Redirect> {
let logbook = Logbook::find_by_id(db, logbook_id).await;
if let Some(logbook) = logbook {
@ -268,6 +268,35 @@ async fn delete(db: &State<SqlitePool>, logbook_id: i32, user: User) -> Flash<Re
}
}
#[get("/<logbook_id>/delete")]
async fn delete_kiosk(
db: &State<SqlitePool>,
logbook_id: i32,
_kiosk: KioskCookie,
) -> Flash<Redirect> {
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<Route> {
routes![
index,
@ -279,7 +308,8 @@ pub fn routes() -> Vec<Route> {
new_kiosk,
show,
show_kiosk,
delete
delete,
delete_kiosk
]
}