/** * @return $this */ protected function _prepareCollection() { $collection = $this->_userRolesFactory->create(); $collection->setRolesFilter(); $this->setCollection($collection); return parent::_prepareCollection(); }
/** * {@inheritdoc} */ public function getAclRoleId() { $userId = $this->userContext->getUserId(); $userType = $this->userContext->getUserType(); $roleCollection = $this->roleCollectionFactory->create(); /** @var Role $role */ $role = $roleCollection->setUserFilter($userId, $userType)->getFirstItem(); if (!$role->getId()) { return null; } return $role->getId(); }
/** * Identify authorization role associated with provided integration. * * @param int $integrationId * @return \Magento\Authorization\Model\Role|false Return false in case when no role associated with user was found. */ protected function _getUserRole($integrationId) { $roleCollection = $this->_roleCollectionFactory->create(); /** @var Role $role */ $role = $roleCollection->setUserFilter($integrationId, UserContextInterface::USER_TYPE_INTEGRATION)->getFirstItem(); return $role->getId() ? $role : false; }
/** * Identify user role from user identifier. * * @param string $userType * @param int $userId * @return \Magento\Authorization\Model\Role|bool False if no role associated with provided user was found. * @throws \LogicException */ protected function _getUserRole($userType, $userId) { if (!$this->_canRoleBeCreatedForUserType($userType)) { throw new \LogicException("The role with user type '{$userType}' does not exist and cannot be created"); } $roleCollection = $this->roleCollectionFactory->create(); /** @var Role $role */ $role = $roleCollection->setUserFilter($userId, $userType)->getFirstItem(); return $role->getId() ? $role : false; }