Compare commits

...

4 Commits

Author SHA1 Message Date
7355d9d69b allow upload of membership pdf
All checks were successful
CI/CD Pipeline / test (push) Successful in 8m6s
CI/CD Pipeline / deploy-staging (push) Has been skipped
CI/CD Pipeline / deploy-main (push) Has been skipped
2024-05-06 13:35:42 +02:00
b4023c1ea8 Merge branch 'main' of ssh://git.hofer.link:2222/Ruderverein-Donau-Linz/rowt 2024-05-06 13:30:17 +02:00
31fda6bee9 Merge pull request 'trim name of new user name' (#479) from trim-new-user-names into main
All checks were successful
CI/CD Pipeline / test (push) Successful in 8m49s
CI/CD Pipeline / deploy-staging (push) Has been skipped
CI/CD Pipeline / deploy-main (push) Successful in 6m23s
Reviewed-on: #479
2024-05-04 18:36:00 +02:00
1d9adf071f trim name of new user name
All checks were successful
CI/CD Pipeline / test (push) Successful in 8m1s
CI/CD Pipeline / deploy-staging (push) Has been skipped
CI/CD Pipeline / deploy-main (push) Has been skipped
2024-05-04 18:19:07 +02:00

View File

@ -245,6 +245,18 @@ impl User {
false false
} }
pub async fn has_membership_pdf(&self, db: &SqlitePool) -> bool {
match sqlx::query_scalar!("SELECT membership_pdf FROM user WHERE id = ?", self.id)
.fetch_one(db)
.await
.unwrap()
{
Some(a) if a.is_empty() => false,
None => false,
_ => true,
}
}
pub async fn roles(&self, db: &SqlitePool) -> Vec<String> { pub async fn roles(&self, db: &SqlitePool) -> Vec<String> {
sqlx::query!( sqlx::query!(
"SELECT r.name FROM role r JOIN user_role ur ON r.id = ur.role_id JOIN user u ON u.id = ur.user_id WHERE ur.user_id = ? AND u.deleted = 0;", "SELECT r.name FROM role r JOIN user_role ur ON r.id = ur.role_id JOIN user u ON u.id = ur.user_id WHERE ur.user_id = ? AND u.deleted = 0;",
@ -434,6 +446,7 @@ ORDER BY last_access DESC
} }
pub async fn create(db: &SqlitePool, name: &str) -> bool { pub async fn create(db: &SqlitePool, name: &str) -> bool {
let name = name.trim();
sqlx::query!("INSERT INTO USER(name) VALUES (?)", name) sqlx::query!("INSERT INTO USER(name) VALUES (?)", name)
.execute(db) .execute(db)
.await .await
@ -447,9 +460,7 @@ ORDER BY last_access DESC
family_id = Some(Family::insert(db).await) family_id = Some(Family::insert(db).await)
} }
let user_with_membershippdf = UserWithMembershipPdf::from(db, self.clone()).await; if !self.has_membership_pdf(db).await {
if user_with_membershippdf.membership_pdf.is_none() {
if let Some(membership_pdf) = data.membership_pdf { if let Some(membership_pdf) = data.membership_pdf {
let mut stream = membership_pdf.open().await.unwrap(); let mut stream = membership_pdf.open().await.unwrap();
let mut buffer = Vec::new(); let mut buffer = Vec::new();
@ -967,16 +978,7 @@ pub struct UserWithRolesAndMembershipPdf {
impl UserWithRolesAndMembershipPdf { impl UserWithRolesAndMembershipPdf {
pub(crate) async fn from_user(db: &SqlitePool, user: User) -> Self { pub(crate) async fn from_user(db: &SqlitePool, user: User) -> Self {
let membership_pdf = let membership_pdf = user.has_membership_pdf(db).await;
match sqlx::query_scalar!("SELECT membership_pdf FROM user WHERE id = ?", user.id)
.fetch_one(db)
.await
.unwrap()
{
Some(a) if a.is_empty() => false,
None => false,
_ => true,
};
Self { Self {
roles: user.roles(db).await, roles: user.roles(db).await,