diff --git a/application/Espo/Hooks/Note/Notifications.php b/application/Espo/Hooks/Note/Notifications.php index 76f3f0f43c..ec81a055d3 100644 --- a/application/Espo/Hooks/Note/Notifications.php +++ b/application/Espo/Hooks/Note/Notifications.php @@ -60,13 +60,26 @@ class Notifications extends \Espo\Core\Hooks\Base return $mentionedUserList; } - protected function getSubscriberIdList($parentType, $parentId) + protected function getSubscriberIdList($parentType, $parentId, $isInternal = false) { $pdo = $this->getEntityManager()->getPDO(); - $sql = " - SELECT user_id AS userId - FROM subscription - WHERE entity_id = " . $pdo->quote($parentId) . " AND entity_type = " . $pdo->quote($parentType); + + if (!$isInternal) { + $sql = " + SELECT user_id AS userId + FROM subscription + WHERE entity_id = " . $pdo->quote($parentId) . " AND entity_type = " . $pdo->quote($parentType) . " + "; + } else { + $sql = " + SELECT subscription.user_id AS userId + FROM subscription + JOIN user ON user.id = subscription.user_id + WHERE + entity_id = " . $pdo->quote($parentId) . " AND entity_type = " . $pdo->quote($parentType) . " AND + user.is_portal_user = 0 + "; + } $sth = $pdo->prepare($sql); $sth->execute(); $userIdList = []; @@ -89,9 +102,9 @@ class Notifications extends \Espo\Core\Hooks\Base $userIdList = []; if ($parentType && $parentId) { - $userIdList = array_merge($userIdList, $this->getSubscriberIdList($parentType, $parentId)); + $userIdList = array_merge($userIdList, $this->getSubscriberIdList($parentType, $parentId, $entity->get('isInternal'))); if ($superParentType && $superParentId) { - $userIdList = array_merge($userIdList, $this->getSubscriberIdList($superParentType, $superParentId)); + $userIdList = array_merge($userIdList, $this->getSubscriberIdList($superParentType, $superParentId, $entity->get('isInternal'))); } } else { $targetType = $entity->get('targetType'); diff --git a/application/Espo/Modules/Crm/Resources/metadata/clientDefs/Case.json b/application/Espo/Modules/Crm/Resources/metadata/clientDefs/Case.json index 23d047d1ed..9abaae85f4 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/clientDefs/Case.json +++ b/application/Espo/Modules/Crm/Resources/metadata/clientDefs/Case.json @@ -48,5 +48,6 @@ "boolFilterList": ["onlyMy"], "selectDefaultFilters": { "filter": "open" - } + }, + "allowInternalNotes": true } diff --git a/application/Espo/Resources/i18n/en_US/Global.json b/application/Espo/Resources/i18n/en_US/Global.json index 1dbdca626b..85c9e8a27d 100644 --- a/application/Espo/Resources/i18n/en_US/Global.json +++ b/application/Espo/Resources/i18n/en_US/Global.json @@ -224,7 +224,8 @@ "writeMessageToSelf": "Write a message to self", "typeAndPressEnter": "Type & press enter", "checkForNewNotifications": "Check for new notifications", - "checkForNewNotes": "Check for new Stream entries" + "checkForNewNotes": "Check for new Stream entries", + "internalPost": "Post will be seen only by internal users" }, "boolFilters": { "onlyMy": "Only My", diff --git a/application/Espo/Resources/metadata/app/aclPortal.json b/application/Espo/Resources/metadata/app/aclPortal.json index 82312340c5..de969bcc44 100644 --- a/application/Espo/Resources/metadata/app/aclPortal.json +++ b/application/Espo/Resources/metadata/app/aclPortal.json @@ -63,6 +63,10 @@ }, "Attachment": { "parent": false + }, + "Note": { + "isInternal": false, + "isGlobal": false } } }, diff --git a/application/Espo/Resources/metadata/entityDefs/Note.json b/application/Espo/Resources/metadata/entityDefs/Note.json index 4d15836439..9545ad4ddb 100644 --- a/application/Espo/Resources/metadata/entityDefs/Note.json +++ b/application/Espo/Resources/metadata/entityDefs/Note.json @@ -50,6 +50,9 @@ "type": "jsonArray", "notStorable": true }, + "isInternal": { + "type": "bool" + }, "isToSelf": { "type": "bool" }, diff --git a/application/Espo/Services/Stream.php b/application/Espo/Services/Stream.php index 10e1849f93..177f0c9355 100644 --- a/application/Espo/Services/Stream.php +++ b/application/Espo/Services/Stream.php @@ -300,7 +300,7 @@ class Stream extends \Espo\Core\Services\Base $selectParamsList = []; - $selectParamsList[] = array( + $selectParamsSubscription = array( 'select' => $select, 'leftJoins' => ['createdBy'], 'customJoin' => " @@ -318,7 +318,15 @@ class Stream extends \Espo\Core\Services\Base 'order' => 'DESC' ); - $selectParamsList[] = array( + if ($user->get('isPortalUser')) { + $selectParamsSubscription['whereClause'][] = array( + 'isInternal' => false + ); + } + + $selectParamsList[] = $selectParamsSubscription; + + $selectParamsSubscriptionSuper = array( 'select' => $select, 'leftJoins' => ['createdBy'], 'customJoin' => " @@ -342,6 +350,14 @@ class Stream extends \Espo\Core\Services\Base 'order' => 'DESC' ); + if ($user->get('isPortalUser')) { + $selectParamsSubscriptionSuper['whereClause'][] = array( + 'isInternal' => false + ); + } + + $selectParamsList[] = $selectParamsSubscriptionSuper; + $selectParamsList[] = array( 'select' => $select, 'leftJoins' => ['createdBy'], @@ -594,6 +610,12 @@ class Stream extends \Espo\Core\Services\Base } } + if ($this->getUser()->get('isPortalUser')) { + $where[] = array( + 'isInternal' => false + ); + } + $collection = $this->getEntityManager()->getRepository('Note')->find(array( 'whereClause' => $where, 'offset' => $params['offset'], diff --git a/client/res/templates/stream/panel.tpl b/client/res/templates/stream/panel.tpl index 03de03b4e4..8facc345c3 100644 --- a/client/res/templates/stream/panel.tpl +++ b/client/res/templates/stream/panel.tpl @@ -3,6 +3,12 @@