Skip to content

Commit

Permalink
Use less restrictive assert (#1760)
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Apr 13, 2024
1 parent 662565b commit 94a8bcc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
13 changes: 8 additions & 5 deletions src/Controller/PageAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@

namespace Sonata\PageBundle\Controller;

use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Controller\CRUDController;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use Sonata\BlockBundle\Block\BlockServiceManagerInterface;
use Sonata\BlockBundle\Block\Service\EditableBlockService;
use Sonata\PageBundle\Admin\BlockAdmin;
use Sonata\PageBundle\Admin\SnapshotAdmin;
use Sonata\PageBundle\Model\BlockInteractorInterface;
use Sonata\PageBundle\Model\PageBlockInterface;
use Sonata\PageBundle\Model\PageInterface;
use Sonata\PageBundle\Model\PageManagerInterface;
use Sonata\PageBundle\Model\SiteManagerInterface;
use Sonata\PageBundle\Page\TemplateManagerInterface;
use Sonata\PageBundle\Service\Contract\CreateSnapshotByPageInterface;
use Sonata\PageBundle\Service\CreateSnapshotService;
use Sonata\PageBundle\Site\SiteSelectorInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
Expand Down Expand Up @@ -62,11 +65,11 @@ public static function getSubscribedServices(): array
public function batchActionSnapshot(ProxyQueryInterface $query): RedirectResponse
{
$snapShotAdmin = $this->container->get('sonata.page.admin.snapshot');
\assert($snapShotAdmin instanceof SnapshotAdmin);
\assert($snapShotAdmin instanceof AdminInterface);
$snapShotAdmin->checkAccess('create');

$createSnapshot = $this->container->get('sonata.page.service.create_snapshot');
\assert($createSnapshot instanceof CreateSnapshotService);
\assert($createSnapshot instanceof CreateSnapshotByPageInterface);
foreach ($query->execute() as $page) {
$createSnapshot->createByPage($page);
}
Expand Down Expand Up @@ -171,7 +174,7 @@ public function composeAction(Request $request): Response
$this->admin->checkAccess('compose');

$blockAdmin = $this->container->get('sonata.page.admin.block');
\assert($blockAdmin instanceof BlockAdmin);
\assert($blockAdmin instanceof AdminInterface);

if (false === $blockAdmin->isGranted('LIST')) {
throw new AccessDeniedException();
Expand Down Expand Up @@ -258,15 +261,15 @@ public function composeAction(Request $request): Response
public function composeContainerShowAction(Request $request): Response
{
$blockAdmin = $this->container->get('sonata.page.admin.block');
\assert($blockAdmin instanceof BlockAdmin);
\assert($blockAdmin instanceof AdminInterface);

if (false === $blockAdmin->isGranted('LIST')) {
throw new AccessDeniedException();
}

$id = $request->get($this->admin->getIdParameter());
$block = $blockAdmin->getObject($id);
if (null === $block) {
if (!$block instanceof PageBlockInterface) {
throw new NotFoundHttpException(sprintf('Unable to find the block with id : %s', $id));
}

Expand Down
6 changes: 4 additions & 2 deletions src/Controller/SiteAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@

namespace Sonata\PageBundle\Controller;

use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Controller\CRUDController;
use Sonata\PageBundle\Admin\SnapshotAdmin;
use Sonata\PageBundle\Model\SiteInterface;
use Sonata\PageBundle\Service\Contract\CreateSnapshotBySiteInterface;
use Sonata\PageBundle\Service\CreateSnapshotService;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -45,7 +47,7 @@ public static function getSubscribedServices(): array
public function snapshotsAction(Request $request): Response
{
$adminSnapshot = $this->container->get('sonata.page.admin.snapshot');
\assert($adminSnapshot instanceof SnapshotAdmin);
\assert($adminSnapshot instanceof AdminInterface);
if (false === $adminSnapshot->isGranted('CREATE')) {
throw new AccessDeniedException();
}
Expand All @@ -62,7 +64,7 @@ public function snapshotsAction(Request $request): Response

if ('POST' === $request->getMethod()) {
$createSnapshot = $this->container->get('sonata.page.service.create_snapshot');
\assert($createSnapshot instanceof CreateSnapshotService);
\assert($createSnapshot instanceof CreateSnapshotBySiteInterface);
$createSnapshot->createBySite($object);

$this->addFlash(
Expand Down

0 comments on commit 94a8bcc

Please sign in to comment.