Пример #1
0
 /**
  * @param bool $json
  * @return string|array
  */
 public function getUsers($json = false)
 {
     if ($this->getRequest()->getParam('in_role_user') != "") {
         return $this->getRequest()->getParam('in_role_user');
     }
     $roleId = $this->getRequest()->getParam('rid') > 0 ? $this->getRequest()->getParam('rid') : $this->_coreRegistry->registry('RID');
     $users = $this->_roleFactory->create()->setId($roleId)->getRoleUsers();
     if (sizeof($users) > 0) {
         if ($json) {
             $jsonUsers = [];
             foreach ($users as $usrid) {
                 $jsonUsers[$usrid] = 0;
             }
             return $this->_jsonEncoder->encode((object) $jsonUsers);
         } else {
             return array_values($users);
         }
     } else {
         if ($json) {
             return '{}';
         } else {
             return [];
         }
     }
 }
Пример #2
0
 /**
  * Initialize role model by passed parameter in request
  *
  * @param string $requestVariable
  * @return \Magento\User\Model\Role
  */
 protected function _initRole($requestVariable = 'rid')
 {
     $this->_title->add(__('Roles'));
     $role = $this->_roleFactory->create()->load($this->getRequest()->getParam($requestVariable));
     // preventing edit of relation role
     if ($role->getId() && $role->getRoleType() != RoleGroup::ROLE_TYPE) {
         $role->unsetData($role->getIdFieldName());
     }
     $this->_coreRegistry->register('current_role', $role);
     return $this->_coreRegistry->registry('current_role');
 }
Пример #3
0
 /**
  * Create role for provided user of provided type
  *
  * @param int $parentId
  * @param ModelUser $user
  * @return void
  */
 protected function _createUserRole($parentId, ModelUser $user)
 {
     if ($parentId > 0) {
         /** @var \Magento\User\Model\Role $parentRole */
         $parentRole = $this->_roleFactory->create()->load($parentId);
     } else {
         $role = new \Magento\Framework\Object();
         $role->setTreeLevel(0);
     }
     if ($parentRole->getId()) {
         $data = new \Magento\Framework\Object(array('parent_id' => $parentRole->getId(), 'tree_level' => $parentRole->getTreeLevel() + 1, 'sort_order' => 0, 'role_type' => RoleUser::ROLE_TYPE, 'user_id' => $user->getId(), 'role_name' => $user->getFirstname()));
         $insertData = $this->_prepareDataForTable($data, $this->getTable('admin_role'));
         $this->_getWriteAdapter()->insert($this->getTable('admin_role'), $insertData);
         $this->_aclCache->clean();
     }
 }
Пример #4
0
 /**
  * Remove an ACL role. This deletes the cascading permissions
  *
  * @param UserIdentifier $userIdentifier
  * @return Role
  * @throws NoSuchEntityException
  * @throws \LogicException
  */
 protected function _deleteRole($userIdentifier)
 {
     $userType = $userIdentifier->getUserType();
     if (!$this->_canRoleBeCreatedForUserType($userType)) {
         throw new \LogicException("The role with user type '{$userType}' cannot be created or deleted.");
     }
     $userId = $userIdentifier->getUserId();
     switch ($userType) {
         case UserIdentifier::USER_TYPE_INTEGRATION:
             $roleName = $userType . $userId;
             break;
         default:
             throw NoSuchEntityException::singleField('userType', $userType);
     }
     $role = $this->_roleFactory->create()->load($roleName, 'role_name');
     return $role->delete();
 }
Пример #5
0
 /**
  * Creates role model
  *
  * @return \Magento\User\Model\Role
  */
 public function createRole()
 {
     return $this->_roleFactory->create();
 }
Пример #6
0
 /**
  * Get admin role model
  *
  * @return \Magento\User\Model\Role
  */
 public function getRole()
 {
     if (null === $this->_role) {
         $this->_role = $this->_roleFactory->create();
         $roles = $this->getRoles();
         if ($roles && isset($roles[0]) && $roles[0]) {
             $this->_role->load($roles[0]);
         }
     }
     return $this->_role;
 }