Merge branch 'privacyEvent'

This commit is contained in:
Tchama 2019-02-28 11:33:38 +01:00
commit 10577e1735
3 changed files with 53 additions and 8 deletions

View File

@ -18,9 +18,11 @@ Version 1.5.3
- the javascript for uploading a file now works within collections, listening to collection events.
`Master` branch
===============
Master branch
=============
- replace default message on download button below dropzone ;
- launch event when dropzone is initialized, to allow to customize events on dropzone;
- add privacy events to document index / show
- add privacy events to document edit / update

View File

@ -5,7 +5,9 @@ namespace Chill\DocStoreBundle\Controller;
use Chill\DocStoreBundle\Entity\PersonDocument;
use Chill\DocStoreBundle\Form\PersonDocumentType;
use Chill\DocStoreBundle\Repository\DocumentRepository;
use Chill\PersonBundle\Privacy\PrivacyEvent;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
@ -29,9 +31,21 @@ class DocumentPersonController extends Controller
*/
protected $translator;
public function __construct(TranslatorInterface $translator)
/**
* @var EventDispatcherInterface
*/
protected $eventDispatcher;
/**
* DocumentPersonController constructor.
*
* @param TranslatorInterface $translator
* @param EventDispatcherInterface $eventDispatcher
*/
public function __construct(TranslatorInterface $translator, EventDispatcherInterface $eventDispatcher)
{
$this->translator = $translator;
$this->eventDispatcher = $eventDispatcher;
}
/**
@ -59,6 +73,12 @@ class DocumentPersonController extends Controller
array('date' => 'DESC')
);
$event = new PrivacyEvent($person, array(
'element_class' => PersonDocument::class,
'action' => 'index'
));
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
return $this->render(
'ChillDocStoreBundle:PersonDocument:index.html.twig',
[
@ -120,6 +140,13 @@ class DocumentPersonController extends Controller
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
$this->denyAccessUnlessGranted('CHILL_PERSON_DOCUMENT_SEE', $document);
$event = new PrivacyEvent($person, array(
'element_class' => PersonDocument::class,
'element_id' => $document->getId(),
'action' => 'show'
));
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
return $this->render(
'ChillDocStoreBundle:PersonDocument:show.html.twig',
['document' => $document, 'person' => $person]);
@ -148,13 +175,28 @@ class DocumentPersonController extends Controller
$this->addFlash('success', $this->translator->trans("The document is successfully updated"));
$event = new PrivacyEvent($person, array(
'element_class' => PersonDocument::class,
'element_id' => $document->getId(),
'action' => 'update'
));
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
return $this->redirectToRoute(
'person_document_edit',
['id' => $document->getId(), 'person' => $person->getId()]);
} elseif ($form->isSubmitted() and !$form->isValid()) {
$this->addFlash('error', $this->translator->trans("This form contains errors"));
}
$event = new PrivacyEvent($person, array(
'element_class' => PersonDocument::class,
'element_id' => $document->getId(),
'action' => 'edit'
));
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
return $this->render(
'ChillDocStoreBundle:PersonDocument:edit.html.twig',
[

View File

@ -5,4 +5,5 @@ services:
Chill\DocStoreBundle\Controller\DocumentPersonController:
autowire: true
arguments:
$eventDispatcher: '@Symfony\Component\EventDispatcher\EventDispatcherInterface'