hide logbook for guests
This commit is contained in:
@ -41,8 +41,12 @@ impl<'r> FromRequest<'r> for KioskCookie {
|
||||
}
|
||||
|
||||
#[get("/", rank = 2)]
|
||||
async fn index(db: &State<SqlitePool>, flash: Option<FlashMessage<'_>>, user: User) -> Template {
|
||||
let boats = Boat::for_user(db, &user).await;
|
||||
async fn index(
|
||||
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(
|
||||
User::cox(db)
|
||||
@ -153,13 +157,17 @@ async fn kiosk(
|
||||
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 ;)");
|
||||
|
||||
match Logbook::create(
|
||||
db,
|
||||
data.into_inner(),
|
||||
user
|
||||
&user.user
|
||||
)
|
||||
.await
|
||||
{
|
||||
@ -181,7 +189,11 @@ async fn create_logbook(db: &SqlitePool, data: Form<LogToAdd>, user: &User) -> F
|
||||
}
|
||||
|
||||
#[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
|
||||
}
|
||||
|
||||
@ -192,14 +204,14 @@ async fn create_kiosk(
|
||||
_kiosk: KioskCookie,
|
||||
) -> Flash<Redirect> {
|
||||
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(
|
||||
db: &SqlitePool,
|
||||
data: Form<LogToFinalize>,
|
||||
logbook_id: i32,
|
||||
user: &User,
|
||||
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 ;)");
|
||||
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"),
|
||||
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(
|
||||
@ -232,9 +244,12 @@ async fn home_kiosk(
|
||||
db,
|
||||
data,
|
||||
logbook_id,
|
||||
&User::find_by_id(db, logbook.shipmaster as i32)
|
||||
.await
|
||||
.unwrap(),
|
||||
&NonGuestUser::try_from(
|
||||
User::find_by_id(db, logbook.shipmaster as i32)
|
||||
.await
|
||||
.unwrap(), //TODO: fixme
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
@ -244,7 +259,7 @@ async fn home(
|
||||
db: &State<SqlitePool>,
|
||||
data: Form<LogToFinalize>,
|
||||
logbook_id: i32,
|
||||
user: User,
|
||||
user: NonGuestUser,
|
||||
) -> Flash<Redirect> {
|
||||
home_logbook(db, data, logbook_id, &user).await
|
||||
}
|
||||
|
Reference in New Issue
Block a user