Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZP-32173: Fixed UDW 'allowed_content_types' configuration #1666

Merged
merged 4 commits into from
Dec 17, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
barw4 marked this conversation as resolved.
Show resolved Hide resolved
{
$access = $this->permissionResolver->hasAccess('content', 'read');
if (!\is_array($access)) {
return [];
return count($contentTypesAllowedViaConfig) ? $contentTypesAllowedViaConfig : null;
barw4 marked this conversation as resolved.
Show resolved Hide resolved
}

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

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

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

//hacky, but as of now null or empty array means UDW allows all Content Types, which shouldn't be the case
return empty($allowedContentTypesIdentifiers) ? [microtime()] : array_values($allowedContentTypesIdentifiers);
barw4 marked this conversation as resolved.
Show resolved Hide resolved
}

public static function getSubscribedEvents(): array
Expand All @@ -80,10 +85,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 ?: null;

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