diff --git a/application/Espo/Core/Acl/Table.php b/application/Espo/Core/Acl/Table.php index 1f85abba2b..a920452c18 100644 --- a/application/Espo/Core/Acl/Table.php +++ b/application/Espo/Core/Acl/Table.php @@ -207,6 +207,7 @@ class Table $this->applyDefault($aclTable, $fieldTable); $this->applyDisabled($aclTable, $fieldTable); $this->applyMandatory($aclTable, $fieldTable); + $this->applyAdditional($aclTable, $fieldTable, $valuePermissionLists); } else { $aclTable = (object) []; foreach ($this->getScopeList() as $scope) { @@ -524,6 +525,19 @@ class Table } } + protected function applyAdditional(&$table, &$fieldTable, &$valuePermissionLists) + { + if ($this->getUser()->get('isPortalUser')) { + foreach ($this->getScopeList() as $scope) { + $table->$scope = false; + unset($fieldTable->$scope); + } + foreach ($this->valuePermissionList as $permission) { + $valuePermissionLists->{$permission}[] = 'no'; + } + } + } + private function mergeValueList(array $list, $defaultValue) { $result = null; diff --git a/application/Espo/Core/AclPortal/Table.php b/application/Espo/Core/AclPortal/Table.php index 4ccadcd2aa..549173b85a 100644 --- a/application/Espo/Core/AclPortal/Table.php +++ b/application/Espo/Core/AclPortal/Table.php @@ -127,5 +127,9 @@ class Table extends \Espo\Core\Acl\Table } } } + + protected function applyAdditional(&$table, &$fieldTable, &$valuePermissionLists) + { + } } diff --git a/application/Espo/Repositories/Preferences.php b/application/Espo/Repositories/Preferences.php index 6a54251c40..2fe2a914c0 100644 --- a/application/Espo/Repositories/Preferences.php +++ b/application/Espo/Repositories/Preferences.php @@ -118,8 +118,10 @@ class Preferences extends \Espo\Core\ORM\Repository $entity->set($this->data[$id]); + $this->fetchAutoFollowEntityTypeList($entity); + $entity->setAsFetched($this->data[$id]); $d = $entity->toArray(); @@ -152,8 +154,6 @@ class Preferences extends \Espo\Core\ORM\Repository { $id = $entity->id; - $isChanged = false; - $was = $entity->getFetched('autoFollowEntityTypeList'); $became = $entity->get('autoFollowEntityTypeList'); @@ -200,7 +200,10 @@ class Preferences extends \Espo\Core\ORM\Repository $fileName = $this->getFilePath($entity->id); $this->getFileManager()->putContents($fileName, Json::encode($data, \JSON_PRETTY_PRINT)); - $this->storeAutoFollowEntityTypeList($entity); + $user = $this->getEntityManger()->getEntity('User', $entity->id); + if ($user && !$user->get('isPortalUser')) { + $this->storeAutoFollowEntityTypeList($entity); + } return $entity; } diff --git a/application/Espo/Resources/metadata/app/aclPortal.json b/application/Espo/Resources/metadata/app/aclPortal.json index 82312340c5..d1d989f85e 100644 --- a/application/Espo/Resources/metadata/app/aclPortal.json +++ b/application/Espo/Resources/metadata/app/aclPortal.json @@ -53,7 +53,8 @@ "smtpPassword": false, "smtpAuth": false, "receiveAssignmentEmailNotifications": false, - "defaultReminders": false + "defaultReminders": false, + "autoFollowEntityTypeList": false }, "Call": { "reminders": false diff --git a/application/Espo/Services/Notification.php b/application/Espo/Services/Notification.php index b54f727f17..e8a4353ea8 100644 --- a/application/Espo/Services/Notification.php +++ b/application/Espo/Services/Notification.php @@ -81,13 +81,13 @@ class Notification extends \Espo\Services\Record $sql = "INSERT INTO `notification` (`id`, `data`, `type`, `user_id`, `created_at`, `related_id`, `related_type`, `related_parent_id`, `related_parent_type`) VALUES "; $arr = []; - foreach ($userIdList as $userId) { - if (empty($userId)) continue; - $user = $this->getEntityManager()->getEntity('User'); - $user->id = $userId; - $user->setIsNew(false); - $user->setAsFetched(); + $userList = $this->getEntityManager()->getRepository('User')->where(array( + 'isActive' => true, + 'id' => $userIdList + ))->find(); + foreach ($userList as $user) { + $userId = $user->id; if (!$this->checkUserNoteAccess($user, $note)) { continue; } @@ -105,11 +105,16 @@ class Notification extends \Espo\Services\Record public function checkUserNoteAccess(\Espo\Entities\User $user, \Espo\Entities\Note $note) { - if (in_array($note->get('type'), ['EmailSent', 'EmailReceived'])) { - if (!$this->getAclManager()->checkScope($user, 'Email')) { + if ($user->get('isPortalUser')) { + if ($note->get('relatedType')) { + if ($note->get('relatedType') === 'Email' && $note->get('parentType') === 'Case') { + return true; + } return false; } + return true; } + if ($note->get('relatedType')) { if (!$this->getAclManager()->checkScope($user, $note->get('relatedType'))) { return false;