Skip to content

Commit b643af8

Browse files
author
Oleksandr Gorkun
committed
MC-13958: Additional Permissions for Design settings
1 parent 5a5b406 commit b643af8

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -948,12 +948,14 @@ public function beforeSave()
948948
)
949949
&& !$this->authorization->isAllowed('Magento_Catalog::edit_category_design')
950950
) {
951-
$this->setData('custom_design', $this->getOrigData('custom_design'));
952-
$this->setData('custom_design_from', $this->getOrigData('custom_design_from'));
953-
$this->setData('custom_design_to', $this->getOrigData('custom_design_to'));
954-
$this->setData('page_layout', $this->getOrigData('page_layout'));
955-
$this->setData('custom_layout_update', $this->getOrigData('custom_layout_update'));
956-
$this->setData('custom_apply_to_products', $this->getOrigData('custom_apply_to_products'));
951+
$this->getCustomAttributes();
952+
foreach ($this->_designAttributes as $attributeCode) {
953+
$this->setData($attributeCode, $value = $this->getOrigData($attributeCode));
954+
if (array_key_exists($attributeCode, $this->_data[self::CUSTOM_ATTRIBUTES])) {
955+
//In case custom attribute were used to update the entity.
956+
$this->_data[self::CUSTOM_ATTRIBUTES][$attributeCode]->setValue($value);
957+
}
958+
}
957959
}
958960

959961
return parent::beforeSave();

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

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

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ public function testSaveDesign()
8585

8686
$category->setCustomAttribute('custom_design', 2);
8787
$category = $this->repo->save($category);
88-
$this->assertEmpty($category->getCustomAttribute('custom_design'));
88+
$customDesignAttribute = $category->getCustomAttribute('custom_design');
89+
$this->assertTrue(!$customDesignAttribute || !$customDesignAttribute->getValue());
8990

9091
//Admin has access to category' design.
9192
$this->aclBuilder->getAcl()
@@ -105,6 +106,7 @@ public function testSaveDesign()
105106
$this->aclBuilder->getAcl()->deny(null, 'Magento_Catalog::edit_category_design');
106107
$newCategory->setCustomAttribute('custom_design', 2);
107108
$newCategory = $this->repo->save($newCategory);
108-
$this->assertEmpty($newCategory->getCustomAttribute('custom_design'));
109+
$customDesignAttribute = $newCategory->getCustomAttribute('custom_design');
110+
$this->assertTrue(!$customDesignAttribute || !$customDesignAttribute->getValue());
109111
}
110112
}

0 commit comments

Comments
 (0)