Loading module/Soutenance/config/others/presoutenance.config.php +2 −0 Original line number Diff line number Diff line Loading @@ -61,6 +61,8 @@ return [ 'presoutenance', ], 'privileges' => PresoutenancePrivileges::PRESOUTENANCE_PRESOUTENANCE_VISUALISATION, 'assertion' => PresoutenanceAssertion::class, ], [ 'controller' => PresoutenanceController::class, Loading module/Soutenance/src/Soutenance/Assertion/PresoutenanceAssertion.php +130 −21 Original line number Diff line number Diff line Loading @@ -2,51 +2,160 @@ namespace Soutenance\Assertion; use Application\Assertion\AbstractAssertion; use Application\Assertion\Exception\FailedAssertionException; use Application\Assertion\ThrowsFailedAssertionExceptionTrait; use Application\Entity\Db\Role; use These\Entity\Db\These; use Application\RouteMatch; use Application\Service\UserContextServiceAwareInterface; use Application\Service\UserContextServiceAwareTrait; use Soutenance\Provider\Privilege\PresoutenancePrivileges; use Laminas\Permissions\Acl\Acl; use Laminas\Permissions\Acl\Assertion\AssertionInterface; use Laminas\Permissions\Acl\Resource\ResourceInterface; use Laminas\Permissions\Acl\Role\RoleInterface; use Soutenance\Provider\Privilege\PresoutenancePrivileges; use These\Entity\Db\These; use These\Service\These\TheseServiceAwareTrait; use UnicaenApp\Service\MessageCollectorAwareInterface; use UnicaenApp\Service\MessageCollectorAwareTrait; class PresoutenanceAssertion extends AbstractAssertion implements UserContextServiceAwareInterface, MessageCollectorAwareInterface { class PresoutenanceAssertion implements AssertionInterface { use UserContextServiceAwareTrait; use MessageCollectorAwareTrait; use TheseServiceAwareTrait; use ThrowsFailedAssertionExceptionTrait; private ?These $these = null; /** * !!!! Pour éviter l'erreur "Serialization of 'Closure' is not allowed"... !!!! * * @return array * @param array $page * @return bool */ public function __sleep() public function __invoke(array $page): bool { return []; return $this->assertPage($page); } public function __invoke($page) /** * @param array $page * @return bool */ private function assertPage(array $page): bool { return true; } public function assert(Acl $acl, RoleInterface $role = null, ResourceInterface $resource = null, $privilege = null) /** * @param These $entity * @param string $privilege * @return boolean */ protected function assertEntity(ResourceInterface $entity, $privilege = null): bool { /** @var These $these */ $these = $resource; if (! parent::assertEntity($entity, $privilege)) { return false; } $this->these = $entity; try { switch ($privilege) { case PresoutenancePrivileges::PRESOUTENANCE_ASSOCIATION_MEMBRE_INDIVIDU: case PresoutenancePrivileges::PRESOUTENANCE_DATE_RETOUR_MODIFICATION: $role = $this->userContextService->getSelectedIdentityRole(); return ($role->getCode() === Role::CODE_BDD && $role->getStructure() === $these->getEtablissement()->getStructure()); return ($role->getCode() === Role::CODE_BDD && $role->getStructure() === $this->these->getEtablissement()->getStructure()); } } catch (FailedAssertionException $e) { if ($e->getMessage()) { $this->getServiceMessageCollector()->addMessage($e->getMessage(), __CLASS__); } return false; } return true; } /** * @param string $controller * @param string $action * @param string $privilege * @return boolean */ protected function assertController($controller, $action = null, $privilege = null): bool { if (!parent::assertController($controller, $action, $privilege)) { return false; } $this->these = $this->getRequestedThese(); try { switch ($action) { case 'presoutenance': if ($this->these !== null) { $this->assertCanAccessInformationsPresoutenance($this->these); } break; case PresoutenancePrivileges::PRESOUTENANCE_PRESOUTENANCE_VISUALISATION: } } catch (FailedAssertionException $e) { if ($e->getMessage()) { $this->getServiceMessageCollector()->addMessage($e->getMessage(), __CLASS__); } return false; } return true; } private function assertCanAccessInformationsPresoutenance(These $these){ $role = $this->userContextService->getSelectedIdentityRole(); return (($role->getCode() === Role::CODE_BDD && $role->getStructure() === $these->getEtablissement()->getStructure()) || $role->getCode() === Role::CODE_OBSERVATEUR || $role->getCode() === Role::CODE_ADMIN_TECH); if (!$role) { return; } return false; if ($role->isDoctorant()) { $doctorant = $this->userContextService->getIdentityDoctorant(); $this->assertTrue( $these->getDoctorant()->getId() === $doctorant->getId(), "La thèse n'appartient pas au doctorant " . $doctorant ); } if ($roleMaisonDoctorat = $this->userContextService->getSelectedRoleBDD()) { $this->assertTrue( $these->getEtablissement()->getStructure()->getId() === $roleMaisonDoctorat->getStructure()->getId(), "La thèse n'appartient pas à la maison du doctorat " . $roleMaisonDoctorat->getStructure()->getId() ); } elseif ($roleEcoleDoctorale = $this->userContextService->getSelectedRoleEcoleDoctorale()) { $this->assertTrue( $these->getEcoleDoctorale()->getStructure()->getId() === $roleEcoleDoctorale->getStructure()->getId(), "La thèse n'est pas rattachée à l'ED " . $roleEcoleDoctorale->getStructure()->getCode() ); } elseif ($roleUniteRech = $this->userContextService->getSelectedRoleUniteRecherche()) { $this->assertTrue( $these->getUniteRecherche()->getStructure()->getId() === $roleUniteRech->getStructure()->getId(), "La thèse n'est pas rattachée à l'UR " . $roleUniteRech->getStructure()->getCode() ); } } protected function getRequestedThese(): ?These { $these = null; if (($routeMatch = $this->getRouteMatch()) && $id = $routeMatch->getParam('these')) { $these = $this->theseService->getRepository()->find($id); } return $these; } protected function getRouteMatch(): ?RouteMatch { /** @var RouteMatch $rm */ $rm = $this->getMvcEvent()->getRouteMatch(); return $rm; } } No newline at end of file module/Soutenance/src/Soutenance/Assertion/PresoutenanceAssertionFactory.php +24 −0 Original line number Diff line number Diff line Loading @@ -2,8 +2,12 @@ namespace Soutenance\Assertion; use Application\Assertion\AbstractAssertion; use Application\Service\UserContextService; use Interop\Container\ContainerInterface; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; use These\Service\These\TheseService; class PresoutenanceAssertionFactory { Loading @@ -17,12 +21,32 @@ class PresoutenanceAssertionFactory { * @var UserContextService $userContext */ $userContext = $container->get('UnicaenAuth\Service\UserContext'); $theseService = $container->get(TheseService::class); $messageCollector = $container->get('MessageCollector'); /** @var $assertion */ $assertion = new PresoutenanceAssertion(); $assertion->setUserContextService($userContext); $assertion->setTheseService($theseService); $assertion->setServiceMessageCollector($messageCollector); $this->injectCommons($assertion, $container); return $assertion; } /** * @throws NotFoundExceptionInterface * @throws ContainerExceptionInterface */ protected function injectCommons(AbstractAssertion $assertion, \Psr\Container\ContainerInterface $container) { $authorizeService = $container->get('BjyAuthorize\Service\Authorize'); $mvcEvent = $container->get('Application')->getMvcEvent(); $assertion->setServiceAuthorize($authorizeService); $assertion->setMvcEvent($mvcEvent); } } No newline at end of file Loading
module/Soutenance/config/others/presoutenance.config.php +2 −0 Original line number Diff line number Diff line Loading @@ -61,6 +61,8 @@ return [ 'presoutenance', ], 'privileges' => PresoutenancePrivileges::PRESOUTENANCE_PRESOUTENANCE_VISUALISATION, 'assertion' => PresoutenanceAssertion::class, ], [ 'controller' => PresoutenanceController::class, Loading
module/Soutenance/src/Soutenance/Assertion/PresoutenanceAssertion.php +130 −21 Original line number Diff line number Diff line Loading @@ -2,51 +2,160 @@ namespace Soutenance\Assertion; use Application\Assertion\AbstractAssertion; use Application\Assertion\Exception\FailedAssertionException; use Application\Assertion\ThrowsFailedAssertionExceptionTrait; use Application\Entity\Db\Role; use These\Entity\Db\These; use Application\RouteMatch; use Application\Service\UserContextServiceAwareInterface; use Application\Service\UserContextServiceAwareTrait; use Soutenance\Provider\Privilege\PresoutenancePrivileges; use Laminas\Permissions\Acl\Acl; use Laminas\Permissions\Acl\Assertion\AssertionInterface; use Laminas\Permissions\Acl\Resource\ResourceInterface; use Laminas\Permissions\Acl\Role\RoleInterface; use Soutenance\Provider\Privilege\PresoutenancePrivileges; use These\Entity\Db\These; use These\Service\These\TheseServiceAwareTrait; use UnicaenApp\Service\MessageCollectorAwareInterface; use UnicaenApp\Service\MessageCollectorAwareTrait; class PresoutenanceAssertion extends AbstractAssertion implements UserContextServiceAwareInterface, MessageCollectorAwareInterface { class PresoutenanceAssertion implements AssertionInterface { use UserContextServiceAwareTrait; use MessageCollectorAwareTrait; use TheseServiceAwareTrait; use ThrowsFailedAssertionExceptionTrait; private ?These $these = null; /** * !!!! Pour éviter l'erreur "Serialization of 'Closure' is not allowed"... !!!! * * @return array * @param array $page * @return bool */ public function __sleep() public function __invoke(array $page): bool { return []; return $this->assertPage($page); } public function __invoke($page) /** * @param array $page * @return bool */ private function assertPage(array $page): bool { return true; } public function assert(Acl $acl, RoleInterface $role = null, ResourceInterface $resource = null, $privilege = null) /** * @param These $entity * @param string $privilege * @return boolean */ protected function assertEntity(ResourceInterface $entity, $privilege = null): bool { /** @var These $these */ $these = $resource; if (! parent::assertEntity($entity, $privilege)) { return false; } $this->these = $entity; try { switch ($privilege) { case PresoutenancePrivileges::PRESOUTENANCE_ASSOCIATION_MEMBRE_INDIVIDU: case PresoutenancePrivileges::PRESOUTENANCE_DATE_RETOUR_MODIFICATION: $role = $this->userContextService->getSelectedIdentityRole(); return ($role->getCode() === Role::CODE_BDD && $role->getStructure() === $these->getEtablissement()->getStructure()); return ($role->getCode() === Role::CODE_BDD && $role->getStructure() === $this->these->getEtablissement()->getStructure()); } } catch (FailedAssertionException $e) { if ($e->getMessage()) { $this->getServiceMessageCollector()->addMessage($e->getMessage(), __CLASS__); } return false; } return true; } /** * @param string $controller * @param string $action * @param string $privilege * @return boolean */ protected function assertController($controller, $action = null, $privilege = null): bool { if (!parent::assertController($controller, $action, $privilege)) { return false; } $this->these = $this->getRequestedThese(); try { switch ($action) { case 'presoutenance': if ($this->these !== null) { $this->assertCanAccessInformationsPresoutenance($this->these); } break; case PresoutenancePrivileges::PRESOUTENANCE_PRESOUTENANCE_VISUALISATION: } } catch (FailedAssertionException $e) { if ($e->getMessage()) { $this->getServiceMessageCollector()->addMessage($e->getMessage(), __CLASS__); } return false; } return true; } private function assertCanAccessInformationsPresoutenance(These $these){ $role = $this->userContextService->getSelectedIdentityRole(); return (($role->getCode() === Role::CODE_BDD && $role->getStructure() === $these->getEtablissement()->getStructure()) || $role->getCode() === Role::CODE_OBSERVATEUR || $role->getCode() === Role::CODE_ADMIN_TECH); if (!$role) { return; } return false; if ($role->isDoctorant()) { $doctorant = $this->userContextService->getIdentityDoctorant(); $this->assertTrue( $these->getDoctorant()->getId() === $doctorant->getId(), "La thèse n'appartient pas au doctorant " . $doctorant ); } if ($roleMaisonDoctorat = $this->userContextService->getSelectedRoleBDD()) { $this->assertTrue( $these->getEtablissement()->getStructure()->getId() === $roleMaisonDoctorat->getStructure()->getId(), "La thèse n'appartient pas à la maison du doctorat " . $roleMaisonDoctorat->getStructure()->getId() ); } elseif ($roleEcoleDoctorale = $this->userContextService->getSelectedRoleEcoleDoctorale()) { $this->assertTrue( $these->getEcoleDoctorale()->getStructure()->getId() === $roleEcoleDoctorale->getStructure()->getId(), "La thèse n'est pas rattachée à l'ED " . $roleEcoleDoctorale->getStructure()->getCode() ); } elseif ($roleUniteRech = $this->userContextService->getSelectedRoleUniteRecherche()) { $this->assertTrue( $these->getUniteRecherche()->getStructure()->getId() === $roleUniteRech->getStructure()->getId(), "La thèse n'est pas rattachée à l'UR " . $roleUniteRech->getStructure()->getCode() ); } } protected function getRequestedThese(): ?These { $these = null; if (($routeMatch = $this->getRouteMatch()) && $id = $routeMatch->getParam('these')) { $these = $this->theseService->getRepository()->find($id); } return $these; } protected function getRouteMatch(): ?RouteMatch { /** @var RouteMatch $rm */ $rm = $this->getMvcEvent()->getRouteMatch(); return $rm; } } No newline at end of file
module/Soutenance/src/Soutenance/Assertion/PresoutenanceAssertionFactory.php +24 −0 Original line number Diff line number Diff line Loading @@ -2,8 +2,12 @@ namespace Soutenance\Assertion; use Application\Assertion\AbstractAssertion; use Application\Service\UserContextService; use Interop\Container\ContainerInterface; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; use These\Service\These\TheseService; class PresoutenanceAssertionFactory { Loading @@ -17,12 +21,32 @@ class PresoutenanceAssertionFactory { * @var UserContextService $userContext */ $userContext = $container->get('UnicaenAuth\Service\UserContext'); $theseService = $container->get(TheseService::class); $messageCollector = $container->get('MessageCollector'); /** @var $assertion */ $assertion = new PresoutenanceAssertion(); $assertion->setUserContextService($userContext); $assertion->setTheseService($theseService); $assertion->setServiceMessageCollector($messageCollector); $this->injectCommons($assertion, $container); return $assertion; } /** * @throws NotFoundExceptionInterface * @throws ContainerExceptionInterface */ protected function injectCommons(AbstractAssertion $assertion, \Psr\Container\ContainerInterface $container) { $authorizeService = $container->get('BjyAuthorize\Service\Authorize'); $mvcEvent = $container->get('Application')->getMvcEvent(); $assertion->setServiceAuthorize($authorizeService); $assertion->setMvcEvent($mvcEvent); } } No newline at end of file