Commit b26436b7 authored by Thomas Hamel's avatar Thomas Hamel
Browse files

Ajout des privilèges associés au portfolio

parent 9868157c
Loading
Loading
Loading
Loading
+58 −44
Original line number Diff line number Diff line
@@ -86,20 +86,13 @@ WHERE NOT EXISTS (SELECT 1
                  FROM unicaen_privilege_privilege p
                  WHERE p.CODE = d.code);

-- ajout des privilèges au profil BDD (Maison du Doctorat)
INSERT INTO PROFIL_PRIVILEGE (PRIVILEGE_ID, PROFIL_ID)
with data(categ, priv) as (select 'formation_formation', 'configurer-module')
select p.id as PRIVILEGE_ID, profil.id as PROFIL_ID
from data
         join PROFIL on profil.ROLE_ID in (
                                           'ADMIN_TECH',
                                           'BDD',
                                           'GEST_ED'
    )
         join unicaen_privilege_categorie cp on cp.CODE = data.categ
         join unicaen_privilege_privilege p on p.CATEGORIE_ID = cp.id and p.code = data.priv
where not exists (select * from PROFIL_PRIVILEGE where PRIVILEGE_ID = p.id and PROFIL_ID = profil.id);
-- ajout des privilèges au profil BDD (Maison du Doctorat), ADMIN_TECH, GEST_ED
select privilege__grant_privileges_to_profiles('formation_formation',
                                               ARRAY[
                                                   'configurer-module'
                                               ],
                                               ARRAY['ADMIN_TECH', 'BDD', 'GEST_ED']
);

INSERT INTO unicaen_privilege_categorie (ID, CODE, LIBELLE, ORDRE)
SELECT nextval('categorie_privilege_id_seq'),
@@ -120,40 +113,43 @@ VALUES ((SELECT id FROM unicaen_privilege_categorie WHERE code = 'rncp'), 'resta
INSERT INTO public.unicaen_privilege_privilege (categorie_id, code, libelle, ordre)
VALUES ((SELECT id FROM unicaen_privilege_categorie WHERE code = 'rncp'), 'supprimer-competence', 'Supprimer une compétence et/ou un bloc de compétences', 4);

INSERT INTO PROFIL_PRIVILEGE (PRIVILEGE_ID, PROFIL_ID)
with data(categ, priv) as (select 'rncp', 'ajouter-competence'
                           union
                           select 'rncp', 'modifier-competence'
                           union
                           select 'rncp', 'historiser-competence'
                           union
                           select 'rncp', 'restaurer-competence'
                           union
                           select 'rncp', 'supprimer-competence'
)
select p.id as PRIVILEGE_ID, profil.id as PROFIL_ID
from data
         join PROFIL on profil.ROLE_ID in (
                                           'ADMIN_TECH',
                                           'GEST_ED',
                                            'BDD'
    )
         join unicaen_privilege_categorie cp on cp.CODE = data.categ
         join unicaen_privilege_privilege p on p.CATEGORIE_ID = cp.id and p.code = data.priv
where not exists (select * from PROFIL_PRIVILEGE where PRIVILEGE_ID = p.id and PROFIL_ID = profil.id);

insert into ROLE_PRIVILEGE (ROLE_ID, PRIVILEGE_ID)
select p2r.ROLE_ID, pp.PRIVILEGE_ID
from PROFIL_TO_ROLE p2r
         join profil pr on pr.id = p2r.PROFIL_ID
         join PROFIL_PRIVILEGE pp on pp.PROFIL_ID = pr.id
where not exists (select * from role_privilege where role_id = p2r.role_id and privilege_id = pp.privilege_id)
;
select privilege__grant_privileges_to_profiles('rncp',
                                               ARRAY[
                                                   'modifier-competence',
                                                   'historiser-competence',
                                                   'restaurer-competence',
                                                   'supprimer-competence'
                                               ],
                                               ARRAY['ADMIN_TECH', 'BDD', 'GEST_ED']
);

---
-- Données
---

INSERT INTO public.rncp_fiche (code_rncp, titre, date_echeance, histo_createur_id)
VALUES ('RNCP40525', 'Doctorat (Fiche nationale)','2029-12-31',1);

INSERT INTO public.rncp_bloc_competence (fiche_rncp_id, code, intitule, ordre, histo_createur_id)
SELECT id, 'RNCP40525BC01',
       'Concevoir et élaborer une démarche de recherche',1, 1
FROM rncp_fiche WHERE code_rncp = 'RNCP40525';

INSERT INTO public.rncp_bloc_competence (fiche_rncp_id, code, intitule, ordre, histo_createur_id)
SELECT id, 'RNCP40525BC02',
       'Développer et mettre en œuvre une démarche scientifique',2, 1
FROM rncp_fiche WHERE code_rncp = 'RNCP40525';

INSERT INTO public.rncp_bloc_competence (fiche_rncp_id, code, intitule, ordre, histo_createur_id)
SELECT id, 'RNCP40525BC03',
       'Valoriser, diffuser et transférer les résultats de la recherche',3, 1
FROM rncp_fiche WHERE code_rncp = 'RNCP40525';

INSERT INTO public.rncp_bloc_competence (fiche_rncp_id, code, intitule, ordre, histo_createur_id)
SELECT id, 'RNCP40525BC04',
       'Piloter des projets complexes de recherche et d’innovation',4, 1
FROM rncp_fiche WHERE code_rncp = 'RNCP40525';

INSERT INTO rncp_sous_competence (bloc_competence_id, code, intitule, ordre, histo_createur_id)
SELECT id, 'RNCP40525BC01-01',
       'Disposer d’une expertise scientifique tant générale que spécifique d’un domaine de recherche et de travail déterminé',1, 1
@@ -292,3 +288,21 @@ INSERT INTO rncp_sous_competence (bloc_competence_id, code, intitule, ordre, his
SELECT id, 'RNCP40525BC06-05',
       'Piloter et coordonner une équipe dans le cadre de tâches complexes ou interdisciplinaires pouvant mobiliser de multiples partenaires à l’échelle nationale ou internationale', 5,1
FROM rncp_bloc_competence WHERE code = 'RNCP40525BC06';


----------------------------------------- Portfolio ---------------------------------------------
INSERT INTO unicaen_privilege_categorie (ID, CODE, LIBELLE, ORDRE)
SELECT nextval('categorie_privilege_id_seq'),
       'portfolio',
       'Portfolio',
       5009 WHERE NOT EXISTS (SELECT 1
                               FROM unicaen_privilege_categorie
                               WHERE CODE = 'portfolio');

INSERT INTO public.unicaen_privilege_privilege (categorie_id, code, libelle, ordre)
VALUES ((SELECT id FROM unicaen_privilege_categorie WHERE code = 'portfolio'), 'afficher', 'Afficher le portfolio', 1);

select privilege__grant_privileges_to_profiles('portfolio',
                                               ARRAY['afficher'],
                                               ARRAY['ADMIN_TECH', 'DOCTORANT']
);
 No newline at end of file
+15 −22
Original line number Diff line number Diff line
@@ -2,13 +2,13 @@
namespace Portfolio;

use Application\Navigation\ApplicationNavigationFactory;
use Doctrine\ORM\Mapping\Driver\XmlDriver;
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
use Formation\Provider\Privilege\IndexPrivileges;
use Portfolio\Assertion\PortfolioAssertion;
use Portfolio\Assertion\PortfolioAssertionFactory;
use Portfolio\Controller\PortfolioController;
use Portfolio\Controller\PortfolioControllerFactory;
use Portfolio\Facade\PortfolioFacade;
use Portfolio\Facade\PortfolioFacadeFactory;
use Portfolio\Provider\Privilege\PortfolioPrivileges;
use UnicaenPrivilege\Guard\PrivilegeController;
use UnicaenPrivilege\Provider\Rule\PrivilegeRuleProvider;

@@ -31,11 +31,6 @@ return [
//        ],
    ],
    'bjyauthorize' => [
        'resource_providers' => [
            'BjyAuthorize\Provider\Resource\Config' => [
                'Portfolio' => [],
            ],
        ],
        'rule_providers' => [
            PrivilegeRuleProvider::class => [
                'allow' => [
@@ -44,10 +39,10 @@ return [
                        // Privilèges concernant la ressource Portfolio SOUMIS À ASSERTION.
                        //
                        'privileges' => [

                            PortfolioPrivileges::PORTFOLIO_AFFICHER
                        ],
                        'resources' => ['Portfolio'],
//                        'assertion' => ::class,
                        'resources' => ['These'],
                        'assertion' => PortfolioAssertion::class,
                    ],
                ],
            ],
@@ -59,16 +54,9 @@ return [
                    'action' => [
                        'afficher'
                    ],
                    'privileges' => IndexPrivileges::INDEX_AFFICHER,
                    'role' => 'user'
                    'privileges' => PortfolioPrivileges::PORTFOLIO_AFFICHER,
                    'assertion' => PortfolioAssertion::class,
                ],
//                [
//                    'controller' => ::class,
//                    'action' => [
//                    ],
//                    'privileges' => ,
//                    'assertion' => ,
//                ],
            ],
        ],
    ],
@@ -105,7 +93,7 @@ return [
            'home' => [
                'pages' => [
                    ApplicationNavigationFactory::THESE_SELECTIONNEE_PAGE_ID => [
                        'pages' => [
                        'pages' => $thesePages = [
                            // DEPTH = 2
                            'portfolio' => [
                                'order' => 12,
@@ -116,10 +104,14 @@ return [
                                    'these',
                                ],
                                'icon' => 'fas fa-briefcase',
        //                        'resource' => PresoutenancePrivileges::getResourceId(PropositionPrivileges::PROPOSITION_VISUALISER),
                                'resource' => PortfolioPrivileges::getResourceId(PortfolioPrivileges::PORTFOLIO_AFFICHER),
                            ],
                        ],
                    ],

                    ApplicationNavigationFactory::MA_THESE_PAGE_ID => [
                        'pages' => $thesePages
                    ],
                ],
            ],
        ],
@@ -132,6 +124,7 @@ return [
    'service_manager' => [
        'factories' => [
            PortfolioFacade::class => PortfolioFacadeFactory::class,
            PortfolioAssertion::class => PortfolioAssertionFactory::class
        ],
    ],
    'view_manager' => [
+81 −0
Original line number Diff line number Diff line
<?php

namespace Portfolio\Assertion;

use Application\Assertion\AbstractAssertion;
use Application\Service\UserContextServiceAwareInterface;
use JetBrains\PhpStorm\Pure;
use Laminas\Permissions\Acl\Assertion\AssertionInterface;
use Laminas\Permissions\Acl\Resource\ResourceInterface;
use Portfolio\Provider\Privilege\PortfolioPrivileges;
use These\Entity\Db\These;
use These\Service\These\TheseServiceAwareTrait;
use UnicaenApp\Service\MessageCollectorAwareInterface;

class PortfolioAssertion extends AbstractAssertion implements  AssertionInterface,  UserContextServiceAwareInterface, MessageCollectorAwareInterface
{
    use TheseServiceAwareTrait;

    /**
     * @param array $page
     * @return bool
     */
    #[Pure] public function __invoke(array $page): bool
    {
        return $this->assertPage($page);
    }

    /**
     * @param array $page
     * @return bool
     */
    private function assertPage(array $page): bool
    {
        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;
        }
        
        $theseId = $this->getMvcEvent()->getRouteMatch()->getParam('these');
        /** @var These|null $these */
        if($theseId) $these = $this->theseService->getRepository()->find($theseId);

        if (!$these) {
            return false;
        }

        switch ($action) {
            case 'afficher':
                return $this->userContextService->isStructureDuRoleRespecteeForThese($these);
        }

        return true;
    }

    protected function assertEntity(ResourceInterface $entity, $privilege = null): bool
    {
        if (!parent::assertEntity($entity, $privilege)) {
            return false;
        }

        /** @var These|null $these */
        $these = $entity;

        switch ($privilege) {
            case PortfolioPrivileges::PORTFOLIO_AFFICHER :
                return $this->userContextService->isStructureDuRoleRespecteeForThese($these);
        }

        return true;
    }
}
 No newline at end of file
+33 −0
Original line number Diff line number Diff line
<?php

namespace Portfolio\Assertion;

use Laminas\Mvc\Application;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
use These\Service\These\TheseService;

class PortfolioAssertionFactory {

    /**
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function __invoke(ContainerInterface $container): PortfolioAssertion
    {
        /**
         * @see TheseService $theseService
         */
        $theseService = $container->get(TheseService::class);

        $assertion = new PortfolioAssertion();
        $assertion->setTheseService($theseService);

        /* @var $application Application */
        $application = $container->get('Application');
        $mvcEvent = $application->getMvcEvent();
        $assertion->setMvcEvent($mvcEvent);
        return $assertion;
    }
}
 No newline at end of file
+9 −0
Original line number Diff line number Diff line
<?php
namespace Portfolio\Provider\Privilege;

use UnicaenPrivilege\Provider\Privilege\Privileges;

class PortfolioPrivileges extends Privileges {
    /*************** Compétences **************/
    const PORTFOLIO_AFFICHER    = 'portfolio-afficher';
}
 No newline at end of file