Commit 4e5081b9 authored by Antony Le Courtes's avatar Antony Le Courtes
Browse files

Ajout d'un privilege 'piece-justificative-archiver' pour donner le droit aux...

Ajout d'un privilege 'piece-justificative-archiver' pour donner le droit aux différents intervenants d'archiver une pièce jointe avec une durée de vie pour la mettre à jour sur l'année en cours voulue + script qui met le privilege 'piece-justificative-archiver' sur les roles et statuts si ceux-ci ont déjà le droit 'piece-justificative-edition'
parent 9d6ad71a
Loading
Loading
Loading
Loading
+164 −0
Changes for admin/migration/MigrationPrivilegesArchivage.php: 164 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php


use BddAdmin\Bdd;

class MigrationPrivilegesArchivage extends AbstractMigration
{
    protected $contexte = self::CONTEXTE_ALL;



    public function description(): string
    {
        return "Ajout du privileges archivage pour les statuts et rôles pouvant éditer les pièces jointes";
    }



    public function utile(): bool
    {
        return true;
    }



    public function action(string $contexte)
    {
        if ($contexte == self::CONTEXTE_PRE) {
            $this->before();
        } else {
            $this->after();
        }
    }



    protected function before()
    {

    }



    protected function after()
    {
        $oa      = $this->manager->getOseAdmin();
        $bdd     = $this->manager->getBdd();
        $console = $this->manager->getOseAdmin()->getConsole();


        $sqlPrivilegeArchivage = "
            SELECT
                p.id   id,
                p.code code
                
            FROM
                privilege p 
            JOIN 
                categorie_privilege cp ON p.categorie_id = cp.id
            WHERE
                cp.code = 'piece-justificative'
            AND 
                p.code = 'archivage'
        ";

        $privilegeArchivage   = $bdd->select($sqlPrivilegeArchivage, [], ['fetch' => Bdd::FETCH_ONE]);
        $privilegeArchivageId = $privilegeArchivage['ID'];


        $console->println("Récupération des statuts intervenants pouvant éditer une pièce jointe", CONSOLE::COLOR_GREEN);


        //Traitement des privileges pour les statuts
        $statutIntervenant = [];

        $sqlStatut = "SELECT 
            si.code    code_statut,
            si.id      id,
            si.libelle libelle,
            cp.code    categorie_privilege,
            p.code     code_privilege
            FROM statut_intervenant si
            JOIN statut_privilege sp ON sp.statut_id = si.id
            JOIN privilege p ON sp.privilege_id = p.id 
            JOIN categorie_privilege cp ON cp.id = p.categorie_id
            WHERE cp.code = 'piece-justificative'
            AND (p.code = 'edition' OR p.code ='archivage')
            AND si.histo_destruction IS NULL
            ORDER BY si.code ASC
        ";

        $statutsIntervenantPrivilegesArchivage = $bdd->select($sqlStatut);
        foreach ($statutsIntervenantPrivilegesArchivage as $spd) {
            $statutIntervenant[$spd['CODE_STATUT']]['PRIVILEGES'][] = $spd;
            if (!isset($statutIntervenant[$spd['CODE_STATUT']]['ID'])) {
                $statutIntervenant[$spd['CODE_STATUT']]['ID'] = $spd['ID'];
            }
        }

        foreach ($statutIntervenant as $codeStatut => $statut) {
            $console->println('Mise à niveau des privilèges archivage pour le statut : ' . $codeStatut, CONSOLE::COLOR_BLUE);
            if ($this->hasPrivilege($statut, 'edition') && !$this->hasPrivilege($statut, 'archivage')) {
                //On ajouter les privleges archivage pour ce statut car il peut éditer les pièces jointes
                $sqlInsert = "INSERT INTO statut_privilege (privilege_id, statut_id) VALUES ('" . $privilegeArchivageId . "', '" . $statut['ID'] . "')";
                $bdd->exec($sqlInsert);
            }
        }


        $console->println("Récupération des roles pouvant éditer une pièce jointe", CONSOLE::COLOR_GREEN);

        $roles = [];

        $sqlRole = "SELECT
            r.code code_role,
            r.id   id,
            r.libelle libelle,
            cp.code categorie_privilege,
            p.code code_privilege
            FROM role r
            JOIN role_privilege rp ON r.id = rp.role_id
            JOIN privilege p ON p.id = rp.privilege_id
            JOIN categorie_privilege cp ON cp.id = p.categorie_id
            WHERE cp.code = 'piece-justificative'
            AND (p.code = 'edition' OR p.code ='archivage')
            AND r.histo_destruction IS NULL 
            ORDER BY r.code ASC
        ";

        $rolePrivilegesArchivage = $bdd->select($sqlRole);
        foreach ($rolePrivilegesArchivage as $rpd) {
            $roles[$rpd['CODE_ROLE']]['PRIVILEGES'][] = $rpd;
            if (!isset($roles[$rpd['CODE_ROLE']]['ID'])) {
                $roles[$rpd['CODE_ROLE']]['ID'] = $rpd['ID'];
            }
        }

        //Traitement des privileges pour les roles
        foreach ($roles as $codeRole => $role) {
            $console->println('Mise à niveau du privilege archivage pour le role : ' . $codeRole, CONSOLE::COLOR_BLUE);
            if ($this->hasPrivilege($role, 'edition') && !$this->hasPrivilege($role, 'archivage')) {
                //On ajouter les privleges archivage pour ce role car il peut éditer les pièces jointes
                $sqlInsert = "INSERT INTO role_privilege (privilege_id, role_id) VALUES ('" . $privilegeArchivageId . "', '" . $role['ID'] . "')";
                $bdd->exec($sqlInsert);
            }
        }
        //Clear cache car on a modifié les privileges donc les entity en cache ne doivent plus servir
        $oa->run('clear-cache');
    }



    private function hasPrivilege($statut, $privilegeCode)
    {
        foreach ($statut['PRIVILEGES'] as $privilege) {
            if ($privilege['CODE_PRIVILEGE'] == $privilegeCode) {
                return true;
            }
        }

        return false;
    }
}
+1 −0
Changes for data/privileges.php: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -107,6 +107,7 @@ return [
            'edition'               => 'Édition',
            'validation'            => 'Validation',
            'devalidation'          => 'Dévalidation',
            'archivage'             => 'Archivage',
            'gestion-edition'       => 'Gestion des pièces justificatives (édition)',
            'gestion-visualisation' => 'Gestion des pièces justificatives (visualisation)',
            'telechargement'        => 'Téléchargement',
+8 −2
Changes for module/Application/config/pieces.config.php: 8 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -277,7 +277,7 @@ return [
        'guards'             => [
            PrivilegeController::class => [
                /* Dossier */
                [//Créer un droit archivage
                [
                    'controller' => 'Application\Controller\Dossier',
                    'action'     => ['index'],
                    'privileges' => [Privileges::DOSSIER_VISUALISATION],
@@ -311,7 +311,7 @@ return [
                    'privileges' => [Privileges::DOSSIER_SUPPRESSION],
                ],

                [//Créer un droit archivage
                [
                    'controller' => 'Application\Controller\IntervenantDossier',
                    'action'     => ['index'],
                    'privileges' => [Privileges::DOSSIER_VISUALISATION, Privileges::DOSSIER_IDENTITE_EDITION],
@@ -373,6 +373,12 @@ return [
                    'privileges' => Privileges::PIECE_JUSTIFICATIVE_EDITION,
                    'assertion'  => Assertion\DossierPiecesAssertion::class,
                ],
                [
                    'controller' => 'Application\Controller\PieceJointe',
                    'action'     => ['archiver'],
                    'privileges' => Privileges::PIECE_JUSTIFICATIVE_ARCHIVAGE,
                    'assertion'  => Assertion\DossierPiecesAssertion::class,
                ],
                [
                    'controller' => 'Application\Controller\PieceJointe',
                    'action'     => ['valider'],
+1 −0
Changes for module/Application/src/Application/Provider/Privilege/Privileges.php: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -190,6 +190,7 @@ class Privileges extends \UnicaenAuth\Provider\Privilege\Privileges
    const PIECE_JUSTIFICATIVE_TELECHARGEMENT                  = 'piece-justificative-telechargement';
    const PIECE_JUSTIFICATIVE_VALIDATION                      = 'piece-justificative-validation';
    const PIECE_JUSTIFICATIVE_VISUALISATION                   = 'piece-justificative-visualisation';
    const PIECE_JUSTIFICATIVE_ARCHIVAGE                       = 'piece-justificative-archivage';
    const PILOTAGE_ECARTS_ETATS                               = 'pilotage-ecarts-etats';
    const PILOTAGE_VISUALISATION                              = 'pilotage-visualisation';
    const PLAFONDS_GESTION_EDITION                            = 'plafonds-gestion-edition';
+3 −2
Changes for module/Application/view/application/piece-jointe/index.phtml: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ $this->headTitle()->append((string)$intervenant)->append("Pièces justificatives
$canEdit      = $this->isAllowed(Privileges::getResourceId(Privileges::PIECE_JUSTIFICATIVE_EDITION));
$canValider   = $this->isAllowed(Privileges::getResourceId(Privileges::PIECE_JUSTIFICATIVE_VALIDATION));
$canDevalider = $this->isAllowed(Privileges::getResourceId(Privileges::PIECE_JUSTIFICATIVE_DEVALIDATION));
$canArchiver  = $this->isAllowed(Privileges::getResourceId(Privileges::PIECE_JUSTIFICATIVE_ARCHIVAGE));

$infosUrl = $this->url('piece-jointe/intervenant/infos', ['intervenant' => $intervenant->getId()]);

@@ -46,7 +47,7 @@ $menuUrl = $this->url('intervenant/services', ['intervenant' => $intervenant->ge
                } else {
                    $pj = null;
                }
                echo $this->partial('application/piece-jointe/partial/piece-jointe', compact('intervenant', 'tpj', 'pj', 'canEdit', 'canValider', 'canDevalider', 'obligatoire', 'annee'));
                echo $this->partial('application/piece-jointe/partial/piece-jointe', compact('intervenant', 'tpj', 'pj', 'canEdit', 'canValider', 'canDevalider', 'canArchiver', 'obligatoire', 'annee'));
            }
            echo '</div>';

@@ -76,7 +77,7 @@ $menuUrl = $this->url('intervenant/services', ['intervenant' => $intervenant->ge
                if ($pj->getIntervenant()->getAnnee()->getId() == $annee->getId()) {
                    $haveRestante = true;
                    $tpj          = $pj->getType();
                    $html         .= $this->partial('application/piece-jointe/partial/piece-jointe', compact('intervenant', 'tpj', 'pj', 'canEdit', 'canValider', 'canDevalider', 'obligatoire', 'annee'));
                    $html         .= $this->partial('application/piece-jointe/partial/piece-jointe', compact('intervenant', 'tpj', 'pj', 'canEdit', 'canValider', 'canDevalider', 'canArchiver', 'obligatoire', 'annee'));
                }
            }
            $html .= '</div>';
Loading