Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch '6.13' into 7.1
  • Loading branch information
andrerom committed May 2, 2018
2 parents 1a392f2 + 0981954 commit 9a70e57
Showing 1 changed file with 26 additions and 7 deletions.
Expand Up @@ -14,28 +14,47 @@ class PoliciesConfigBuilder extends ContainerConfigBuilder
{
public function addConfig(array $config)
{
$policyMap = [];
$previousPolicyMap = [];

if ($this->containerBuilder->hasParameter('ezpublish.api.role.policy_map')) {
$previousPolicyMap = $this->containerBuilder->getParameter('ezpublish.api.role.policy_map');
}

// We receive limitations as values, but we want them as keys to be used by isset().
foreach ($config as $module => $functionArray) {
foreach ($functionArray as $function => $limitationCollection) {
$policyMap[$module][$function] = array_fill_keys((array)$limitationCollection, true);
}
}
if (null !== $limitationCollection && $this->policyExists($previousPolicyMap, $module, $function)) {
$limitations = array_merge_recursive($previousPolicyMap[$module][$function], array_fill_keys((array)$limitationCollection, true));
} else {
$limitations = array_fill_keys((array)$limitationCollection, true);
}

if ($this->containerBuilder->hasParameter('ezpublish.api.role.policy_map')) {
$previousPolicyMap = $this->containerBuilder->getParameter('ezpublish.api.role.policy_map');
$previousPolicyMap[$module][$function] = $limitations;
}
}

$this->containerBuilder->setParameter(
'ezpublish.api.role.policy_map',
array_merge_recursive($previousPolicyMap, $policyMap)
$previousPolicyMap
);
}

public function addResource(ResourceInterface $resource)
{
$this->containerBuilder->addResource($resource);
}

/**
* Checks if policy for module and function exist in Policy Map.
*
* @param array $policyMap
* @param string $module
* @param string $function
*
* @return bool
*/
private function policyExists(array $policyMap, $module, $function)
{
return array_key_exists($module, $policyMap) && array_key_exists($function, $policyMap[$module]);
}
}

0 comments on commit 9a70e57

Please sign in to comment.