Skip to content

Commit 9e9262d

Browse files
author
Oleksandr Gorkun
committed
MC-13958: Additional Permissions for Design settings
1 parent f1c1e93 commit 9e9262d

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ public function save(\Magento\Catalog\Api\Data\CategoryInterface $category)
102102
}
103103
}
104104
} else {
105+
//Clearing all redundant data and using only properly extracted data for the entity.
106+
/** @var Category $category */
107+
$category = $this->categoryFactory->create();
105108
$parentId = $category->getParentId() ?: $this->storeManager->getStore()->getRootCategoryId();
106109
$parentCategory = $this->get($parentId, $storeId);
107110
$existingData['path'] = $parentCategory->getPath();

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,19 +1134,4 @@ private function getAggregateCount()
11341134
}
11351135
return $this->aggregateCount;
11361136
}
1137-
1138-
/**
1139-
* @inheritDoc
1140-
*
1141-
* @param CategoryEntity|object $object
1142-
*/
1143-
public function validate($object)
1144-
{
1145-
$isValid = parent::validate($object);
1146-
if ($isValid !== true) {
1147-
return $isValid;
1148-
}
1149-
1150-
return true;
1151-
}
11521137
}

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
use Magento\Backend\Model\Auth;
1111
use Magento\Catalog\Api\CategoryRepositoryInterface;
12+
use Magento\Catalog\Api\Data\CategoryInterface;
13+
use Magento\Catalog\Api\Data\CategoryInterfaceFactory;
1214
use Magento\Framework\Acl\Builder;
1315
use Magento\TestFramework\Helper\Bootstrap;
1416
use PHPUnit\Framework\TestCase;
@@ -36,6 +38,11 @@ class CategoryRepositoryTest extends TestCase
3638
*/
3739
private $aclBuilder;
3840

41+
/**
42+
* @var CategoryInterfaceFactory
43+
*/
44+
private $categoryFactory;
45+
3946
/**
4047
* Sets up common objects.
4148
*
@@ -46,6 +53,7 @@ protected function setUp()
4653
$this->repo = Bootstrap::getObjectManager()->create(CategoryRepositoryInterface::class);
4754
$this->auth = Bootstrap::getObjectManager()->get(Auth::class);
4855
$this->aclBuilder = Bootstrap::getObjectManager()->get(Builder::class);
56+
$this->categoryFactory = Bootstrap::getObjectManager()->get(CategoryInterfaceFactory::class);
4957
}
5058

5159
/**
@@ -87,5 +95,16 @@ public function testSaveDesign()
8795
$category = $this->repo->save($category);
8896
$this->assertNotEmpty($category->getCustomAttribute('custom_design'));
8997
$this->assertEquals(2, $category->getCustomAttribute('custom_design')->getValue());
98+
99+
//Creating a new one
100+
/** @var CategoryInterface $newCategory */
101+
$newCategory = $this->categoryFactory->create();
102+
$newCategory->setName('new category without design');
103+
$newCategory->setParentId($category->getParentId());
104+
$newCategory->setIsActive(true);
105+
$this->aclBuilder->getAcl()->deny(null, 'Magento_Catalog::edit_category_design');
106+
$newCategory->setCustomAttribute('custom_design', 2);
107+
$newCategory = $this->repo->save($newCategory);
108+
$this->assertEmpty($newCategory->getCustomAttribute('custom_design'));
90109
}
91110
}

0 commit comments

Comments
 (0)