From e8d489242b8cf48c2183640d6450de040a330f22 Mon Sep 17 00:00:00 2001 From: Sztig Date: Tue, 15 Apr 2025 15:19:14 +0200 Subject: [PATCH 1/3] fixed edit permission check --- .../Content/ContentTreeController.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/bundle/Controller/Content/ContentTreeController.php b/src/bundle/Controller/Content/ContentTreeController.php index 92ad117f4f..b6e8d93011 100644 --- a/src/bundle/Controller/Content/ContentTreeController.php +++ b/src/bundle/Controller/Content/ContentTreeController.php @@ -226,7 +226,7 @@ private function getLocationPermissionRestrictions(Location $location): array 'restrictedLanguageCodes' => $createLimitationsValues[Limitation::LANGUAGE], ], 'edit' => [ - 'hasAccess' => $lookupUpdateLimitationsResult->hasAccess(), + 'hasAccess' => $this->canUserEditContent($location), // skipped content type limitation values as in this case it can be inferred from "hasAccess" above 'restrictedLanguageCodes' => $updateLimitationsValues[Limitation::LANGUAGE], ], @@ -325,6 +325,21 @@ private function isPreviewable( return !empty($siteAccesses); } + + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\BadStateException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException + */ + private function canUserEditContent(Location $location): bool + { + $content = $location->getContent(); + + return $this->permissionResolver->canUser( + 'content', + 'edit', + $content + ); + } } class_alias(ContentTreeController::class, 'EzSystems\EzPlatformAdminUiBundle\Controller\Content\ContentTreeController'); From 9388dceb94edd59433d288f5dfd7ea0caf52d3ca Mon Sep 17 00:00:00 2001 From: Sztig Date: Tue, 15 Apr 2025 15:40:24 +0200 Subject: [PATCH 2/3] implemented suggested changes --- src/bundle/Controller/Content/ContentTreeController.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/bundle/Controller/Content/ContentTreeController.php b/src/bundle/Controller/Content/ContentTreeController.php index b6e8d93011..2cb971d7cc 100644 --- a/src/bundle/Controller/Content/ContentTreeController.php +++ b/src/bundle/Controller/Content/ContentTreeController.php @@ -226,7 +226,7 @@ private function getLocationPermissionRestrictions(Location $location): array 'restrictedLanguageCodes' => $createLimitationsValues[Limitation::LANGUAGE], ], 'edit' => [ - 'hasAccess' => $this->canUserEditContent($location), + 'hasAccess' => $this->canUserEditContent($location->getContent()), // skipped content type limitation values as in this case it can be inferred from "hasAccess" above 'restrictedLanguageCodes' => $updateLimitationsValues[Limitation::LANGUAGE], ], @@ -330,10 +330,8 @@ private function isPreviewable( * @throws \Ibexa\Contracts\Core\Repository\Exceptions\BadStateException * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ - private function canUserEditContent(Location $location): bool + private function canUserEditContent(Content $content): bool { - $content = $location->getContent(); - return $this->permissionResolver->canUser( 'content', 'edit', From 27182d9188751fd7748ace7f1ca2091981f2c5bf Mon Sep 17 00:00:00 2001 From: Sztig Date: Fri, 16 May 2025 16:11:32 +0200 Subject: [PATCH 3/3] small refactor of initial fix --- src/bundle/Controller/Content/ContentTreeController.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/bundle/Controller/Content/ContentTreeController.php b/src/bundle/Controller/Content/ContentTreeController.php index 2cb971d7cc..4d04c34ece 100644 --- a/src/bundle/Controller/Content/ContentTreeController.php +++ b/src/bundle/Controller/Content/ContentTreeController.php @@ -49,7 +49,7 @@ class ContentTreeController extends RestController private ConfigResolverInterface $configResolver; - private SiteaccessResolverInterface $siteaccessResolver; + private SiteaccessResolverInterface $siteaccessResolver; public function __construct( LocationService $locationService, @@ -226,7 +226,7 @@ private function getLocationPermissionRestrictions(Location $location): array 'restrictedLanguageCodes' => $createLimitationsValues[Limitation::LANGUAGE], ], 'edit' => [ - 'hasAccess' => $this->canUserEditContent($location->getContent()), + 'hasAccess' => $this->canUserEditContent($location), // skipped content type limitation values as in this case it can be inferred from "hasAccess" above 'restrictedLanguageCodes' => $updateLimitationsValues[Limitation::LANGUAGE], ], @@ -330,12 +330,13 @@ private function isPreviewable( * @throws \Ibexa\Contracts\Core\Repository\Exceptions\BadStateException * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ - private function canUserEditContent(Content $content): bool + private function canUserEditContent(Location $location): bool { return $this->permissionResolver->canUser( 'content', 'edit', - $content + $location->getContent(), + [$location] ); } }