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

@ -14,6 +14,10 @@ impl UserTrip {
return Err(UserTripError::EventAlreadyFull);
}
if user.is_guest && !trip_details.allow_guests {
return Err(UserTripError::GuestNotAllowedForThisEvent);
}
//check if cox if own event
let is_cox = sqlx::query!(
"SELECT count(*) as amount
@ -80,6 +84,7 @@ pub enum UserTripError {
AlreadyRegisteredAsCox,
EventAlreadyFull,
CantRegisterAtOwnEvent,
GuestNotAllowedForThisEvent,
}
#[cfg(test)]
@ -180,4 +185,19 @@ mod test {
assert_eq!(result, UserTripError::AlreadyRegisteredAsCox);
}
#[sqlx::test]
fn test_fail_create_guest() {
let pool = testdb!();
let user = User::find_by_name(&pool, "guest".into()).await.unwrap();
let trip_details = TripDetails::find_by_id(&pool, 1).await.unwrap();
let result = UserTrip::create(&pool, &user, &trip_details)
.await
.expect_err("Not allowed for guests");
assert_eq!(result, UserTripError::GuestNotAllowedForThisEvent);
}
}