Skip to content

Commit bfd7965

Browse files
author
OlgaVasyltsun
committed
Merge remote-tracking branch 'origin/2.1.18-develop' into MC-16967
2 parents c34fd08 + 9a54450 commit bfd7965

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
@@ -267,8 +267,6 @@ class Category extends \Magento\Catalog\Model\AbstractModel implements
267267
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
268268
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
269269
* @param array $data
270-
* @param UserContextInterface|null $userContext
271-
* @param AuthorizationInterface|null $authorization
272270
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
273271
*/
274272
public function __construct(
@@ -292,9 +290,7 @@ public function __construct(
292290
CategoryRepositoryInterface $categoryRepository,
293291
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
294292
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
295-
array $data = [],
296-
UserContextInterface $userContext = null,
297-
AuthorizationInterface $authorization = null
293+
array $data = []
298294
) {
299295
$this->metadataService = $metadataService;
300296
$this->_treeModel = $categoryTreeResource;
@@ -319,8 +315,6 @@ public function __construct(
319315
$resourceCollection,
320316
$data
321317
);
322-
$this->userContext = $userContext ?: ObjectManager::getInstance()->get(UserContextInterface::class);
323-
$this->authorization = $authorization ?: ObjectManager::getInstance()->get(AuthorizationInterface::class);
324318
}
325319

326320
/**
@@ -935,16 +929,44 @@ public function beforeDelete()
935929
return parent::beforeDelete();
936930
}
937931

932+
/**
933+
* Get user context.
934+
*
935+
* @return UserContextInterface
936+
*/
937+
private function getUserContext()
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()
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 (($userType === UserContextInterface::USER_TYPE_ADMIN
946968
|| $userType === UserContextInterface::USER_TYPE_INTEGRATION)
947-
&& !$this->authorization->isAllowed('Magento_Catalog::edit_category_design')
969+
&& !$this->getAuthorization()->isAllowed('Magento_Catalog::edit_category_design')
948970
) {
949971
foreach ($this->_designAttributes as $attributeCode) {
950972
$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
@@ -397,8 +397,6 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
397397
* @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
398398
* @param \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $joinProcessor
399399
* @param array $data
400-
* @param UserContextInterface|null $userContext
401-
* @param AuthorizationInterface|null $authorization
402400
*
403401
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
404402
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
@@ -438,9 +436,7 @@ public function __construct(
438436
EntryConverterPool $mediaGalleryEntryConverterPool,
439437
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
440438
\Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $joinProcessor,
441-
array $data = [],
442-
UserContextInterface $userContext = null,
443-
AuthorizationInterface $authorization = null
439+
array $data = []
444440
) {
445441
$this->metadataService = $metadataService;
446442
$this->_itemOptionFactory = $itemOptionFactory;
@@ -479,8 +475,6 @@ public function __construct(
479475
$resourceCollection,
480476
$data
481477
);
482-
$this->userContext = $userContext ?: ObjectManager::getInstance()->get(UserContextInterface::class);
483-
$this->authorization = $authorization ?: ObjectManager::getInstance()->get(AuthorizationInterface::class);
484478
}
485479

486480
/**
@@ -854,6 +848,34 @@ public function getAttributes($groupId = null, $skipSuper = false)
854848
return $attributes;
855849
}
856850

851+
/**
852+
* Get user context.
853+
*
854+
* @return UserContextInterface
855+
*/
856+
private function getUserContext()
857+
{
858+
if (!$this->userContext) {
859+
$this->userContext = ObjectManager::getInstance()->get(UserContextInterface::class);
860+
}
861+
862+
return $this->userContext;
863+
}
864+
865+
/**
866+
* Get authorization service.
867+
*
868+
* @return AuthorizationInterface
869+
*/
870+
private function getAuthorization()
871+
{
872+
if (!$this->authorization) {
873+
$this->authorization = ObjectManager::getInstance()->get(AuthorizationInterface::class);
874+
}
875+
876+
return $this->authorization;
877+
}
878+
857879
/**
858880
* Check product options and type options and save them, too
859881
*
@@ -872,10 +894,10 @@ public function beforeSave()
872894
$this->getTypeInstance()->beforeSave($this);
873895

874896
//Validate changing of design.
875-
$userType = $this->userContext->getUserType();
897+
$userType = $this->getUserContext()->getUserType();
876898
if (($userType === UserContextInterface::USER_TYPE_ADMIN
877899
|| $userType === UserContextInterface::USER_TYPE_INTEGRATION)
878-
&& !$this->authorization->isAllowed('Magento_Catalog::edit_product_design')
900+
&& !$this->getAuthorization()->isAllowed('Magento_Catalog::edit_product_design')
879901
) {
880902
$this->setData('custom_design', $this->getOrigData('custom_design'));
881903
$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
@@ -85,8 +85,6 @@ class PageRepository implements PageRepositoryInterface
8585
* @param DataObjectHelper $dataObjectHelper
8686
* @param DataObjectProcessor $dataObjectProcessor
8787
* @param StoreManagerInterface $storeManager
88-
* @param UserContextInterface|null $userContext
89-
* @param AuthorizationInterface|null $authorization
9088
*
9189
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
9290
*/
@@ -98,9 +96,7 @@ public function __construct(
9896
Data\PageSearchResultsInterfaceFactory $searchResultsFactory,
9997
DataObjectHelper $dataObjectHelper,
10098
DataObjectProcessor $dataObjectProcessor,
101-
StoreManagerInterface $storeManager,
102-
UserContextInterface $userContext = null,
103-
AuthorizationInterface $authorization = null
99+
StoreManagerInterface $storeManager
104100
) {
105101
$this->resource = $resource;
106102
$this->pageFactory = $pageFactory;
@@ -110,8 +106,34 @@ public function __construct(
110106
$this->dataPageFactory = $dataPageFactory;
111107
$this->dataObjectProcessor = $dataObjectProcessor;
112108
$this->storeManager = $storeManager;
113-
$this->userContext = $userContext ?: ObjectManager::getInstance()->get(UserContextInterface::class);
114-
$this->authorization = $authorization ?: ObjectManager::getInstance()->get(AuthorizationInterface::class);
109+
}
110+
111+
/**
112+
* Get user context.
113+
*
114+
* @return UserContextInterface
115+
*/
116+
private function getUserContext()
117+
{
118+
if (!$this->userContext) {
119+
$this->userContext = ObjectManager::getInstance()->get(UserContextInterface::class);
120+
}
121+
122+
return $this->userContext;
123+
}
124+
125+
/**
126+
* Get authorization service.
127+
*
128+
* @return AuthorizationInterface
129+
*/
130+
private function getAuthorization()
131+
{
132+
if (!$this->authorization) {
133+
$this->authorization = ObjectManager::getInstance()->get(AuthorizationInterface::class);
134+
}
135+
136+
return $this->authorization;
115137
}
116138

117139
/**
@@ -129,10 +151,10 @@ public function save(\Magento\Cms\Api\Data\PageInterface $page)
129151
}
130152
try {
131153
//Validate changing of design.
132-
$userType = $this->userContext->getUserType();
154+
$userType = $this->getUserContext()->getUserType();
133155
if (($userType === UserContextInterface::USER_TYPE_ADMIN
134156
|| $userType === UserContextInterface::USER_TYPE_INTEGRATION)
135-
&& !$this->authorization->isAllowed('Magento_Cms::save_design')
157+
&& !$this->getAuthorization()->isAllowed('Magento_Cms::save_design')
136158
) {
137159
if (!$page->getId()) {
138160
$page->setLayoutUpdateXml(null);

0 commit comments

Comments
 (0)