privacyEvent, add event on list and view actions

This commit is contained in:
Mat 2018-10-16 12:25:50 +02:00
parent b4c9cf06be
commit 43a2e4705f
3 changed files with 38 additions and 1 deletions

View File

@ -21,6 +21,8 @@
namespace Chill\ReportBundle\Controller; namespace Chill\ReportBundle\Controller;
use Chill\PersonBundle\Privacy\PrivacyEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
@ -38,6 +40,22 @@ use Chill\ReportBundle\Form\ReportType;
*/ */
class ReportController extends Controller class ReportController extends Controller
{ {
/**
* @var EventDispatcherInterface
*/
protected $eventDispatcher;
/**
* ReportController constructor.
*
* @param EventDispatcherInterface $eventDispatcher
*/
public function __construct(EventDispatcherInterface $eventDispatcher)
{
$this->eventDispatcher = $eventDispatcher;
}
/** /**
* List all the report entities for a given person. * List all the report entities for a given person.
* *
@ -78,6 +96,12 @@ class ReportController extends Controller
->getResult() ->getResult()
; ;
$event = new PrivacyEvent($person, array(
'element_class' => Report::class,
'action' => 'list'
));
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
return $this->render('ChillReportBundle:Report:list.html.twig', array( return $this->render('ChillReportBundle:Report:list.html.twig', array(
'reports' => $reports, 'reports' => $reports,
'person' => $person, 'person' => $person,
@ -379,7 +403,15 @@ class ReportController extends Controller
} }
$this->denyAccessUnlessGranted('CHILL_REPORT_SEE', $entity); $this->denyAccessUnlessGranted('CHILL_REPORT_SEE', $entity);
$event = new PrivacyEvent($person, array(
'element_class' => Report::class,
'element_id' => intval($report_id),
'action' => 'view'
));
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
return $this->render('ChillReportBundle:Report:view.html.twig', array( return $this->render('ChillReportBundle:Report:view.html.twig', array(
'entity' => $entity, 'entity' => $entity,
'person' => $person, 'person' => $person,

View File

@ -29,6 +29,7 @@ class ChillReportExtension extends Extension implements PrependExtensionInterfac
$loader->load('services.yml'); $loader->load('services.yml');
$loader->load('services/fixtures.yml'); $loader->load('services/fixtures.yml');
$loader->load('services/export.yml'); $loader->load('services/export.yml');
$loader->load('services/controller.yml');
} }
/** /**

View File

@ -0,0 +1,4 @@
services:
Chill\ReportBundle\Controller\ReportController:
arguments:
$eventDispatcher: '@Symfony\Component\EventDispatcher\EventDispatcherInterface'