diff --git a/addons/userrights/userrightsprofile.class.inc.php b/addons/userrights/userrightsprofile.class.inc.php index 366630510..b9ac16d84 100644 --- a/addons/userrights/userrightsprofile.class.inc.php +++ b/addons/userrights/userrightsprofile.class.inc.php @@ -353,7 +353,11 @@ class URP_UserProfile extends UserRightsBaseClassGUI { throw new SecurityException(Dict::Format('UI:Login:Error:AccessRestricted')); } - if (!UserRights::IsActionAllowed(get_class($this), $iActionCode, DBObjectSet::FromObject($this))) + + $oSet = new \ormLinkSet(get_class($oUser), 'profile_list', \DBObjectSet::FromScratch(\URP_UserProfile::class)); + $oSet->AddItem(MetaModel::NewObject('URP_UserProfile', ['profileid' => $this->GetKey(), 'reason' => 'CheckIfProfileIsAllowed'])); + + if (!UserRights::IsActionAllowed(get_class($this), $iActionCode, $oSet)) { throw new SecurityException(Dict::Format('UI:Error:ObjectCannotBeUpdated')); } @@ -495,10 +499,8 @@ class UserRightsProfile extends UserRightsAddOnAPI $oAdminProfile = MetaModel::GetObjectFromOQL("SELECT URP_Profiles WHERE name = :name", array('name' => ADMIN_PROFILE_NAME), true /*all data*/); if (is_object($oAdminProfile)) { - $oUserProfile = new URP_UserProfile(); - $oUserProfile->Set('profileid', $oAdminProfile->GetKey()); - $oUserProfile->Set('reason', 'By definition, the administrator must have the administrator profile'); - $oSet = DBObjectSet::FromObject($oUserProfile); + $oSet = new \ormLinkSet(UserLocal::class, 'profile_list', \DBObjectSet::FromScratch(\URP_UserProfile::class)); + $oSet->AddItem(MetaModel::NewObject('URP_UserProfile', ['profileid' => $oAdminProfile->GetKey(), 'reason' => 'CreateAdministrator'])); $oUser->Set('profile_list', $oSet); } $iUserId = $oUser->DBInsertNoReload(); diff --git a/tests/php-unit-tests/src/BaseTestCase/ItopDataTestCase.php b/tests/php-unit-tests/src/BaseTestCase/ItopDataTestCase.php index 1abfa234d..7b350534d 100644 --- a/tests/php-unit-tests/src/BaseTestCase/ItopDataTestCase.php +++ b/tests/php-unit-tests/src/BaseTestCase/ItopDataTestCase.php @@ -616,10 +616,9 @@ abstract class ItopDataTestCase extends ItopTestCase $sPassword = $sLogin; } - $oUserProfile = new URP_UserProfile(); - $oUserProfile->Set('profileid', $iProfileId); - $oUserProfile->Set('reason', 'UNIT Tests'); - $oSet = DBObjectSet::FromObject($oUserProfile); + $oSet = new \ormLinkSet(\UserLocal::class, 'profile_list', \DBObjectSet::FromScratch(\URP_UserProfile::class)); + $oSet->AddItem(MetaModel::NewObject('URP_UserProfile', ['profileid' => $iProfileId, 'reason' => 'UNIT Tests'])); + /** @var \UserLocal $oUser */ $oUser = $this->createObject('UserLocal', array( 'login' => $sLogin, diff --git a/tests/php-unit-tests/unitary-tests/core/UserRightsTest.php b/tests/php-unit-tests/unitary-tests/core/UserRightsTest.php index 5a743a0e8..7bc2a36c9 100644 --- a/tests/php-unit-tests/unitary-tests/core/UserRightsTest.php +++ b/tests/php-unit-tests/unitary-tests/core/UserRightsTest.php @@ -33,7 +33,7 @@ use DBObject; use DBObjectSearch; use DBObjectSet; use DeleteException; -use URP_UserProfile; +use MetaModel; use UserRights; use utils; @@ -421,10 +421,8 @@ class UserRightsTest extends ItopDataTestCase $this->AddProfileToUser($oUser, 3); // Keep only the profile 3 (remove profile 1) - $oUserProfile = new URP_UserProfile(); - $oUserProfile->Set('profileid', 3); - $oUserProfile->Set('reason', 'UNIT Tests'); - $oSet = DBObjectSet::FromObject($oUserProfile); + $oSet = new \ormLinkSet(\UserLocal::class, 'profile_list', \DBObjectSet::FromScratch(\URP_UserProfile::class)); + $oSet->AddItem(MetaModel::NewObject('URP_UserProfile', ['profileid' => 3, 'reason' => 'UNIT Tests'])); $oUser->Set('profile_list', $oSet); try { diff --git a/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-config/BulkChangeExtKeyTest.php b/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-config/BulkChangeExtKeyTest.php index f16adeb73..26c2bbe66 100644 --- a/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-config/BulkChangeExtKeyTest.php +++ b/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-config/BulkChangeExtKeyTest.php @@ -69,10 +69,8 @@ class BulkChangeExtKeyTest extends ItopDataTestCase { $sUid = $this->GetUid(); - $oUserProfile = new \URP_UserProfile(); - $oUserProfile->Set('profileid', $oProfile->GetKey()); - $oUserProfile->Set('reason', 'UNIT Tests'); - $oSet = \DBObjectSet::FromObject($oUserProfile); + $oSet = new \ormLinkSet(\UserLocal::class, 'profile_list', \DBObjectSet::FromScratch(\URP_UserProfile::class)); + $oSet->AddItem(MetaModel::NewObject('URP_UserProfile', ['profileid' => $oProfile->GetKey(), 'reason' => 'UNIT Tests'])); $oPerson = $this->CreatePerson('666', $oOrg2->GetKey()); $oUser = $this->createObject('UserLocal', array(