Skip to content

Commit 56b0007

Browse files
Merge branch '2.4.4-develop' into 2.4.4-develop-2.4-develop-sync-120621
# Conflicts: # app/code/Magento/Swagger/Test/Mftf/Test/StorefrontMagentoApiSwaggerActionsExistTest.xml
2 parents 26edafb + ea6c573 commit 56b0007

File tree

43 files changed

+1246
-150
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1246
-150
lines changed

app/code/Magento/Cms/Ui/Component/Listing/Column/BlockActions.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,24 @@ public function prepareDataSource(array $dataSource)
6666
'href' => $this->urlBuilder->getUrl(
6767
static::URL_PATH_EDIT,
6868
[
69-
'block_id' => $item['block_id'],
69+
'block_id' => $item['block_id']
7070
]
7171
),
72-
'label' => __('Edit'),
72+
'label' => __('Edit')
7373
],
7474
'delete' => [
7575
'href' => $this->urlBuilder->getUrl(
7676
static::URL_PATH_DELETE,
7777
[
78-
'block_id' => $item['block_id'],
78+
'block_id' => $item['block_id']
7979
]
8080
),
8181
'label' => __('Delete'),
8282
'confirm' => [
8383
'title' => __('Delete %1', $title),
84-
'message' => __('Are you sure you want to delete a %1 record?', $title),
84+
'message' => __('Are you sure you want to delete a %1 record?', $title)
8585
],
86-
'post' => true,
86+
'post' => true
8787
],
8888
];
8989
}
@@ -102,6 +102,7 @@ public function prepareDataSource(array $dataSource)
102102
private function getEscaper()
103103
{
104104
if (!$this->escaper) {
105+
// phpcs:ignore Magento2.PHP.AutogeneratedClassNotInConstructor
105106
$this->escaper = ObjectManager::getInstance()->get(Escaper::class);
106107
}
107108
return $this->escaper;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Contact\Plugin\UserDataProvider;
9+
10+
use Magento\Framework\DataObject;
11+
use Magento\Framework\View\Element\Block\ArgumentInterface;
12+
use Magento\Framework\View\Element\BlockInterface;
13+
14+
/**
15+
* Sets the view model
16+
*/
17+
class ViewModel
18+
{
19+
/**
20+
* Key `view_model`
21+
*/
22+
private const VIEW_MODEL = 'view_model';
23+
24+
/**
25+
* @var ArgumentInterface
26+
*/
27+
private $viewModel;
28+
29+
/**
30+
* @param ArgumentInterface $viewModel
31+
*/
32+
public function __construct(ArgumentInterface $viewModel)
33+
{
34+
$this->viewModel = $viewModel;
35+
}
36+
37+
/**
38+
* Sets the view model before rendering to HTML
39+
*
40+
* @param DataObject|BlockInterface $block
41+
* @return null
42+
*/
43+
public function beforeToHtml(DataObject $block)
44+
{
45+
if (!$block->hasData(self::VIEW_MODEL)) {
46+
$block->setData(self::VIEW_MODEL, $this->viewModel);
47+
}
48+
49+
return null;
50+
}
51+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Contact\Test\Unit\Plugin\UserDataProvider;
9+
10+
use Magento\Contact\Plugin\UserDataProvider\ViewModel as ViewModelPlugin;
11+
use Magento\Framework\DataObject;
12+
use Magento\Framework\View\Element\Block\ArgumentInterface;
13+
use PHPUnit\Framework\MockObject\MockObject;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* Unit test for the ViewModelPlugin class
18+
*/
19+
class ViewModelTest extends TestCase
20+
{
21+
/**
22+
* @var ArgumentInterface|MockObject
23+
*/
24+
private $viewModelMock;
25+
26+
/**
27+
* @var DataObject|MockObject
28+
*/
29+
private $blockMock;
30+
31+
/**
32+
* @var ViewModelPlugin
33+
*/
34+
private $plugin;
35+
36+
/**
37+
* @inheritDoc
38+
*/
39+
protected function setUp(): void
40+
{
41+
$this->viewModelMock = $this->getMockForAbstractClass(ArgumentInterface::class);
42+
$this->blockMock = $this->createMock(DataObject::class);
43+
44+
$this->plugin = new ViewModelPlugin($this->viewModelMock);
45+
}
46+
47+
/**
48+
* @dataProvider dataProvider
49+
*/
50+
public function testBeforeToHtml($hasDataResult, $setDataExpects)
51+
{
52+
$this->blockMock->expects($this->once())
53+
->method('hasData')
54+
->with('view_model')
55+
->willReturn($hasDataResult);
56+
57+
$this->blockMock->expects($setDataExpects)
58+
->method('setData')
59+
->with('view_model', $this->viewModelMock);
60+
61+
$this->plugin->beforeToHtml($this->blockMock);
62+
}
63+
64+
public function dataProvider()
65+
{
66+
return [
67+
'view model was not preset before' => [
68+
'hasData' => false,
69+
'setData' => $this->once(),
70+
],
71+
'view model was pre-installed before' => [
72+
'hasData' => true,
73+
'setData' => $this->never(),
74+
]
75+
];
76+
}
77+
}

app/code/Magento/Contact/etc/frontend/di.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,12 @@
1313
</argument>
1414
</arguments>
1515
</type>
16+
<type name="Magento\Contact\Plugin\UserDataProvider\ViewModel">
17+
<arguments>
18+
<argument name="viewModel" xsi:type="object">Magento\Contact\ViewModel\UserDataProvider</argument>
19+
</arguments>
20+
</type>
21+
<type name="Magento\Contact\Block\ContactForm">
22+
<plugin name="set_view_model" type="Magento\Contact\Plugin\UserDataProvider\ViewModel" />
23+
</type>
1624
</config>

app/code/Magento/Contact/view/frontend/layout/contact_index_index.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
<referenceContainer name="content">
1414
<block class="Magento\Contact\Block\ContactForm" name="contactForm" template="Magento_Contact::form.phtml">
1515
<container name="form.additional.info" label="Form Additional Info"/>
16-
<arguments>
17-
<argument name="view_model" xsi:type="object">Magento\Contact\ViewModel\UserDataProvider</argument>
18-
</arguments>
1916
</block>
2017
</referenceContainer>
2118
</body>

app/code/Magento/Integration/Model/Oauth/Token.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ class Token extends \Magento\Framework\Model\AbstractModel
5959

6060
/**#@- */
6161

62-
/**#@- */
62+
/**
63+
* @var OauthHelper
64+
*/
6365
protected $_oauthHelper;
6466

6567
/**
@@ -136,9 +138,10 @@ public function __construct(
136138
$this->_consumerFactory = $consumerFactory;
137139
$this->_oauthData = $oauthData;
138140
$this->_oauthHelper = $oauthHelper;
139-
$this->reader = ObjectManager::getInstance()->get(UserTokenReaderInterface::class);
140-
$this->issuer = ObjectManager::getInstance()->get(UserTokenIssuerInterface::class);
141-
$this->tokenParamsFactory = ObjectManager::getInstance()->get(UserTokenParametersInterfaceFactory::class);
141+
$this->reader = $reader ?? ObjectManager::getInstance()->get(UserTokenReaderInterface::class);
142+
$this->issuer = $issuer ?? ObjectManager::getInstance()->get(UserTokenIssuerInterface::class);
143+
$this->tokenParamsFactory = $paramsFactory ??
144+
ObjectManager::getInstance()->get(UserTokenParametersInterfaceFactory::class);
142145
}
143146

144147
/**
@@ -360,6 +363,7 @@ public function loadByConsumerIdAndUserType($consumerId, $userType)
360363
{
361364
$tokenData = $this->getResource()->selectTokenByConsumerIdAndUserType($consumerId, $userType);
362365
$this->setData($tokenData ? $tokenData : []);
366+
$this->getResource()->afterLoad($this);
363367
return $this;
364368
}
365369

app/code/Magento/Integration/Model/Oauth/Token/Provider.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct(
4444
}
4545

4646
/**
47-
* {@inheritdoc}
47+
* @inheritdoc
4848
*/
4949
public function validateConsumer($consumer)
5050
{
@@ -58,7 +58,7 @@ public function validateConsumer($consumer)
5858
}
5959

6060
/**
61-
* {@inheritdoc}
61+
* @inheritdoc
6262
*/
6363
public function createRequestToken($consumer)
6464
{
@@ -73,7 +73,7 @@ public function createRequestToken($consumer)
7373
}
7474

7575
/**
76-
* {@inheritdoc}
76+
* @inheritdoc
7777
*/
7878
public function validateRequestToken($requestToken, $consumer, $oauthVerifier)
7979
{
@@ -99,7 +99,7 @@ public function validateRequestToken($requestToken, $consumer, $oauthVerifier)
9999
}
100100

101101
/**
102-
* {@inheritdoc}
102+
* @inheritdoc
103103
*/
104104
public function getAccessToken($consumer)
105105
{
@@ -118,7 +118,7 @@ public function getAccessToken($consumer)
118118
}
119119

120120
/**
121-
* {@inheritdoc}
121+
* @inheritdoc
122122
*/
123123
public function validateAccessTokenRequest($accessToken, $consumer)
124124
{
@@ -144,7 +144,7 @@ public function validateAccessTokenRequest($accessToken, $consumer)
144144
}
145145

146146
/**
147-
* {@inheritdoc}
147+
* @inheritdoc
148148
*/
149149
public function validateAccessToken($accessToken)
150150
{
@@ -168,15 +168,15 @@ public function validateAccessToken($accessToken)
168168
}
169169

170170
/**
171-
* {@inheritdoc}
171+
* @inheritdoc
172172
*/
173173
public function validateOauthToken($oauthToken)
174174
{
175175
return strlen($oauthToken) == \Magento\Framework\Oauth\Helper\Oauth::LENGTH_TOKEN;
176176
}
177177

178178
/**
179-
* {@inheritdoc}
179+
* @inheritdoc
180180
*/
181181
public function getConsumerByKey($consumerKey)
182182
{

app/code/Magento/Integration/Model/ResourceModel/Oauth/Consumer.php

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,29 @@
55
*/
66
namespace Magento\Integration\Model\ResourceModel\Oauth;
77

8+
use Magento\Framework\App\ObjectManager;
9+
use Magento\Framework\Encryption\Encryptor;
10+
811
class Consumer extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
912
{
13+
14+
/**
15+
* @var Encryptor
16+
*/
17+
private $encryptor;
18+
1019
/**
1120
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
1221
* @param string $connectionName
22+
* @param Encryptor $encryptor
1323
*/
1424
public function __construct(
1525
\Magento\Framework\Model\ResourceModel\Db\Context $context,
16-
$connectionName = null
26+
$connectionName = null,
27+
Encryptor $encryptor = null
1728
) {
1829
parent::__construct($context, $connectionName);
30+
$this->encryptor = $encryptor ?? ObjectManager::getInstance()->get(Encryptor::class);
1931
}
2032

2133
/**
@@ -61,4 +73,40 @@ public function getTimeInSecondsSinceCreation($consumerId)
6173

6274
return $connection->fetchOne($select);
6375
}
76+
77+
/**
78+
* @inheritdoc
79+
*/
80+
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
81+
{
82+
if ($object->getSecret()) {
83+
$object->setSecret($this->encryptor->encrypt($object->getSecret()));
84+
}
85+
86+
return parent::_beforeSave($object);
87+
}
88+
89+
/**
90+
* @inheritdoc
91+
*/
92+
protected function _afterLoad(\Magento\Framework\Model\AbstractModel $object)
93+
{
94+
if ($object->getSecret()) {
95+
$object->setSecret($this->encryptor->decrypt($object->getSecret()));
96+
}
97+
98+
return parent::_afterLoad($object);
99+
}
100+
101+
/**
102+
* @inheritdoc
103+
*/
104+
protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
105+
{
106+
if ($object->getSecret()) {
107+
$object->setSecret($this->encryptor->decrypt($object->getSecret()));
108+
}
109+
110+
return parent::_afterSave($object);
111+
}
64112
}

0 commit comments

Comments
 (0)