Compare commits
No commits in common. "1aba6948ee041e218c7b96e2341f822727c73381" and "08a970853abeda1c74b1d5c4b81c5ffb84e49f68" have entirely different histories.
1aba6948ee
...
08a970853a
@ -959,30 +959,6 @@ impl Deref for PlannedEventUser {
|
|||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[derive(FromRow, Serialize, Deserialize, Clone, Debug)]
|
|
||||||
pub struct UserWithRolesAndMembershipPdf {
|
|
||||||
#[serde(flatten)]
|
|
||||||
pub user: User,
|
|
||||||
pub membership_pdf: bool,
|
|
||||||
pub roles: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl UserWithRolesAndMembershipPdf {
|
|
||||||
pub(crate) async fn from_user(db: &SqlitePool, user: User) -> Self {
|
|
||||||
let membership_pdf: bool =
|
|
||||||
sqlx::query_scalar!("SELECT membership_pdf FROM user WHERE id = $1", user.id)
|
|
||||||
.fetch_optional(db)
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.is_some();
|
|
||||||
|
|
||||||
Self {
|
|
||||||
roles: user.roles(db).await,
|
|
||||||
user,
|
|
||||||
membership_pdf,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(FromRow, Serialize, Deserialize, Clone, Debug)]
|
#[derive(FromRow, Serialize, Deserialize, Clone, Debug)]
|
||||||
pub struct UserWithMembershipPdf {
|
pub struct UserWithMembershipPdf {
|
||||||
|
@ -5,10 +5,7 @@ use crate::model::{
|
|||||||
log::Log,
|
log::Log,
|
||||||
logbook::Logbook,
|
logbook::Logbook,
|
||||||
role::Role,
|
role::Role,
|
||||||
user::{
|
user::{AdminUser, User, UserWithMembershipPdf, UserWithRoles, VorstandUser},
|
||||||
AdminUser, User, UserWithMembershipPdf, UserWithRoles, UserWithRolesAndMembershipPdf,
|
|
||||||
VorstandUser,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
use futures::future::join_all;
|
use futures::future::join_all;
|
||||||
use rocket::{
|
use rocket::{
|
||||||
@ -48,13 +45,13 @@ async fn index(
|
|||||||
let user_futures: Vec<_> = User::all(db)
|
let user_futures: Vec<_> = User::all(db)
|
||||||
.await
|
.await
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|u| async move { UserWithRolesAndMembershipPdf::from_user(db, u).await })
|
.map(|u| async move { UserWithRoles::from_user(u, db).await })
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let user: User = user.into();
|
let user: User = user.into();
|
||||||
let allowed_to_edit = user.has_role(db, "admin").await;
|
let allowed_to_edit = user.has_role(db, "admin").await;
|
||||||
|
|
||||||
let users: Vec<UserWithRolesAndMembershipPdf> = join_all(user_futures).await;
|
let users: Vec<UserWithRoles> = join_all(user_futures).await;
|
||||||
|
|
||||||
let roles = Role::all(db).await;
|
let roles = Role::all(db).await;
|
||||||
let families = Family::all_with_members(db).await;
|
let families = Family::all_with_members(db).await;
|
||||||
@ -81,13 +78,14 @@ async fn index_admin(
|
|||||||
let user_futures: Vec<_> = User::all(db)
|
let user_futures: Vec<_> = User::all(db)
|
||||||
.await
|
.await
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|u| async move { UserWithRolesAndMembershipPdf::from_user(db, u).await })
|
.map(|u| async move { UserWithRoles::from_user(u, db).await })
|
||||||
.collect();
|
.collect();
|
||||||
let users: Vec<UserWithRolesAndMembershipPdf> = join_all(user_futures).await;
|
|
||||||
|
|
||||||
let user: User = user.user;
|
let user: User = user.user;
|
||||||
let allowed_to_edit = user.has_role(db, "admin").await;
|
let allowed_to_edit = user.has_role(db, "admin").await;
|
||||||
|
|
||||||
|
let users: Vec<UserWithRoles> = join_all(user_futures).await;
|
||||||
|
|
||||||
let roles = Role::all(db).await;
|
let roles = Role::all(db).await;
|
||||||
let families = Family::all_with_members(db).await;
|
let families = Family::all_with_members(db).await;
|
||||||
|
|
||||||
|
@ -49,24 +49,20 @@ async fn index(
|
|||||||
) -> Template {
|
) -> Template {
|
||||||
let boats = Boat::for_user(db, &user).await;
|
let boats = Boat::for_user(db, &user).await;
|
||||||
|
|
||||||
let mut coxes: Vec<UserWithWaterStatus> = futures::future::join_all(
|
let coxes: Vec<UserWithWaterStatus> = futures::future::join_all(
|
||||||
User::cox(db)
|
User::cox(db)
|
||||||
.await
|
.await
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|user| UserWithWaterStatus::from_user(user, db)),
|
.map(|user| UserWithWaterStatus::from_user(user, db)),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
coxes.retain(|u| u.roles.contains(&"Donau Linz".into()));
|
let users: Vec<UserWithWaterStatus> = futures::future::join_all(
|
||||||
|
|
||||||
let mut users: Vec<UserWithWaterStatus> = futures::future::join_all(
|
|
||||||
User::all(db)
|
User::all(db)
|
||||||
.await
|
.await
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|user| UserWithWaterStatus::from_user(user, db)),
|
.map(|user| UserWithWaterStatus::from_user(user, db)),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
users.retain(|u| u.roles.contains(&"Donau Linz".into()));
|
|
||||||
|
|
||||||
let logtypes = LogType::all(db).await;
|
let logtypes = LogType::all(db).await;
|
||||||
let distances = Logbook::distances(db).await;
|
let distances = Logbook::distances(db).await;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user