Commit 6c06c3ba authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Merge branch 'fix_rapport_assertion'

parents cbbf1927 2e71e028
Loading
Loading
Loading
Loading
+21 −18
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@

namespace Application;

use Application\Assertion\RapportActivite\RapportActiviteAssertion;
use Application\Assertion\Rapport\RapportAssertion;
use Application\Controller\Factory\Rapport\RapportActiviteControllerFactory;
use Application\Controller\Factory\Rapport\RapportActiviteRechercheControllerFactory;
use Application\Controller\Factory\Rapport\RapportCsiControllerFactory;
@@ -81,7 +81,7 @@ return [
                            RapportPrivileges::RAPPORT_MIPARCOURS_TELECHARGER_SIEN,
                        ],
                        'resources'  => ['Rapport'],
                        'assertion' => 'Assertion\\RapportActivite', /** @see RapportActiviteAssertion */
                        'assertion' => 'Assertion\\Rapport', /** @see RapportAssertion */
                    ],
                ],
            ],
@@ -98,7 +98,7 @@ return [
                        RapportPrivileges::RAPPORT_ACTIVITE_LISTER_TOUT,
                        RapportPrivileges::RAPPORT_ACTIVITE_LISTER_SIEN,
                    ],
                    'assertion' => 'Assertion\\RapportActivite',
                    'assertion' => 'Assertion\\Rapport',
                ],
                [
                    'controller' => RapportActiviteController::class,
@@ -109,7 +109,7 @@ return [
                        RapportPrivileges::RAPPORT_ACTIVITE_TELECHARGER_TOUT,
                        RapportPrivileges::RAPPORT_ACTIVITE_TELECHARGER_SIEN,
                    ],
                    'assertion' => 'Assertion\\RapportActivite',
                    'assertion' => 'Assertion\\Rapport',
                ],
                [
                    'controller' => RapportActiviteController::class,
@@ -120,7 +120,7 @@ return [
                        RapportPrivileges::RAPPORT_ACTIVITE_TELEVERSER_TOUT,
                        RapportPrivileges::RAPPORT_ACTIVITE_TELEVERSER_SIEN,
                    ],
                    'assertion' => 'Assertion\\RapportActivite',
                    'assertion' => 'Assertion\\Rapport',
                ],
                [
                    'controller' => RapportActiviteController::class,
@@ -131,7 +131,7 @@ return [
                        RapportPrivileges::RAPPORT_ACTIVITE_SUPPRIMER_TOUT,
                        RapportPrivileges::RAPPORT_ACTIVITE_SUPPRIMER_SIEN,
                    ],
                    'assertion' => 'Assertion\\RapportActivite',
                    'assertion' => 'Assertion\\Rapport',
                ],
                [
                    'controller' => RapportActiviteRechercheController::class,
@@ -143,7 +143,7 @@ return [
                        RapportPrivileges::RAPPORT_ACTIVITE_RECHERCHER_TOUT,
                        RapportPrivileges::RAPPORT_ACTIVITE_RECHERCHER_SIEN,
                    ],
                    'assertion' => 'Assertion\\RapportActivite',
                    'assertion' => 'Assertion\\Rapport',
                ],
                [
                    'controller' => RapportActiviteRechercheController::class,
@@ -151,7 +151,7 @@ return [
                        'telecharger-zip',
                    ],
                    'privileges' => RapportPrivileges::RAPPORT_ACTIVITE_TELECHARGER_ZIP,
                    'assertion' => 'Assertion\\RapportActivite',
                    'assertion' => 'Assertion\\Rapport',
                ],
                [
                    'controller' => RapportValidationController::class,
@@ -162,7 +162,7 @@ return [
                        RapportPrivileges::RAPPORT_ACTIVITE_VALIDER_TOUT,
                        RapportPrivileges::RAPPORT_ACTIVITE_VALIDER_SIEN,
                    ],
                    'assertion' => 'Assertion\\RapportActivite',
                    'assertion' => 'Assertion\\Rapport',
                ],
                [
                    'controller' => RapportValidationController::class,
@@ -173,7 +173,7 @@ return [
                        RapportPrivileges::RAPPORT_ACTIVITE_DEVALIDER_TOUT,
                        RapportPrivileges::RAPPORT_ACTIVITE_DEVALIDER_SIEN,
                    ],
                    'assertion' => 'Assertion\\RapportActivite',
                    'assertion' => 'Assertion\\Rapport',
                ],

                ////////////////////////////////////////// Rapports CSI //////////////////////////////////////////
@@ -186,7 +186,7 @@ return [
                        RapportPrivileges::RAPPORT_CSI_LISTER_TOUT,
                        RapportPrivileges::RAPPORT_CSI_LISTER_SIEN,
                    ],
                    'assertion' => 'Assertion\\RapportActivite',
                    'assertion' => 'Assertion\\Rapport',
                ],
                [
                    'controller' => RapportCsiController::class,
@@ -197,7 +197,7 @@ return [
                        RapportPrivileges::RAPPORT_CSI_TELECHARGER_TOUT,
                        RapportPrivileges::RAPPORT_CSI_TELECHARGER_SIEN,
                    ],
                    'assertion' => 'Assertion\\RapportActivite',
                    'assertion' => 'Assertion\\Rapport',
                ],
                [
                    'controller' => RapportCsiController::class,
@@ -208,7 +208,7 @@ return [
                        RapportPrivileges::RAPPORT_CSI_TELEVERSER_TOUT,
                        RapportPrivileges::RAPPORT_CSI_TELEVERSER_SIEN,
                    ],
                    'assertion' => 'Assertion\\RapportActivite',
                    'assertion' => 'Assertion\\Rapport',
                ],
                [
                    'controller' => RapportCsiController::class,
@@ -219,7 +219,7 @@ return [
                        RapportPrivileges::RAPPORT_CSI_SUPPRIMER_TOUT,
                        RapportPrivileges::RAPPORT_CSI_SUPPRIMER_SIEN,
                    ],
                    'assertion' => 'Assertion\\RapportActivite',
                    'assertion' => 'Assertion\\Rapport',
                ],
                [
                    'controller' => RapportCsiRechercheController::class,
@@ -250,7 +250,7 @@ return [
                        RapportPrivileges::RAPPORT_MIPARCOURS_LISTER_TOUT,
                        RapportPrivileges::RAPPORT_MIPARCOURS_LISTER_SIEN,
                    ],
                    'assertion' => 'Assertion\\RapportActivite',
                    'assertion' => 'Assertion\\Rapport',
                ],
                [
                    'controller' => RapportMiparcoursController::class,
@@ -261,7 +261,7 @@ return [
                        RapportPrivileges::RAPPORT_MIPARCOURS_TELECHARGER_TOUT,
                        RapportPrivileges::RAPPORT_MIPARCOURS_TELECHARGER_SIEN,
                    ],
                    'assertion' => 'Assertion\\RapportActivite',
                    'assertion' => 'Assertion\\Rapport',
                ],
                [
                    'controller' => RapportMiparcoursController::class,
@@ -272,7 +272,7 @@ return [
                        RapportPrivileges::RAPPORT_MIPARCOURS_TELEVERSER_TOUT,
                        RapportPrivileges::RAPPORT_MIPARCOURS_TELEVERSER_SIEN,
                    ],
                    'assertion' => 'Assertion\\RapportActivite',
                    'assertion' => 'Assertion\\Rapport',
                ],
                [
                    'controller' => RapportMiparcoursController::class,
@@ -283,7 +283,7 @@ return [
                        RapportPrivileges::RAPPORT_MIPARCOURS_SUPPRIMER_TOUT,
                        RapportPrivileges::RAPPORT_MIPARCOURS_SUPPRIMER_SIEN,
                    ],
                    'assertion' => 'Assertion\\RapportActivite',
                    'assertion' => 'Assertion\\Rapport',
                ],
                [
                    'controller' => RapportMiparcoursRechercheController::class,
@@ -676,6 +676,7 @@ return [
                                    RapportPrivileges::RAPPORT_ACTIVITE_RECHERCHER_TOUT,
                                    RapportPrivileges::RAPPORT_ACTIVITE_RECHERCHER_SIEN,
                                ],
                                'visible' => 'Assertion\\Rapport',
                            ],
                            'rapport-csi' => [
                                'label'    => "Rapports CSI",
@@ -686,6 +687,7 @@ return [
                                    RapportPrivileges::RAPPORT_CSI_RECHERCHER_TOUT,
                                    RapportPrivileges::RAPPORT_CSI_RECHERCHER_SIEN,
                                ],
                                'visible' => 'Assertion\\Rapport',
                            ],
                            'rapport-miparcours' => [
                                'label'    => "Rapports mi-parcours",
@@ -696,6 +698,7 @@ return [
                                    RapportPrivileges::RAPPORT_MIPARCOURS_RECHERCHER_TOUT,
                                    RapportPrivileges::RAPPORT_MIPARCOURS_RECHERCHER_SIEN,
                                ],
                                'visible' => 'Assertion\\Rapport',
                            ],
                            '----------' => [
                                'label' => null,
+3 −0
Original line number Diff line number Diff line
@@ -951,6 +951,7 @@ return [
                                    'these',
                                ],
                                'resource' => PrivilegeController::getResourceId(RapportActiviteController::class, 'consulter'),
                                'visible' => 'Assertion\\Rapport',
                            ],
                            'rapport-csi' => [
                                'label' => 'Rapports CSI',
@@ -961,6 +962,7 @@ return [
                                    'these',
                                ],
                                'resource' => PrivilegeController::getResourceId(RapportCsiController::class, 'consulter'),
                                'visible' => 'Assertion\\Rapport',
                            ],
                            'rapport-miparcours' => [
                                'label' => 'Rapports mi-parcours',
@@ -971,6 +973,7 @@ return [
                                    'these',
                                ],
                                'resource' => PrivilegeController::getResourceId(RapportMiparcoursController::class, 'consulter'),
                                'visible' => 'Assertion\\Rapport',
                            ],
                            'divider-2' => [
                                'label' => null,
+20 −30
Original line number Diff line number Diff line
<?php

namespace Application\Assertion\RapportActivite;
namespace Application\Assertion\Rapport;

use Application\Assertion\BaseAssertion;
use Application\Entity\Db\Rapport;
use Zend\Permissions\Acl\Resource\ResourceInterface;

class RapportActiviteAssertion extends BaseAssertion
/**
 * Class RapportAssertion
 *
 * @property \Application\Assertion\Rapport\RapportEntityAssertion $entityAssertion
 * @property \Application\Assertion\Rapport\RapportControllerAssertion $controllerAssertion
 * @property \Application\Assertion\Rapport\RapportPageAssertion $pageAssertion
 */
class RapportAssertion extends BaseAssertion
{
    protected function getContext(): array
    {
        return [
            'these' => $this->getRouteMatch()->getThese(),
            'rapport' => $this->getRouteMatch()->getRapport(),
        ];
    }

    /**
     * @return self
     */
    protected function initControllerAssertion(): self
    {
        $this->controllerAssertion->setContext([
            'rapport' => $this->getRapportActivite(),
        ]);
        $this->controllerAssertion->setContext($this->getContext());

        return $this;
    }
@@ -25,9 +37,7 @@ class RapportActiviteAssertion extends BaseAssertion
     */
    protected function initPageAssertion(): self
    {
        $this->pageAssertion->setContext([
            'rapport' => $this->getRapportActivite(),
        ]);
        $this->pageAssertion->setContext($this->getContext());

        return $this;
    }
@@ -38,28 +48,8 @@ class RapportActiviteAssertion extends BaseAssertion
     */
    protected function initEntityAssertion(ResourceInterface $entity): self
    {
        $this->entityAssertion->setContext([
            'rapport' => $entity,
        ]);
        $this->entityAssertion->setContext(['rapport' => $entity]);

        return $this;
    }

    /**
     * @return Rapport|null
     */
    protected function getRapportActivite(): ?Rapport
    {
        $these = $this->getRouteMatch()->getThese();
        $rapport = $this->getRouteMatch()->getRapport();

//        if ($rapport === null) {
//            $rapport = new Rapport();
//            if ($these !== null) {
//                $rapport->setThese($these);
//            }
//        }

        return $rapport;
    }
}
 No newline at end of file
+17 −16
Original line number Diff line number Diff line
<?php

namespace Application\Assertion\RapportActivite;
namespace Application\Assertion\Rapport;

use Application\Assertion\ControllerAssertion;
use Application\Assertion\ThrowsFailedAssertionExceptionTrait;
use Application\Entity\Db\Doctorant;
use Application\Entity\Db\Rapport;
use Application\Entity\Db\These;
use Application\Provider\Privilege\RapportPrivileges;
use Application\Service\UserContextServiceAwareTrait;

class RapportActiviteControllerAssertion extends ControllerAssertion
class RapportControllerAssertion extends ControllerAssertion
{
    use ThrowsFailedAssertionExceptionTrait;
    use UserContextServiceAwareTrait;

    /**
     * @var Rapport
     * @var \Application\Entity\Db\These
     */
    private $rapport;
    private $these;

    /**
     * @param array $context
     */
    public function setContext(array $context)
    {
        $this->rapport = $context['rapport'] ?? null;
        $this->these = $context['these'] ?? null;
    }

    /**
     * @inheritDoc
     */
    public function assert($privilege = null)
    public function assert($privilege = null): bool
    {
        if ($this->rapport === null) {
            return true;
        }
        if ($this->rapport->getThese() === null) {
        if ($this->these === null) {
            return true;
        }

@@ -49,15 +42,23 @@ class RapportActiviteControllerAssertion extends ControllerAssertion
    {
        if ($doctorant = $this->userContextService->getIdentityDoctorant()) {
            $this->assertTrue(
                $this->rapport->getThese()->getDoctorant()->getId() === $doctorant->getId(),
                $this->these->getDoctorant()->getId() === $doctorant->getId(),
                "La thèse n'appartient pas au doctorant " . $doctorant
            );
        }
        if ($roleEcoleDoctorale = $this->userContextService->getSelectedRoleDirecteurEcoleDoctorale()) {
            $this->assertTrue(
                $this->rapport->getThese()->getEcoleDoctorale()->getStructure()->getId() === $roleEcoleDoctorale->getStructure()->getId(),
                $this->these->getEcoleDoctorale()->getStructure()->getId() === $roleEcoleDoctorale->getStructure()->getId(),
                "La thèse n'est pas rattachée à l'ED " . $roleEcoleDoctorale->getStructure()->getCode()
            );
        }
        if ($this->userContextService->getSelectedRoleDirecteurThese()) {
            $individuUtilisateur = $this->userContextService->getIdentityDb()->getIndividu();
            $this->assertTrue(
                $this->these->hasActeurWithRole($individuUtilisateur, \Application\Entity\Db\Role::CODE_DIRECTEUR_THESE) ||
                $this->these->hasActeurWithRole($individuUtilisateur, \Application\Entity\Db\Role::CODE_CODIRECTEUR_THESE),
                "La thèse n'est pas dirigée par " . $individuUtilisateur
            );
        }
    }
}
 No newline at end of file
+36 −4
Original line number Diff line number Diff line
<?php

namespace Application\Assertion\RapportActivite;
namespace Application\Assertion\Rapport;

use Application\Assertion\Exception\FailedAssertionException;
use Application\Assertion\Interfaces\EntityAssertionInterface;
use Application\Assertion\ThrowsFailedAssertionExceptionTrait;
use Application\Entity\Db\Rapport;
use Application\Entity\Db\Role;
use Application\Entity\Db\These;
use Application\Entity\Db\TypeValidation;
use Application\Provider\Privilege\RapportPrivileges;
use Application\Service\UserContextServiceAwareTrait;

class RapportActiviteEntityAssertion implements EntityAssertionInterface
class RapportEntityAssertion implements EntityAssertionInterface
{
    use UserContextServiceAwareTrait;
    use ThrowsFailedAssertionExceptionTrait;
@@ -45,6 +45,16 @@ class RapportActiviteEntityAssertion implements EntityAssertionInterface
            case RapportPrivileges::RAPPORT_ACTIVITE_VALIDER_SIEN:
            case RapportPrivileges::RAPPORT_ACTIVITE_DEVALIDER_TOUT:
            case RapportPrivileges::RAPPORT_ACTIVITE_DEVALIDER_SIEN:

            case RapportPrivileges::RAPPORT_CSI_TELEVERSER_TOUT:
            case RapportPrivileges::RAPPORT_CSI_TELEVERSER_SIEN:
            case RapportPrivileges::RAPPORT_CSI_SUPPRIMER_TOUT:
            case RapportPrivileges::RAPPORT_CSI_SUPPRIMER_SIEN:

            case RapportPrivileges::RAPPORT_MIPARCOURS_TELEVERSER_TOUT:
            case RapportPrivileges::RAPPORT_MIPARCOURS_TELEVERSER_SIEN:
            case RapportPrivileges::RAPPORT_MIPARCOURS_SUPPRIMER_TOUT:
            case RapportPrivileges::RAPPORT_MIPARCOURS_SUPPRIMER_SIEN:
                $this->assertEtatThese();
        }

@@ -56,6 +66,14 @@ class RapportActiviteEntityAssertion implements EntityAssertionInterface
            case RapportPrivileges::RAPPORT_ACTIVITE_VALIDER_SIEN:
            case RapportPrivileges::RAPPORT_ACTIVITE_DEVALIDER_TOUT:
            case RapportPrivileges::RAPPORT_ACTIVITE_DEVALIDER_SIEN:

            case RapportPrivileges::RAPPORT_CSI_TELEVERSER_SIEN:
            case RapportPrivileges::RAPPORT_CSI_SUPPRIMER_SIEN:
            case RapportPrivileges::RAPPORT_CSI_TELECHARGER_SIEN:

            case RapportPrivileges::RAPPORT_MIPARCOURS_TELEVERSER_SIEN:
            case RapportPrivileges::RAPPORT_MIPARCOURS_SUPPRIMER_SIEN:
            case RapportPrivileges::RAPPORT_MIPARCOURS_TELECHARGER_SIEN:
                $this->assertAppartenanceThese();
        }

@@ -64,6 +82,12 @@ class RapportActiviteEntityAssertion implements EntityAssertionInterface
            case RapportPrivileges::RAPPORT_ACTIVITE_SUPPRIMER_SIEN:
            case RapportPrivileges::RAPPORT_ACTIVITE_VALIDER_TOUT:
            case RapportPrivileges::RAPPORT_ACTIVITE_VALIDER_SIEN:

            case RapportPrivileges::RAPPORT_CSI_SUPPRIMER_TOUT:
            case RapportPrivileges::RAPPORT_CSI_SUPPRIMER_SIEN:

            case RapportPrivileges::RAPPORT_MIPARCOURS_SUPPRIMER_TOUT:
            case RapportPrivileges::RAPPORT_MIPARCOURS_SUPPRIMER_SIEN:
                $this->assertAucuneValidation();
        }

@@ -84,6 +108,14 @@ class RapportActiviteEntityAssertion implements EntityAssertionInterface
                "La thèse n'est pas rattachée à l'ED " . $roleEcoleDoctorale->getStructure()->getCode()
            );
        }
        if ($this->userContextService->getSelectedRoleDirecteurThese()) {
            $individuUtilisateur = $this->userContextService->getIdentityDb()->getIndividu();
            $this->assertTrue(
                $this->rapport->getThese()->hasActeurWithRole($individuUtilisateur, Role::CODE_DIRECTEUR_THESE) ||
                $this->rapport->getThese()->hasActeurWithRole($individuUtilisateur, Role::CODE_CODIRECTEUR_THESE),
                "La thèse n'est pas dirigée par " . $individuUtilisateur
            );
        }
    }

    private function assertEtatThese()
@@ -97,7 +129,7 @@ class RapportActiviteEntityAssertion implements EntityAssertionInterface
    private function assertAucuneValidation()
    {
        $this->assertTrue(
            $this->rapport->getRapportValidationOfType(TypeValidation::CODE_RAPPORT_ACTIVITE) === null,
            $this->rapport->getRapportValidation() === null,
            "Le rapport ne doit pas avoir été validé"
        );
    }
Loading