mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-27 09:05:01 +00:00
Merge branch '331-manage-attachments-to-workflow' into 'master'
Add attachments to workflow Closes #331 See merge request Chill-Projet/chill-bundles!764
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?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\Workflow\Attachment;
|
||||
|
||||
use Chill\DocStoreBundle\GenericDoc\Exception\AssociatedStoredObjectNotFound;
|
||||
use Chill\DocStoreBundle\GenericDoc\ManagerInterface;
|
||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflowAttachment;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
class AddAttachmentAction
|
||||
{
|
||||
public function __construct(private readonly EntityManagerInterface $em, private readonly ManagerInterface $manager) {}
|
||||
|
||||
/**
|
||||
* @throws AssociatedStoredObjectNotFound
|
||||
*/
|
||||
public function __invoke(AddAttachmentRequestDTO $dto): EntityWorkflowAttachment
|
||||
{
|
||||
$genericDoc = $this->manager->buildOneGenericDoc($dto->relatedGenericDocKey, $dto->relatedGenericDocIdentifiers);
|
||||
|
||||
if (null === $genericDoc) {
|
||||
throw new \RuntimeException(sprintf('could not build any generic doc, %s key and %s identifiers', $dto->relatedGenericDocKey, json_encode($dto->relatedGenericDocIdentifiers)));
|
||||
}
|
||||
|
||||
$storedObject = $this->manager->fetchStoredObject($genericDoc);
|
||||
|
||||
$attachement = new EntityWorkflowAttachment($dto->relatedGenericDocKey, $dto->relatedGenericDocIdentifiers, $dto->entityWorkflow, $storedObject);
|
||||
|
||||
$this->em->persist($attachement);
|
||||
|
||||
return $attachement;
|
||||
}
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
<?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\Workflow\Attachment;
|
||||
|
||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
|
||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
final class AddAttachmentRequestDTO
|
||||
{
|
||||
#[Serializer\Groups('write')]
|
||||
#[Assert\NotNull()]
|
||||
public ?string $relatedGenericDocKey = null;
|
||||
#[Serializer\Groups('write')]
|
||||
#[Assert\NotNull()]
|
||||
public ?array $relatedGenericDocIdentifiers = null;
|
||||
|
||||
public function __construct(
|
||||
public readonly EntityWorkflow $entityWorkflow,
|
||||
) {}
|
||||
}
|
@@ -13,6 +13,7 @@ namespace Chill\MainBundle\Workflow;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
|
||||
@@ -35,6 +36,11 @@ interface EntityWorkflowHandlerInterface
|
||||
*/
|
||||
public function getRelatedEntity(EntityWorkflow $entityWorkflow): ?object;
|
||||
|
||||
/**
|
||||
* Return a related accompanying period, if the workflow can be related in an accompanying period.
|
||||
*/
|
||||
public function getRelatedAccompanyingPeriod(EntityWorkflow $entityWorkflow): ?AccompanyingPeriod;
|
||||
|
||||
public function getRelatedObjects(object $object): array;
|
||||
|
||||
/**
|
||||
|
@@ -18,6 +18,7 @@ use Chill\MainBundle\Entity\Workflow\EntityWorkflowSend;
|
||||
use Chill\MainBundle\Workflow\Exception\HandlerNotFoundException;
|
||||
use Chill\MainBundle\Workflow\Exception\HandlerWithPublicViewNotFoundException;
|
||||
use Chill\MainBundle\Workflow\Templating\EntityWorkflowViewMetadataDTO;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
use Symfony\Component\Workflow\Registry;
|
||||
@@ -157,4 +158,9 @@ class EntityWorkflowManager
|
||||
{
|
||||
return $this->getHandler($entityWorkflow)->getSuggestedThirdParties($entityWorkflow);
|
||||
}
|
||||
|
||||
public function getRelatedAccompanyingPeriod(EntityWorkflow $entityWorkflow): ?AccompanyingPeriod
|
||||
{
|
||||
return $this->getHandler($entityWorkflow)->getRelatedAccompanyingPeriod($entityWorkflow);
|
||||
}
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Workflow\Helper;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
|
||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflowSignatureStateEnum;
|
||||
use Chill\MainBundle\Workflow\EntityWorkflowManager;
|
||||
@@ -146,12 +147,14 @@ class WorkflowRelatedEntityPermissionHelper
|
||||
{
|
||||
$currentUser = $this->security->getUser();
|
||||
|
||||
if (!$currentUser instanceof User) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($entityWorkflows as $entityWorkflow) {
|
||||
// so, the workflow is running... We return true if the current user is involved
|
||||
foreach ($entityWorkflow->getSteps() as $step) {
|
||||
if ($step->getAllDestUser()->contains($currentUser)) {
|
||||
return true;
|
||||
}
|
||||
if ($entityWorkflow->isUserInvolved($currentUser)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user