Skip to content

Commit 76cb3c6

Browse files
author
OlgaVasyltsun
committed
MAGETWO-98202: Additional Permissions for Design settings
1 parent cd5d54c commit 76cb3c6

File tree

9 files changed

+65
-35
lines changed

9 files changed

+65
-35
lines changed

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -946,12 +946,9 @@ public function beforeSave()
946946
|| $userType === UserContextInterface::USER_TYPE_INTEGRATION)
947947
&& !$this->authorization->isAllowed('Magento_Catalog::edit_category_design')
948948
) {
949-
$this->setData('custom_design', $this->getOrigData('custom_design'));
950-
$this->setData('custom_design_from', $this->getOrigData('custom_design_from'));
951-
$this->setData('custom_design_to', $this->getOrigData('custom_design_to'));
952-
$this->setData('page_layout', $this->getOrigData('page_layout'));
953-
$this->setData('custom_layout_update', $this->getOrigData('custom_layout_update'));
954-
$this->setData('custom_apply_to_products', $this->getOrigData('custom_apply_to_products'));
949+
foreach ($this->_designAttributes as $attributeCode) {
950+
$this->setData($attributeCode, $this->getOrigData($attributeCode));
951+
}
955952
}
956953

957954
return parent::beforeSave();

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Eav\Model\Config;
1212
use Magento\Eav\Model\Entity\Type;
1313
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory;
14+
use Magento\Framework\App\ObjectManager;
1415
use Magento\Store\Model\Store;
1516
use Magento\Store\Model\StoreManagerInterface;
1617
use Magento\Ui\Component\Form\Field;
@@ -116,7 +117,7 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
116117
/**
117118
* @var AuthorizationInterface
118119
*/
119-
private $auth;
120+
private $authorization;
120121

121122
/**
122123
* DataProvider constructor
@@ -133,7 +134,7 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
133134
* @param CategoryFactory $categoryFactory
134135
* @param array $meta
135136
* @param array $data
136-
* @param AuthorizationInterface|null $auth
137+
* @param AuthorizationInterface|null $authorization
137138
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
138139
*/
139140
public function __construct(
@@ -149,7 +150,7 @@ public function __construct(
149150
CategoryFactory $categoryFactory,
150151
array $meta = [],
151152
array $data = [],
152-
AuthorizationInterface $auth = null
153+
AuthorizationInterface $authorization = null
153154
) {
154155
$this->eavValidationRules = $eavValidationRules;
155156
$this->collection = $categoryCollectionFactory->create();
@@ -159,7 +160,7 @@ public function __construct(
159160
$this->storeManager = $storeManager;
160161
$this->request = $request;
161162
$this->categoryFactory = $categoryFactory;
162-
$this->auth = $auth ?: \Magento\Framework\App\ObjectManager::getInstance()->get(AuthorizationInterface::class);
163+
$this->authorization = $authorization ?: ObjectManager::getInstance()->get(AuthorizationInterface::class);
163164

164165
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
165166
$this->meta = $this->prepareMeta($this->meta);
@@ -190,7 +191,7 @@ public function prepareMeta($meta)
190191
*/
191192
private function prepareFieldsMeta($fieldsMap, $fieldsMeta)
192193
{
193-
$canEditDesign = $this->auth->isAllowed('Magento_Catalog::edit_category_design');
194+
$canEditDesign = $this->authorization->isAllowed('Magento_Catalog::edit_category_design');
194195

195196
$result = [];
196197
foreach ($fieldsMap as $fieldSet => $fields) {

app/code/Magento/Catalog/Model/Product.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,9 @@ public function beforeSave()
881881
$this->setData('page_layout', $this->getOrigData('page_layout'));
882882
$this->setData('options_container', $this->getOrigData('options_container'));
883883
$this->setData('custom_layout_update', $this->getOrigData('custom_layout_update'));
884+
$this->setData('custom_design_from', $this->getOrigData('custom_design_from'));
885+
$this->setData('custom_design_to', $this->getOrigData('custom_design_to'));
886+
$this->setData('custom_layout', $this->getOrigData('custom_layout'));
884887
}
885888

886889
$hasOptions = false;

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,22 @@ class Eav extends AbstractModifier
172172
/**
173173
* @var AuthorizationInterface
174174
*/
175-
private $auth;
175+
private $authorization;
176+
177+
/**
178+
* Product design attribute codes.
179+
*
180+
* @var array
181+
*/
182+
private $designAttributeCodes = [
183+
'custom_design',
184+
'page_layout',
185+
'options_container',
186+
'custom_layout_update',
187+
'custom_design_from',
188+
'custom_design_to',
189+
'custom_layout',
190+
];
176191

177192
/**
178193
* @param LocatorInterface $locator
@@ -194,7 +209,7 @@ class Eav extends AbstractModifier
194209
* @param DataPersistorInterface $dataPersistor
195210
* @param array $attributesToDisable
196211
* @param array $attributesToEliminate
197-
* @param AuthorizationInterface|null $auth
212+
* @param AuthorizationInterface|null $authorization
198213
*
199214
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
200215
*/
@@ -218,7 +233,7 @@ public function __construct(
218233
DataPersistorInterface $dataPersistor,
219234
$attributesToDisable = [],
220235
$attributesToEliminate = [],
221-
AuthorizationInterface $auth = null
236+
AuthorizationInterface $authorization = null
222237
) {
223238
$this->locator = $locator;
224239
$this->catalogEavValidationRules = $catalogEavValidationRules;
@@ -239,7 +254,7 @@ public function __construct(
239254
$this->dataPersistor = $dataPersistor;
240255
$this->attributesToDisable = $attributesToDisable;
241256
$this->attributesToEliminate = $attributesToEliminate;
242-
$this->auth = $auth ?: ObjectManager::getInstance()->get(AuthorizationInterface::class);
257+
$this->authorization = $authorization ?: ObjectManager::getInstance()->get(AuthorizationInterface::class);
243258
}
244259

245260
/**
@@ -636,9 +651,8 @@ public function setupAttributeMeta(ProductAttributeInterface $attribute, $groupC
636651
}
637652

638653
//Checking access to design config.
639-
$designAttributeCodes = ['custom_design', 'page_layout', 'options_container', 'custom_layout_update'];
640-
if (in_array($attributeCode, $designAttributeCodes, true)) {
641-
if (!$this->auth->isAllowed('Magento_Catalog::edit_product_design')) {
654+
if (in_array($attributeCode, $this->designAttributeCodes, true)) {
655+
if (!$this->authorization->isAllowed('Magento_Catalog::edit_product_design')) {
642656
$meta = $this->arrayManager->merge(
643657
$configPath,
644658
$meta,

app/code/Magento/Cms/Model/Page/DataProvider.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
3333
/**
3434
* @var AuthorizationInterface
3535
*/
36-
protected $auth;
36+
private $authorization;
3737

3838
/**
3939
* @param string $name
@@ -43,7 +43,7 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
4343
* @param DataPersistorInterface $dataPersistor
4444
* @param array $meta
4545
* @param array $data
46-
* @param AuthorizationInterface|null $auth
46+
* @param AuthorizationInterface|null $authorization
4747
*/
4848
public function __construct(
4949
$name,
@@ -53,12 +53,12 @@ public function __construct(
5353
DataPersistorInterface $dataPersistor,
5454
array $meta = [],
5555
array $data = [],
56-
AuthorizationInterface $auth = null
56+
AuthorizationInterface $authorization = null
5757
) {
5858
$this->collection = $pageCollectionFactory->create();
5959
$this->dataPersistor = $dataPersistor;
6060
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
61-
$this->auth = $auth ?: ObjectManager::getInstance()->get(AuthorizationInterface::class);
61+
$this->authorization = $authorization ?: ObjectManager::getInstance()->get(AuthorizationInterface::class);
6262
$this->meta = $this->prepareMeta($this->meta);
6363
}
6464

@@ -107,7 +107,7 @@ public function getMeta()
107107
{
108108
$meta = parent::getMeta();
109109

110-
if (!$this->auth->isAllowed('Magento_Cms::save_design')) {
110+
if (!$this->authorization->isAllowed('Magento_Cms::save_design')) {
111111
$designMeta = [
112112
'design' => [
113113
'arguments' => [
@@ -118,6 +118,15 @@ public function getMeta()
118118
],
119119
],
120120
],
121+
'custom_design_update' => [
122+
'arguments' => [
123+
'data' => [
124+
'config' => [
125+
'disabled' => true,
126+
],
127+
],
128+
],
129+
],
121130
];
122131
$meta = array_merge_recursive($meta, $designMeta);
123132
}

app/code/Magento/Cms/Model/PageRepository.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,18 @@ public function save(\Magento\Cms\Api\Data\PageInterface $page)
139139
$page->setPageLayout(null);
140140
$page->setCustomTheme(null);
141141
$page->setCustomLayoutUpdateXml(null);
142+
$page->setCustomRootTemplate(null);
143+
$page->setCustomThemeFrom(null);
144+
$page->setCustomThemeTo(null);
142145
} else {
143146
$savedPage = $this->getById($page->getId());
144147
$page->setLayoutUpdateXml($savedPage->getLayoutUpdateXml());
145148
$page->setPageLayout($savedPage->getPageLayout());
146149
$page->setCustomTheme($savedPage->getCustomTheme());
147150
$page->setCustomLayoutUpdateXml($savedPage->getCustomLayoutUpdateXml());
151+
$page->setCustomRootTemplate($savedPage->getCustomRootTemplate());
152+
$page->setCustomThemeFrom($savedPage->getCustomThemeFrom());
153+
$page->setCustomThemeTo($savedPage->getCustomThemeTo());
148154
}
149155
}
150156

dev/tests/integration/testsuite/Magento/Catalog/Model/CategoryRepositoryTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class CategoryRepositoryTest extends \PHPUnit_Framework_TestCase
2727
/**
2828
* @var Auth
2929
*/
30-
private $auth;
30+
private $authorization;
3131

3232
/**
3333
* @var Builder
@@ -42,7 +42,7 @@ class CategoryRepositoryTest extends \PHPUnit_Framework_TestCase
4242
protected function setUp()
4343
{
4444
$this->repository = Bootstrap::getObjectManager()->create(CategoryRepositoryInterface::class);
45-
$this->auth = Bootstrap::getObjectManager()->get(Auth::class);
45+
$this->authorization = Bootstrap::getObjectManager()->get(Auth::class);
4646
$this->aclBuilder = Bootstrap::getObjectManager()->get(Builder::class);
4747
}
4848

@@ -53,7 +53,7 @@ protected function tearDown()
5353
{
5454
parent::tearDown();
5555

56-
$this->auth->logout();
56+
$this->authorization->logout();
5757
}
5858

5959
/**
@@ -67,7 +67,7 @@ protected function tearDown()
6767
public function testSaveDesign()
6868
{
6969
$category = $this->repository->get(333);
70-
$this->auth->login(TestBootstrap::ADMIN_NAME, TestBootstrap::ADMIN_PASSWORD);
70+
$this->authorization->login(TestBootstrap::ADMIN_NAME, TestBootstrap::ADMIN_PASSWORD);
7171

7272
//Admin doesn't have access to category's design.
7373
$this->aclBuilder->getAcl()->deny(null, 'Magento_Catalog::edit_category_design');

dev/tests/integration/testsuite/Magento/Catalog/Model/ProductRepositoryTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ProductRepositoryTest extends \PHPUnit_Framework_TestCase
3030
/**
3131
* @var Auth
3232
*/
33-
private $auth;
33+
private $authorization;
3434

3535
/**
3636
* @var Builder
@@ -43,7 +43,7 @@ class ProductRepositoryTest extends \PHPUnit_Framework_TestCase
4343
protected function setUp()
4444
{
4545
$this->productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
46-
$this->auth = Bootstrap::getObjectManager()->get(Auth::class);
46+
$this->authorization = Bootstrap::getObjectManager()->get(Auth::class);
4747
$this->aclBuilder = Bootstrap::getObjectManager()->get(Builder::class);
4848
}
4949

@@ -54,7 +54,7 @@ protected function tearDown()
5454
{
5555
parent::tearDown();
5656

57-
$this->auth->logout();
57+
$this->authorization->logout();
5858
}
5959

6060
/**
@@ -66,7 +66,7 @@ protected function tearDown()
6666
public function testSaveDesign()
6767
{
6868
$product = $this->productRepository->get('simple');
69-
$this->auth->login(TestBootstrap::ADMIN_NAME, TestBootstrap::ADMIN_PASSWORD);
69+
$this->authorization->login(TestBootstrap::ADMIN_NAME, TestBootstrap::ADMIN_PASSWORD);
7070

7171
//Admin doesn't have access to product's design.
7272
$this->aclBuilder->getAcl()->deny(null, 'Magento_Catalog::edit_product_design');

dev/tests/integration/testsuite/Magento/Cms/Model/PageRepositoryTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class PageRepositoryTest extends \PHPUnit_Framework_TestCase
2929
/**
3030
* @var Auth
3131
*/
32-
private $auth;
32+
private $authorization;
3333

3434
/**
3535
* @var SearchCriteriaBuilder
@@ -54,7 +54,7 @@ class PageRepositoryTest extends \PHPUnit_Framework_TestCase
5454
protected function setUp()
5555
{
5656
$this->repository = Bootstrap::getObjectManager()->create(PageRepositoryInterface::class);
57-
$this->auth = Bootstrap::getObjectManager()->get(Auth::class);
57+
$this->authorization = Bootstrap::getObjectManager()->get(Auth::class);
5858
$this->criteriaBuilder = Bootstrap::getObjectManager()->get(SearchCriteriaBuilder::class);
5959
$this->aclBuilder = Bootstrap::getObjectManager()->get(Builder::class);
6060
$this->pageCollectionFactory = Bootstrap::getObjectManager()->get(PageCollectionFactory::class);
@@ -67,7 +67,7 @@ protected function tearDown()
6767
{
6868
parent::tearDown();
6969

70-
$this->auth->logout();
70+
$this->authorization->logout();
7171
}
7272

7373
/**
@@ -84,7 +84,7 @@ public function testSaveDesign()
8484
$pagesCollection->addFieldToFilter('identifier', ['eq' => 'page_design_blank']);
8585
$page = $pagesCollection->getFirstItem();
8686

87-
$this->auth->login(TestBootstrap::ADMIN_NAME, TestBootstrap::ADMIN_PASSWORD);
87+
$this->authorization->login(TestBootstrap::ADMIN_NAME, TestBootstrap::ADMIN_PASSWORD);
8888

8989
//Admin doesn't have access to page's design.
9090
$this->aclBuilder->getAcl()->deny(null, 'Magento_Cms::save_design');

0 commit comments

Comments
 (0)