diff --git a/src/Controller/PoliciesController.php b/src/Controller/PoliciesController.php index 097e5433..b68e2cc6 100644 --- a/src/Controller/PoliciesController.php +++ b/src/Controller/PoliciesController.php @@ -4,6 +4,7 @@ use App\Entity\Policies; use App\Repository\PoliciesRepository; +use App\Repository\TeamRepository; use App\Service\ApproveService; use App\Service\AssignService; use App\Service\CurrentTeamService; @@ -175,21 +176,24 @@ public function editPolicy( AssignService $assignService, CurrentTeamService $currentTeamService, PoliciesRepository $policiesRepository, + TeamRepository $teamRepository, ): Response { $team = $currentTeamService->getCurrentTeam($this->getUser()); + $teamPath = $team ? $teamRepository->getPath($team) : null; $policy = $policiesRepository->find($request->get('id')); - if ($securityService->teamDataCheck($policy, $team) === false) { + if ($securityService->teamPathDataCheck($policy, $teamPath) === false) { return $this->redirectToRoute('policies'); } $newPolicy = $policiesService->clonePolicy($policy, $this->getUser()); - $form = $policiesService->createForm($newPolicy, $team); + $isEditable = $policy->getTeam() === $team; + $form = $policiesService->createForm($newPolicy, $team, ['disabled' => !$isEditable]); $form->handleRequest($request); - $assign = $assignService->createForm($policy, $team); + $assign = $assignService->createForm($policy, $team, ['disabled' => !$isEditable]); $errors = array(); - if ($form->isSubmitted() && $form->isValid() && $policy->getActiv() && !$policy->getApproved()) { + if ($form->isSubmitted() && $form->isValid() && $policy->getActiv() && !$policy->getApproved() && $isEditable) { $policy->setActiv(false); $newPolicy = $form->getData(); $errors = $validator->validate($newPolicy); @@ -214,7 +218,8 @@ public function editPolicy( 'title' => $this->translator->trans(id: 'policies.edit', domain: 'policies'), 'policy' => $policy, 'activ' => $policy->getActiv(), - 'snack' => $request->get('snack') + 'snack' => $request->get('snack'), + 'isEditable' => $isEditable, ]); } @@ -223,16 +228,19 @@ public function index( SecurityService $securityService, CurrentTeamService $currentTeamService, PoliciesRepository $policiesRepository, + TeamRepository $teamRepository, ): Response { $team = $currentTeamService->getCurrentTeam($this->getUser()); if ($securityService->teamCheck($team) === false) { return $this->redirectToRoute('dashboard'); } - $polcies = $policiesRepository->findActiveByTeam($team); + + $teamPath = $teamRepository->getPath($team); + $policies = $policiesRepository->findActiveByTeamPath($teamPath); return $this->render('policies/index.html.twig', [ - 'data' => $polcies, + 'data' => $policies, 'currentTeam' => $team, ]); } diff --git a/src/Form/Type/PolicyType.php b/src/Form/Type/PolicyType.php index 47d7a523..b88af0e9 100644 --- a/src/Form/Type/PolicyType.php +++ b/src/Form/Type/PolicyType.php @@ -27,13 +27,40 @@ class PolicyType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { + $summernoteClass = 'summernote'; + if ($options['disabled']) { + $summernoteClass .= ' summernote-disable'; + } $builder - ->add('title', TextType::class, ['label' => 'policyName', 'required' => true, 'translation_domain' => 'form']) - ->add('scope', TextareaType::class, ['attr' => ['class' => 'summernote'], 'label' => 'policyScope', 'required' => true, 'translation_domain' => 'form']) - ->add('risk', TextareaType::class, ['attr' => ['class' => 'summernote'], 'label' => 'policyPotentialDangers', 'required' => true, 'translation_domain' => 'form']) - ->add('foundation', TextareaType::class, ['attr' => ['class' => 'summernote'], 'label' => 'policyLegislation', 'required' => true, 'translation_domain' => 'form']) - ->add('reference', TextType::class, ['label' => 'fileNumber', 'required' => false, 'translation_domain' => 'form']) + ->add('title', TextType::class, [ + 'label' => 'policyName', + 'required' => true, + 'translation_domain' => 'form' + ]) + ->add('scope', TextareaType::class, [ + 'attr' => ['class' => $summernoteClass], + 'label' => 'policyScope', + 'required' => true, + 'translation_domain' => 'form' + ]) + ->add('risk', TextareaType::class, [ + 'attr' => ['class' => $summernoteClass], + 'label' => 'policyPotentialDangers', + 'required' => true, + 'translation_domain' => 'form' + ]) + ->add('foundation', TextareaType::class, [ + 'attr' => ['class' => $summernoteClass], + 'label' => 'policyLegislation', + 'required' => true, + 'translation_domain' => 'form' + ]) + ->add('reference', TextType::class, [ + 'label' => 'fileNumber', + 'required' => false, + 'translation_domain' => 'form' + ]) ->add('processes', EntityType::class, [ 'choice_label' => 'name', 'class' => VVT::class, @@ -48,10 +75,30 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'data-live-search' => 'true' ] ]) - ->add('protection', TextareaType::class, ['attr' => ['class' => 'summernote'], 'label' => 'policySafetyMeasures', 'required' => false, 'translation_domain' => 'form']) - ->add('notes', TextareaType::class, ['attr' => ['class' => 'summernote'], 'label' => 'policyTrainingOffer', 'required' => false, 'translation_domain' => 'form']) - ->add('consequences', TextareaType::class, ['attr' => ['class' => 'summernote'], 'label' => 'policyNoncomplianceConsequences', 'required' => false, 'translation_domain' => 'form']) - ->add('contact', TextareaType::class, ['attr' => ['row' => 5], 'label' => 'policyContacts', 'required' => false, 'translation_domain' => 'form']) + ->add('protection', TextareaType::class, [ + 'attr' => ['class' => $summernoteClass], + 'label' => 'policySafetyMeasures', + 'required' => false, + 'translation_domain' => 'form' + ]) + ->add('notes', TextareaType::class, [ + 'attr' => ['class' => $summernoteClass], + 'label' => 'policyTrainingOffer', + 'required' => false, + 'translation_domain' => 'form' + ]) + ->add('consequences', TextareaType::class, [ + 'attr' => ['class' => $summernoteClass], + 'label' => 'policyNoncomplianceConsequences', + 'required' => false, + 'translation_domain' => 'form' + ]) + ->add('contact', TextareaType::class, [ + 'attr' => ['row' => 5], + 'label' => 'policyContacts', + 'required' => false, + 'translation_domain' => 'form' + ]) ->add('people', EntityType::class, [ 'choice_label' => 'name', 'class' => VVTPersonen::class, diff --git a/src/Repository/PoliciesRepository.php b/src/Repository/PoliciesRepository.php index 5828b403..ad18ec8d 100644 --- a/src/Repository/PoliciesRepository.php +++ b/src/Repository/PoliciesRepository.php @@ -29,6 +29,16 @@ public function findActiveByTeam($value) ->getResult(); } + public function findActiveByTeamPath(array $teamPath) + { + return $this->createQueryBuilder('a') + ->andWhere('a.team IN (:teamPath)') + ->andWhere('a.activ = 1') + ->setParameter('teamPath', $teamPath) + ->getQuery() + ->getResult(); + } + public function findPublicByTeamPath(array $teamPath) { return $this->createQueryBuilder('a') diff --git a/src/Service/PoliciesService.php b/src/Service/PoliciesService.php index 28d859a9..5a4538db 100644 --- a/src/Service/PoliciesService.php +++ b/src/Service/PoliciesService.php @@ -44,15 +44,25 @@ function clonePolicy(Policies $policy, User $user) return $newPolicy; } - function createForm(Policies $policies, Team $team) + function createForm(Policies $policies, Team $team, array $options = []) { - $personen = $this->em->getRepository(VVTPersonen::class)->findByTeam($team); - $kategorien = $this->em->getRepository(VVTDatenkategorie::class)->findByTeam($team); - $processes = $this->em->getRepository(VVT::class)->findActiveByTeam($team); + if (isset($options['disabled']) && $options['disabled']) { + $teamPath = $this->em->getRepository(Team::class)->getPath($team); + $personen = $this->em->getRepository(VVTPersonen::class)->findByTeamPath($teamPath); + $kategorien = $this->em->getRepository(VVTDatenkategorie::class)->findByTeamPath($teamPath); + $processes = $this->em->getRepository(VVT::class)->findActiveByTeamPath($teamPath); + } else { + $personen = $this->em->getRepository(VVTPersonen::class)->findByTeam($team); + $kategorien = $this->em->getRepository(VVTDatenkategorie::class)->findByTeam($team); + $processes = $this->em->getRepository(VVT::class)->findActiveByTeam($team); + } - $form = $this->formBuilder->create(PolicyType::class, $policies, ['personen' => $personen, 'kategorien' => $kategorien, 'user' => $team->getMembers(), 'processes' => $processes]); - - return $form; + return $this->formBuilder->create(PolicyType::class, $policies, array_merge([ + 'personen' => $personen, + 'kategorien' => $kategorien, + 'user' => $team->getMembers(), + 'processes' => $processes + ], $options)); } function newPolicy(Team $team, User $user) diff --git a/templates/policies/edit.html.twig b/templates/policies/edit.html.twig index 6022f42c..f2b51724 100644 --- a/templates/policies/edit.html.twig +++ b/templates/policies/edit.html.twig @@ -9,8 +9,10 @@ {% trans from 'general' %}pdf.createWithHistory{% endtrans %} - {{ include('base/__approveBtn.html.twig',{'data':policy,'dataLink':'policy_approve'}) }} - {{ include('base/__disableBtn.html.twig',{'data':policy,'dataLink':'policy_disable'}) }} + {% if isEditable %} + {{ include('base/__approveBtn.html.twig',{'data':policy,'dataLink':'policy_approve'}) }} + {{ include('base/__disableBtn.html.twig',{'data':policy,'dataLink':'policy_disable'}) }} + {% endif %} {% endif %} {% endblock %} @@ -21,7 +23,9 @@ {{ include('base/__approvedBy.html.twig', {'data':policy}) }}
- {{ include('assign/__assign.html.twig',{'data':policy,'path':'assign_policy'}) }} + {% if isEditable %} + {{ include('assign/__assign.html.twig',{'data':policy,'path':'assign_policy'}) }} + {% endif %}
diff --git a/templates/policies/index.html.twig b/templates/policies/index.html.twig index f084bd9b..902e0354 100644 --- a/templates/policies/index.html.twig +++ b/templates/policies/index.html.twig @@ -20,6 +20,7 @@ {% trans %}scopes{% endtrans %} {% trans from 'general' %}processings{% endtrans %} {% trans from 'general' %}state{% endtrans %} + {% trans from 'general' %}inheritance.fromTeam{% endtrans %} @@ -32,6 +33,9 @@ {% if d.approved %}{% trans from 'general' %}approved{% endtrans %}{% else %}{{ d.statusString }}{% endif %} + + {% if d.team != currentTeam %}{{ d.team }}{% else %}-{% endif %} + {% endfor %}