Skip to content

Commit 1fa707c

Browse files
committed
MC-18753: 'adminhtml_user_delete' missing deleted username/user id
1 parent 267db35 commit 1fa707c

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

app/code/Magento/User/Controller/Adminhtml/User/Delete.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22
/**
3-
*
43
* Copyright © Magento, Inc. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
@@ -9,10 +8,16 @@
98

109
use Magento\User\Block\User\Edit\Tab\Main as UserEdit;
1110
use Magento\Framework\Exception\AuthenticationException;
11+
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
1212

13-
class Delete extends \Magento\User\Controller\Adminhtml\User
13+
/**
14+
* Delete admin user.
15+
*/
16+
class Delete extends \Magento\User\Controller\Adminhtml\User implements HttpPostActionInterface
1417
{
1518
/**
19+
* Execute delete action.
20+
*
1621
* @return void
1722
*/
1823
public function execute()
@@ -37,7 +42,7 @@ public function execute()
3742
$currentUser->performIdentityCheck($currentUserPassword);
3843
/** @var \Magento\User\Model\User $model */
3944
$model = $this->_userFactory->create();
40-
$model->setId($userId);
45+
$model->load($userId);
4146
$model->delete();
4247
$this->messageManager->addSuccess(__('You deleted the user.'));
4348
$this->_redirect('adminhtml/*/');

app/code/Magento/User/Model/ResourceModel/User.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ protected function _afterLoad(\Magento\Framework\Model\AbstractModel $user)
253253
*/
254254
public function delete(\Magento\Framework\Model\AbstractModel $user)
255255
{
256+
$user->beforeDelete();
256257
$this->_beforeDelete($user);
257258
$connection = $this->getConnection();
258259

@@ -268,7 +269,9 @@ public function delete(\Magento\Framework\Model\AbstractModel $user)
268269
$connection->rollBack();
269270
return false;
270271
}
272+
$user->afterDelete();
271273
$connection->commit();
274+
$user->afterDeleteCommit();
272275
$this->_afterDelete($user);
273276
return true;
274277
}

app/code/Magento/User/Test/Unit/Controller/Adminhtml/User/DeleteTest.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected function setUp()
8181

8282
$this->userMock = $this->getMockBuilder(\Magento\User\Model\User::class)
8383
->disableOriginalConstructor()
84-
->setMethods(['getId', 'performIdentityCheck', 'delete'])
84+
->setMethods(['getId', 'performIdentityCheck', 'delete', 'load'])
8585
->getMock();
8686

8787
$this->userFactoryMock = $this->getMockBuilder(\Magento\User\Model\UserFactory::class)
@@ -134,15 +134,18 @@ public function testExecute($currentUserPassword, $userId, $currentUserId, $resu
134134

135135
$this->requestMock->expects($this->any())
136136
->method('getPost')
137-
->willReturnMap([
138-
['user_id', $userId],
139-
[\Magento\User\Block\User\Edit\Tab\Main::CURRENT_USER_PASSWORD_FIELD, $currentUserPassword],
140-
]);
137+
->willReturnMap(
138+
[
139+
['user_id', $userId],
140+
[\Magento\User\Block\User\Edit\Tab\Main::CURRENT_USER_PASSWORD_FIELD, $currentUserPassword],
141+
]
142+
);
141143

142144
$userMock = clone $currentUserMock;
143145

144146
$this->userFactoryMock->expects($this->any())->method('create')->will($this->returnValue($userMock));
145147
$this->responseMock->expects($this->any())->method('setRedirect')->willReturnSelf();
148+
$this->userMock->expects($this->any())->method('load')->with($userId)->willReturn($this->userFactoryMock);
146149
$this->userMock->expects($this->any())->method('delete')->willReturnSelf();
147150
$this->messageManagerMock->expects($this->once())->method($resultMethod);
148151

@@ -172,10 +175,12 @@ public function testEmptyPassword()
172175

173176
$this->requestMock->expects($this->any())
174177
->method('getPost')
175-
->willReturnMap([
176-
['user_id', $userId],
177-
[\Magento\User\Block\User\Edit\Tab\Main::CURRENT_USER_PASSWORD_FIELD, ''],
178-
]);
178+
->willReturnMap(
179+
[
180+
['user_id', $userId],
181+
[\Magento\User\Block\User\Edit\Tab\Main::CURRENT_USER_PASSWORD_FIELD, ''],
182+
]
183+
);
179184

180185
$result = $this->controller->execute();
181186
$this->assertNull($result);
@@ -191,8 +196,8 @@ public function executeDataProvider()
191196
return [
192197
[
193198
'currentUserPassword' => '123123q',
194-
'userId' => 1,
195-
'currentUserId' => 2,
199+
'userId' => 2,
200+
'currentUserId' => 1,
196201
'resultMethod' => 'addSuccess',
197202
],
198203
[

dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/User/DeleteTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function testDeleteActionWithError()
2222
$messageManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
2323
->get(\Magento\Framework\Message\ManagerInterface::class);
2424
$user->load(1);
25+
$this->getRequest()->setMethod('POST');
2526
$this->getRequest()->setPostValue('user_id', $user->getId() . '_suffix_ignored_in_mysql_casting_to_int');
2627

2728
$this->dispatch('backend/admin/user/delete');

0 commit comments

Comments
 (0)