-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EZP-29742: Implement permissions for Content/Create in Content item view
- Loading branch information
1 parent
997b274
commit 51d7a63
Showing
19 changed files
with
648 additions
and
80 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
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
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
12 changes: 12 additions & 0 deletions
12
src/lib/Form/Type/ChoiceList/Provider/ChoiceListProviderInterface.php
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,12 @@ | ||
<?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. | ||
*/ | ||
namespace EzSystems\EzPlatformAdminUi\Form\Type\ChoiceList\Provider; | ||
|
||
interface ChoiceListProviderInterface | ||
{ | ||
public function getChoiceList(): array; | ||
} |
39 changes: 39 additions & 0 deletions
39
src/lib/Form/Type/ChoiceList/Provider/ContentTypeChoiceListProvider.php
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,39 @@ | ||
<?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\Form\Type\ChoiceList\Provider; | ||
|
||
use eZ\Publish\API\Repository\ContentTypeService; | ||
|
||
class ContentTypeChoiceListProvider implements ChoiceListProviderInterface | ||
{ | ||
/** @var \eZ\Publish\API\Repository\ContentTypeService */ | ||
protected $contentTypeService; | ||
|
||
/** | ||
* @param \eZ\Publish\API\Repository\ContentTypeService $contentTypeService | ||
*/ | ||
public function __construct(ContentTypeService $contentTypeService) | ||
{ | ||
$this->contentTypeService = $contentTypeService; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getChoiceList(): array | ||
{ | ||
$contentTypes = []; | ||
$contentTypeGroups = $this->contentTypeService->loadContentTypeGroups(); | ||
foreach ($contentTypeGroups as $contentTypeGroup) { | ||
$contentTypes[$contentTypeGroup->identifier] = $this->contentTypeService->loadContentTypes($contentTypeGroup); | ||
} | ||
|
||
return $contentTypes; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/lib/Form/Type/ChoiceList/Provider/LanguageChoiceListProvider.php
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,56 @@ | ||
<?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\Form\Type\ChoiceList\Provider; | ||
|
||
use eZ\Publish\API\Repository\LanguageService; | ||
|
||
class LanguageChoiceListProvider implements ChoiceListProviderInterface | ||
{ | ||
/** @var \eZ\Publish\API\Repository\LanguageService */ | ||
protected $languageService; | ||
|
||
/** @var array */ | ||
protected $siteAccessLanguages; | ||
|
||
/** | ||
* @param \eZ\Publish\API\Repository\LanguageService $languageService | ||
* @param array $siteAccessLanguages | ||
*/ | ||
public function __construct(LanguageService $languageService, array $siteAccessLanguages) | ||
{ | ||
$this->languageService = $languageService; | ||
$this->siteAccessLanguages = $siteAccessLanguages; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getChoiceList(): array | ||
{ | ||
$saLanguages = []; | ||
$languagesByCode = []; | ||
|
||
foreach ($this->languageService->loadLanguages() as $language) { | ||
if ($language->enabled) { | ||
$languagesByCode[$language->languageCode] = $language; | ||
} | ||
} | ||
|
||
foreach ($this->siteAccessLanguages as $languageCode) { | ||
if (!isset($languagesByCode[$languageCode])) { | ||
continue; | ||
} | ||
|
||
$saLanguages[] = $languagesByCode[$languageCode]; | ||
unset($languagesByCode[$languageCode]); | ||
} | ||
|
||
return array_merge($saLanguages, array_values($languagesByCode)); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
src/lib/Form/Type/ChoiceList/Provider/PermissionAwareContentTypeChoiceListProvider.php
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,80 @@ | ||
<?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\Form\Type\ChoiceList\Provider; | ||
|
||
use eZ\Publish\API\Repository\PermissionResolver; | ||
use eZ\Publish\API\Repository\Values\User\Limitation\ContentTypeLimitation; | ||
use EzSystems\EzPlatformAdminUi\Util\PermissionUtilInterface; | ||
use eZ\Publish\API\Repository\Values\ContentType\ContentType; | ||
|
||
class PermissionAwareContentTypeChoiceListProvider implements ChoiceListProviderInterface | ||
{ | ||
/** @var \EzSystems\EzPlatformAdminUi\Form\Type\ChoiceList\Provider\ChoiceListProviderInterface */ | ||
private $decorated; | ||
|
||
/** @var \eZ\Publish\API\Repository\PermissionResolver */ | ||
private $permissionResolver; | ||
|
||
/** @var \EzSystems\EzPlatformAdminUi\Util\PermissionUtilInterface */ | ||
private $permissionUtil; | ||
|
||
/** @var string */ | ||
private $module; | ||
|
||
/** @var string */ | ||
private $function; | ||
|
||
/** | ||
* @param \eZ\Publish\API\Repository\PermissionResolver $permissionResolver | ||
* @param \EzSystems\EzPlatformAdminUi\Util\PermissionUtilInterface $permissionUtil | ||
* @param \EzSystems\EzPlatformAdminUi\Form\Type\ChoiceList\Provider\ContentTypeChoiceListProvider $decorated | ||
* @param string $module | ||
* @param string $function | ||
*/ | ||
public function __construct( | ||
PermissionResolver $permissionResolver, | ||
PermissionUtilInterface $permissionUtil, | ||
ContentTypeChoiceListProvider $decorated, | ||
string $module, | ||
string $function | ||
) { | ||
$this->decorated = $decorated; | ||
$this->permissionResolver = $permissionResolver; | ||
$this->permissionUtil = $permissionUtil; | ||
$this->module = $module; | ||
$this->function = $function; | ||
} | ||
|
||
/** | ||
* @return array | ||
* | ||
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException | ||
*/ | ||
public function getChoiceList(): array | ||
{ | ||
$hasAccess = $this->permissionResolver->hasAccess($this->module, $this->function); | ||
if (!is_bool($hasAccess)) { | ||
$restrictedContentTypesIds = $this->permissionUtil->getRestrictions($hasAccess, ContentTypeLimitation::class); | ||
} | ||
|
||
$contentTypesGroups = $this->decorated->getChoiceList(); | ||
|
||
if (empty($restrictedContentTypesIds)) { | ||
return $contentTypesGroups; | ||
} | ||
|
||
foreach ($contentTypesGroups as $group => $contentTypes) { | ||
$contentTypesGroups[$group] = array_filter($contentTypes, function (ContentType $contentType) use ($restrictedContentTypesIds) { | ||
return in_array($contentType->id, $restrictedContentTypesIds); | ||
}); | ||
} | ||
|
||
return $contentTypesGroups; | ||
} | ||
} |
Oops, something went wrong.