create member type
This commit is contained in:
@ -2,14 +2,14 @@ use std::ops::DerefMut;
|
||||
|
||||
use chrono::{Datelike, Duration, Local, NaiveDateTime};
|
||||
use rocket::FromForm;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::{FromRow, Sqlite, SqlitePool, Transaction};
|
||||
|
||||
use super::{
|
||||
boat::Boat, log::Log, notification::Notification, role::Role, rower::Rower, user::User,
|
||||
};
|
||||
|
||||
#[derive(FromRow, Serialize, Clone, Debug)]
|
||||
#[derive(FromRow, Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct Logbook {
|
||||
pub id: i64,
|
||||
pub boat_id: i64,
|
||||
@ -105,7 +105,7 @@ impl TryFrom<LogToAdd> for LogToFinalize {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct LogbookWithBoatAndRowers {
|
||||
#[serde(flatten)]
|
||||
pub logbook: Logbook,
|
||||
|
44
src/model/user/member.rs
Normal file
44
src/model/user/member.rs
Normal file
@ -0,0 +1,44 @@
|
||||
use super::ScheckbuchUser;
|
||||
use crate::model::{
|
||||
logbook::{Logbook, LogbookWithBoatAndRowers},
|
||||
user::User,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::SqlitePool;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub(crate) enum Member {
|
||||
SchnupperInterest(User),
|
||||
Schnupperant(User),
|
||||
Scheckbuch(Vec<LogbookWithBoatAndRowers>),
|
||||
Regular(User),
|
||||
Foerdernd(User),
|
||||
Unterstuetzend(User),
|
||||
}
|
||||
|
||||
impl Member {
|
||||
pub(crate) async fn from(db: &SqlitePool, user: User) -> Self {
|
||||
if ScheckbuchUser::new(db, &user).await.is_some() {
|
||||
Self::Scheckbuch(Logbook::completed_with_user(db, &user).await)
|
||||
} else if user.has_role(db, "schnupper-interessierte").await {
|
||||
Self::SchnupperInterest(user)
|
||||
} else if user.has_role(db, "schnupperant").await {
|
||||
Self::Schnupperant(user)
|
||||
} else if user.has_role(db, "Donau Linz").await {
|
||||
Self::Regular(user)
|
||||
} else if user.has_role(db, "Förderndes Mitglied").await {
|
||||
Self::Foerdernd(user)
|
||||
} else if user.has_role(db, "Unterstützend").await {
|
||||
Self::Unterstuetzend(user)
|
||||
} else {
|
||||
panic!("User {user} has no membership_type!!");
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn is_club_member(&self) -> bool {
|
||||
match self {
|
||||
Member::Regular(_) | Member::Foerdernd(_) | Member::Unterstuetzend(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
@ -34,6 +34,7 @@ use scheckbuch::ScheckbuchUser;
|
||||
|
||||
mod basic;
|
||||
mod fee;
|
||||
pub(crate) mod member;
|
||||
mod scheckbuch;
|
||||
|
||||
#[derive(FromRow, Serialize, Deserialize, Clone, Debug, Eq, Hash, PartialEq)]
|
||||
@ -1015,7 +1016,6 @@ special_user!(AllowedToEditPaymentStatusUser, +"kassier", +"admin");
|
||||
special_user!(ManageUserUser, +"admin", +"schriftfuehrer");
|
||||
special_user!(AllowedToSendFeeReminderUser, +"admin", +"schriftfuehrer", +"kassier");
|
||||
special_user!(AllowedToUpdateTripToAlwaysBeShownUser, +"admin");
|
||||
special_user!(ClubMember, +"Donau Linz");
|
||||
|
||||
#[derive(FromRow, Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct UserWithRolesAndMembershipPdf {
|
||||
|
@ -7,7 +7,7 @@ use crate::{
|
||||
logbook::Logbook,
|
||||
role::Role,
|
||||
user::{
|
||||
AdminUser, AllowedToEditPaymentStatusUser, ClubMember, ManageUserUser, User,
|
||||
member::Member, AdminUser, AllowedToEditPaymentStatusUser, ManageUserUser, User,
|
||||
UserWithDetails, UserWithMembershipPdf, UserWithRolesAndMembershipPdf, VorstandUser,
|
||||
},
|
||||
},
|
||||
@ -125,7 +125,8 @@ async fn view(
|
||||
format!("User mit ID {} gibts ned", user),
|
||||
));
|
||||
};
|
||||
let clubmember = ClubMember::new(db, &user).await;
|
||||
|
||||
let member = Member::from(db, user.clone()).await;
|
||||
|
||||
let user = UserWithRolesAndMembershipPdf::from_user(db, user).await;
|
||||
|
||||
@ -141,7 +142,8 @@ async fn view(
|
||||
}
|
||||
context.insert("allowed_to_edit", &allowed_to_edit);
|
||||
context.insert("user", &user);
|
||||
context.insert("clubmember", &clubmember);
|
||||
context.insert("is_clubmember", &member.is_club_member());
|
||||
context.insert("member", &member);
|
||||
context.insert("roles", &roles);
|
||||
context.insert("families", &families);
|
||||
context.insert(
|
||||
|
Reference in New Issue
Block a user