N°4720 - fix Deprecation warnings with ormLinkSet->UpdateFromCompleteList API

This commit is contained in:
odain
2025-11-03 08:37:35 +01:00
parent 775ac3df77
commit bdc8fdd02f
4 changed files with 15 additions and 18 deletions

View File

@@ -353,7 +353,11 @@ class URP_UserProfile extends UserRightsBaseClassGUI
{ {
throw new SecurityException(Dict::Format('UI:Login:Error:AccessRestricted')); 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')); 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*/); $oAdminProfile = MetaModel::GetObjectFromOQL("SELECT URP_Profiles WHERE name = :name", array('name' => ADMIN_PROFILE_NAME), true /*all data*/);
if (is_object($oAdminProfile)) if (is_object($oAdminProfile))
{ {
$oUserProfile = new URP_UserProfile(); $oSet = new \ormLinkSet(UserLocal::class, 'profile_list', \DBObjectSet::FromScratch(\URP_UserProfile::class));
$oUserProfile->Set('profileid', $oAdminProfile->GetKey()); $oSet->AddItem(MetaModel::NewObject('URP_UserProfile', ['profileid' => $oAdminProfile->GetKey(), 'reason' => 'CreateAdministrator']));
$oUserProfile->Set('reason', 'By definition, the administrator must have the administrator profile');
$oSet = DBObjectSet::FromObject($oUserProfile);
$oUser->Set('profile_list', $oSet); $oUser->Set('profile_list', $oSet);
} }
$iUserId = $oUser->DBInsertNoReload(); $iUserId = $oUser->DBInsertNoReload();

View File

@@ -616,10 +616,9 @@ abstract class ItopDataTestCase extends ItopTestCase
$sPassword = $sLogin; $sPassword = $sLogin;
} }
$oUserProfile = new URP_UserProfile(); $oSet = new \ormLinkSet(\UserLocal::class, 'profile_list', \DBObjectSet::FromScratch(\URP_UserProfile::class));
$oUserProfile->Set('profileid', $iProfileId); $oSet->AddItem(MetaModel::NewObject('URP_UserProfile', ['profileid' => $iProfileId, 'reason' => 'UNIT Tests']));
$oUserProfile->Set('reason', 'UNIT Tests');
$oSet = DBObjectSet::FromObject($oUserProfile);
/** @var \UserLocal $oUser */ /** @var \UserLocal $oUser */
$oUser = $this->createObject('UserLocal', array( $oUser = $this->createObject('UserLocal', array(
'login' => $sLogin, 'login' => $sLogin,

View File

@@ -33,7 +33,7 @@ use DBObject;
use DBObjectSearch; use DBObjectSearch;
use DBObjectSet; use DBObjectSet;
use DeleteException; use DeleteException;
use URP_UserProfile; use MetaModel;
use UserRights; use UserRights;
use utils; use utils;
@@ -421,10 +421,8 @@ class UserRightsTest extends ItopDataTestCase
$this->AddProfileToUser($oUser, 3); $this->AddProfileToUser($oUser, 3);
// Keep only the profile 3 (remove profile 1) // Keep only the profile 3 (remove profile 1)
$oUserProfile = new URP_UserProfile(); $oSet = new \ormLinkSet(\UserLocal::class, 'profile_list', \DBObjectSet::FromScratch(\URP_UserProfile::class));
$oUserProfile->Set('profileid', 3); $oSet->AddItem(MetaModel::NewObject('URP_UserProfile', ['profileid' => 3, 'reason' => 'UNIT Tests']));
$oUserProfile->Set('reason', 'UNIT Tests');
$oSet = DBObjectSet::FromObject($oUserProfile);
$oUser->Set('profile_list', $oSet); $oUser->Set('profile_list', $oSet);
try { try {

View File

@@ -69,10 +69,8 @@ class BulkChangeExtKeyTest extends ItopDataTestCase {
$sUid = $this->GetUid(); $sUid = $this->GetUid();
$oUserProfile = new \URP_UserProfile(); $oSet = new \ormLinkSet(\UserLocal::class, 'profile_list', \DBObjectSet::FromScratch(\URP_UserProfile::class));
$oUserProfile->Set('profileid', $oProfile->GetKey()); $oSet->AddItem(MetaModel::NewObject('URP_UserProfile', ['profileid' => $oProfile->GetKey(), 'reason' => 'UNIT Tests']));
$oUserProfile->Set('reason', 'UNIT Tests');
$oSet = \DBObjectSet::FromObject($oUserProfile);
$oPerson = $this->CreatePerson('666', $oOrg2->GetKey()); $oPerson = $this->CreatePerson('666', $oOrg2->GetKey());
$oUser = $this->createObject('UserLocal', array( $oUser = $this->createObject('UserLocal', array(