Skip to content

Commit

Permalink
Add readonly inherited policies
Browse files Browse the repository at this point in the history
  • Loading branch information
melegiul committed Jul 25, 2023
1 parent ab63385 commit bba7280
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 26 deletions.
22 changes: 15 additions & 7 deletions src/Controller/PoliciesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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,
]);
}

Expand All @@ -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,
]);
}
Expand Down
65 changes: 56 additions & 9 deletions src/Form/Type/PolicyType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions src/Repository/PoliciesRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
24 changes: 17 additions & 7 deletions src/Service/PoliciesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions templates/policies/edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
<a class="btn btn-amber ml-1 btn-sm " href="{{ path('bericht_policy', {'id':policy.id, 'all':1}) }}">
<span>{% trans from 'general' %}pdf.createWithHistory{% endtrans %}</span>
</a>
{{ 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 %}

Expand All @@ -21,7 +23,9 @@
{{ include('base/__approvedBy.html.twig', {'data':policy}) }}
</div>
<div class="col-md-4 text-right">
{{ include('assign/__assign.html.twig',{'data':policy,'path':'assign_policy'}) }}
{% if isEditable %}
{{ include('assign/__assign.html.twig',{'data':policy,'path':'assign_policy'}) }}
{% endif %}
</div>
</div>

Expand Down
4 changes: 4 additions & 0 deletions templates/policies/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<th scope="col">{% trans %}scopes{% endtrans %}</th>
<th scope="col">{% trans from 'general' %}processings{% endtrans %}</th>
<th scope="col">{% trans from 'general' %}state{% endtrans %}</th>
<th scope="col">{% trans from 'general' %}inheritance.fromTeam{% endtrans %}</th>
</tr>
</thead>
<tbody>
Expand All @@ -32,6 +33,9 @@
<td>{% if d.approved %}<span
class="note-success p-1">{% trans from 'general' %}approved{% endtrans %}</span>{% else %}{{ d.statusString }}{% endif %}
</td>
<td{% if d.team != currentTeam %} title="{% trans from 'general' %}inheritance.infoText{% endtrans %}"{% endif %}>
{% if d.team != currentTeam %}{{ d.team }}{% else %}-{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
Expand Down

0 comments on commit bba7280

Please sign in to comment.