Skip to content

Commit

Permalink
Merge branch '2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
barw4 committed Dec 17, 2020
2 parents eb6fea5 + bea40eb commit 8eb0772
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,9 @@ public function testUdwConfigResolveOnUnsupportedConfigName(): void
$this->assertEquals([], $event->getConfig());
}

/**
* @dataProvider dataProviderForUdwConfigResolveWhenThereIsNoContentReadLimitations
*/
public function testUdwConfigResolveWhenThereIsNoContentReadLimitations(bool $hasAccess): void
public function testUdwConfigResolveWhenThereIsNoContentReadLimitations(): void
{
$this->permissionResolver->method('hasAccess')->with('content', 'read')->willReturn($hasAccess);
$this->permissionResolver->method('hasAccess')->with('content', 'read')->willReturn(true);
$this->permissionChecker->expects($this->never())->method('getRestrictions');
$this->contentTypeService->expects($this->never())->method('loadContentTypeList');

Expand All @@ -78,12 +75,15 @@ public function testUdwConfigResolveWhenThereIsNoContentReadLimitations(bool $ha
]);
}

public function dataProviderForUdwConfigResolveWhenThereIsNoContentReadLimitations(): iterable
public function testUdwConfigResolveWhenThereIsNoContentReadLimitationsAndNoAccess(): void
{
return [
['hasAccess' => false],
['hasAccess' => true],
];
$this->permissionResolver->method('hasAccess')->with('content', 'read')->willReturn(false);
$this->permissionChecker->expects($this->never())->method('getRestrictions');
$this->contentTypeService->expects($this->never())->method('loadContentTypeList');

$this->assertConfigurationResolvingResult([
'allowed_content_types' => [null],
]);
}

public function testUdwConfigResolveWhenThereAreContentReadLimitations(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ public function __construct(
/**
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
*/
private function getAllowedContentTypesIdentifiers(): array
private function getAllowedContentTypesIdentifiers(array $contentTypesAllowedViaConfig): ?array
{
$access = $this->permissionResolver->hasAccess('content', 'read');
if (!\is_array($access)) {
return [];
return $access ? ($contentTypesAllowedViaConfig ?: null) : [null];
}

$restrictedContentTypesIds = $this->permissionChecker->getRestrictions($access, ContentTypeLimitation::class);
if (empty($restrictedContentTypesIds)) {
return [];
return $contentTypesAllowedViaConfig ?: null;
}

$allowedContentTypesIdentifiers = [];
Expand All @@ -61,7 +61,11 @@ private function getAllowedContentTypesIdentifiers(): array
$allowedContentTypesIdentifiers[] = $contentType->identifier;
}

return $allowedContentTypesIdentifiers;
$allowedContentTypesIdentifiers = count($contentTypesAllowedViaConfig)
? array_intersect($contentTypesAllowedViaConfig, $allowedContentTypesIdentifiers)
: $allowedContentTypesIdentifiers;

return empty($allowedContentTypesIdentifiers) ? [null] : array_values($allowedContentTypesIdentifiers);
}

public static function getSubscribedEvents(): array
Expand All @@ -80,10 +84,10 @@ public function onUdwConfigResolve(ConfigResolveEvent $event): void
}

if ($this->allowedContentTypesIdentifiers === null) {
$this->allowedContentTypesIdentifiers = $this->getAllowedContentTypesIdentifiers();
$this->allowedContentTypesIdentifiers = $this->getAllowedContentTypesIdentifiers($config['allowed_content_types'] ?? []);
}

$config['allowed_content_types'] = !empty($this->allowedContentTypesIdentifiers) ? $this->allowedContentTypesIdentifiers : null;
$config['allowed_content_types'] = $this->allowedContentTypesIdentifiers;

$event->setConfig($config);
}
Expand Down

0 comments on commit 8eb0772

Please sign in to comment.