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-29742: Implement permissions for Content/Create in Content item view #713

Merged
merged 5 commits into from
Nov 20, 2018
Merged
Show file tree
Hide file tree
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
Prev Previous commit
Next Next commit
EZP-29742: Implement permissions for Content/Create in Content item v…
…iew - choice loaders
  • Loading branch information
mikadamczyk committed Nov 20, 2018
commit afe3a5ff8e15118de2213689b16c688e5694a7c1
49 changes: 2 additions & 47 deletions src/bundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ imports:
- { resource: services/translation.yml }
- { resource: services/user_settings.yml }
- { resource: services/rest.yml }
- { resource: services/permission.yml }
- { resource: services/permissions.yml }
- { resource: services/forms.yml }

services:
_defaults:
Expand Down Expand Up @@ -77,23 +78,6 @@ services:
tags:
- {name: kernel.event_subscriber}

EzSystems\EzPlatformAdminUi\Form\SubmitHandler: ~

EzSystems\EzPlatformAdminUi\Form\Type\:
resource: '../../../lib/Form/Type'

EzSystems\EzPlatformAdminUi\Form\DataMapper\:
resource: '../../../lib/Form/DataMapper'

EzSystems\EzPlatformAdminUi\Form\Type\Policy\PolicyChoiceType:
arguments:
$policyMap: "%ezpublish.api.role.policy_map%"

EzSystems\EzPlatformAdminUi\Form\Type\Content\Draft\ContentCreateType:
arguments:
$choiceListProvider: '@EzSystems\EzPlatformAdminUi\Form\Type\ChoiceList\Provider\PermissionAwareContentTypeChoiceListProvider'
$languageChoiceListProvider: '@EzSystems\EzPlatformAdminUi\Form\Type\ChoiceList\Provider\PermissionAwareLanguageChoiceListProvider'

EzSystems\EzPlatformAdminUi\UI\Dataset\DatasetFactory:
arguments:
$userContentTypeIdentifier: '$user_content_type_identifier$'
Expand All @@ -107,16 +91,10 @@ services:
tags:
- { name: form.type }

EzSystems\EzPlatformAdminUi\Form\Factory\FormFactory: ~

EzSystems\EzPlatformAdminUi\Notification\FlashBagNotificationHandler: ~

EzSystems\EzPlatformAdminUi\Notification\NotificationHandlerInterface: '@EzSystems\EzPlatformAdminUi\Notification\FlashBagNotificationHandler'

EzSystems\EzPlatformAdminUi\Form\Type\Extension\Content\ContentEditTypeExtension:
tags:
- { name: form.type_extension, extended_type: EzSystems\RepositoryForms\Form\Type\Content\ContentEditType }

EzSystems\EzPlatformAdminUi\RepositoryForms\View\ViewParametersListener:
public: true
tags:
Expand All @@ -141,9 +119,6 @@ services:
tags:
- { name: knp_menu.voter }

EzSystems\EzPlatformAdminUi\Form\EventListener\:
resource: '../../../lib/Form/EventListener'

EzSystems\EzPlatformAdminUi\RepositoryForms\Dispatcher\ContentOnTheFlyDispatcher:
calls:
- [setEventDispatcher, ["@event_dispatcher"]]
Expand All @@ -153,23 +128,3 @@ services:
- {name: kernel.event_subscriber, priority: -250}

EzSystems\EzPlatformAdminUiBundle\Templating\Twig\UserPreferencesGlobalExtension: ~

EzSystems\EzPlatformAdminUi\Form\Type\ChoiceList\Provider\ContentTypeChoiceListProvider: ~

EzSystems\EzPlatformAdminUi\Form\Type\ChoiceList\Provider\LanguageChoiceListProvider:
arguments:
$siteAccessLanguages: '$languages$'

EzSystems\EzPlatformAdminUi\Form\Type\ChoiceList\Provider\PermissionAwareContentTypeChoiceListProvider:
arguments:
$decorated: '@EzSystems\EzPlatformAdminUi\Form\Type\ChoiceList\Provider\ContentTypeChoiceListProvider'
$module: 'content'
$function: 'create'

EzSystems\EzPlatformAdminUi\Form\Type\ChoiceList\Provider\PermissionAwareLanguageChoiceListProvider:
arguments:
$decorated: '@EzSystems\EzPlatformAdminUi\Form\Type\ChoiceList\Provider\LanguageChoiceListProvider'
$module: 'content'
$function: 'create'


49 changes: 49 additions & 0 deletions src/bundle/Resources/config/services/forms.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
services:
_defaults:
autowire: true
autoconfigure: true
public: false

EzSystems\EzPlatformAdminUi\Form\SubmitHandler: ~

EzSystems\EzPlatformAdminUi\Form\Factory\FormFactory: ~

EzSystems\EzPlatformAdminUi\Form\DataMapper\:
resource: '../../../lib/Form/DataMapper'

EzSystems\EzPlatformAdminUi\Form\Type\:
resource: '../../../lib/Form/Type'

EzSystems\EzPlatformAdminUi\Form\EventListener\:
resource: '../../../lib/Form/EventListener'

EzSystems\EzPlatformAdminUi\Form\Type\Extension\Content\ContentEditTypeExtension:
tags:
- { name: form.type_extension, extended_type: EzSystems\RepositoryForms\Form\Type\Content\ContentEditType }

EzSystems\EzPlatformAdminUi\Form\Type\Policy\PolicyChoiceType:
arguments:
$policyMap: "%ezpublish.api.role.policy_map%"

EzSystems\EzPlatformAdminUi\Form\Type\Content\Draft\ContentCreateType:
arguments:
$contentTypeChoiceLoader: '@EzSystems\EzPlatformAdminUi\Form\Type\ChoiceList\Loader\PermissionAwareContentTypeChoiceLoader'
$languageChoiceLoader: '@EzSystems\EzPlatformAdminUi\Form\Type\ChoiceList\Loader\PermissionAwareLanguageChoiceLoader'

EzSystems\EzPlatformAdminUi\Form\Type\ChoiceList\Loader\ContentTypeChoiceLoader: ~

EzSystems\EzPlatformAdminUi\Form\Type\ChoiceList\Loader\LanguageChoiceLoader:
arguments:
$siteAccessLanguages: '$languages$'

EzSystems\EzPlatformAdminUi\Form\Type\ChoiceList\Loader\PermissionAwareContentTypeChoiceLoader:
arguments:
$decorated: '@EzSystems\EzPlatformAdminUi\Form\Type\ChoiceList\Loader\ContentTypeChoiceLoader'
$module: 'content'
$function: 'create'

EzSystems\EzPlatformAdminUi\Form\Type\ChoiceList\Loader\PermissionAwareLanguageChoiceLoader:
arguments:
$decorated: '@EzSystems\EzPlatformAdminUi\Form\Type\ChoiceList\Loader\LanguageChoiceLoader'
$module: 'content'
$function: 'create'
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ services:
autoconfigure: true
public: false

EzSystems\EzPlatformAdminUi\Permission\:
resource: "../../../lib/Permission"
EzSystems\EzPlatformAdminUi\Permission\PermissionChecker: ~

EzSystems\EzPlatformAdminUi\Permission\PermissionCheckerInterface:
alias: EzSystems\EzPlatformAdminUi\Permission\PermissionChecker
89 changes: 89 additions & 0 deletions src/lib/Form/Type/ChoiceList/Loader/ContentTypeChoiceLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?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\Loader;

use eZ\Publish\API\Repository\ContentTypeService;
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;

class ContentTypeChoiceLoader implements ChoiceLoaderInterface
{
/** @var \eZ\Publish\API\Repository\ContentTypeService */
protected $contentTypeService;

/**
* @param \eZ\Publish\API\Repository\ContentTypeService $contentTypeService
*/
public function __construct(ContentTypeService $contentTypeService)
{
$this->contentTypeService = $contentTypeService;
}

/**
* {@inheritdoc}
*/
public function getChoiceList(): array
{
$contentTypes = [];
$contentTypeGroups = $this->contentTypeService->loadContentTypeGroups();
foreach ($contentTypeGroups as $contentTypeGroup) {
$contentTypes[$contentTypeGroup->identifier] = $this->contentTypeService->loadContentTypes($contentTypeGroup);
}

return $contentTypes;
}

/**
* {@inheritdoc}
*/
public function loadChoiceList($value = null)
{
$choices = $this->getChoiceList();

return new ArrayChoiceList($choices, $value);
}

/**
* {@inheritdoc}
*/
public function loadChoicesForValues(array $values, $value = null)
{
// Optimize
$values = array_filter($values);
if (empty($values)) {
return [];
}

// If no callable is set, values are the same as choices
if (null === $value) {
return $values;
}

return $this->loadChoiceList($value)->getChoicesForValues($values);
}

/**
* {@inheritdoc}
*/
public function loadValuesForChoices(array $choices, $value = null)
{
// Optimize
$choices = array_filter($choices);
if (empty($choices)) {
return [];
}

// If no callable is set, choices are the same as values
if (null === $value) {
return $choices;
}

return $this->loadChoiceList($value)->getValuesForChoices($choices);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
*/
declare(strict_types=1);

namespace EzSystems\EzPlatformAdminUi\Form\Type\ChoiceList\Provider;
namespace EzSystems\EzPlatformAdminUi\Form\Type\ChoiceList\Loader;

use eZ\Publish\API\Repository\LanguageService;
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;

class LanguageChoiceListProvider implements ChoiceListProviderInterface
class LanguageChoiceLoader implements ChoiceLoaderInterface
{
/** @var \eZ\Publish\API\Repository\LanguageService */
protected $languageService;

/** @var array */
/** @var string[] */
protected $siteAccessLanguages;

/**
Expand All @@ -29,7 +31,7 @@ public function __construct(LanguageService $languageService, array $siteAccessL
}

/**
* @return array
* {@inheritdoc}
*/
public function getChoiceList(): array
{
Expand All @@ -53,4 +55,52 @@ public function getChoiceList(): array

return array_merge($saLanguages, array_values($languagesByCode));
}

/**
* {@inheritdoc}
*/
public function loadChoiceList($value = null)
{
$choices = $this->getChoiceList();

return new ArrayChoiceList($choices, $value);
}

/**
* {@inheritdoc}
*/
public function loadChoicesForValues(array $values, $value = null)
{
// Optimize
$values = array_filter($values);
if (empty($values)) {
return [];
}

// If no callable is set, values are the same as choices
if (null === $value) {
return $values;
}

return $this->loadChoiceList($value)->getChoicesForValues($values);
}

/**
* {@inheritdoc}
*/
public function loadValuesForChoices(array $choices, $value = null)
{
// Optimize
$choices = array_filter($choices);
if (empty($choices)) {
return [];
}

// If no callable is set, choices are the same as values
if (null === $value) {
return $choices;
}

return $this->loadChoiceList($value)->getValuesForChoices($choices);
}
}
Loading