Add person menu entry for signature list

This commit is contained in:
2024-09-04 15:13:14 +00:00
committed by Julien Fastré
parent 3e5a558cdf
commit 5f5d4b8f06
13 changed files with 240 additions and 30 deletions

View File

@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Repository\Workflow;
use Chill\MainBundle\Entity\Workflow\EntityWorkflowStepSignature;
use Chill\PersonBundle\Entity\Person;
interface EntityWorkflowSignatureACLAwareRepositoryInterface
{
/**
* @return array<EntityWorkflowStepSignature>
*/
public function findByPersonAndPendingState(Person $person): array;
}

View File

@@ -18,9 +18,9 @@ use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ObjectRepository;
class EntityWorkflowStepRepository implements ObjectRepository
readonly class EntityWorkflowStepRepository implements ObjectRepository
{
private readonly EntityRepository $repository;
private EntityRepository $repository;
public function __construct(EntityManagerInterface $entityManager)
{

View File

@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Repository\Workflow;
use Chill\DocStoreBundle\Security\Authorization\StoredObjectRoleEnum;
use Chill\MainBundle\Entity\Workflow\EntityWorkflowSignatureStateEnum;
use Chill\MainBundle\Workflow\EntityWorkflowManager;
use Chill\PersonBundle\Entity\Person;
use Symfony\Component\Security\Core\Security;
class EntityWorkflowStepSignatureACLAwareRepository implements EntityWorkflowSignatureACLAwareRepositoryInterface
{
public function __construct(
private readonly EntityWorkflowStepSignatureRepository $repository,
private readonly EntityWorkflowManager $entityWorkflowManager,
private readonly Security $security,
) {}
public function findByPersonAndPendingState(Person $person): array
{
$signatures = $this->repository->findByPerson($person);
$filteredSignatures = [];
foreach ($signatures as $signature) {
if (EntityWorkflowSignatureStateEnum::SIGNED === $signature->getState() || EntityWorkflowSignatureStateEnum::CANCELED === $signature->getState() || EntityWorkflowSignatureStateEnum::REJECTED === $signature->getState()) {
continue;
}
$workflow = $signature->getStep()->getEntityWorkflow();
$storedObject = $this->entityWorkflowManager->getAssociatedStoredObject($workflow);
if (null === $storedObject) {
continue;
}
if ($this->security->isGranted(StoredObjectRoleEnum::SEE->value, $storedObject)) {
$filteredSignatures[] = $signature;
}
}
return $filteredSignatures;
}
}

View File

@@ -12,43 +12,28 @@ declare(strict_types=1);
namespace Chill\MainBundle\Repository\Workflow;
use Chill\MainBundle\Entity\Workflow\EntityWorkflowStepSignature;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ObjectRepository;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Chill\PersonBundle\Entity\Person;
use Doctrine\Persistence\ManagerRegistry;
/**
* @template-implements ObjectRepository<EntityWorkflowStepSignature>
* @template-extends ServiceEntityRepository<EntityWorkflowStepSignature>
*/
class EntityWorkflowStepSignatureRepository implements ObjectRepository
class EntityWorkflowStepSignatureRepository extends ServiceEntityRepository
{
private readonly \Doctrine\ORM\EntityRepository $repository;
public function __construct(EntityManagerInterface $entityManager)
public function __construct(ManagerRegistry $registry)
{
$this->repository = $entityManager->getRepository(EntityWorkflowStepSignature::class);
parent::__construct($registry, EntityWorkflowStepSignature::class);
}
public function find($id): ?EntityWorkflowStepSignature
public function findByPerson(Person $person): array
{
return $this->repository->find($id);
}
$qb = $this->createQueryBuilder('ewss');
$qb->select('ewss');
$qb->where($qb->expr()->eq('ewss.personSigner', ':person'));
public function findAll(): array
{
return $this->repository->findAll();
}
$qb->setParameter('person', $person);
public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array
{
return $this->findBy($criteria, $orderBy, $limit, $offset);
}
public function findOneBy(array $criteria): ?EntityWorkflowStepSignature
{
return $this->findOneBy($criteria);
}
public function getClassName(): string
{
return EntityWorkflowStepSignature::class;
return $qb->getQuery()->getResult();
}
}