From f15c16f699caa30e6d18696c53af13a9c28ce657 Mon Sep 17 00:00:00 2001
From: Jean-Philippe Metivier <jean-philippe.metivier@unicaen.fr>
Date: Tue, 26 Nov 2024 15:13:24 +0100
Subject: [PATCH] Ajout de pribilege pour la gestion manuelle des chaines de
 validations

---
 database/migration/1.0.4.sql                  | 10 ++++++
 database/script/init_privilege_1.sql          |  4 ++-
 .../config/merged/agent-validateur.config.php | 10 +++++-
 .../Provider/Privilege/AgentPrivileges.php    |  3 ++
 module/Agent/view/agent/agent/afficher.phtml  | 36 ++++++++++---------
 .../View/Helper/partial/inscriptions.phtml    |  4 +--
 6 files changed, 47 insertions(+), 20 deletions(-)
 create mode 100644 database/migration/1.0.4.sql

diff --git a/database/migration/1.0.4.sql b/database/migration/1.0.4.sql
new file mode 100644
index 00000000..6d43c864
--- /dev/null
+++ b/database/migration/1.0.4.sql
@@ -0,0 +1,10 @@
+INSERT INTO unicaen_privilege_categorie (code, libelle, namespace, ordre)
+VALUES ('agent', 'Gestion des agents', 'Agent\Provider\Privilege', 100);
+INSERT INTO unicaen_privilege_privilege(CATEGORIE_ID, CODE, LIBELLE, ORDRE)
+WITH d(code, lib, ordre) AS (
+    SELECT 'agent_gerer_valideur_importe', 'Gérer les valideur·deuses importé·es', 60 UNION
+    SELECT 'agent_gerer_valideur_saisi', 'Gérer les valideur·deuses saisi·es', 70
+)
+SELECT cp.id, d.code, d.lib, d.ordre
+FROM d
+JOIN unicaen_privilege_categorie cp ON cp.CODE = 'agent';
\ No newline at end of file
diff --git a/database/script/init_privilege_1.sql b/database/script/init_privilege_1.sql
index 38cf0790..88adbcf2 100644
--- a/database/script/init_privilege_1.sql
+++ b/database/script/init_privilege_1.sql
@@ -325,12 +325,14 @@ WITH d(code, lib, ordre) AS (
     SELECT 'agent_index', 'Accéder à l''index', 0 UNION
     SELECT 'agent_afficher', 'Afficher un agent', 10 UNION
     SELECT 'agent_modifier', 'Modifier un agent', 30 UNION
+    SELECT 'agent_gerer_valideur_importe', 'Gérer les valideur·deuses importé·es', 60 UNION
+    SELECT 'agent_gerer_valideur_saisi', 'Gérer les valideur·deuses saisi·es', 70 UNION
     SELECT 'agent_rechercher', 'Rechercher un agent', 100 UNION
     SELECT 'agent_mesagents', 'Menu - Mes Agent·es -', 200
 )
 SELECT cp.id, d.code, d.lib, d.ordre
 FROM d
-         JOIN unicaen_privilege_categorie cp ON cp.CODE = 'agent';
+JOIN unicaen_privilege_categorie cp ON cp.CODE = 'agent';
 
 -- STRUCTURE
 INSERT INTO unicaen_privilege_categorie (code, libelle, namespace, ordre)
diff --git a/module/Agent/config/merged/agent-validateur.config.php b/module/Agent/config/merged/agent-validateur.config.php
index 050fea43..86a366f7 100644
--- a/module/Agent/config/merged/agent-validateur.config.php
+++ b/module/Agent/config/merged/agent-validateur.config.php
@@ -35,11 +35,19 @@ return [
                         'ajouter',
                         'modifier',
                         'supprimer',
+                    ],
+                    'privilege' => [
+                        AgentPrivileges::getResourceId(AgentPrivileges::AGENT_GERER_VALIDEUR_IMPORTE),
+                    ],
+                ],
+                [
+                    'controller' => ValidateurController::class,
+                    'action' => [
                         'historiser',
                         'restaurer',
                     ],
                     'privilege' => [
-                        AgentPrivileges::getResourceId(AgentPrivileges::AGENT_MODIFIER),
+                        AgentPrivileges::getResourceId(AgentPrivileges::AGENT_GERER_VALIDEUR_SAISI),
                     ],
                 ],
             ],
diff --git a/module/Agent/src/Provider/Privilege/AgentPrivileges.php b/module/Agent/src/Provider/Privilege/AgentPrivileges.php
index 8901416f..b3a02c2c 100644
--- a/module/Agent/src/Provider/Privilege/AgentPrivileges.php
+++ b/module/Agent/src/Provider/Privilege/AgentPrivileges.php
@@ -11,4 +11,7 @@ class AgentPrivileges extends Privileges
     const AGENT_MODIFIER = 'agent-agent_modifier';
     const AGENT_RECHERCHER = 'agent-agent_rechercher';
     const AGENT_MESAGENTS = 'agent-agent_mesagents';
+
+    const AGENT_GERER_VALIDEUR_IMPORTE = 'agent-agent_gerer_valideur_importe';
+    const AGENT_GERER_VALIDEUR_SAISI = 'agent-agent_gerer_valideur_saisi';
 }
\ No newline at end of file
diff --git a/module/Agent/view/agent/agent/afficher.phtml b/module/Agent/view/agent/agent/afficher.phtml
index 1480d87d..975fbf6f 100644
--- a/module/Agent/view/agent/agent/afficher.phtml
+++ b/module/Agent/view/agent/agent/afficher.phtml
@@ -27,6 +27,8 @@ $this->headTitle("Afficher l'agent " . $agent->getDenomination());
 
 $statuts = AgentStatut::generateStatutsArray($agentStatuts);
 
+$canGererValideurSaisi = $this->isAllowed(AgentPrivileges::getResourceId(AgentPrivileges::AGENT_GERER_VALIDEUR_SAISI));
+$canGererValideurImporte = $this->isAllowed(AgentPrivileges::getResourceId(AgentPrivileges::AGENT_GERER_VALIDEUR_IMPORTE));
 $canModifier = $this->isAllowed(AgentPrivileges::getResourceId(AgentPrivileges::AGENT_MODIFIER));
 ?>
 
@@ -118,7 +120,7 @@ $canModifier = $this->isAllowed(AgentPrivileges::getResourceId(AgentPrivileges::
     <?php endif; ?>
 
     <dt class="col-md-4"> Validateur·trices<br>
-        <?php if ($canModifier) : ?>
+        <?php if ($canGererValideurSaisi) : ?>
             <?php /** @see \Agent\Controller\ValidateurController::ajouterAction() */ ?>
             <a href="<?php echo $this->url('agent/validateur/ajouter', ['agent' => $agent->getId()], [], true); ?>"
                class="btn btn-primary ajax-modal" data-event="modification">
@@ -137,13 +139,13 @@ $canModifier = $this->isAllowed(AgentPrivileges::getResourceId(AgentPrivileges::
         <?php else: ?>
             <ul>
                 <?php foreach ($validateurs as $validateur) : ?>
-                    <?php if (!$validateur->estHistorise() or $canModifier) : ?>
+                    <?php if (!$validateur->estHistorise() or $canGererValideurSaisi or $canGererValideurImporte) : ?>
                         <li
                                 title="Sur la période du <?php echo $validateur->getDateDebut()->format('d/m/Y'); ?> au <?php echo $validateur->getDateFin() ? $validateur->getDateFin()->format('d/m/y') : " ---"; ?>">
                             <span class="<?php if ($validateur->estHistorise()) echo "historise"; ?>"><?php echo $validateur->getValidateur()->getDenomination(); ?></span>
                             <span
                                     class="badge"> <?php echo $validateur->getSourceId(); ?> </span>
-                            <?php if ($validateur->getSourceId() === 'MES FORMATIONS' and $canModifier) : ?>
+                            <?php if ($validateur->getSourceId() === 'MES FORMATIONS' and $canGererValideurSaisi) : ?>
                                 <?php /** @see \Agent\Controller\ValidateurController::modifierAction() */ ?>
                                 <a href="<?php echo $this->url('agent/validateur/modifier', ['agent-validateur' => $validateur->getId()], [], true); ?>"
                                    class="ajax-modal action primary" data-event="modification">
@@ -157,19 +159,21 @@ $canModifier = $this->isAllowed(AgentPrivileges::getResourceId(AgentPrivileges::
                                     Supprimer
                                 </a>
                             <?php else : ?>
-                                <?php if ($validateur->estHistorise()) : ?>
-                                    <?php /** @see \Agent\Controller\ValidateurController::restaurerAction() */ ?>
-                                    <a href="<?php echo $this->url('agent/validateur/restaurer', ['agent-validateur' => $validateur->getId()], [], true); ?>"
-                                       class="action warning" >
-                                        <span class="icon icon-restaurer"></span>
-                                        Ré-établir
-                                    </a>
-                                <?php else : ?>
-                                    <a href="<?php echo $this->url('agent/validateur/historiser', ['agent-validateur' => $validateur->getId()], [], true); ?>"
-                                       class="action warning">
-                                        <span class="icon icon-historiser"></span>
-                                        Révoquer
-                                    </a>
+                                <?php if ($canGererValideurImporte AND $validateur->getSourceId() !== 'MES FORMATIONS') : ?>
+                                    <?php if ($validateur->estHistorise()) : ?>
+                                        <?php /** @see \Agent\Controller\ValidateurController::restaurerAction() */ ?>
+                                        <a href="<?php echo $this->url('agent/validateur/restaurer', ['agent-validateur' => $validateur->getId()], [], true); ?>"
+                                           class="action warning" >
+                                            <span class="icon icon-restaurer"></span>
+                                            Ré-établir
+                                        </a>
+                                    <?php else : ?>
+                                        <a href="<?php echo $this->url('agent/validateur/historiser', ['agent-validateur' => $validateur->getId()], [], true); ?>"
+                                           class="action warning">
+                                            <span class="icon icon-historiser"></span>
+                                            Révoquer
+                                        </a>
+                                    <?php endif; ?>
                                 <?php endif; ?>
                             <?php endif; ?>
                         </li>
diff --git a/module/Formation/src/Formation/View/Helper/partial/inscriptions.phtml b/module/Formation/src/Formation/View/Helper/partial/inscriptions.phtml
index fdbf0691..a682cd4a 100644
--- a/module/Formation/src/Formation/View/Helper/partial/inscriptions.phtml
+++ b/module/Formation/src/Formation/View/Helper/partial/inscriptions.phtml
@@ -89,8 +89,8 @@ if (!$displayDocument) $etatSize += 2;
                     <?php if ($inscription->isRqth()) : ?>
                         <br>
                         <span class="text-info" data-bs-toggle="tooltip" data-bs-html="true"
-                              title="<?php echo $inscription->getPrecisionRqth(); ?>">
-                        <span class="icon icon-rqth"></span>
+                              title="<?php echo ($inscription->getPrecisionRqth())??"Aucune précision"; ?>">
+                            <span class="icon icon-rqth"></span>
                             RQTH
                     </span>
                     <?php endif; ?>
-- 
GitLab