Skip to content

Commit 7743c5b

Browse files
committed
feature #948 #946 use Voter constants instead of plain explicit string (inmarelibero)
This PR was squashed before being merged into the master branch (closes #948). Discussion ---------- #946 use Voter constants instead of plain explicit string address issue #946 Commits ------- 9ace78f #946 use Voter constants instead of plain explicit string
2 parents d59a50f + 9ace78f commit 7743c5b

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/Controller/Admin/BlogController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use App\Entity\Post;
1515
use App\Form\PostType;
1616
use App\Repository\PostRepository;
17+
use App\Security\PostVoter;
1718
use App\Utils\Slugger;
1819
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
1920
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@@ -119,7 +120,7 @@ public function show(Post $post): Response
119120
{
120121
// This security check can also be performed
121122
// using an annotation: @IsGranted("show", subject="post", message="Posts can only be shown to their authors.")
122-
$this->denyAccessUnlessGranted('show', $post, 'Posts can only be shown to their authors.');
123+
$this->denyAccessUnlessGranted(PostVoter::SHOW, $post, 'Posts can only be shown to their authors.');
123124

124125
return $this->render('admin/blog/show.html.twig', [
125126
'post' => $post,

src/Security/PostVoter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ class PostVoter extends Voter
2828
{
2929
// Defining these constants is overkill for this simple application, but for real
3030
// applications, it's a recommended practice to avoid relying on "magic strings"
31-
private const SHOW = 'show';
32-
private const EDIT = 'edit';
33-
private const DELETE = 'delete';
31+
public const DELETE = 'delete';
32+
public const EDIT = 'edit';
33+
public const SHOW = 'show';
3434

3535
/**
3636
* {@inheritdoc}

0 commit comments

Comments
 (0)