From 4e5081b90cc126863f05cf22b494fcade77ad310 Mon Sep 17 00:00:00 2001 From: Antony Le Courtes <antony.lecourtes@unicaen.fr> Date: Tue, 17 Nov 2020 16:15:54 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20d'un=20privilege=20'piece-justificative?= =?UTF-8?q?-archiver'=20pour=20donner=20le=20droit=20aux=20diff=C3=A9rents?= =?UTF-8?q?=20intervenants=20d'archiver=20une=20pi=C3=A8ce=20jointe=20avec?= =?UTF-8?q?=20une=20dur=C3=A9e=20de=20vie=20pour=20la=20mettre=20=C3=A0=20?= =?UTF-8?q?jour=20sur=20l'ann=C3=A9e=20en=20cours=20voulue=20+=20script=20?= =?UTF-8?q?qui=20met=20le=20privilege=20'piece-justificative-archiver'=20s?= =?UTF-8?q?ur=20les=20roles=20et=20statuts=20si=20ceux-ci=20ont=20d=C3=A9j?= =?UTF-8?q?=C3=A0=20le=20droit=20'piece-justificative-edition'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MigrationPrivilegesArchivage.php | 164 ++++++++++++++++++ data/privileges.php | 1 + module/Application/config/pieces.config.php | 26 +-- .../Provider/Privilege/Privileges.php | 1 + .../view/application/piece-jointe/index.phtml | 5 +- .../piece-jointe/partial/piece-jointe.phtml | 43 +++-- 6 files changed, 209 insertions(+), 31 deletions(-) create mode 100644 admin/migration/MigrationPrivilegesArchivage.php diff --git a/admin/migration/MigrationPrivilegesArchivage.php b/admin/migration/MigrationPrivilegesArchivage.php new file mode 100644 index 0000000000..49db600e6b --- /dev/null +++ b/admin/migration/MigrationPrivilegesArchivage.php @@ -0,0 +1,164 @@ +<?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; + } +} + diff --git a/data/privileges.php b/data/privileges.php index 721e62daaf..1af4dd7086 100644 --- a/data/privileges.php +++ b/data/privileges.php @@ -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', diff --git a/module/Application/config/pieces.config.php b/module/Application/config/pieces.config.php index 9ea7414ce1..ae56270774 100755 --- a/module/Application/config/pieces.config.php +++ b/module/Application/config/pieces.config.php @@ -277,11 +277,11 @@ return [ 'guards' => [ PrivilegeController::class => [ /* Dossier */ - [//Créer un droit archivage - 'controller' => 'Application\Controller\Dossier', - 'action' => ['index'], - 'privileges' => [Privileges::DOSSIER_VISUALISATION], - 'assertion' => Assertion\DossierPiecesAssertion::class, + [ + 'controller' => 'Application\Controller\Dossier', + 'action' => ['index'], + 'privileges' => [Privileges::DOSSIER_VISUALISATION], + 'assertion' => Assertion\DossierPiecesAssertion::class, ], [ 'controller' => 'Application\Controller\Dossier', @@ -311,11 +311,11 @@ return [ 'privileges' => [Privileges::DOSSIER_SUPPRESSION], ], - [//Créer un droit archivage - 'controller' => 'Application\Controller\IntervenantDossier', - 'action' => ['index'], - 'privileges' => [Privileges::DOSSIER_VISUALISATION, Privileges::DOSSIER_IDENTITE_EDITION], - 'assertion' => Assertion\DossierPiecesAssertion::class, + [ + 'controller' => 'Application\Controller\IntervenantDossier', + 'action' => ['index'], + 'privileges' => [Privileges::DOSSIER_VISUALISATION, Privileges::DOSSIER_IDENTITE_EDITION], + 'assertion' => Assertion\DossierPiecesAssertion::class, ], @@ -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'], diff --git a/module/Application/src/Application/Provider/Privilege/Privileges.php b/module/Application/src/Application/Provider/Privilege/Privileges.php index d529aaced0..e24d7e0444 100755 --- a/module/Application/src/Application/Provider/Privilege/Privileges.php +++ b/module/Application/src/Application/Provider/Privilege/Privileges.php @@ -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'; diff --git a/module/Application/view/application/piece-jointe/index.phtml b/module/Application/view/application/piece-jointe/index.phtml index 96bd6ccbcf..8e668f1446 100755 --- a/module/Application/view/application/piece-jointe/index.phtml +++ b/module/Application/view/application/piece-jointe/index.phtml @@ -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>'; diff --git a/module/Application/view/application/piece-jointe/partial/piece-jointe.phtml b/module/Application/view/application/piece-jointe/partial/piece-jointe.phtml index 2763e0f44a..0347fe80bd 100755 --- a/module/Application/view/application/piece-jointe/partial/piece-jointe.phtml +++ b/module/Application/view/application/piece-jointe/partial/piece-jointe.phtml @@ -7,8 +7,10 @@ * @var $intervenant \Application\Entity\Db\Intervenant * @var $canEdit boolean * @var $canValider boolean + * @var $canArchiver boolean * @var $canDevalider boolean * @var $obligatoire boolean + * @var $annee \Application\Entity\Db\Annee */ $hasValidation = $pj && $pj->getValidation(); @@ -48,26 +50,29 @@ $uploader = $this->uploader()->setUrl($this->url('piece-jointe/intervenant/fichi > <div class="panel-heading panel-heading-h3"> <h3> - <?php if ((!$hasValidation && $canValider) || ($hasValidation && $canDevalider)): ?> - - <?php if ($pj && $pj->getIntervenant()->getAnnee()->getId() != $annee->getId()): ?> - <div class="validation-bar pull-right" - data-url="<?= $this->url('piece-jointe/intervenant/archiver', ['pieceJointe' => $pj->getId()], [], true) ?>"> - <a class="archiver-pj btn btn-success" - href="<?= $this->url('piece-jointe/intervenant/archiver', ['pieceJointe' => $pj->getId()], [], true) ?>" - title="Archiver cette pièce jointe pour pouvoir en fournir une plus récente." - data-loading-text="Patientez..." - > - <span class="glyphicon glyphicon-refresh"></span> Modifier (si besoin) - </a> - </div> - <?php else: ?> - <div class="validation-bar pull-right" - data-url="<?= $this->url('piece-jointe/intervenant/validation', ['typePieceJointe' => $tpj->getId()], [], true) ?>"> - <?= $this->partial('application/piece-jointe/validation', compact('pj')) ?> - </div> - <?php endif; ?> + <?php if ($hasValidation && $canArchiver && $pj && $pj->getIntervenant()->getAnnee()->getId() != $annee->getId()): ?> + <div class="validation-bar pull-right" + data-url="<?= $this->url('piece-jointe/intervenant/archiver', ['pieceJointe' => $pj->getId()], [], true) ?>"> + <a class="archiver-pj btn btn-success pop-ajax" + href="<?= $this->url('piece-jointe/intervenant/archiver', ['pieceJointe' => $pj->getId()], [], true) ?>" + data-loading-text="Patientez..." + title="Archiver cette pièce jointe pour en fournir une plus récente ?" + data-content="Archiver cette pièce jointe pour en fournir une plus récente ?" + data-confirm="true" + data-submit-reload="true" + data-confirm-button="Oui" + data-cancel-button="Non" + > + <span class="glyphicon glyphicon-refresh"></span> Modifier (si besoin) + </a> + </div> + <?php elseif ((!$hasValidation && $canValider && $pj && $pj->getIntervenant()->getAnnee()->getId() == $annee->getId()) || ($hasValidation && $canDevalider && $pj && $pj->getIntervenant()->getAnnee()->getId() == $annee->getId())): ?> + <div class="validation-bar pull-right" + data-url="<?= $this->url('piece-jointe/intervenant/validation', ['typePieceJointe' => $tpj->getId()], [], true) ?>"> + <?= $this->partial('application/piece-jointe/validation', compact('pj')) ?> + </div> <?php endif; ?> + <!--Infos sur document fourni sur une autre année--> <?= ($pj && $pj->getIntervenant()->getAnnee()->getId() != $annee->getId()) ? $type . " <span style=\"font-size:0.6em;\">Fourni(e) en " . $pj->getIntervenant()->getAnnee()->getId() . "</span>" : $type; -- GitLab