Skip to content

Commit 3c00856

Browse files
committed
Merge branch '2.4-develop' into ACP2E-148
2 parents a319f5c + 83f3d01 commit 3c00856

File tree

938 files changed

+32065
-22128
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

938 files changed

+32065
-22128
lines changed

app/code/Magento/AsynchronousOperations/Model/MassPublisher.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function __construct(
7979
}
8080

8181
/**
82-
* {@inheritdoc}
82+
* @inheritdoc
8383
*/
8484
public function publish($topicName, $data)
8585
{
@@ -91,6 +91,7 @@ public function publish($topicName, $data)
9191
[
9292
'body' => $message,
9393
'properties' => [
94+
'topic_name' => $topicName,
9495
'delivery_mode' => 2,
9596
'message_id' => $this->messageIdGenerator->generate($topicName),
9697
]

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

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\Authorization\Model\Acl\Loader;
99

10+
use Magento\Framework\Acl;
1011
use Magento\Framework\Acl\Data\CacheInterface;
1112
use Magento\Framework\Acl\LoaderInterface;
1213
use Magento\Framework\Acl\RootResource;
@@ -21,7 +22,12 @@ class Rule implements LoaderInterface
2122
/**
2223
* Rules array cache key
2324
*/
24-
const ACL_RULE_CACHE_KEY = 'authorization_rule_cached_data';
25+
public const ACL_RULE_CACHE_KEY = 'authorization_rule_cached_data';
26+
27+
/**
28+
* Allow everything resource id
29+
*/
30+
private const ALLOW_EVERYTHING = 'Magento_Backend::all';
2531

2632
/**
2733
* @var ResourceConnection
@@ -75,27 +81,74 @@ public function __construct(
7581
/**
7682
* Populate ACL with rules from external storage
7783
*
78-
* @param \Magento\Framework\Acl $acl
84+
* @param Acl $acl
7985
* @return void
8086
*/
81-
public function populateAcl(\Magento\Framework\Acl $acl)
87+
public function populateAcl(Acl $acl)
8288
{
89+
$result = $this->applyPermissionsAccordingToRules($acl);
90+
$this->applyDenyPermissionsForMissingRules($acl, ...$result);
91+
}
92+
93+
/**
94+
* Apply ACL with rules
95+
*
96+
* @param Acl $acl
97+
* @return array[]
98+
*/
99+
private function applyPermissionsAccordingToRules(Acl $acl): array
100+
{
101+
$foundResources = $foundDeniedRoles = [];
83102
foreach ($this->getRulesArray() as $rule) {
84103
$role = $rule['role_id'];
85104
$resource = $rule['resource_id'];
86105
$privileges = !empty($rule['privileges']) ? explode(',', $rule['privileges']) : null;
87106

88107
if ($acl->has($resource)) {
108+
$foundResources[$resource] = $resource;
89109
if ($rule['permission'] == 'allow') {
90110
if ($resource === $this->_rootResource->getId()) {
91111
$acl->allow($role, null, $privileges);
92112
}
93113
$acl->allow($role, $resource, $privileges);
94114
} elseif ($rule['permission'] == 'deny') {
115+
$foundDeniedRoles[$role] = $role;
95116
$acl->deny($role, $resource, $privileges);
96117
}
97118
}
98119
}
120+
return [$foundResources, $foundDeniedRoles];
121+
}
122+
123+
/**
124+
* Apply deny permissions for missing rules
125+
*
126+
* For all rules that were not regenerated in authorization_rule table,
127+
* when adding a new module and without re-saving all roles,
128+
* consider not present rules with deny permissions
129+
*
130+
* @param Acl $acl
131+
* @param array $resources
132+
* @param array $deniedRoles
133+
* @return void
134+
*/
135+
private function applyDenyPermissionsForMissingRules(
136+
Acl $acl,
137+
array $resources,
138+
array $deniedRoles
139+
) {
140+
if (count($resources) && count($deniedRoles)
141+
//ignore denying missing permission if all are allowed
142+
&& !(count($resources) === 1 && isset($resources[static::ALLOW_EVERYTHING]))
143+
) {
144+
foreach ($acl->getResources() as $resource) {
145+
if (!isset($resources[$resource])) {
146+
foreach ($deniedRoles as $role) {
147+
$acl->deny($role, $resource, null);
148+
}
149+
}
150+
}
151+
}
99152
}
100153

101154
/**
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Authorization\Test\Fixture;
9+
10+
use Magento\Authorization\Model\Acl\Role\Group;
11+
use Magento\Authorization\Model\ResourceModel\Role as RoleResource;
12+
use Magento\Authorization\Model\UserContextInterface;
13+
use Magento\Framework\DataObject;
14+
use Magento\SharedCatalog\Model\SharedCatalogFactory;
15+
use Magento\TestFramework\Fixture\Data\ProcessorInterface;
16+
use Magento\TestFramework\Fixture\RevertibleDataFixtureInterface;
17+
use Magento\Authorization\Model\RoleFactory;
18+
use Magento\Authorization\Model\RulesFactory;
19+
use Magento\User\Model\UserFactory;
20+
21+
/**
22+
* Creating a new admin role
23+
*/
24+
class Role implements RevertibleDataFixtureInterface
25+
{
26+
private const DEFAULT_DATA = [
27+
'role_name' => 'Role Name %uniqid%',
28+
'role_type' => Group::ROLE_TYPE,
29+
'user_id' => 0,
30+
'user_type' => UserContextInterface::USER_TYPE_ADMIN
31+
];
32+
33+
private const DEFAULT_DATA_RULES = [
34+
'id' => null,
35+
'role_id' => null,
36+
'resources' => ['Magento_Backend::all']
37+
];
38+
39+
/**
40+
* @var RoleFactory
41+
*/
42+
private $roleFactory;
43+
44+
/**
45+
* @var ProcessorInterface
46+
*/
47+
private $dataProcessor;
48+
49+
/**
50+
* @var RoleResource
51+
*/
52+
private $roleResourceModel;
53+
54+
/**
55+
* @var RulesFactory
56+
*/
57+
private $rulesFactory;
58+
59+
/**
60+
* @param RoleFactory $roleFactory
61+
* @param RoleResource $roleResourceModel
62+
* @param RulesFactory $rulesFactory
63+
* @param ProcessorInterface $dataProcessor
64+
*/
65+
public function __construct(
66+
RoleFactory $roleFactory,
67+
RoleResource $roleResourceModel,
68+
RulesFactory $rulesFactory,
69+
ProcessorInterface $dataProcessor
70+
) {
71+
$this->roleFactory = $roleFactory;
72+
$this->roleResourceModel = $roleResourceModel;
73+
$this->rulesFactory = $rulesFactory;
74+
$this->dataProcessor = $dataProcessor;
75+
}
76+
77+
/**
78+
* @inheritdoc
79+
*/
80+
public function apply(array $data = []): ?DataObject
81+
{
82+
$role = $this->roleFactory->create();
83+
$role->setData($this->prepareData(array_diff_key($data, self::DEFAULT_DATA_RULES)));
84+
$this->roleResourceModel->save($role);
85+
86+
$rules = $this->rulesFactory->create();
87+
$rules->setRoleId($role->getId() ?? null);
88+
$rules->setResources($data['resources'] ?? self::DEFAULT_DATA_RULES['resources']);
89+
$rules->saveRel();
90+
91+
return $role;
92+
}
93+
94+
/**
95+
* @inheritdoc
96+
*/
97+
public function revert(DataObject $data): void
98+
{
99+
$role = $this->roleFactory->create();
100+
$role->load($data->getId());
101+
102+
if ($role->getId() !== null) {
103+
$role->delete();
104+
}
105+
}
106+
107+
/**
108+
* Prepare admin role data
109+
*
110+
* @param array $data
111+
* @return array
112+
*/
113+
private function prepareData(array $data): array
114+
{
115+
$data = array_merge(self::DEFAULT_DATA, $data);
116+
return $this->dataProcessor->process($this, $data);
117+
}
118+
}

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ static function ($value) {
9797
*/
9898
public function testPopulateAclFromCache(): void
9999
{
100+
$rules = [
101+
['role_id' => 1, 'resource_id' => 'Magento_Backend::all', 'permission' => 'allow'],
102+
['role_id' => 2, 'resource_id' => 1, 'permission' => 'allow'],
103+
['role_id' => 3, 'resource_id' => 1, 'permission' => 'deny']
104+
];
100105
$this->resourceMock->expects($this->never())->method('getTable');
101106
$this->resourceMock->expects($this->never())
102107
->method('getConnection');
@@ -105,13 +110,7 @@ public function testPopulateAclFromCache(): void
105110
->method('load')
106111
->with(Rule::ACL_RULE_CACHE_KEY)
107112
->willReturn(
108-
json_encode(
109-
[
110-
['role_id' => 1, 'resource_id' => 'Magento_Backend::all', 'permission' => 'allow'],
111-
['role_id' => 2, 'resource_id' => 1, 'permission' => 'allow'],
112-
['role_id' => 3, 'resource_id' => 1, 'permission' => 'deny']
113-
]
114-
)
113+
json_encode($rules)
115114
);
116115

117116
$aclMock = $this->createMock(Acl::class);
@@ -123,9 +122,21 @@ public function testPopulateAclFromCache(): void
123122
['1', 'Magento_Backend::all', null],
124123
['2', 1, null]
125124
);
125+
126126
$aclMock
127127
->method('deny')
128-
->with('3', 1, null);
128+
->withConsecutive(
129+
['3', 1, null]
130+
);
131+
132+
$aclMock
133+
->method('getResources')
134+
->willReturn([
135+
'Magento_Backend::all',
136+
'Magento_Backend::admin',
137+
'Vendor_MyModule::menu',
138+
'Vendor_MyModule::index'
139+
]);
129140

130141
$this->model->populateAcl($aclMock);
131142
}

app/code/Magento/AwsS3/Test/Mftf/Test/AdminAwsS3ImportBundleProductTest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
<helper class="Magento\AwsS3\Test\Mftf\Helper\S3FileAssertions" method="deleteDirectory" stepKey="deleteImportImagesFilesDirectoryS3" after="deleteImportFilesDirectoryS3">
6060
<argument name="path">var/import/images/{{ImportProduct_Bundle.name}}</argument>
6161
</helper>
62+
<actionGroup ref="CliCacheFlushActionGroup" stepKey="flushCache" after="deleteImportImagesFilesDirectoryS3">
63+
<argument name="tags" value=""/>
64+
</actionGroup>
6265

6366
<!-- Disable AWS S3 Remote Storage & Delete Local Data -->
6467
<magentoCLI command="setup:config:set {{RemoteStorageAwsS3ConfigData.disable_options}}" stepKey="disableRemoteStorage" after="logoutFromAdmin"/>

app/code/Magento/AwsS3/Test/Mftf/Test/AdminAwsS3ImportDownloadableProductsWithFileLinksTest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@
7575
<helper class="Magento\AwsS3\Test\Mftf\Helper\S3FileAssertions" method="deleteDirectory" stepKey="deleteImportImagesFilesDirectoryS3" after="deleteImportFilesDirectoryS3">
7676
<argument name="path">var/import/images/{{ImportProduct_Downloadable_FileLinks.name}}</argument>
7777
</helper>
78+
<actionGroup ref="CliCacheFlushActionGroup" stepKey="flushCache" after="deleteImportImagesFilesDirectoryS3">
79+
<argument name="tags" value=""/>
80+
</actionGroup>
7881

7982
<!-- Disable AWS S3 Remote Storage & Delete Local Data -->
8083
<magentoCLI command="setup:config:set {{RemoteStorageAwsS3ConfigData.disable_options}}" stepKey="disableRemoteStorage" after="logoutFromAdmin"/>

app/code/Magento/AwsS3/Test/Mftf/Test/AdminAwsS3ImportDownloadableProductsWithUrlLinksTest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
<helper class="Magento\AwsS3\Test\Mftf\Helper\S3FileAssertions" method="deleteDirectory" stepKey="deleteImportImagesFilesDirectoryS3" after="deleteImportFilesDirectoryS3">
6060
<argument name="path">var/import/images/{{ImportProduct_Downloadable_UrlLinks.name}}</argument>
6161
</helper>
62+
<actionGroup ref="CliCacheFlushActionGroup" stepKey="flushCache" after="deleteImportImagesFilesDirectoryS3">
63+
<argument name="tags" value=""/>
64+
</actionGroup>
6265

6366
<!-- Disable AWS S3 Remote Storage & Delete Local Data -->
6467
<magentoCLI command="setup:config:set {{RemoteStorageAwsS3ConfigData.disable_options}}" stepKey="disableRemoteStorage" after="logoutFromAdmin"/>

app/code/Magento/AwsS3/Test/Mftf/Test/AdminAwsS3ImportGroupedProductTest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
<helper class="Magento\AwsS3\Test\Mftf\Helper\S3FileAssertions" method="deleteDirectory" stepKey="deleteImportImagesFilesDirectoryS3" after="deleteImportFilesDirectoryS3">
6060
<argument name="path">var/import/images/{{ImportProduct_Grouped.name}}</argument>
6161
</helper>
62+
<actionGroup ref="CliCacheFlushActionGroup" stepKey="flushCache" after="deleteImportImagesFilesDirectoryS3">
63+
<argument name="tags" value=""/>
64+
</actionGroup>
6265

6366
<!-- Disable AWS S3 Remote Storage & Delete Local Data -->
6467
<magentoCLI command="setup:config:set {{RemoteStorageAwsS3ConfigData.disable_options}}" stepKey="disableRemoteStorage" after="logoutFromAdmin"/>

app/code/Magento/AwsS3/Test/Mftf/Test/AdminAwsS3ImportSimpleAndConfigurableProductsWithAssignedImagesTest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
<helper class="Magento\AwsS3\Test\Mftf\Helper\S3FileAssertions" method="deleteDirectory" stepKey="deleteImportImagesFilesDirectoryS3" after="deleteImportFilesDirectoryS3">
6161
<argument name="path">var/import/images/{{ImportProduct_Configurable.name}}</argument>
6262
</helper>
63+
<actionGroup ref="CliCacheFlushActionGroup" stepKey="flushCache" after="deleteImportImagesFilesDirectoryS3">
64+
<argument name="tags" value=""/>
65+
</actionGroup>
6366

6467
<!-- Disable AWS S3 Remote Storage & Delete Local Data -->
6568
<magentoCLI command="setup:config:set {{RemoteStorageAwsS3ConfigData.disable_options}}" stepKey="disableRemoteStorage" after="logoutFromAdmin"/>

app/code/Magento/AwsS3/Test/Mftf/Test/AdminAwsS3ImportSimpleProductImagesDuplicationTest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
<helper class="Magento\AwsS3\Test\Mftf\Helper\S3FileAssertions" method="deleteDirectory" stepKey="deleteImportImagesFilesDirectoryS3" after="deleteImportFilesDirectoryS3">
5959
<argument name="path">var/import/images/test_image_duplication</argument>
6060
</helper>
61+
<actionGroup ref="CliCacheFlushActionGroup" stepKey="flushCache" after="deleteImportImagesFilesDirectoryS3">
62+
<argument name="tags" value=""/>
63+
</actionGroup>
6164

6265
<!-- Disable AWS S3 Remote Storage & Delete Local Data -->
6366
<magentoCLI command="setup:config:set {{RemoteStorageAwsS3ConfigData.disable_options}}" stepKey="disableRemoteStorage" after="logoutFromAdmin"/>

0 commit comments

Comments
 (0)