File tree Expand file tree Collapse file tree 4 files changed +59
-7
lines changed
Controller/Adminhtml/User
dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/User Expand file tree Collapse file tree 4 files changed +59
-7
lines changed Original file line number Diff line number Diff line change @@ -48,11 +48,25 @@ protected function _construct()
4848 parent ::_construct ();
4949
5050 $ this ->buttonList ->update ('save ' , 'label ' , __ ('Save User ' ));
51- $ this ->buttonList ->update ('delete ' , ' label ' , __ ( ' Delete User ' ) );
51+ $ this ->buttonList ->remove ('delete ' );
5252
5353 $ objId = $ this ->getRequest ()->getParam ($ this ->_objectId );
5454
5555 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+
5670 $ deleteConfirmMsg = __ ("Are you sure you want to revoke the user\'s tokens? " );
5771 $ this ->addButton (
5872 'invalidate ' ,
Original file line number Diff line number Diff line change @@ -14,8 +14,8 @@ class Delete extends \Magento\User\Controller\Adminhtml\User
1414 public function execute ()
1515 {
1616 $ 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 ) {
1919 if ($ currentUser ->getId () == $ userId ) {
2020 $ this ->messageManager ->addError (__ ('You cannot delete your own account. ' ));
2121 $ 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 33 * See COPYING.txt for license details.
44 */
55define ( [
6- 'Magento_Ui/js/modal/confirm'
7- ] , function ( confirm ) {
6+ 'Magento_Ui/js/modal/confirm' ,
7+ 'mage/dataPost'
8+ ] , function ( confirm , dataPost ) {
89 'use strict' ;
910
1011 /**
@@ -19,14 +20,20 @@ define([
1920 * Helper for onclick action.
2021 * @param {String } message
2122 * @param {String } url
23+ * @param {Object } postData
2224 * @returns {boolean }
2325 */
24- window . deleteConfirm = function ( message , url ) {
26+ window . deleteConfirm = function ( message , url , postData ) {
2527 confirm ( {
2628 content : message ,
2729 actions : {
2830 confirm : function ( ) {
29- setLocation ( url ) ;
31+ if ( postData !== undefined ) {
32+ postData . action = url ;
33+ dataPost ( ) . postData ( postData ) ;
34+ } else {
35+ setLocation ( url ) ;
36+ }
3037 }
3138 }
3239 } ) ;
You can’t perform that action at this time.
0 commit comments