Skip to content

Commit 94f5510

Browse files
Merge branch '2.4.4-develop' into 2.4.4-develop-2.4-develop-sync-122021
2 parents e8c31f5 + fb61230 commit 94f5510

File tree

61 files changed

+1626
-235
lines changed

Some content is hidden

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

61 files changed

+1626
-235
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/Customer/Controller/Account/CreatePassword.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Magento\Framework\Controller\Result\Redirect;
1818
use Magento\Framework\View\Result\Page;
1919
use Magento\Framework\View\Result\PageFactory;
20+
use Magento\Customer\Api\CustomerRepositoryInterface;
2021

2122
/**
2223
* Controller for front-end customer password reset form
@@ -48,21 +49,28 @@ class CreatePassword extends \Magento\Customer\Controller\AbstractAccount implem
4849
*/
4950
private $getByToken;
5051

52+
/**
53+
* @var CustomerRepositoryInterface
54+
*/
55+
private $customerRepository;
56+
5157
/**
5258
* @param Context $context
5359
* @param Session $customerSession
5460
* @param PageFactory $resultPageFactory
5561
* @param AccountManagementInterface $accountManagement
5662
* @param ConfirmCustomerByToken|null $confirmByToken
5763
* @param GetCustomerByToken|null $getByToken
64+
* @param CustomerRepositoryInterface|null $customerRepository
5865
*/
5966
public function __construct(
6067
Context $context,
6168
Session $customerSession,
6269
PageFactory $resultPageFactory,
6370
AccountManagementInterface $accountManagement,
6471
ConfirmCustomerByToken $confirmByToken = null,
65-
GetCustomerByToken $getByToken = null
72+
GetCustomerByToken $getByToken = null,
73+
CustomerRepositoryInterface $customerRepository = null
6674
) {
6775
$this->session = $customerSession;
6876
$this->resultPageFactory = $resultPageFactory;
@@ -71,6 +79,8 @@ public function __construct(
7179
?? ObjectManager::getInstance()->get(ConfirmCustomerByToken::class);
7280
$this->getByToken = $getByToken
7381
?? ObjectManager::getInstance()->get(GetCustomerByToken::class);
82+
$this->customerRepository = $customerRepository
83+
?? ObjectManager::getInstance()->get(CustomerRepositoryInterface::class);
7484

7585
parent::__construct($context);
7686
}
@@ -83,23 +93,25 @@ public function __construct(
8393
public function execute()
8494
{
8595
$resetPasswordToken = (string)$this->getRequest()->getParam('token');
96+
$customerId = (int)$this->getRequest()->getParam('id');
8697
$isDirectLink = $resetPasswordToken != '';
8798
if (!$isDirectLink) {
8899
$resetPasswordToken = (string)$this->session->getRpToken();
100+
$customerId = (int)$this->session->getRpCustomerId();
89101
}
90102

91103
try {
92-
$this->accountManagement->validateResetPasswordLinkToken(null, $resetPasswordToken);
93-
94-
$this->confirmByToken->execute($resetPasswordToken);
104+
$this->accountManagement->validateResetPasswordLinkToken($customerId, $resetPasswordToken);
105+
$this->confirmByToken->resetCustomerConfirmation($customerId);
95106

96107
// Extend token validity to avoid expiration while this form is
97108
// being completed by the user.
98-
$customer = $this->getByToken->execute($resetPasswordToken);
109+
$customer = $this->customerRepository->getById($customerId);
99110
$this->accountManagement->changeResetPasswordLinkToken($customer, $resetPasswordToken);
100111

101112
if ($isDirectLink) {
102113
$this->session->setRpToken($resetPasswordToken);
114+
$this->session->setRpCustomerId($customerId);
103115
$resultRedirect = $this->resultRedirectFactory->create();
104116
$resultRedirect->setPath('*/*/createpassword');
105117

@@ -109,7 +121,8 @@ public function execute()
109121
$resultPage = $this->resultPageFactory->create();
110122
$resultPage->getLayout()
111123
->getBlock('resetPassword')
112-
->setResetPasswordLinkToken($resetPasswordToken);
124+
->setResetPasswordLinkToken($resetPasswordToken)
125+
->setRpCustomerId($customerId);
113126

114127
return $resultPage;
115128
}

app/code/Magento/Customer/Controller/Account/ResetPasswordPost.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ public function execute()
6767
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
6868
$resultRedirect = $this->resultRedirectFactory->create();
6969
$resetPasswordToken = (string)$this->getRequest()->getQuery('token');
70+
$customerId = (string)$this->getRequest()->getQuery('id');
7071
$password = (string)$this->getRequest()->getPost('password');
7172
$passwordConfirmation = (string)$this->getRequest()->getPost('password_confirmation');
73+
$email = null;
7274

7375
if ($password !== $passwordConfirmation) {
7476
$this->messageManager->addErrorMessage(__("New Password and Confirm New Password values didn't match."));
@@ -83,9 +85,13 @@ public function execute()
8385
return $resultRedirect;
8486
}
8587

88+
if ($customerId && $this->customerRepository->getById($customerId)) {
89+
$email = $this->customerRepository->getById($customerId)->getEmail();
90+
}
91+
8692
try {
8793
$this->accountManagement->resetPassword(
88-
null,
94+
$email,
8995
$resetPasswordToken,
9096
$password
9197
);
@@ -95,6 +101,7 @@ public function execute()
95101
$this->session->start();
96102
}
97103
$this->session->unsRpToken();
104+
$this->session->unsRpCustomerId();
98105
$this->messageManager->addSuccessMessage(__('You updated your password.'));
99106
$resultRedirect->setPath('*/*/login');
100107

app/code/Magento/Customer/Model/AccountManagement.php

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -704,8 +704,8 @@ private function handleUnknownTemplate($template)
704704
public function resetPassword($email, $resetToken, $newPassword)
705705
{
706706
if (!$email) {
707-
$customer = $this->getByToken->execute($resetToken);
708-
$email = $customer->getEmail();
707+
$params = ['fieldName' => 'email'];
708+
throw new InputException(__('"%fieldName" is required. Enter and try again.', $params));
709709
} else {
710710
$customer = $this->customerRepository->get($email);
711711
}
@@ -1163,24 +1163,17 @@ public function validateCustomerStoreIdByWebsiteId(CustomerInterface $customer)
11631163
* @throws NoSuchEntityException If customer doesn't exist
11641164
* @SuppressWarnings(PHPMD.LongVariable)
11651165
*/
1166-
private function validateResetPasswordToken($customerId, $resetPasswordLinkToken)
1166+
private function validateResetPasswordToken(int $customerId, string $resetPasswordLinkToken): bool
11671167
{
1168-
if ($customerId !== null && $customerId <= 0) {
1168+
if (!$customerId) {
11691169
throw new InputException(
11701170
__(
11711171
'Invalid value of "%value" provided for the %fieldName field.',
11721172
['value' => $customerId, 'fieldName' => 'customerId']
11731173
)
11741174
);
11751175
}
1176-
1177-
if ($customerId === null) {
1178-
//Looking for the customer.
1179-
$customerId = $this->getByToken
1180-
->execute($resetPasswordLinkToken)
1181-
->getId();
1182-
}
1183-
if (!is_string($resetPasswordLinkToken) || empty($resetPasswordLinkToken)) {
1176+
if (!$resetPasswordLinkToken) {
11841177
$params = ['fieldName' => 'resetPasswordLinkToken'];
11851178
throw new InputException(__('"%fieldName" is required. Enter and try again.', $params));
11861179
}
@@ -1451,7 +1444,7 @@ public function isResetPasswordLinkTokenExpired($rpToken, $rpTokenCreatedAt)
14511444
* @throws LocalizedException
14521445
* @throws NoSuchEntityException
14531446
*/
1454-
public function changeResetPasswordLinkToken($customer, $passwordLinkToken)
1447+
public function changeResetPasswordLinkToken(CustomerInterface $customer, string $passwordLinkToken): bool
14551448
{
14561449
if (!is_string($passwordLinkToken) || empty($passwordLinkToken)) {
14571450
throw new InputException(
@@ -1460,15 +1453,15 @@ public function changeResetPasswordLinkToken($customer, $passwordLinkToken)
14601453
['value' => $passwordLinkToken, 'fieldName' => 'password reset token']
14611454
)
14621455
);
1456+
} else {
1457+
$customerSecure = $this->customerRegistry->retrieveSecureData($customer->getId());
1458+
$customerSecure->setRpToken($passwordLinkToken);
1459+
$customerSecure->setRpTokenCreatedAt(
1460+
$this->dateTimeFactory->create()->format(DateTime::DATETIME_PHP_FORMAT)
1461+
);
1462+
$this->setIgnoreValidationFlag($customer);
1463+
$this->customerRepository->save($customer);
14631464
}
1464-
$customerSecure = $this->customerRegistry->retrieveSecureData($customer->getId());
1465-
$customerSecure->setRpToken($passwordLinkToken);
1466-
$customerSecure->setRpTokenCreatedAt(
1467-
$this->dateTimeFactory->create()->format(DateTime::DATETIME_PHP_FORMAT)
1468-
);
1469-
$this->setIgnoreValidationFlag($customer);
1470-
$this->customerRepository->save($customer);
1471-
14721465
return true;
14731466
}
14741467

0 commit comments

Comments
 (0)