Lugh, a new cook, “improved” Bruna's pie by adding anchovies. Bruna is furious. New rule in the kitchen: to each their own dishes. A cook only edits the dishes they invented, and the boss can edit everything.
A role is no longer enough: the right depends on the object (this particular dish) and on who is asking. That's the job of a Voter.
Your mission
- Every dish now remembers its creator (
Plat::$createur, already mapped). InnouveauPlat(), make the logged-in staff member the new dish's creator. - Write
PlatVoter, which decides on thePLAT_MODIFIERattribute (“edit dish”) for aPlat:- nobody logged in: denied;
- the boss: granted;
- the dish's creator: granted;
- everyone else: denied.
- Protect
modifierPlat()with this voter, and only display “Edit” on the dish page if you are allowed to edit this dish.
The historic dishes on the menu have no creator: only the boss can edit them.
Reminder
A voter answers two questions: “do I handle this?” (supports) and, if so, “is it allowed?” (voteOnAttribute). Symfony asks every voter. The ones that don't feel concerned abstain.