Commit bbb4b7a3 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

début refactoring assertion pj

parent 5317fdeb
Loading
Loading
Loading
Loading
Loading
+20 −50
Changes for module/PieceJointe/src/Assertion/PiecesJointesAssertion.php: 20 added lines, 50 removed lines.
Original line number Diff line number Diff line
@@ -2,10 +2,9 @@

namespace PieceJointe\Assertion;

use Application\Provider\Privileges;
use Laminas\Permissions\Acl\Resource\ResourceInterface;
use Unicaen\Framework\Authorize\AbstractAssertion;
use Intervenant\Entity\Db\Intervenant;
use Laminas\Permissions\Acl\Resource\ResourceInterface;
use PieceJointe\Controller\PieceJointeController;
use Workflow\Entity\Db\WorkflowEtape;
use Workflow\Service\WorkflowServiceAwareTrait;
@@ -21,37 +20,21 @@ class PiecesJointesAssertion extends AbstractAssertion
    use WorkflowServiceAwareTrait;


    /**
     * @param string $controller
     * @param string $action
     * @param string $privilege
     *
     * @return boolean
     */
    protected function assertController(string $controller, ?string $action): bool
    {
        $intervenant = $this->getParam(Intervenant::class);

        if (!$intervenant) return false;

        switch ($controller) {
            case PieceJointeController::class:
                switch ($action) {
                    case 'index':
                        if (!$this->assertPriv(Privileges::PIECE_JUSTIFICATIVE_VISUALISATION)) return false;
                        if (!$intervenant) return false;
                        return $this->assertPieceJointeAction($intervenant);
                    case 'televerser':
                    case 'supprimer':
                        if (!$this->assertPriv(Privileges::PIECE_JUSTIFICATIVE_EDITION)) return false;

                        return $this->assertPieceJointeAction($intervenant);
                        return $this->assertSaisie($intervenant);
                    case 'valider':
                        if (!$this->assertPriv(Privileges::PIECE_JUSTIFICATIVE_VALIDATION)) return false;

                        return $this->assertPieceJointeAction($intervenant);
                    case 'devalider':
                        if (!$this->assertPriv(Privileges::PIECE_JUSTIFICATIVE_DEVALIDATION)) return false;

                        return $this->assertPieceJointeAction($intervenant);
                        return $this->assertValidation($intervenant);
                }
                break;
        }
@@ -61,51 +44,38 @@ class PiecesJointesAssertion extends AbstractAssertion



    /**
     * @param ResourceInterface $entity
     * @param string            $privilege
     *
     * @return boolean
     */
    protected function assertEntity(?ResourceInterface $entity, $privilege = null): bool
    protected function assertEntity(ResourceInterface $entity, ?string $privilege): bool
    {
        // @todo test par PJ en fonction des privilèges première instance/complémentaire,
        // Vérifier que l'assertion est bien exploitée
        return true;
    }



    protected function assertDossierEdition(Intervenant $intervenant): bool
    protected function assertSaisie(Intervenant $intervenant): bool
    {
        if (!$this->assertEtapeAtteignable(WorkflowEtape::DONNEES_PERSO_SAISIE, $intervenant)) {
            return false;
        $feuilleDeRoute = $this->getServiceWorkflow()->getFeuilleDeRoute($intervenant);
        if ($feuilleDeRoute->get(WorkflowEtape::PJ_SAISIE)?->isAllowed()) {
            return true;
        }

        if ($feuilleDeRoute->get(WorkflowEtape::PJ_COMPL_SAISIE)?->isAllowed()) {
            return true;
        }



    protected function assertPieceJointeAction(Intervenant $intervenant): bool
    {
        if (!$this->assertEtapeAtteignable(WorkflowEtape::PJ_SAISIE, $intervenant)) {
        return false;
    }

        return true;
    }



    protected function assertEtapeAtteignable($etape, Intervenant $intervenant): bool
    protected function assertValidation(Intervenant $intervenant): bool
    {
        $feuilleDeRoute = $this->getServiceWorkflow()->getFeuilleDeRoute($intervenant);
        return $feuilleDeRoute->get($etape)?->isAllowed() ?: false;
        if ($feuilleDeRoute->get(WorkflowEtape::PJ_VALIDATION)?->isAllowed()) {
            return true;
        }



    protected function assertPriv($privilege): bool
    {
        return $this->authorize->isAllowedPrivilege($privilege);
        if ($feuilleDeRoute->get(WorkflowEtape::PJ_COMPL_VALIDATION)?->isAllowed()) {
            return true;
        }
        return false;
    }
}
 No newline at end of file