Skip to content
Snippets Groups Projects
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
Branches
Tags 4.0.0
1 merge request!55Ll bug report services
<?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;
}
}
......@@ -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',
......
......@@ -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'],
......
......@@ -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';
......
......@@ -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>';
......
......@@ -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()): ?>
<?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"
<a class="archiver-pj btn btn-success pop-ajax"
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..."
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 else: ?>
<?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; ?>
<?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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment