Role.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\User\Controller\Adminhtml\User;
  7. use Magento\Authorization\Model\Acl\Role\Group as RoleGroup;
  8. abstract class Role extends \Magento\Backend\App\AbstractAction
  9. {
  10. /**
  11. * Authorization level of a basic admin session
  12. *
  13. * @see _isAllowed()
  14. */
  15. const ADMIN_RESOURCE = 'Magento_User::acl_roles';
  16. /**
  17. * Core registry
  18. *
  19. * @var \Magento\Framework\Registry
  20. */
  21. protected $_coreRegistry = null;
  22. /**
  23. * Factory for user role model
  24. *
  25. * @var \Magento\Authorization\Model\RoleFactory
  26. */
  27. protected $_roleFactory;
  28. /**
  29. * User model factory
  30. *
  31. * @var \Magento\User\Model\UserFactory
  32. */
  33. protected $_userFactory;
  34. /**
  35. * Rules model factory
  36. *
  37. * @var \Magento\Authorization\Model\RulesFactory
  38. */
  39. protected $_rulesFactory;
  40. /**
  41. * Backend auth session
  42. *
  43. * @var \Magento\Backend\Model\Auth\Session
  44. */
  45. protected $_authSession;
  46. /**
  47. * @var \Magento\Framework\Filter\FilterManager
  48. */
  49. protected $_filterManager;
  50. /**
  51. * @param \Magento\Backend\App\Action\Context $context
  52. * @param \Magento\Framework\Registry $coreRegistry
  53. * @param \Magento\Authorization\Model\RoleFactory $roleFactory
  54. * @param \Magento\User\Model\UserFactory $userFactory
  55. * @param \Magento\Authorization\Model\RulesFactory $rulesFactory
  56. * @param \Magento\Backend\Model\Auth\Session $authSession
  57. * @param \Magento\Framework\Filter\FilterManager $filterManager
  58. */
  59. public function __construct(
  60. \Magento\Backend\App\Action\Context $context,
  61. \Magento\Framework\Registry $coreRegistry,
  62. \Magento\Authorization\Model\RoleFactory $roleFactory,
  63. \Magento\User\Model\UserFactory $userFactory,
  64. \Magento\Authorization\Model\RulesFactory $rulesFactory,
  65. \Magento\Backend\Model\Auth\Session $authSession,
  66. \Magento\Framework\Filter\FilterManager $filterManager
  67. ) {
  68. parent::__construct($context);
  69. $this->_coreRegistry = $coreRegistry;
  70. $this->_roleFactory = $roleFactory;
  71. $this->_userFactory = $userFactory;
  72. $this->_rulesFactory = $rulesFactory;
  73. $this->_authSession = $authSession;
  74. $this->_filterManager = $filterManager;
  75. }
  76. /**
  77. * Preparing layout for output
  78. *
  79. * @return Role
  80. */
  81. protected function _initAction()
  82. {
  83. $this->_view->loadLayout();
  84. $this->_setActiveMenu('Magento_User::system_acl_roles');
  85. $this->_addBreadcrumb(__('System'), __('System'));
  86. $this->_addBreadcrumb(__('Permissions'), __('Permissions'));
  87. $this->_addBreadcrumb(__('Roles'), __('Roles'));
  88. return $this;
  89. }
  90. /**
  91. * Initialize role model by passed parameter in request
  92. *
  93. * @param string $requestVariable
  94. * @return \Magento\Authorization\Model\Role
  95. */
  96. protected function _initRole($requestVariable = 'rid')
  97. {
  98. $role = $this->_roleFactory->create()->load($this->getRequest()->getParam($requestVariable));
  99. // preventing edit of relation role
  100. if ($role->getId() && $role->getRoleType() != RoleGroup::ROLE_TYPE) {
  101. $role->unsetData($role->getIdFieldName());
  102. }
  103. $this->_coreRegistry->register('current_role', $role);
  104. return $this->_coreRegistry->registry('current_role');
  105. }
  106. }