Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZP-31837: Creating an additional Content Location does not respect Content visibility #107

Closed
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
44 changes: 44 additions & 0 deletions eZ/Publish/API/Repository/Tests/LocationServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,50 @@ public function testCreateLocation()
];
}

/**
* Test for the createLocation() method.
*
* @see \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()
{
$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 */

$this->assertInstanceOf(
'\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location',
$location
);

$this->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 @@ -20,7 +20,7 @@
* @property-read int $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 int $parentLocationId the id of the parent location
Expand Down Expand Up @@ -121,8 +121,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 @@ -808,7 +808,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
3 changes: 2 additions & 1 deletion eZ/Publish/Core/Repository/LocationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,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
8 changes: 5 additions & 3 deletions eZ/Publish/Core/Repository/Mapper/ContentDomainMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,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 @@ -681,7 +682,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 @@ -723,10 +725,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
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 @@ -2659,7 +2659,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 @@ -2669,7 +2670,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 @@ -2869,7 +2871,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));

$fieldTypeMock = $this->createMock(SPIFieldType::class);
Expand Down