Skip to content

Commit a270d71

Browse files
Merge pull request #4252 from magento-qwerty/MAGETWO-99818
Fixed Issues: - MAGETWO-99818: [2.2.x] Remove new dependencies added for design edit validations
2 parents 41268ba + 222838c commit a270d71

File tree

3 files changed

+93
-27
lines changed

3 files changed

+93
-27
lines changed

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

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,6 @@ class Category extends \Magento\Catalog\Model\AbstractModel implements
277277
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
278278
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
279279
* @param array $data
280-
* @param UserContextInterface|null $userContext
281-
* @param AuthorizationInterface|null $authorization
282280
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
283281
*/
284282
public function __construct(
@@ -302,9 +300,7 @@ public function __construct(
302300
CategoryRepositoryInterface $categoryRepository,
303301
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
304302
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
305-
array $data = [],
306-
UserContextInterface $userContext = null,
307-
AuthorizationInterface $authorization = null
303+
array $data = []
308304
) {
309305
$this->metadataService = $metadataService;
310306
$this->_treeModel = $categoryTreeResource;
@@ -329,8 +325,6 @@ public function __construct(
329325
$resourceCollection,
330326
$data
331327
);
332-
$this->userContext = $userContext ?? ObjectManager::getInstance()->get(UserContextInterface::class);
333-
$this->authorization = $authorization ?? ObjectManager::getInstance()->get(AuthorizationInterface::class);
334328
}
335329

336330
/**
@@ -945,16 +939,44 @@ public function beforeDelete()
945939
return parent::beforeDelete();
946940
}
947941

942+
/**
943+
* Get user context.
944+
*
945+
* @return UserContextInterface
946+
*/
947+
private function getUserContext(): UserContextInterface
948+
{
949+
if (!$this->userContext) {
950+
$this->userContext = ObjectManager::getInstance()->get(UserContextInterface::class);
951+
}
952+
953+
return $this->userContext;
954+
}
955+
956+
/**
957+
* Get authorization service.
958+
*
959+
* @return AuthorizationInterface
960+
*/
961+
private function getAuthorization(): AuthorizationInterface
962+
{
963+
if (!$this->authorization) {
964+
$this->authorization = ObjectManager::getInstance()->get(AuthorizationInterface::class);
965+
}
966+
967+
return $this->authorization;
968+
}
969+
948970
/**
949971
* @inheritdoc
950972
*/
951973
public function beforeSave()
952974
{
953975
//Validate changing of design.
954-
$userType = $this->userContext->getUserType();
976+
$userType = $this->getUserContext()->getUserType();
955977
if (($userType === UserContextInterface::USER_TYPE_ADMIN
956978
|| $userType === UserContextInterface::USER_TYPE_INTEGRATION)
957-
&& !$this->authorization->isAllowed('Magento_Catalog::edit_category_design')
979+
&& !$this->getAuthorization()->isAllowed('Magento_Catalog::edit_category_design')
958980
) {
959981
foreach ($this->_designAttributes as $attributeCode) {
960982
$this->setData($attributeCode, $value = $this->getOrigData($attributeCode));

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

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,6 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
408408
* @param \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $joinProcessor
409409
* @param array $data
410410
* @param \Magento\Eav\Model\Config|null $config
411-
* @param UserContextInterface|null $userContext
412-
* @param AuthorizationInterface|null $authorization
413411
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
414412
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
415413
*/
@@ -449,9 +447,7 @@ public function __construct(
449447
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
450448
\Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $joinProcessor,
451449
array $data = [],
452-
\Magento\Eav\Model\Config $config = null,
453-
UserContextInterface $userContext = null,
454-
AuthorizationInterface $authorization = null
450+
\Magento\Eav\Model\Config $config = null
455451
) {
456452
$this->metadataService = $metadataService;
457453
$this->_itemOptionFactory = $itemOptionFactory;
@@ -491,8 +487,6 @@ public function __construct(
491487
$data
492488
);
493489
$this->eavConfig = $config ?? ObjectManager::getInstance()->get(\Magento\Eav\Model\Config::class);
494-
$this->userContext = $userContext ?? ObjectManager::getInstance()->get(UserContextInterface::class);
495-
$this->authorization = $authorization ?? ObjectManager::getInstance()->get(AuthorizationInterface::class);
496490
}
497491

498492
/**
@@ -866,6 +860,34 @@ public function getAttributes($groupId = null, $skipSuper = false)
866860
return $attributes;
867861
}
868862

863+
/**
864+
* Get user context.
865+
*
866+
* @return UserContextInterface
867+
*/
868+
private function getUserContext(): UserContextInterface
869+
{
870+
if (!$this->userContext) {
871+
$this->userContext = ObjectManager::getInstance()->get(UserContextInterface::class);
872+
}
873+
874+
return $this->userContext;
875+
}
876+
877+
/**
878+
* Get authorization service.
879+
*
880+
* @return AuthorizationInterface
881+
*/
882+
private function getAuthorization(): AuthorizationInterface
883+
{
884+
if (!$this->authorization) {
885+
$this->authorization = ObjectManager::getInstance()->get(AuthorizationInterface::class);
886+
}
887+
888+
return $this->authorization;
889+
}
890+
869891
/**
870892
* Check product options and type options and save them, too
871893
*
@@ -884,10 +906,10 @@ public function beforeSave()
884906
$this->getTypeInstance()->beforeSave($this);
885907

886908
//Validate changing of design.
887-
$userType = $this->userContext->getUserType();
909+
$userType = $this->getUserContext()->getUserType();
888910
if (($userType === UserContextInterface::USER_TYPE_ADMIN
889911
|| $userType === UserContextInterface::USER_TYPE_INTEGRATION)
890-
&& !$this->authorization->isAllowed('Magento_Catalog::edit_product_design')
912+
&& !$this->getAuthorization()->isAllowed('Magento_Catalog::edit_product_design')
891913
) {
892914
$this->setData('custom_design', $this->getOrigData('custom_design'));
893915
$this->setData('page_layout', $this->getOrigData('page_layout'));

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

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ class PageRepository implements PageRepositoryInterface
9191
* @param DataObjectProcessor $dataObjectProcessor
9292
* @param StoreManagerInterface $storeManager
9393
* @param CollectionProcessorInterface $collectionProcessor
94-
* @param UserContextInterface|null $userContext
95-
* @param AuthorizationInterface|null $authorization
9694
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
9795
*/
9896
public function __construct(
@@ -104,9 +102,7 @@ public function __construct(
104102
DataObjectHelper $dataObjectHelper,
105103
DataObjectProcessor $dataObjectProcessor,
106104
StoreManagerInterface $storeManager,
107-
CollectionProcessorInterface $collectionProcessor = null,
108-
UserContextInterface $userContext = null,
109-
AuthorizationInterface $authorization = null
105+
CollectionProcessorInterface $collectionProcessor = null
110106
) {
111107
$this->resource = $resource;
112108
$this->pageFactory = $pageFactory;
@@ -117,8 +113,34 @@ public function __construct(
117113
$this->dataObjectProcessor = $dataObjectProcessor;
118114
$this->storeManager = $storeManager;
119115
$this->collectionProcessor = $collectionProcessor ?: $this->getCollectionProcessor();
120-
$this->userContext = $userContext ?? ObjectManager::getInstance()->get(UserContextInterface::class);
121-
$this->authorization = $authorization ?? ObjectManager::getInstance()->get(AuthorizationInterface::class);
116+
}
117+
118+
/**
119+
* Get user context.
120+
*
121+
* @return UserContextInterface
122+
*/
123+
private function getUserContext(): UserContextInterface
124+
{
125+
if (!$this->userContext) {
126+
$this->userContext = ObjectManager::getInstance()->get(UserContextInterface::class);
127+
}
128+
129+
return $this->userContext;
130+
}
131+
132+
/**
133+
* Get authorization service.
134+
*
135+
* @return AuthorizationInterface
136+
*/
137+
private function getAuthorization(): AuthorizationInterface
138+
{
139+
if (!$this->authorization) {
140+
$this->authorization = ObjectManager::getInstance()->get(AuthorizationInterface::class);
141+
}
142+
143+
return $this->authorization;
122144
}
123145

124146
/**
@@ -136,10 +158,10 @@ public function save(\Magento\Cms\Api\Data\PageInterface $page)
136158
}
137159
try {
138160
//Validate changing of design.
139-
$userType = $this->userContext->getUserType();
161+
$userType = $this->getUserContext()->getUserType();
140162
if (($userType === UserContextInterface::USER_TYPE_ADMIN
141163
|| $userType === UserContextInterface::USER_TYPE_INTEGRATION)
142-
&& !$this->authorization->isAllowed('Magento_Cms::save_design')
164+
&& !$this->getAuthorization()->isAllowed('Magento_Cms::save_design')
143165
) {
144166
if (!$page->getId()) {
145167
$page->setLayoutUpdateXml(null);

0 commit comments

Comments
 (0)