Skip to content

Commit

Permalink
Merge branch 'master' into rm-unused-raml
Browse files Browse the repository at this point in the history
# Conflicts:
#	docs/api/rest_api/rest_api_reference/input/ez_original.raml
  • Loading branch information
adriendupuis committed Apr 3, 2024
2 parents b22d29b + b1acd18 commit b190956
Show file tree
Hide file tree
Showing 257 changed files with 2,252 additions and 1,119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(ContentService $contentService, LocationService $loc
protected function configure()
{
$this
->setDescription('Add a Location to Content item and hides it.')
->setDescription('Add a Location to content item and hides it.')
->setDefinition([
new InputArgument('contentId', InputArgument::REQUIRED, 'Content ID'),
new InputArgument('parentLocationId', InputArgument::REQUIRED, 'Parent Location ID'),
Expand All @@ -56,7 +56,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$contentInfo = $this->contentService->loadContentInfo($contentId);
$newLocation = $this->locationService->createLocation($contentInfo, $locationCreateStruct);

$output->writeln('Added hidden location ' . $newLocation->id . ' to Content item: ' . $contentInfo->name);
$output->writeln('Added hidden location ' . $newLocation->id . ' to content item: ' . $contentInfo->name);

return self::SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function configure()
new InputArgument('contentType', InputArgument::REQUIRED, 'Identifier of a content type with a Name and Description Field'),
new InputArgument('name', InputArgument::REQUIRED, 'Content for the Name field'),
])
->addOption('publish', 'p', InputOption::VALUE_NONE, 'Do you want to publish the Content item?');
->addOption('publish', 'p', InputOption::VALUE_NONE, 'Do you want to publish the content item?');
}

protected function execute(InputInterface $input, OutputInterface $output)
Expand All @@ -67,7 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

if ($input->getOption('publish')) {
$content = $this->contentService->publishVersion($draft->versionInfo);
$output->writeln('Published Content item ' . $content->getName());
$output->writeln('Published content item ' . $content->getName());
}

return self::SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function configure()
new InputArgument('name', InputArgument::REQUIRED, 'Content for the Name field'),
new InputArgument('file', InputArgument::REQUIRED, 'Content for the Image field'),
])
->addOption('publish', 'p', InputOption::VALUE_NONE, 'Do you want to publish the Content item?');
->addOption('publish', 'p', InputOption::VALUE_NONE, 'Do you want to publish the content item?');
}

protected function execute(InputInterface $input, OutputInterface $output)
Expand Down Expand Up @@ -76,7 +76,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

if ($publish == true) {
$content = $this->contentService->publishVersion($draft->versionInfo);
$output->writeln('Published Content item ' . $content->getName());
$output->writeln('Published content item ' . $content->getName());
}

return self::SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(ContentService $contentService, UserService $userSer
protected function configure()
{
$this
->setDescription('Creates OS group with provided States and assigned the Lock OS to provided Content item')
->setDescription('Creates OS group with provided States and assigned the Lock OS to provided content item')
->setDefinition([
new InputArgument('objectStateGroupIdentifier', InputArgument::REQUIRED, 'Identifier of new OG group to create'),
new InputArgument('objectStateIdentifier', InputArgument::REQUIRED, 'Identifier(s) of a new Object State'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(SectionService $sectionService, UserService $userSer
protected function configure()
{
$this
->setDescription('Creates new section and adds selected Content item to it.')
->setDescription('Creates new section and adds selected content item to it.')
->setDefinition([
new InputArgument('sectionName', InputArgument::REQUIRED, 'Name of the new Section'),
new InputArgument('sectionIdentifier', InputArgument::REQUIRED, 'Identifier of the new Section'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(ContentService $contentService, UserService $userSer
protected function configure()
{
$this
->setDescription('Set a Location as Content item\'s main')
->setDescription('Set a Location as content item\'s main')
->setDefinition([
new InputArgument('contentId', InputArgument::REQUIRED, 'The Content ID'),
new InputArgument('locationId', InputArgument::REQUIRED, 'One of the Locations of the Content'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function configure()
new InputArgument('locationId', InputArgument::REQUIRED, 'Location to trash'),
new InputArgument('newParentId', InputArgument::OPTIONAL, 'New Location to restore under'),
])
->addOption('restore', 'r', InputOption::VALUE_NONE, 'Do you want to restore the Content item?');
->addOption('restore', 'r', InputOption::VALUE_NONE, 'Do you want to restore the content item?');
}

protected function execute(InputInterface $input, OutputInterface $output)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public function __construct(ContentService $contentService, UserService $userSer
protected function configure()
{
$this
->setDescription('Update provided Content item with a new name')
->setDescription('Update provided content item with a new name')
->setDefinition([
new InputArgument('contentId', InputArgument::REQUIRED, 'Content ID'),
new InputArgument('newName', InputArgument::REQUIRED, 'New name for the updated Content item'),
new InputArgument('newName', InputArgument::REQUIRED, 'New name for the updated content item'),
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(ContentService $contentService, ContentTypeService $
protected function configure()
{
$this
->setDescription('Output Field values on provided Content item.')
->setDescription('Output Field values on provided content item.')
->setDefinition([
new InputArgument('contentId', InputArgument::REQUIRED, 'Location ID'),
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(ContentService $contentService, LocationService $loc
protected function configure()
{
$this
->setDescription('Output various metadata about a Content item.')
->setDescription('Output various metadata about a content item.')
->setDefinition([
new InputArgument('contentId', InputArgument::REQUIRED, 'An existing content ID'),
]);
Expand Down
2 changes: 1 addition & 1 deletion code_samples/api/rest_api/create_image.json.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,6 @@
exit(9);
}

echo "Success: Image Content item created with ID $contentId and published.\n";
echo "Success: Image content item created with ID $contentId and published.\n";

exit(0);
2 changes: 1 addition & 1 deletion code_samples/api/rest_api/create_image.xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,6 @@
exit(9);
}

echo "Success: Image Content item created with ID $contentId and published.\n";
echo "Success: Image content item created with ID $contentId and published.\n";

exit(0);
12 changes: 12 additions & 0 deletions code_samples/back_office/limitation/config/append_to_services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
services:
App\Security\Limitation\CustomLimitationType:
tags:
- { name: 'ibexa.permissions.limitation_type', alias: 'CustomLimitation' }

App\Security\Limitation\Mapper\CustomLimitationFormMapper:
tags:
- { name: 'ibexa.admin_ui.limitation.mapper.form', limitationType: 'CustomLimitation' }

App\Security\Limitation\Mapper\CustomLimitationValueMapper:
tags:
- { name: 'ibexa.admin_ui.limitation.mapper.value', limitationType: 'CustomLimitation' }
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ibexa:
system:
default:
limitation_value_templates:
- { template: '@ibexadesign/limitation/custom_limitation_value.html.twig', priority: 0 }
24 changes: 24 additions & 0 deletions code_samples/back_office/limitation/src/Kernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace App;

use App\Security\MyPolicyProvider;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;

class Kernel extends BaseKernel
{
use MicroKernelTrait;

protected function build(ContainerBuilder $container): void
{
// Retrieve "ibexa" container extension
/** @var \Ibexa\Bundle\Core\DependencyInjection\IbexaCoreExtension $IbexaExtension */
$ibexaExtension = $container->getExtension('ibexa');
// Add the policy provider
$ibexaExtension->addPolicyProvider(new MyPolicyProvider());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# src/Resources/config/policies.yaml
custom_module:
custom_function_1: ~
custom_function_2: [CustomLimitation]
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

declare(strict_types=1);

namespace App\Security\Limitation;

use Ibexa\Contracts\Core\Limitation\Type;
use Ibexa\Contracts\Core\Repository\Exceptions\NotImplementedException;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\CriterionInterface;
use Ibexa\Contracts\Core\Repository\Values\User\Limitation;
use Ibexa\Contracts\Core\Repository\Values\User\UserReference;
use Ibexa\Contracts\Core\Repository\Values\ValueObject;
use Ibexa\Core\Base\Exceptions\InvalidArgumentType;
use Ibexa\Core\FieldType\ValidationError;

class CustomLimitationType implements Type
{
public function acceptValue(Limitation $limitationValue): void
{
if (!$limitationValue instanceof CustomLimitationValue) {
throw new InvalidArgumentType(
'$limitationValue',
FieldGroupLimitation::class,
$limitationValue
);
}
}

/** @return \Ibexa\Core\FieldType\ValidationError[] */
public function validate(Limitation $limitationValue): array
{
$validationErrors = [];
if (!array_key_exists('value', $limitationValue->limitationValues)) {
$validationErrors[] = new ValidationError("limitationValues['value'] is missing.");
} elseif (!is_bool($limitationValue->limitationValues['value'])) {
$validationErrors[] = new ValidationError("limitationValues['value'] is not a boolean.");
}

return $validationErrors;
}

public function buildValue(array $limitationValues): CustomLimitationValue
{
$value = false;
if (array_key_exists('value', $limitationValues)) {
$value = $limitationValues['value'];
} elseif (count($limitationValues)) {
$value = (bool)$limitationValues[0];
}

return new CustomLimitationValue(['limitationValues' => ['value' => $value]]);
}

/**
* @param \Ibexa\Contracts\Core\Repository\Values\ValueObject[]|null $targets
*
* @return bool|null
*/
public function evaluate(Limitation $value, UserReference $currentUser, ValueObject $object, array $targets = null): ?bool
{
if (!$value instanceof CustomLimitationValue) {
throw new InvalidArgumentException('$value', 'Must be of type: CustomLimitationValue');
}

if ($value->limitationValues['value']) {
return Type::ACCESS_GRANTED;
}

// If the limitation value is not set to `true`, then $currentUser, $object and/or $targets could be challenged to determine if the access is granted or not; Here or elsewhere. When passing the baton, a limitation can return Type::ACCESS_ABSTAIN
return Type::ACCESS_DENIED;
}

public function getCriterion(Limitation $value, UserReference $currentUser): CriterionInterface
{
throw new NotImplementedException(__METHOD__);
}

public function valueSchema(): void
{
throw new NotImplementedException(__METHOD__);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace App\Security\Limitation;

use Ibexa\Contracts\Core\Repository\Values\User\Limitation;

class CustomLimitationValue extends Limitation
{
public function getIdentifier(): string
{
return 'CustomLimitation';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace App\Security\Limitation\Mapper;

use Ibexa\AdminUi\Limitation\LimitationFormMapperInterface;
use Ibexa\AdminUi\Translation\Extractor\LimitationTranslationExtractor;
use Ibexa\Contracts\Core\Repository\Values\User\Limitation;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\FormInterface;

class CustomLimitationFormMapper implements LimitationFormMapperInterface
{
public function mapLimitationForm(FormInterface $form, Limitation $data): void
{
$form->add('limitationValues', CheckboxType::class, [
'label' => LimitationTranslationExtractor::identifierToLabel($data->getIdentifier()),
'required' => false,
'data' => $data->limitationValues['value'],
'property_path' => 'limitationValues[value]',
]);
}

public function getFormTemplate(): string
{
return '@ibexadesign/limitation/custom_limitation_form.html.twig';
}

public function filterLimitationValues(Limitation $limitation): void
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace App\Security\Limitation\Mapper;

use Ibexa\AdminUi\Limitation\LimitationValueMapperInterface;
use Ibexa\Contracts\Core\Repository\Values\User\Limitation;

class CustomLimitationValueMapper implements LimitationValueMapperInterface
{
public function mapLimitationValue(Limitation $limitation): bool
{
return $limitation->limitationValues['value'];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace App\Security;

use Ibexa\Bundle\Core\DependencyInjection\Security\PolicyProvider\YamlPolicyProvider;

class MyPolicyProvider extends YamlPolicyProvider
{
/** @returns string[] */
protected function getFiles(): array
{
return [
__DIR__ . '/../Resources/config/policies.yaml',
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{# templates/themes/admin/limitation/custom_limitation_form.html.twig #}
{{ form_label(form.limitationValues) }}
{{ form_widget(form.limitationValues) }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{# templates/themes/standard/limitation/custom_limitation_value.html.twig #}
{% block ez_limitation_customlimitation_value %}
<span style="color: {{ values ? 'green' : 'red' }};">{{ values ? 'Yes' : 'No' }}</span>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
role.policy.custom_module: 'Custom module'
role.policy.custom_module.all_functions: 'Custom module / All functions'
role.policy.custom_module.custom_function_1: 'Custom module / Function #1'
role.policy.custom_module.custom_function_2: 'Custom module / Function #2'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
policy.limitation.identifier.customlimitation: 'Custom limitation'
Loading

0 comments on commit b190956

Please sign in to comment.