Loading module/Contrat/config/module.config.php +0 −4 Original line number Diff line number Diff line Loading @@ -262,10 +262,6 @@ return [ Privileges::CONTRAT_CONTRAT_GENERATION, Privileges::CONTRAT_ENVOI_EMAIL, Privileges::CONTRAT_ENVOYER_SIGNATURE_ELECTRONIQUE, ContratAssertion::PRIV_LISTER_FICHIERS, ContratAssertion::PRIV_AJOUTER_FICHIER, ContratAssertion::PRIV_SUPPRIMER_FICHIER, ContratAssertion::PRIV_EXPORT, ], 'resources' => Contrat::class, 'assertion' => Assertion\ContratAssertion::class, Loading module/Contrat/src/Assertion/ContratAssertion.php +31 −73 Original line number Diff line number Diff line Loading @@ -31,12 +31,6 @@ class ContratAssertion extends AbstractAssertion use ContratServiceAwareTrait; use ContextServiceAwareTrait; 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'; /** * @return \Application\Service\ContextService|null Loading @@ -59,20 +53,19 @@ class ContratAssertion extends AbstractAssertion */ protected function assertEntity(ResourceInterface $entity, $privilege = null): bool { $intervenant = $this->getParam(Intervenant::class) ?? $this->getParam(Contrat::class)?->getIntervenant(); if (!$this->isEtapeAccessible($intervenant)) { 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); 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_ENVOI_EMAIL: return true; case Privileges::CONTRAT_VISUALISATION: return $this->assertVisualisation($entity); Loading @@ -96,8 +89,6 @@ class ContratAssertion extends AbstractAssertion case Privileges::CONTRAT_SUPPRESSION: return $this->assertSuppression($entity); case Privileges::CONTRAT_ENVOI_EMAIL: return true; } break; } Loading @@ -107,36 +98,6 @@ class ContratAssertion extends AbstractAssertion protected function assertGeneration(Contrat $contrat): bool { //Si je suis connecté en tant qu'intervenant if ($this->getContextService()->getIntervenant()) { //Si le role à le même intervenant que le contrat et que le contrat est validé if ($this->getServiceContext()->getIntervenant() == $contrat->getIntervenant() && !$contrat->estUnProjet()) { return true; } } if ($contrat->estUnProjet()) { return $this->authorize->isAllowedPrivilege(Privileges::CONTRAT_PROJET_GENERATION); } else { return $this->authorize->isAllowedPrivilege(Privileges::CONTRAT_CONTRAT_GENERATION); } } protected function assertListerFichiers(Contrat $contrat): bool { return $this->asserts( $this->authorize->isAllowedPrivilege(Privileges::CONTRAT_VISUALISATION), $this->assertVisualisation($contrat), !$contrat->estUnProjet(), ); } protected function assertVisualisation(Contrat $contrat): bool { return $this->assertRole($contrat); Loading Loading @@ -171,19 +132,6 @@ class ContratAssertion extends AbstractAssertion return $contrat->getStructure() == null || $contrat->getStructure()->inStructure($structure); } protected function assertModifierFichier(Contrat $contrat): bool { return $this->asserts([ $this->authorize->isAllowedPrivilege(Privileges::CONTRAT_DEPOT_RETOUR_SIGNE), empty($contrat->getDateRetourSigne()), $this->assertDepotRetourSigne($contrat), ]); } protected function assertDepotRetourSigne(Contrat $contrat): bool { return $this->asserts([ Loading Loading @@ -311,22 +259,32 @@ class ContratAssertion extends AbstractAssertion case ContratController::class . '.creerProcessSignature': case ContratController::class . '.supprimerProcessSignature': case ContratController::class . '.rafraichirProcessSignature': $intervenant = $this->getParam(Intervenant::class); if (!$intervenant) { $contrat = $this->getParam(Contrat::class); if ($contrat) { $intervenant = $contrat->getIntervenant(); } } if ($intervenant) { $feuilleDeRoute = $this->getServiceWorkflow()->getFeuilleDeRoute($intervenant); $wfEtape = $feuilleDeRoute->get(WorkflowEtape::CONTRAT); if ($wfEtape && $wfEtape->isAllowed()) return true; } $intervenant = $this->getParam(Intervenant::class) ?? $this->getParam(Contrat::class)?->getIntervenant(); throw new UnAuthorizedException('Action de contrôleur ' . $controller . ':' . $action . ' non autorisée'); return $this->isEtapeAccessible($intervenant); default: throw new UnAuthorizedException('Action de contrôleur ' . $controller . ':' . $action . ' non traitée'); } } /** * @param Intervenant $intervenant * @return bool */ public function isEtapeAccessible(mixed $intervenant): bool { if (!$intervenant) { return false; } $wfEtape = $this ->getServiceWorkflow() ->getFeuilleDeRoute($intervenant) ->get(WorkflowEtape::CONTRAT); return $wfEtape?->isAllowed() ?? false; } } No newline at end of file module/Contrat/src/Controller/ContratController.php +14 −9 Original line number Diff line number Diff line Loading @@ -378,10 +378,15 @@ class ContratController extends AbstractController /* @var Contrat $contrat */ $contrat = $this->getEvent()->getParam('contrat'); //On teste si on a le droit de télécharger le contrat if (!$this->isAllowed($contrat, ContratAssertion::PRIV_EXPORT)) { throw new UnAuthorizedException("Génération du contrat interdite."); if ($contrat->estUnProjet()) { if (!$this->isAllowed($contrat, Privileges::CONTRAT_PROJET_GENERATION)) { throw new UnAuthorizedException("Génération du projet interdite."); } } elseif (!$this->isAllowed($contrat, Privileges::CONTRAT_CONTRAT_GENERATION)) { throw new UnAuthorizedException("Génération du contrat interdite."); } $this->getServiceContrat()->generer($contrat); die(); } Loading @@ -396,7 +401,7 @@ class ContratController extends AbstractController $title = 'Envoi du contrat à l\'intervenant'; if (!$this->isAllowed($contrat, ContratAssertion::PRIV_EXPORT)) { if (!$this->isAllowed($contrat, Privileges::CONTRAT_ENVOI_EMAIL)) { throw new UnAuthorizedException("Interdiction d'envoyer le contrat par email"); } $intervenant = $contrat->getIntervenant(); Loading Loading @@ -468,7 +473,7 @@ class ContratController extends AbstractController $contrat = $this->getEvent()->getParam('contrat'); /* @var $contrat Contrat */ if (!$this->isAllowed($contrat, ContratAssertion::PRIV_AJOUTER_FICHIER)) { if (!$this->isAllowed($contrat, Privileges::CONTRAT_DEPOT_RETOUR_SIGNE)) { throw new UnAuthorizedException('Vous n\'avez pas de droit de déposer ce fichier'); } Loading Loading @@ -497,8 +502,8 @@ class ContratController extends AbstractController $contrat = $this->getEvent()->getParam('contrat'); /* @var $contrat Contrat */ if (!$this->isAllowed($contrat, ContratAssertion::PRIV_LISTER_FICHIERS)) { throw new UnAuthorizedException('Vous n\'avez pas de droit de visualiser les fichierzs dépôsés'); if (!$this->isAllowed($contrat, Privileges::CONTRAT_VISUALISATION)) { throw new UnAuthorizedException('Vous n\'avez pas de droit de visualiser les fichiers dépôsés'); } return [ Loading Loading @@ -550,7 +555,7 @@ class ContratController extends AbstractController $fichier = $this->getEvent()->getParam('fichier'); if (!$this->isAllowed($contrat, ContratAssertion::PRIV_SUPPRIMER_FICHIER)) { if (!$this->isAllowed($contrat, Privileges::CONTRAT_DEPOT_RETOUR_SIGNE)) { throw new UnAuthorizedException('Vous n\'avez pas de droit de supprimer ce fichier'); } Loading module/Contrat/view/contrat/contrat/lister-fichier.phtml +2 −1 Original line number Diff line number Diff line <?php use Application\Provider\Privileges; use Contrat\Assertion\ContratAssertion; $contrat = $this->contrat; Loading @@ -7,7 +8,7 @@ $contrat = $this->contrat; $fichiers = $contrat ? $contrat->getFichier() : []; /* @var $fichiers \Application\Entity\Db\Fichier[] */ $canDelete = $this->isAllowed($contrat, ContratAssertion::PRIV_SUPPRIMER_FICHIER); $canDelete = $this->isAllowed($contrat, Privileges::CONTRAT_SUPPRESSION); ?> <?php if (count($fichiers)): ?> Loading module/Contrat/view/contrat/contrat/partial/contrat-signature-electronique.phtml +4 −4 Original line number Diff line number Diff line Loading @@ -19,16 +19,16 @@ $retourSigne = $contrat->getDateRetourSigne(); $dateEnvoiEmail = $contrat->getDateEnvoiEmail(); $uploader = $this->uploader(); $urlExport = $this->isAllowed($contrat, ContratAssertion::PRIV_EXPORT) $urlExport = $this->isAllowed($contrat, Privileges::CONTRAT_VISUALISATION) ? $this->url('contrat/exporter', ['contrat' => $contrat->getId()]) // oui car on peut le voir!! : null; $urlLister = $this->isAllowed($contrat, ContratAssertion::PRIV_LISTER_FICHIERS) $urlLister = $this->isAllowed($contrat, Privileges::CONTRAT_VISUALISATION) ? $this->url('contrat/lister-fichier', ['contrat' => $contrat->getId()], [], true) : null; $fichiers = $contrat->getFichier(); $urlTelechargerContratSigned = $this->isAllowed($contrat, ContratAssertion::PRIV_LISTER_FICHIERS) $urlTelechargerContratSigned = $this->isAllowed($contrat, Privileges::CONTRAT_VISUALISATION) ? (count($fichiers)) ? $this->url('contrat/telecharger-fichier', ['contrat' => $contrat->getId(), 'fichier' => $fichiers[0]->getId(), 'nomFichier' => $fichiers[0]->getNom()]) : null : null; Loading Loading @@ -60,7 +60,7 @@ $urlSaisieRetour = $this->isAllowed($contrat, Privileges::CONTRAT_SAISIE_DATE_RE ? $this->url('contrat/saisir-retour', ['contrat' => $contrat->getId()]) : null; $urlAjouter = $this->isAllowed($contrat, ContratAssertion::PRIV_AJOUTER_FICHIER) $urlAjouter = $this->isAllowed($contrat, Privileges::CONTRAT_DEPOT_RETOUR_SIGNE) ? $this->url('contrat/deposer-fichier', ['contrat' => $contrat->getId()], [], true) : null; Loading Loading
module/Contrat/config/module.config.php +0 −4 Original line number Diff line number Diff line Loading @@ -262,10 +262,6 @@ return [ Privileges::CONTRAT_CONTRAT_GENERATION, Privileges::CONTRAT_ENVOI_EMAIL, Privileges::CONTRAT_ENVOYER_SIGNATURE_ELECTRONIQUE, ContratAssertion::PRIV_LISTER_FICHIERS, ContratAssertion::PRIV_AJOUTER_FICHIER, ContratAssertion::PRIV_SUPPRIMER_FICHIER, ContratAssertion::PRIV_EXPORT, ], 'resources' => Contrat::class, 'assertion' => Assertion\ContratAssertion::class, Loading
module/Contrat/src/Assertion/ContratAssertion.php +31 −73 Original line number Diff line number Diff line Loading @@ -31,12 +31,6 @@ class ContratAssertion extends AbstractAssertion use ContratServiceAwareTrait; use ContextServiceAwareTrait; 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'; /** * @return \Application\Service\ContextService|null Loading @@ -59,20 +53,19 @@ class ContratAssertion extends AbstractAssertion */ protected function assertEntity(ResourceInterface $entity, $privilege = null): bool { $intervenant = $this->getParam(Intervenant::class) ?? $this->getParam(Contrat::class)?->getIntervenant(); if (!$this->isEtapeAccessible($intervenant)) { 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); 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_ENVOI_EMAIL: return true; case Privileges::CONTRAT_VISUALISATION: return $this->assertVisualisation($entity); Loading @@ -96,8 +89,6 @@ class ContratAssertion extends AbstractAssertion case Privileges::CONTRAT_SUPPRESSION: return $this->assertSuppression($entity); case Privileges::CONTRAT_ENVOI_EMAIL: return true; } break; } Loading @@ -107,36 +98,6 @@ class ContratAssertion extends AbstractAssertion protected function assertGeneration(Contrat $contrat): bool { //Si je suis connecté en tant qu'intervenant if ($this->getContextService()->getIntervenant()) { //Si le role à le même intervenant que le contrat et que le contrat est validé if ($this->getServiceContext()->getIntervenant() == $contrat->getIntervenant() && !$contrat->estUnProjet()) { return true; } } if ($contrat->estUnProjet()) { return $this->authorize->isAllowedPrivilege(Privileges::CONTRAT_PROJET_GENERATION); } else { return $this->authorize->isAllowedPrivilege(Privileges::CONTRAT_CONTRAT_GENERATION); } } protected function assertListerFichiers(Contrat $contrat): bool { return $this->asserts( $this->authorize->isAllowedPrivilege(Privileges::CONTRAT_VISUALISATION), $this->assertVisualisation($contrat), !$contrat->estUnProjet(), ); } protected function assertVisualisation(Contrat $contrat): bool { return $this->assertRole($contrat); Loading Loading @@ -171,19 +132,6 @@ class ContratAssertion extends AbstractAssertion return $contrat->getStructure() == null || $contrat->getStructure()->inStructure($structure); } protected function assertModifierFichier(Contrat $contrat): bool { return $this->asserts([ $this->authorize->isAllowedPrivilege(Privileges::CONTRAT_DEPOT_RETOUR_SIGNE), empty($contrat->getDateRetourSigne()), $this->assertDepotRetourSigne($contrat), ]); } protected function assertDepotRetourSigne(Contrat $contrat): bool { return $this->asserts([ Loading Loading @@ -311,22 +259,32 @@ class ContratAssertion extends AbstractAssertion case ContratController::class . '.creerProcessSignature': case ContratController::class . '.supprimerProcessSignature': case ContratController::class . '.rafraichirProcessSignature': $intervenant = $this->getParam(Intervenant::class); if (!$intervenant) { $contrat = $this->getParam(Contrat::class); if ($contrat) { $intervenant = $contrat->getIntervenant(); } } if ($intervenant) { $feuilleDeRoute = $this->getServiceWorkflow()->getFeuilleDeRoute($intervenant); $wfEtape = $feuilleDeRoute->get(WorkflowEtape::CONTRAT); if ($wfEtape && $wfEtape->isAllowed()) return true; } $intervenant = $this->getParam(Intervenant::class) ?? $this->getParam(Contrat::class)?->getIntervenant(); throw new UnAuthorizedException('Action de contrôleur ' . $controller . ':' . $action . ' non autorisée'); return $this->isEtapeAccessible($intervenant); default: throw new UnAuthorizedException('Action de contrôleur ' . $controller . ':' . $action . ' non traitée'); } } /** * @param Intervenant $intervenant * @return bool */ public function isEtapeAccessible(mixed $intervenant): bool { if (!$intervenant) { return false; } $wfEtape = $this ->getServiceWorkflow() ->getFeuilleDeRoute($intervenant) ->get(WorkflowEtape::CONTRAT); return $wfEtape?->isAllowed() ?? false; } } No newline at end of file
module/Contrat/src/Controller/ContratController.php +14 −9 Original line number Diff line number Diff line Loading @@ -378,10 +378,15 @@ class ContratController extends AbstractController /* @var Contrat $contrat */ $contrat = $this->getEvent()->getParam('contrat'); //On teste si on a le droit de télécharger le contrat if (!$this->isAllowed($contrat, ContratAssertion::PRIV_EXPORT)) { throw new UnAuthorizedException("Génération du contrat interdite."); if ($contrat->estUnProjet()) { if (!$this->isAllowed($contrat, Privileges::CONTRAT_PROJET_GENERATION)) { throw new UnAuthorizedException("Génération du projet interdite."); } } elseif (!$this->isAllowed($contrat, Privileges::CONTRAT_CONTRAT_GENERATION)) { throw new UnAuthorizedException("Génération du contrat interdite."); } $this->getServiceContrat()->generer($contrat); die(); } Loading @@ -396,7 +401,7 @@ class ContratController extends AbstractController $title = 'Envoi du contrat à l\'intervenant'; if (!$this->isAllowed($contrat, ContratAssertion::PRIV_EXPORT)) { if (!$this->isAllowed($contrat, Privileges::CONTRAT_ENVOI_EMAIL)) { throw new UnAuthorizedException("Interdiction d'envoyer le contrat par email"); } $intervenant = $contrat->getIntervenant(); Loading Loading @@ -468,7 +473,7 @@ class ContratController extends AbstractController $contrat = $this->getEvent()->getParam('contrat'); /* @var $contrat Contrat */ if (!$this->isAllowed($contrat, ContratAssertion::PRIV_AJOUTER_FICHIER)) { if (!$this->isAllowed($contrat, Privileges::CONTRAT_DEPOT_RETOUR_SIGNE)) { throw new UnAuthorizedException('Vous n\'avez pas de droit de déposer ce fichier'); } Loading Loading @@ -497,8 +502,8 @@ class ContratController extends AbstractController $contrat = $this->getEvent()->getParam('contrat'); /* @var $contrat Contrat */ if (!$this->isAllowed($contrat, ContratAssertion::PRIV_LISTER_FICHIERS)) { throw new UnAuthorizedException('Vous n\'avez pas de droit de visualiser les fichierzs dépôsés'); if (!$this->isAllowed($contrat, Privileges::CONTRAT_VISUALISATION)) { throw new UnAuthorizedException('Vous n\'avez pas de droit de visualiser les fichiers dépôsés'); } return [ Loading Loading @@ -550,7 +555,7 @@ class ContratController extends AbstractController $fichier = $this->getEvent()->getParam('fichier'); if (!$this->isAllowed($contrat, ContratAssertion::PRIV_SUPPRIMER_FICHIER)) { if (!$this->isAllowed($contrat, Privileges::CONTRAT_DEPOT_RETOUR_SIGNE)) { throw new UnAuthorizedException('Vous n\'avez pas de droit de supprimer ce fichier'); } Loading
module/Contrat/view/contrat/contrat/lister-fichier.phtml +2 −1 Original line number Diff line number Diff line <?php use Application\Provider\Privileges; use Contrat\Assertion\ContratAssertion; $contrat = $this->contrat; Loading @@ -7,7 +8,7 @@ $contrat = $this->contrat; $fichiers = $contrat ? $contrat->getFichier() : []; /* @var $fichiers \Application\Entity\Db\Fichier[] */ $canDelete = $this->isAllowed($contrat, ContratAssertion::PRIV_SUPPRIMER_FICHIER); $canDelete = $this->isAllowed($contrat, Privileges::CONTRAT_SUPPRESSION); ?> <?php if (count($fichiers)): ?> Loading
module/Contrat/view/contrat/contrat/partial/contrat-signature-electronique.phtml +4 −4 Original line number Diff line number Diff line Loading @@ -19,16 +19,16 @@ $retourSigne = $contrat->getDateRetourSigne(); $dateEnvoiEmail = $contrat->getDateEnvoiEmail(); $uploader = $this->uploader(); $urlExport = $this->isAllowed($contrat, ContratAssertion::PRIV_EXPORT) $urlExport = $this->isAllowed($contrat, Privileges::CONTRAT_VISUALISATION) ? $this->url('contrat/exporter', ['contrat' => $contrat->getId()]) // oui car on peut le voir!! : null; $urlLister = $this->isAllowed($contrat, ContratAssertion::PRIV_LISTER_FICHIERS) $urlLister = $this->isAllowed($contrat, Privileges::CONTRAT_VISUALISATION) ? $this->url('contrat/lister-fichier', ['contrat' => $contrat->getId()], [], true) : null; $fichiers = $contrat->getFichier(); $urlTelechargerContratSigned = $this->isAllowed($contrat, ContratAssertion::PRIV_LISTER_FICHIERS) $urlTelechargerContratSigned = $this->isAllowed($contrat, Privileges::CONTRAT_VISUALISATION) ? (count($fichiers)) ? $this->url('contrat/telecharger-fichier', ['contrat' => $contrat->getId(), 'fichier' => $fichiers[0]->getId(), 'nomFichier' => $fichiers[0]->getNom()]) : null : null; Loading Loading @@ -60,7 +60,7 @@ $urlSaisieRetour = $this->isAllowed($contrat, Privileges::CONTRAT_SAISIE_DATE_RE ? $this->url('contrat/saisir-retour', ['contrat' => $contrat->getId()]) : null; $urlAjouter = $this->isAllowed($contrat, ContratAssertion::PRIV_AJOUTER_FICHIER) $urlAjouter = $this->isAllowed($contrat, Privileges::CONTRAT_DEPOT_RETOUR_SIGNE) ? $this->url('contrat/deposer-fichier', ['contrat' => $contrat->getId()], [], true) : null; Loading