File tree 4 files changed +59
-7
lines changed
Controller/Adminhtml/User
dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/User
4 files changed +59
-7
lines changed Original file line number Diff line number Diff line change @@ -48,11 +48,25 @@ protected function _construct()
48
48
parent ::_construct ();
49
49
50
50
$ this ->buttonList ->update ('save ' , 'label ' , __ ('Save User ' ));
51
- $ this ->buttonList ->update ('delete ' , ' label ' , __ ( ' Delete User ' ) );
51
+ $ this ->buttonList ->remove ('delete ' );
52
52
53
53
$ objId = $ this ->getRequest ()->getParam ($ this ->_objectId );
54
54
55
55
if (!empty ($ objId )) {
56
+ $ this ->addButton (
57
+ 'delete ' ,
58
+ [
59
+ 'label ' => __ ('Delete User ' ),
60
+ 'class ' => 'delete ' ,
61
+ 'onclick ' => sprintf (
62
+ 'deleteConfirm("%s", "%s", %s) ' ,
63
+ __ ('Are you sure you want to do this? ' ),
64
+ $ this ->getUrl ('adminhtml/*/delete ' ),
65
+ json_encode (['data ' => ['user_id ' => $ objId ]])
66
+ ),
67
+ ]
68
+ );
69
+
56
70
$ deleteConfirmMsg = __ ("Are you sure you want to revoke the user\'s tokens? " );
57
71
$ this ->addButton (
58
72
'invalidate ' ,
Original file line number Diff line number Diff line change @@ -14,8 +14,8 @@ class Delete extends \Magento\User\Controller\Adminhtml\User
14
14
public function execute ()
15
15
{
16
16
$ currentUser = $ this ->_objectManager ->get (\Magento \Backend \Model \Auth \Session::class)->getUser ();
17
-
18
- if ($ userId = $ this -> getRequest ()-> getParam ( ' user_id ' ) ) {
17
+ $ userId = ( int ) $ this -> getRequest ()-> getPost ( ' user_id ' );
18
+ if ($ userId ) {
19
19
if ($ currentUser ->getId () == $ userId ) {
20
20
$ this ->messageManager ->addError (__ ('You cannot delete your own account. ' ));
21
21
$ this ->_redirect ('adminhtml/*/edit ' , ['user_id ' => $ userId ]);
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © 2016 Magento. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ namespace Magento \User \Controller \Adminhtml \User ;
7
+
8
+ /**
9
+ * Test class for \Magento\User\Controller\Adminhtml\User\Delete
10
+ * @magentoAppArea adminhtml
11
+ */
12
+ class DeleteTest extends \Magento \TestFramework \TestCase \AbstractBackendController
13
+ {
14
+ /**
15
+ * @covers \Magento\User\Controller\Adminhtml\User\Delete::execute
16
+ */
17
+ public function testDeleteActionWithError ()
18
+ {
19
+ $ user = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()
20
+ ->create (\Magento \User \Model \User::class);
21
+ /** @var \Magento\Framework\Message\ManagerInterface $messageManager */
22
+ $ messageManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()
23
+ ->get (\Magento \Framework \Message \ManagerInterface::class);
24
+ $ user ->load (1 );
25
+ $ this ->getRequest ()->setPostValue ('user_id ' , $ user ->getId () . '_suffix_ignored_in_mysql_casting_to_int ' );
26
+
27
+ $ this ->dispatch ('backend/admin/user/delete ' );
28
+ $ message = $ messageManager ->getMessages ()->getLastAddedMessage ()->getText ();
29
+ $ this ->assertEquals ('You cannot delete your own account. ' , $ message );
30
+ }
31
+ }
Original file line number Diff line number Diff line change 3
3
* See COPYING.txt for license details.
4
4
*/
5
5
define ( [
6
- 'Magento_Ui/js/modal/confirm'
7
- ] , function ( confirm ) {
6
+ 'Magento_Ui/js/modal/confirm' ,
7
+ 'mage/dataPost'
8
+ ] , function ( confirm , dataPost ) {
8
9
'use strict' ;
9
10
10
11
/**
@@ -19,14 +20,20 @@ define([
19
20
* Helper for onclick action.
20
21
* @param {String } message
21
22
* @param {String } url
23
+ * @param {Object } postData
22
24
* @returns {boolean }
23
25
*/
24
- window . deleteConfirm = function ( message , url ) {
26
+ window . deleteConfirm = function ( message , url , postData ) {
25
27
confirm ( {
26
28
content : message ,
27
29
actions : {
28
30
confirm : function ( ) {
29
- setLocation ( url ) ;
31
+ if ( postData !== undefined ) {
32
+ postData . action = url ;
33
+ dataPost ( ) . postData ( postData ) ;
34
+ } else {
35
+ setLocation ( url ) ;
36
+ }
30
37
}
31
38
}
32
39
} ) ;
You can’t perform that action at this time.
0 commit comments