Skip to content

Commit

Permalink
Added PermissionLimitationResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk authored and lucasOsti committed Sep 7, 2023
1 parent a9c9a34 commit 1329c27
Show file tree
Hide file tree
Showing 18 changed files with 806 additions and 136 deletions.
15 changes: 5 additions & 10 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8630,6 +8630,11 @@ parameters:
count: 1
path: src/lib/Pagination/Pagerfanta/URLWildcardAdapter.php

-
message: "#^Access to protected property Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\User\\\\LookupLimitationResult\\:\\:\\$hasAccess\\.$#"
count: 1
path: src/lib/Permission/LimitationResolver.php

-
message: "#^Access to protected property Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\User\\\\LookupLimitationResult\\:\\:\\$lookupPolicyLimitations\\.$#"
count: 2
Expand Down Expand Up @@ -8685,16 +8690,6 @@ parameters:
count: 1
path: src/lib/Permission/PermissionChecker.php

-
message: "#^Parameter \\#1 \\$array of function array_filter expects array, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Language\\> given\\.$#"
count: 1
path: src/lib/Permission/PermissionChecker.php

-
message: "#^Parameter \\#1 \\$contentTypeIds of method Ibexa\\\\Contracts\\\\Core\\\\Limitation\\\\Target\\\\Builder\\\\VersionBuilder\\:\\:createFromAnyContentTypeOf\\(\\) expects array\\<int\\>, array\\<string\\> given\\.$#"
count: 2
path: src/lib/Permission/PermissionChecker.php

-
message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\User\\\\UserGroup\\> given\\.$#"
count: 1
Expand Down
40 changes: 40 additions & 0 deletions src/bundle/Controller/Permission/LanguageLimitationController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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\Values\Content\Content;
use Ibexa\Contracts\Core\Repository\Values\Content\Location;
use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;

final class LanguageLimitationController extends Controller
{
private LimitationResolverInterface $limitationResolver;

public function __construct(LimitationResolverInterface $limitationResolver)
{
$this->limitationResolver = $limitationResolver;
}

public function loadLanguageLimitationsForContentAction(
Content $content,
?VersionInfo $versionInfo = null,
?Location $location = null
): Response {
return new JsonResponse(
$this->limitationResolver->getLanguageLimitations(
$versionInfo ?? $content->getVersionInfo(),
$location ?? $content->getVersionInfo()->getContentInfo()->getMainLocation()
)
);
}
}
11 changes: 11 additions & 0 deletions src/bundle/Resources/config/routing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -958,3 +958,14 @@ ibexa.asset.upload_image:
defaults:
_controller: 'Ibexa\Bundle\AdminUi\Controller\AssetController::uploadImageAction'
methods: [POST]

#
# Permissions
#
ibexa.permission.limitation.language:
path: permission/limitation/language/{contentId}
options:
expose: true
defaults:
_controller: 'Ibexa\Bundle\AdminUi\Controller\Permission\LanguageLimitationController::loadLanguageLimitationsForContentAction'
methods: [GET]
7 changes: 7 additions & 0 deletions src/bundle/Resources/config/services/components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,10 @@ services:
public: false

Ibexa\Contracts\AdminUi\Component\Renderer\RendererInterface: '@Ibexa\AdminUi\Component\Renderer\DefaultRenderer'

ibexa.adminui.html.body:
parent: Ibexa\AdminUi\Component\TwigComponent
arguments:
$template: '@@ibexadesign/ui/html_body.html.twig'
tags:
- { name: ibexa.admin_ui.component, group: 'html-body' }
6 changes: 6 additions & 0 deletions src/bundle/Resources/config/services/controllers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,9 @@ services:
autowire: true

Ibexa\Bundle\AdminUi\Controller\User\InvitationController: ~

Ibexa\Bundle\AdminUi\Controller\Permission\LanguageLimitationController:
parent: Ibexa\Contracts\AdminUi\Controller\Controller
autowire: true
tags:
- controller.service_arguments
5 changes: 5 additions & 0 deletions src/bundle/Resources/config/services/permissions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ services:
alias: Ibexa\AdminUi\Permission\PermissionChecker

Ibexa\AdminUi\Permission\LookupLimitationsTransformer: ~

Ibexa\AdminUi\Permission\LimitationResolver: ~

Ibexa\AdminUi\Permission\LimitationResolverInterface:
alias: Ibexa\AdminUi\Permission\LimitationResolver
2 changes: 2 additions & 0 deletions src/bundle/Resources/config/services/ui_config/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ services:

Ibexa\Bundle\AdminUi\Templating\Twig\ContentTypeIconExtension: ~

Ibexa\Bundle\AdminUi\Templating\Twig\EmbeddedItemEditFormExtension: ~

Ibexa\AdminUi\UI\Config\Provider\UserContentTypes:
tags:
- { name: ibexa.admin_ui.config.provider, key: 'userContentTypes' }
Expand Down
22 changes: 22 additions & 0 deletions src/bundle/Resources/views/themes/admin/ui/html_body.html.twig
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>
2 changes: 2 additions & 0 deletions src/bundle/Resources/views/themes/admin/ui/layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@
{% endblock %}
{% endif %}

{{ ibexa_render_component_group('html-body') }}

{{ encore_entry_script_tags('ibexa-admin-ui-layout-js', null, 'ibexa') }}
{{ encore_entry_script_tags('ibexa-admin-ui-udw-tabs-js', null, 'ibexa') }}
{{ encore_entry_script_tags('ibexa-admin-ui-udw-extras-js', null, 'ibexa') }}
Expand Down
52 changes: 52 additions & 0 deletions src/bundle/Templating/Twig/EmbeddedItemEditFormExtension.php
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();
}
}
14 changes: 10 additions & 4 deletions src/contracts/Permission/PermissionCheckerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,26 @@ public function getRestrictions(array $hasAccess, string $class): array;
public function canCreateInLocation(Location $location, $hasAccess): bool;

/**
* @internal
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\BadStateException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
*
* @internal
*
* @deprecated 4.6.0 The "\Ibexa\Contracts\AdminUi\Permission\PermissionCheckerInterface::getContentCreateLimitations()" method is deprecated, will be removed in 5.0.
* Use { @see \Ibexa\AdminUi\Permission\LimitationResolverInterface::getContentCreateLimitations } instead.
*/
public function getContentCreateLimitations(Location $parentLocation): LookupLimitationResult;

/**
* @internal
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\BadStateException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
*
* @internal
*
* @deprecated 4.6.0 The "\Ibexa\Contracts\AdminUi\Permission\PermissionCheckerInterface::getContentUpdateLimitations()" method is deprecated, will be removed in 5.0.
* Use { @see \Ibexa\AdminUi\Permission\LimitationResolverInterface::getContentUpdateLimitations } instead.
*/
public function getContentUpdateLimitations(Location $parentLocation): LookupLimitationResult;
}
Expand Down
Loading

0 comments on commit 1329c27

Please sign in to comment.