From 71b93c14299f0c9b5e458d64076f4bb9a6f0a615 Mon Sep 17 00:00:00 2001 From: Giuliano Mele Date: Wed, 26 Jul 2023 09:19:23 +0200 Subject: [PATCH] Add readonly inherited software --- src/Controller/SoftwareController.php | 17 ++++++++---- src/Service/SoftwareService.php | 21 ++++++++++----- templates/software/edit.html.twig | 38 ++++++++++++++++----------- templates/software/index.html.twig | 4 +++ 4 files changed, 52 insertions(+), 28 deletions(-) diff --git a/src/Controller/SoftwareController.php b/src/Controller/SoftwareController.php index 14250d6d..f413435e 100644 --- a/src/Controller/SoftwareController.php +++ b/src/Controller/SoftwareController.php @@ -5,6 +5,7 @@ use App\Entity\SoftwareConfig; use App\Repository\SoftwareConfigRepository; use App\Repository\SoftwareRepository; +use App\Repository\TeamRepository; use App\Service\ApproveService; use App\Service\AssignService; use App\Service\CurrentTeamService; @@ -228,22 +229,25 @@ public function editSoftware( AssignService $assignService, CurrentTeamService $currentTeamService, SoftwareRepository $softwareRepository, + TeamRepository $teamRepository, ): Response { //Request: id: SoftwareID, snack:Snack Notice $team = $currentTeamService->getCurrentTeam($this->getUser()); + $teamPath = $team ? $teamRepository->getPath($team) : null; $software = $softwareRepository->find($request->get('id')); - if ($securityService->teamDataCheck($software, $team) === false) { + if ($securityService->teamPathDataCheck($software, $teamPath) === false) { return $this->redirectToRoute('software'); } $newSoftware = $softwareService->cloneSoftware($software, $this->getUser()); - $form = $softwareService->createForm($newSoftware, $team); + $isEditable = $software->getTeam() === $team; + $form = $softwareService->createForm($newSoftware, $team, ['disabled' => !$isEditable]); $form->handleRequest($request); - $assign = $assignService->createForm($software, $team); + $assign = $assignService->createForm($software, $team, ['disabled' => !$isEditable]); $errors = array(); - if ($form->isSubmitted() && $form->isValid() && $software->getActiv() && !$software->getApproved()) { + if ($form->isSubmitted() && $form->isValid() && $software->getActiv() && !$software->getApproved() && $isEditable) { $software->setActiv(false); $newSoftware = $form->getData(); @@ -276,6 +280,7 @@ public function editSoftware( 'software' => $software, 'activ' => $software->getActiv(), 'snack' => $request->get('snack'), + 'isEditable' => $isEditable, ]); } @@ -285,6 +290,7 @@ public function index( Request $request, CurrentTeamService $currentTeamService, SoftwareRepository $softwareRepository, + TeamRepository $teamRepository, ): Response { //Request: snack: Snack Notice @@ -292,7 +298,8 @@ public function index( if ($securityService->teamCheck($team) === false) { return $this->redirectToRoute('dashboard'); } - $software = $softwareRepository->findActiveByTeam($team); + $teamPath = $teamRepository->getPath($team); + $software = $softwareRepository->findActiveByTeamPath($teamPath); return $this->render('software/index.html.twig', [ 'data' => $software, diff --git a/src/Service/SoftwareService.php b/src/Service/SoftwareService.php index e72ecb47..c10f80cd 100644 --- a/src/Service/SoftwareService.php +++ b/src/Service/SoftwareService.php @@ -51,14 +51,21 @@ public function createConfigForm(SoftwareConfig $softwareConfig): FormInterface return $form; } - public function createForm(Software $software, Team $team): FormInterface + public function createForm(Software $software, Team $team, array $options = []): FormInterface { - $processes = $this->em->getRepository(VVT::class)->findActiveByTeam($team); - $data = $this->em->getRepository(Datenweitergabe::class)->findBy(['team' => $team, 'activ' => true, 'art' => 1]); - - $form = $this->formBuilder->create(SoftwareType::class, $software, ['processes' => $processes, 'datenweitergabe' => $data]); - - return $form; + if (isset($options['disabled']) && $options['disabled']) { + $teamPath = $this->em->getRepository(Team::class)->getPath($team); + $processes = $this->em->getRepository(VVT::class)->findActiveByTeamPath($teamPath); + $data = $this->em->getRepository(Datenweitergabe::class)->findActiveTransfersByTeamPath($teamPath); + } else { + $processes = $this->em->getRepository(VVT::class)->findActiveByTeam($team); + $data = $this->em->getRepository(Datenweitergabe::class)->findBy(['team' => $team, 'activ' => true, 'art' => 1]); + } + + return $this->formBuilder->create(SoftwareType::class, $software, array_merge([ + 'processes' => $processes, + 'datenweitergabe' => $data + ], $options)); } public function newConfig(Software $software): SoftwareConfig diff --git a/templates/software/edit.html.twig b/templates/software/edit.html.twig index 482ec31e..f8ae0274 100644 --- a/templates/software/edit.html.twig +++ b/templates/software/edit.html.twig @@ -9,7 +9,9 @@ {% trans from 'general' %}pdf.createWithHistory{% endtrans %} - {{ include('base/__approveBtn.html.twig',{'data':software,'dataLink':'software_approve'}) }} + {% if isEditable %} + {{ include('base/__approveBtn.html.twig',{'data':software,'dataLink':'software_approve'}) }} + {% endif %} {% endif %} {% endblock %} @@ -21,7 +23,9 @@ {{ include('base/__approvedBy.html.twig', {'data':software}) }}
- {{ include('assign/__assign.html.twig',{'data':software,'path':'assign_software'}) }} + {% if isEditable %} + {{ include('assign/__assign.html.twig',{'data':software,'path':'assign_software'}) }} + {% endif %}
@@ -36,7 +40,7 @@ -
{{ include('software/__form.html.twig') }} @@ -44,21 +48,23 @@
-
-
-
- -
-
-
-
- {{ include('software/__config.html.twig') }} + {% if isEditable %} +
+
+
+ +
+
+
+
+ {{ include('software/__config.html.twig') }} +
-
+ {% endif %}
{% if software.previous %} diff --git a/templates/software/index.html.twig b/templates/software/index.html.twig index 209dbadd..03f2c846 100644 --- a/templates/software/index.html.twig +++ b/templates/software/index.html.twig @@ -24,6 +24,7 @@ {% trans %}licence.word{% endtrans %} {% trans %}expiration.date{% endtrans %} {% trans from 'general' %}state{% endtrans %} + {% trans from 'general' %}inheritance.fromTeam{% endtrans %} @@ -48,6 +49,9 @@ {{ d.statusString }} {% endif %} + + {% if d.team != currentTeam %}{{ d.team }}{% else %}-{% endif %} + {% endfor %}