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

This commit is contained in:
Pierre Goiffon
2024-03-07 11:12:39 +01:00
11 changed files with 148 additions and 17 deletions

View File

@@ -624,7 +624,7 @@ class WebPage implements Page
break;
case static::ENUM_RESOURCE_TYPE_CSS:
$this->a_linked_stylesheets[$sFileAbsURI] = $sFileAbsURI;
$this->a_linked_stylesheets[$sFileAbsURI] = ['link' => $sFileAbsURI, 'condition' => ''];
break;
}
}

View File

@@ -11,6 +11,7 @@ use Combodo\iTop\Application\UI\Base\Component\Input\Set\SetUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\Panel\Panel;
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
use Combodo\iTop\Application\WebPage\iTopWebPage;
use Combodo\iTop\Core\Trigger\Enum\SubscriptionPolicy;
use Combodo\iTop\Renderer\BlockRenderer;
use Combodo\iTop\Service\Notification\NotificationsRepository;
use Combodo\iTop\Service\Router\Router;
@@ -82,7 +83,7 @@ class NotificationsCenterController extends Controller
// Add the action notification to the list of actions notifications for the trigger
$oActionsNotificationsByTrigger[$iTriggerId][] = $oSubscribedActionNotification;
// Add the subscribed status to the list of subscribed actions notifications for the trigger
$aSubscribedActionsNotificationsByTrigger[$iTriggerId][$oSubscribedActionNotification->GetKey()] = $oLnkActionsNotifications->Get('subscribed') || $oTrigger->Get('subscription_policy') === 'force_all_channels';
$aSubscribedActionsNotificationsByTrigger[$iTriggerId][$oSubscribedActionNotification->GetKey()] = $oLnkActionsNotifications->Get('subscribed') || $oTrigger->Get('subscription_policy') === SubscriptionPolicy::ForceAllChannels->value;
}
// Build table rows
@@ -155,7 +156,7 @@ class NotificationsCenterController extends Controller
$oChannelSet->SetOptionsTemplate('application/object/set/option_renderer.html.twig');
$oChannelSet->SetItemsTemplate('application/preferences/notification-center/item_renderer.html.twig');
// Disable the input set if the subscription policy is 'force_all_channels'
if($sTriggerSubscriptionPolicy === 'force_all_channels'){
if ($sTriggerSubscriptionPolicy === SubscriptionPolicy::ForceAllChannels->value) {
$oChannelSet->SetIsDisabled(true);
}
// Add a CSRF Token
@@ -190,8 +191,8 @@ $.ajax({
});
JS
);
// Set the minimum number of channels to 1 if the subscription policy is 'force_at_least_one_channel'
if($sTriggerSubscriptionPolicy === 'force_at_least_one_channel')
// Set the minimum number of channels to 1 if the subscription policy is {@see SubscriptionPolicy::ForceAtLeastOneChannel}
if($sTriggerSubscriptionPolicy === SubscriptionPolicy::ForceAtLeastOneChannel->value)
{
$oChannelSet->SetMinItems(1);
}
@@ -289,7 +290,7 @@ JS
// Add the action notification to the list of actions notifications for the trigger
$oActionsNotificationsByTrigger[$iTriggerId][] = $oSubscribedActionNotification;
// Add the subscribed status to the list of subscribed actions notifications for the trigger
$aSubscribedActionsNotificationsByTrigger[$iTriggerId][$oSubscribedActionNotification->GetKey()] = $oLnkActionsNotifications->Get('subscribed') || $oTrigger->Get('subscription_policy') === 'force_all_channels';
$aSubscribedActionsNotificationsByTrigger[$iTriggerId][$oSubscribedActionNotification->GetKey()] = $oLnkActionsNotifications->Get('subscribed') || $oTrigger->Get('subscription_policy') === SubscriptionPolicy::ForceAllChannels->value;
}
$oPage->AddTabContainer('NotificationsCenter', '', $oNotificationsPanel);
@@ -491,7 +492,7 @@ JS
throw new \Exception('Invalid trigger');
}
// Check the trigger subscription policy
if($oTrigger->Get('subscription_policy') === 'force_all_channels'){
if ($oTrigger->Get('subscription_policy') === SubscriptionPolicy::ForceAllChannels->value) {
throw new \Exception('You are not allowed to unsubscribe from this channel');
}
@@ -501,7 +502,7 @@ JS
throw new \Exception('You are not subscribed to any channel');
}
// Check the trigger subscription policy and if we are subscribed to at least 1 channel if necessary
if($oTrigger->Get('subscription_policy') === 'force_at_least_one_channel') {
if($oTrigger->Get('subscription_policy') === SubscriptionPolicy::ForceAtLeastOneChannel->value) {
$oTotalSubscribedActionsNotificationsSet = NotificationsRepository::GetInstance()->SearchSubscriptionByTriggerContactAndSubscription($iTriggerId, \UserRights::GetContactId(), '1');
if (($oTotalSubscribedActionsNotificationsSet->Count() - $oSubscribedActionsNotificationsSet->Count()) === 0) {
throw new \Exception('You can\'t unsubscribe from this channel, you must be subscribed to at least one channel');

View File

@@ -0,0 +1,16 @@
<?php
namespace Combodo\iTop\Core\Trigger\Enum;
/**
* Class SubscriptionPolicy
*
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
* @package Combodo\iTop\Core\Trigger\Enum
* @since 3.2.0
*/
enum SubscriptionPolicy: string {
case AllowNoChannel = "allow_no_channel";
case ForceAtLeastOneChannel = "force_at_least_one_channel";
case ForceAllChannels = "force_all_channels";
}

View File

@@ -3,6 +3,7 @@ namespace Combodo\iTop\Service\Notification;
use ActionNotification;
use Combodo\iTop\Core\Trigger\Enum\SubscriptionPolicy;
use Contact;
use lnkActionNotificationToContact;
use Trigger;
@@ -99,7 +100,7 @@ class NotificationsService {
public function IsSubscribed(Trigger $oTrigger, ActionNotification $oActionNotification, Contact $oRecipient): bool
{
// Check if the trigger subscription policy is 'force_all_channels'
if ($oTrigger->Get('subscription_policy') === 'force_all_channels') {
if ($oTrigger->Get('subscription_policy') === SubscriptionPolicy::ForceAllChannels->value) {
return true;
}
// Check if the user is already subscribed to the action notification