Gorm's reservation book

Exercise 4 of 6 in chapter 10 · 290 XP · 5 objectives checked by tests

Topics covered: Transitions from a controllerGuards#[AsGuardListener]TransitionBlockerworkflow_transitions()

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:

Guards

A guard prevents a transition under certain conditions. There are two ways to write one:

Guards apply everywhere: can(), apply(), and even in Twig. The reservation book (RegistreController, registre = reservation book) only displays the allowed buttons.

Your mission

  1. 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.
  2. Only the boss can cancel.
  3. 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).
  4. 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.