Gorm keeps the reservation book in an old notebook full of crossings-out. Pippin has prepared a page for him, /kitchen/reservations, which lists the reservations and offers a button for each possible transition. All that is left is to make these buttons work, and to set two house rules:
- only Gorm, the boss, cancels a reservation;
- a reservation is only honored from the day of the meal onwards.
Guards
A guard prevents a transition under certain conditions. There are two ways to write one:
- an expression in the configuration (
guard: "is_granted('ROLE_PATRON')"), for simple rules; - a guard listener (
#[AsGuardListener]), for rules that need code. It can explain its refusal with aTransitionBlocker.
Guards apply everywhere: can(), apply(), and even in Twig. The reservation book (RegistreController, registre = reservation book) only displays the allowed buttons.
Your mission
- Make the reservation book's buttons work: a valid CSRF token, the transition if it is possible, a message, then back to the reservation book.
- Only the boss can cancel.
- A reservation is not honored before its day, and the reservation book explains why (“The meal has not taken place yet”). Write the guard in
PasAvantLeRepas(not before the meal). - An impossible transition, or one that does not exist, is explained in an error message, without a 500 error.
To try it out: log in with bruna@drunken-dragon.me / cauldron (cook), then with gorm@drunken-dragon.me / barrel (boss), and open the Reservation book. The app:ouvrir-le-registre command (open the reservation book) has written a few reservations into it.