Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
38 changes: 22 additions & 16 deletions src/lib/Repository/ContentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ContentInfo is in draft state, mainLocationId is yet not set
if (!$contentInfo->isDraft()) {
$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();
Expand Down Expand Up @@ -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 ContentInfo is in draft state, mainLocationId is yet not set
if (!$contentInfo->isDraft()) {
$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();
Expand Down
70 changes: 70 additions & 0 deletions tests/integration/Core/Repository/ContentServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3610,7 +3610,7 @@
$demoDesign
);

$demoDesignLocation = $this->locationService->loadLocation($demoDesign->mainLocationId);

Check failure on line 3613 in tests/integration/Core/Repository/ContentServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (7.4)

Ignored error pattern #^Parameter \#1 \$locationId of method Ibexa\\Contracts\\Core\\Repository\\LocationService\:\:loadLocation\(\) expects int, int\|null given\.$# (argument.type) in path /home/runner/work/core/core/tests/integration/Core/Repository/ContentServiceTest.php is expected to occur 12 times, but occurred 14 times.

Check failure on line 3613 in tests/integration/Core/Repository/ContentServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.0)

Ignored error pattern #^Parameter \#1 \$locationId of method Ibexa\\Contracts\\Core\\Repository\\LocationService\:\:loadLocation\(\) expects int, int\|null given\.$# (argument.type) in path /home/runner/work/core/core/tests/integration/Core/Repository/ContentServiceTest.php is expected to occur 12 times, but occurred 14 times.

Check failure on line 3613 in tests/integration/Core/Repository/ContentServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.1)

Ignored error pattern #^Parameter \#1 \$locationId of method Ibexa\\Contracts\\Core\\Repository\\LocationService\:\:loadLocation\(\) expects int, int\|null given\.$# (argument.type) in path /home/runner/work/core/core/tests/integration/Core/Repository/ContentServiceTest.php is expected to occur 12 times, but occurred 14 times.

// Trashing Content's last Location will change its status to archived,
// in this case relation towards it will not be loaded.
Expand Down Expand Up @@ -6229,6 +6229,76 @@
$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

Check failure on line 6243 in tests/integration/Core/Repository/ContentServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (7.4)

PHPDoc tag `@throws` with type Ibexa\Contracts\Core\Repository\Exceptions\APIInvalidArgumentException|Ibexa\Contracts\Core\Repository\Exceptions\BadStateException|Ibexa\Contracts\Core\Repository\Exceptions\ContentFieldValidationException|Ibexa\Contracts\Core\Repository\Exceptions\ContentValidationException|Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException|Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException is not subtype of Throwable

Check failure on line 6243 in tests/integration/Core/Repository/ContentServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.0)

PHPDoc tag `@throws` with type Ibexa\Contracts\Core\Repository\Exceptions\APIInvalidArgumentException|Ibexa\Contracts\Core\Repository\Exceptions\BadStateException|Ibexa\Contracts\Core\Repository\Exceptions\ContentFieldValidationException|Ibexa\Contracts\Core\Repository\Exceptions\ContentValidationException|Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException|Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException is not subtype of Throwable

Check failure on line 6243 in tests/integration/Core/Repository/ContentServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.1)

PHPDoc tag `@throws` with type Ibexa\Contracts\Core\Repository\Exceptions\APIInvalidArgumentException|Ibexa\Contracts\Core\Repository\Exceptions\BadStateException|Ibexa\Contracts\Core\Repository\Exceptions\ContentFieldValidationException|Ibexa\Contracts\Core\Repository\Exceptions\ContentValidationException|Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException|Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException is not subtype of Throwable
{
$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

Check failure on line 6278 in tests/integration/Core/Repository/ContentServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (7.4)

PHPDoc tag `@throws` with type Ibexa\Contracts\Core\Repository\Exceptions\APIInvalidArgumentException|Ibexa\Contracts\Core\Repository\Exceptions\BadStateException|Ibexa\Contracts\Core\Repository\Exceptions\ContentFieldValidationException|Ibexa\Contracts\Core\Repository\Exceptions\ContentValidationException|Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException|Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException is not subtype of Throwable

Check failure on line 6278 in tests/integration/Core/Repository/ContentServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.0)

PHPDoc tag `@throws` with type Ibexa\Contracts\Core\Repository\Exceptions\APIInvalidArgumentException|Ibexa\Contracts\Core\Repository\Exceptions\BadStateException|Ibexa\Contracts\Core\Repository\Exceptions\ContentFieldValidationException|Ibexa\Contracts\Core\Repository\Exceptions\ContentValidationException|Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException|Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException is not subtype of Throwable

Check failure on line 6278 in tests/integration/Core/Repository/ContentServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.1)

PHPDoc tag `@throws` with type Ibexa\Contracts\Core\Repository\Exceptions\APIInvalidArgumentException|Ibexa\Contracts\Core\Repository\Exceptions\BadStateException|Ibexa\Contracts\Core\Repository\Exceptions\ContentFieldValidationException|Ibexa\Contracts\Core\Repository\Exceptions\ContentValidationException|Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException|Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException is not subtype of Throwable
{
$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
*/
Expand Down Expand Up @@ -6328,10 +6398,10 @@
$this->contentService->revealContent($contents[0]->contentInfo);

$directChildContent = $this->contentService->loadContent($contents[1]->id);
$directChildLocation = $this->locationService->loadLocation($directChildContent->contentInfo->mainLocationId);

Check failure on line 6401 in tests/integration/Core/Repository/ContentServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (7.4)

Parameter #1 $locationId of method Ibexa\Contracts\Core\Repository\LocationService::loadLocation() expects int, int|null given.

Check failure on line 6401 in tests/integration/Core/Repository/ContentServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.0)

Parameter #1 $locationId of method Ibexa\Contracts\Core\Repository\LocationService::loadLocation() expects int, int|null given.

Check failure on line 6401 in tests/integration/Core/Repository/ContentServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.1)

Parameter #1 $locationId of method Ibexa\Contracts\Core\Repository\LocationService::loadLocation() expects int, int|null given.

$childContent = $this->contentService->loadContent($contents[2]->id);
$childLocation = $this->locationService->loadLocation($childContent->contentInfo->mainLocationId);

Check failure on line 6404 in tests/integration/Core/Repository/ContentServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (7.4)

Parameter #1 $locationId of method Ibexa\Contracts\Core\Repository\LocationService::loadLocation() expects int, int|null given.

Check failure on line 6404 in tests/integration/Core/Repository/ContentServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.0)

Parameter #1 $locationId of method Ibexa\Contracts\Core\Repository\LocationService::loadLocation() expects int, int|null given.

Check failure on line 6404 in tests/integration/Core/Repository/ContentServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.1)

Parameter #1 $locationId of method Ibexa\Contracts\Core\Repository\LocationService::loadLocation() expects int, int|null given.
$childSublocations = $this->locationService->loadLocationList([
$contents[3]->contentInfo->mainLocationId,
$contents[4]->contentInfo->mainLocationId,
Expand Down
Loading