Skip to content

Commit 829f4df

Browse files
karyna-tandrewbess
authored andcommitted
AC-5893: Replace Zend_Acl with laminas\laminas-permissions-acl
1 parent dbc97f9 commit 829f4df

File tree

24 files changed

+185
-112
lines changed

24 files changed

+185
-112
lines changed

app/code/Magento/Authorization/Model/Acl/AclRetriever.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
*/
2222
class AclRetriever
2323
{
24-
const PERMISSION_ANONYMOUS = 'anonymous';
25-
const PERMISSION_SELF = 'self';
24+
public const PERMISSION_ANONYMOUS = 'anonymous';
25+
public const PERMISSION_SELF = 'self';
2626

2727
/**
2828
* @var \Psr\Log\LoggerInterface
@@ -117,7 +117,7 @@ public function getAllowedResourcesByRole($roleId)
117117
/** @var \Magento\Authorization\Model\Rules $ruleItem */
118118
foreach ($rulesCollection->getItems() as $ruleItem) {
119119
$resourceId = $ruleItem->getResourceId();
120-
if ($acl->has($resourceId) && $acl->isAllowed($roleId, $resourceId)) {
120+
if ($acl->hasResource($resourceId) && $acl->isAllowed($roleId, $resourceId)) {
121121
$allowedResources[] = $resourceId;
122122
}
123123
}

app/code/Magento/Authorization/Model/Acl/Loader/Rule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private function applyPermissionsAccordingToRules(Acl $acl): array
104104
$resource = $rule['resource_id'];
105105
$privileges = !empty($rule['privileges']) ? explode(',', $rule['privileges']) : null;
106106

107-
if ($acl->has($resource)) {
107+
if ($acl->hasResource($resource)) {
108108
$foundResources[$resource] = $resource;
109109
if ($rule['permission'] == 'allow') {
110110
if ($resource === $this->_rootResource->getId()) {

app/code/Magento/Authorization/Model/Acl/Role/Generic.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
*/
66
namespace Magento\Authorization\Model\Acl\Role;
77

8+
use Laminas\Permissions\Acl\Role\GenericRole;
9+
810
/**
911
* Generic acl role
1012
*/
11-
class Generic extends \Zend_Acl_Role
13+
class Generic extends GenericRole
1214
{
1315
}

app/code/Magento/Authorization/Test/Unit/Model/Acl/AclRetrieverTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ protected function createAclRetriever()
165165
/**
166166
* @var Acl|MockObject $aclMock
167167
*/
168-
$aclMock = $this->createPartialMock(Acl::class, ['has', 'isAllowed']);
169-
$aclMock->expects($this->any())->method('has')->willReturn(true);
170-
$aclMock->expects($this->any())->method('isAllowed')->willReturn(true);
168+
$aclMock = $this->createPartialMock(Acl::class, ['hasResource', 'isAllowed']);
169+
$aclMock->method('hasResource')->willReturn(true);
170+
$aclMock->method('isAllowed')->willReturn(true);
171171

172172
/**
173173
* @var Builder|MockObject $aclBuilderMock

app/code/Magento/Authorization/Test/Unit/Model/Acl/Loader/RuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function testPopulateAclFromCache(): void
114114
);
115115

116116
$aclMock = $this->createMock(Acl::class);
117-
$aclMock->method('has')->willReturn(true);
117+
$aclMock->method('hasResource')->willReturn(true);
118118
$aclMock
119119
->method('allow')
120120
->withConsecutive(

app/code/Magento/Backend/Model/Auth/Session.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function isAllowed($resource, $privilege = null)
152152
return $acl->isAllowed($user->getAclRole(), $resource, $privilege);
153153
} catch (\Exception $e) {
154154
try {
155-
if (!$acl->has($resource)) {
155+
if (!$acl->hasResource($resource)) {
156156
return $acl->isAllowed($user->getAclRole(), null, $privilege);
157157
}
158158
} catch (\Exception $e) {

app/code/Magento/Config/Controller/Adminhtml/System/ConfigSectionChecker.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\Config\Controller\Adminhtml\System;
88

9+
use Laminas\Permissions\Acl\Exception\InvalidArgumentException;
910
use Magento\Framework\Exception\NotFoundException;
1011

1112
/**
@@ -41,11 +42,14 @@ public function isSectionAllowed($sectionId)
4142
{
4243
try {
4344
if (false == $this->_configStructure->getElement($sectionId)->isAllowed()) {
45+
// phpcs:ignore Magento2.Exceptions.DirectThrow
4446
throw new \Exception('');
4547
}
4648
return true;
47-
} catch (\Zend_Acl_Exception $e) {
49+
} catch (InvalidArgumentException $e) {
50+
// phpcs:ignore Magento2.Exceptions.ThrowCatch
4851
throw new NotFoundException(__('Page not found.'));
52+
// phpcs:ignore Magento2.Exceptions.ThrowCatch
4953
} catch (\Exception $e) {
5054
return false;
5155
}

dev/tests/integration/framework/Magento/TestFramework/Bootstrap.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,28 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
namespace Magento\TestFramework;
8+
79
/**
810
* Bootstrap for the integration testing environment
911
*/
10-
namespace Magento\TestFramework;
11-
1212
class Bootstrap
1313
{
1414
/**#@+
1515
* Predefined admin user credentials
1616
*/
17-
const ADMIN_NAME = 'user';
18-
const ADMIN_PASSWORD = 'password1';
19-
const ADMIN_EMAIL = 'admin@example.com';
20-
const ADMIN_FIRSTNAME = 'firstname';
21-
const ADMIN_LASTNAME = 'lastname';
17+
public const ADMIN_NAME = 'user';
18+
public const ADMIN_PASSWORD = 'password1';
19+
public const ADMIN_EMAIL = 'admin@example.com';
20+
public const ADMIN_FIRSTNAME = 'firstname';
21+
public const ADMIN_LASTNAME = 'lastname';
2222
/**#@- */
2323

2424
/**
2525
* Predefined admin user role name
2626
*/
27-
const ADMIN_ROLE_NAME = 'Administrators';
27+
public const ADMIN_ROLE_NAME = 'Administrators';
28+
public const ADMIN_ROLE_ID = 1;
2829

2930
/**
3031
* @var \Magento\TestFramework\Bootstrap\Settings

dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractBackendController.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\TestFramework\TestCase;
77

8+
use Magento\Framework\Acl\Builder as AclBuilder;
9+
use Magento\TestFramework\Bootstrap;
10+
811
/**
912
* A parent class for backend controllers - contains directives for admin user creation and authentication.
1013
*
@@ -125,9 +128,9 @@ public function testAclNoAccess()
125128
if ($this->httpMethod) {
126129
$this->getRequest()->setMethod($this->httpMethod);
127130
}
128-
$this->_objectManager->get(\Magento\Framework\Acl\Builder::class)
129-
->getAcl()
130-
->deny(null, $this->resource);
131+
132+
$acl = $this->_objectManager->get(AclBuilder::class)->getAcl();
133+
$acl->deny($this->_auth->getUser()->getRoles(), $this->resource);
131134
$this->dispatch($this->uri);
132135
$this->assertSame($this->expectedNoAccessResponseCode, $this->getResponse()->getHttpResponseCode());
133136
}

dev/tests/integration/testsuite/Magento/Backend/App/AbstractActionTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Backend\App;
77

8+
use Magento\TestFramework\Bootstrap;
9+
810
/**
911
* Test class for \Magento\Backend\App\AbstractAction.
1012
* @magentoAppArea adminhtml
@@ -91,7 +93,7 @@ public function testAclInNodes($blockName, $resource, $isLimitedAccess)
9193
->get(\Magento\Framework\Acl\Builder::class)
9294
->getAcl();
9395
if ($isLimitedAccess) {
94-
$acl->deny(null, $resource);
96+
$acl->deny(Bootstrap::ADMIN_ROLE_ID, $resource);
9597
}
9698

9799
$this->dispatch('backend/admin/dashboard');

0 commit comments

Comments
 (0)