Skip to content

Commit

Permalink
Merge pull request #231 from H2-invent/feature/simple-deletion-concep…
Browse files Browse the repository at this point in the history
…t-inheritance

Feature/simple deletion concept inheritance
  • Loading branch information
KaydenLiss authored Dec 13, 2023
2 parents 8f83cb6 + 00a82bb commit 684dfb2
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 24 deletions.
18 changes: 15 additions & 3 deletions src/Controller/VvtController.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public function editVvt(
VVTService $VVTService,
SecurityService $securityService,
AssignService $assignService,
VVTDatenkategorieService $VVTDatenkategorieService,
VVTDatenkategorieService $vvtDatenkategorieService,
CurrentTeamService $currentTeamService,
VVTRepository $vvtRepository
): Response
Expand All @@ -234,10 +234,13 @@ public function editVvt(
return $this->redirectToRoute('vvt');
}
$newVvt = $VVTService->cloneVvt($vvt, $this->getUser());
$latestCategories = [];

foreach ($vvt->getKategorien() as $category) {//hier haben wir die geklonten Kategorien
$cloneOf = $category->getCloneOf() ?: $category; //wir hängen die neueste gültige Datenkategorie an den VVT clone an.
$newVvt->addKategorien($VVTDatenkategorieService->findLatestKategorie($cloneOf));
$latestCategory = $vvtDatenkategorieService->findLatestKategorie($cloneOf);
$newVvt->addKategorien($latestCategory);
$latestCategories[] = $latestCategory;
}

$isEditable = $vvt->getTeam() === $team;
Expand All @@ -247,14 +250,22 @@ public function editVvt(
$assign = $assignService->createForm($vvt, $team);

$errors = array();
$inheritedEntities = [];

if (!$isEditable) {
// This vvt was inherited by ancestor team.
// In this case we want inherited categories and deletion concepts available by links inside the vvt form.
$inheritedEntities = $vvtDatenkategorieService->getInheritedEntities($latestCategories);
}

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

$errors = $validator->validate($newVvt);
if (count($errors) == 0) {
foreach ($newVvt->getKategorien() as $kategorie) { // wir haben die fiktiven neuesten Kategories
$tmp = $VVTDatenkategorieService->createChild($kategorie);//wir klonen die kategorie damit diese revisionssicher ist
$tmp = $vvtDatenkategorieService->createChild($kategorie);//wir klonen die kategorie damit diese revisionssicher ist
$newVvt->removeKategorien($kategorie);//wir entferenen die fiktive neues kategorie
$newVvt->addKategorien($tmp);//wir fügen die geklonte kategorie an
}
Expand Down Expand Up @@ -300,6 +311,7 @@ public function editVvt(
'activNummer' => false,
'isEditable' => $isEditable,
'currentTeam' => $team,
'inheritedEntities' => $inheritedEntities,
]);
}

Expand Down
41 changes: 41 additions & 0 deletions src/DataTypes/InheritedEntity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace App\DataTypes;

use App\Entity\Loeschkonzept;
use App\Entity\VVTDatenkategorie;

class InheritedEntity
{
private ?VVTDatenkategorie $category;

private ?Loeschkonzept $deletionConcept;

public function __construct()
{
$this->category = null;
$this->deletionConcept = null;
}

public function getCategory(): ?VVTDatenkategorie
{
return $this->category;
}

public function setCategory(?VVTDatenkategorie $category): InheritedEntity
{
$this->category = $category;
return $this;
}

public function getDeletionConcept(): ?Loeschkonzept
{
return $this->deletionConcept;
}

public function setDeletionConcept(?Loeschkonzept $deletionConcept): InheritedEntity
{
$this->deletionConcept = $deletionConcept;
return $this;
}
}
7 changes: 2 additions & 5 deletions src/Repository/VVTDatenkategorieRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class VVTDatenkategorieRepository extends ServiceEntityRepository
{
public function __construct(
ManagerRegistry $registry,
private readonly TeamRepository $teamRepository,
)
{
parent::__construct($registry, VVTDatenkategorie::class);
Expand All @@ -44,14 +43,12 @@ public function add(VVTDatenkategorie $entity, bool $flush = true): void

public function findByTeam(Team $team)
{
$teamPath = $this->teamRepository->getPath($team);

$qb = $this->createQueryBuilder('a');
return $qb
->andWhere('a.team is null OR a.team IN (:teamPath)')
->andWhere('a.team is null OR a.team = :team')
->andWhere($qb->expr()->isNull('a.cloneOf'))
->andWhere('a.activ = 1')
->setParameter('teamPath', $teamPath)
->setParameter('team', $team)
->getQuery()
->getResult();
}
Expand Down
20 changes: 20 additions & 0 deletions src/Service/VVTDatenkategorieService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace App\Service;


use App\DataTypes\InheritedEntity;
use App\Entity\Loeschkonzept;
use App\Entity\Team;
use App\Entity\User;
Expand Down Expand Up @@ -100,4 +101,23 @@ function newVVTDatenkategorie(Team $team, User $user)
return $vVTDatenkategorie;
}

/**
* @param VVTDatenkategorie[] $categories
* @return array
*/
function getInheritedEntities(array $categories): array
{
$result = [];
foreach ($categories as $category) {
$inheritedEntity = new InheritedEntity();
$inheritedEntity->setCategory($category);
$latestDeletionConcept = $category->getLastLoeschkonzept();
if ($latestDeletionConcept && $latestDeletionConcept->getActiv()) {
$inheritedEntity->setDeletionConcept($latestDeletionConcept);
}
$result[] = $inheritedEntity;
}
return $result;
}

}
37 changes: 22 additions & 15 deletions templates/base/__teamToggle.html.twig
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
{% set teams = adminArea is defined and adminArea ? app.user.adminRoles : app.user.teams %}

{% if teams|length > 1 and currentTeam is defined and currentTeam %}
{% if currentTeam is defined and currentTeam %}
<div class="flex flex-row justify-end items-center relative">
<button data-type="dropdown" data-target="#teamtoggle-menu" class="relative !inline-flex !items-center justify-center h-10 gap-x-2 p-3 rounded-[6.25rem] text-sm tracking-[.00714em] text-center font-medium hover:bg-surface-300 focus:bg-surface-400">
<span class="material-symbols-outlined">group</span>
{{ currentTeam.name }}
</button>
<ul id="teamtoggle-menu" role="dropdownmenu" class="dropdown hidden top-10">
{% for team in teams %}
{% if team != currentTeam %}
<li class="relative">
<a href="{{ path('team_switch',{'team':team.id}) }}">{{ team.name }}</a>
</li>
{% endif %}
{% endfor %}
</ul>
{% if teams|length > 1 %}
<button data-type="dropdown" data-target="#teamtoggle-menu" class="relative !inline-flex !items-center justify-center h-10 gap-x-2 p-3 rounded-[6.25rem] text-sm tracking-[.00714em] text-center font-medium hover:bg-surface-300 focus:bg-surface-400">
<span class="material-symbols-outlined">group</span>
{{ currentTeam.name }}
</button>
<ul id="teamtoggle-menu" role="dropdownmenu" class="dropdown hidden top-10">
{% for team in teams %}
{% if team != currentTeam %}
<li class="relative">
<a href="{{ path('team_switch',{'team':team.id}) }}">{{ team.name }}</a>
</li>
{% endif %}
{% endfor %}
</ul>
{% else %}
<div class="!inline-flex !items-center justify-center gap-x-2 p-3 text-sm font-medium">
<span class="material-symbols-outlined">group</span>
{{ currentTeam.name }}
</div>
{% endif %}
</div>
{% endif %}
{% endif %}
39 changes: 39 additions & 0 deletions templates/vvt/__inheritedEntities.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{% if not isEditable %}
<div class="card mt-4">
<h4 class="h4-responsive card-header">{% trans from 'vvt' %}inheritedEntities{% endtrans %}</h4>
<div class="card-body">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>{% trans from 'vvt_datenkategorie' %}dataCategory.word{% endtrans %}</th>
<th>{% trans from 'vvt_datenkategorie' %}deletion.deadline{% endtrans %}</th>
</tr>
</thead>
<tbody>
{% for inherited in inheritedEntities %}
<tr>
<td>
<a class="badge badge-light" href="{{ path('app_vvtdatenkategorie_show', {id: inherited.category.id}) }}">
{{ inherited.category.name }}
</a>
</td>
<td>
{% if inherited.deletionConcept %}
<a class="badge badge-light" href="{{ path('app_loeschkonzept_show', {id: inherited.deletionConcept.id}) }}">
{{ inherited.deletionConcept.standartlf }}
</a>
{% else %}
{% trans from 'loeschkonzept' %}deletionConcept.notSet{% endtrans %}
{% endif %}
</td>
</tr>
{% else %}
<tr><td>{% trans from 'vvt' %}noInheritedEntities{% endtrans %}</td></tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
{% endif %}
2 changes: 1 addition & 1 deletion templates/vvt/edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@

{{ include('vvt/__form.html.twig') }}
<p class="created-by">{% trans from 'general' %}createdBy{% endtrans %}: {{ vvt.user.email }}</p>
{{ include('vvt/__inheritedEntities.html.twig') }}
{% if vvt.previous %}

<h3 class="mt-10">{% trans from 'general' %}history{% endtrans %}</h3>
<ol class="item-history">
{{ include('vvt/__history.html.twig', {'p':vvt.previous}) }}
Expand Down
1 change: 1 addition & 0 deletions translations/loeschkonzept/loeschkonzept.de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ deletionConcept:
new: Neues Löschkonzept anlegen
overview: Löschkonzept Übersicht
directoryOf: Verzeichnis der Löschkonzepte von
notSet: Löschkonzept nicht gesetzt
deadline:
standard: Standard Löschfrist
legal: Gesetzliche Löschfrist
Expand Down
2 changes: 2 additions & 0 deletions translations/vvt/vvt.de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,5 @@ inheritance:
inactive:
short: Gerbte Verarbeitung - für dieses Team deaktiviert
long: Die Verarbeitung wurde mit allen zugehörigen Elementen von einem übergeordneten Team vererbt, diese sind jedoch für dieses Team deaktiviert.
inheritedEntities: Vererbte Datenkategorien und Löschkonzepte
noInheritedEntities: Keine vererbten Datenkategorien und Löschkonzepte verfügbar

0 comments on commit 684dfb2

Please sign in to comment.