From fcf86c7ff12d9953e3a6079c33b5854378ef0d5d Mon Sep 17 00:00:00 2001 From: philipp Date: Fri, 26 Apr 2024 09:50:01 +0200 Subject: [PATCH 1/2] if user is logged in, use that user as default rower --- frontend/main.ts | 5 ++++- frontend/tests/log.spec.ts | 2 ++ templates/log.html.tera | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/frontend/main.ts b/frontend/main.ts index 69efee5..15360e6 100644 --- a/frontend/main.ts +++ b/frontend/main.ts @@ -5,6 +5,7 @@ export interface choiceMap { [details: string]: Choices; } +declare var loggedin_user_id: string; let choiceObjects: choiceMap = {}; let boat_in_ottensheim = true; let boat_reserved_today= true; @@ -176,7 +177,9 @@ function selectBoatChange() { /** custom code for Etsch */ choiceObjects["newrower"].setChoiceByValue("81"); } - } + }else if (typeof loggedin_user_id !== 'undefined'){ + choiceObjects["newrower"].setChoiceByValue(loggedin_user_id); + } const inputElement = document.getElementById( "departure", diff --git a/frontend/tests/log.spec.ts b/frontend/tests/log.spec.ts index b12f0cb..a5380b7 100644 --- a/frontend/tests/log.spec.ts +++ b/frontend/tests/log.spec.ts @@ -18,6 +18,7 @@ test("Cox can start and cancel trip", async ({ page }, testInfo) => { await page.getByText('2x', { exact: true }).click(); await page.getByText("Joe", { exact: true }).click(); } + await page.getByLabel('Remove item: \'6\'').click(); // remove pre-filled cox2 await page.getByPlaceholder("Ruderer auswählen").click(); await page.getByRole("option", { name: "rower2" }).click(); await page.getByRole("option", { name: "cox2" }).click(); @@ -59,6 +60,7 @@ test("Cox can start and finish trip", async ({ page }, testInfo) => { await page.getByText('2x', { exact: true }).click(); await page.getByText("Joe", { exact: true }).click(); } + await page.getByLabel('Remove item: \'6\'').click(); // remove pre-filled cox2 await page.getByPlaceholder("Ruderer auswählen").click(); await page.getByRole("option", { name: "rower2" }).click(); await page.getByRole("option", { name: "cox2" }).click(); diff --git a/templates/log.html.tera b/templates/log.html.tera index 5650da0..1bf266b 100644 --- a/templates/log.html.tera +++ b/templates/log.html.tera @@ -38,5 +38,6 @@ + {% if loggedin_user %}{% endif %} {% endblock content %} -- 2.45.2 From c27a2ad15e66ba73d2490a4c716af2597e5f542f Mon Sep 17 00:00:00 2001 From: philipp Date: Sun, 28 Apr 2024 19:16:38 +0200 Subject: [PATCH 2/2] don't respond with 500 if no rower is selected --- src/tera/log.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/tera/log.rs b/src/tera/log.rs index 2c618b0..0cdca4a 100644 --- a/src/tera/log.rs +++ b/src/tera/log.rs @@ -250,7 +250,13 @@ async fn create_kiosk( } else if let Some(shipmaster) = data.shipmaster { User::find_by_id(db, shipmaster as i32).await.unwrap() } else { - User::find_by_id(db, data.rowers[0] as i32).await.unwrap() + let Some(rower) = data.rowers.get(0) else { + return Flash::error( + Redirect::to("/log"), + "Ausfahrt ohne Benutzer kann nicht angelegt werden.", + ); + }; + User::find_by_id(db, *rower as i32).await.unwrap() }; Log::create( db, -- 2.45.2