diff --git a/application/Espo/Classes/Acl/Portal/AccessChecker.php b/application/Espo/Classes/Acl/Portal/AccessChecker.php new file mode 100644 index 0000000000..b9e6727fa2 --- /dev/null +++ b/application/Espo/Classes/Acl/Portal/AccessChecker.php @@ -0,0 +1,72 @@ +defaultAccessChecker = $defaultAccessChecker; + $this->aclManager = $aclManager; + } + + public function checkRead(User $user, ScopeData $data): bool + { + $level = $this->aclManager->getPermissionLevel($user, 'portal'); + + return $level === Table::LEVEL_YES; + } + + public function checkEntityRead(User $user, Entity $entity, ScopeData $data): bool + { + $level = $this->aclManager->getPermissionLevel($user, 'portal'); + + return $level === Table::LEVEL_YES; + } +} diff --git a/application/Espo/Resources/metadata/aclDefs/Portal.json b/application/Espo/Resources/metadata/aclDefs/Portal.json new file mode 100644 index 0000000000..da30526717 --- /dev/null +++ b/application/Espo/Resources/metadata/aclDefs/Portal.json @@ -0,0 +1,3 @@ +{ + "accessCheckerClassName": "Espo\\Classes\\Acl\\Portal\\AccessChecker" +} diff --git a/application/Espo/Resources/metadata/app/acl.json b/application/Espo/Resources/metadata/app/acl.json index be437ee3a8..3efaf2e2f9 100644 --- a/application/Espo/Resources/metadata/app/acl.json +++ b/application/Espo/Resources/metadata/app/acl.json @@ -116,6 +116,18 @@ "read": "all", "edit": "all", "delete": "all" + }, + "Job": { + "create": "no", + "read": "all", + "edit": "no", + "delete": "all" + }, + "Extension": { + "create": "no", + "read": "all", + "edit": "no", + "delete": "all" } } }, diff --git a/application/Espo/Services/Record.php b/application/Espo/Services/Record.php index eed13c2c97..6974c909df 100644 --- a/application/Espo/Services/Record.php +++ b/application/Espo/Services/Record.php @@ -407,7 +407,7 @@ class Record implements Crud, */ public function read(string $id): Entity { - if (!$this->acl->check($this->entityType)) { + if (!$this->acl->check($this->entityType, AclTable::ACTION_READ)) { throw new ForbiddenSilent(); } @@ -1010,7 +1010,7 @@ class Record implements Crud, */ public function create(StdClass $data): Entity { - if (!$this->acl->check($this->entityType)) { + if (!$this->acl->check($this->entityType, AclTable::ACTION_CREATE)) { throw new ForbiddenSilent(); } @@ -1059,7 +1059,7 @@ class Record implements Crud, */ public function update(string $id, StdClass $data): Entity { - if (!$this->acl->check($this->entityType)) { + if (!$this->acl->check($this->entityType, AclTable::ACTION_EDIT)) { throw new ForbiddenSilent(); } @@ -1140,7 +1140,10 @@ class Record implements Crud, public function delete(string $id): void { - if (!$this->acl->check($this->entityType)) { + if ( + !$this->acl->check($this->entityType, AclTable::ACTION_DELETE) && + !$this->acl->check($this->entityType, AclTable::ACTION_EDIT) + ) { throw new ForbiddenSilent(); } @@ -1199,7 +1202,7 @@ class Record implements Crud, */ public function find(array $params): RecordCollection { - if (!$this->acl->check($this->entityType)) { + if (!$this->acl->check($this->entityType, AclTable::ACTION_READ)) { throw new ForbiddenSilent(); } @@ -1331,7 +1334,7 @@ class Record implements Crud, */ public function findLinked(string $id, string $link, array $params): RecordCollection { - if (!$this->acl->check($this->entityType)) { + if (!$this->acl->check($this->entityType, AclTable::ACTION_READ)) { throw new ForbiddenSilent("No access."); } @@ -1502,10 +1505,9 @@ class Record implements Crud, if (!$this->acl->check($entity, AclTable::ACTION_READ)) { throw new Forbidden(); } - } else { - if (!$this->acl->check($entity, AclTable::ACTION_EDIT)) { - throw new Forbidden(); - } + } + else if (!$this->acl->check($entity, AclTable::ACTION_EDIT)) { + throw new Forbidden(); } $methodName = 'link' . ucfirst($link); @@ -1627,7 +1629,7 @@ class Record implements Crud, public function linkFollowers(string $id, string $foreignId): void { - if (!$this->acl->check($this->entityType)) { + if (!$this->acl->check($this->entityType, AclTable::ACTION_EDIT)) { throw new Forbidden(); } @@ -1680,7 +1682,7 @@ class Record implements Crud, public function unlinkFollowers(string $id, string $foreignId): void { - if (!$this->acl->check($this->entityType)) { + if (!$this->acl->check($this->entityType, AclTable::ACTION_EDIT)) { throw new Forbidden(); } @@ -1729,7 +1731,7 @@ class Record implements Crud, public function massLink(string $id, string $link, array $where, ?array $selectData = null) { - if (!$this->acl->check($this->entityType)) { + if (!$this->acl->check($this->entityType, AclTable::ACTION_EDIT)) { throw new Forbidden(); } @@ -1881,7 +1883,7 @@ class Record implements Crud, */ public function follow(string $id, ?string $userId = null) { - if (!$this->acl->check($this->entityType)) { + if (!$this->acl->check($this->entityType, AclTable::ACTION_STREAM)) { throw new Forbidden(); } @@ -2066,6 +2068,10 @@ class Record implements Crud, */ public function merge(string $id, array $sourceIdList, StdClass $data): void { + if (!$this->acl->check($this->entityType, AclTable::ACTION_EDIT)) { + throw new Forbidden("No edit access."); + } + if (!$id) { throw new Error("No ID passed."); } diff --git a/application/Espo/Tools/Kanban/KanbanService.php b/application/Espo/Tools/Kanban/KanbanService.php index 208842ec94..0abe687319 100644 --- a/application/Espo/Tools/Kanban/KanbanService.php +++ b/application/Espo/Tools/Kanban/KanbanService.php @@ -35,6 +35,7 @@ use Espo\Core\{ Utils\Config, Utils\Metadata, Exceptions\ForbiddenSilent, + Acl\Table, }; use Espo\Entities\User; @@ -123,7 +124,7 @@ class KanbanService throw new Forbidden("Non-object entitis are not supported."); } - if (!$this->aclManager->check($this->user, $entityType, 'read')) { + if (!$this->aclManager->check($this->user, $entityType, Table::ACTION_READ)) { throw new ForbiddenSilent(); } }