From f2f291dbbc7f835339c22d2fbfc7cf6dd2a82d40 Mon Sep 17 00:00:00 2001 From: Fred Tempez Date: Fri, 1 Dec 2023 16:24:12 +0100 Subject: [PATCH] =?UTF-8?q?protection=20des=20profils=20utilis=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/module/user/user.php | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/core/module/user/user.php b/core/module/user/user.php index 758f659..ca65054 100644 --- a/core/module/user/user.php +++ b/core/module/user/user.php @@ -561,8 +561,19 @@ class user extends common */ public function profil() { - foreach ($this->getData(['profil']) as $groupId => $groupData) { + // Ne pas supprimer un profil utililsé + // recherche les membres du groupe + $groups = helper::arrayColumn($this->getData(['user']), 'group'); + $groups = array_keys($groups, $this->getUrl(2)); + $profilUsed = true; + // Stoppe si le profil est affecté + foreach ($groups as $userId) { + if ((string) $this->getData(['user', $userId, 'profil']) === $this->getUrl(3)) { + $profilUsed= false; + } + } + foreach ($this->getData(['profil']) as $groupId => $groupData) { // Membres sans permissions spécifiques if ( $groupId == self::GROUP_BANNED || @@ -605,7 +616,7 @@ class user extends common 'href' => helper::baseUrl() . 'user/profilDelete/' . $groupId . '/' . $profilId, 'value' => template::ico('trash'), 'help' => 'Supprimer', - 'disabled' => $profilData['permanent'], + 'disabled' => $profilData['permanent'] && $profilUsed, ]) ]; } @@ -927,6 +938,17 @@ class user extends common public function profilDelete() { + // Ne pas supprimer un profil utililsé + // recherche les membres du groupe + $groups = helper::arrayColumn($this->getData(['user']), 'group'); + $groups = array_keys($groups, $this->getUrl(2)); + $flag= true; + // Stoppe si le profil est affecté + foreach ($groups as $userId) { + if ((string) $this->getData(['user', $userId, 'profil']) === $this->getUrl(3)) { + $flag= false; + } + } if ( $this->getUser('permission', __CLASS__, __FUNCTION__) !== true || $this->getData(['profil', $this->getUrl(2), $this->getUrl(3)]) === null || @@ -938,12 +960,15 @@ class user extends common ]); // Suppression } else { - $this->deleteData(['profil', $this->getUrl(2), $this->getUrl(3)]); + if ($flag) { + $this->deleteData(['profil', $this->getUrl(2), $this->getUrl(3)]); + } + // Valeurs en sortie $this->addOutput([ 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/profil', - 'notification' => helper::translate('Profil supprimé'), - 'state' => true + 'notification' => $flag ? helper::translate('Profil supprimé') : helper::translate('Action interdite'), + 'state' => $flag ]); } }