Loading module/Contrat/Module.php +x+22 Changes for module/Contrat/Module.php: 22 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Contrat; use Application\ConfigFactory; class Module { public function getConfig() { return ConfigFactory::configFromSimplified(__DIR__, __NAMESPACE__); } public function getAutoloaderConfig() { return ConfigFactory::autoloaderConfig(__DIR__, __NAMESPACE__); } } module/Contrat/autoload_classmap.php +x+4 Changes for module/Contrat/autoload_classmap.php: 4 added lines, 0 removed lines. Original line number Diff line number Diff line <?php // Generated by UnicaenCode return [ ]; No newline at end of file module/Contrat/config/module.config.php +x+211 Changes for module/Contrat/config/module.config.php: 211 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Contrat; use Application\Provider\Privilege\Privileges; use Contrat\Assertion\ContratAssertion; use Contrat\Controller\ContratController; use Contrat\Service\ContratServiceListeService; return [ 'routes' => [ 'contrat' => [ 'route' => '/contrat', 'controller' => ContratController::class, 'action' => 'index', 'may_terminate' => true, 'child_routes' => [ 'creer' => [ 'route' => '/:intervenant/creer/:structure', 'constraints' => [ 'structure' => '[0-9]*', ], 'action' => 'creer', 'controller' => ContratController::class, ], 'supprimer' => [ 'route' => '/:contrat/supprimer', 'constraints' => [ 'contrat' => '[0-9]*', ], 'action' => 'supprimer', 'controller' => ContratController::class, ], 'valider' => [ 'route' => '/:contrat/valider', 'constraints' => [ 'contrat' => '[0-9]*', ], 'action' => 'valider', 'controller' => ContratController::class, ], 'devalider' => [ 'route' => '/:contrat/devalider', 'constraints' => [ 'contrat' => '[0-9]*', ], 'action' => 'devalider', 'controller' => ContratController::class, ], 'saisir-retour' => [ 'route' => '/:contrat/saisir-retour', 'constraints' => [ 'contrat' => '[0-9]*', ], 'action' => 'saisir-retour', 'controller' => ContratController::class, ], 'exporter' => [ 'route' => '/:contrat/exporter', 'constraints' => [ 'contrat' => '[0-9]*', ], 'action' => 'exporter', 'controller' => ContratController::class, ], 'envoyer-mail' => [ 'route' => '/:contrat/mail', 'constraints' => [ 'contrat' => '[0-9]*', ], 'action' => 'envoyer-mail', 'controller' => ContratController::class, ], 'deposer-fichier' => [ 'route' => '/:contrat/deposer-fichier', 'constraints' => [ 'contrat' => '[0-9]*', ], 'action' => 'deposer-fichier', 'controller' => ContratController::class, ], 'lister-fichier' => [ 'route' => '/:contrat/lister-fichier', 'constraints' => [ 'contrat' => '[0-9]*', ], 'action' => 'lister-fichier', 'controller' => ContratController::class, ], 'telecharger-fichier' => [ 'route' => '/:contrat/telecharger-fichier[/:fichier/:nomFichier]', 'constraints' => [ 'contrat' => '[0-9]*', ], 'action' => 'telecharger-fichier', 'controller' => ContratController::class, ], 'supprimer-fichier' => [ 'route' => '/:contrat/supprimer-fichier[/:fichier]', 'constraints' => [ 'contrat' => '[0-9]*', 'fichier' => '[0-9]*', ], 'action' => 'supprimer-fichier', 'controller' => ContratController::class, ], ], ], ], 'guards' => [ [ 'controller' => ContratController::class, 'action' => ['index'], 'privileges' => Privileges::CONTRAT_VISUALISATION, 'assertion' => \Contrat\Assertion\ContratAssertion::class, ], [ 'controller' => ContratController::class, 'action' => ['telecharger-fichier', 'lister-fichier'], 'privileges' => Privileges::CONTRAT_VISUALISATION, ], [ 'controller' => ContratController::class, 'action' => ['exporter'], 'privileges' => [Privileges::CONTRAT_CONTRAT_GENERATION, Privileges::CONTRAT_PROJET_GENERATION], 'assertion' => \Contrat\Assertion\ContratAssertion::class, ], [ 'controller' => ContratController::class, 'action' => ['envoyer-mail'], 'privileges' => [Privileges::CONTRAT_ENVOI_EMAIL], ], [ 'controller' => ContratController::class, 'action' => ['creer'], 'privileges' => Privileges::CONTRAT_CREATION, 'assertion' => \Contrat\Assertion\ContratAssertion::class, ], [ 'controller' => ContratController::class, 'action' => ['supprimer'], 'privileges' => Privileges::CONTRAT_SUPPRESSION, 'assertion' => \Contrat\Assertion\ContratAssertion::class, ], [ 'controller' => ContratController::class, 'action' => ['valider'], 'privileges' => Privileges::CONTRAT_VALIDATION, 'assertion' => \Contrat\Assertion\ContratAssertion::class, ], [ 'controller' => ContratController::class, 'action' => ['devalider'], 'privileges' => Privileges::CONTRAT_DEVALIDATION, 'assertion' => \Contrat\Assertion\ContratAssertion::class, ], [ 'controller' => ContratController::class, 'action' => ['deposer-fichier', 'supprimer-fichier'], 'privileges' => Privileges::CONTRAT_DEPOT_RETOUR_SIGNE, 'assertion' => \Contrat\Assertion\ContratAssertion::class, ], [ 'controller' => ContratController::class, 'action' => ['saisir-retour'], 'privileges' => Privileges::CONTRAT_SAISIE_DATE_RETOUR_SIGNE, 'assertion' => \Contrat\Assertion\ContratAssertion::class, ], ], 'rules' => [ [ 'privileges' => [ Privileges::CONTRAT_CREATION, Privileges::CONTRAT_DEPOT_RETOUR_SIGNE, Privileges::CONTRAT_DEVALIDATION, Privileges::CONTRAT_SAISIE_DATE_RETOUR_SIGNE, Privileges::CONTRAT_SUPPRESSION, Privileges::CONTRAT_VALIDATION, Privileges::CONTRAT_VISUALISATION, Privileges::CONTRAT_PROJET_GENERATION, Privileges::CONTRAT_CONTRAT_GENERATION, Privileges::CONTRAT_ENVOI_EMAIL, ContratAssertion::PRIV_LISTER_FICHIERS, ContratAssertion::PRIV_AJOUTER_FICHIER, ContratAssertion::PRIV_SUPPRIMER_FICHIER, ContratAssertion::PRIV_EXPORT, ], 'resources' => 'Contrat', 'assertion' => \Contrat\Assertion\ContratAssertion::class, ], ], 'controllers' => [ ContratController::class => \Contrat\Controller\ContratControllerFactory::class, ], 'services' => [ \Contrat\Assertion\ContratAssertion::class => \UnicaenPrivilege\Assertion\AssertionFactory::class, \Contrat\Service\ContratService::class => \Contrat\Service\ContratServiceFactory::class, \Contrat\Service\TypeContratService::class => \Contrat\Service\TypeContratServiceFactory::class, \Contrat\Processus\ContratProcessus::class => \Contrat\Processus\ContratProcessusFactory::class, \Contrat\Service\ContratServiceListeService::class => \Contrat\Service\ContratServiceListeServiceFactory::class, ], 'view_helpers' => [ ], 'forms' => [ \Contrat\Form\ContratValidationForm::class => \Contrat\Form\ContratValidationFormFactory::class, /** @todo à supprimer ? */ \Contrat\Form\ContratRetourForm::class => \Contrat\Form\ContratRetourFormFactory::class, ], ]; module/Contrat/src/Assertion/ContratAssertion.php +x+288 Changes for module/Contrat/src/Assertion/ContratAssertion.php: 288 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Contrat\Assertion; use Application\Acl\Role; use Application\Entity\Db\Intervenant; use Application\Entity\Db\Parametre; use Application\Entity\Db\Structure; use Application\Entity\Db\WfEtape; use Application\Provider\Privilege\Privileges; use Application\Service\Traits\ParametresServiceAwareTrait; use Contrat\Entity\Db\Contrat; // sous réserve que vous utilisiez les privilèges d'UnicaenAuth et que vous ayez généré votre fournisseur use Application\Service\Traits\WorkflowServiceAwareTrait; use UnicaenPrivilege\Assertion\AbstractAssertion; use Laminas\Permissions\Acl\Resource\ResourceInterface; /** * Description of ContratAssertion * * @author LECLUSE Laurent <laurent.lecluse at unicaen.fr> */ class ContratAssertion extends AbstractAssertion { use ParametresServiceAwareTrait; const PRIV_LISTER_FICHIERS = 'contrat-lister-fichiers'; const PRIV_SUPPRIMER_FICHIER = 'contrat-supprimer-fichier'; const PRIV_AJOUTER_FICHIER = 'contrat-ajouter-fichier'; const PRIV_EXPORT = 'contrat-export-all'; use WorkflowServiceAwareTrait; /** * @param ResourceInterface $entity * @param string $privilege * * @return boolean */ protected function assertEntity(ResourceInterface $entity, $privilege = null) { $localPrivs = [ self::PRIV_LISTER_FICHIERS, self::PRIV_AJOUTER_FICHIER, self::PRIV_SUPPRIMER_FICHIER, ]; $role = $this->getRole(); // Si le rôle n'est pas renseigné alors on s'en va... if (!$role instanceof Role) return false; switch (true) { case $entity instanceof Contrat: switch ($privilege) { case Privileges::CONTRAT_PROJET_GENERATION: case Privileges::CONTRAT_CONTRAT_GENERATION: case self::PRIV_EXPORT: return $this->assertGeneration($entity); } break; } // pareil si le rôle ne possède pas le privilège adéquat if ($privilege && !in_array($privilege, $localPrivs) && !$role->hasPrivilege($privilege)) return false; // @todo traiter les privilèges locaux!! switch (true) { case $entity instanceof Contrat: switch ($privilege) { case self::PRIV_LISTER_FICHIERS: return $this->assertListerFichiers($entity); case self::PRIV_AJOUTER_FICHIER: case self::PRIV_SUPPRIMER_FICHIER: return $this->assertModifierFichier($entity); case Privileges::CONTRAT_VISUALISATION: return $this->assertVisualisation($entity); case Privileges::CONTRAT_CREATION: return $this->assertCreation($entity); case Privileges::CONTRAT_VALIDATION: return $this->assertValidation($entity); case Privileges::CONTRAT_DEPOT_RETOUR_SIGNE: return $this->assertDepotRetourSigne($entity); case Privileges::CONTRAT_SAISIE_DATE_RETOUR_SIGNE: return $this->assertSaisieDateRetour($entity); case Privileges::CONTRAT_DEVALIDATION: return $this->assertDevalidation($entity); case Privileges::CONTRAT_SUPPRESSION: return $this->assertSuppression($entity); } break; } return true; } /** * @param string $controller * @param string $action * @param string $privilege * * @return boolean */ protected function assertController($controller, $action = null, $privilege = null) { $intervenant = $this->getMvcEvent()->getParam('intervenant'); if ($intervenant) { $workflowEtape = $this->getServiceWorkflow()->getEtape(WfEtape::CODE_CONTRAT, $intervenant); $wfOk = $workflowEtape && $workflowEtape->isAtteignable(); if (!$wfOk) return false; } return true; } protected function assertListerFichiers(Contrat $contrat) { return $this->asserts([ $this->getRole()->hasPrivilege(Privileges::CONTRAT_VISUALISATION), $this->assertVisualisation($contrat), !$contrat->estUnProjet(), ]); } protected function assertModifierFichier(Contrat $contrat) { return $this->asserts([ $this->getRole()->hasPrivilege(Privileges::CONTRAT_DEPOT_RETOUR_SIGNE), empty($contrat->getDateRetourSigne()), $this->assertDepotRetourSigne($contrat), ]); } protected function assertVisualisation(Contrat $contrat) { return $this->assertRole($contrat); } protected function assertCreation(Contrat $contrat) { return $this->asserts([ $this->assertRole($contrat), $this->assertWorkflow($contrat), ]); } protected function assertValidation(Contrat $contrat) { return $this->asserts([ $this->assertRole($contrat), !$contrat->getValidation(), ]); } protected function assertDevalidation(Contrat $contrat) { if (!$contrat->estUnAvenant()) { $devalid = $contrat->getIntervenant()->getContrat()->count() == 1; // on ne peut dévalider un contrat que si aucun avenant n'existe } else { $devalid = true; } $contratDirectResult = $this->getServiceParametres()->get('contrat_direct'); $contratDirect = ($contratDirectResult == Parametre::CONTRAT_DIRECT); return $this->asserts([ $this->assertRole($contrat), $contrat->getValidation() && !$contratDirect, !$contrat->getDateRetourSigne(), $devalid, ]); } protected function assertSuppression(Contrat $contrat) { if (!$contrat->estUnAvenant()) { $devalid = $contrat->getIntervenant()->getContrat()->count() == 1; // on ne peut supprimer un contrat que si aucun avenant n'existe } else { $devalid = true; } $contratDirectResult = $this->getServiceParametres()->get('contrat_direct'); $contratDirect = ($contratDirectResult == Parametre::CONTRAT_DIRECT); return $this->asserts([ $this->assertRole($contrat), !$contrat->getValidation() || ($contratDirect && $devalid), !$contrat->getDateRetourSigne(), ]); } protected function assertGeneration(Contrat $contrat) { if ($contrat->estUnProjet()) { return $this->getRole()->hasPrivilege(Privileges::CONTRAT_PROJET_GENERATION); } else { return $this->getRole()->hasPrivilege(Privileges::CONTRAT_CONTRAT_GENERATION); } } protected function assertDepotRetourSigne(Contrat $contrat) { return $this->asserts([ $this->assertRole($contrat), !$contrat->estUnProjet(), ]); } protected function assertSaisieDateRetour(Contrat $contrat) { return $this->asserts([ $this->assertRole($contrat), !$contrat->estUnProjet(), ]); } protected function assertRole(Contrat $contrat, $checkStructure = true) { if ($intervenant = $this->getRole()->getIntervenant()) { if (!$this->assertIntervenant($contrat, $intervenant)) return false; } if ($checkStructure && ($structure = $this->getRole()->getStructure())) { if (!$this->assertStructure($contrat, $structure)) return false; } return true; } protected function assertIntervenant(Contrat $contrat, Intervenant $intervenant) { return $contrat->getIntervenant() == $intervenant; } protected function assertStructure(Contrat $contrat, Structure $structure) { return $contrat->getStructure() == $structure || $contrat->getStructure() == null; } protected function assertWorkflow(Contrat $contrat) { $workflowEtape = $this->getServiceWorkflow()->getEtape(WfEtape::CODE_CONTRAT, $contrat->getIntervenant(), $contrat->getStructure()); return $this->asserts( $workflowEtape && $workflowEtape->isAtteignable() ); } } No newline at end of file module/Contrat/src/Controller/ContratController.php +x+594 File added.Preview size limit exceeded, changes collapsed. Show changes Loading
module/Contrat/Module.php +x+22 Changes for module/Contrat/Module.php: 22 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Contrat; use Application\ConfigFactory; class Module { public function getConfig() { return ConfigFactory::configFromSimplified(__DIR__, __NAMESPACE__); } public function getAutoloaderConfig() { return ConfigFactory::autoloaderConfig(__DIR__, __NAMESPACE__); } }
module/Contrat/autoload_classmap.php +x+4 Changes for module/Contrat/autoload_classmap.php: 4 added lines, 0 removed lines. Original line number Diff line number Diff line <?php // Generated by UnicaenCode return [ ]; No newline at end of file
module/Contrat/config/module.config.php +x+211 Changes for module/Contrat/config/module.config.php: 211 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Contrat; use Application\Provider\Privilege\Privileges; use Contrat\Assertion\ContratAssertion; use Contrat\Controller\ContratController; use Contrat\Service\ContratServiceListeService; return [ 'routes' => [ 'contrat' => [ 'route' => '/contrat', 'controller' => ContratController::class, 'action' => 'index', 'may_terminate' => true, 'child_routes' => [ 'creer' => [ 'route' => '/:intervenant/creer/:structure', 'constraints' => [ 'structure' => '[0-9]*', ], 'action' => 'creer', 'controller' => ContratController::class, ], 'supprimer' => [ 'route' => '/:contrat/supprimer', 'constraints' => [ 'contrat' => '[0-9]*', ], 'action' => 'supprimer', 'controller' => ContratController::class, ], 'valider' => [ 'route' => '/:contrat/valider', 'constraints' => [ 'contrat' => '[0-9]*', ], 'action' => 'valider', 'controller' => ContratController::class, ], 'devalider' => [ 'route' => '/:contrat/devalider', 'constraints' => [ 'contrat' => '[0-9]*', ], 'action' => 'devalider', 'controller' => ContratController::class, ], 'saisir-retour' => [ 'route' => '/:contrat/saisir-retour', 'constraints' => [ 'contrat' => '[0-9]*', ], 'action' => 'saisir-retour', 'controller' => ContratController::class, ], 'exporter' => [ 'route' => '/:contrat/exporter', 'constraints' => [ 'contrat' => '[0-9]*', ], 'action' => 'exporter', 'controller' => ContratController::class, ], 'envoyer-mail' => [ 'route' => '/:contrat/mail', 'constraints' => [ 'contrat' => '[0-9]*', ], 'action' => 'envoyer-mail', 'controller' => ContratController::class, ], 'deposer-fichier' => [ 'route' => '/:contrat/deposer-fichier', 'constraints' => [ 'contrat' => '[0-9]*', ], 'action' => 'deposer-fichier', 'controller' => ContratController::class, ], 'lister-fichier' => [ 'route' => '/:contrat/lister-fichier', 'constraints' => [ 'contrat' => '[0-9]*', ], 'action' => 'lister-fichier', 'controller' => ContratController::class, ], 'telecharger-fichier' => [ 'route' => '/:contrat/telecharger-fichier[/:fichier/:nomFichier]', 'constraints' => [ 'contrat' => '[0-9]*', ], 'action' => 'telecharger-fichier', 'controller' => ContratController::class, ], 'supprimer-fichier' => [ 'route' => '/:contrat/supprimer-fichier[/:fichier]', 'constraints' => [ 'contrat' => '[0-9]*', 'fichier' => '[0-9]*', ], 'action' => 'supprimer-fichier', 'controller' => ContratController::class, ], ], ], ], 'guards' => [ [ 'controller' => ContratController::class, 'action' => ['index'], 'privileges' => Privileges::CONTRAT_VISUALISATION, 'assertion' => \Contrat\Assertion\ContratAssertion::class, ], [ 'controller' => ContratController::class, 'action' => ['telecharger-fichier', 'lister-fichier'], 'privileges' => Privileges::CONTRAT_VISUALISATION, ], [ 'controller' => ContratController::class, 'action' => ['exporter'], 'privileges' => [Privileges::CONTRAT_CONTRAT_GENERATION, Privileges::CONTRAT_PROJET_GENERATION], 'assertion' => \Contrat\Assertion\ContratAssertion::class, ], [ 'controller' => ContratController::class, 'action' => ['envoyer-mail'], 'privileges' => [Privileges::CONTRAT_ENVOI_EMAIL], ], [ 'controller' => ContratController::class, 'action' => ['creer'], 'privileges' => Privileges::CONTRAT_CREATION, 'assertion' => \Contrat\Assertion\ContratAssertion::class, ], [ 'controller' => ContratController::class, 'action' => ['supprimer'], 'privileges' => Privileges::CONTRAT_SUPPRESSION, 'assertion' => \Contrat\Assertion\ContratAssertion::class, ], [ 'controller' => ContratController::class, 'action' => ['valider'], 'privileges' => Privileges::CONTRAT_VALIDATION, 'assertion' => \Contrat\Assertion\ContratAssertion::class, ], [ 'controller' => ContratController::class, 'action' => ['devalider'], 'privileges' => Privileges::CONTRAT_DEVALIDATION, 'assertion' => \Contrat\Assertion\ContratAssertion::class, ], [ 'controller' => ContratController::class, 'action' => ['deposer-fichier', 'supprimer-fichier'], 'privileges' => Privileges::CONTRAT_DEPOT_RETOUR_SIGNE, 'assertion' => \Contrat\Assertion\ContratAssertion::class, ], [ 'controller' => ContratController::class, 'action' => ['saisir-retour'], 'privileges' => Privileges::CONTRAT_SAISIE_DATE_RETOUR_SIGNE, 'assertion' => \Contrat\Assertion\ContratAssertion::class, ], ], 'rules' => [ [ 'privileges' => [ Privileges::CONTRAT_CREATION, Privileges::CONTRAT_DEPOT_RETOUR_SIGNE, Privileges::CONTRAT_DEVALIDATION, Privileges::CONTRAT_SAISIE_DATE_RETOUR_SIGNE, Privileges::CONTRAT_SUPPRESSION, Privileges::CONTRAT_VALIDATION, Privileges::CONTRAT_VISUALISATION, Privileges::CONTRAT_PROJET_GENERATION, Privileges::CONTRAT_CONTRAT_GENERATION, Privileges::CONTRAT_ENVOI_EMAIL, ContratAssertion::PRIV_LISTER_FICHIERS, ContratAssertion::PRIV_AJOUTER_FICHIER, ContratAssertion::PRIV_SUPPRIMER_FICHIER, ContratAssertion::PRIV_EXPORT, ], 'resources' => 'Contrat', 'assertion' => \Contrat\Assertion\ContratAssertion::class, ], ], 'controllers' => [ ContratController::class => \Contrat\Controller\ContratControllerFactory::class, ], 'services' => [ \Contrat\Assertion\ContratAssertion::class => \UnicaenPrivilege\Assertion\AssertionFactory::class, \Contrat\Service\ContratService::class => \Contrat\Service\ContratServiceFactory::class, \Contrat\Service\TypeContratService::class => \Contrat\Service\TypeContratServiceFactory::class, \Contrat\Processus\ContratProcessus::class => \Contrat\Processus\ContratProcessusFactory::class, \Contrat\Service\ContratServiceListeService::class => \Contrat\Service\ContratServiceListeServiceFactory::class, ], 'view_helpers' => [ ], 'forms' => [ \Contrat\Form\ContratValidationForm::class => \Contrat\Form\ContratValidationFormFactory::class, /** @todo à supprimer ? */ \Contrat\Form\ContratRetourForm::class => \Contrat\Form\ContratRetourFormFactory::class, ], ];
module/Contrat/src/Assertion/ContratAssertion.php +x+288 Changes for module/Contrat/src/Assertion/ContratAssertion.php: 288 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Contrat\Assertion; use Application\Acl\Role; use Application\Entity\Db\Intervenant; use Application\Entity\Db\Parametre; use Application\Entity\Db\Structure; use Application\Entity\Db\WfEtape; use Application\Provider\Privilege\Privileges; use Application\Service\Traits\ParametresServiceAwareTrait; use Contrat\Entity\Db\Contrat; // sous réserve que vous utilisiez les privilèges d'UnicaenAuth et que vous ayez généré votre fournisseur use Application\Service\Traits\WorkflowServiceAwareTrait; use UnicaenPrivilege\Assertion\AbstractAssertion; use Laminas\Permissions\Acl\Resource\ResourceInterface; /** * Description of ContratAssertion * * @author LECLUSE Laurent <laurent.lecluse at unicaen.fr> */ class ContratAssertion extends AbstractAssertion { use ParametresServiceAwareTrait; const PRIV_LISTER_FICHIERS = 'contrat-lister-fichiers'; const PRIV_SUPPRIMER_FICHIER = 'contrat-supprimer-fichier'; const PRIV_AJOUTER_FICHIER = 'contrat-ajouter-fichier'; const PRIV_EXPORT = 'contrat-export-all'; use WorkflowServiceAwareTrait; /** * @param ResourceInterface $entity * @param string $privilege * * @return boolean */ protected function assertEntity(ResourceInterface $entity, $privilege = null) { $localPrivs = [ self::PRIV_LISTER_FICHIERS, self::PRIV_AJOUTER_FICHIER, self::PRIV_SUPPRIMER_FICHIER, ]; $role = $this->getRole(); // Si le rôle n'est pas renseigné alors on s'en va... if (!$role instanceof Role) return false; switch (true) { case $entity instanceof Contrat: switch ($privilege) { case Privileges::CONTRAT_PROJET_GENERATION: case Privileges::CONTRAT_CONTRAT_GENERATION: case self::PRIV_EXPORT: return $this->assertGeneration($entity); } break; } // pareil si le rôle ne possède pas le privilège adéquat if ($privilege && !in_array($privilege, $localPrivs) && !$role->hasPrivilege($privilege)) return false; // @todo traiter les privilèges locaux!! switch (true) { case $entity instanceof Contrat: switch ($privilege) { case self::PRIV_LISTER_FICHIERS: return $this->assertListerFichiers($entity); case self::PRIV_AJOUTER_FICHIER: case self::PRIV_SUPPRIMER_FICHIER: return $this->assertModifierFichier($entity); case Privileges::CONTRAT_VISUALISATION: return $this->assertVisualisation($entity); case Privileges::CONTRAT_CREATION: return $this->assertCreation($entity); case Privileges::CONTRAT_VALIDATION: return $this->assertValidation($entity); case Privileges::CONTRAT_DEPOT_RETOUR_SIGNE: return $this->assertDepotRetourSigne($entity); case Privileges::CONTRAT_SAISIE_DATE_RETOUR_SIGNE: return $this->assertSaisieDateRetour($entity); case Privileges::CONTRAT_DEVALIDATION: return $this->assertDevalidation($entity); case Privileges::CONTRAT_SUPPRESSION: return $this->assertSuppression($entity); } break; } return true; } /** * @param string $controller * @param string $action * @param string $privilege * * @return boolean */ protected function assertController($controller, $action = null, $privilege = null) { $intervenant = $this->getMvcEvent()->getParam('intervenant'); if ($intervenant) { $workflowEtape = $this->getServiceWorkflow()->getEtape(WfEtape::CODE_CONTRAT, $intervenant); $wfOk = $workflowEtape && $workflowEtape->isAtteignable(); if (!$wfOk) return false; } return true; } protected function assertListerFichiers(Contrat $contrat) { return $this->asserts([ $this->getRole()->hasPrivilege(Privileges::CONTRAT_VISUALISATION), $this->assertVisualisation($contrat), !$contrat->estUnProjet(), ]); } protected function assertModifierFichier(Contrat $contrat) { return $this->asserts([ $this->getRole()->hasPrivilege(Privileges::CONTRAT_DEPOT_RETOUR_SIGNE), empty($contrat->getDateRetourSigne()), $this->assertDepotRetourSigne($contrat), ]); } protected function assertVisualisation(Contrat $contrat) { return $this->assertRole($contrat); } protected function assertCreation(Contrat $contrat) { return $this->asserts([ $this->assertRole($contrat), $this->assertWorkflow($contrat), ]); } protected function assertValidation(Contrat $contrat) { return $this->asserts([ $this->assertRole($contrat), !$contrat->getValidation(), ]); } protected function assertDevalidation(Contrat $contrat) { if (!$contrat->estUnAvenant()) { $devalid = $contrat->getIntervenant()->getContrat()->count() == 1; // on ne peut dévalider un contrat que si aucun avenant n'existe } else { $devalid = true; } $contratDirectResult = $this->getServiceParametres()->get('contrat_direct'); $contratDirect = ($contratDirectResult == Parametre::CONTRAT_DIRECT); return $this->asserts([ $this->assertRole($contrat), $contrat->getValidation() && !$contratDirect, !$contrat->getDateRetourSigne(), $devalid, ]); } protected function assertSuppression(Contrat $contrat) { if (!$contrat->estUnAvenant()) { $devalid = $contrat->getIntervenant()->getContrat()->count() == 1; // on ne peut supprimer un contrat que si aucun avenant n'existe } else { $devalid = true; } $contratDirectResult = $this->getServiceParametres()->get('contrat_direct'); $contratDirect = ($contratDirectResult == Parametre::CONTRAT_DIRECT); return $this->asserts([ $this->assertRole($contrat), !$contrat->getValidation() || ($contratDirect && $devalid), !$contrat->getDateRetourSigne(), ]); } protected function assertGeneration(Contrat $contrat) { if ($contrat->estUnProjet()) { return $this->getRole()->hasPrivilege(Privileges::CONTRAT_PROJET_GENERATION); } else { return $this->getRole()->hasPrivilege(Privileges::CONTRAT_CONTRAT_GENERATION); } } protected function assertDepotRetourSigne(Contrat $contrat) { return $this->asserts([ $this->assertRole($contrat), !$contrat->estUnProjet(), ]); } protected function assertSaisieDateRetour(Contrat $contrat) { return $this->asserts([ $this->assertRole($contrat), !$contrat->estUnProjet(), ]); } protected function assertRole(Contrat $contrat, $checkStructure = true) { if ($intervenant = $this->getRole()->getIntervenant()) { if (!$this->assertIntervenant($contrat, $intervenant)) return false; } if ($checkStructure && ($structure = $this->getRole()->getStructure())) { if (!$this->assertStructure($contrat, $structure)) return false; } return true; } protected function assertIntervenant(Contrat $contrat, Intervenant $intervenant) { return $contrat->getIntervenant() == $intervenant; } protected function assertStructure(Contrat $contrat, Structure $structure) { return $contrat->getStructure() == $structure || $contrat->getStructure() == null; } protected function assertWorkflow(Contrat $contrat) { $workflowEtape = $this->getServiceWorkflow()->getEtape(WfEtape::CODE_CONTRAT, $contrat->getIntervenant(), $contrat->getStructure()); return $this->asserts( $workflowEtape && $workflowEtape->isAtteignable() ); } } No newline at end of file
module/Contrat/src/Controller/ContratController.php +x+594 File added.Preview size limit exceeded, changes collapsed. Show changes