src/Products/NotificationsBundle/Controller/AbstractDashboardController.php line 76

Open in your IDE?
  1. <?php
  2. namespace Products\NotificationsBundle\Controller;
  3. use App\Controller\AbstractController;
  4. use Cms\TenantBundle\Model\ProductsBitwise;
  5. use Platform\MarketingBundle\Model\ProductControllerInterface;
  6. use Products\NotificationsBundle\Entity\Notifications\Message;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  10. use Symfony\Component\HttpKernel\KernelEvents;
  11. /**
  12.  * Class AbstractDashboardController
  13.  * @package Products\NotificationsBundle\Controller
  14.  */
  15. abstract class AbstractDashboardController extends AbstractController
  16.     implements
  17.         ProductControllerInterface,
  18.         EventSubscriberInterface
  19. {
  20.     /**
  21.      * {@inheritdoc}
  22.      */
  23.     public static function getSubscribedEvents(): array
  24.     {
  25.         return [
  26.             KernelEvents::CONTROLLER => [
  27.                 ['onKernelController'0],
  28.             ],
  29.         ];
  30.     }
  31.     /**
  32.      * @param ControllerEvent $event
  33.      * @return void
  34.      */
  35.     public function onKernelController(ControllerEvent $event): void
  36.     {
  37.         // get the controller
  38.         $controller $event->getController();
  39.         // should be an array of object then method call
  40.         if (is_array($controller) && $controller[0] instanceof static) {
  41.             // 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?
  42.             // AUDIT
  43.             //$this->denyAccessUnlessGranted('campussuite.notifications.manage');
  44.         }
  45.     }
  46.     /**
  47.      * {@inheritdoc}
  48.      */
  49.     public function productCheck(ProductsBitwise $products): ?Response
  50.     {
  51.         if ( ! $products->checkAnyFlag(ProductsBitwise::NOTIFICATIONS__V2)) {
  52.             return $this->redirectToRoute(
  53.                 'platform.marketing.dashboard.default.notifications'
  54.             );
  55.         }
  56.         return null;
  57.     }
  58.     protected function audit(Message $message): void
  59.     {
  60.         if ($message->getLists()->isEmpty()) {
  61.             $this->denyAccessUnlessGranted(
  62.                 sprintf('app.notifications.messaging.%s'$message->isUrgent() ? 'urgent' 'general')
  63.             );
  64.         }
  65.         foreach ($message->getLists() as $list) {
  66.             $this->denyAccessUnlessGranted(
  67.                 sprintf('app.notifications.messaging.%s'$message->isUrgent() ? 'urgent' 'general'), [$list]
  68.             );
  69.         }
  70.     }
  71. }