Skip to content

Commit

Permalink
Add readonly inherited vvt
Browse files Browse the repository at this point in the history
- Adds extra column "Inherited by team" to vvt table
- Inherited vvt cannot be edited
  • Loading branch information
melegiul committed Jul 20, 2023
1 parent 4abf786 commit d199c5f
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 28 deletions.
16 changes: 11 additions & 5 deletions src/Controller/VvtController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace App\Controller;

use App\Form\Type\VvtDsfaType;
use App\Repository\TeamRepository;
use App\Repository\VVTDsfaRepository;
use App\Repository\VVTRepository;
use App\Service\ApproveService;
Expand Down Expand Up @@ -216,12 +217,14 @@ public function editVvt(
VVTDatenkategorieService $VVTDatenkategorieService,
CurrentTeamService $currentTeamService,
VVTRepository $vvtRepository,
TeamRepository $teamRepository
): Response
{
$team = $currentTeamService->getCurrentTeam($this->getUser());
$vvt = $vvtRepository->find($request->get('id'));
$teamPath = $team ? $teamRepository->getPath($team) : null;

if ($securityService->teamDataCheck($vvt, $team) === false) {
if ($securityService->teamPathDataCheck($vvt, $teamPath) === false) {
return $this->redirectToRoute('vvt');
}
$newVvt = $VVTService->cloneVvt($vvt, $this->getUser());
Expand All @@ -230,13 +233,13 @@ public function editVvt(
$newVvt->addKategorien($VVTDatenkategorieService->findLatestKategorie($cloneKat->getCloneOf()));//wir hängen die neueste gültige Datenkategorie an den VVT clone an.
}

$form = $VVTService->createForm($newVvt, $team);
$form = $VVTService->createForm($newVvt, $team, ['disabled' => $vvt->getTeam() !== $team]);
$form->remove('nummer');
$form->handleRequest($request);
$assign = $assignService->createForm($vvt, $team);

$errors = array();
if ($form->isSubmitted() && $form->isValid() && $vvt->getActiv() && !$vvt->getApproved()) {
if ($form->isSubmitted() && $form->isValid() && $vvt->getActiv() && !$vvt->getApproved() && $vvt->getTeam() === $team) {
$vvt->setActiv(false);
$newVvt = $form->getData();

Expand Down Expand Up @@ -287,7 +290,8 @@ public function editVvt(
'vvt' => $vvt,
'activ' => $vvt->getActiv(),
'activNummer' => false,
'snack' => $request->get('snack')
'snack' => $request->get('snack'),
'isEditable' => $vvt->getTeam() === $team
]);
}

Expand Down Expand Up @@ -353,13 +357,15 @@ public function index(
Request $request,
CurrentTeamService $currentTeamService,
VVTRepository $vvtRepository,
TeamRepository $teamRepository
): Response
{
$team = $currentTeamService->getCurrentTeam($this->getUser());
if ($securityService->teamCheck($team) === false) {
return $this->redirectToRoute('dashboard');
}
$vvt = $vvtRepository->findActiveByTeam($team);
$teamPath = $teamRepository->getPath($team);
$vvt = $vvtRepository->findActiveByTeamPath($teamPath);

return $this->render('vvt/index.html.twig', [
'vvt' => $vvt,
Expand Down
19 changes: 12 additions & 7 deletions src/Form/Type/VVTType.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class VVTType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$summernoteClass = 'summernote';
if ($options['disabled']) {
$summernoteClass .= ' summernote-disable';
}

$builder
->add('nummer', TextType::class, [
Expand Down Expand Up @@ -82,7 +86,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'help' => 'procedureUsedSOftwareHelp'
])
->add('zweck', TextareaType::class, [
'attr' => ['class' => 'summernote'],
'attr' => ['class' => $summernoteClass],
'label' => 'procedurePurpose',
'required' => true,
'translation_domain' => 'form',
Expand All @@ -101,7 +105,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'help' => 'isContractHelp'
])
->add('speicherung', TextareaType::class, [
'attr' => ['class' => 'summernote'],
'attr' => ['class' => $summernoteClass],
'label' => 'procedureDataStorage',
'required' => true,
'translation_domain' => 'form',
Expand All @@ -115,7 +119,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'help' => 'deleteDeadlineHelp'
])
->add('weitergabe', TextareaType::class, [
'attr' => ['class' => 'summernote'],
'attr' => ['readonly'=>true, 'class' => $summernoteClass],
'label' => 'procedureDataTransferPartners',
'required' => false,
'translation_domain' => 'form',
Expand Down Expand Up @@ -192,7 +196,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'help' => 'procedureTOM'
])
->add('tom', TextareaType::class, [
'attr' => ['class' => 'summernote'],
'attr' => ['class' => $summernoteClass],
'label' => 'procedureFurtherMeasures',
'required' => false,
'translation_domain' => 'form',
Expand Down Expand Up @@ -245,14 +249,14 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'help' => 'procedureDataCollectionHelp'
])
->add('informationspflicht', TextareaType::class, [
'attr' => ['class' => 'summernote'],
'attr' => ['readonly'=>true, 'class' => $summernoteClass],
'label' => 'informationObligation',
'required' => false,
'translation_domain' => 'form',
'help' => 'informationObligationHelp'
])
->add('dsb', TextareaType::class, [
'attr' => ['class' => 'summernote'],
'attr' => ['class' => $summernoteClass],
'label' => 'dsbComment',
'required' => false,
'translation_domain' => 'form',
Expand Down Expand Up @@ -327,7 +331,8 @@ public function configureOptions(OptionsResolver $resolver)
'tom' => array(),
'abteilung' => array(),
'produkte' => array(),
'software' => array()
'software' => array(),
'disabled' => true
]);
}
}
33 changes: 33 additions & 0 deletions src/Service/SecurityService.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,37 @@ public function teamDataCheck($data, $team): bool

return true;
}

/**
* @param $data
* @param Team[]|null $teamPath
* @return bool
*/
public function teamPathDataCheck($data, ?array $teamPath): bool
{
//Sicherheitsfunktion, dass ein Team vorhanden ist
if (!$teamPath) {
$message = [
'typ' => 'LOGIN',
'error' => true,
'hinweis' => $this->translator->trans(id: 'error.userWithoutTeam', domain: 'general'),
];
$this->logger->error($message['typ'], $message);
return false;
}

//Sicherheitsfunktion, dass nur eigene Daten bearbeitet werden können
if (!in_array($data->getTeam(), $teamPath)) {
$message = [
'typ' => 'LOGIN',
'error' => true,
'hinweis' => $this->translator->trans(id: 'error.userNotInTeamAccessDenied', domain: 'general'),
'team' => $teamPath,
];
$this->logger->error($message['typ'], $message);
return false;
}

return true;
}
}
33 changes: 17 additions & 16 deletions src/Service/VVTService.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function cloneVvt(VVT $vvt, User $user)
return $newVvt;
}

function createForm(VVT $VVT, Team $team)
function createForm(VVT $VVT, Team $team, array $options = [])
{
$status = $this->em->getRepository(VVTStatus::class)->findActiveByTeam($team);
$personen = $this->em->getRepository(VVTPersonen::class)->findByTeam($team);
Expand All @@ -75,21 +75,22 @@ function createForm(VVT $VVT, Team $team)
$produkte = $this->em->getRepository(Produkte::class)->findActiveByTeam($team);
$software = $this->em->getRepository(Software::class)->findActiveByTeam($team);

$form = $this->formBuilder->create(VVTType::class, $VVT, [
'personen' => $personen,
'kategorien' => $kategorien,
'risiken' => $risiken,
'status' => $status,
'grundlage' => $grundlagen,
'user' => $team->getMembers(),
'daten' => $daten,
'tom' => $tom,
'abteilung' => $abteilung,
'produkte' => $produkte,
'software' => $software
]);

return $form;
return $this->formBuilder->create(VVTType::class, $VVT, array_merge(
[
'personen' => $personen,
'kategorien' => $kategorien,
'risiken' => $risiken,
'status' => $status,
'grundlage' => $grundlagen,
'user' => $team->getMembers(),
'daten' => $daten,
'tom' => $tom,
'abteilung' => $abteilung,
'produkte' => $produkte,
'software' => $software
],
$options
));
}

function newDsfa(Team $team, User $user, VVT $vvt)
Expand Down
4 changes: 4 additions & 0 deletions templates/vvt/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<th scope="col">{% trans from 'general' %}product{% endtrans %}</th>
<th scope="col">{% trans from 'general' %}state{% endtrans %}</th>
<th scope="col">{% trans %}assessment{% endtrans %}</th>
<th scope="col">{% trans from 'general' %}inheritance.fromTeam{% endtrans %}</th>
</tr>
</thead>
<tbody>
Expand All @@ -46,6 +47,9 @@
{% endif %}
</td>
<td>| E: {{ v.beurteilungEintrittString }}<br>| S: {{ v.beurteilungSchadenString }}</td>
<td{% if v.team != currentTeam %} title="{% trans from 'general' %}inheritance.infoText{% endtrans %}"{% endif %}>
{% if v.team != currentTeam %}{{ v.team }}{% else %}-{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
Expand Down
3 changes: 3 additions & 0 deletions translations/general/general.de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,6 @@ uuid: UID
version: Version
versionApproved: (Diese Version war freigegeben)
yes: Ja
inheritance:
fromTeam: Von Team vererbt
infoText: Dieses Element wurde durch Team-Vererbung übertragen und ist daher nicht bearbeitbar.
3 changes: 3 additions & 0 deletions translations/general/general.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,6 @@ uuid: UID
version: Version
versionApproved: (Diese Version war freigegeben)
yes: Ja
inheritance:
fromTeam: Inherited from team
infoText: This element was transferred by team inheritance und thus is not editable.
3 changes: 3 additions & 0 deletions translations/general/general.ev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,6 @@ uuid: UID
version: Version
versionApproved: (Diese Version war freigegeben)
yes: Ja
inheritance:
fromTeam: Von Team vererbt
infoText: Dieses Element wurde durch Team-Vererbung übertragen und ist daher nicht bearbeitbar.
3 changes: 3 additions & 0 deletions translations/general/general.fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,6 @@ uuid: UID
version: Version
versionApproved: (Diese Version war freigegeben)
yes: Ja
inheritance:
fromTeam: Von Team vererbt
infoText: Dieses Element wurde durch Team-Vererbung übertragen und ist daher nicht bearbeitbar.

0 comments on commit d199c5f

Please sign in to comment.