9 use Magento\Authorization\Model\ResourceModel\Role\CollectionFactory as RoleCollectionFactory;
10 use Magento\Authorization\Model\ResourceModel\Rules\CollectionFactory as RulesCollectionFactory;
12 use Magento\Authorization\Model\RoleFactory;
13 use Magento\Authorization\Model\RulesFactory;
19 use Psr\Log\LoggerInterface as Logger;
76 AclBuilder $aclBuilder,
77 RoleFactory $roleFactory,
78 RoleCollectionFactory $roleCollectionFactory,
79 RulesFactory $rulesFactory,
80 RulesCollectionFactory $rulesCollectionFactory,
82 RootAclResource $rootAclResource
84 $this->_aclBuilder = $aclBuilder;
85 $this->_roleFactory = $roleFactory;
86 $this->_rulesFactory = $rulesFactory;
87 $this->_rulesCollectionFactory = $rulesCollectionFactory;
88 $this->_roleCollectionFactory = $roleCollectionFactory;
90 $this->_rootAclResource = $rootAclResource;
99 $role = $this->_getUserRole($integrationId);
103 $this->_associateResourcesWithRole($role, $resources);
104 }
catch (\Exception $e) {
105 $this->_logger->critical($e);
107 __(
'An error occurred during the attempt to grant permissions. For details, see the exceptions log.')
117 $this->
grantPermissions($integrationId, [$this->_rootAclResource->getId()]);
127 }
catch (\Exception $e) {
128 $this->_logger->critical($e);
131 'Something went wrong while deleting roles and permissions.' 132 .
' You can find out more in the exceptions log.' 147 $role = $this->_roleFactory->create();
148 $role->setRoleName($roleName)
150 ->setUserId($integrationId)
151 ->setRoleType(\
Magento\Authorization\Model\
Acl\
Role\User::ROLE_TYPE)
166 $role = $this->_roleFactory->create()->load($roleName,
'role_name');
167 return $role->delete();
176 protected function _getUserRole($integrationId)
178 $roleCollection = $this->_roleCollectionFactory->create();
180 $role = $roleCollection
183 return $role->getId() ? $role :
false;
194 protected function _associateResourcesWithRole($role, $resources)
197 $rules = $this->_rulesFactory->create();
198 $rules->setRoleId($role->getId())->setResources($resources)->saveRel();
grantAllPermissions($integrationId)
removePermissions($integrationId)
__construct(AclBuilder $aclBuilder, RoleFactory $roleFactory, RoleCollectionFactory $roleCollectionFactory, RulesFactory $rulesFactory, RulesCollectionFactory $rulesCollectionFactory, Logger $logger, RootAclResource $rootAclResource)
_createRole($integrationId)
_deleteRole($integrationId)
grantPermissions($integrationId, $resources)
const USER_TYPE_INTEGRATION