Merge remote-tracking branch 'origin/support/3.2' into develop

This commit is contained in:
Molkobain
2024-02-22 16:08:09 +01:00
11 changed files with 53 additions and 23 deletions

View File

@@ -41,9 +41,10 @@ require_once(APPROOT.'/core/email.class.inc.php');
*/
abstract class Action extends cmdbAbstractObject
{
/** @var $oCallingTrigger Trigger|null The trigger that called this action {@see DoExecute}
/**
* @var $oCallingTrigger Trigger|null The trigger that called this action {@see DoExecute}
* @since 3.2.0
* */
*/
protected ?Trigger $oCallingTrigger = null;
/**

View File

@@ -132,7 +132,7 @@
<display_max_height>96</display_max_height>
<storage_max_width>256</storage_max_width>
<storage_max_height>256</storage_max_height>
<default_image>null</default_image>
<default_image />
</field>
<field id="priority" xsi:type="AttributeEnum">
<sql>priority</sql>
@@ -253,7 +253,7 @@
<static>false</static>
<access>public</access>
<code><![CDATA[
public function DoExecute($oTrigger, $aContextArgs)
public function DoExecute($oTrigger, $aContextArgs)
{
$oRecipientsSearch = DBObjectSearch::FromOQL($this->Get('recipients'));
$oRecipientsSearch->AllowAllData();
@@ -262,15 +262,36 @@
while ($oRecipient = $oRecipientsSet->Fetch()) {
// Skip recipients that have no users
if (get_class($oRecipient) === Person::class && UserRights::GetUserFromPerson($oRecipient) === null) {
continue;
}
continue;
}
if (!\Combodo\iTop\Service\Notification\NotificationsService::GetInstance()->IsSubscribed($oTrigger, $this, $oRecipient)) {
continue;
}
continue;
}
if (array_key_exists('this->object()', $aContextArgs)) {
$iObjectId = $aContextArgs['this->object()']->GetKey();
$sObjectClass = get_class($aContextArgs['this->object()']);
} else {
$iObjectId = 0;
$sObjectClass = null;
}
$oEvent = new EventiTopNotification();
$oEvent->Set('title', MetaModel::ApplyParams($this->Get('title'), $aContextArgs));
$oEvent->Set('message', MetaModel::ApplyParams($this->Get('message'), $aContextArgs));
$oIcon = !$this->Get('icon')->IsEmpty() ? $this->Get('icon') : MetaModel::GetAttributeDef('EventiTopNotification', 'icon')->MakeRealValue(Combodo\iTop\Application\Branding::GetCompactMainLogoAbsoluteUrl(), $oEvent);
// Compute icon
// - First check if one is defined on the action
if (false === $this->Get('icon')->IsEmpty()) {
$oIcon = $this->Get('icon');
}
// - Then, check if the action is for a DM object and if its class has an icon
elseif ($iObjectId > 0 && utils::IsNotNullOrEmptyString(MetaModel::GetClassIcon($sObjectClass, false))) {
$oIcon = MetaModel::GetAttributeDef(EventiTopNotification::class, 'icon')->MakeRealValue(MetaModel::GetClassIcon($sObjectClass, false), $oEvent);
}
// - Otherwise, fallback on the compact logo of the application
else {
$oIcon = MetaModel::GetAttributeDef(EventiTopNotification::class, 'icon')->MakeRealValue(\Combodo\iTop\Application\Branding::GetCompactMainLogoAbsoluteUrl(), $oEvent);
}
$oEvent->Set('icon', $oIcon);
$oEvent->Set('priority', $this->Get('priority'));
$oEvent->Set('contact_id', $oRecipient->GetKey());
@@ -281,7 +302,7 @@
$oEvent->Set('url', MetaModel::ApplyParams($this->Get('url'), $aContextArgs));
$oEvent->DBInsertNoReload();
\Combodo\iTop\Service\Notification\NotificationsService::GetInstance()->RegisterSubscription($oTrigger, $this, $oRecipient);
\Combodo\iTop\Service\Notification\NotificationsService::GetInstance()->RegisterSubscription($oTrigger, $this, $oRecipient);
}
$this->SetNotificationLanguage($sPreviousLanguage, $aPreviousPluginProperties['language_code'] ?? null);
}
@@ -317,7 +338,7 @@
<sql>icon</sql>
<default_value/>
<is_null_allowed>true</is_null_allowed>
<default_image>null</default_image>
<default_image />
</field>
<field id="priority" xsi:type="AttributeEnum">
<sql>priority</sql>

View File

@@ -73,7 +73,7 @@ if (!class_exists('StructureInstaller'))
SetupLog::Info("| Migrate ActionEmail language attribute values to its parent.");
$sTableToRead = MetaModel::DBGetTable('ActionEmail');
$sTableToSet = MetaModel::DBGetTable('ActionNotification');
self::MoveColumnInDB($sTableToRead, 'language', $sTableToSet, 'language');
self::MoveColumnInDB($sTableToRead, 'language', $sTableToSet, 'language', true);
SetupLog::Info("| ActionEmail migration done.");
}
// If you want to migrate data from one format to another, do it here

View File

@@ -11,6 +11,7 @@ use Combodo\iTop\Service\Router\Router;
use CoreException;
use DBObjectSearch;
use DBObjectSet;
use Dict;
use DisplayBlock;
use MetaModel;
use UserRights;

View File

@@ -105,7 +105,7 @@ class NotificationsService {
// Check if the user is already subscribed to the action notification
$oSubscribedActionsNotificationsSet = NotificationsRepository::GetInstance()->SearchSubscriptionByTriggerContactAndAction($oTrigger->GetKey(), $oRecipient->GetKey(), $oActionNotification->GetKey());
if ($oSubscribedActionsNotificationsSet->Count() === 0) {
return false;
return true;
}
// Return the subscribed status

View File

@@ -26,7 +26,7 @@ class LoginTest extends ItopDataTestCase {
@chmod($this->sConfigPath, 0770);
$oConfig->WriteToFile();
@chmod($this->sConfigPath, 0440);
@chmod($this->sConfigPath, 0444);
}
protected function tearDown(): void {
@@ -34,7 +34,7 @@ class LoginTest extends ItopDataTestCase {
//put config back
@chmod($this->sConfigPath, 0770);
file_put_contents($this->sConfigPath, file_get_contents($this->sConfigTmpBackupFile));
@chmod($this->sConfigPath, 0440);
@chmod($this->sConfigPath, 0444);
@unlink($this->sConfigTmpBackupFile);
}
parent::tearDown();

View File

@@ -58,7 +58,7 @@ class AttributeDefinitionTest extends ItopDataTestCase {
// Note: This is test is not great as we are datamodel dependent and don't have a class with all the attribute types
return [
'AttributeDateTime' => [
Change::class,
UserRequest::class,
'start_date', // no default value on this field
<<<PHP
\$oObject->Set('start_date', '2023-09-06 12:26:00');

View File

@@ -47,7 +47,7 @@ class iTopConfigParserTest extends ItopTestCase
@chmod($this->sConfigPath, 0770);
$bRenameResult = rename($this->tmpSavePath, $this->sConfigPath);
echo "Restored config file, result={$bRenameResult}";
@chmod($this->sConfigPath, 0440);
@chmod($this->sConfigPath, 0444);
}
}

View File

@@ -32,11 +32,14 @@ class DBBackupDataTest extends ItopDataTestCase
if ($bUnsafeFileException) {
$this->expectExceptionMessage("Backup: Aborting, resource '$sExtraFile'. Considered as UNSAFE because not inside the iTop directory.");
}
$aFiles = $this->InvokeNonPublicMethod('DBBackup', 'PrepareFilesToBackup', $oBackup, [APPROOT . '/conf/production/config-itop.php', $sTmpDir, true]);
$aFiles = $this->InvokeNonPublicMethod('DBBackup', 'PrepareFilesToBackup', $oBackup, [APPROOT . '/conf/'.$this->GetTestEnvironment().'/config-itop.php', $sTmpDir, true]);
SetupUtils::rrmdir($sTmpDir);
$aExpectedFiles = [
$sTmpDir . '/config-itop.php',
];
if (file_exists(APPROOT.'/data/'.$this->GetTestEnvironment().'.delta.xml')) {
$aExpectedFiles[] = $sTmpDir . '/' . 'delta.xml';
}
foreach ($aExtraFiles as $sRelFile => $bExists) {
if ($bExists) {
$aExpectedFiles[] = $sTmpDir . '/' . $sRelFile;
@@ -47,13 +50,17 @@ class DBBackupDataTest extends ItopDataTestCase
foreach ($aExtraFiles as $sExtraFile => $bExists) {
if ($bExists) {
unlink(APPROOT . '/' . $sExtraFile);
$folderPath = dirname(APPROOT . '/' . $sExtraFile);
if (is_dir($folderPath) && count(glob($folderPath . '/*')) === 0) {
rmdir($folderPath);
}
}
}
}
sort($aFiles);
sort($aExpectedFiles);
$this->assertEquals($aFiles, $aExpectedFiles);
$this->assertEquals($aExpectedFiles, $aFiles);
}
function prepareFilesToBackupProvider()

View File

@@ -161,7 +161,7 @@ class SessionHandlerTest extends ItopDataTestCase
$aJson = json_decode($sFirstContent, true);
$this->assertNotEquals(false, $aJson, 'Should return a valid json string, found: '.$sFirstContent);
$this->assertEquals($sUserId, $aJson['user_id'] ?? '', "Should report the login of the logged in user in [user_id]: $sFirstContent");
$this->assertEquals(ContextTag::TAG_REST, $aJson['context'] ?? '', "Should report the context tag(s) in [context]: $sFirstContent");
$this->assertStringContainsString(ContextTag::TAG_REST, $aJson['context'] ?? '', "Should report the context tag(s) in [context]: $sFirstContent");
$this->assertIsInt($aJson['creation_time'] ?? '', "Should report the session start timestamp in [creation_time]: $sFirstContent");
$this->assertEquals('foo_login_mode', $aJson['login_mode'] ?? '', "Should report the current login mode in [login_mode]: $sFirstContent");

View File

@@ -55,7 +55,7 @@ class CliResetSessionTest extends ItopDataTestCase
@chmod($sConfigPath, 0770);
$oConfig = new Config($this->sConfigTmpBackupFile);
$oConfig->WriteToFile($sConfigPath);
@chmod($sConfigPath, 0440);
@chmod($sConfigPath, 0444);
unlink($this->sConfigTmpBackupFile);
}
@@ -72,14 +72,14 @@ class CliResetSessionTest extends ItopDataTestCase
MetaModel::GetConfig()->SetAllowedLoginTypes($aAllowedLoginTypes);
MetaModel::GetConfig()->WriteToFile();
}
@chmod(MetaModel::GetConfig()->GetLoadedFile(), 0440);
@chmod(MetaModel::GetConfig()->GetLoadedFile(), 0444);
}
protected function SetLoginModes($aAllowedLoginTypes){
@chmod(MetaModel::GetConfig()->GetLoadedFile(), 0770);
MetaModel::GetConfig()->SetAllowedLoginTypes($aAllowedLoginTypes);
MetaModel::GetConfig()->WriteToFile();
@chmod(MetaModel::GetConfig()->GetLoadedFile(), 0440);
@chmod(MetaModel::GetConfig()->GetLoadedFile(), 0444);
}
public function RestProvider(){