From cd3f7d7ead8fa0d08a01ee54b902bd52262acc57 Mon Sep 17 00:00:00 2001 From: odain Date: Wed, 21 Jun 2023 21:42:40 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B05324=20-=20disable=20repairment=20with?= =?UTF-8?q?=20backoffice=20and=20a=20customized=20portal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/UserProfilesEventListener.php | 9 ++++++- .../UserProfilesEventListenerTest.php | 24 +++++++++++++++---- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/datamodels/2.x/itop-profiles-itil/src/UserProfilesEventListener.php b/datamodels/2.x/itop-profiles-itil/src/UserProfilesEventListener.php index 0f299788b1..6ce5b3f797 100644 --- a/datamodels/2.x/itop-profiles-itil/src/UserProfilesEventListener.php +++ b/datamodels/2.x/itop-profiles-itil/src/UserProfilesEventListener.php @@ -89,10 +89,17 @@ class UserProfilesEventListener implements iEventServiceSetup $sRepairmentProfile = \utils::GetConfig()->GetModuleSetting('itop-profiles-itil', 'poweruserportal-repair-profile', null); - if (is_null($sRepairmentProfile) && sizeof($aPortalDispatcherData) > 2){ + if (is_null($sRepairmentProfile) && count($aPortalDispatcherData) > 2){ //when there are further portals we dont want to force a specific portal by repairing the associated profiles to a user $this->bIsRepairmentEnabled = false; return; + } else{ + $aPortalNames = array_keys($aPortalDispatcherData); + sort($aPortalNames); + if ($aPortalNames !== ['backoffice', 'itop-portal']){ + $this->bIsRepairmentEnabled = false; + return; + } } if (is_null($sRepairmentProfile)){ diff --git a/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-profiles-itil/UserProfilesEventListenerTest.php b/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-profiles-itil/UserProfilesEventListenerTest.php index 6d020f6ded..0be313ef1e 100644 --- a/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-profiles-itil/UserProfilesEventListenerTest.php +++ b/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-profiles-itil/UserProfilesEventListenerTest.php @@ -377,13 +377,27 @@ class UserProfilesEventListenerTest extends ItopDataTestCase $this->assertTrue($oUserProfilesEventListener->IsRepairmentEnabled()); } - public function testUserProfilesEventListenerInit_furtherportals_norepairmentconfigured(){ - $aPortalDispatcherData = [ - 'itop-portal', - 'customer-portal', - 'backoffice' + public function CustomizedPortalsProvider(){ + return [ + 'console + customized portal' => [ + 'aPortalDispatcherData' => [ + 'customer-portal', + 'backoffice' + ]], + 'console + itop portal + customized portal' => [ + 'aPortalDispatcherData' => [ + 'itop-portal', + 'customer-portal', + 'backoffice' + ] + ], ]; + } + /** + * @dataProvider CustomizedPortalsProvider + */ + public function testUserProfilesEventListenerInit_furtherportals_norepairmentconfigured($aPortalDispatcherData){ $oUserProfilesEventListener = new UserProfilesEventListener(); $oUserProfilesEventListener->Init($aPortalDispatcherData);