only allow guests to register for specific events; don't even show them the other trips

This commit is contained in:
2023-04-29 18:57:01 +02:00
parent 5b06eaeebc
commit bb4dba7bc9
12 changed files with 96 additions and 29 deletions

View File

@ -34,6 +34,7 @@ async fn create(
data.max_people,
data.day.clone(),
data.notes.clone(),
data.allow_guests,
data.trip_type,
)
.await;
@ -43,14 +44,7 @@ async fn create(
//the object
//TODO: fix clone()
PlannedEvent::create(
db,
data.name.clone(),
data.planned_amount_cox,
data.allow_guests,
trip_details,
)
.await;
PlannedEvent::create(db, data.name.clone(), data.planned_amount_cox, trip_details).await;
Flash::success(Redirect::to("/"), "Successfully planned the event")
}

View File

@ -22,6 +22,7 @@ struct AddTripForm {
max_people: i32,
notes: Option<String>,
trip_type: Option<i64>,
allow_guests: bool,
}
#[post("/trip", data = "<data>")]
@ -33,6 +34,7 @@ async fn create(db: &State<SqlitePool>, data: Form<AddTripForm>, cox: CoxUser) -
data.max_people,
data.day.clone(),
data.notes.clone(),
data.allow_guests,
data.trip_type,
)
.await;

View File

@ -37,6 +37,7 @@ async fn index(db: &State<SqlitePool>, user: User, flash: Option<FlashMessage<'_
.num_days()
+ 1;
}
if user.is_cox || user.is_admin {
let triptypes = TripType::all(db).await;
context.insert("trip_types", &triptypes);
@ -44,7 +45,12 @@ async fn index(db: &State<SqlitePool>, user: User, flash: Option<FlashMessage<'_
for i in 0..show_next_n_days {
let date = (Local::now() + Duration::days(i)).date_naive();
days.push(Day::new(db, date).await);
if user.is_guest {
days.push(Day::new_guest(db, date).await);
} else {
days.push(Day::new(db, date).await);
}
}
if let Some(msg) = flash {
@ -86,6 +92,10 @@ async fn join(db: &State<SqlitePool>, trip_details_id: i64, user: User) -> Flash
Redirect::to("/"),
"Du kannst bei einer selbst ausgeschriebenen Fahrt nicht mitrudern ;)",
),
Err(UserTripError::GuestNotAllowedForThisEvent) => Flash::error(
Redirect::to("/"),
"Bei dieser Ausfahrt können leider keine Gäste mitfahren.",
),
}
}