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

IBX-6315: Edit embedded items #872

Merged
merged 7 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
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
5 changes: 0 additions & 5 deletions phpstan-baseline-7.4.neon
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,6 @@ parameters:
count: 1
path: src/lib/Pagination/Mapper/AbstractPagerContentToDataMapper.php

-
message: "#^Parameter \\#1 \\$input 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 \\$var of function count expects array\\|Countable, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\User\\\\UserGroup\\> given\\.$#"
count: 1
Expand Down
5 changes: 0 additions & 5 deletions phpstan-baseline-8.0.neon
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,6 @@ parameters:
count: 1
path: src/lib/Pagination/Mapper/AbstractPagerContentToDataMapper.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 \\$value of function count expects array\\|Countable, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\User\\\\UserGroup\\> given\\.$#"
count: 1
Expand Down
10 changes: 5 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8445,6 +8445,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 @@ -8500,11 +8505,6 @@ parameters:
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: "#^Method Ibexa\\\\AdminUi\\\\QueryType\\\\LocationPathQueryType\\:\\:doGetQuery\\(\\) has parameter \\$parameters with no value type specified in iterable type array\\.$#"
count: 1
Expand Down
120 changes: 120 additions & 0 deletions src/bundle/Controller/Permission/LanguageLimitationController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?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 Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
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 ContentService $contentService;

private LimitationResolverInterface $limitationResolver;

private LocationService $locationService;

public function __construct(
ContentService $contentService,
LimitationResolverInterface $limitationResolver,
LocationService $locationService
) {
$this->contentService = $contentService;
$this->limitationResolver = $limitationResolver;
$this->locationService = $locationService;
}

public function loadLanguageLimitationsForContentCreateAction(Location $location): Response
{
$contentInfo = $location->getContentInfo();
$contentType = $contentInfo->getContentType();
$contentCreateStruct = $this->contentService->newContentCreateStruct(
$contentType,
$contentInfo->getMainLanguageCode()
);
$contentCreateStruct->sectionId = $contentInfo->getSection();
$locationCreateStruct = $this->locationService->newLocationCreateStruct($location->id);

return new JsonResponse(
$this->limitationResolver->getLanguageLimitations(
'create',
$contentCreateStruct,
[],
[
$locationCreateStruct,
]
)
);
}

public function loadLanguageLimitationsForContentEditAction(
ContentInfo $contentInfo,
?VersionInfo $versionInfo = null,
?Location $location = null
): Response {
return new JsonResponse(
$this->getLanguageLimitationsByFunction(
'edit',
$contentInfo,
$versionInfo,
$location
)
);
}

public function loadLanguageLimitationsForContentReadAction(
ContentInfo $contentInfo,
?VersionInfo $versionInfo = null,
?Location $location = null
): Response {
return new JsonResponse(
$this->getLanguageLimitationsByFunction(
'read',
$contentInfo,
$versionInfo,
$location
)
);
}

/**
* @return array<array{
* languageCode: string,
* name: string,
* hasAccess: bool,
* }>
*/
private function getLanguageLimitationsByFunction(
string $function,
ContentInfo $contentInfo,
?VersionInfo $versionInfo = null,
?Location $location = null
): array {
$versionInfo ??= $this->contentService->loadVersionInfo($contentInfo);
$location ??= $contentInfo->getMainLocation();
$targets = [];

if (null !== $location) {
$targets[] = $location;
}

return $this->limitationResolver->getLanguageLimitations(
$function,
$contentInfo,
$versionInfo->getLanguages(),
$targets
);
}
}
30 changes: 30 additions & 0 deletions src/bundle/Resources/config/routing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -958,3 +958,33 @@ ibexa.asset.upload_image:
defaults:
_controller: 'Ibexa\Bundle\AdminUi\Controller\AssetController::uploadImageAction'
methods: [POST]

#
# Permissions
#
ibexa.permission.limitation.language.content_create:
path: /permission/limitation/language/content-create/{locationId}
options:
expose: true
controller: 'Ibexa\Bundle\AdminUi\Controller\Permission\LanguageLimitationController::loadLanguageLimitationsForContentCreateAction'
methods: [GET]
requirements:
locationId: \d+

ibexa.permission.limitation.language.content_edit:
path: /permission/limitation/language/content-edit/{contentInfoId}
options:
expose: true
controller: 'Ibexa\Bundle\AdminUi\Controller\Permission\LanguageLimitationController::loadLanguageLimitationsForContentEditAction'
methods: [GET]
requirements:
contentInfoId: \d+

ibexa.permission.limitation.language.content_read:
path: /permission/limitation/language/content-read/{contentInfoId}
options:
expose: true
controller: 'Ibexa\Bundle\AdminUi\Controller\Permission\LanguageLimitationController::loadLanguageLimitationsForContentReadAction'
methods: [GET]
requirements:
contentInfoId: \d+
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.layout.content.after:
parent: Ibexa\AdminUi\Component\TwigComponent
arguments:
$template: '@@ibexadesign/ui/layout_content_after.html.twig'
tags:
- { name: ibexa.admin_ui.component, group: 'layout-content-after' }
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
1 change: 1 addition & 0 deletions src/bundle/Resources/encore/ibexa.js.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const layout = [
path.resolve(__dirname, '../public/js/scripts/admin.back.to.top.js'),
path.resolve(__dirname, '../public/js/scripts/admin.middle.ellipsis.js'),
path.resolve(__dirname, '../public/js/scripts/admin.form.error.js'),
path.resolve(__dirname, '../public/js/scripts/embedded.item.actions'),
path.resolve(__dirname, '../public/js/scripts/widgets/flatpickr.js'),
];
const fieldTypes = [];
Expand Down
8 changes: 8 additions & 0 deletions src/bundle/Resources/public/js/scripts/admin.location.view.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
const sortContainer = doc.querySelector('[data-sort-field][data-sort-order]');
const sortField = sortContainer.getAttribute('data-sort-field');
const sortOrder = sortContainer.getAttribute('data-sort-order');
const emdedItemsUpdateChannel = new BroadcastChannel('ibexa-emded-item-live-update');
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const publishedContentId = urlParams.get('publishedContentId');
const handleEditItem = (content, location) => {
const contentId = content._id;
const locationId = location._id;
Expand Down Expand Up @@ -190,6 +194,10 @@
}),
);
});

if (publishedContentId) {
emdedItemsUpdateChannel.postMessage({ contentId: publishedContentId });
}
})(
window,
window.document,
Expand Down
Loading
Loading