Skip to content

Commit e39bfb4

Browse files
committed
MAGETWO-98202: Additional Permissions for Design settings
1 parent 04c8c7b commit e39bfb4

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,7 @@ public function beforeSave()
948948
) {
949949
foreach ($this->_designAttributes as $attributeCode) {
950950
$this->setData($attributeCode, $this->getOrigData($attributeCode));
951+
$this->setCustomAttribute($attributeCode, $this->getOrigData($attributeCode));
951952
}
952953
}
953954

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

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
use Magento\Backend\Model\Auth;
1010
use Magento\Catalog\Api\CategoryRepositoryInterface;
11+
use Magento\Catalog\Api\Data\CategoryInterface;
12+
use Magento\Catalog\Api\Data\CategoryInterfaceFactory;
1113
use Magento\Framework\Acl\Builder;
1214
use Magento\Framework\Acl\CacheInterface;
1315
use Magento\TestFramework\Helper\Bootstrap;
@@ -40,6 +42,11 @@ class CategoryRepositoryTest extends \PHPUnit_Framework_TestCase
4042
*/
4143
private $aclCache;
4244

45+
/**
46+
* @var CategoryInterfaceFactory
47+
*/
48+
private $categoryFactory;
49+
4350
/**
4451
* Sets up common objects.
4552
*
@@ -51,6 +58,8 @@ protected function setUp()
5158
$this->authorization = Bootstrap::getObjectManager()->get(Auth::class);
5259
$this->aclBuilder = Bootstrap::getObjectManager()->get(Builder::class);
5360
$this->aclCache = Bootstrap::getObjectManager()->get(CacheInterface::class);
61+
$this->categoryFactory = Bootstrap::getObjectManager()->get(CategoryInterfaceFactory::class);
62+
$this->authorization->login(TestBootstrap::ADMIN_NAME, TestBootstrap::ADMIN_PASSWORD);
5463
}
5564

5665
/**
@@ -67,6 +76,7 @@ protected function tearDown()
6776
/**
6877
* Test authorization when saving category's design settings.
6978
*
79+
* @return CategoryInterface
7080
* @magentoDataFixture Magento/Catalog/_files/category.php
7181
* @magentoAppArea adminhtml
7282
* @magentoDbIsolation enabled
@@ -75,14 +85,14 @@ protected function tearDown()
7585
public function testSaveDesign()
7686
{
7787
$category = $this->repository->get(333);
78-
$this->authorization->login(TestBootstrap::ADMIN_NAME, TestBootstrap::ADMIN_PASSWORD);
7988

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

8392
$category->setCustomAttribute('custom_design', 2);
8493
$category = $this->repository->save($category);
85-
$this->assertEmpty($category->getCustomAttribute('custom_design'));
94+
$customDesignAttribute = $category->getCustomAttribute('custom_design');
95+
$this->assertTrue(!$customDesignAttribute || !$customDesignAttribute->getValue());
8696

8797
//Admin has access to category' design.
8898
$this->aclBuilder->getAcl()
@@ -92,5 +102,32 @@ public function testSaveDesign()
92102
$category = $this->repository->save($category);
93103
$this->assertNotEmpty($category->getCustomAttribute('custom_design'));
94104
$this->assertEquals(2, $category->getCustomAttribute('custom_design')->getValue());
105+
106+
return $category;
107+
}
108+
109+
/**
110+
* Test authorization when saving category's design settings with restricted permission.
111+
*
112+
* @param CategoryInterface $category
113+
* @return void
114+
* @magentoAppArea adminhtml
115+
* @magentoDbIsolation enabled
116+
* @magentoAppIsolation enabled
117+
* @depends testSaveDesign
118+
*/
119+
public function testSaveDesignWithRestrictedPermission(CategoryInterface $category)
120+
{
121+
/** @var CategoryInterface $newCategory */
122+
$newCategory = $this->categoryFactory->create();
123+
$newCategory->setName('new category without design');
124+
$newCategory->setParentId($category->getParentId());
125+
$newCategory->setIsActive(true);
126+
$this->aclBuilder->getAcl()->deny(null, 'Magento_Catalog::edit_category_design');
127+
$newCategory->setCustomAttribute('custom_design', 2);
128+
$newCategory = $this->repository->save($newCategory);
129+
$customDesignAttribute = $newCategory->getCustomAttribute('custom_design');
130+
131+
$this->assertTrue(!$customDesignAttribute || !$customDesignAttribute->getValue());
95132
}
96133
}

0 commit comments

Comments
 (0)