9 use Magento\Authorization\Model\ResourceModel\Role\CollectionFactory as RoleCollectionFactory;
10 use Magento\Authorization\Model\ResourceModel\Rules\CollectionFactory as RulesCollectionFactory;
16 use Psr\Log\LoggerInterface as Logger;
84 $role = $this->_getUserRole($userType, $userId);
87 __(
"The role wasn't found for the user. Verify the role and try again.")
93 }
catch (\Exception $e) {
94 $this->logger->critical($e);
97 'Something went wrong while compiling a list of allowed resources. ' 98 .
'You can find out more in the exceptions log.' 111 public function getAllowedResourcesByRole(
$roleId)
114 $rulesCollection = $this->rulesCollectionFactory->create();
115 $rulesCollection->getByRoles(
$roleId)->load();
116 $acl = $this->aclBuilder->getAcl();
118 foreach ($rulesCollection->getItems() as $ruleItem) {
119 $resourceId = $ruleItem->getResourceId();
120 if ($acl->has($resourceId) && $acl->isAllowed(
$roleId, $resourceId)) {
135 protected function _getUserRole($userType, $userId)
138 throw new \LogicException(
139 "The role with user type '{$userType}' does not exist and cannot be created" 142 $roleCollection = $this->roleCollectionFactory->create();
144 $role = $roleCollection->setUserFilter($userId, $userType)->getFirstItem();
145 return $role->getId() ? $role :
false;
const PERMISSION_ANONYMOUS
elseif(isset( $params[ 'redirect_parent']))
__construct(AclBuilder $aclBuilder, RoleCollectionFactory $roleCollectionFactory, RulesCollectionFactory $rulesCollectionFactory, Logger $logger)
getAllowedResourcesByUser($userType, $userId)
_canRoleBeCreatedForUserType($userType)
const USER_TYPE_INTEGRATION