Compare commits

...

3 Commits

4 changed files with 38 additions and 27 deletions

View File

@@ -11,12 +11,15 @@ declare(strict_types=1);
namespace Chill\ReportBundle\Controller; namespace Chill\ReportBundle\Controller;
use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter;
use Chill\MainBundle\Pagination\PaginatorFactory; use Chill\MainBundle\Pagination\PaginatorFactory;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper; use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Privacy\PrivacyEvent; use Chill\PersonBundle\Privacy\PrivacyEvent;
use Chill\ReportBundle\Entity\Report; use Chill\ReportBundle\Entity\Report;
use Chill\ReportBundle\Form\ReportType; use Chill\ReportBundle\Form\ReportType;
use Chill\ReportBundle\Security\Authorization\ReportVoter;
use DateTime; use DateTime;
use RuntimeException; use RuntimeException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@@ -25,7 +28,7 @@ use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\FormType; use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Role\Role; use Symfony\Component\Security\Core\Role\Role;
use Symfony\Component\Security\Core\Security;
use function count; use function count;
/** /**
@@ -48,17 +51,25 @@ class ReportController extends AbstractController
*/ */
protected $paginator; protected $paginator;
private CenterResolverManagerInterface $centerResolverManager;
private Security $security;
/** /**
* ReportController constructor. * ReportController constructor.
*/ */
public function __construct( public function __construct(
EventDispatcherInterface $eventDispatcher, EventDispatcherInterface $eventDispatcher,
AuthorizationHelper $authorizationHelper, AuthorizationHelper $authorizationHelper,
PaginatorFactory $paginator PaginatorFactory $paginator,
CenterResolverManagerInterface $centerResolverManager,
Security $security
) { ) {
$this->eventDispatcher = $eventDispatcher; $this->eventDispatcher = $eventDispatcher;
$this->authorizationHelper = $authorizationHelper; $this->authorizationHelper = $authorizationHelper;
$this->paginator = $paginator; $this->paginator = $paginator;
$this->centerResolverManager = $centerResolverManager;
$this->security = $security;
} }
/** /**
@@ -120,7 +131,7 @@ class ReportController extends AbstractController
->trans('The form is not valid. The report has not been created !') ->trans('The form is not valid. The report has not been created !')
); );
return $this->render('ChillReportBundle:Report:new.html.twig', [ return $this->render('@ChillReport/Report/new.html.twig', [
'entity' => $entity, 'entity' => $entity,
'form' => $form->createView(), 'form' => $form->createView(),
'person' => $person, 'person' => $person,
@@ -140,7 +151,7 @@ class ReportController extends AbstractController
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
/** @var Report $report */ /** @var Report $report */
$report = $em->getRepository('ChillReportBundle:Report')->find($report_id); $report = $em->getRepository(Report::class)->find($report_id);
if (!$report) { if (!$report) {
throw $this->createNotFoundException( throw $this->createNotFoundException(
@@ -189,7 +200,7 @@ class ReportController extends AbstractController
$cFGroup = $em->getRepository(\Chill\CustomFieldsBundle\Entity\CustomFieldsGroup::class)->find($cf_group_id); $cFGroup = $em->getRepository(\Chill\CustomFieldsBundle\Entity\CustomFieldsGroup::class)->find($cf_group_id);
$reports = $em->getRepository('ChillReportBundle:Report')->findByCFGroup($cFGroup); $reports = $em->getRepository('ChillReportBundle:Report')->findByCFGroup($cFGroup);
$response = $this->render('ChillReportBundle:Report:export.csv.twig', [ $response = $this->render('@ChillReport/Report/export.csv.twig', [
'reports' => $reports, 'reports' => $reports,
'cf_group' => $cFGroup, 'cf_group' => $cFGroup,
]); ]);
@@ -218,9 +229,9 @@ class ReportController extends AbstractController
$reachableScopes = $this->authorizationHelper $reachableScopes = $this->authorizationHelper
->getReachableScopes( ->getReachableScopes(
$this->getUser(), $this->security->getUser(),
new Role('CHILL_REPORT_SEE'), ReportVoter::SEE,
$person->getCenter() $this->centerResolverManager->resolveCenters($person)
); );
$total = $em $total = $em
@@ -298,7 +309,7 @@ class ReportController extends AbstractController
$form = $this->createCreateForm($entity, $person, $cFGroup); $form = $this->createCreateForm($entity, $person, $cFGroup);
return $this->render('ChillReportBundle:Report:new.html.twig', [ return $this->render('@ChillReport/Report/new.html.twig', [
'entity' => $entity, 'entity' => $entity,
'form' => $form->createView(), 'form' => $form->createView(),
'person' => $person, 'person' => $person,
@@ -515,7 +526,7 @@ class ReportController extends AbstractController
$person = $em->getRepository(\Chill\PersonBundle\Entity\Person::class)->find($person_id); $person = $em->getRepository(\Chill\PersonBundle\Entity\Person::class)->find($person_id);
$entity = $em->getRepository('ChillReportBundle:Report')->find($report_id); $entity = $em->getRepository(Report::class)->find($report_id);
if (!$entity || !$person) { if (!$entity || !$person) {
throw $this->createNotFoundException( throw $this->createNotFoundException(
@@ -532,7 +543,7 @@ class ReportController extends AbstractController
]); ]);
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
return $this->render('ChillReportBundle:Report:view.html.twig', [ return $this->render('@ChillReport/Report/view.html.twig', [
'entity' => $entity, 'entity' => $entity,
'person' => $person, 'person' => $person,
]); ]);
@@ -578,8 +589,8 @@ class ReportController extends AbstractController
), ),
'method' => 'PUT', 'method' => 'PUT',
'cFGroup' => $entity->getCFGroup(), 'cFGroup' => $entity->getCFGroup(),
'role' => new Role('CHILL_REPORT_UPDATE'), //'role' => ReportVoter::UPDATE,
'center' => $entity->getPerson()->getCenter(), //'center' => $this->centerResolverManager->resolveCenters($entity->getPerson()),
]); ]);
} }
} }

View File

@@ -74,15 +74,15 @@ class ReportType extends AbstractType
'group' => $options['cFGroup'], ] 'group' => $options['cFGroup'], ]
); );
$this->appendScopeChoices( //$this->appendScopeChoices(
$builder, // $builder,
$options['role'], // $options['role'],
$options['center'], // $options['center'],
$this->user, // $this->user,
$this->authorizationHelper, // $this->authorizationHelper,
$this->translatableStringHelper, // $this->translatableStringHelper,
$this->om // $this->om
); //);
} }
public function configureOptions(OptionsResolver $resolver) public function configureOptions(OptionsResolver $resolver)
@@ -97,7 +97,7 @@ class ReportType extends AbstractType
$resolver->setAllowedTypes('cFGroup', 'Chill\CustomFieldsBundle\Entity\CustomFieldsGroup'); $resolver->setAllowedTypes('cFGroup', 'Chill\CustomFieldsBundle\Entity\CustomFieldsGroup');
$this->appendScopeChoicesOptions($resolver); //$this->appendScopeChoicesOptions($resolver);
} }
/** /**

View File

@@ -25,7 +25,9 @@
{{ form_row(edit_form.user) }} {{ form_row(edit_form.user) }}
{{ form_row(edit_form.date) }} {{ form_row(edit_form.date) }}
{#
{{ form_row(edit_form.scope) }} {{ form_row(edit_form.scope) }}
#}
{{ form_row(edit_form.cFData) }} {{ form_row(edit_form.cFData) }}
{{ form_widget(edit_form) }} {{ form_widget(edit_form) }}

View File

@@ -1,7 +1,5 @@
services: services:
Chill\ReportBundle\Controller\ReportController: Chill\ReportBundle\Controller\ReportController:
arguments: autowire: true
$eventDispatcher: '@Symfony\Component\EventDispatcher\EventDispatcherInterface' autoconfigure: true
$authorizationHelper: '@Chill\MainBundle\Security\Authorization\AuthorizationHelper'
$paginator: '@Chill\MainBundle\Pagination\PaginatorFactory'
tags: ['controller.service_arguments'] tags: ['controller.service_arguments']