diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php index cc4e36e..12bdbab 100755 --- a/src/Controller/AdminController.php +++ b/src/Controller/AdminController.php @@ -349,23 +349,32 @@ public function productVersionCreation(Request $request): Response #[Route('admin/archive/{entityType}/{id}', name: 'archive_entity')] public function archiveEntity(Request $request, string $entityType, int $id): Response { - $originUrl = $request->headers->get('referer'); - $user = $this->getUser()->getUsername(); - $commentary = $request->request->get('archivingCommentary'); + if ($this->getUser() !== null && $this->authChecker->isGranted('ROLE_ADMIN') == false) { + $this->addFlash('danger', 'Vous n\'avez pas les droits pour effectuer cette action'); + return $this->redirectToRoute('app_base'); + } else { - $this->logger->info($user . ' archived entity: ' . $entityType . ' ' . $id . ' ' . 'commentaire: ' . $commentary . ' full request: ' . json_encode($request->getContent())); + $originUrl = $request->headers->get('referer'); + $user = $this->getUser()->getUsername(); + $commentary = $request->request->get('archivingCommentary'); - $result = $this->entityDeletionService->archivedEntity($entityType, $id, $commentary, $user); + if ($entityType == "efnc" && $commentary == null) { + $this->addFlash('danger', 'Un commentaire est requis pour archiver une EFNC'); + return $this->redirect($originUrl); + } - if ($result == false) { - $this->addFlash('danger', 'L\'élément n\'a pas pu être archivé'); - return $this->redirect($originUrl); - } else { - $this->addFlash('success', 'L\'élément a bien été archivé'); - if ($entityType == "efnc") { - return $this->redirectToRoute('app_base', []); - } else { + $result = $this->entityDeletionService->archivedEntity($entityType, $id, $commentary, $user); + + if ($result == false) { + $this->addFlash('danger', 'L\'élément n\'a pas pu être archivé'); return $this->redirect($originUrl); + } else { + $this->addFlash('success', 'L\'élément a bien été archivé'); + if ($entityType == "efnc") { + return $this->redirectToRoute('app_base', []); + } else { + return $this->redirect($originUrl); + } } } } diff --git a/src/Controller/EFNCController.php b/src/Controller/EFNCController.php index 51f7d77..7b456fb 100755 --- a/src/Controller/EFNCController.php +++ b/src/Controller/EFNCController.php @@ -27,8 +27,9 @@ public function formCreation(Request $request): Response { $efnc = new EFNC(); $imcome = new ImmediateConservatoryMeasures(); - $riskWeighting = new RiskWeighting(); $product = new Product(); + $riskWeighting = new RiskWeighting(); + $efnc->getImmediateConservatoryMeasures()->add($imcome); $efnc->getProduct($product); $efnc->getRiskWeighting($riskWeighting); diff --git a/templates/services/efnc/creation/form_creation.html.twig b/templates/services/efnc/creation/form_creation.html.twig index 6147262..c78ae38 100755 --- a/templates/services/efnc/creation/form_creation.html.twig +++ b/templates/services/efnc/creation/form_creation.html.twig @@ -5,21 +5,30 @@ {% block body %} -