<?php
namespace Products\NotificationsBundle\Controller;
use App\Controller\AbstractController;
use Cms\TenantBundle\Model\ProductsBitwise;
use Platform\MarketingBundle\Model\ProductControllerInterface;
use Products\NotificationsBundle\Entity\Notifications\Message;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\KernelEvents;
/**
* Class AbstractDashboardController
* @package Products\NotificationsBundle\Controller
*/
abstract class AbstractDashboardController extends AbstractController
implements
ProductControllerInterface,
EventSubscriberInterface
{
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents(): array
{
return [
KernelEvents::CONTROLLER => [
['onKernelController', 0],
],
];
}
/**
* @param ControllerEvent $event
* @return void
*/
public function onKernelController(ControllerEvent $event): void
{
// get the controller
$controller = $event->getController();
// should be an array of object then method call
if (is_array($controller) && $controller[0] instanceof static) {
// TODO: any way we can update this as some kind of catchall, or do we just need to ensure we're checking perms in other places?
// AUDIT
//$this->denyAccessUnlessGranted('campussuite.notifications.manage');
}
}
/**
* {@inheritdoc}
*/
public function productCheck(ProductsBitwise $products): ?Response
{
if ( ! $products->checkAnyFlag(ProductsBitwise::NOTIFICATIONS__V2)) {
return $this->redirectToRoute(
'platform.marketing.dashboard.default.notifications'
);
}
return null;
}
protected function audit(Message $message): void
{
if ($message->getLists()->isEmpty()) {
$this->denyAccessUnlessGranted(
sprintf('app.notifications.messaging.%s', $message->isUrgent() ? 'urgent' : 'general')
);
}
foreach ($message->getLists() as $list) {
$this->denyAccessUnlessGranted(
sprintf('app.notifications.messaging.%s', $message->isUrgent() ? 'urgent' : 'general'), [$list]
);
}
}
}