Skip to content

Commit d6b8b4c

Browse files
committed
MAGETWO-97122: User Role minor changes
1 parent 0965809 commit d6b8b4c

File tree

2 files changed

+372
-4
lines changed

2 files changed

+372
-4
lines changed

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,42 @@
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
}
3039

3140
try {
32-
$this->_initRole()->delete();
41+
$role = $this->_initRole();
42+
if (!$role->getId()) {
43+
throw new \Exception();
44+
}
45+
$role->delete();
3346
$this->messageManager->addSuccess(__('You deleted the role.'));
3447
} catch (\Exception $e) {
3548
$this->messageManager->addError(__('An error occurred while deleting this role.'));

0 commit comments

Comments
 (0)