From 2ce99b370264ef06b699a7c1d03c81945635b21b Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Wed, 19 Mar 2025 15:11:36 +0200 Subject: [PATCH] order applier acl manager --- .../Espo/Core/Select/Applier/Factory.php | 6 ++++++ .../Espo/Core/Select/Applier/FactoryTest.php | 19 +++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/application/Espo/Core/Select/Applier/Factory.php b/application/Espo/Core/Select/Applier/Factory.php index b1253b6f16..513ffdb4f4 100644 --- a/application/Espo/Core/Select/Applier/Factory.php +++ b/application/Espo/Core/Select/Applier/Factory.php @@ -29,6 +29,7 @@ namespace Espo\Core\Select\Applier; +use Espo\Core\AclManager; use Espo\Core\Select\Text\Applier as TextFilterApplier; use Espo\Core\Select\AccessControl\Applier as AccessControlFilterApplier; use Espo\Core\Select\Where\Applier as WhereApplier; @@ -45,6 +46,7 @@ use Espo\Core\InjectableFactory; use Espo\Core\Select\SelectManager; use Espo\Core\Select\SelectManagerFactory; +use Espo\Core\Utils\Acl\UserAclManagerProvider; use Espo\Entities\User; use RuntimeException; @@ -77,6 +79,7 @@ class Factory public function __construct( private InjectableFactory $injectableFactory, + private UserAclManagerProvider $userAclManagerProvider, private SelectManagerFactory $selectManagerFactory ) {} @@ -87,11 +90,14 @@ class Factory // SelectManager is used for backward compatibility. $selectManager = $this->selectManagerFactory->create($entityType, $user); + $aclManager = $this->userAclManagerProvider->get($user); + $bindingData = new BindingData(); $binder = new Binder($bindingData); $binder ->bindInstance(User::class, $user) + ->bindInstance(AclManager::class, $aclManager) ->bindInstance(SelectManager::class, $selectManager) ->for($className) ->bindValue('$entityType', $entityType) diff --git a/tests/unit/Espo/Core/Select/Applier/FactoryTest.php b/tests/unit/Espo/Core/Select/Applier/FactoryTest.php index 7c40fc5e24..1135d27029 100644 --- a/tests/unit/Espo/Core/Select/Applier/FactoryTest.php +++ b/tests/unit/Espo/Core/Select/Applier/FactoryTest.php @@ -29,6 +29,7 @@ namespace tests\unit\Espo\Core\Select\Applier; +use Espo\Core\AclManager; use Espo\Core\Binding\Binder; use Espo\Core\Binding\BindingContainer; use Espo\Core\Binding\BindingData; @@ -46,21 +47,34 @@ use Espo\Core\Select\SelectManagerFactory; use Espo\Core\Select\Text\Applier as TextFilterApplier; use Espo\Core\Select\Where\Applier as WhereApplier; +use Espo\Core\Utils\Acl\UserAclManagerProvider; use Espo\Entities\User; +use PHPUnit\Framework\TestCase; -class FactoryTest extends \PHPUnit\Framework\TestCase +class FactoryTest extends TestCase { + private $aclManager; + protected function setUp(): void { $this->injectableFactory = $this->createMock(InjectableFactory::class); $this->selectManagerFactory = $this->createMock(SelectManagerFactory::class); - $this->selectManagerFactory = $this->createMock(SelectManagerFactory::class); $this->user = $this->createMock(User::class); $this->selectManager = $this->createMock(SelectManager::class); + $userAclManagerProvider = $this->createMock(UserAclManagerProvider::class); + + $this->aclManager = $this->createMock(AclManager::class); + + $userAclManagerProvider + ->expects($this->any()) + ->method('get') + ->willReturn($this->aclManager); + $this->factory = new ApplierFactory( $this->injectableFactory, + $userAclManagerProvider, $this->selectManagerFactory ); } @@ -134,6 +148,7 @@ class FactoryTest extends \PHPUnit\Framework\TestCase $binder ->bindInstance(User::class, $this->user) ->bindInstance(SelectManager::class, $this->selectManager) + ->bindInstance(AclManager::class, $this->aclManager) ->for($applierClassName) ->bindValue('$entityType', $entityType) ->bindValue('$selectManager', $this->selectManager);