fix membership application error
All checks were successful
CI/CD Pipeline / test (push) Successful in 11m50s
CI/CD Pipeline / deploy-staging (push) Successful in 6m55s
CI/CD Pipeline / deploy-main (push) Has been skipped

This commit is contained in:
philipp 2024-04-08 19:04:57 +02:00
parent db3158d4e7
commit 3b9103e9aa
3 changed files with 32 additions and 7 deletions

View File

@ -959,6 +959,30 @@ impl Deref for PlannedEventUser {
&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)]
pub struct UserWithMembershipPdf {

View File

@ -5,7 +5,10 @@ use crate::model::{
log::Log,
logbook::Logbook,
role::Role,
user::{AdminUser, User, UserWithMembershipPdf, UserWithRoles, VorstandUser},
user::{
AdminUser, User, UserWithMembershipPdf, UserWithRoles, UserWithRolesAndMembershipPdf,
VorstandUser,
},
};
use futures::future::join_all;
use rocket::{
@ -45,13 +48,13 @@ async fn index(
let user_futures: Vec<_> = User::all(db)
.await
.into_iter()
.map(|u| async move { UserWithRoles::from_user(u, db).await })
.map(|u| async move { UserWithRolesAndMembershipPdf::from_user(db, u).await })
.collect();
let user: User = user.into();
let allowed_to_edit = user.has_role(db, "admin").await;
let users: Vec<UserWithRoles> = join_all(user_futures).await;
let users: Vec<UserWithRolesAndMembershipPdf> = join_all(user_futures).await;
let roles = Role::all(db).await;
let families = Family::all_with_members(db).await;
@ -78,14 +81,13 @@ async fn index_admin(
let user_futures: Vec<_> = User::all(db)
.await
.into_iter()
.map(|u| async move { UserWithRoles::from_user(u, db).await })
.map(|u| async move { UserWithRolesAndMembershipPdf::from_user(db, u).await })
.collect();
let users: Vec<UserWithRolesAndMembershipPdf> = join_all(user_futures).await;
let user: User = user.user;
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 families = Family::all_with_members(db).await;

View File

@ -1,6 +1,5 @@
use std::net::IpAddr;
use futures::{stream, StreamExt};
use rocket::{
form::Form,
get,