From 8ebed08fdc632e8750151cce17bc1dbe1bdd0847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edi=20Modri=C4=87?= Date: Mon, 30 Jan 2017 13:32:22 +0100 Subject: [PATCH] Use denyAccessUnlessGranted method --- Controller/Admin/RelatedContentController.php | 7 +- Controller/Admin/SynonymController.php | 13 +--- Controller/Admin/TagController.php | 73 +++---------------- Controller/Admin/TreeController.php | 7 +- 4 files changed, 16 insertions(+), 84 deletions(-) diff --git a/Controller/Admin/RelatedContentController.php b/Controller/Admin/RelatedContentController.php index 7fc08afc..20c41a40 100644 --- a/Controller/Admin/RelatedContentController.php +++ b/Controller/Admin/RelatedContentController.php @@ -5,7 +5,6 @@ use Netgen\TagsBundle\API\Repository\Values\Tags\Tag; use Pagerfanta\Adapter\AdapterInterface; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\Security\Core\Exception\AccessDeniedException; class RelatedContentController extends Controller { @@ -45,15 +44,11 @@ public function setPagerLimit($pagerLimit) * @param \Symfony\Component\HttpFoundation\Request $request * @param \Netgen\TagsBundle\API\Repository\Values\Tags\Tag $tag * - * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException - * * @return \Symfony\Component\HttpFoundation\Response */ public function relatedContentAction(Request $request, Tag $tag) { - if (!$this->isGranted('ez:tags:read')) { - throw new AccessDeniedException(); - } + $this->denyAccessUnlessGranted('ez:tags:read'); $currentPage = (int)$request->query->get('page'); $pager = $this->createPager($this->adapter, $currentPage, $this->pagerLimit, $tag); diff --git a/Controller/Admin/SynonymController.php b/Controller/Admin/SynonymController.php index e09bfc84..dff0d74e 100644 --- a/Controller/Admin/SynonymController.php +++ b/Controller/Admin/SynonymController.php @@ -6,7 +6,6 @@ use Netgen\TagsBundle\Form\Type\LanguageSelectType; use Netgen\TagsBundle\Form\Type\SynonymCreateType; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\Security\Core\Exception\AccessDeniedException; use Symfony\Component\Translation\TranslatorInterface; class SynonymController extends Controller @@ -40,15 +39,11 @@ public function __construct(TagsService $tagsService, TranslatorInterface $trans * @param \Symfony\Component\HttpFoundation\Request $request * @param int|string $mainTagId * - * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException - * * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response */ public function addSynonymSelectAction(Request $request, $mainTagId) { - if (!$this->isGranted('ez:tags:addsynonym')) { - throw new AccessDeniedException(); - } + $this->denyAccessUnlessGranted('ez:tags:addsynonym'); $form = $this->createForm( LanguageSelectType::class, @@ -86,15 +81,11 @@ public function addSynonymSelectAction(Request $request, $mainTagId) * @param int|string $mainTagId * @param string $languageCode * - * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException - * * @return \Symfony\Component\HttpFoundation\Response */ public function addSynonymAction(Request $request, $mainTagId, $languageCode) { - if (!$this->isGranted('ez:tags:addsynonym')) { - throw new AccessDeniedException(); - } + $this->denyAccessUnlessGranted('ez:tags:addsynonym'); $synonymCreateStruct = $this->tagsService->newSynonymCreateStruct($mainTagId, $languageCode); diff --git a/Controller/Admin/TagController.php b/Controller/Admin/TagController.php index c570d384..28fd114f 100644 --- a/Controller/Admin/TagController.php +++ b/Controller/Admin/TagController.php @@ -20,7 +20,6 @@ use Symfony\Component\HttpFoundation\Request; use eZ\Publish\API\Repository\Values\Content\Query; use eZ\Publish\API\Repository\Values\Content\Query\Criterion; -use Symfony\Component\Security\Core\Exception\AccessDeniedException; use Symfony\Component\Translation\TranslatorInterface; class TagController extends Controller @@ -79,15 +78,11 @@ public function __construct( * @param \Symfony\Component\HttpFoundation\Request $request * @param \Netgen\TagsBundle\API\Repository\Values\Tags\Tag $tag * - * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException - * * @return \Symfony\Component\HttpFoundation\Response */ public function showTagAction(Request $request, Tag $tag = null) { - if (!$this->isGranted('ez:tags:read')) { - throw new AccessDeniedException(); - } + $this->denyAccessUnlessGranted('ez:tags:read'); $data = array(); @@ -132,15 +127,11 @@ public function showTagAction(Request $request, Tag $tag = null) * @param \Symfony\Component\HttpFoundation\Request $request * @param \Netgen\TagsBundle\API\Repository\Values\Tags\Tag $parentTag * - * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException - * * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response */ public function addTagSelectAction(Request $request, Tag $parentTag = null) { - if (!$this->isGranted('ez:tags:add', $parentTag)) { - throw new AccessDeniedException(); - } + $this->denyAccessUnlessGranted('ez:tags:add', $parentTag); $form = $this->createForm( LanguageSelectType::class, @@ -178,15 +169,11 @@ public function addTagSelectAction(Request $request, Tag $parentTag = null) * @param string $languageCode * @param \Netgen\TagsBundle\API\Repository\Values\Tags\Tag $parentTag * - * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException - * * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response */ public function addTagAction(Request $request, $languageCode, Tag $parentTag = null) { - if (!$this->isGranted('ez:tags:add', $parentTag)) { - throw new AccessDeniedException(); - } + $this->denyAccessUnlessGranted('ez:tags:add', $parentTag); $tagCreateStruct = $this->tagsService->newTagCreateStruct( $parentTag ? $parentTag->id : 0, @@ -227,15 +214,11 @@ public function addTagAction(Request $request, $languageCode, Tag $parentTag = n * @param \Symfony\Component\HttpFoundation\Request $request * @param \Netgen\TagsBundle\API\Repository\Values\Tags\Tag $tag * - * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException - * * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response */ public function updateTagSelectAction(Request $request, Tag $tag) { - if (!$this->isGranted('ez:tags:edit' . ($tag->isSynonym() ? 'synonym' : ''))) { - throw new AccessDeniedException(); - } + $this->denyAccessUnlessGranted('ez:tags:edit' . ($tag->isSynonym() ? 'synonym' : '')); $form = $this->createForm( LanguageSelectType::class, @@ -275,15 +258,11 @@ public function updateTagSelectAction(Request $request, Tag $tag) * @param \Netgen\TagsBundle\API\Repository\Values\Tags\Tag $tag * @param string $languageCode * - * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException - * * @return \Symfony\Component\HttpFoundation\Response */ public function updateTagAction(Request $request, Tag $tag, $languageCode) { - if (!$this->isGranted('ez:tags:edit' . ($tag->isSynonym() ? 'synonym' : ''))) { - throw new AccessDeniedException(); - } + $this->denyAccessUnlessGranted('ez:tags:edit' . ($tag->isSynonym() ? 'synonym' : '')); $tagUpdateStruct = $this->tagsService->newTagUpdateStruct(); $tagUpdateStruct->remoteId = $tag->remoteId; @@ -330,15 +309,11 @@ public function updateTagAction(Request $request, Tag $tag, $languageCode) * @param \Symfony\Component\HttpFoundation\Request $request * @param \Netgen\TagsBundle\API\Repository\Values\Tags\Tag $tag * - * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException - * * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response */ public function deleteTagAction(Request $request, Tag $tag) { - if (!$this->isGranted('ez:tags:delete' . ($tag->isSynonym() ? 'synonym' : ''))) { - throw new AccessDeniedException(); - } + $this->denyAccessUnlessGranted('ez:tags:delete' . ($tag->isSynonym() ? 'synonym' : '')); if ($request->request->has('DeleteTagButton')) { if (!$this->isCsrfTokenValid('eztags_admin', $request->request->get('_csrf_token'))) { @@ -370,15 +345,11 @@ public function deleteTagAction(Request $request, Tag $tag) * @param \Symfony\Component\HttpFoundation\Request $request * @param \Netgen\TagsBundle\API\Repository\Values\Tags\Tag $tag * - * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException - * * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response */ public function mergeTagAction(Request $request, Tag $tag) { - if (!$this->isGranted('ez:tags:merge')) { - throw new AccessDeniedException(); - } + $this->denyAccessUnlessGranted('ez:tags:merge'); $form = $this->createForm( TagMergeType::class, @@ -425,15 +396,11 @@ public function mergeTagAction(Request $request, Tag $tag) * @param \Symfony\Component\HttpFoundation\Request $request * @param \Netgen\TagsBundle\API\Repository\Values\Tags\Tag $tag * - * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException - * * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response */ public function convertToSynonymAction(Request $request, Tag $tag) { - if (!$this->isGranted('ez:tags:makesynonym')) { - throw new AccessDeniedException(); - } + $this->denyAccessUnlessGranted('ez:tags:makesynonym'); $form = $this->createForm( TagConvertType::class, @@ -480,15 +447,11 @@ public function convertToSynonymAction(Request $request, Tag $tag) * @param \Symfony\Component\HttpFoundation\Request $request * @param \Netgen\TagsBundle\API\Repository\Values\Tags\Tag $tag * - * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException - * * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response */ public function translationAction(Request $request, Tag $tag) { - if (!$this->isGranted('ez:tags:edit' . ($tag->isSynonym() ? 'synonym' : ''))) { - throw new AccessDeniedException(); - } + $this->denyAccessUnlessGranted('ez:tags:edit' . ($tag->isSynonym() ? 'synonym' : '')); if (!$this->isCsrfTokenValid('eztags_admin', $request->request->get('_csrf_token'))) { $this->addFlashMessage('errors', 'invalid_csrf_token'); @@ -608,15 +571,11 @@ public function childrenAction(Request $request, Tag $tag = null) * @param \Symfony\Component\HttpFoundation\Request $request * @param \Netgen\TagsBundle\API\Repository\Values\Tags\Tag $parentTag * - * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException - * * @return \Symfony\Component\HttpFoundation\Response */ public function moveTagsAction(Request $request, Tag $parentTag = null) { - if (!$this->isGranted('ez:tags:edit')) { - throw new AccessDeniedException(); - } + $this->denyAccessUnlessGranted('ez:tags:edit'); $tagIds = $request->request->has('Tags') ? $request->request->get('Tags') : @@ -678,15 +637,11 @@ public function moveTagsAction(Request $request, Tag $parentTag = null) * @param \Symfony\Component\HttpFoundation\Request $request * @param \Netgen\TagsBundle\API\Repository\Values\Tags\Tag $parentTag * - * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException - * * @return \Symfony\Component\HttpFoundation\Response */ public function copyTagsAction(Request $request, Tag $parentTag = null) { - if (!$this->isGranted('ez:tags:read')) { - throw new AccessDeniedException(); - } + $this->denyAccessUnlessGranted('ez:tags:read'); $tagIds = $request->request->has('Tags') ? $request->request->get('Tags') : @@ -748,15 +703,11 @@ public function copyTagsAction(Request $request, Tag $parentTag = null) * @param \Symfony\Component\HttpFoundation\Request $request * @param \Netgen\TagsBundle\API\Repository\Values\Tags\Tag $parentTag * - * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException - * * @return \Symfony\Component\HttpFoundation\Response */ public function deleteTagsAction(Request $request, Tag $parentTag = null) { - if (!$this->isGranted('ez:tags:delete')) { - throw new AccessDeniedException(); - } + $this->denyAccessUnlessGranted('ez:tags:delete'); $tagIds = $request->request->has('Tags') ? $request->request->get('Tags') : diff --git a/Controller/Admin/TreeController.php b/Controller/Admin/TreeController.php index 5c5dd9b9..a2baa2ae 100644 --- a/Controller/Admin/TreeController.php +++ b/Controller/Admin/TreeController.php @@ -5,7 +5,6 @@ use Netgen\TagsBundle\API\Repository\TagsService; use Netgen\TagsBundle\API\Repository\Values\Tags\Tag; use Symfony\Component\HttpFoundation\JsonResponse; -use Symfony\Component\Security\Core\Exception\AccessDeniedException; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Translation\TranslatorInterface; @@ -83,15 +82,11 @@ public function __construct( * @param int * @param bool $isRoot * - * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException - * * @return \Symfony\Component\HttpFoundation\JsonResponse */ public function getChildrenAction(Tag $tag = null, $isRoot = false) { - if (!$this->isGranted('ez:tags:read')) { - throw new AccessDeniedException(); - } + $this->denyAccessUnlessGranted('ez:tags:read'); $result = array();