From ed818bb1e3247a0cf70dd42f97a378d7994327a6 Mon Sep 17 00:00:00 2001 From: Vidar Langseid Date: Fri, 24 Oct 2025 13:40:57 +0200 Subject: [PATCH 1/3] IBX-10854: Not possible to hide content draft --- src/lib/Repository/ContentService.php | 38 ++++++++++++++++----------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/lib/Repository/ContentService.php b/src/lib/Repository/ContentService.php index 2cee84e93a..57509af237 100644 --- a/src/lib/Repository/ContentService.php +++ b/src/lib/Repository/ContentService.php @@ -2528,14 +2528,17 @@ public function deleteTranslationFromDraft(APIVersionInfo $versionInfo, string $ */ public function hideContent(ContentInfo $contentInfo): void { - $locationTarget = (new DestinationLocationTarget($contentInfo->mainLocationId, $contentInfo)); - if (!$this->permissionResolver->canUser( - 'content', - 'hide', - $contentInfo, - [$locationTarget] - )) { - throw new UnauthorizedException('content', 'hide', ['contentId' => $contentInfo->id]); + // If content is in draft state, mainLocationId is yet not set + if ($contentInfo->mainLocationId !== null) { + $locationTarget = (new DestinationLocationTarget($contentInfo->mainLocationId, $contentInfo)); + if (!$this->permissionResolver->canUser( + 'content', + 'hide', + $contentInfo, + [$locationTarget] + )) { + throw new UnauthorizedException('content', 'hide', ['contentId' => $contentInfo->id]); + } } $this->repository->beginTransaction(); @@ -2568,14 +2571,17 @@ public function hideContent(ContentInfo $contentInfo): void */ public function revealContent(ContentInfo $contentInfo): void { - $locationTarget = (new DestinationLocationTarget($contentInfo->mainLocationId, $contentInfo)); - if (!$this->permissionResolver->canUser( - 'content', - 'hide', - $contentInfo, - [$locationTarget] - )) { - throw new UnauthorizedException('content', 'hide', ['contentId' => $contentInfo->id]); + // If content is in draft state, mainLocationId is yet not set + if ($contentInfo->mainLocationId !== null) { + $locationTarget = (new DestinationLocationTarget($contentInfo->mainLocationId, $contentInfo)); + if (!$this->permissionResolver->canUser( + 'content', + 'hide', + $contentInfo, + [$locationTarget] + )) { + throw new UnauthorizedException('content', 'hide', ['contentId' => $contentInfo->id]); + } } $this->repository->beginTransaction(); From 3dfb2c73279e7e7cdcf1a6913cd27211381140a0 Mon Sep 17 00:00:00 2001 From: Vidar Langseid Date: Fri, 24 Oct 2025 14:13:16 +0200 Subject: [PATCH 2/3] Added tests for IBX-10854: Not possible to hide content draft --- .../Core/Repository/ContentServiceTest.php | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/tests/integration/Core/Repository/ContentServiceTest.php b/tests/integration/Core/Repository/ContentServiceTest.php index b609acec3c..a6e7f73a3d 100644 --- a/tests/integration/Core/Repository/ContentServiceTest.php +++ b/tests/integration/Core/Repository/ContentServiceTest.php @@ -6229,6 +6229,76 @@ function (Location $parentLocation) { $this->assertEquals($hiddenLocations, $hiddenLocationsAfterReveal); } + /** + * @covers \Ibexa\Contracts\Core\Repository\ContentService::hideContent + + * + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\APIInvalidArgumentException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\BadStateException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\ContentFieldValidationException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\ContentValidationException + */ + public function testHideContentDraft(): void + { + $publishedContent = $this->createContentForHideRevealDraftTests(false); + $location = $this->locationService->loadLocation($publishedContent->contentInfo->mainLocationId); + + $content = $this->contentService->loadContent($publishedContent->contentInfo->id); + self::assertTrue($content->contentInfo->isHidden, 'Content is not hidden'); + self::assertTrue($location->isHidden(), 'Location is visible'); + } + + /** + * @covers \Ibexa\Contracts\Core\Repository\ContentService::revealContent + + * + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException + */ + public function testHideAndRevealContentDraft(): void + { + $publishedContent = $this->createContentForHideRevealDraftTests(true); + $location = $this->locationService->loadLocation($publishedContent->contentInfo->mainLocationId); + + $content = $this->contentService->loadContent($publishedContent->contentInfo->id); + self::assertFalse($content->contentInfo->isHidden, 'Content is hidden'); + self::assertFalse($location->isHidden(), 'Location is hidden'); + } + + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\APIInvalidArgumentException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\BadStateException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\ContentFieldValidationException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\ContentValidationException + */ + private function createContentForHideRevealDraftTests(bool $hideAndRevel): Content + { + $contentTypeService = $this->getRepository()->getContentTypeService(); + + $locationCreateStructs = $this->locationService->newLocationCreateStruct(2); + + $contentType = $contentTypeService->loadContentTypeByIdentifier('folder'); + + $contentCreate = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); + $contentCreate->setField('name', 'Folder to hide'); + + $draft = $this->contentService->createContent( + $contentCreate, + [$locationCreateStructs] + ); + + $this->contentService->hideContent($draft->contentInfo); + if ($hideAndRevel) { + $this->contentService->revealContent($draft->contentInfo); + } + + return $this->contentService->publishVersion($draft->versionInfo); + } + /** * @depends testRevealContent */ From acbb2d8103543d11d04c9ddfbc5b07205bb0ad00 Mon Sep 17 00:00:00 2001 From: Vidar Langseid Date: Mon, 27 Oct 2025 12:53:21 +0100 Subject: [PATCH 3/3] fixup! IBX-10854: Not possible to hide content draft --- src/lib/Repository/ContentService.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/Repository/ContentService.php b/src/lib/Repository/ContentService.php index 57509af237..1f10734205 100644 --- a/src/lib/Repository/ContentService.php +++ b/src/lib/Repository/ContentService.php @@ -2528,8 +2528,8 @@ public function deleteTranslationFromDraft(APIVersionInfo $versionInfo, string $ */ public function hideContent(ContentInfo $contentInfo): void { - // If content is in draft state, mainLocationId is yet not set - if ($contentInfo->mainLocationId !== null) { + // If ContentInfo is in draft state, mainLocationId is yet not set + if (!$contentInfo->isDraft()) { $locationTarget = (new DestinationLocationTarget($contentInfo->mainLocationId, $contentInfo)); if (!$this->permissionResolver->canUser( 'content', @@ -2571,8 +2571,8 @@ public function hideContent(ContentInfo $contentInfo): void */ public function revealContent(ContentInfo $contentInfo): void { - // If content is in draft state, mainLocationId is yet not set - if ($contentInfo->mainLocationId !== null) { + // If ContentInfo is in draft state, mainLocationId is yet not set + if (!$contentInfo->isDraft()) { $locationTarget = (new DestinationLocationTarget($contentInfo->mainLocationId, $contentInfo)); if (!$this->permissionResolver->canUser( 'content',