Skip to content

Commit 8e4e59f

Browse files
author
Oleksandr Gorkun
committed
MAGETWO-99817: Remove new dependencies added for design edit validations
1 parent ce9b748 commit 8e4e59f

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
@@ -246,8 +246,6 @@ class Category extends \Magento\Catalog\Model\AbstractModel implements
246246
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
247247
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
248248
* @param array $data
249-
* @param UserContextInterface|null $userContext
250-
* @param AuthorizationInterface|null $authorization
251249
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
252250
*/
253251
public function __construct(
@@ -271,9 +269,7 @@ public function __construct(
271269
CategoryRepositoryInterface $categoryRepository,
272270
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
273271
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
274-
array $data = [],
275-
?UserContextInterface $userContext = null,
276-
?AuthorizationInterface $authorization = null
272+
array $data = []
277273
) {
278274
$this->metadataService = $metadataService;
279275
$this->_treeModel = $categoryTreeResource;
@@ -298,8 +294,6 @@ public function __construct(
298294
$resourceCollection,
299295
$data
300296
);
301-
$this->userContext = $userContext ?? ObjectManager::getInstance()->get(UserContextInterface::class);
302-
$this->authorization = $authorization ?? ObjectManager::getInstance()->get(AuthorizationInterface::class);
303297
}
304298

305299
/**
@@ -935,18 +929,46 @@ public function beforeDelete()
935929
return parent::beforeDelete();
936930
}
937931

932+
/**
933+
* Get user context.
934+
*
935+
* @return UserContextInterface
936+
*/
937+
private function getUserContext(): UserContextInterface
938+
{
939+
if (!$this->userContext) {
940+
$this->userContext = ObjectManager::getInstance()->get(UserContextInterface::class);
941+
}
942+
943+
return $this->userContext;
944+
}
945+
946+
/**
947+
* Get authorization service.
948+
*
949+
* @return AuthorizationInterface
950+
*/
951+
private function getAuthorization(): AuthorizationInterface
952+
{
953+
if (!$this->authorization) {
954+
$this->authorization = ObjectManager::getInstance()->get(AuthorizationInterface::class);
955+
}
956+
957+
return $this->authorization;
958+
}
959+
938960
/**
939961
* @inheritDoc
940962
*/
941963
public function beforeSave()
942964
{
943965
//Validate changing of design.
944-
$userType = $this->userContext->getUserType();
966+
$userType = $this->getUserContext()->getUserType();
945967
if ((
946968
$userType === UserContextInterface::USER_TYPE_ADMIN
947969
|| $userType === UserContextInterface::USER_TYPE_INTEGRATION
948970
)
949-
&& !$this->authorization->isAllowed('Magento_Catalog::edit_category_design')
971+
&& !$this->getAuthorization()->isAllowed('Magento_Catalog::edit_category_design')
950972
) {
951973
foreach ($this->_designAttributes as $attributeCode) {
952974
$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
@@ -403,8 +403,6 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
403403
* @param array $data
404404
* @param \Magento\Eav\Model\Config|null $config
405405
* @param FilterProductCustomAttribute|null $filterCustomAttribute
406-
* @param UserContextInterface|null $userContext
407-
* @param AuthorizationInterface|null $authorization
408406
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
409407
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
410408
*/
@@ -445,9 +443,7 @@ public function __construct(
445443
\Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $joinProcessor,
446444
array $data = [],
447445
\Magento\Eav\Model\Config $config = null,
448-
FilterProductCustomAttribute $filterCustomAttribute = null,
449-
?UserContextInterface $userContext = null,
450-
?AuthorizationInterface $authorization = null
446+
FilterProductCustomAttribute $filterCustomAttribute = null
451447
) {
452448
$this->metadataService = $metadataService;
453449
$this->_itemOptionFactory = $itemOptionFactory;
@@ -489,8 +485,6 @@ public function __construct(
489485
$this->eavConfig = $config ?? ObjectManager::getInstance()->get(\Magento\Eav\Model\Config::class);
490486
$this->filterCustomAttribute = $filterCustomAttribute
491487
?? ObjectManager::getInstance()->get(FilterProductCustomAttribute::class);
492-
$this->userContext = $userContext ?? ObjectManager::getInstance()->get(UserContextInterface::class);
493-
$this->authorization = $authorization ?? ObjectManager::getInstance()->get(AuthorizationInterface::class);
494488
}
495489

496490
/**
@@ -877,6 +871,34 @@ public function getAttributes($groupId = null, $skipSuper = false)
877871
return $attributes;
878872
}
879873

874+
/**
875+
* Get user context.
876+
*
877+
* @return UserContextInterface
878+
*/
879+
private function getUserContext(): UserContextInterface
880+
{
881+
if (!$this->userContext) {
882+
$this->userContext = ObjectManager::getInstance()->get(UserContextInterface::class);
883+
}
884+
885+
return $this->userContext;
886+
}
887+
888+
/**
889+
* Get authorization service.
890+
*
891+
* @return AuthorizationInterface
892+
*/
893+
private function getAuthorization(): AuthorizationInterface
894+
{
895+
if (!$this->authorization) {
896+
$this->authorization = ObjectManager::getInstance()->get(AuthorizationInterface::class);
897+
}
898+
899+
return $this->authorization;
900+
}
901+
880902
/**
881903
* Check product options and type options and save them, too
882904
*
@@ -895,12 +917,12 @@ public function beforeSave()
895917
$this->getTypeInstance()->beforeSave($this);
896918

897919
//Validate changing of design.
898-
$userType = $this->userContext->getUserType();
920+
$userType = $this->getUserContext()->getUserType();
899921
if ((
900922
$userType === UserContextInterface::USER_TYPE_ADMIN
901923
|| $userType === UserContextInterface::USER_TYPE_INTEGRATION
902924
)
903-
&& !$this->authorization->isAllowed('Magento_Catalog::edit_product_design')
925+
&& !$this->getAuthorization()->isAllowed('Magento_Catalog::edit_product_design')
904926
) {
905927
$this->setData('custom_design', $this->getOrigData('custom_design'));
906928
$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
@@ -92,8 +92,6 @@ class PageRepository implements PageRepositoryInterface
9292
* @param DataObjectProcessor $dataObjectProcessor
9393
* @param StoreManagerInterface $storeManager
9494
* @param CollectionProcessorInterface $collectionProcessor
95-
* @param UserContextInterface|null $userContext
96-
* @param AuthorizationInterface|null $authorization
9795
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
9896
*/
9997
public function __construct(
@@ -105,9 +103,7 @@ public function __construct(
105103
DataObjectHelper $dataObjectHelper,
106104
DataObjectProcessor $dataObjectProcessor,
107105
StoreManagerInterface $storeManager,
108-
CollectionProcessorInterface $collectionProcessor = null,
109-
?UserContextInterface $userContext = null,
110-
?AuthorizationInterface $authorization = null
106+
CollectionProcessorInterface $collectionProcessor = null
111107
) {
112108
$this->resource = $resource;
113109
$this->pageFactory = $pageFactory;
@@ -118,8 +114,34 @@ public function __construct(
118114
$this->dataObjectProcessor = $dataObjectProcessor;
119115
$this->storeManager = $storeManager;
120116
$this->collectionProcessor = $collectionProcessor ?: $this->getCollectionProcessor();
121-
$this->userContext = $userContext ?? ObjectManager::getInstance()->get(UserContextInterface::class);
122-
$this->authorization = $authorization ?? ObjectManager::getInstance()->get(AuthorizationInterface::class);
117+
}
118+
119+
/**
120+
* Get user context.
121+
*
122+
* @return UserContextInterface
123+
*/
124+
private function getUserContext(): UserContextInterface
125+
{
126+
if (!$this->userContext) {
127+
$this->userContext = ObjectManager::getInstance()->get(UserContextInterface::class);
128+
}
129+
130+
return $this->userContext;
131+
}
132+
133+
/**
134+
* Get authorization service.
135+
*
136+
* @return AuthorizationInterface
137+
*/
138+
private function getAuthorization(): AuthorizationInterface
139+
{
140+
if (!$this->authorization) {
141+
$this->authorization = ObjectManager::getInstance()->get(AuthorizationInterface::class);
142+
}
143+
144+
return $this->authorization;
123145
}
124146

125147
/**
@@ -137,12 +159,12 @@ public function save(\Magento\Cms\Api\Data\PageInterface $page)
137159
}
138160
try {
139161
//Validate changing of design.
140-
$userType = $this->userContext->getUserType();
162+
$userType = $this->getUserContext()->getUserType();
141163
if ((
142164
$userType === UserContextInterface::USER_TYPE_ADMIN
143165
|| $userType === UserContextInterface::USER_TYPE_INTEGRATION
144166
)
145-
&& !$this->authorization->isAllowed('Magento_Cms::save_design')
167+
&& !$this->getAuthorization()->isAllowed('Magento_Cms::save_design')
146168
) {
147169
if (!$page->getId()) {
148170
$page->setLayoutUpdateXml(null);

0 commit comments

Comments
 (0)