Adjust logic for removing the hold on a workflow only by user who owns the hold and when a transition is applied on the workflow

This commit is contained in:
2024-08-30 12:59:08 +02:00
committed by Julien Fastré
parent 41ffc470a0
commit 745a29f742
5 changed files with 48 additions and 26 deletions

View File

@@ -12,12 +12,14 @@ declare(strict_types=1);
namespace Chill\MainBundle\Repository\Workflow;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
use Chill\MainBundle\Entity\Workflow\EntityWorkflowStep;
use Chill\MainBundle\Entity\Workflow\EntityWorkflowStepHold;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\NoResultException;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\Workflow\Workflow;
/**
* @template-extends ServiceEntityRepository<EntityWorkflowStepHold>
@@ -58,6 +60,23 @@ class EntityWorkflowStepHoldRepository extends ServiceEntityRepository
return $this->findBy(['step' => $step]);
}
/**
* @throws NonUniqueResultException
*/
public function findByWorkflow(EntityWorkflow $workflow): ?EntityWorkflowStepHold
{
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select('h')
->from(EntityWorkflowStepHold::class, 'h')
->join('h.step', 's')
->join('s.entityWorkflow', 'w')
->where('w = :workflow')
->setParameter('workflow', $workflow);
return $qb->getQuery()->getOneOrNullResult();
}
/**
* Find a single EntityWorkflowStepHold by step and user.
*