Skip to content

Commit

Permalink
IBX-6315: Edit embedded items (#872)
Browse files Browse the repository at this point in the history
Co-authored-by: Tomasz Kryszan <tomasz.kryszan@ez.no>
  • Loading branch information
lucasOsti and ciastektk authored Oct 19, 2023
1 parent 69e8a2c commit b942418
Show file tree
Hide file tree
Showing 36 changed files with 1,490 additions and 174 deletions.
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

0 comments on commit b942418

Please sign in to comment.