Skip to content

Commit 20fd44c

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-97122' into 2.1.18-develop-pr67
2 parents d1233a7 + 401ceab commit 20fd44c

File tree

2 files changed

+375
-4
lines changed

2 files changed

+375
-4
lines changed

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,44 @@
77
namespace Magento\User\Controller\Adminhtml\User\Role;
88

99
use Magento\Framework\Controller\ResultFactory;
10+
use Magento\Framework\Exception\NotFoundException;
1011

12+
/**
13+
* User roles delete action.
14+
*/
1115
class Delete extends \Magento\User\Controller\Adminhtml\User\Role
1216
{
1317
/**
14-
* Remove role action
18+
* Remove role action.
1519
*
16-
* @return \Magento\Backend\Model\View\Result\Redirect|void
20+
* @return \Magento\Backend\Model\View\Result\Redirect
21+
* @throws NotFoundException
1722
*/
1823
public function execute()
1924
{
25+
if (!$this->getRequest()->isPost()) {
26+
throw new NotFoundException(__('Page not found'));
27+
}
2028
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
2129
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
22-
$rid = $this->getRequest()->getParam('rid', false);
30+
$rid = (int)$this->getRequest()->getParam('rid', false);
2331
/** @var \Magento\User\Model\User $currentUser */
2432
$currentUser = $this->_userFactory->create()->setId($this->_authSession->getUser()->getId());
2533

2634
if (in_array($rid, $currentUser->getRoles())) {
2735
$this->messageManager->addError(__('You cannot delete self-assigned roles.'));
36+
2837
return $resultRedirect->setPath('adminhtml/*/editrole', ['rid' => $rid]);
2938
}
39+
$role = $this->_initRole();
40+
if (!$role->getId()) {
41+
$this->messageManager->addError(__('We can\'t find a role to delete.'));
42+
43+
return $resultRedirect->setPath("*/*/");
44+
}
3045

3146
try {
32-
$this->_initRole()->delete();
47+
$role->delete();
3348
$this->messageManager->addSuccess(__('You deleted the role.'));
3449
} catch (\Exception $e) {
3550
$this->messageManager->addError(__('An error occurred while deleting this role.'));

0 commit comments

Comments
 (0)