diff --git a/admin/migration/MigrationPrivilegesArchivage.php b/admin/migration/MigrationPrivilegesArchivage.php new file mode 100644 index 0000000000000000000000000000000000000000..49db600e6bc15e729a824445665499e56ffbfd86 --- /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 721e62daaf5f37d616e458b9aa9701cb6c3858c2..1af4dd708609de52f335ea742f5e0a109e5dc452 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 9ea7414ce12da8a243eea103e1ee95c25141d7ca..ae562707749891fa1b4b132aac308b52a0fc9457 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 d529aaced027baef3243768efd5f3b1529a23c21..e24d7e0444d30aad47a859bd193b2f6e10c27cd0 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 96bd6ccbcf91e58dc20b636a358f0618792505b4..8e668f14463a982d2d58cd8091d540d7cfeef6d4 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 2763e0f44af3a6dd059e19b30f4b620e51979eac..0347fe80bdd5f8561866cb26d9e959f14a224fbe 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;