From f7bbbbbe8735490182dbf719235ca0a9b86330bf Mon Sep 17 00:00:00 2001 From: Molkobain Date: Tue, 30 Apr 2024 11:26:42 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B02039=20-=20Send=20news=20only=20to=20Per?= =?UTF-8?q?son=20with=20at=20least=201=20active=20user=20which=20has=20acc?= =?UTF-8?q?ess=20to=20the=20backoffice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/portaldispatcher.class.inc.php | 12 ++++++++--- core/datamodel.core.xml | 23 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/application/portaldispatcher.class.inc.php b/application/portaldispatcher.class.inc.php index ce71cfec2..432091717 100644 --- a/application/portaldispatcher.class.inc.php +++ b/application/portaldispatcher.class.inc.php @@ -9,11 +9,17 @@ class PortalDispatcher $this->sPortalid = $sPortalId; $this->aData = PortalDispatcherData::GetData($sPortalId); } - - public function IsUserAllowed() + + /** + * @param \User|null $oUser + * + * @return bool + * @since 3.2.0 N°2039 Add $oUser parameter + */ + public function IsUserAllowed(?User $oUser = null) { $bRet = true; - $aProfiles = UserRights::ListProfiles(); + $aProfiles = UserRights::ListProfiles($oUser); foreach($this->aData['deny'] as $sDeniedProfile) { diff --git a/core/datamodel.core.xml b/core/datamodel.core.xml index 533ef8af8..820928a7c 100644 --- a/core/datamodel.core.xml +++ b/core/datamodel.core.xml @@ -287,6 +287,29 @@ 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; + } + + // Skip recipients that have unsubscribed if (!\Combodo\iTop\Service\Notification\NotificationsService::GetInstance()->IsSubscribed($oTrigger, $this, $oRecipient)) { continue; }