Skip to content

Commit

Permalink
update policy repository
Browse files Browse the repository at this point in the history
  • Loading branch information
KaydenLiss committed Aug 8, 2023
1 parent 6e7e547 commit 7571733
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/Controller/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function dashboard(Request $request,
$kontakte = $contactRepository->findActiveByTeamPath($teamPath);
$tom = $tomRepository->findActiveByTeam($currentTeam);
$forms = $formRepository->findPublicByTeam($currentTeam);
$policies = $policyRepository->findPublicByTeamPath($teamPath);
$policies = $policyRepository->findPublicByTeam($currentTeam);
$software = $softwareRepository->findActiveByTeam($currentTeam);
$tasks = $taskRepository->findActiveAndOpenByTeam($currentTeam);
$loeschkonzepte = $deletionConceptRepository->findByTeam($currentTeam);
Expand Down
5 changes: 2 additions & 3 deletions src/Controller/PoliciesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ public function editPolicy(
'activ' => $policy->getActiv(),
'snack' => $request->get('snack'),
'isEditable' => $isEditable,
'currentTeam' => $team,
]);
}

Expand All @@ -228,16 +229,14 @@ 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');
}

$teamPath = $teamRepository->getPath($team);
$policies = $policiesRepository->findActiveByTeamPath($teamPath);
$policies = $policiesRepository->findAllByTeam($team);

return $this->render('policies/index.html.twig', [
'data' => $policies,
Expand Down
73 changes: 45 additions & 28 deletions src/Repository/PoliciesRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace App\Repository;

use App\Entity\Policies;
use App\Entity\Team;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ManagerRegistry;

/**
Expand All @@ -14,52 +16,67 @@
*/
class PoliciesRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
public function __construct(
ManagerRegistry $registry,
private readonly TeamRepository $teamRepository,
)
{
parent::__construct($registry, Policies::class);
}

public function findActiveByTeam($value)
public function findActiveByTeam(Team $team)
{
return $this->createQueryBuilder('a')
->andWhere('a.team = :val')
->andWhere('a.activ = 1')
->setParameter('val', $value)
->getQuery()
->getResult();
$queryBuilder = $this->getBaseQueryBuilder(team: $team);
$this->excludeIgnored(team: $team, queryBuilder: $queryBuilder);
return $queryBuilder->getQuery()->getResult();
}

public function findActiveByTeamPath(array $teamPath)
public function findAllByTeam(Team $team)
{
return $this->createQueryBuilder('a')
->andWhere('a.team IN (:teamPath)')
->andWhere('a.activ = 1')
->setParameter('teamPath', $teamPath)
->getQuery()
->getResult();
$queryBuilder = $this->getBaseQueryBuilder(team: $team);
return $queryBuilder->getQuery()->getResult();
}

public function findPublicByTeamPath(array $teamPath)
public function findPublicByTeam(Team $team)
{
return $this->createQueryBuilder('a')
->andWhere('a.team IN (:teamPath)')
->andWhere('a.activ = 1')
->andWhere('a.status != 4')
->setParameter('teamPath', $teamPath)
->getQuery()
->getResult();
$queryBuilder = $this->getBaseQueryBuilder(team: $team);
$this->excludeIgnored(team: $team, queryBuilder: $queryBuilder);
$queryBuilder->andWhere('a.status != 4');
return $queryBuilder->getQuery()->getResult();
}

public function findActiveByTeamAndUser($team, $user)
{
return $this->createQueryBuilder('a')
->andWhere('a.team = :team')
$queryBuilder = $this->getBaseQueryBuilder(team: $team);
$this->excludeIgnored(team: $team, queryBuilder: $queryBuilder);
$queryBuilder
->andWhere('a.assignedUser = :user')
->setParameter('user', $user)
;
return $queryBuilder->getQuery()->getResult();
}

private function excludeIgnored(Team $team, QueryBuilder $queryBuilder) :void
{
$ignored = $team->getIgnoredInheritances();
if (count($ignored)) {
$queryBuilder
->andWhere('process NOT IN (:ignored)')
->setParameter('ignored', $ignored);
}
}

private function getBaseQueryBuilder(Team $team) :QueryBuilder
{
$teamPath = $this->teamRepository->getPath($team);

return $this->createQueryBuilder('a')
->innerJoin('a.processes', 'process')
->andWhere('a.team = :team OR (process.team = :team OR process.inherited = 1) AND process.activ = 1 AND process.team IN (:teamPath)')
->andWhere('a.activ = 1')
->setParameter('teamPath', $teamPath)
->setParameter('team', $team)
->setParameter('user', $user)
->orderBy('a.createdAt', 'DESC')
->getQuery()
->getResult();
;
}
}
1 change: 1 addition & 0 deletions src/Repository/TomRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ private function getBaseQueryBuilder(Team $team) :QueryBuilder
return $this->createQueryBuilder('a')
->innerJoin('a.vvts', 'process')
->andWhere('a.team = :team OR (process.team = :team OR process.inherited = 1) AND process.activ = 1 AND process.team IN (:teamPath)')
->andWhere('a.activ = 1')
->setParameter('teamPath', $teamPath)
->setParameter('team', $team)
->orderBy('a.createdAt', 'DESC')
Expand Down
6 changes: 6 additions & 0 deletions templates/policies/edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
{{ include('assign/__assign.html.twig',{'data':policy,'path':'assign_policy'}) }}
{% endif %}
</div>
<div class="col-12">
{% set inherited = policyInherited(policy) %}
{% set used = teamUsesPolicy(currentTeam, policy) %}
{% include 'base/__inheritanceInfo.html.twig' with {team:policy.team, currentTeam:currentTeam, used:used, inherited:inherited} %}
{% include 'base/__flashMessage.html.twig' with {app:app} %}
</div>
</div>


Expand Down

0 comments on commit 7571733

Please sign in to comment.