Skip to content

Commit e8c98e3

Browse files
merge magento/2.3-qwerty into magento-arcticfoxes/2.3-qwerty-pr
2 parents cdd0845 + 0c8932c commit e8c98e3

File tree

26 files changed

+587
-46
lines changed

26 files changed

+587
-46
lines changed

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

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
*/
66
namespace Magento\Catalog\Model;
77

8+
use Magento\Authorization\Model\UserContextInterface;
89
use Magento\Catalog\Api\CategoryRepositoryInterface;
910
use Magento\Catalog\Api\Data\CategoryInterface;
1011
use Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator;
1112
use Magento\Framework\Api\AttributeValueFactory;
13+
use Magento\Framework\App\ObjectManager;
14+
use Magento\Framework\AuthorizationInterface;
1215
use Magento\Framework\Convert\ConvertArray;
1316
use Magento\Framework\Exception\NoSuchEntityException;
1417
use Magento\Framework\Profiler;
@@ -211,6 +214,16 @@ class Category extends \Magento\Catalog\Model\AbstractModel implements
211214
*/
212215
protected $metadataService;
213216

217+
/**
218+
* @var UserContextInterface
219+
*/
220+
private $userContext;
221+
222+
/**
223+
* @var AuthorizationInterface
224+
*/
225+
private $authorization;
226+
214227
/**
215228
* @param \Magento\Framework\Model\Context $context
216229
* @param \Magento\Framework\Registry $registry
@@ -233,6 +246,8 @@ class Category extends \Magento\Catalog\Model\AbstractModel implements
233246
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
234247
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
235248
* @param array $data
249+
* @param UserContextInterface|null $userContext
250+
* @param AuthorizationInterface|null $authorization
236251
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
237252
*/
238253
public function __construct(
@@ -256,7 +271,9 @@ public function __construct(
256271
CategoryRepositoryInterface $categoryRepository,
257272
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
258273
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
259-
array $data = []
274+
array $data = [],
275+
?UserContextInterface $userContext = null,
276+
?AuthorizationInterface $authorization = null
260277
) {
261278
$this->metadataService = $metadataService;
262279
$this->_treeModel = $categoryTreeResource;
@@ -281,6 +298,8 @@ public function __construct(
281298
$resourceCollection,
282299
$data
283300
);
301+
$this->userContext = $userContext ?? ObjectManager::getInstance()->get(UserContextInterface::class);
302+
$this->authorization = $authorization ?? ObjectManager::getInstance()->get(AuthorizationInterface::class);
284303
}
285304

286305
/**
@@ -311,6 +330,7 @@ protected function getCustomAttributesCodes()
311330
return $this->customAttributesCodes;
312331
}
313332

333+
// phpcs:disable Generic.CodeAnalysis.UselessOverridingMethod
314334
/**
315335
* Returns model resource
316336
*
@@ -322,6 +342,7 @@ protected function _getResource()
322342
{
323343
return parent::_getResource();
324344
}
345+
// phpcs:enable
325346

326347
/**
327348
* Get flat resource model flag
@@ -914,6 +935,32 @@ public function beforeDelete()
914935
return parent::beforeDelete();
915936
}
916937

938+
/**
939+
* @inheritDoc
940+
*/
941+
public function beforeSave()
942+
{
943+
//Validate changing of design.
944+
$userType = $this->userContext->getUserType();
945+
if ((
946+
$userType === UserContextInterface::USER_TYPE_ADMIN
947+
|| $userType === UserContextInterface::USER_TYPE_INTEGRATION
948+
)
949+
&& !$this->authorization->isAllowed('Magento_Catalog::edit_category_design')
950+
) {
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+
}
959+
}
960+
961+
return parent::beforeSave();
962+
}
963+
917964
/**
918965
* Retrieve anchors above
919966
*

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@
2525
use Magento\Ui\Component\Form\Field;
2626
use Magento\Ui\DataProvider\EavValidationRules;
2727
use Magento\Ui\DataProvider\Modifier\PoolInterface;
28+
use Magento\Framework\AuthorizationInterface;
2829

2930
/**
3031
* Class DataProvider
3132
*
3233
* @api
3334
*
3435
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
36+
* @SuppressWarnings(PHPMD.TooManyFields)
3537
* @since 101.0.0
3638
*/
3739
class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
@@ -146,6 +148,11 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
146148
*/
147149
private $fileInfo;
148150

151+
/**
152+
* @var AuthorizationInterface
153+
*/
154+
private $auth;
155+
149156
/**
150157
* DataProvider constructor
151158
*
@@ -162,6 +169,7 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
162169
* @param array $meta
163170
* @param array $data
164171
* @param PoolInterface|null $pool
172+
* @param AuthorizationInterface|null $auth
165173
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
166174
*/
167175
public function __construct(
@@ -177,7 +185,8 @@ public function __construct(
177185
CategoryFactory $categoryFactory,
178186
array $meta = [],
179187
array $data = [],
180-
PoolInterface $pool = null
188+
PoolInterface $pool = null,
189+
?AuthorizationInterface $auth = null
181190
) {
182191
$this->eavValidationRules = $eavValidationRules;
183192
$this->collection = $categoryCollectionFactory->create();
@@ -187,6 +196,7 @@ public function __construct(
187196
$this->storeManager = $storeManager;
188197
$this->request = $request;
189198
$this->categoryFactory = $categoryFactory;
199+
$this->auth = $auth ?? ObjectManager::getInstance()->get(AuthorizationInterface::class);
190200

191201
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data, $pool);
192202
}
@@ -210,6 +220,8 @@ public function getMeta()
210220
}
211221

212222
/**
223+
* Disable fields if they are using default values.
224+
*
213225
* @param Category $category
214226
* @param array $meta
215227
* @return array
@@ -277,11 +289,20 @@ public function prepareMeta($meta)
277289
*/
278290
private function prepareFieldsMeta($fieldsMap, $fieldsMeta)
279291
{
292+
$canEditDesign = $this->auth->isAllowed('Magento_Catalog::edit_category_design');
293+
280294
$result = [];
281295
foreach ($fieldsMap as $fieldSet => $fields) {
282296
foreach ($fields as $field) {
283297
if (isset($fieldsMeta[$field])) {
284-
$result[$fieldSet]['children'][$field]['arguments']['data']['config'] = $fieldsMeta[$field];
298+
$config = $fieldsMeta[$field];
299+
if (($fieldSet === 'design' || $fieldSet === 'schedule_design_update') && !$canEditDesign) {
300+
$config['required'] = 1;
301+
$config['disabled'] = 1;
302+
$config['serviceDisabled'] = true;
303+
}
304+
305+
$result[$fieldSet]['children'][$field]['arguments']['data']['config'] = $config;
285306
}
286307
}
287308
}
@@ -498,6 +519,7 @@ private function convertValues($category, $categoryData)
498519
$stat = $fileInfo->getStat($fileName);
499520
$mime = $fileInfo->getMimeType($fileName);
500521

522+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
501523
$categoryData[$attributeCode][0]['name'] = basename($fileName);
502524

503525
if ($fileInfo->isBeginsWithMediaDirectoryPath($fileName)) {
@@ -533,6 +555,8 @@ public function getDefaultMetaData($result)
533555
}
534556

535557
/**
558+
* List of fields groups and fields.
559+
*
536560
* @return array
537561
* @since 101.0.0
538562
*/

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use Magento\Catalog\Api\Data\CategoryInterface;
1414

1515
/**
16+
* Repository for categories.
17+
*
1618
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1719
*/
1820
class CategoryRepository implements \Magento\Catalog\Api\CategoryRepositoryInterface
@@ -70,7 +72,7 @@ public function __construct(
7072
}
7173

7274
/**
73-
* {@inheritdoc}
75+
* @inheritdoc
7476
*/
7577
public function save(\Magento\Catalog\Api\Data\CategoryInterface $category)
7678
{
@@ -125,7 +127,7 @@ public function save(\Magento\Catalog\Api\Data\CategoryInterface $category)
125127
}
126128

127129
/**
128-
* {@inheritdoc}
130+
* @inheritdoc
129131
*/
130132
public function get($categoryId, $storeId = null)
131133
{
@@ -146,7 +148,7 @@ public function get($categoryId, $storeId = null)
146148
}
147149

148150
/**
149-
* {@inheritdoc}
151+
* @inheritdoc
150152
*/
151153
public function delete(\Magento\Catalog\Api\Data\CategoryInterface $category)
152154
{
@@ -167,7 +169,7 @@ public function delete(\Magento\Catalog\Api\Data\CategoryInterface $category)
167169
}
168170

169171
/**
170-
* {@inheritdoc}
172+
* @inheritdoc
171173
*/
172174
public function deleteByIdentifier($categoryId)
173175
{
@@ -208,6 +210,8 @@ protected function validateCategory(Category $category)
208210
}
209211

210212
/**
213+
* Lazy loader for the converter.
214+
*
211215
* @return \Magento\Framework\Api\ExtensibleDataObjectConverter
212216
*
213217
* @deprecated 101.0.0
@@ -222,6 +226,8 @@ private function getExtensibleDataObjectConverter()
222226
}
223227

224228
/**
229+
* Lazy loader for the metadata pool.
230+
*
225231
* @return \Magento\Framework\EntityManager\MetadataPool
226232
*/
227233
private function getMetadataPool()

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

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Catalog\Model;
77

8+
use Magento\Authorization\Model\UserContextInterface;
89
use Magento\Catalog\Api\CategoryRepositoryInterface;
910
use Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface;
1011
use Magento\Catalog\Api\Data\ProductInterface;
@@ -14,6 +15,7 @@
1415
use Magento\Framework\Api\AttributeValueFactory;
1516
use Magento\Framework\App\Filesystem\DirectoryList;
1617
use Magento\Framework\App\ObjectManager;
18+
use Magento\Framework\AuthorizationInterface;
1719
use Magento\Framework\DataObject\IdentityInterface;
1820
use Magento\Framework\Pricing\SaleableInterface;
1921

@@ -353,6 +355,16 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
353355
*/
354356
private $filterCustomAttribute;
355357

358+
/**
359+
* @var UserContextInterface
360+
*/
361+
private $userContext;
362+
363+
/**
364+
* @var AuthorizationInterface
365+
*/
366+
private $authorization;
367+
356368
/**
357369
* @param \Magento\Framework\Model\Context $context
358370
* @param \Magento\Framework\Registry $registry
@@ -391,6 +403,8 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
391403
* @param array $data
392404
* @param \Magento\Eav\Model\Config|null $config
393405
* @param FilterProductCustomAttribute|null $filterCustomAttribute
406+
* @param UserContextInterface|null $userContext
407+
* @param AuthorizationInterface|null $authorization
394408
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
395409
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
396410
*/
@@ -431,7 +445,9 @@ public function __construct(
431445
\Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $joinProcessor,
432446
array $data = [],
433447
\Magento\Eav\Model\Config $config = null,
434-
FilterProductCustomAttribute $filterCustomAttribute = null
448+
FilterProductCustomAttribute $filterCustomAttribute = null,
449+
?UserContextInterface $userContext = null,
450+
?AuthorizationInterface $authorization = null
435451
) {
436452
$this->metadataService = $metadataService;
437453
$this->_itemOptionFactory = $itemOptionFactory;
@@ -473,6 +489,8 @@ public function __construct(
473489
$this->eavConfig = $config ?? ObjectManager::getInstance()->get(\Magento\Eav\Model\Config::class);
474490
$this->filterCustomAttribute = $filterCustomAttribute
475491
?? ObjectManager::getInstance()->get(FilterProductCustomAttribute::class);
492+
$this->userContext = $userContext ?? ObjectManager::getInstance()->get(UserContextInterface::class);
493+
$this->authorization = $authorization ?? ObjectManager::getInstance()->get(AuthorizationInterface::class);
476494
}
477495

478496
/**
@@ -485,6 +503,7 @@ protected function _construct()
485503
$this->_init(\Magento\Catalog\Model\ResourceModel\Product::class);
486504
}
487505

506+
// phpcs:disable Generic.CodeAnalysis.UselessOverridingMethod
488507
/**
489508
* Get resource instance
490509
*
@@ -496,6 +515,7 @@ protected function _getResource()
496515
{
497516
return parent::_getResource();
498517
}
518+
// phpcs:enable
499519

500520
/**
501521
* Get a list of custom attribute codes that belongs to product attribute set.
@@ -874,6 +894,22 @@ public function beforeSave()
874894

875895
$this->getTypeInstance()->beforeSave($this);
876896

897+
//Validate changing of design.
898+
$userType = $this->userContext->getUserType();
899+
if ((
900+
$userType === UserContextInterface::USER_TYPE_ADMIN
901+
|| $userType === UserContextInterface::USER_TYPE_INTEGRATION
902+
)
903+
&& !$this->authorization->isAllowed('Magento_Catalog::edit_product_design')
904+
) {
905+
$this->setData('custom_design', $this->getOrigData('custom_design'));
906+
$this->setData('page_layout', $this->getOrigData('page_layout'));
907+
$this->setData('options_container', $this->getOrigData('options_container'));
908+
$this->setData('custom_layout_update', $this->getOrigData('custom_layout_update'));
909+
$this->setData('custom_design_from', $this->getOrigData('custom_design_from'));
910+
$this->setData('custom_design_to', $this->getOrigData('custom_design_to'));
911+
}
912+
877913
$hasOptions = false;
878914
$hasRequiredOptions = false;
879915

@@ -1166,7 +1202,7 @@ public function getFormattedPrice()
11661202
/**
11671203
* Get formatted by currency product price
11681204
*
1169-
* @return array|double
1205+
* @return array|double
11701206
*
11711207
* @deprecated
11721208
* @see getFormattedPrice()
@@ -1817,7 +1853,7 @@ public function formatUrlKey($str)
18171853
/**
18181854
* Save current attribute with code $code and assign new value
18191855
*
1820-
* @param string $code Attribute code
1856+
* @param string $code Attribute code
18211857
* @param mixed $value New attribute value
18221858
* @param int $store Store ID
18231859
* @return void

0 commit comments

Comments
 (0)