Skip to content

Commit

Permalink
EZP-31837: Creating an additional Content Location does not repect Co…
Browse files Browse the repository at this point in the history
…ntent visibility (#3066)
  • Loading branch information
pspanja authored Oct 5, 2020
1 parent 1d1f320 commit 42fee31
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 11 deletions.
41 changes: 41 additions & 0 deletions eZ/Publish/API/Repository/Tests/LocationServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,47 @@ public function testCreateLocation()
];
}

/**
* Test for the createLocation() method.
*
* @covers \eZ\Publish\API\Repository\LocationService::createLocation
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCreateLocation
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testHideContent
*/
public function testCreateLocationChecksContentVisibility(): void
{
$repository = $this->getRepository();

$contentId = $this->generateId('object', 41);
$parentLocationId = $this->generateId('location', 5);
/* BEGIN: Use Case */
// $contentId is the ID of an existing content object
// $parentLocationId is the ID of an existing location
$contentService = $repository->getContentService();
$locationService = $repository->getLocationService();

// ContentInfo for "How to use eZ Publish"
$contentInfo = $contentService->loadContentInfo($contentId);
$contentService->hideContent($contentInfo);

$locationCreate = $locationService->newLocationCreateStruct($parentLocationId);
$locationCreate->priority = 23;
$locationCreate->hidden = false;
$locationCreate->remoteId = 'sindelfingen';
$locationCreate->sortField = Location::SORT_FIELD_NODE_ID;
$locationCreate->sortOrder = Location::SORT_ORDER_DESC;

$location = $locationService->createLocation(
$contentInfo,
$locationCreate
);
/* END: Use Case */

self::assertInstanceOf(Location::class, $location);

self::assertTrue($location->invisible);
}

/**
* Test for the createLocation() method with utilizing default ContentType sorting options.
*
Expand Down
6 changes: 3 additions & 3 deletions eZ/Publish/API/Repository/Values/Content/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @property-read mixed $id the id of the location
* @property-read int $priority Position of the Location among its siblings when sorted using priority
* @property-read bool $hidden Indicates that the Location entity is hidden (explicitly or hidden by content).
* @property-read bool $invisible Indicates that the Location is implicitly marked as hidden by a parent location
* @property-read bool $invisible Indicates that the Location is not visible, being either marked as hidden itself, or implicitly hidden by its Content or an ancestor Location
* @property-read bool $explicitlyHidden Indicates that the Location entity has been explicitly marked as hidden.
* @property-read string $remoteId a global unique id of the content object
* @property-read mixed $parentLocationId the id of the parent location
Expand Down Expand Up @@ -119,8 +119,8 @@ abstract class Location extends ValueObject
protected $hidden;

/**
* Indicates that the Location is implicitly marked as hidden by a parent
* location.
* Indicates that the Location is not visible, being either marked as hidden itself,
* or implicitly hidden by its Content or an ancestor Location.
*
* @var bool
*/
Expand Down
3 changes: 2 additions & 1 deletion eZ/Publish/Core/Repository/ContentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,8 @@ protected function buildSPILocationCreateStructs(array $locationCreateStructs)
$mainLocation,
// For Content draft contentId and contentVersionNo are set in ContentHandler upon draft creation
null,
null
null,
false
);

// First Location in the list will be created as main Location
Expand Down
8 changes: 5 additions & 3 deletions eZ/Publish/Core/Repository/Helper/DomainMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ public function buildLocationDomainObjectsOnSearchResult(SearchResult $result, a
* @param mixed $mainLocation
* @param mixed $contentId
* @param mixed $contentVersionNo
* @param bool $isContentHidden
*
* @return \eZ\Publish\SPI\Persistence\Content\Location\CreateStruct
*/
Expand All @@ -691,7 +692,8 @@ public function buildSPILocationCreateStruct(
APILocation $parentLocation,
$mainLocation,
$contentId,
$contentVersionNo
$contentVersionNo,
bool $isContentHidden
) {
if (!$this->isValidLocationPriority($locationCreateStruct->priority)) {
throw new InvalidArgumentValue('priority', $locationCreateStruct->priority, 'LocationCreateStruct');
Expand Down Expand Up @@ -733,10 +735,10 @@ public function buildSPILocationCreateStruct(
'priority' => $locationCreateStruct->priority,
'hidden' => $locationCreateStruct->hidden,
// If we declare the new Location as hidden, it is automatically invisible
// Otherwise it picks up visibility from parent Location
// Otherwise it picks up visibility from parent Location and Content
// Note: There is no need to check for hidden status of parent, as hidden Location
// is always invisible as well
'invisible' => ($locationCreateStruct->hidden === true || $parentLocation->invisible),
'invisible' => ($locationCreateStruct->hidden === true || $parentLocation->invisible || $isContentHidden),
'remoteId' => $remoteId,
'contentId' => $contentId,
'contentVersion' => $contentVersionNo,
Expand Down
3 changes: 2 additions & 1 deletion eZ/Publish/Core/Repository/LocationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,8 @@ public function createLocation(ContentInfo $contentInfo, LocationCreateStruct $l
$parentLocation,
$contentInfo->mainLocationId ?? true,
$contentInfo->id,
$contentInfo->currentVersionNo
$contentInfo->currentVersionNo,
$contentInfo->isHidden
);

$this->repository->beginTransaction();
Expand Down
9 changes: 6 additions & 3 deletions eZ/Publish/Core/Repository/Tests/Service/Mock/ContentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2510,7 +2510,8 @@ public function testCreateContentWithLocations()
$this->equalTo($parentLocation),
$this->equalTo(true),
$this->equalTo(null),
$this->equalTo(null)
$this->equalTo(null),
$this->equalTo(false)
)->will($this->returnValue($spiLocationCreateStruct));

$domainMapperMock->expects($this->at(2))
Expand All @@ -2520,7 +2521,8 @@ public function testCreateContentWithLocations()
$this->equalTo($parentLocation),
$this->equalTo(false),
$this->equalTo(null),
$this->equalTo(null)
$this->equalTo(null),
$this->equalTo(false)
)->will($this->returnValue($spiLocationCreateStruct));

$spiContentCreateStruct = new SPIContentCreateStruct(
Expand Down Expand Up @@ -2689,7 +2691,8 @@ function ($object) use ($that, $contentCreateStruct) {
$this->equalTo($parentLocation),
$this->equalTo(true),
$this->equalTo(null),
$this->equalTo(null)
$this->equalTo(null),
$this->equalTo(false)
)->will($this->returnValue($spiLocationCreateStruct));

$mockedService->createContent(
Expand Down

0 comments on commit 42fee31

Please sign in to comment.