From acae0900366ad63b673f001d317ab5943cab8cff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Laurent=20L=C3=A9cluse?= <laurent.lecluse@unicaen.fr>
Date: Tue, 12 Nov 2019 16:40:17 +0100
Subject: [PATCH] =?UTF-8?q?Correction=20bug=20lors=20de=20la=20suppression?=
 =?UTF-8?q?=20de=20r=C3=B4les?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 CHANGELOG.md                                      |  1 +
 .../Application/Controller/DroitsController.php   |  3 +++
 .../Provider/Identity/IdentityProvider.php        | 15 +++++++++++----
 .../Application/Provider/Role/RoleProvider.php    |  2 +-
 4 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index b5e892817f..f5ba7a06fd 100755
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@ author: Laurent Lécluse - DSI - Unicaen
 * Un bug modifiant les paramètres globaux qui avaient été configurés a été résolu
 * La duplication de statuts refonctionne
 * Lors de la création d'un nouveau statut, l'octroi de privilèges ne plante plus
+* La suppression de rôle fonctionne de nouveau correctement 
 
 
 # OSE 9.0.1-zf2 et 9.0.1-zf3
diff --git a/module/Application/src/Application/Controller/DroitsController.php b/module/Application/src/Application/Controller/DroitsController.php
index 35d4e3ad6c..c2be42c762 100755
--- a/module/Application/src/Application/Controller/DroitsController.php
+++ b/module/Application/src/Application/Controller/DroitsController.php
@@ -106,6 +106,9 @@ class DroitsController extends AbstractController
         $title  = "Suppression du rôle";
         $form   = $this->makeFormSupprimer( function() use ($role){
             $this->getServiceRole()->delete($role);
+            $this->getCacheFilesystem()->delete(RoleProvider::class.'/affectations');
+            $cc = $this->getCacheContainer(PrivilegeService::class);
+            unset($cc->privilegesRoles);
         } );
 
         return compact('role', 'title', 'form');
diff --git a/module/Application/src/Application/Provider/Identity/IdentityProvider.php b/module/Application/src/Application/Provider/Identity/IdentityProvider.php
index 9cd4a69589..04937ce009 100755
--- a/module/Application/src/Application/Provider/Identity/IdentityProvider.php
+++ b/module/Application/src/Application/Provider/Identity/IdentityProvider.php
@@ -60,11 +60,18 @@ class IdentityProvider implements ChainableProvider, IdentityProviderInterface
             if ($utilisateur = $this->getServiceContext()->getUtilisateur()) {
                 foreach ($utilisateur->getAffectation() as $affectation) {
                     /* @var $affectation Affectation */
-                    $roleId = $affectation->getRole()->getCode();
-                    if ($structure = $affectation->getStructure()) {
-                        $roleId .= '-' . $structure->getSourceCode();
+                    $role = $affectation->getRole();
+                    try {
+                        $roleId = $role->getCode();
+                        if ($role->estNonHistorise()) {
+                            if ($structure = $affectation->getStructure()) {
+                                $roleId .= '-' . $structure->getSourceCode();
+                            }
+                            $this->identityRoles[] = $roleId;
+                        }
+                    }catch(\Exception $e){
+                        // on ignore les affectations dont les rôles ont été supprimés
                     }
-                    $this->identityRoles[] = $roleId;
                 }
             }
 
diff --git a/module/Application/src/Application/Provider/Role/RoleProvider.php b/module/Application/src/Application/Provider/Role/RoleProvider.php
index 8684d95d9d..c04653773d 100755
--- a/module/Application/src/Application/Provider/Role/RoleProvider.php
+++ b/module/Application/src/Application/Provider/Role/RoleProvider.php
@@ -155,7 +155,7 @@ class RoleProvider implements ProviderInterface, EntityManagerAwareInterface
                 /* @var $affectation Affectation */
                 if ($structure = $affectation->getStructure()) {
                     $affRoleId = $roleId . '-' . $structure->getSourceCode();
-                    if (!isset($roles[$affRoleId])) {
+                    if (!isset($roles[$affRoleId]) && $dbRole->estNonHistorise()) {
                         $affRoleLibelle = $dbRole->getLibelle() . ' (' . $structure->getLibelleCourt() . ')';
                         $affRole        = new \Application\Acl\Role($affRoleId, $roleId, $affRoleLibelle);
                         if (isset($rolesPrivileges[$roleId])) {
-- 
GitLab