kiosk-allow-foerdernde #1096
@ -529,6 +529,13 @@ impl User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn remove_membership_pdf(&self, db: &SqlitePool, updated_by: &ManageUserUser) {
|
pub(crate) async fn remove_membership_pdf(&self, db: &SqlitePool, updated_by: &ManageUserUser) {
|
||||||
|
ActivityBuilder::new(&format!(
|
||||||
|
"{updated_by} hat die Beitrittserklärung vom Beutzer gelöscht."
|
||||||
|
))
|
||||||
|
.user(self)
|
||||||
|
.save(db)
|
||||||
|
.await;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"UPDATE user SET membership_pdf = null where id = ?",
|
"UPDATE user SET membership_pdf = null where id = ?",
|
||||||
self.id
|
self.id
|
||||||
|
@ -102,6 +102,13 @@ impl UserWithDetails {
|
|||||||
user,
|
user,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn allowed_to_row(&self) -> bool {
|
||||||
|
self.roles.contains(&"Donau Linz".into())
|
||||||
|
|| self.roles.contains(&"Förderndes Mitglied".into())
|
||||||
|
|| self.roles.contains(&"scheckbuch".into())
|
||||||
|
|| self.user.name == "Externe Steuerperson"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -40,7 +40,7 @@ async fn index(
|
|||||||
let allowed_to_edit = AllowedToUpdateBoathouse::new(db, &admin.user)
|
let allowed_to_edit = AllowedToUpdateBoathouse::new(db, &admin.user)
|
||||||
.await
|
.await
|
||||||
.is_some();
|
.is_some();
|
||||||
context.insert("allowed_to_edit", &boathouse);
|
context.insert("allowed_to_edit", &allowed_to_edit);
|
||||||
|
|
||||||
context.insert(
|
context.insert(
|
||||||
"loggedin_user",
|
"loggedin_user",
|
||||||
|
118
src/tera/log.rs
118
src/tera/log.rs
@ -47,12 +47,44 @@ impl<'r> FromRequest<'r> for KioskCookie {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[get("/", rank = 2)]
|
#[get("/", rank = 2)]
|
||||||
async fn index(
|
async fn index_loggedin(
|
||||||
db: &State<SqlitePool>,
|
db: &State<SqlitePool>,
|
||||||
flash: Option<FlashMessage<'_>>,
|
flash: Option<FlashMessage<'_>>,
|
||||||
user: DonauLinzUser,
|
user: DonauLinzUser,
|
||||||
) -> Template {
|
) -> Template {
|
||||||
|
let mut context = Context::new();
|
||||||
|
|
||||||
let boats = Boat::for_user(db, &user).await;
|
let boats = Boat::for_user(db, &user).await;
|
||||||
|
context.insert("boats", &boats);
|
||||||
|
|
||||||
|
context.insert(
|
||||||
|
"loggedin_user",
|
||||||
|
&UserWithDetails::from_user(user.into_inner(), db).await,
|
||||||
|
);
|
||||||
|
|
||||||
|
index(db, flash, context).await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/")]
|
||||||
|
async fn index_kiosk(
|
||||||
|
db: &State<SqlitePool>,
|
||||||
|
flash: Option<FlashMessage<'_>>,
|
||||||
|
_kiosk: KioskCookie,
|
||||||
|
) -> Template {
|
||||||
|
let mut context = Context::new();
|
||||||
|
|
||||||
|
let boats = Boat::all(db).await;
|
||||||
|
context.insert("boats", &boats);
|
||||||
|
|
||||||
|
context.insert("show_kiosk_header", &true);
|
||||||
|
|
||||||
|
index(db, flash, context).await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn index(db: &SqlitePool, flash: Option<FlashMessage<'_>>, mut context: Context) -> Template {
|
||||||
|
if let Some(msg) = flash {
|
||||||
|
context.insert("flash", &msg.into_inner());
|
||||||
|
}
|
||||||
|
|
||||||
let mut coxes: Vec<UserWithDetails> = futures::future::join_all(
|
let mut coxes: Vec<UserWithDetails> = futures::future::join_all(
|
||||||
User::cox(db)
|
User::cox(db)
|
||||||
@ -61,9 +93,7 @@ async fn index(
|
|||||||
.map(|user| UserWithDetails::from_user(user, db)),
|
.map(|user| UserWithDetails::from_user(user, db)),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
coxes.retain(|u| {
|
coxes.retain(|u| u.roles.contains(&"Donau Linz".into()));
|
||||||
u.roles.contains(&"Donau Linz".into()) || u.roles.contains(&"scheckbuch".into())
|
|
||||||
});
|
|
||||||
|
|
||||||
let mut users: Vec<UserWithDetails> = futures::future::join_all(
|
let mut users: Vec<UserWithDetails> = futures::future::join_all(
|
||||||
User::all(db)
|
User::all(db)
|
||||||
@ -72,24 +102,13 @@ async fn index(
|
|||||||
.map(|user| UserWithDetails::from_user(user, db)),
|
.map(|user| UserWithDetails::from_user(user, db)),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
users.retain(|u| {
|
users.retain(|u| u.allowed_to_row());
|
||||||
u.roles.contains(&"Donau Linz".into())
|
|
||||||
|| u.roles.contains(&"Förderndes Mitglied".into())
|
|
||||||
|| u.roles.contains(&"scheckbuch".into())
|
|
||||||
|| u.user.name == "Externe Steuerperson"
|
|
||||||
});
|
|
||||||
|
|
||||||
let logtypes = LogType::all(db).await;
|
let logtypes = LogType::all(db).await;
|
||||||
let distances = Distance::all(db).await;
|
let distances = Distance::all(db).await;
|
||||||
|
|
||||||
let on_water = Logbook::on_water(db).await;
|
let on_water = Logbook::on_water(db).await;
|
||||||
|
|
||||||
let mut context = Context::new();
|
|
||||||
if let Some(msg) = flash {
|
|
||||||
context.insert("flash", &msg.into_inner());
|
|
||||||
}
|
|
||||||
|
|
||||||
context.insert("boats", &boats);
|
|
||||||
context.insert("planned_trips", &Trip::get_for_today(db).await);
|
context.insert("planned_trips", &Trip::get_for_today(db).await);
|
||||||
context.insert(
|
context.insert(
|
||||||
"reservations",
|
"reservations",
|
||||||
@ -98,14 +117,10 @@ async fn index(
|
|||||||
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",
|
|
||||||
&UserWithDetails::from_user(user.into_inner(), db).await,
|
|
||||||
);
|
|
||||||
context.insert("on_water", &on_water);
|
context.insert("on_water", &on_water);
|
||||||
context.insert("distances", &distances);
|
context.insert("distances", &distances);
|
||||||
|
|
||||||
Template::render("log", context.into_json())
|
Template::render("kiosk", context.into_json())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/show", rank = 3)]
|
#[get("/show", rank = 3)]
|
||||||
@ -180,63 +195,6 @@ async fn new_kiosk(
|
|||||||
Redirect::to("/log")
|
Redirect::to("/log")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/")]
|
|
||||||
async fn kiosk(
|
|
||||||
db: &State<SqlitePool>,
|
|
||||||
flash: Option<FlashMessage<'_>>,
|
|
||||||
_kiosk: KioskCookie,
|
|
||||||
) -> Template {
|
|
||||||
let boats = Boat::all(db).await;
|
|
||||||
let mut coxes: Vec<UserWithDetails> = futures::future::join_all(
|
|
||||||
User::cox(db)
|
|
||||||
.await
|
|
||||||
.into_iter()
|
|
||||||
.map(|user| UserWithDetails::from_user(user, db)),
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
coxes.retain(|u| {
|
|
||||||
u.roles.contains(&"Donau Linz".into()) || u.roles.contains(&"scheckbuch".into())
|
|
||||||
});
|
|
||||||
|
|
||||||
let mut users: Vec<UserWithDetails> = futures::future::join_all(
|
|
||||||
User::all(db)
|
|
||||||
.await
|
|
||||||
.into_iter()
|
|
||||||
.map(|user| UserWithDetails::from_user(user, db)),
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
users.retain(|u| {
|
|
||||||
u.roles.contains(&"Donau Linz".into()) || u.roles.contains(&"scheckbuch".into())
|
|
||||||
});
|
|
||||||
|
|
||||||
let logtypes = LogType::all(db).await;
|
|
||||||
let distances = Distance::all(db).await;
|
|
||||||
|
|
||||||
let on_water = Logbook::on_water(db).await;
|
|
||||||
|
|
||||||
let mut context = Context::new();
|
|
||||||
if let Some(msg) = flash {
|
|
||||||
context.insert("flash", &msg.into_inner());
|
|
||||||
}
|
|
||||||
|
|
||||||
context.insert("planned_trips", &Trip::get_for_today(db).await);
|
|
||||||
context.insert("boats", &boats);
|
|
||||||
context.insert(
|
|
||||||
"reservations",
|
|
||||||
&BoatReservation::all_future_with_groups(db).await,
|
|
||||||
);
|
|
||||||
context.insert("coxes", &coxes);
|
|
||||||
context.insert("users", &users);
|
|
||||||
context.insert("logtypes", &logtypes);
|
|
||||||
context.insert("on_water", &on_water);
|
|
||||||
context.insert("distances", &distances);
|
|
||||||
context.insert("show_kiosk_header", &true);
|
|
||||||
|
|
||||||
Template::render("kiosk", context.into_json())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn create_logbook(
|
async fn create_logbook(
|
||||||
db: &SqlitePool,
|
db: &SqlitePool,
|
||||||
data: Form<LogToAdd>,
|
data: Form<LogToAdd>,
|
||||||
@ -569,11 +527,11 @@ async fn delete_kiosk(
|
|||||||
|
|
||||||
pub fn routes() -> Vec<Route> {
|
pub fn routes() -> Vec<Route> {
|
||||||
routes![
|
routes![
|
||||||
index,
|
index_loggedin,
|
||||||
|
index_kiosk,
|
||||||
create,
|
create,
|
||||||
create_kiosk,
|
create_kiosk,
|
||||||
home,
|
home,
|
||||||
kiosk,
|
|
||||||
home_kiosk,
|
home_kiosk,
|
||||||
new_kiosk,
|
new_kiosk,
|
||||||
show,
|
show,
|
||||||
|
Reference in New Issue
Block a user