-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
506 additions
and
125 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/bundle/Controller/Permission/LanguageLimitationController.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,54 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Bundle\AdminUi\Controller\Permission; | ||
|
||
use Ibexa\AdminUi\Permission\LimitationResolverInterface; | ||
use Ibexa\Contracts\AdminUi\Controller\Controller; | ||
use Ibexa\Contracts\Core\Repository\ContentService; | ||
use Ibexa\Contracts\Core\Repository\LocationService; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
final class LanguageLimitationController extends Controller | ||
{ | ||
private ContentService $contentService; | ||
|
||
private LocationService $locationService; | ||
|
||
private LimitationResolverInterface $limitationResolver; | ||
|
||
public function __construct( | ||
ContentService $contentService, | ||
LocationService $locationService, | ||
LimitationResolverInterface $limitationResolver | ||
) { | ||
$this->contentService = $contentService; | ||
$this->locationService = $locationService; | ||
$this->limitationResolver = $limitationResolver; | ||
} | ||
|
||
public function loadLanguageLimitationsForContentAction( | ||
int $contentId, | ||
?int $versionNo = null, | ||
?int $locationId = null | ||
): Response { | ||
$versionInfo = $this->contentService->loadVersionInfoById($contentId, $versionNo); | ||
|
||
if (null === $locationId) { | ||
$locationId = $versionInfo->getContentInfo()->getMainLocationId(); | ||
} | ||
|
||
return new JsonResponse( | ||
$this->limitationResolver->getLanguageLimitations( | ||
$versionInfo, | ||
$this->locationService->loadLocation($locationId) | ||
) | ||
); | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
src/bundle/Resources/views/themes/admin/ui/html_body.html.twig
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,22 @@ | ||
<div class="ibexa-embedded-item-edit-container"> | ||
{% set form = ibexa_render_embedded_item_edit_form() %} | ||
|
||
{{ form_start(form) }} | ||
{{ form_widget(form.content_info, { 'attr': { | ||
'hidden': 'hidden', | ||
'class': 'ibexa-embedded-item-edit__form-field ibexa-embedded-item-edit__form-field--content-info' | ||
} }) }} | ||
{{ form_widget(form.version_info, { 'attr': { | ||
'hidden': 'hidden', | ||
'class': 'ibexa-embedded-item-edit__form-field ibexa-embedded-item-edit__form-field--version-info' | ||
} }) }} | ||
{{ form_widget(form.language, { 'attr': { | ||
'hidden': 'hidden', | ||
'class': 'ibexa-embedded-item-edit__form-field ibexa-embedded-item-edit__form-field--language' | ||
} }) }} | ||
{{ form_widget(form.location, { 'attr': { | ||
'hidden': 'hidden', | ||
'class': 'ibexa-embedded-item-edit__form-field ibexa-embedded-item-edit__form-field--location' | ||
} }) }} | ||
{{ form_end(form) }} | ||
</div> |
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
52 changes: 52 additions & 0 deletions
52
src/bundle/Templating/Twig/EmbeddedItemEditFormExtension.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,52 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Bundle\AdminUi\Templating\Twig; | ||
|
||
use Ibexa\AdminUi\Form\Data\Content\Draft\ContentEditData; | ||
use Ibexa\AdminUi\Form\Factory\FormFactory; | ||
use Symfony\Component\Form\FormView; | ||
use Symfony\Component\Routing\RouterInterface; | ||
use Twig\Extension\AbstractExtension; | ||
use Twig\TwigFunction; | ||
|
||
final class EmbeddedItemEditFormExtension extends AbstractExtension | ||
{ | ||
private FormFactory $formFactory; | ||
|
||
private RouterInterface $router; | ||
|
||
public function __construct( | ||
FormFactory $formFactory, | ||
RouterInterface $router | ||
) { | ||
$this->formFactory = $formFactory; | ||
$this->router = $router; | ||
} | ||
|
||
public function getFunctions(): array | ||
{ | ||
return [ | ||
new TwigFunction( | ||
'ibexa_render_embedded_item_edit_form', | ||
[$this, 'renderEmbeddedItemEditForm'] | ||
), | ||
]; | ||
} | ||
|
||
public function renderEmbeddedItemEditForm(): FormView | ||
{ | ||
return $this->formFactory->contentEdit( | ||
new ContentEditData(), | ||
'embedded_item_edit', | ||
[ | ||
'action' => $this->router->generate('ibexa.content.edit'), | ||
] | ||
)->createView(); | ||
} | ||
} |
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,154 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\AdminUi\Permission; | ||
|
||
use Ibexa\Contracts\Core\Limitation\Target\Builder\VersionBuilder; | ||
use Ibexa\Contracts\Core\Repository\ContentService; | ||
use Ibexa\Contracts\Core\Repository\ContentTypeService; | ||
use Ibexa\Contracts\Core\Repository\LanguageService; | ||
use Ibexa\Contracts\Core\Repository\LocationService; | ||
use Ibexa\Contracts\Core\Repository\PermissionResolver; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Language; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Location; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo; | ||
use Ibexa\Contracts\Core\Repository\Values\User\Limitation; | ||
use Ibexa\Contracts\Core\Repository\Values\User\LookupLimitationResult; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class LimitationResolver implements LimitationResolverInterface | ||
{ | ||
private ContentService $contentService; | ||
|
||
private ContentTypeService $contentTypeService; | ||
|
||
private LanguageService $languageService; | ||
|
||
private LocationService $locationService; | ||
|
||
private LookupLimitationsTransformer $lookupLimitationsTransformer; | ||
|
||
private PermissionResolver $permissionResolver; | ||
|
||
public function __construct( | ||
ContentService $contentService, | ||
ContentTypeService $contentTypeService, | ||
LanguageService $languageService, | ||
LocationService $locationService, | ||
LookupLimitationsTransformer $lookupLimitationsTransformer, | ||
PermissionResolver $permissionResolver | ||
) { | ||
$this->contentService = $contentService; | ||
$this->contentTypeService = $contentTypeService; | ||
$this->languageService = $languageService; | ||
$this->locationService = $locationService; | ||
$this->lookupLimitationsTransformer = $lookupLimitationsTransformer; | ||
$this->permissionResolver = $permissionResolver; | ||
} | ||
|
||
public function getContentCreateLimitations(Location $parentLocation): LookupLimitationResult | ||
{ | ||
$contentInfo = $parentLocation->getContentInfo(); | ||
$contentType = $this->contentTypeService->loadContentType($contentInfo->getContentType()->id); | ||
$contentCreateStruct = $this->contentService->newContentCreateStruct($contentType, $contentInfo->getMainLanguageCode()); | ||
$contentCreateStruct->sectionId = $contentInfo->getSection(); | ||
$locationCreateStruct = $this->locationService->newLocationCreateStruct($parentLocation->id); | ||
|
||
$versionBuilder = new VersionBuilder(); | ||
$versionBuilder->translateToAnyLanguageOf($this->getActiveLanguageCodes()); | ||
$versionBuilder->createFromAnyContentTypeOf($this->getContentTypeIds()); | ||
|
||
return $this->permissionResolver->lookupLimitations( | ||
'content', | ||
'create', | ||
$contentCreateStruct, | ||
[$versionBuilder->build(), $locationCreateStruct], | ||
[Limitation::CONTENTTYPE, Limitation::LANGUAGE] | ||
); | ||
} | ||
|
||
public function getContentUpdateLimitations(Location $parentLocation): LookupLimitationResult | ||
{ | ||
$versionBuilder = new VersionBuilder(); | ||
$versionBuilder->translateToAnyLanguageOf($this->getActiveLanguageCodes()); | ||
$versionBuilder->createFromAnyContentTypeOf($this->getContentTypeIds()); | ||
|
||
return $this->permissionResolver->lookupLimitations( | ||
'content', | ||
'edit', | ||
$parentLocation->getContentInfo(), | ||
[$versionBuilder->build(), $parentLocation], | ||
[Limitation::CONTENTTYPE, Limitation::LANGUAGE] | ||
); | ||
} | ||
|
||
public function getLanguageLimitations( | ||
VersionInfo $versionInfo, | ||
Location $location | ||
): array { | ||
$languages = $versionInfo->getLanguages(); | ||
$lookupLimitations = $this->permissionResolver->lookupLimitations( | ||
'content', | ||
'edit', | ||
$versionInfo->getContentInfo(), | ||
[ | ||
(new VersionBuilder())->translateToAnyLanguageOf($this->getActiveLanguageCodes($languages))->build(), | ||
$location, | ||
], | ||
[Limitation::LANGUAGE] | ||
); | ||
|
||
$limitationLanguageCodes = $this->lookupLimitationsTransformer->getFlattenedLimitationsValues($lookupLimitations); | ||
|
||
return array_map( | ||
static function (Language $language) use ($limitationLanguageCodes): array { | ||
return [ | ||
'languageCode' => $language->getLanguageCode(), | ||
'name' => $language->getName(), | ||
'hasAccess' => empty($limitationLanguageCodes) || in_array($language->getLanguageCode(), $limitationLanguageCodes, true), | ||
]; | ||
}, | ||
$languages | ||
); | ||
} | ||
|
||
/** | ||
* @return array<string> | ||
*/ | ||
private function getContentTypeIds(): array | ||
{ | ||
$contentTypeIds = []; | ||
|
||
$contentTypeGroups = $this->contentTypeService->loadContentTypeGroups(); | ||
foreach ($contentTypeGroups as $contentTypeGroup) { | ||
$contentTypes = $this->contentTypeService->loadContentTypes($contentTypeGroup); | ||
foreach ($contentTypes as $contentType) { | ||
$contentTypeIds[] = $contentType->id; | ||
} | ||
} | ||
|
||
return $contentTypeIds; | ||
} | ||
|
||
/** | ||
* @return array<string> | ||
*/ | ||
private function getActiveLanguageCodes(?array $languageCodes = null): array | ||
{ | ||
$filter = array_filter( | ||
$languageCodes ?? $this->languageService->loadLanguages(), | ||
static function (Language $language) { | ||
return $language->enabled; | ||
} | ||
); | ||
|
||
return array_column($filter, 'languageCode'); | ||
} | ||
} |
Oops, something went wrong.