1515use App \Form \PostType ;
1616use App \Repository \PostRepository ;
1717use App \Utils \Slugger ;
18+ use Sensio \Bundle \FrameworkExtraBundle \Configuration \IsGranted ;
1819use Sensio \Bundle \FrameworkExtraBundle \Configuration \Security ;
1920use Symfony \Bundle \FrameworkBundle \Controller \AbstractController ;
2021use Symfony \Component \Form \Extension \Core \Type \SubmitType ;
@@ -118,7 +119,7 @@ public function new(Request $request): Response
118119 public function show (Post $ post ): Response
119120 {
120121 // This security check can also be performed
121- // using an annotation: @Security("is_granted(' show', post) ")
122+ // using an annotation: @IsGranted(" show", subject=" post")
122123 $ this ->denyAccessUnlessGranted ('show ' , $ post , 'Posts can only be shown to their authors. ' );
123124
124125 return $ this ->render ('admin/blog/show.html.twig ' , [
@@ -130,11 +131,10 @@ public function show(Post $post): Response
130131 * Displays a form to edit an existing Post entity.
131132 *
132133 * @Route("/{id}/edit", requirements={"id": "\d+"}, methods={"GET", "POST"}, name="admin_post_edit")
134+ * @IsGranted("edit", subject="post", message="Posts can only be edited by their authors.")
133135 */
134136 public function edit (Request $ request , Post $ post ): Response
135137 {
136- $ this ->denyAccessUnlessGranted ('edit ' , $ post , 'Posts can only be edited by their authors. ' );
137-
138138 $ form = $ this ->createForm (PostType::class, $ post );
139139 $ form ->handleRequest ($ request );
140140
@@ -157,7 +157,7 @@ public function edit(Request $request, Post $post): Response
157157 * Deletes a Post entity.
158158 *
159159 * @Route("/{id}/delete", methods={"POST"}, name="admin_post_delete")
160- * @Security("is_granted(' delete', post) ")
160+ * @IsGranted(" delete", subject=" post")
161161 *
162162 * The Security annotation value is an expression (if it evaluates to false,
163163 * the authorization mechanism will prevent the user accessing this resource).
0 commit comments