Merge branch 'staging' into 'main'

Staging

See merge request PhilippHofer/rot!44
This commit is contained in:
PhilippHofer 2023-10-24 09:16:09 +00:00
commit 390ef6a965
4 changed files with 44 additions and 25 deletions

View File

@ -13,7 +13,7 @@ use crate::{
model::{ model::{
boat::Boat, boat::Boat,
boatdamage::{BoatDamage, BoatDamageFixed, BoatDamageToAdd, BoatDamageVerified}, boatdamage::{BoatDamage, BoatDamageFixed, BoatDamageToAdd, BoatDamageVerified},
user::{CoxUser, TechUser, User}, user::{CoxUser, NonGuestUser, TechUser, User},
}, },
tera::log::KioskCookie, tera::log::KioskCookie,
}; };
@ -42,7 +42,11 @@ async fn index_kiosk(
} }
#[get("/", rank = 2)] #[get("/", rank = 2)]
async fn index(db: &State<SqlitePool>, flash: Option<FlashMessage<'_>>, user: User) -> Template { async fn index(
db: &State<SqlitePool>,
flash: Option<FlashMessage<'_>>,
user: NonGuestUser,
) -> Template {
let boatdamages = BoatDamage::all(db).await; let boatdamages = BoatDamage::all(db).await;
let boats = Boat::all(db).await; let boats = Boat::all(db).await;
@ -53,7 +57,7 @@ async fn index(db: &State<SqlitePool>, flash: Option<FlashMessage<'_>>, user: Us
context.insert("boatdamages", &boatdamages); context.insert("boatdamages", &boatdamages);
context.insert("boats", &boats); context.insert("boats", &boats);
context.insert("loggedin_user", &user); context.insert("loggedin_user", &user.user);
Template::render("boatdamages", context.into_json()) Template::render("boatdamages", context.into_json())
} }
@ -69,14 +73,14 @@ pub struct FormBoatDamageToAdd<'r> {
async fn create<'r>( async fn create<'r>(
db: &State<SqlitePool>, db: &State<SqlitePool>,
data: Form<FormBoatDamageToAdd<'r>>, data: Form<FormBoatDamageToAdd<'r>>,
user: User, user: NonGuestUser,
) -> Flash<Redirect> { ) -> Flash<Redirect> {
return Flash::error(Redirect::to("/log"), "Du musst noch kurz geduldig sein. Sobald wir unser Logbuch umgestellt haben, kannst du es hier im Ruderassistenten verwenden ;)"); return Flash::error(Redirect::to("/log"), "Du musst noch kurz geduldig sein. Sobald wir unser Logbuch umgestellt haben, kannst du es hier im Ruderassistenten verwenden ;)");
let boatdamage_to_add = BoatDamageToAdd { let boatdamage_to_add = BoatDamageToAdd {
boat_id: data.boat_id, boat_id: data.boat_id,
desc: data.desc, desc: data.desc,
lock_boat: data.lock_boat, lock_boat: data.lock_boat,
user_id_created: user.id as i32, user_id_created: user.user.id as i32,
}; };
match BoatDamage::create(db, boatdamage_to_add).await { match BoatDamage::create(db, boatdamage_to_add).await {
Ok(_) => Flash::success( Ok(_) => Flash::success(

View File

@ -41,8 +41,12 @@ impl<'r> FromRequest<'r> for KioskCookie {
} }
#[get("/", rank = 2)] #[get("/", rank = 2)]
async fn index(db: &State<SqlitePool>, flash: Option<FlashMessage<'_>>, user: User) -> Template { async fn index(
let boats = Boat::for_user(db, &user).await; db: &State<SqlitePool>,
flash: Option<FlashMessage<'_>>,
user: NonGuestUser,
) -> Template {
let boats = Boat::for_user(db, &user.user).await;
let coxes: Vec<UserWithWaterStatus> = futures::future::join_all( let coxes: Vec<UserWithWaterStatus> = futures::future::join_all(
User::cox(db) User::cox(db)
@ -72,7 +76,7 @@ async fn index(db: &State<SqlitePool>, flash: Option<FlashMessage<'_>>, user: Us
context.insert("coxes", &coxes); context.insert("coxes", &coxes);
context.insert("users", &users); context.insert("users", &users);
context.insert("logtypes", &logtypes); context.insert("logtypes", &logtypes);
context.insert("loggedin_user", &user); context.insert("loggedin_user", &user.user);
context.insert("on_water", &on_water); context.insert("on_water", &on_water);
context.insert("distances", &distances); context.insert("distances", &distances);
@ -83,7 +87,7 @@ async fn index(db: &State<SqlitePool>, flash: Option<FlashMessage<'_>>, user: Us
async fn show(db: &State<SqlitePool>, user: NonGuestUser) -> Template { async fn show(db: &State<SqlitePool>, user: NonGuestUser) -> Template {
let logs = Logbook::completed(db).await; let logs = Logbook::completed(db).await;
Template::render("log.completed", context!(logs, loggedin_user: &user)) Template::render("log.completed", context!(logs, loggedin_user: &user.user))
} }
#[get("/show")] #[get("/show")]
@ -153,13 +157,17 @@ async fn kiosk(
Template::render("kiosk", context.into_json()) Template::render("kiosk", context.into_json())
} }
async fn create_logbook(db: &SqlitePool, data: Form<LogToAdd>, user: &User) -> Flash<Redirect> { async fn create_logbook(
db: &SqlitePool,
data: Form<LogToAdd>,
user: &NonGuestUser,
) -> Flash<Redirect> {
return Flash::error(Redirect::to("/log"), "Du musst noch kurz geduldig sein. Sobald wir unser Logbuch umgestellt haben, kannst du es hier im Ruderassistenten verwenden ;)"); return Flash::error(Redirect::to("/log"), "Du musst noch kurz geduldig sein. Sobald wir unser Logbuch umgestellt haben, kannst du es hier im Ruderassistenten verwenden ;)");
match Logbook::create( match Logbook::create(
db, db,
data.into_inner(), data.into_inner(),
user &user.user
) )
.await .await
{ {
@ -181,7 +189,11 @@ async fn create_logbook(db: &SqlitePool, data: Form<LogToAdd>, user: &User) -> F
} }
#[post("/", data = "<data>", rank = 2)] #[post("/", data = "<data>", rank = 2)]
async fn create(db: &State<SqlitePool>, data: Form<LogToAdd>, user: User) -> Flash<Redirect> { async fn create(
db: &State<SqlitePool>,
data: Form<LogToAdd>,
user: NonGuestUser,
) -> Flash<Redirect> {
create_logbook(db, data, &user).await create_logbook(db, data, &user).await
} }
@ -192,14 +204,14 @@ async fn create_kiosk(
_kiosk: KioskCookie, _kiosk: KioskCookie,
) -> Flash<Redirect> { ) -> Flash<Redirect> {
let creator = User::find_by_id(db, data.shipmaster as i32).await.unwrap(); let creator = User::find_by_id(db, data.shipmaster as i32).await.unwrap();
create_logbook(db, data, &creator).await create_logbook(db, data, &NonGuestUser::try_from(creator).unwrap()).await //TODO: fixme
} }
async fn home_logbook( async fn home_logbook(
db: &SqlitePool, db: &SqlitePool,
data: Form<LogToFinalize>, data: Form<LogToFinalize>,
logbook_id: i32, logbook_id: i32,
user: &User, user: &NonGuestUser,
) -> Flash<Redirect> { ) -> Flash<Redirect> {
return Flash::error(Redirect::to("/log"), "Du musst noch kurz geduldig sein. Sobald wir unser Logbuch umgestellt haben, kannst du es hier im Ruderassistenten verwenden ;)"); return Flash::error(Redirect::to("/log"), "Du musst noch kurz geduldig sein. Sobald wir unser Logbuch umgestellt haben, kannst du es hier im Ruderassistenten verwenden ;)");
let logbook: Option<Logbook> = Logbook::find_by_id(db, logbook_id).await; let logbook: Option<Logbook> = Logbook::find_by_id(db, logbook_id).await;
@ -210,7 +222,7 @@ async fn home_logbook(
); );
}; };
match logbook.home(db, user, data.into_inner()).await { match logbook.home(db, &user.user, data.into_inner()).await {
Ok(_) => Flash::success(Redirect::to("/log"), "Ausfahrt korrekt eingetragen"), Ok(_) => Flash::success(Redirect::to("/log"), "Ausfahrt korrekt eingetragen"),
Err(LogbookUpdateError::TooManyRowers(expected, actual)) => Flash::error(Redirect::to("/log"), format!("Zu viele Ruderer (Boot fasst maximal {expected}, es wurden jedoch {actual} Ruderer ausgewählt)")), Err(LogbookUpdateError::TooManyRowers(expected, actual)) => Flash::error(Redirect::to("/log"), format!("Zu viele Ruderer (Boot fasst maximal {expected}, es wurden jedoch {actual} Ruderer ausgewählt)")),
Err(_) => Flash::error( Err(_) => Flash::error(
@ -232,9 +244,12 @@ async fn home_kiosk(
db, db,
data, data,
logbook_id, logbook_id,
&User::find_by_id(db, logbook.shipmaster as i32) &NonGuestUser::try_from(
.await User::find_by_id(db, logbook.shipmaster as i32)
.unwrap(), .await
.unwrap(), //TODO: fixme
)
.unwrap(),
) )
.await .await
} }
@ -244,7 +259,7 @@ async fn home(
db: &State<SqlitePool>, db: &State<SqlitePool>,
data: Form<LogToFinalize>, data: Form<LogToFinalize>,
logbook_id: i32, logbook_id: i32,
user: User, user: NonGuestUser,
) -> Flash<Redirect> { ) -> Flash<Redirect> {
home_logbook(db, data, logbook_id, &user).await home_logbook(db, data, logbook_id, &user).await
} }

View File

@ -4,20 +4,20 @@ use sqlx::SqlitePool;
use crate::model::{ use crate::model::{
stat::{self, Stat}, stat::{self, Stat},
user::User, user::{NonGuestUser, User},
}; };
use super::log::KioskCookie; use super::log::KioskCookie;
#[get("/", rank = 2)] #[get("/", rank = 2)]
async fn index(db: &State<SqlitePool>, user: User) -> Template { async fn index(db: &State<SqlitePool>, user: NonGuestUser) -> Template {
let stat = Stat::get_rowed_km(db).await; let stat = Stat::get_rowed_km(db).await;
let personal = stat::get_personal(db, &user).await; let personal = stat::get_personal(db, &user.user).await;
let kiosk = false; let kiosk = false;
Template::render( Template::render(
"stat", "stat",
context!(loggedin_user: &user, stat, personal, kiosk), context!(loggedin_user: &user.user, stat, personal, kiosk),
) )
} }

View File

@ -13,6 +13,7 @@
{% include "includes/question-icon" %} {% include "includes/question-icon" %}
<span class="sr-only">FAQs</span> <span class="sr-only">FAQs</span>
</a> </a>
{% if not loggedin_user.is_guest %}
<a href="#" class="inline-flex justify-center rounded-md bg-primary-600 mx-1 px-3 py-2 text-sm font-semibold text-white hover:bg-primary-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-600 cursor-pointer" <a href="#" class="inline-flex justify-center rounded-md bg-primary-600 mx-1 px-3 py-2 text-sm font-semibold text-white hover:bg-primary-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-600 cursor-pointer"
data-sidebar="true" data-trigger="sidebar" data-header="Logbuch" data-body="#mobile-menu"> data-sidebar="true" data-trigger="sidebar" data-header="Logbuch" data-body="#mobile-menu">
{% include "includes/book" %} {% include "includes/book" %}
@ -23,11 +24,9 @@
<a href="/log" class="block w-100 py-2 hover:text-primary-600"> <a href="/log" class="block w-100 py-2 hover:text-primary-600">
Ausfahrt eintragen Ausfahrt eintragen
</a> </a>
{% if not loggedin_user.is_guest %}
<a href="/log/show" class="block w-100 py-2 hover:text-primary-600 border-t"> <a href="/log/show" class="block w-100 py-2 hover:text-primary-600 border-t">
Logbuch Logbuch
</a> </a>
{% endif %}
<a href="/stat" class="block w-100 py-2 hover:text-primary-600 border-t"> <a href="/stat" class="block w-100 py-2 hover:text-primary-600 border-t">
Statistik Statistik
</a> </a>
@ -41,6 +40,7 @@
</a> </a>
</div> </div>
</div> </div>
{% endif %}
{% if loggedin_user.is_admin %} {% if loggedin_user.is_admin %}
<a href="/admin/user" class="inline-flex justify-center rounded-md bg-primary-600 mx-1 px-3 py-2 text-sm font-semibold text-white hover:bg-primary-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-600 cursor-pointer"> <a href="/admin/user" class="inline-flex justify-center rounded-md bg-primary-600 mx-1 px-3 py-2 text-sm font-semibold text-white hover:bg-primary-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-600 cursor-pointer">