Skip to content

Commit eb7d034

Browse files
author
Joan He
committed
MAGETWO-91529: Restricted admin user can remove product from other websites
- Disable fields for locked attributes
1 parent c62d922 commit eb7d034

File tree

14 files changed

+147
-29
lines changed

14 files changed

+147
-29
lines changed

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/AbstractModifierTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ protected function setUp()
6363
'getAttributes',
6464
'getStore',
6565
'getAttributeDefaultValue',
66-
'getExistsStoreValueFlag'
66+
'getExistsStoreValueFlag',
67+
'isLockedAttribute'
6768
])->getMockForAbstractClass();
6869
$this->storeMock = $this->getMockBuilder(StoreInterface::class)
6970
->setMethods(['load', 'getId', 'getConfig'])
@@ -81,9 +82,6 @@ protected function setUp()
8182
$this->arrayManagerMock->expects($this->any())
8283
->method('set')
8384
->willReturnArgument(1);
84-
$this->arrayManagerMock->expects($this->any())
85-
->method('merge')
86-
->willReturnArgument(1);
8785
$this->arrayManagerMock->expects($this->any())
8886
->method('remove')
8987
->willReturnArgument(1);

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/AttributeSetTest.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Catalog\Test\Unit\Ui\DataProvider\Product\Form\Modifier;
77

8+
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
89
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AttributeSet;
910
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory;
1011
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection;
@@ -84,7 +85,27 @@ protected function createModel()
8485

8586
public function testModifyMeta()
8687
{
87-
$this->assertNotEmpty($this->getModel()->modifyMeta(['test_group' => []]));
88+
$modifyMeta = $this->getModel()->modifyMeta(['test_group' => []]);
89+
$this->assertNotEmpty($modifyMeta);
90+
}
91+
92+
/**
93+
* @param bool $locked
94+
* @dataProvider modifyMetaLockedDataProvider
95+
*/
96+
public function testModifyMetaLocked($locked)
97+
{
98+
$this->productMock->expects($this->any())
99+
->method('isLockedAttribute')
100+
->willReturn($locked);
101+
$modifyMeta = $this->getModel()->modifyMeta([AbstractModifier::DEFAULT_GENERAL_PANEL => []]);
102+
$this->assertEquals($locked,
103+
$modifyMeta[AbstractModifier::DEFAULT_GENERAL_PANEL]['children']['attribute_set_id']['arguments']['data']['config']['disabled']);
104+
}
105+
106+
public function modifyMetaLockedDataProvider()
107+
{
108+
return [[true], [false]];
88109
}
89110

90111
public function testModifyMetaToBeEmpty()

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,44 @@ public function testModifyMeta()
114114
$this->assertArrayHasKey($groupCode, $this->getModel()->modifyMeta($meta));
115115
}
116116

117+
/**
118+
* @param bool $locked
119+
* @dataProvider modifyMetaLockedDataProvider
120+
*/
121+
public function testModifyMetaLocked($locked)
122+
{
123+
$groupCode = 'test_group_code';
124+
$meta = [
125+
$groupCode => [
126+
'children' => [
127+
'category_ids' => [
128+
'sortOrder' => 10,
129+
],
130+
],
131+
],
132+
];
133+
134+
$this->arrayManagerMock->expects($this->any())
135+
->method('findPath')
136+
->willReturn('path');
137+
138+
$this->productMock->expects($this->any())
139+
->method('isLockedAttribute')
140+
->willReturn($locked);
141+
142+
$this->arrayManagerMock->expects($this->any())
143+
->method('merge')
144+
->willReturnArgument(2);
145+
146+
$modifyMeta = $this->createModel()->modifyMeta($meta);
147+
$this->assertEquals($locked, $modifyMeta['arguments']['data']['config']['disabled']);
148+
}
149+
150+
public function modifyMetaLockedDataProvider()
151+
{
152+
return [[true], [false]];
153+
}
154+
117155
public function testModifyMetaWithCaching()
118156
{
119157
$this->arrayManagerMock->expects($this->exactly(2))

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/EavTest.php

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -456,20 +456,24 @@ public function testModifyData()
456456
* @param string $attrValue
457457
* @param string $note
458458
* @param array $expected
459+
* @param bool $locked
459460
* @covers \Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Eav::isProductExists
460461
* @covers \Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Eav::setupAttributeMeta
461462
* @dataProvider setupAttributeMetaDataProvider
462463
*/
463-
public function testSetupAttributeMetaDefaultAttribute($productId, $productRequired, $attrValue, $note, $expected)
464+
public function testSetupAttributeMetaDefaultAttribute($productId, $productRequired, $attrValue, $note, $expected, $locked = false)
464465
{
465-
$configPath = 'arguments/data/config';
466466
$groupCode = 'product-details';
467467
$sortOrder = '0';
468468

469469
$this->productMock->expects($this->any())
470470
->method('getId')
471471
->willReturn($productId);
472472

473+
$this->productMock->expects($this->any())
474+
->method('isLockedAttribute')
475+
->willReturn($locked);
476+
473477
$this->productAttributeMock->expects($this->any())
474478
->method('getIsRequired')
475479
->willReturn($productRequired);
@@ -509,12 +513,7 @@ public function testSetupAttributeMetaDefaultAttribute($productId, $productRequi
509513

510514
$this->arrayManagerMock->expects($this->any())
511515
->method('set')
512-
->with(
513-
$configPath,
514-
[],
515-
$expected
516-
)
517-
->willReturn($expected);
516+
->willReturnArgument(2);
518517

519518
$this->arrayManagerMock->expects($this->any())
520519
->method('merge')
@@ -540,8 +539,10 @@ public function setupAttributeMetaDataProvider()
540539
{
541540
return [
542541
'default_null_prod_not_new_and_required' => $this->defaultNullProdNotNewAndRequired(),
542+
'default_null_prod_not_new_locked_and_required' => $this->defaultNullProdNotNewLockedAndRequired(),
543543
'default_null_prod_not_new_and_not_required' => $this->defaultNullProdNotNewAndNotRequired(),
544544
'default_null_prod_new_and_not_required' => $this->defaultNullProdNewAndNotRequired(),
545+
'default_null_prod_new_locked_and_not_required' => $this->defaultNullProdNewLOckedAndNotRequired(),
545546
'default_null_prod_new_and_required' => $this->defaultNullProdNewAndRequired(),
546547
'default_null_prod_new_and_required_and_filled_notice' =>
547548
$this->defaultNullProdNewAndRequiredAndFilledNotice()
@@ -575,6 +576,32 @@ private function defaultNullProdNotNewAndRequired()
575576
];
576577
}
577578

579+
private function defaultNullProdNotNewLockedAndRequired()
580+
{
581+
return [
582+
'productId' => 1,
583+
'productRequired' => true,
584+
'attrValue' => 'val',
585+
'note' => null,
586+
'expected' => [
587+
'dataType' => null,
588+
'formElement' => null,
589+
'visible' => null,
590+
'required' => true,
591+
'notice' => null,
592+
'default' => null,
593+
'label' => new Phrase('mylabel'),
594+
'code' => 'code',
595+
'source' => 'product-details',
596+
'scopeLabel' => '',
597+
'globalScope' => false,
598+
'sortOrder' => 0,
599+
'disabled' => true,
600+
],
601+
'locked' => true
602+
];
603+
}
604+
578605
/**
579606
* @return array
580607
*/
@@ -629,6 +656,32 @@ private function defaultNullProdNewAndNotRequired()
629656
];
630657
}
631658

659+
private function defaultNullProdNewLockedAndNotRequired()
660+
{
661+
return [
662+
'productId' => null,
663+
'productRequired' => false,
664+
'attrValue' => null,
665+
'note' => null,
666+
'expected' => [
667+
'dataType' => null,
668+
'formElement' => null,
669+
'visible' => null,
670+
'required' => false,
671+
'notice' => null,
672+
'default' => 'required_value',
673+
'label' => new Phrase('mylabel'),
674+
'code' => 'code',
675+
'source' => 'product-details',
676+
'scopeLabel' => '',
677+
'globalScope' => false,
678+
'sortOrder' => 0,
679+
'disabled' => true,
680+
],
681+
'locked' => true,
682+
];
683+
}
684+
632685
/**
633686
* @return array
634687
*/

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/GeneralTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ protected function createModel()
6060

6161
public function testModifyMeta()
6262
{
63+
$this->arrayManagerMock->expects($this->any())
64+
->method('merge')
65+
->willReturnArgument(2);
6366
$this->assertNotEmpty($this->getModel()->modifyMeta([
6467
'first_panel_code' => [
6568
'arguments' => [

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/ScheduleDesignUpdateTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ protected function createModel()
2424

2525
public function testModifyMeta()
2626
{
27+
$this->arrayManagerMock->expects($this->any())
28+
->method('merge')
29+
->willReturnArgument(1);
2730
$this->assertSame([], $this->getModel()->modifyMeta([]));
2831
}
2932

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/WebsitesTest.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ class WebsitesTest extends AbstractModifierTest
7676

7777
protected function setUp()
7878
{
79-
$this->objectManager = new ObjectManager($this);
79+
parent::setUp();
80+
$this->productMock->expects($this->any())
81+
->method('getId')
82+
->willReturn(self::PRODUCT_ID);
8083
$this->assignedWebsites = [self::SECOND_WEBSITE_ID];
8184
$this->websiteMock = $this->getMockBuilder(\Magento\Store\Model\Website::class)
8285
->setMethods(['getId', 'getName'])
@@ -101,15 +104,9 @@ protected function setUp()
101104
$this->storeRepositoryMock = $this->getMockBuilder(\Magento\Store\Api\StoreRepositoryInterface::class)
102105
->setMethods(['getList'])
103106
->getMockForAbstractClass();
104-
$this->locatorMock = $this->getMockBuilder(\Magento\Catalog\Model\Locator\LocatorInterface::class)
105-
->setMethods(['getProduct', 'getWebsiteIds'])
106-
->getMockForAbstractClass();
107107
$this->productMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductInterface::class)
108108
->setMethods(['getId'])
109109
->getMockForAbstractClass();
110-
$this->locatorMock->expects($this->any())
111-
->method('getProduct')
112-
->willReturn($this->productMock);
113110
$this->locatorMock->expects($this->any())
114111
->method('getWebsiteIds')
115112
->willReturn($this->assignedWebsites);
@@ -148,9 +145,6 @@ protected function setUp()
148145
$this->storeRepositoryMock->expects($this->any())
149146
->method('getList')
150147
->willReturn([$this->storeViewMock]);
151-
$this->productMock->expects($this->any())
152-
->method('getId')
153-
->willReturn(self::PRODUCT_ID);
154148
$this->secondWebsiteMock->expects($this->any())
155149
->method('getId')
156150
->willReturn($this->assignedWebsites[0]);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,8 @@ private function getTierPriceStructure($tierPricePath)
432432
'dndConfig' => [
433433
'enabled' => false,
434434
],
435-
'disabled' => false,
435+
'disabled' =>
436+
$this->arrayManager->get($tierPricePath . '/arguments/data/config/disabled', $this->meta),
436437
'required' => false,
437438
'sortOrder' =>
438439
$this->arrayManager->get($tierPricePath . '/arguments/data/config/sortOrder', $this->meta),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public function modifyMeta(array $meta)
108108
self::ATTRIBUTE_SET_FIELD_ORDER
109109
),
110110
'multiple' => false,
111+
'disabled' => $this->locator->getProduct()->isLockedAttribute('attribute_set_id'),
111112
];
112113
}
113114

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ protected function customizeCategoriesField(array $meta)
228228
'componentType' => 'container',
229229
'component' => 'Magento_Ui/js/form/components/group',
230230
'scopeLabel' => __('[GLOBAL]'),
231+
'disabled' => $this->locator->getProduct()->isLockedAttribute($fieldCode),
231232
],
232233
],
233234
],

0 commit comments

Comments
 (0)