Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
3.63% |
15 / 413 |
|
26.09% |
6 / 23 |
CRAP | |
0.00% |
0 / 1 |
TreatmentController | |
3.63% |
15 / 413 |
|
26.09% |
6 / 23 |
11744.78 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
getDomain | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getModel | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getModelClass | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getFormType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
listAction | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
30 | |||
reportAction | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
configurationAction | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
42 | |||
publicListAction | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
12 | |||
publicShowAction | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
20 | |||
apiGetTreatmentsByCollectivity | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
30 | |||
listDataTables | |
0.00% |
0 / 57 |
|
0.00% |
0 / 1 |
702 | |||
countSensitiveData | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
20 | |||
getAvisAipd | |
0.00% |
0 / 26 |
|
0.00% |
0 / 1 |
72 | |||
getTreatmentConformity | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
30 | |||
getSpecificTraitement | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
90 | |||
generateActionCellContent | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
30 | |||
pdfAllAction | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
12 | |||
archiveAllAction | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
archiveConfirmationAction | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
90 | |||
deleteAllAction | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
deleteConfirmationAllAction | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
90 | |||
getLabelAndKeysArray | |
0.00% |
0 / 86 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | /** |
4 | * This file is part of the MADIS - RGPD Management application. |
5 | * |
6 | * @copyright Copyright (c) 2018-2019 Soluris - Solutions Numériques Territoriales Innovantes |
7 | * |
8 | * This program is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU Affero General Public License as published by |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU Affero General Public License for more details. |
17 | * |
18 | * You should have received a copy of the GNU Affero General Public License |
19 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
20 | */ |
21 | |
22 | declare(strict_types=1); |
23 | |
24 | namespace App\Domain\Registry\Controller; |
25 | |
26 | use App\Application\Controller\CRUDController; |
27 | use App\Application\Symfony\Security\UserProvider; |
28 | use App\Application\Traits\ServersideDatatablesTrait; |
29 | use App\Domain\Documentation\Model\Category; |
30 | use App\Domain\Registry\Calculator\Completion\ConformiteTraitementCompletion; |
31 | use App\Domain\Registry\Dictionary\ConformiteTraitementLevelDictionary; |
32 | use App\Domain\Registry\Dictionary\TreatmentAuthorDictionary; |
33 | use App\Domain\Registry\Dictionary\TreatmentLegalBasisDictionary; |
34 | use App\Domain\Registry\Dictionary\TreatmentStatutDictionary; |
35 | use App\Domain\Registry\Form\Type\TreatmentConfigurationType; |
36 | use App\Domain\Registry\Form\Type\TreatmentType; |
37 | use App\Domain\Registry\Model\PublicConfiguration; |
38 | use App\Domain\Registry\Model\Treatment; |
39 | use App\Domain\Registry\Repository; |
40 | use App\Domain\Reporting\Handler\WordHandler; |
41 | use App\Domain\User\Dictionary\UserRoleDictionary; |
42 | use App\Domain\User\Model as UserModel; |
43 | use App\Domain\User\Model\Collectivity; |
44 | use App\Domain\User\Repository as UserRepository; |
45 | use Doctrine\ORM\EntityManagerInterface; |
46 | use Doctrine\ORM\Tools\Pagination\Paginator; |
47 | use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse; |
48 | use Knp\Snappy\Pdf; |
49 | use Symfony\Component\HttpFoundation\JsonResponse; |
50 | use Symfony\Component\HttpFoundation\Request; |
51 | use Symfony\Component\HttpFoundation\RequestStack; |
52 | use Symfony\Component\HttpFoundation\Response; |
53 | use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; |
54 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
55 | use Symfony\Component\Routing\RouterInterface; |
56 | use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; |
57 | use Symfony\Contracts\Translation\TranslatorInterface; |
58 | |
59 | /** |
60 | * @property Repository\Treatment $repository |
61 | */ |
62 | class TreatmentController extends CRUDController |
63 | { |
64 | use ServersideDatatablesTrait; |
65 | |
66 | /** |
67 | * @var UserRepository\Collectivity |
68 | */ |
69 | protected $collectivityRepository; |
70 | /** |
71 | * @var RequestStack |
72 | */ |
73 | protected $requestStack; |
74 | |
75 | /** |
76 | * @var WordHandler |
77 | */ |
78 | protected $wordHandler; |
79 | |
80 | /** |
81 | * @var RouterInterface |
82 | */ |
83 | private $router; |
84 | |
85 | public function __construct( |
86 | EntityManagerInterface $entityManager, |
87 | TranslatorInterface $translator, |
88 | Repository\Treatment $repository, |
89 | UserRepository\Collectivity $collectivityRepository, |
90 | RequestStack $requestStack, |
91 | WordHandler $wordHandler, |
92 | AuthorizationCheckerInterface $authorizationChecker, |
93 | UserProvider $userProvider, |
94 | Pdf $pdf, |
95 | RouterInterface $router, |
96 | ) { |
97 | parent::__construct($entityManager, $translator, $repository, $pdf, $userProvider, $authorizationChecker); |
98 | $this->collectivityRepository = $collectivityRepository; |
99 | $this->requestStack = $requestStack; |
100 | $this->wordHandler = $wordHandler; |
101 | $this->router = $router; |
102 | } |
103 | |
104 | protected function getDomain(): string |
105 | { |
106 | return 'registry'; |
107 | } |
108 | |
109 | protected function getModel(): string |
110 | { |
111 | return 'treatment'; |
112 | } |
113 | |
114 | protected function getModelClass(): string |
115 | { |
116 | return Treatment::class; |
117 | } |
118 | |
119 | protected function getFormType(): string |
120 | { |
121 | return TreatmentType::class; |
122 | } |
123 | |
124 | public function listAction(): Response |
125 | { |
126 | $request = $this->requestStack->getMasterRequest(); |
127 | $criteria['active'] = 'true' === $request->query->get('active') || \is_null($request->query->get('active')) |
128 | ? true |
129 | : false |
130 | ; |
131 | $user = $this->userProvider->getAuthenticatedUser(); |
132 | if (!$this->authorizationChecker->isGranted('ROLE_ADMIN')) { |
133 | $criteria['collectivity'] = $this->userProvider->getAuthenticatedUser()->getCollectivity(); |
134 | } |
135 | if (\in_array(UserRoleDictionary::ROLE_REFERENT, $user->getRoles())) { |
136 | $criteria['collectivity'] = $user->getCollectivitesReferees(); |
137 | } |
138 | |
139 | $category = $this->entityManager->getRepository(Category::class)->findOneBy([ |
140 | 'name' => 'Traitement', |
141 | ]); |
142 | |
143 | return $this->render('Registry/Treatment/list.html.twig', [ |
144 | 'totalItem' => $this->repository->count($criteria), |
145 | 'category' => $category, |
146 | 'route' => $this->router->generate('registry_treatment_list_datatables', ['active' => $criteria['active']]), |
147 | ]); |
148 | } |
149 | |
150 | /** |
151 | * Generate a word report of contractors. |
152 | * |
153 | * @throws \PhpOffice\PhpWord\Exception\Exception |
154 | */ |
155 | public function reportAction(): Response |
156 | { |
157 | $objects = $this->repository->findAllActiveByCollectivity( |
158 | $this->userProvider->getAuthenticatedUser()->getCollectivity(), |
159 | true, |
160 | ['name' => 'asc'] |
161 | ); |
162 | |
163 | return $this->wordHandler->generateRegistryTreatmentReport($objects); |
164 | } |
165 | |
166 | public function configurationAction(): Response |
167 | { |
168 | $request = $this->requestStack->getMasterRequest(); |
169 | $criteria['active'] = 'true' === $request->query->get('active') || \is_null($request->query->get('active')) |
170 | ? true |
171 | : false |
172 | ; |
173 | |
174 | $configuration = $this |
175 | ->getDoctrine() |
176 | ->getRepository(PublicConfiguration::class) |
177 | // find by type |
178 | ->findOneBy(['type' => Treatment::class]); |
179 | |
180 | if (!$configuration) { |
181 | $configuration = new PublicConfiguration(Treatment::class); |
182 | } |
183 | |
184 | $form = $this->createForm(TreatmentConfigurationType::class, $configuration); |
185 | |
186 | $form->handleRequest($request); |
187 | if ($form->isSubmitted() && $form->isValid()) { |
188 | $task = $form->getData(); |
189 | |
190 | $entityManager = $this->getDoctrine()->getManager(); |
191 | $entityManager->persist($task); |
192 | $entityManager->flush(); |
193 | } |
194 | |
195 | return $this->render('Registry/Treatment/configuration.html.twig', [ |
196 | 'route' => $this->router->generate('registry_treatment_configuration', ['active' => $criteria['active']]), |
197 | 'form' => $form->createView(), |
198 | ]); |
199 | } |
200 | |
201 | /** |
202 | * The list public action view |
203 | * Get collectivity treatments & display them. |
204 | */ |
205 | public function publicListAction(string $id): Response |
206 | { |
207 | $collectivity = $this |
208 | ->getDoctrine() |
209 | ->getRepository(Collectivity::class) |
210 | ->find($id); |
211 | |
212 | $data = $this |
213 | ->getDoctrine() |
214 | ->getRepository(Treatment::class) |
215 | ->findBy( |
216 | [ |
217 | 'collectivity' => $collectivity, |
218 | 'public' => 1, |
219 | 'active' => 1, |
220 | ], |
221 | [ |
222 | 'name' => 'ASC', |
223 | ], |
224 | ); |
225 | |
226 | $objects = []; |
227 | |
228 | foreach ($data as $treatment) { |
229 | if (true == $treatment->getPublic()) { |
230 | $objects[] = $treatment; |
231 | } |
232 | } |
233 | |
234 | return $this->render($this->getTemplatingBasePath('public_list'), [ |
235 | 'objects' => $objects, |
236 | 'route' => '/public/traitements/datatables?active=1', |
237 | 'totalItem' => count($objects), |
238 | 'collectivity' => $collectivity, |
239 | ]); |
240 | } |
241 | |
242 | /** |
243 | * The public show action view |
244 | * Display the public information of the object. |
245 | * |
246 | * @param string $id The ID of the treatment to display |
247 | */ |
248 | public function publicShowAction(string $id): Response |
249 | { |
250 | $objects = $this->repository->findBy([ |
251 | 'id' => $id, |
252 | 'public' => 1] |
253 | ); |
254 | $object = null; |
255 | if (count($objects) > 0) { |
256 | $object = $objects[0]; |
257 | } |
258 | |
259 | if (!$object) { |
260 | throw new NotFoundHttpException("No object found with ID '{$id}'"); |
261 | } |
262 | |
263 | $configurationEntity = $this |
264 | ->getDoctrine() |
265 | ->getRepository(PublicConfiguration::class) |
266 | // find by type |
267 | ->findOneBy(['type' => Treatment::class]); |
268 | |
269 | if ($configurationEntity) { |
270 | $configuration = json_decode($configurationEntity->getSavedConfiguration(), true); |
271 | } else { |
272 | $configuration = new PublicConfiguration(Treatment::class); |
273 | } |
274 | |
275 | return $this->render($this->getTemplatingBasePath('public_show'), [ |
276 | 'object' => $object, |
277 | 'config' => $configuration, |
278 | ]); |
279 | } |
280 | |
281 | /** |
282 | * Get all active treatments of a collectivity and return their id/name as JSON. |
283 | */ |
284 | public function apiGetTreatmentsByCollectivity(string $collectivityId): Response |
285 | { |
286 | if (!$this->authorizationChecker->isGranted('ROLE_ADMIN')) { |
287 | throw new AccessDeniedHttpException('You can\'t access to a collectivity treatment data'); |
288 | } |
289 | |
290 | /** @var Collectivity|null $collectivity */ |
291 | $collectivity = $this->collectivityRepository->findOneById($collectivityId); |
292 | if (null === $collectivity) { |
293 | throw new NotFoundHttpException('Can\'t find collectivity for id ' . $collectivityId); |
294 | } |
295 | |
296 | $treatments = $this->repository->findAllByCollectivity( |
297 | $collectivity, |
298 | [ |
299 | 'active' => 'DESC', |
300 | 'name' => 'ASC', |
301 | ] |
302 | ); |
303 | $responseData = []; |
304 | |
305 | /** @var Treatment $treatment */ |
306 | foreach ($treatments as $treatment) { |
307 | $responseData[] = [ |
308 | 'value' => $treatment->getId()->toString(), |
309 | 'text' => $treatment->isActive() ? $treatment->__toString() : '(Inactif) ' . $treatment->__toString(), |
310 | ]; |
311 | } |
312 | |
313 | return new JsonResponse($responseData); |
314 | } |
315 | |
316 | public function listDataTables(Request $request): JsonResponse |
317 | { |
318 | $request = $this->requestStack->getMasterRequest(); |
319 | $criteria['active'] = $request->query->getBoolean('active'); |
320 | $user = $this->userProvider->getAuthenticatedUser(); |
321 | |
322 | if (!$this->authorizationChecker->isGranted('ROLE_ADMIN')) { |
323 | $criteria['collectivity'] = $user->getCollectivity(); |
324 | } |
325 | |
326 | if ($user) { |
327 | if (\in_array(UserRoleDictionary::ROLE_REFERENT, $user->getRoles())) { |
328 | $criteria['collectivity'] = $user->getCollectivitesReferees(); |
329 | } |
330 | } |
331 | |
332 | /** @var Paginator $treatments */ |
333 | $treatments = $this->getResults($request, $criteria); |
334 | |
335 | $reponse = $this->getBaseDataTablesResponse($request, $treatments, $criteria); |
336 | |
337 | /** @var Treatment $treatment */ |
338 | foreach ($treatments as $treatment) { |
339 | if (is_array($treatment)) { |
340 | $treatment = $treatment[0]; |
341 | } |
342 | if (!$this->authorizationChecker->isGranted('IS_AUTHENTICATED_ANONYMOUSLY')) { |
343 | $treatmentLink = '<a href="' . $this->router->generate('registry_public_treatment_show', ['id' => $treatment->getId()->toString()]) . '"> |
344 | ' . \htmlspecialchars($treatment->getName()) . ' |
345 | </a>'; |
346 | } else { |
347 | $treatmentLink = '<a href="' . $this->router->generate('registry_treatment_show', ['id' => $treatment->getId()->toString()]) . '"> |
348 | ' . \htmlspecialchars($treatment->getName()) . ' |
349 | </a>'; |
350 | } |
351 | |
352 | // Separate contractors by comma in XLS export. |
353 | // https://gitlab.adullact.net/soluris/madis/-/issues/890 |
354 | $ctr = []; |
355 | foreach ($treatment->getContractors() as $contractor) { |
356 | $ctr[] = $contractor->getName(); |
357 | } |
358 | |
359 | $contractors = join(', ', $ctr); |
360 | |
361 | $yes = '<span class="badge bg-green">' . $this->translator->trans('global.label.yes') . '</span>'; |
362 | $no = '<span class="badge bg-yellow">' . $this->translator->trans('global.label.no') . '</span>'; |
363 | |
364 | $reponse['data'][] = [ |
365 | 'id' => $treatment->getId(), |
366 | 'nom' => $treatmentLink, |
367 | 'collectivite' => $this->authorizationChecker->isGranted('ROLE_REFERENT') ? $treatment->getCollectivity()->getName() : '', |
368 | 'service' => $treatment->getService() ? $treatment->getService()->getName() : '', |
369 | 'baseLegal' => !empty($treatment->getLegalBasis()) && array_key_exists($treatment->getLegalBasis(), TreatmentLegalBasisDictionary::getBasis()) ? TreatmentLegalBasisDictionary::getBasis()[$treatment->getLegalBasis()] : $treatment->getLegalBasis(), |
370 | 'logiciel' => $treatment->getToolsString(), |
371 | 'enTantQue' => !empty($treatment->getAuthor()) && array_key_exists($treatment->getAuthor(), TreatmentAuthorDictionary::getAuthors()) ? TreatmentAuthorDictionary::getAuthors()[$treatment->getAuthor()] : $treatment->getAuthor(), |
372 | 'gestionnaire' => $treatment->getManager(), |
373 | 'sousTraitant' => $contractors, |
374 | 'controleAcces' => $treatment->getSecurityAccessControl()->isCheck() ? $yes : $no, |
375 | 'update' => $treatment->getSecurityUpdate()->isCheck() ? $yes : $no, |
376 | 'saving' => $treatment->getSecuritySaving()->isCheck() ? $yes : $no, |
377 | 'tracabilite' => $treatment->getSecurityTracability()->isCheck() ? $yes : $no, |
378 | 'other' => $treatment->getSecurityOther()->isCheck() ? $yes : $no, |
379 | 'entitledPersons' => $treatment->isSecurityEntitledPersons() ? $yes : $no, |
380 | 'openAccounts' => $treatment->isSecurityOpenAccounts() ? $yes : $no, |
381 | 'specificitiesDelivered' => $treatment->isSecuritySpecificitiesDelivered() ? $yes : $no, |
382 | 'updatedAt' => date_format($treatment->getUpdatedAt(), 'd-m-Y H:i'), |
383 | 'createdAt' => date_format($treatment->getCreatedAt(), 'd-m-Y H:i'), |
384 | 'public' => $treatment->getPublic() ? $yes : $no, |
385 | 'responsableTraitement' => $treatment->getCoordonneesResponsableTraitement(), |
386 | 'specific_traitement' => join(', ', $this->getSpecificTraitement($treatment)), |
387 | 'conformite_traitement' => $this->getTreatmentConformity($treatment), |
388 | 'avis_aipd' => $this->getAvisAipd($treatment), |
389 | 'exempt_AIPD' => $treatment->getExemptAIPD() ? $yes : $no, |
390 | 'statut' => $treatment->getStatut() && isset(TreatmentStatutDictionary::getStatuts()[$treatment->getStatut()]) ? TreatmentStatutDictionary::getStatuts()[$treatment->getStatut()] : '', |
391 | 'sensitiveData' => $this->countSensitiveData($treatment->getDataCategories()), |
392 | 'actions' => $this->generateActionCellContent($treatment), |
393 | ]; |
394 | } |
395 | |
396 | return new JsonResponse($reponse); |
397 | } |
398 | |
399 | private function countSensitiveData($categories) |
400 | { |
401 | $sensitive = '<span class="badge bg-yellow">' . $this->translator->trans('global.label.yes') . '</span>'; |
402 | $noSensitive = '<span class="badge bg-green">' . $this->translator->trans('global.label.no') . '</span>'; |
403 | |
404 | $count = 0; |
405 | foreach ($categories as $category) { |
406 | if ($category->isSensible()) { |
407 | ++$count; |
408 | } |
409 | } |
410 | |
411 | return $count > 0 ? $sensitive : $noSensitive; |
412 | } |
413 | |
414 | private function getAvisAipd(Treatment $treatment) |
415 | { |
416 | if (!$treatment->getConformiteTraitement()) { |
417 | return '<span class="label label-default" style="min-width: 100%; display: inline-block;">Non réalisée</span>'; |
418 | } |
419 | $conf = $treatment->getConformiteTraitement(); |
420 | |
421 | if (null === $conf->getLastAnalyseImpact()) { |
422 | return '<span class="label label-default" style="min-width: 100%; display: inline-block;">Non réalisée</span>'; |
423 | } |
424 | $analyse_impact = $conf->getLastAnalyseImpact(); |
425 | $statut = $analyse_impact->getStatut(); |
426 | |
427 | switch ($statut) { |
428 | case 'defavorable': |
429 | $label = 'Défavorable'; |
430 | $class = 'label-danger'; |
431 | break; |
432 | case 'favorable_reserve': |
433 | $label = 'Favorable avec réserve(s)'; |
434 | $class = 'label-warning'; |
435 | break; |
436 | case 'favorable': |
437 | $label = 'Favorable'; |
438 | $class = 'label-success'; |
439 | break; |
440 | case 'en_cours': |
441 | $label = 'En cours'; |
442 | $class = 'label-default'; |
443 | break; |
444 | default: |
445 | $label = 'Non réalisée'; |
446 | $class = 'label-default'; |
447 | } |
448 | |
449 | return '<span class="label ' . $class . '" style="min-width: 100%; display: inline-block;">' . $label . '</span>'; |
450 | } |
451 | |
452 | private function getTreatmentConformity(Treatment $treatment) |
453 | { |
454 | if (!$treatment->getConformiteTraitement()) { |
455 | return '<span class="label label-default" style="min-width: 100%; display: inline-block;">Non évalué</span>'; |
456 | } |
457 | $conf = $treatment->getConformiteTraitement(); |
458 | $level = ConformiteTraitementCompletion::getConformiteTraitementLevel($conf); |
459 | |
460 | $weight = ConformiteTraitementLevelDictionary::getConformitesWeight()[$level]; |
461 | |
462 | switch ($weight) { |
463 | case 1: |
464 | $label = 'Conforme'; |
465 | $class = 'label-success'; |
466 | break; |
467 | case 2: |
468 | $label = 'Non-conforme mineure'; |
469 | $class = 'label-warning'; |
470 | break; |
471 | default: |
472 | $label = 'Non-conforme majeure'; |
473 | $class = 'label-danger'; |
474 | } |
475 | |
476 | return '<span class="label ' . $class . '" style="min-width: 100%; display: inline-block;">' . $label . '</span>'; |
477 | } |
478 | |
479 | private function getSpecificTraitement(Treatment $treatment) |
480 | { |
481 | $user = $this->userProvider->getAuthenticatedUser(); |
482 | $values = []; |
483 | if ($treatment->isLargeScaleCollection()) { |
484 | array_push($values, $this->translator->trans('registry.treatment.label.large_scale_collection')); |
485 | } |
486 | if ($treatment->isDataCrossing()) { |
487 | array_push($values, $this->translator->trans('registry.treatment.label.data_crossing')); |
488 | } |
489 | if ($treatment->isAutomatedDecisionsWithLegalEffect()) { |
490 | array_push($values, $this->translator->trans('registry.treatment.label.automated_decisions_with_legal_effect')); |
491 | } |
492 | if ($treatment->isEvaluationOrRating()) { |
493 | array_push($values, $this->translator->trans('registry.treatment.label.evaluation_or_rating')); |
494 | } |
495 | if ($treatment->isAutomaticExclusionService()) { |
496 | array_push($values, $this->translator->trans('registry.treatment.label.automatic_exclusion_service')); |
497 | } |
498 | if ($treatment->isVulnerablePeople()) { |
499 | array_push($values, $this->translator->trans('registry.treatment.label.vulnerable_people')); |
500 | } |
501 | if ($treatment->isSystematicMonitoring()) { |
502 | array_push($values, $this->translator->trans('registry.treatment.label.systematic_monitoring')); |
503 | } |
504 | if ($treatment->isInnovativeUse()) { |
505 | array_push($values, $this->translator->trans('registry.treatment.label.innovative_use')); |
506 | } |
507 | |
508 | return $values; |
509 | } |
510 | |
511 | private function generateActionCellContent(Treatment $treatment) |
512 | { |
513 | $id = $treatment->getId(); |
514 | |
515 | $user = $this->userProvider->getAuthenticatedUser(); |
516 | if ($user->getServices()->isEmpty() || $treatment->isInUserServices($user) || $this->authorizationChecker->isGranted('ROLE_ADMIN')) { |
517 | $editPath = $this->router->generate('registry_treatment_edit', ['id' => $id]); |
518 | $deletePath = $this->router->generate('registry_treatment_delete', ['id' => $id]); |
519 | |
520 | if ($this->authorizationChecker->isGranted('ROLE_USER')) { |
521 | return '<a href="' . $editPath . '"> |
522 | <i aria-hidden="true" class="fa fa-pencil"></i> |
523 | ' . $this->translator->trans('global.action.edit') . ' |
524 | </a> |
525 | <a href="' . $deletePath . '"> |
526 | <i aria-hidden="true" class="fa fa-trash"></i> |
527 | ' . $this->translator->trans('global.action.delete') . ' |
528 | </a>' |
529 | ; |
530 | } |
531 | } |
532 | |
533 | return null; |
534 | } |
535 | |
536 | public function pdfAllAction(Request $request) |
537 | { |
538 | $ids = $request->query->get('ids'); |
539 | $ids = explode(',', $ids); |
540 | |
541 | $objects = []; |
542 | |
543 | foreach ($ids as $id) { |
544 | $treatment = $this->repository->findOneById($id); |
545 | if ($this->userProvider->getAuthenticatedUser()->hasAccessTo($treatment, false)) { |
546 | array_push($objects, $treatment); |
547 | } |
548 | } |
549 | |
550 | return new PdfResponse( |
551 | $this->pdf->getOutputFromHtml( |
552 | $this->renderView($this->getTemplatingBasePath('pdf_all'), ['objects' => $objects]) |
553 | ), |
554 | $this->getPdfName((string) 'print') . '.pdf' |
555 | ); |
556 | } |
557 | |
558 | /** |
559 | * The archive action view |
560 | * Display a confirmation message to confirm data archivation. |
561 | */ |
562 | public function archiveAllAction(Request $request): Response |
563 | { |
564 | $ids = $request->query->get('ids'); |
565 | $ids = explode(',', $ids); |
566 | |
567 | if (!$this->authorizationChecker->isGranted('ROLE_USER')) { |
568 | $this->addFlash('error', 'Vous ne pouvez pas supprimer ces traitements'); |
569 | |
570 | return $this->redirectToRoute($this->getRouteName('list')); |
571 | } |
572 | |
573 | return $this->render($this->getTemplatingBasePath('archive_all'), [ // delete_all |
574 | 'ids' => $ids, |
575 | 'treatment_length' => count($ids), |
576 | ]); |
577 | } |
578 | |
579 | /** |
580 | * The archive action |
581 | * Display a confirmation message to confirm data archived. |
582 | */ |
583 | public function archiveConfirmationAction(): Response |
584 | { |
585 | $request = $this->requestStack->getMasterRequest(); |
586 | $ids = $request->query->get('ids'); |
587 | |
588 | if (!$this->authorizationChecker->isGranted('ROLE_USER')) { |
589 | // $this->addFlash('success', $this->getFlashbagMessage('success', 'delete')); |
590 | $this->addFlash('error', 'Vous ne pouvez pas archiver ces traitements'); |
591 | |
592 | return $this->redirectToRoute($this->getRouteName('list')); |
593 | } |
594 | |
595 | foreach ($ids as $id) { |
596 | /** |
597 | * @var Treatment |
598 | */ |
599 | $treatment = $this->repository->findOneById($id); |
600 | $user = $this->getUser(); |
601 | if ($treatment |
602 | && $user instanceof UserModel\User |
603 | && (( |
604 | $treatment->getCollectivity() === $user->getCollectivity() |
605 | && (0 === count($user->getServices()) || in_array($treatment->getService(), $user->getServices()->toArray())) |
606 | ) |
607 | || $user->hasAccessTo($treatment)) |
608 | ) { |
609 | $treatment->setActive(false); |
610 | $this->addFlash('success', $this->getFlashbagMessage('success', 'archive', $treatment)); |
611 | } |
612 | } |
613 | $this->entityManager->flush(); |
614 | |
615 | return $this->redirectToRoute($this->getRouteName('list')); |
616 | } |
617 | |
618 | /** |
619 | * The delete action view |
620 | * Display a confirmation message to confirm data deletion. |
621 | */ |
622 | public function deleteAllAction(Request $request): Response |
623 | { |
624 | $ids = $request->query->get('ids'); |
625 | $ids = explode(',', $ids); |
626 | |
627 | if (!$this->authorizationChecker->isGranted('ROLE_USER')) { |
628 | $this->addFlash('error', 'Vous ne pouvez pas supprimer ces traitements'); |
629 | |
630 | return $this->redirectToRoute($this->getRouteName('list')); |
631 | } |
632 | |
633 | return $this->render($this->getTemplatingBasePath('delete_all'), [ // delete_all |
634 | 'ids' => $ids, |
635 | 'treatment_length' => count($ids), |
636 | ]); |
637 | } |
638 | |
639 | public function deleteConfirmationAllAction(Request $request): Response |
640 | { |
641 | $ids = $request->query->get('ids'); |
642 | |
643 | if (!$this->authorizationChecker->isGranted('ROLE_USER')) { |
644 | $this->addFlash('error', 'Vous ne pouvez pas supprimer ces traitements'); |
645 | |
646 | return $this->redirectToRoute($this->getRouteName('list')); |
647 | } |
648 | |
649 | foreach ($ids as $id) { |
650 | /** |
651 | * @var Treatment |
652 | */ |
653 | $treatment = $this->repository->findOneById($id); |
654 | $user = $this->getUser(); |
655 | if ($treatment |
656 | && $user instanceof UserModel\User |
657 | && (( |
658 | $treatment->getCollectivity() === $user->getCollectivity() |
659 | && (0 === count($user->getServices()) || in_array($treatment->getService(), $user->getServices()->toArray())) |
660 | ) |
661 | || $user->hasAccessTo($treatment)) |
662 | ) { |
663 | $this->deleteConfirmationAction($id); |
664 | } |
665 | } |
666 | |
667 | return $this->redirectToRoute($this->getRouteName('list')); |
668 | } |
669 | |
670 | protected function getLabelAndKeysArray(): array |
671 | { |
672 | if ($this->authorizationChecker->isGranted('ROLE_REFERENT')) { |
673 | return [ |
674 | '1' => 'name', |
675 | '2' => 'collectivite', |
676 | '3' => 'service', |
677 | '4' => 'statut', |
678 | '5' => 'baseLegal', |
679 | '6' => 'logiciel', |
680 | '7' => 'enTantQue', |
681 | '8' => 'gestionnaire', |
682 | '9' => 'sousTraitant', |
683 | '10' => 'sensitiveData', |
684 | '11' => 'controleAcces', |
685 | '12' => 'tracabilite', |
686 | '13' => 'saving', |
687 | '14' => 'update', |
688 | '15' => 'other', |
689 | '16' => 'entitledPersons', |
690 | '17' => 'openAccounts', |
691 | '18' => 'specificitiesDelivered', |
692 | '19' => 'public', |
693 | '20' => 'responsableTraitement', |
694 | '21' => 'specific_traitement', |
695 | '22' => 'conformite_traitement', |
696 | '23' => 'avis_aipd', |
697 | '24' => 'exempt_AIPD', |
698 | '25' => 'createdAt', |
699 | '26' => 'updatedAt', |
700 | '27' => 'actions', |
701 | ]; |
702 | } |
703 | |
704 | if ($this->userProvider->getAuthenticatedUser()->hasServices()) { |
705 | return [ |
706 | '1' => 'name', |
707 | '2' => 'service', |
708 | '3' => 'statut', |
709 | '4' => 'baseLegal', |
710 | '5' => 'logiciel', |
711 | '6' => 'enTantQue', |
712 | '7' => 'gestionnaire', |
713 | '8' => 'sousTraitant', |
714 | '9' => 'sensitiveData', |
715 | '10' => 'controleAcces', |
716 | '11' => 'tracabilite', |
717 | '12' => 'saving', |
718 | '13' => 'update', |
719 | '14' => 'other', |
720 | '15' => 'entitledPersons', |
721 | '16' => 'openAccounts', |
722 | '17' => 'specificitiesDelivered', |
723 | '18' => 'public', |
724 | '19' => 'responsableTraitement', |
725 | '20' => 'specific_traitement', |
726 | '21' => 'conformite_traitement', |
727 | '22' => 'avis_aipd', |
728 | '23' => 'exempt_AIPD', |
729 | '24' => 'createdAt', |
730 | '25' => 'updatedAt', |
731 | '26' => 'actions', |
732 | ]; |
733 | } |
734 | |
735 | return [ |
736 | '1' => 'name', |
737 | '2' => 'statut', |
738 | '3' => 'baseLegal', |
739 | '4' => 'logiciel', |
740 | '5' => 'enTantQue', |
741 | '6' => 'gestionnaire', |
742 | '7' => 'sousTraitant', |
743 | '8' => 'sensitiveData', |
744 | '9' => 'controleAcces', |
745 | '10' => 'tracabilite', |
746 | '11' => 'saving', |
747 | '12' => 'update', |
748 | '13' => 'other', |
749 | '14' => 'entitledPersons', |
750 | '15' => 'openAccounts', |
751 | '16' => 'specificitiesDelivered', |
752 | '17' => 'public', |
753 | '18' => 'responsableTraitement', |
754 | '19' => 'specific_traitement', |
755 | '20' => 'conformite_traitement', |
756 | '21' => 'avis_aipd', |
757 | '22' => 'exempt_AIPD', |
758 | '23' => 'createdAt', |
759 | '24' => 'updatedAt', |
760 | '25' => 'actions', |
761 | ]; |
762 | } |
763 | } |