0

I create an admin user role from setup using this code,

$role=$this->_roleFactory->create();
$role->setName('test') 
     ->setPid(0)
     ->setRoleType(RoleGroup::ROLE_TYPE) 
     ->setUserType(UserContextInterface::USER_TYPE_ADMIN); 

$role->save(); 
$resource=[
  'Magento_Backend::admin'
]; 

$this->_rulesFactory->create()
     ->setRoleId($role->getId())->setResources($resource)->saveRel(); 

But I want to add a new resource to this role, using UpgradeData.

Is there any solution?

1

I do it, using this code :

$role = $this->_roleCollection->addFieldToFilter('role_name', 'test')->getFirstItem();
$resource = $this->_aclRetriver->getAllowedResourcesByRole($role->getId());
array_push($resource,
   'Magento_Catalog::products'
);
$this->_rulesFactory->create()->setRoleId($role->getId())->setResources($resource)->saveRel();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.