-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EZEE-2533: Error HTTP 400 trying to preview Form during creation
- Loading branch information
1 parent
b0f9146
commit 7005894
Showing
6 changed files
with
232 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace EzSystems\EzPlatformAdminUi\Siteaccess; | ||
|
||
use eZ\Publish\Core\MVC\ConfigResolverInterface; | ||
|
||
abstract class AbstractSiteaccessPreviewVoter implements SiteaccessPreviewVoterInterface | ||
{ | ||
/** @var \eZ\Publish\Core\MVC\ConfigResolverInterface */ | ||
protected $configResolver; | ||
|
||
/** | ||
* @param \eZ\Publish\Core\MVC\ConfigResolverInterface $configResolver | ||
*/ | ||
public function __construct( | ||
ConfigResolverInterface $configResolver | ||
) { | ||
$this->configResolver = $configResolver; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function vote(SiteaccessPreviewVoterContext $context): bool | ||
{ | ||
$siteaccess = $context->getSiteaccess(); | ||
$location = $context->getLocation(); | ||
$languageCode = $context->getLanguageCode(); | ||
$contentLanguages = $context->getVersionInfo()->languageCodes; | ||
|
||
if (empty(array_intersect($this->getRootLocationIds($siteaccess), $location->path))) { | ||
return false; | ||
} | ||
|
||
$siteaccessLanguages = $this->configResolver->getParameter( | ||
'languages', | ||
null, | ||
$siteaccess | ||
); | ||
if (!in_array($languageCode, $siteaccessLanguages)) { | ||
return false; | ||
} | ||
|
||
$primarySiteaccessLanguage = reset($siteaccessLanguages); | ||
if ( | ||
$languageCode !== $primarySiteaccessLanguage | ||
&& in_array($primarySiteaccessLanguage, $contentLanguages) | ||
) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* @param string $siteaccess | ||
* | ||
* @return int[] | ||
*/ | ||
abstract protected function getRootLocationIds(string $siteaccess): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace EzSystems\EzPlatformAdminUi\Siteaccess; | ||
|
||
class AdminSiteaccessPreviewVoter extends AbstractSiteaccessPreviewVoter | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getRootLocationIds(string $siteaccess): array | ||
{ | ||
$locationIds = []; | ||
$locationIds[] = $this->configResolver->getParameter( | ||
'location_ids.content_structure', | ||
null, | ||
$siteaccess | ||
); | ||
$locationIds[] = $this->configResolver->getParameter( | ||
'location_ids.media', | ||
null, | ||
$siteaccess | ||
); | ||
$locationIds[] = $this->configResolver->getParameter( | ||
'location_ids.users', | ||
null, | ||
$siteaccess | ||
); | ||
|
||
return $locationIds; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace EzSystems\EzPlatformAdminUi\Siteaccess; | ||
|
||
use eZ\Publish\API\Repository\Values\Content\Location; | ||
use eZ\Publish\API\Repository\Values\Content\VersionInfo; | ||
|
||
final class SiteaccessPreviewVoterContext | ||
{ | ||
/** @var \eZ\Publish\API\Repository\Values\Content\Location */ | ||
private $location; | ||
|
||
/** @var \eZ\Publish\API\Repository\Values\Content\VersionInfo */ | ||
private $versionInfo; | ||
|
||
/** @var string */ | ||
private $siteaccess; | ||
|
||
/** @var string */ | ||
private $languageCode; | ||
|
||
public function __construct( | ||
Location $location, | ||
VersionInfo $versionInfo, | ||
string $siteaccess, | ||
string $languageCode | ||
) { | ||
$this->location = $location; | ||
$this->versionInfo = $versionInfo; | ||
$this->siteaccess = $siteaccess; | ||
$this->languageCode = $languageCode; | ||
} | ||
|
||
/** | ||
* @return \eZ\Publish\API\Repository\Values\Content\Location | ||
*/ | ||
public function getLocation(): Location | ||
{ | ||
return $this->location; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getSiteaccess(): string | ||
{ | ||
return $this->siteaccess; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getLanguageCode(): string | ||
{ | ||
return $this->languageCode; | ||
} | ||
|
||
/** | ||
* @return \eZ\Publish\API\Repository\Values\Content\VersionInfo | ||
*/ | ||
public function getVersionInfo(): VersionInfo | ||
{ | ||
return $this->versionInfo; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace EzSystems\EzPlatformAdminUi\Siteaccess; | ||
|
||
interface SiteaccessPreviewVoterInterface | ||
{ | ||
/** | ||
* Votes whether the Content item can be previewed in given siteaccess. | ||
* | ||
* @param \EzSystems\EzPlatformAdminUi\Siteaccess\SiteaccessPreviewVoterContext $context | ||
* | ||
* @return bool | ||
*/ | ||
public function vote(SiteaccessPreviewVoterContext $context): bool; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters