Skip to content

Commit 8a627e0

Browse files
author
Yauhen_Lyskavets
committed
MC-16455: Admin user with permission for 1 store can manage categories
- Fix unit and static tests failures.
1 parent 5e07003 commit 8a627e0

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

app/code/Magento/Catalog/Model/Category/DataProvider.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
162162
private $auth;
163163

164164
/**
165-
* @param string $name
166-
* @param string $primaryFieldName
167-
* @param string $requestFieldName
165+
* @param $name
166+
* @param $primaryFieldName
167+
* @param $requestFieldName
168168
* @param EavValidationRules $eavValidationRules
169169
* @param CategoryCollectionFactory $categoryCollectionFactory
170170
* @param StoreManagerInterface $storeManager
@@ -176,7 +176,8 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
176176
* @param array $data
177177
* @param PoolInterface|null $pool
178178
* @param AuthorizationInterface|null $auth
179-
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
179+
* @param ArrayUtils|null $arrayUtils
180+
* @throws \Magento\Framework\Exception\LocalizedException
180181
*/
181182
public function __construct(
182183
$name,
@@ -321,7 +322,7 @@ private function prepareFieldsMeta(array $fieldsMap, array $fieldsMeta): array
321322
* @inheritDoc
322323
* @since 101.0.0
323324
*/
324-
public function getData(): array
325+
public function getData()
325326
{
326327
if (isset($this->loadedData)) {
327328
return $this->loadedData;
@@ -382,7 +383,7 @@ public function getAttributesMeta(Type $entityType)
382383
// disable fields
383384
$attributeIsLocked = $this->getCurrentCategory()->isLockedAttribute($code);
384385
$meta[$code]['disabled'] = $attributeIsLocked;
385-
if (array_search('use_config.' . $code, $fields, true) && $meta[$code]['disabled']) {
386+
if (array_search('use_config.' . $code, $fields) && $meta[$code]['disabled']) {
386387
$meta['use_config.' . $code]['disabled'] = true;
387388
}
388389
}

app/code/Magento/Catalog/Test/Unit/Model/Category/DataProviderTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Magento\Store\Model\StoreManagerInterface;
1818
use Magento\Ui\DataProvider\EavValidationRules;
1919
use Magento\Ui\DataProvider\Modifier\PoolInterface;
20+
use Magento\Framework\Stdlib\ArrayUtils;
2021

2122
/**
2223
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -78,6 +79,14 @@ class DataProviderTest extends \PHPUnit\Framework\TestCase
7879
*/
7980
private $modifierPool;
8081

82+
/**
83+
* @var ArrayUtils|\PHPUnit_Framework_MockObject_MockObject
84+
*/
85+
private $arrayUtils;
86+
87+
/**
88+
* @inheritDoc
89+
*/
8190
protected function setUp()
8291
{
8392
$this->eavValidationRules = $this->getMockBuilder(EavValidationRules::class)
@@ -128,6 +137,10 @@ protected function setUp()
128137
->getMock();
129138

130139
$this->modifierPool = $this->getMockBuilder(PoolInterface::class)->getMockForAbstractClass();
140+
141+
$this->arrayUtils = $this->getMockBuilder(ArrayUtils::class)
142+
->setMethods(['flatten'])
143+
->disableOriginalConstructor()->getMock();
131144
}
132145

133146
/**
@@ -157,7 +170,8 @@ private function getModel()
157170
'eavConfig' => $this->eavConfig,
158171
'request' => $this->request,
159172
'categoryFactory' => $this->categoryFactory,
160-
'pool' => $this->modifierPool
173+
'pool' => $this->modifierPool,
174+
'arrayUtils' => $this->arrayUtils
161175
]
162176
);
163177

@@ -331,6 +345,8 @@ public function testGetData()
331345

332346
public function testGetMetaWithoutParentInheritanceResolving()
333347
{
348+
$this->arrayUtils->expects($this->atLeastOnce())->method('flatten')->willReturn([1,3,3]);
349+
334350
$categoryMock = $this->getMockBuilder(\Magento\Catalog\Model\Category::class)
335351
->disableOriginalConstructor()
336352
->getMock();

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function modifyMeta(array $meta)
149149
*/
150150
private function isAllowed(): bool
151151
{
152-
return $this->authorization->isAllowed('Magento_Catalog::categories');
152+
return (bool) $this->authorization->isAllowed('Magento_Catalog::categories');
153153
}
154154

155155
/**
@@ -291,6 +291,7 @@ protected function customizeCategoriesField(array $meta)
291291
'formElement' => 'container',
292292
'additionalClasses' => 'admin__field-small',
293293
'componentType' => 'container',
294+
'disabled' => $fieldIsDisabled,
294295
'component' => 'Magento_Ui/js/form/components/button',
295296
'template' => 'ui/form/components/button/container',
296297
'actions' => [
@@ -315,7 +316,6 @@ protected function customizeCategoriesField(array $meta)
315316
'displayArea' => 'insideGroup',
316317
'sortOrder' => 20,
317318
'dataScope' => $fieldCode,
318-
'disabled' => $fieldIsDisabled,
319319
],
320320
],
321321
]

app/code/Magento/Ui/Component/Form/Element/Wysiwyg.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function __construct(
5252
array $config = []
5353
) {
5454
$wysiwygConfigData = isset($config['wysiwygConfigData']) ? $config['wysiwygConfigData'] : [];
55-
if ($config['disabled'] === true) {
55+
if (isset($config['disabled']) && $config['disabled'] === true) {
5656
$config['wysiwygConfigData']['settings']['readonly'] = 1;
5757
}
5858

0 commit comments

Comments
 (0)