Skip to content

Commit 87d63fc

Browse files
committed
MAGETWO-55849: Customer can be deleted without Merchant permissions verification
1 parent 726928a commit 87d63fc

File tree

4 files changed

+58
-14
lines changed

4 files changed

+58
-14
lines changed

app/code/Magento/User/Block/User/Edit.php

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,9 @@ protected function _construct()
5858
[
5959
'label' => __('Delete User'),
6060
'class' => 'delete',
61-
'onclick' => sprintf(
62-
'deleteUserAccount("%s", "%s", %s)',
63-
__('Are you sure you want to do this?'),
64-
$this->getUrl('adminhtml/*/delete'),
65-
$objId
66-
),
61+
'data_attribute' => [
62+
'role' => 'delete-user'
63+
]
6764
]
6865
);
6966

@@ -79,6 +76,32 @@ protected function _construct()
7976
}
8077
}
8178

79+
/**
80+
* @return \Magento\Framework\Phrase
81+
*/
82+
public function getDeleteMessage()
83+
{
84+
return __('Are you sure you want to do this?');
85+
}
86+
87+
/**
88+
* Returns user deletion url
89+
*
90+
* @return string
91+
*/
92+
public function getDeleteUrl()
93+
{
94+
return $this->getUrl('adminhtml/*/delete');
95+
}
96+
97+
/**
98+
* @return int
99+
*/
100+
public function getObjectId()
101+
{
102+
return (int)$this->getRequest()->getParam($this->_objectId);
103+
}
104+
82105
/**
83106
* @return \Magento\Framework\Phrase
84107
*/

app/code/Magento/User/view/adminhtml/requirejs-config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
var config = {
77
map: {
88
'*': {
9-
rolesTree: 'Magento_User/js/roles-tree'
9+
rolesTree: 'Magento_User/js/roles-tree',
10+
deleteUserAccount: 'Magento_User/js/delete-user-account'
1011
}
1112
}
1213
};

app/code/Magento/User/view/adminhtml/templates/user/roles_grid_js.phtml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ require([
1414
], function(){
1515

1616
<?php $myBlock = $block->getLayout()->getBlock('user.roles.grid'); ?>
17+
<?php $editBlock = $block->getLayout()->getBlock('adminhtml.user.edit'); ?>
1718
<?php if (is_object($myBlock) && $myBlock->getJsObjectName()): ?>
1819
var radioBoxes = $H({});
1920
var warning = false;
@@ -70,13 +71,15 @@ require([
7071
<?php endif; ?>
7172

7273
});
73-
function deleteUserAccount(message, url, objId) {
74-
if (jQuery.validator.validateElement(jQuery('[name="current_password"]'))) {
75-
postData = {'data' : {
76-
'user_id': objId,
77-
'current_password': jQuery('[name="current_password"]').val()
78-
}}
79-
deleteConfirm(message, url, postData);
74+
</script>
75+
<script type="text/x-magento-init">
76+
{
77+
"[data-role=delete-user]" : {
78+
"deleteUserAccount" : {
79+
"message": "<?php /* @escapeNotVerified */ echo $editBlock->getDeleteMessage(); ?>",
80+
"url": "<?php /* @escapeNotVerified */ echo $editBlock->getDeleteUrl(); ?>",
81+
"objId": "<?php /* @escapeNotVerified */ echo $editBlock->getObjectId(); ?>"
82+
}
8083
}
8184
}
8285
</script>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
define([
2+
"jquery"
3+
], function($){
4+
5+
return function (params, elem) {
6+
7+
elem.on('click', function() {
8+
if ($.validator.validateElement($('[name="current_password"]'))) {
9+
postData = {'data' : {
10+
'user_id': params.objId,
11+
'current_password': $('[name="current_password"]').val()
12+
}}
13+
deleteConfirm(params.message, params.url, params.postData);
14+
}
15+
});
16+
}
17+
});

0 commit comments

Comments
 (0)