15
15
use App \Form \PostType ;
16
16
use App \Repository \PostRepository ;
17
17
use App \Utils \Slugger ;
18
+ use Sensio \Bundle \FrameworkExtraBundle \Configuration \IsGranted ;
18
19
use Sensio \Bundle \FrameworkExtraBundle \Configuration \Security ;
19
20
use Symfony \Bundle \FrameworkBundle \Controller \AbstractController ;
20
21
use Symfony \Component \Form \Extension \Core \Type \SubmitType ;
@@ -118,7 +119,7 @@ public function new(Request $request): Response
118
119
public function show (Post $ post ): Response
119
120
{
120
121
// This security check can also be performed
121
- // using an annotation: @Security("is_granted(' show', post) ")
122
+ // using an annotation: @IsGranted(" show", subject=" post")
122
123
$ this ->denyAccessUnlessGranted ('show ' , $ post , 'Posts can only be shown to their authors. ' );
123
124
124
125
return $ this ->render ('admin/blog/show.html.twig ' , [
@@ -130,11 +131,10 @@ public function show(Post $post): Response
130
131
* Displays a form to edit an existing Post entity.
131
132
*
132
133
* @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.")
133
135
*/
134
136
public function edit (Request $ request , Post $ post ): Response
135
137
{
136
- $ this ->denyAccessUnlessGranted ('edit ' , $ post , 'Posts can only be edited by their authors. ' );
137
-
138
138
$ form = $ this ->createForm (PostType::class, $ post );
139
139
$ form ->handleRequest ($ request );
140
140
@@ -157,7 +157,7 @@ public function edit(Request $request, Post $post): Response
157
157
* Deletes a Post entity.
158
158
*
159
159
* @Route("/{id}/delete", methods={"POST"}, name="admin_post_delete")
160
- * @Security("is_granted(' delete', post) ")
160
+ * @IsGranted(" delete", subject=" post")
161
161
*
162
162
* The Security annotation value is an expression (if it evaluates to false,
163
163
* the authorization mechanism will prevent the user accessing this resource).
0 commit comments