allow deletion of trip in kiosk mode
This commit is contained in:
parent
6f9edfa23f
commit
51860ded27
@ -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::{
|
||||
|
@ -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
|
||||
]
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user