diff --git a/core/datamodel.core.xml b/core/datamodel.core.xml
index 136c8dd96..c75b780b4 100644
--- a/core/datamodel.core.xml
+++ b/core/datamodel.core.xml
@@ -157,6 +157,13 @@
4
false
+
+ test_recipient_id
+
+ true
+ Person
+ DEL_MANUAL
+
recipients
@@ -214,12 +221,15 @@
-
20
- -
+
-
30
- -
+
-
40
+ -
+ 50
+
@@ -262,16 +272,14 @@
Get('recipients'));
- $oRecipientsSearch->AllowAllData();
- $oRecipientsSet = new DBObjectSet($oRecipientsSearch, array(), $aContextArgs);
+ $aRecipientsIds = [];
+ $oPotentialRecipientsSearch = DBObjectSearch::FromOQL($this->Get('recipients'));
+ $oPotentialRecipientsSearch->AllowAllData();
+ $oPotentialRecipientsSet = new DBObjectSet($oPotentialRecipientsSearch, array(), $aContextArgs);
+
$bIsAsync = $this->IsAsynchronous();
[$sPreviousLanguage, $aPreviousPluginProperties] = $this->SetNotificationLanguage();
-
- if($bIsAsync === true){
- $aRecipients = [];
- }
-
+
$sMessage = MetaModel::ApplyParams($this->Get('message'), $aContextArgs);
$sTitle = MetaModel::ApplyParams($this->Get('title'), $aContextArgs);
$sUrl = MetaModel::ApplyParams($this->Get('url'), $aContextArgs);
@@ -281,51 +289,63 @@
$iObjectId = $aContextArgs['this->object()']->GetKey();
$sObjectClass = get_class($aContextArgs['this->object()']);
}
-
- while ($oRecipient = $oRecipientsSet->Fetch()) {
- // Skip recipients that have no users
- if ($oRecipient instanceof Person && UserRights::GetUserFromPerson($oRecipient, false) === null) {
- continue;
- }
- // Skip recipient that have no user with access to the backoffice
- $oRecipientUsersSearch = DBObjectSearch::FromOQL("SELECT User WHERE contactid = " . $oRecipient->GetKey() . " AND status = 'enabled'");
- $oRecipientUsersSearch->AllowAllData();
- $oRecipientUsersSet = new DBObjectSet($oRecipientUsersSearch);
- $oPortalDispatcher = new PortalDispatcher('backoffice');
- // - Check if the user has access to the backoffice
- $bHasAccessToBackoffice = false;
- while ($oRecipientUser = $oRecipientUsersSet->Fetch()) {
- // Skip recipients with user that don't have access to the backoffice
- if (false === $oPortalDispatcher->IsUserAllowed($oRecipientUser)) {
- continue;
- }
-
- $bHasAccessToBackoffice = true;
- break;
- }
- // - Skip it if necessary
- if (false === $bHasAccessToBackoffice) {
- continue;
+ if ($this->IsBeingTested()) {
+ // If action is being tested, send notification to the test recipient only, no matter what (unsubscribed, disabled, no access to the backoffice, ...)
+ $iTestRecipientId = $this->Get('test_recipient_id');
+ if ($iTestRecipientId > 0) {
+ $aRecipientsIds[] = $iTestRecipientId;
}
+ } else {
+ // Otherwise, find the recipients to which we can actually send the notification among all the potential ones
+ while ($oPotentialRecipient = $oPotentialRecipientsSet->Fetch()) {
+ // Skip recipients that have no users
+ if ($oPotentialRecipient instanceof Person && UserRights::GetUserFromPerson($oPotentialRecipient, false) === null) {
+ continue;
+ }
- // Skip recipients that have unsubscribed
- if (!\Combodo\iTop\Service\Notification\NotificationsService::GetInstance()->IsSubscribed($oTrigger, $this, $oRecipient)) {
- continue;
- }
-
- if($bIsAsync === true) {
- $aRecipients[] = $oRecipient->GetKey();
- } else {
- $oEvent = Combodo\iTop\Service\Notification\Event\EventNotificationNewsroomService::MakeEventFromAction($this, $oRecipient->GetKey(), $oTrigger->GetKey(), $sMessage, $sTitle, $sUrl, $iObjectId, $sObjectClass);
- $oEvent->DBInsertNoReload();
+ // Skip potential recipient that have no user with access to the backoffice
+ $oPotentialRecipientUsersSearch = DBObjectSearch::FromOQL("SELECT User WHERE contactid = " . $oPotentialRecipient->GetKey() . " AND status = 'enabled'");
+ $oPotentialRecipientUsersSearch->AllowAllData();
+ $oPotentialRecipientUsersSet = new DBObjectSet($oPotentialRecipientUsersSearch);
+ $oPortalDispatcher = new PortalDispatcher('backoffice');
+ // - Check if the user has access to the backoffice
+ $bHasAccessToBackoffice = false;
+ while ($oPotentialRecipientUser = $oPotentialRecipientUsersSet->Fetch()) {
+ // Skip potential recipients with user that don't have access to the backoffice
+ if (false === $oPortalDispatcher->IsUserAllowed($oPotentialRecipientUser)) {
+ continue;
+ }
+
+ $bHasAccessToBackoffice = true;
+ break;
+ }
+ // - Skip it if necessary
+ if (false === $bHasAccessToBackoffice) {
+ continue;
+ }
+
+ // Skip potential recipients that have unsubscribed
+ if (!\Combodo\iTop\Service\Notification\NotificationsService::GetInstance()->IsSubscribed($oTrigger, $this, $oPotentialRecipient)) {
+ continue;
+ }
+
+ $aRecipientsIds[] = $oPotentialRecipient->GetKey();
+
+ // Register subscription even though the notification is not sent yet
+ \Combodo\iTop\Service\Notification\NotificationsService::GetInstance()->RegisterSubscription($oTrigger, $this, $oPotentialRecipient);
}
-
- \Combodo\iTop\Service\Notification\NotificationsService::GetInstance()->RegisterSubscription($oTrigger, $this, $oRecipient);
- }
- if ($bIsAsync === true) {
- AsyncSendiTopNotifications::AddToQueue($this->GetKey(), $oTrigger->GetKey(), $aRecipients, $sMessage, $sTitle, $sUrl, $iObjectId, $sObjectClass);
}
+
+ if ($bIsAsync === true) {
+ AsyncSendNewsroom::AddToQueue($this->GetKey(), $oTrigger->GetKey(), $aRecipientsIds, $sMessage, $sTitle, $sUrl, $iObjectId, $sObjectClass);
+ } else {
+ foreach ($aRecipientsIds as $iRecipientId) {
+ $oEvent = Combodo\iTop\Service\Notification\Event\EventNotificationNewsroomService::MakeEventFromAction($this, $iRecipientId, $oTrigger->GetKey(), $sMessage, $sTitle, $sUrl, $iObjectId, $sObjectClass);
+ $oEvent->DBInsertNoReload();
+ }
+ }
+
$this->SetNotificationLanguage($sPreviousLanguage, $aPreviousPluginProperties['language_code'] ?? null);
}
]]>
diff --git a/dictionaries/en.dictionary.itop.core.php b/dictionaries/en.dictionary.itop.core.php
index e75a20360..6e0d72daa 100644
--- a/dictionaries/en.dictionary.itop.core.php
+++ b/dictionaries/en.dictionary.itop.core.php
@@ -661,6 +661,8 @@ Dict::Add('EN US', 'English', 'English', array(
'Class:ActionNewsroom/Attribute:priority/Value:3+' => 'Important',
'Class:ActionNewsroom/Attribute:priority/Value:4' => 'Standard',
'Class:ActionNewsroom/Attribute:priority/Value:4+' => 'Standard',
+ 'Class:ActionNewsroom/Attribute:test_recipient_id' => 'Test recipient',
+ 'Class:ActionNewsroom/Attribute:test_recipient_id+' => 'Person used instead of Recipients when notification is being tested',
'Class:ActionNewsroom/Attribute:recipients' => 'Recipients',
'Class:ActionNewsroom/Attribute:recipients+' => '',
'Class:ActionNewsroom/Attribute:url' => 'URL',
diff --git a/dictionaries/fr.dictionary.itop.core.php b/dictionaries/fr.dictionary.itop.core.php
index a65d5a699..017af1323 100644
--- a/dictionaries/fr.dictionary.itop.core.php
+++ b/dictionaries/fr.dictionary.itop.core.php
@@ -610,6 +610,8 @@ Dict::Add('FR FR', 'French', 'Français', array(
'Class:ActionNewsroom/Attribute:priority/Value:3+' => 'Important',
'Class:ActionNewsroom/Attribute:priority/Value:4' => 'Standard',
'Class:ActionNewsroom/Attribute:priority/Value:4+' => 'Standard',
+ 'Class:ActionNewsroom/Attribute:test_recipient_id' => 'Destinataire de test',
+ 'Class:ActionNewsroom/Attribute:test_recipient_id+' => 'Personne utilisée en remplacement des Destinataires, lorsque la notification est \'En test\'',
'Class:ActionNewsroom/Attribute:recipients' => 'Destinataires',
'Class:ActionNewsroom/Attribute:recipients+' => '',
'Class:ActionNewsroom/Attribute:url' => 'URL',