Skip to content

Commit

Permalink
feature #948 #946 use Voter constants instead of plain explicit strin…
Browse files Browse the repository at this point in the history
…g (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
  • Loading branch information
javiereguiluz committed Feb 25, 2019
2 parents d59a50f + 9ace78f commit 7743c5b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/Controller/Admin/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use App\Entity\Post;
use App\Form\PostType;
use App\Repository\PostRepository;
use App\Security\PostVoter;
use App\Utils\Slugger;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Expand Down Expand Up @@ -119,7 +120,7 @@ public function show(Post $post): Response
{
// This security check can also be performed
// using an annotation: @IsGranted("show", subject="post", message="Posts can only be shown to their authors.")
$this->denyAccessUnlessGranted('show', $post, 'Posts can only be shown to their authors.');
$this->denyAccessUnlessGranted(PostVoter::SHOW, $post, 'Posts can only be shown to their authors.');

return $this->render('admin/blog/show.html.twig', [
'post' => $post,
Expand Down
6 changes: 3 additions & 3 deletions src/Security/PostVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class PostVoter extends Voter
{
// Defining these constants is overkill for this simple application, but for real
// applications, it's a recommended practice to avoid relying on "magic strings"
private const SHOW = 'show';
private const EDIT = 'edit';
private const DELETE = 'delete';
public const DELETE = 'delete';
public const EDIT = 'edit';
public const SHOW = 'show';

/**
* {@inheritdoc}
Expand Down

0 comments on commit 7743c5b

Please sign in to comment.