Skip to content

Commit

Permalink
Backport #4396 to Magento 2.1
Browse files Browse the repository at this point in the history
This backports a removal of the hardcoding the array index of
Magento_Backend::admin in the resources ACL tree

Original commit 66d1960
  • Loading branch information
Navarr Barnier authored and Navarr Barnier committed Oct 30, 2017
1 parent 97a0832 commit c766c66
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,11 @@ public function isEverythingAllowed()
public function getResourcesTreeJson()
{
$resources = $this->_resourceProvider->getAclResources();
$aclResourcesTree = $this->_integrationData->mapResources($resources[1]['children']);
$configResource = array_filter($resources, function ($node) {
return isset($node['id']) && $node['id'] == 'Magento_Backend::admin';
});
$configResource = reset($configResource);
$aclResourcesTree = $this->_integrationData->mapResources($configResource['children']);

return $this->encoder->encode($aclResourcesTree);
}
Expand All @@ -167,7 +171,11 @@ public function getSelectedResourcesJson()
$selectedResources = $this->_selectedResources;
if ($this->isEverythingAllowed()) {
$resources = $this->_resourceProvider->getAclResources();
$selectedResources = $this->_getAllResourceIds($resources[1]['children']);
$configResource = array_filter($resources, function ($node) {
return isset($node['id']) && $node['id'] == 'Magento_Backend::admin';
});
$configResource = reset($configResource);
$selectedResources = $this->_getAllResourceIds($configResource['children']);
}
return $this->encoder->encode($selectedResources);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ protected function _construct()

/**
* Retrieve saved resource
*
*
* @return array|bool
*/
protected function retrieveFormResources()
Expand Down Expand Up @@ -176,8 +176,12 @@ public function isEverythingAllowed()
public function getTree()
{
$resources = $this->aclResourceProvider->getAclResources();
$configResource = array_filter($resources, function ($node) {
return isset($node['id']) && $node['id'] == 'Magento_Backend::admin';
});
$configResource = reset($configResource);
$rootArray = $this->integrationData->mapResources(
isset($resources[1]['children']) ? $resources[1]['children'] : []
isset($configResource['children']) ? $configResource['children'] : []
);
return $rootArray;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function testGetTree()
{
$this->webapiBlock = $this->getWebapiBlock();
$resources = [
1 => [ 'children' => [1, 2, 3] ]
1 => [ 'id' => 'Magento_Backend::admin', 'children' => [1, 2, 3] ]
];
$this->aclResourceProvider->expects($this->once())
->method('getAclResources')
Expand Down
6 changes: 5 additions & 1 deletion app/code/Magento/User/Block/Role/Tab/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,12 @@ public function getSelectedResources()
public function getTree()
{
$resources = $this->_aclResourceProvider->getAclResources();
$configResource = array_filter($resources, function ($node) {
return isset($node['id']) && $node['id'] == 'Magento_Backend::admin';
});
$configResource = reset($configResource);
$rootArray = $this->_integrationData->mapResources(
isset($resources[1]['children']) ? $resources[1]['children'] : []
isset($configResource['children']) ? $configResource['children'] : []
);
return $rootArray;
}
Expand Down

0 comments on commit c766c66

Please sign in to comment.