Skip to content

Commit

Permalink
Merge pull request #236 from H2-invent/feature/dsfa_table
Browse files Browse the repository at this point in the history
Create index page with table for DSFA
  • Loading branch information
holema authored Dec 28, 2023
2 parents 76aa4a4 + ebfdfb2 commit 8194bf1
Show file tree
Hide file tree
Showing 15 changed files with 207 additions and 120 deletions.
128 changes: 128 additions & 0 deletions src/Controller/DsfaController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php

namespace App\Controller;

use App\Entity\Team;
use App\Form\Type\VvtDsfaType;
use App\Repository\VVTDsfaRepository;
use App\Repository\VVTRepository;
use App\Service\AssignService;
use App\Service\CurrentTeamService;
use App\Service\SecurityService;
use App\Service\VVTService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

class DsfaController extends BaseController
{
public function __construct(
private TranslatorInterface $translator,
private VVTDsfaRepository $repo,
private VVTRepository $VVTRepository,
private EntityManagerInterface $em,
private CurrentTeamService $currentTeamService,
private VVTService $VVTService,
private SecurityService $securityService)
{
}

#[Route('/dsfa', name: 'dsfa')]
public function index(): Response
{
return $this->render('dsfa/index.html.twig', [
'title' => $this->translator->trans(id: 'dataProtectionImpactAssessment.word_plural', domain: 'vvt'),
'dsfas' => $this->repo->findAllByTeam($this->getTeam()),
]);
}

#[Route(path: '/dsfa/new', name: 'dsfa_new')]
public function new(ValidatorInterface $validator, Request $request): Response
{
$team = $this->getTeam();
$vvt = $this->VVTRepository->find($request->get('vvt'));
if ($this->securityService->teamDataCheck($vvt, $team) === false) {
return $this->redirectToRoute('vvt');
}

$dsfa = $this->VVTService->newDsfa($team, $this->getUser(), $vvt);
$form = $this->createForm(VvtDsfaType::class,$dsfa );
$form->handleRequest($request);
$errors = array();

if ($form->isSubmitted() && $form->isValid()) {
$dsfa = $form->getData();
$errors = $validator->validate($dsfa);
if (count($errors) == 0) {
$this->em->persist($dsfa);
$this->em->flush();
$this->addSuccessMessage($this->translator->trans(id: 'dsfa.created', domain: 'vvt'));

return $this->redirectToRoute('vvt_edit', [
'id' => $dsfa->getVvt()->getId(),
]);
}
}

return $this->render('dsfa/edit.html.twig', [
'form' => $form->createView(),
'errors' => $errors,
'title' => $this->translator->trans(id: 'dataPrivacyFollowUpEstimation.create', domain: 'vvt'),
'dsfa' => $dsfa,
'activ' => $dsfa->getActiv(),
]);
}

#[Route(path: '/dsfa/edit', name: 'dsfa_edit')]
public function edit(ValidatorInterface $validator, Request $request, AssignService $assignService): Response
{
$team = $this->getTeam();
$dsfa = $this->repo->find($request->get('dsfa'));

if ($this->securityService->teamDataCheck($dsfa->getVvt(), $team) === false) {
return $this->redirectToRoute('vvt');
}

$newDsfa = $this->VVTService->cloneDsfa($dsfa, $this->getUser());
$form = $this->createForm(VvtDsfaType::class, $newDsfa);
$form->handleRequest($request);
$assign = $assignService->createForm($dsfa, $team);
$errors = array();

if ($form->isSubmitted() && $form->isValid() && $dsfa->getActiv() && !$dsfa->getVvt()->getApproved()) {
$dsfa->setActiv(false);
$newDsfa = $form->getData();
$errors = $validator->validate($newDsfa);

if (count($errors) == 0) {
$this->em->persist($newDsfa);
$this->em->persist($dsfa);
$this->em->flush();
$this->addSuccessMessage($this->translator->trans(id: 'save.successful', domain: 'general'));

return $this->redirectToRoute('dsfa_edit', [
'dsfa' => $newDsfa->getId(),
]);
}
}

$this->setBackButton($this->generateUrl('vvt_edit', ['id' => $dsfa->getVvt()->getId()]));

return $this->render('dsfa/edit.html.twig', [
'form' => $form->createView(),
'assignForm' => $assign->createView(),
'errors' => $errors,
'title' => $this->translator->trans(id: 'dataPrivacyFollowUpEstimation.edit', domain: 'vvt'),
'dsfa' => $dsfa,
'activ' => $dsfa->getActiv(),
]);
}

private function getTeam(): ?Team
{
return $this->currentTeamService->getTeamFromSession($this->getUser());
}
}
104 changes: 1 addition & 103 deletions src/Controller/VvtController.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public function editVvt(
}
}

$this->setBackButton($this->generateUrl('vvt_edit', ['id' => $vvt->getId()]));
$this->setBackButton($this->generateUrl('vvt'));

return $this->render('vvt/edit.html.twig', [
'form' => $form->createView(),
Expand All @@ -295,61 +295,6 @@ public function editVvt(
]);
}

#[Route(path: '/vvt/dsfa/edit', name: 'vvt_dsfa_edit')]
public function editVvtDsfa(
ValidatorInterface $validator,
Request $request,
VVTService $VVTService,
SecurityService $securityService,
AssignService $assignService,
CurrentTeamService $currentTeamService,
VVTDsfaRepository $vvtDsfaRepository,
): Response
{
$team = $currentTeamService->getTeamFromSession($this->getUser());
$dsfa = $vvtDsfaRepository->find($request->get('dsfa'));

if ($securityService->teamDataCheck($dsfa->getVvt(), $team) === false) {
return $this->redirectToRoute('vvt');
}

$newDsfa = $VVTService->cloneDsfa($dsfa, $this->getUser());

$form = $this->createForm(VvtDsfaType::class, $newDsfa);
$form->handleRequest($request);
$assign = $assignService->createForm($dsfa, $team);

$errors = array();
if ($form->isSubmitted() && $form->isValid() && $dsfa->getActiv() && !$dsfa->getVvt()->getApproved()) {

$dsfa->setActiv(false);
$newDsfa = $form->getData();
$errors = $validator->validate($newDsfa);
if (count($errors) == 0) {
$this->em->persist($newDsfa);
$this->em->persist($dsfa);
$this->em->flush();
$this->addSuccessMessage($this->translator->trans(id: 'save.successful', domain: 'general'));

return $this->redirectToRoute(
'vvt_dsfa_edit',
[
'dsfa' => $newDsfa->getId(),
],
);
}
}

return $this->render('vvt/editDsfa.html.twig', [
'form' => $form->createView(),
'assignForm' => $assign->createView(),
'errors' => $errors,
'title' => $this->translator->trans(id: 'dataPrivacyFollowUpEstimation.edit', domain: 'vvt'),
'dsfa' => $dsfa,
'activ' => $dsfa->getActiv(),
]);
}

#[Route(path: '/vvt', name: 'vvt')]
public function index(
SecurityService $securityService,
Expand All @@ -369,51 +314,4 @@ public function index(
'currentTeam' => $team,
]);
}

#[Route(path: '/vvt/dsfa/new', name: 'vvt_dsfa_new')]
public function newVvtDsfa(
ValidatorInterface $validator,
Request $request,
VVTService $VVTService,
SecurityService $securityService,
CurrentTeamService $currentTeamService,
VVTRepository $vvtRepository,
): Response
{
$team = $currentTeamService->getTeamFromSession($this->getUser());
$vvt = $vvtRepository->find($request->get('vvt'));

if ($securityService->teamDataCheck($vvt, $team) === false) {
return $this->redirectToRoute('vvt');
}

$dsfa = $VVTService->newDsfa($team, $this->getUser(), $vvt);

$form = $this->createForm(VvtDsfaType::class, $dsfa);
$form->handleRequest($request);

$errors = array();
if ($form->isSubmitted() && $form->isValid()) {
$dsfa = $form->getData();
$errors = $validator->validate($dsfa);
if (count($errors) == 0) {
$this->em->persist($dsfa);
$this->em->flush();
$this->addSuccessMessage($this->translator->trans(id: 'dsfa.created', domain: 'vvt'));
return $this->redirectToRoute(
'vvt_edit',
[
'id' => $dsfa->getVvt()->getId(),
],
);
}
}
return $this->render('vvt/editDsfa.html.twig', [
'form' => $form->createView(),
'errors' => $errors,
'title' => $this->translator->trans(id: 'dataPrivacyFollowUpEstimation.create', domain: 'vvt'),
'dsfa' => $dsfa,
'activ' => $dsfa->getActiv(),
]);
}
}
15 changes: 15 additions & 0 deletions src/Repository/VVTDsfaRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Repository;

use App\Entity\VVTDsfa;
use App\Entity\Team;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

Expand All @@ -19,6 +20,20 @@ public function __construct(ManagerRegistry $registry)
parent::__construct($registry, VVTDsfa::class);
}

public function findAllByTeam(Team $team): array
{
return $this->createQueryBuilder('d')
->innerJoin('d.vvt', 'v')
->andWhere('v.team = :team')
->andWhere('d.activ = 1')
->andWhere('v.activ = 1')
->setParameter('team', $team)
->orderBy('d.id', 'DESC')
->getQuery()
->getResult()
;
}

public function findActiveByTeam($value)
{
return $this->createQueryBuilder('a')
Expand Down
1 change: 1 addition & 0 deletions src/Security/KeycloakAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function onAuthenticationFailure(
AuthenticationException $exception,
): ?Response
{
$this->logger->error($exception->getMessage());
return new RedirectResponse($this->router->generate('no_team'));
}

Expand Down
1 change: 1 addition & 0 deletions src/Service/MenuService.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function createElementsMenu(array $options): ?ItemInterface
$menu->addChild($this->trans('dataCategories'), ['route' => 'app_vvtdatenkategorie_index']);
$menu->addChild($this->trans('toms'), ['route' => 'tom']);
$menu->addChild($this->trans('processings'), ['route' => 'vvt']);
$menu->addChild($this->trans('dsfa'), ['route' => 'dsfa']);
$menu->addChild($this->trans('deleteConcepts'), ['route' => 'app_loeschkonzept_index']);
$menu->addChild($this->trans('policies'), ['route' => 'policies']);
$menu->addChild($this->trans('contacts'), ['route' => 'kontakt']);
Expand Down
2 changes: 1 addition & 1 deletion templates/assign/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
{% for a in impactAssessments %}
{% if a.vvt.team == currentTeam %}
<li>
<a href="{{ path('vvt_dsfa_edit',{'dsfa':a.id}) }}">{{ a.vvt.team.name }}: {{ a.beschreibung }}</a>
<a href="{{ path('dsfa_edit',{'dsfa':a.id}) }}">{{ a.vvt.team.name }}: {{ a.beschreibung }}</a>
<div>{{ a.vvt.name }}</div>
<div>{{ a.createdAt|date('d.m.Y') }}</div>
</li>
Expand Down
2 changes: 1 addition & 1 deletion templates/dashboard/__assign.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
{% for a in assignDsfa %}
{% if a.activ %}
<li>
<a href="{{ path('vvt_dsfa_edit',{'dsfa':a.id}) }}">{{ a.vvt.team.name }}: {{ a.beschreibung }}</a>
<a href="{{ path('dsfa_edit',{'dsfa':a.id}) }}">{{ a.vvt.team.name }}: {{ a.beschreibung }}</a>
<div>{{ a.createdAt|date('d.m.Y') }}</div>
</li>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion templates/dashboard/__critical.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<ul>
{% for d in openDsfa %}
<li>
<a href="{{ path('vvt_dsfa_edit', {'dsfa':d.id}) }}">{{ d.createdAt|date('d.m.Y H:i') }}
<a href="{{ path('dsfa_edit', {'dsfa':d.id}) }}">{{ d.createdAt|date('d.m.Y H:i') }}
- {{ d.vvt.name }}
({% trans %}{% if not d.dsb %}dsbMissing{% else %}resultMissing{% endif %}{% endtrans %}
)</a></li>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{% trans_default_domain 'vvt' %}
<li>
<a href="{{ path('vvt_dsfa_edit',{'dsfa':p.id}) }}">
<a href="{{ path('dsfa_edit',{'dsfa':p.id}) }}">
{{ p.createdAt|date('d.m.Y h:m') }} -- id: {{ p.id }} -- {% trans from 'general' %}createdBy{% endtrans %}: {{ p.user.email }}
{% if not p.dsb %} --<span>{% trans %}dsbReviewMissing{% endtrans %}</span>{% endif %}
{% if not p.ergebnis %} -- <span>{% trans %}resultMissing{% endtrans %}</span>{% endif %}
</a>
</li>
{% if p.previous %}
{{ include('vvt/__dsfaHistory.html.twig', {'p':p.previous}) }}
{{ include('dsfa/__history.html.twig', {'p':p.previous}) }}
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
{% endblock %}

{% block body %}
<hr>
<div class="my-5">
<a href="{{ path('vvt_edit', {'id': dsfa.vvt.id}) }}" class="btn text-gray-700">
&raquo; {% trans from 'vvt' %}processing.show{% endtrans %}
</a>
</div>
{{ form_start(form) }}
<fieldset>
{{ form_row(form.beschreibung) }}
Expand All @@ -26,8 +32,7 @@
{% if dsfa.previous %}
<h3 class="mt-10">{% trans from 'general' %}history{% endtrans %}</h3>
<ol class="item-history">
{{ include('vvt/__dsfaHistory.html.twig', {'p':dsfa.previous}) }}
{{ include('dsfa/__history.html.twig', {'p':dsfa.previous}) }}
</ol>
{% endif %}

{% endblock %}
32 changes: 32 additions & 0 deletions templates/dsfa/index.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{% extends 'base.html.twig' %}

{% block title %}
{{ title }}
{% endblock %}

{% set fullWidthLayout = true %}

{% block body %}
<table id="data-table" class="dataTable">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">VVT</th>
<th scope="col">{% trans from 'general' %}state{% endtrans %}</th>
<th scope="col">{% trans from 'general' %}appoved{% endtrans %}</th>
<th scope="col">{% trans from 'general' %}date{% endtrans %}</th>
</tr>
</thead>
<tbody>
{% for dsfa in dsfas %}
<tr data-href='{{ path('dsfa_edit',{'dsfa':dsfa.id}) }}'>
<td>{{ dsfa.vvt.nummer }}</td>
<td>{{ dsfa.vvt.name }}</td>
<td>{{ dsfa.vvt.approved ? 'approved'|trans : dsfa.vvt.status.name }}</td>
<td>{{ dsfa.vvt.approved ? 'yes'|trans : 'no'|trans }}</td>
<td>{{ dsfa.createdAt|date('d.m.Y H:i:s') }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
Loading

0 comments on commit 8194bf1

Please sign in to comment.