Skip to content

Commit 8c81024

Browse files
committed
Merge remote-tracking branch 'origin/AC-10886' into spartans_pr_23122024
2 parents e2efd8a + 7104997 commit 8c81024

File tree

3 files changed

+58
-12
lines changed

3 files changed

+58
-12
lines changed

app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\Backend\Controller\Adminhtml\System\Account;
77

@@ -11,9 +11,11 @@
1111
use Magento\Framework\Controller\ResultFactory;
1212
use Magento\Framework\Exception\State\UserLockedException;
1313
use Magento\Security\Model\SecurityCookie;
14+
use Magento\User\Model\User;
1415

1516
/**
1617
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
18+
* @SuppressWarnings(PHPMD.AllPurposeAction)
1719
*/
1820
class Save extends \Magento\Backend\Controller\Adminhtml\System\Account
1921
{
@@ -25,8 +27,11 @@ class Save extends \Magento\Backend\Controller\Adminhtml\System\Account
2527
/**
2628
* Get security cookie
2729
*
30+
* @deprecated 100.1.0 This method is deprecated because dependency injection should be used instead of
31+
* directly accessing the SecurityCookie instance.
32+
* Use dependency injection to get an instance of SecurityCookie.
33+
* @see \Magento\Backend\Controller\Adminhtml\System\Account::__construct()
2834
* @return SecurityCookie
29-
* @deprecated 100.1.0
3035
*/
3136
private function getSecurityCookie()
3237
{
@@ -81,7 +86,29 @@ public function execute()
8186
} else {
8287
$user->save();
8388
$user->sendNotificationEmailsIfRequired();
84-
$this->messageManager->addSuccessMessage(__('You saved the account.'));
89+
90+
$modifiedFields = $this->getModifiedFields($user);
91+
if (!empty($modifiedFields)) {
92+
$countModifiedFields = count($modifiedFields);
93+
// validate how many fields were modified to display them correctly
94+
if ($countModifiedFields > 1) {
95+
$lastModifiedField = array_pop($modifiedFields);
96+
$modifiedFieldsText = implode(', ', $modifiedFields);
97+
$successMessage = __(
98+
'The %1 and %2 of this account have been modified successfully.',
99+
$modifiedFieldsText,
100+
$lastModifiedField
101+
);
102+
} else {
103+
$successMessage = __(
104+
'The %1 of this account has been modified successfully.',
105+
reset($modifiedFields)
106+
);
107+
}
108+
$this->messageManager->addSuccessMessage($successMessage);
109+
} else {
110+
$this->messageManager->addSuccessMessage(__('You saved the account.'));
111+
}
85112
}
86113
} catch (UserLockedException $e) {
87114
$this->_auth->logout();
@@ -103,4 +130,22 @@ public function execute()
103130
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
104131
return $resultRedirect->setPath("*/*/");
105132
}
133+
134+
/**
135+
* Get user modified fields
136+
*
137+
* @param User $user
138+
* @return array
139+
*/
140+
private function getModifiedFields(User $user)
141+
{
142+
$modifiedFields = [];
143+
$propertiesToCheck = ['password', 'username', 'firstname', 'lastname', 'email'];
144+
foreach ($propertiesToCheck as $property) {
145+
if ($user->getOrigData($property) !== $user->{'get' . ucfirst($property)}()) {
146+
$modifiedFields[] = $property;
147+
}
148+
}
149+
return $modifiedFields;
150+
}
106151
}

app/code/Magento/Backend/Test/Unit/Controller/Adminhtml/System/Account/SaveTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -215,7 +215,8 @@ public function testSaveAction(): void
215215
Form::IDENTITY_VERIFICATION_PASSWORD_FIELD => 'current_password'
216216
];
217217

218-
$testedMessage = 'You saved the account.';
218+
$testedMessage = "The password, username, firstname, lastname and email of this account"
219+
." have been modified successfully.";
219220

220221
$this->authSessionMock->expects($this->any())->method('getUser')->willReturn($this->userMock);
221222

app/code/Magento/Security/Test/Mftf/ActionGroup/AdminResetPasswordActionGroup.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
3-
/**
4-
* Copyright © Magento, Inc. All rights reserved.
5-
* See COPYING.txt for license details.
6-
*/
3+
/**
4+
* Copyright 2022 Adobe
5+
* All Rights Reserved.
6+
*/
77
-->
88

99
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -27,7 +27,7 @@
2727
<fillField selector="{{AdminSystemAccountSection.passwordConfirmation}}" userInput="Admin@12345678" stepKey="confirmPassword1"/>
2828
<fillField selector="{{AdminSystemAccountSection.currentPassword}}" userInput="123123aaa" stepKey="fillCorrectPassword"/>
2929
<click selector="{{AdminMainActionsSection.save}}" stepKey="clickSaveUser2"/>
30-
<see selector="{{AdminMessagesSection.success}}" userInput="You saved the account." stepKey="seeSuccessMessage"/>
30+
<see selector="{{AdminMessagesSection.success}}" userInput="The password of this account has been modified successfully." stepKey="seeSuccessMessage"/>
3131

3232
</actionGroup>
3333
</actionGroups>

0 commit comments

Comments
 (0)