Skip to content

EspoCRM – Open Source CRM Application

Acl table fallback fix

Yurii8c0c81c55afe
diff --git a/application/Espo/Core/Acl/Table/DefaultTable.php b/application/Espo/Core/Acl/Table/DefaultTable.php
index 8c3aae51ed..6f128e3ad8 100644
--- a/application/Espo/Core/Acl/Table/DefaultTable.php
+++ b/application/Espo/Core/Acl/Table/DefaultTable.php
@@ -617,16 +617,20 @@ class DefaultTable implements Table
continue;
}
+ if (isset($data->$scope->$action)) {
+ continue;
+ }
+
+ $data->$scope->$action = self::LEVEL_NO;
+
+ // @todo Remove everything below. In v10.1.
if ($i === 0) {
continue;
}
- // @todo Remove everything below.
$previousAction = $this->actionList[$i - 1];
- if (in_array($action, $this->booleanActionList)) {
- $data->$scope->$action = self::LEVEL_YES;
- } else if ($action === self::ACTION_STREAM && isset($data->$scope->$previousAction)) {
+ if ($action === self::ACTION_STREAM && isset($data->$scope->$previousAction)) {
$data->$scope->$action = $data->$scope->$previousAction;
}
}
diff --git a/tests/integration/Espo/Core/Acl/AclTest.php b/tests/integration/Espo/Core/Acl/AclTest.php
index e4f6a2a1ec..a6dc34b1de 100644
--- a/tests/integration/Espo/Core/Acl/AclTest.php
+++ b/tests/integration/Espo/Core/Acl/AclTest.php
@@ -31,6 +31,8 @@ namespace tests\integration\Espo\Core\Acl;
use Espo\Core\AclManager;
use Espo\Core\Acl;
+use Espo\Core\Field\LinkMultiple;
+use Espo\Entities\Role;
use Espo\Entities\User;
use Espo\Modules\Crm\Entities\Account;
use Espo\Modules\Crm\Entities\Call;
@@ -173,4 +175,53 @@ class AclTest extends BaseTestCase
$this->assertFalse($acl->checkLink('Account', 'opportunities'));
}
+
+ public function testMultipleRoles(): void
+ {
+ $em = $this->getEntityManager();
+
+ $role1 = $em->getRDBRepositoryByClass(Role::class)->getNew();
+ $role1->setRawData([
+ 'Lead' => [
+ Acl\Table::ACTION_CREATE => Acl\Table::LEVEL_YES,
+ ],
+ 'Opportunity' => [
+ Acl\Table::ACTION_EDIT => Acl\Table::LEVEL_NO,
+ ],
+ 'Account' => [
+ Acl\Table::ACTION_CREATE => Acl\Table::LEVEL_NO,
+ ],
+ ]);
+ $em->saveEntity($role1);
+
+ $role2 = $em->getRDBRepositoryByClass(Role::class)->getNew();
+ $role2->setRawData([
+ 'Lead' => [
+ Acl\Table::ACTION_EDIT => Acl\Table::LEVEL_NO,
+ ],
+ 'Opportunity' => [
+ Acl\Table::ACTION_CREATE => Acl\Table::LEVEL_YES,
+ ],
+ 'Account' => [
+ Acl\Table::ACTION_EDIT => Acl\Table::LEVEL_NO,
+ ],
+ ]);
+ $em->saveEntity($role2);
+
+ $user = $em->getRDBRepositoryByClass(User::class)->getNew();
+ $user
+ ->setUserName('test-1')
+ ->setRoles(LinkMultiple::create()->withAddedIdList([$role1->getId(), $role2->getId()]));
+ $em->saveEntity($user);
+
+ $em->refreshEntity($user);
+
+ $aclManager = $this->getContainer()->getByClass(AclManager::class);
+
+ $this->assertTrue($aclManager->checkScope($user, 'Lead', Acl\Table::ACTION_CREATE));
+ $this->assertTrue($aclManager->checkScope($user, 'Opportunity', Acl\Table::ACTION_CREATE));
+ $this->assertFalse($aclManager->checkScope($user, 'Account', Acl\Table::ACTION_CREATE));
+ $this->assertFalse($aclManager->checkScope($user, 'Opportunity', Acl\Table::ACTION_EDIT));
+ $this->assertFalse($aclManager->checkScope($user, 'Account', Acl\Table::ACTION_EDIT));
+ }
}