diff --git a/application/Espo/Core/defaults/config.php b/application/Espo/Core/defaults/config.php index e51dc7c91a..7f2259970a 100644 --- a/application/Espo/Core/defaults/config.php +++ b/application/Espo/Core/defaults/config.php @@ -113,6 +113,7 @@ return array ( 'assignmentNotificationsEntityList' => ['Meeting', 'Call', 'Task', 'Email'], "portalStreamEmailNotifications" => true, 'streamEmailNotificationsEntityList' => ['Case'], + 'streamEmailNotificationsTypeList' => ['Post', 'Status', 'EmailReceived'], 'emailMessageMaxSize' => 10, 'notificationsCheckInterval' => 10, 'disabledCountQueryEntityList' => ['Email'], diff --git a/application/Espo/Resources/i18n/en_US/Settings.json b/application/Espo/Resources/i18n/en_US/Settings.json index 18d77bb7b2..b598a66063 100644 --- a/application/Espo/Resources/i18n/en_US/Settings.json +++ b/application/Espo/Resources/i18n/en_US/Settings.json @@ -61,6 +61,7 @@ "streamEmailNotifications": "Notifications about updates in Stream for internal users", "portalStreamEmailNotifications": "Notifications about updates in Stream for portal users", "streamEmailNotificationsEntityList": "Stream email notifications scopes", + "streamEmailNotificationsTypeList": "What to notify about", "b2cMode": "B2C Mode", "avatarsDisabled": "Disable Avatars", "followCreatedEntities": "Follow created records", @@ -103,6 +104,11 @@ "currencyFormat": { "1": "10 USD", "2": "$10" + }, + "streamEmailNotificationsTypeList": { + "Post": "Posts", + "Status": "Status updates", + "EmailReceived": "Received emails" } }, "tooltips": { @@ -140,7 +146,7 @@ "aclStrictMode": "Enabled: Access to scopes will be forbidden if it's not specified in roles.\n\nDisabled: Access to scopes will be allowed if it's not specified in roles.", "aclAllowDeleteCreated": "Users will be able to remove records they created even if they don't have a delete access.", "textFilterUseContainsForVarchar": "If not checked then 'starts with' operator is used. You can use the wildcard '%'.", - "streamEmailNotificationsEntityList": "Email notifications about stream updates of followed records.", + "streamEmailNotificationsEntityList": "Email notifications about stream updates of followed records. Users will receive email notifications only for specified entity types.", "authTokenPreventConcurrent": "Users won't be able to be logged in on multiple devices simultaneously." }, "labels": { diff --git a/application/Espo/Resources/layouts/Settings/notifications.json b/application/Espo/Resources/layouts/Settings/notifications.json index 14d01d7ed2..58d2936061 100644 --- a/application/Espo/Resources/layouts/Settings/notifications.json +++ b/application/Espo/Resources/layouts/Settings/notifications.json @@ -12,7 +12,7 @@ [{"name": "assignmentEmailNotifications"}, {"name": "mentionEmailNotifications"}], [{"name": "assignmentEmailNotificationsEntityList"}, false], [{"name": "streamEmailNotifications"}, {"name": "portalStreamEmailNotifications"}], - [{"name": "streamEmailNotificationsEntityList"}, false] + [{"name": "streamEmailNotificationsEntityList"}, {"name": "streamEmailNotificationsTypeList"}] ] }, { diff --git a/application/Espo/Resources/metadata/entityDefs/Settings.json b/application/Espo/Resources/metadata/entityDefs/Settings.json index 01df367d37..d45e968502 100644 --- a/application/Espo/Resources/metadata/entityDefs/Settings.json +++ b/application/Espo/Resources/metadata/entityDefs/Settings.json @@ -303,6 +303,10 @@ "view": "views/settings/fields/stream-email-notifications-entity-list", "tooltip": true }, + "streamEmailNotificationsTypeList": { + "type": "multiEnum", + "options": ["Post", "Status", "EmailReceived"] + }, "b2cMode": { "type": "bool", "default": false, diff --git a/application/Espo/Services/EmailNotification.php b/application/Espo/Services/EmailNotification.php index d7c39e8c62..93bec04a21 100644 --- a/application/Espo/Services/EmailNotification.php +++ b/application/Espo/Services/EmailNotification.php @@ -49,12 +49,11 @@ class EmailNotification extends \Espo\Core\Services\Base 'fileManager', 'selectManagerFactory', 'templateFileManager', - 'injectableFactory' + 'injectableFactory', + 'config' ]); } - protected $noteNotificationTypeList = ['Post', 'Status', 'EmailReceived']; - protected $emailNotificationEntityHandlerHash = array(); protected function getMailSender() @@ -77,6 +76,11 @@ class EmailNotification extends \Espo\Core\Services\Base return $this->getInjection('dateTime'); } + protected function getConfig() + { + return $this->getInjection('config'); + } + protected function getTemplateFileManager() { return $this->getInjection('templateFileManager'); @@ -227,6 +231,8 @@ class EmailNotification extends \Espo\Core\Services\Base protected function getNotificationSelectParamsNote() { + $noteNotificationTypeList = $this->getConfig()->get('streamEmailNotificationsTypeList', []); + $selectManager = $this->getInjection('selectManagerFactory')->create('Notification'); $selectParams = $selectManager->getEmptySelectParams(); @@ -236,7 +242,7 @@ class EmailNotification extends \Espo\Core\Services\Base $selectParams['customJoin'] .= ' JOIN note ON notification.related_id = note.id'; - $selectParams['whereClause']['note.type'] = $this->noteNotificationTypeList; + $selectParams['whereClause']['note.type'] = $noteNotificationTypeList; $entityList = $this->getConfig()->get('streamEmailNotificationsEntityList'); @@ -346,7 +352,10 @@ class EmailNotification extends \Espo\Core\Services\Base $note = $this->getEntityManager()->getEntity('Note', $notification->get('relatedId')); if (!$note) return; - if (!in_array($note->get('type'), $this->noteNotificationTypeList)) return; + + $noteNotificationTypeList = $this->getConfig()->get('streamEmailNotificationsTypeList', []); + + if (!in_array($note->get('type'), $noteNotificationTypeList)) return; if (!$notification->get('userId')) return; $userId = $notification->get('userId'); @@ -574,6 +583,13 @@ class EmailNotification extends \Espo\Core\Services\Base $parentId = $note->get('parentId'); $parentType = $note->get('parentType'); + $allowedEntityTypeList = $this->getConfig()->get('streamEmailNotificationsEmailReceivedEntityTypeList'); + if ( + is_array($allowedEntityTypeList) + && + !in_array($parentType, $allowedEntityTypeList) + ) return; + $emailAddress = $user->get('emailAddress'); if (!$emailAddress) return; diff --git a/client/src/views/admin/notifications.js b/client/src/views/admin/notifications.js index ab3e3c8627..d129ac560b 100644 --- a/client/src/views/admin/notifications.js +++ b/client/src/views/admin/notifications.js @@ -81,8 +81,10 @@ Espo.define('views/admin/notifications', 'views/settings/record/edit', function controlStreamEmailNotificationsEntityList: function () { if (this.model.get('streamEmailNotifications') || this.model.get('portalStreamEmailNotifications')) { this.showField('streamEmailNotificationsEntityList'); + this.showField('streamEmailNotificationsTypeList'); } else { this.hideField('streamEmailNotificationsEntityList'); + this.hideField('streamEmailNotificationsTypeList'); } }