Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a new option in workflow notificationSettings to ensure that notifications are also sent to inactive users. #16904

Open
wants to merge 2 commits into
base: 11.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions bundles/CoreBundle/src/DependencyInjection/Configuration.php
Expand Up @@ -1614,6 +1614,10 @@ private function addWorkflowNode(ArrayNodeDefinition $rootNode): void
->defaultValue(NotificationSubscriber::DEFAULT_MAIL_TEMPLATE_PATH)
->info('Path to mail source - either Symfony path to template or fullpath to Pimcore document. Optional use ' . NotificationEmailService::MAIL_PATH_LANGUAGE_PLACEHOLDER . ' as placeholder for language.')
->end()
->booleanNode('includeAllUsers')
->defaultFalse()
->info('Set this to true to ensure that notifications are also sent to inactive users')
->end()
->end()
->end()
->end()
Expand Down
15 changes: 9 additions & 6 deletions lib/Workflow/EventSubscriber/NotificationSubscriber.php
Expand Up @@ -81,19 +81,20 @@ public function onWorkflowCompleted(Event $event): void
if (empty($condition) || $this->expressionService->evaluateExpression($workflow, $subject, $condition)) {
$notifyUsers = $notificationSetting['notifyUsers'] ?? [];
$notifyRoles = $notificationSetting['notifyRoles'] ?? [];
$includeAllUsers = $notificationSetting['includeAllUsers'] ?? false;

if (in_array(self::NOTIFICATION_CHANNEL_MAIL, $notificationSetting['channelType'])) {
$this->handleNotifyPostWorkflowEmail($transition, $workflow, $subject, $notificationSetting['mailType'], $notificationSetting['mailPath'], $notifyUsers, $notifyRoles);
$this->handleNotifyPostWorkflowEmail($transition, $workflow, $subject, $notificationSetting['mailType'], $notificationSetting['mailPath'], $notifyUsers, $notifyRoles, $includeAllUsers);
}

if (in_array(self::NOTIFICATION_CHANNEL_PIMCORE_NOTIFICATION, $notificationSetting['channelType'])) {
$this->handleNotifyPostWorkflowPimcoreNotification($transition, $workflow, $subject, $notifyUsers, $notifyRoles);
$this->handleNotifyPostWorkflowPimcoreNotification($transition, $workflow, $subject, $notifyUsers, $notifyRoles, $includeAllUsers);
}
}
}
}

private function handleNotifyPostWorkflowEmail(Transition $transition, \Symfony\Component\Workflow\Workflow $workflow, ElementInterface $subject, string $mailType, string $mailPath, array $notifyUsers, array $notifyRoles): void
private function handleNotifyPostWorkflowEmail(Transition $transition, \Symfony\Component\Workflow\Workflow $workflow, ElementInterface $subject, string $mailType, string $mailPath, array $notifyUsers, array $notifyRoles, bool $includeAllUsers): void
{
//notify users
$subjectType = ($subject instanceof Concrete ? $subject->getClassName() : Service::getElementType($subject));
Expand All @@ -106,11 +107,12 @@ private function handleNotifyPostWorkflowEmail(Transition $transition, \Symfony\
$subject,
$transition->getLabel(),
$mailType,
$mailPath
$mailPath,
$includeAllUsers
);
}

private function handleNotifyPostWorkflowPimcoreNotification(Transition $transition, \Symfony\Component\Workflow\Workflow $workflow, ElementInterface $subject, array $notifyUsers, array $notifyRoles): void
private function handleNotifyPostWorkflowPimcoreNotification(Transition $transition, \Symfony\Component\Workflow\Workflow $workflow, ElementInterface $subject, array $notifyUsers, array $notifyRoles, bool $includeAllUsers): void
{
$subjectType = ($subject instanceof Concrete ? $subject->getClassName() : Service::getElementType($subject));
$this->pimcoreNotificationService->sendPimcoreNotification(
Expand All @@ -119,7 +121,8 @@ private function handleNotifyPostWorkflowPimcoreNotification(Transition $transit
$workflow,
$subjectType,
$subject,
$transition->getLabel()
$transition->getLabel(),
$includeAllUsers
);
}

Expand Down
13 changes: 9 additions & 4 deletions lib/Workflow/Notification/AbstractNotificationService.php
Expand Up @@ -46,7 +46,7 @@ protected function getNoteInfo(int $id): string
*
* @return User[][]
*/
protected function getNotificationUsersByName(array $users, array $roles, bool $includeAllUsers = false): array
protected function getNotificationUsersByName(array $users, array $roles, bool $includeAllUsers): array
{
$notifyUsers = [];

Expand All @@ -57,7 +57,12 @@ protected function getNotificationUsersByName(array $users, array $roles, bool $

foreach ($roleList->load() as $role) {
$userList = new User\Listing();
$userList->setCondition('FIND_IN_SET(?, roles) > 0', [$role->getId()]);

if ($includeAllUsers) {
$userList->setCondition('FIND_IN_SET(?, roles) > 0', [$role->getId()]);
} else {
$userList->setCondition('FIND_IN_SET(?, roles) > 0 and email is not null AND active = ?', [$role->getId()]);
}

foreach ($userList->load() as $user) {
if ($includeAllUsers || $user->getEmail()) {
Expand All @@ -71,10 +76,10 @@ protected function getNotificationUsersByName(array $users, array $roles, bool $
//get users
$userList = new User\Listing();
if ($includeAllUsers) {
$userList->setCondition('name IN ('.implode(',', array_map([Db::get(), 'quote'], $users)).')');
$userList->setCondition('name IN ('.implode(',', array_map([Db::get(), 'quote'], $users)).')', [$includeAllUsers]);
} else {
$userList->setCondition(
'name IN ('.implode(',', array_map([Db::get(), 'quote'], $users)).') and email is not null'
'name IN ('.implode(',', array_map([Db::get(), 'quote'], $users)).') and email is not null AND active = ?', [$includeAllUsers]
);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Workflow/Notification/NotificationEmailService.php
Expand Up @@ -48,10 +48,10 @@ public function __construct(EngineInterface $template, RouterInterface $router,
* Sends an Mail
*
*/
public function sendWorkflowEmailNotification(array $users, array $roles, Workflow $workflow, string $subjectType, ElementInterface $subject, string $action, string $mailType, string $mailPath): void
public function sendWorkflowEmailNotification(array $users, array $roles, Workflow $workflow, string $subjectType, ElementInterface $subject, string $action, string $mailType, string $mailPath, bool $includeAllUsers): void
{
try {
$recipients = $this->getNotificationUsersByName($users, $roles);
$recipients = $this->getNotificationUsersByName($users, $roles, $includeAllUsers);
if (!count($recipients)) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Workflow/Notification/PimcoreNotificationService.php
Expand Up @@ -37,10 +37,10 @@ public function __construct(NotificationService $notificationService, Translator
$this->translator = $translator;
}

public function sendPimcoreNotification(array $users, array $roles, Workflow $workflow, string $subjectType, ElementInterface $subject, string $action): void
public function sendPimcoreNotification(array $users, array $roles, Workflow $workflow, string $subjectType, ElementInterface $subject, string $action, bool $includeAllUsers): void
{
try {
$recipients = $this->getNotificationUsersByName($users, $roles, true);
$recipients = $this->getNotificationUsersByName($users, $roles, $includeAllUsers);
if (!count($recipients)) {
return;
}
Expand Down