Skip to content

Commit

Permalink
Merge branch '7.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
andrerom committed Apr 10, 2018
2 parents a7f261e + a45a2c6 commit 945efb7
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions eZ/Publish/Core/Repository/Permission/CachedPermissionService.php
Expand Up @@ -11,6 +11,7 @@
use eZ\Publish\API\Repository\Repository as RepositoryInterface;
use eZ\Publish\API\Repository\Values\User\UserReference;
use eZ\Publish\API\Repository\Values\ValueObject;
use Exception;

/**
* Cache implementation of PermissionResolver and PermissionCriterionResolver interface.
Expand Down Expand Up @@ -40,6 +41,13 @@ class CachedPermissionService implements APIPermissionResolver, APIPermissionCri
*/
private $cacheTTL;

/**
* Counter for the current sudo nesting level {@see sudo()}.
*
* @var int
*/
private $sudoNestingLevel = 0;

/**
* Cached value for current user's getCriterion() result.
*
Expand Down Expand Up @@ -99,7 +107,7 @@ public function getPermissionsCriterion($module = 'content', $function = 'read')
{
// We only cache content/read lookup as those are the once frequently done, and it's only one we can safely
// do that won't harm the system if it becomes stale (but user might experience permissions exceptions if it do)
if ($module !== 'content' || $function !== 'read') {
if ($module !== 'content' || $function !== 'read' || $this->sudoNestingLevel > 0) {
return $this->permissionCriterionResolver->getPermissionsCriterion($module, $function);
}

Expand All @@ -121,6 +129,15 @@ public function getPermissionsCriterion($module = 'content', $function = 'read')
*/
public function sudo(\Closure $callback, RepositoryInterface $outerRepository)
{
return $this->permissionResolver->sudo($callback, $outerRepository);
++$this->sudoNestingLevel;
try {
$returnValue = $this->permissionResolver->sudo($callback, $outerRepository);
} catch (Exception $e) {
--$this->sudoNestingLevel;
throw $e;
}
--$this->sudoNestingLevel;

return $returnValue;
}
}

0 comments on commit 945efb7

Please sign in to comment.