-
Notifications
You must be signed in to change notification settings - Fork 19
IBX-10854 not possible to hide content draft #667
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
base: 4.6
Are you sure you want to change the base?
Changes from all commits
1fd52ab
3e38c24
3891986
ca2b306
bbf8ce2
2b9758a
e498150
c9a3991
0de3f32
6d66d3b
169c726
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2528,12 +2528,15 @@ public function deleteTranslationFromDraft(APIVersionInfo $versionInfo, string $ | |||||
| */ | ||||||
| public function hideContent(ContentInfo $contentInfo): void | ||||||
| { | ||||||
| $locationTarget = (new DestinationLocationTarget($contentInfo->mainLocationId, $contentInfo)); | ||||||
| // If ContentInfo is in draft state, mainocationId is yet not set | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| $locationTarget = !$contentInfo->isDraft() | ||||||
| ? [new DestinationLocationTarget($contentInfo->mainLocationId, $contentInfo)] | ||||||
| : []; | ||||||
| if (!$this->permissionResolver->canUser( | ||||||
| 'content', | ||||||
| 'hide', | ||||||
| $contentInfo, | ||||||
| [$locationTarget] | ||||||
| $locationTarget | ||||||
| )) { | ||||||
| throw new UnauthorizedException('content', 'hide', ['contentId' => $contentInfo->id]); | ||||||
| } | ||||||
|
|
@@ -2568,12 +2571,16 @@ public function hideContent(ContentInfo $contentInfo): void | |||||
| */ | ||||||
| public function revealContent(ContentInfo $contentInfo): void | ||||||
| { | ||||||
| $locationTarget = (new DestinationLocationTarget($contentInfo->mainLocationId, $contentInfo)); | ||||||
| // If ContentInfo is in draft state, mainLocationId is yet not set | ||||||
| $locationTarget = !$contentInfo->isDraft() | ||||||
| ? [new DestinationLocationTarget($contentInfo->mainLocationId, $contentInfo)] | ||||||
| : []; | ||||||
|
|
||||||
| if (!$this->permissionResolver->canUser( | ||||||
| 'content', | ||||||
| 'hide', | ||||||
| $contentInfo, | ||||||
| [$locationTarget] | ||||||
| $locationTarget | ||||||
| )) { | ||||||
| throw new UnauthorizedException('content', 'hide', ['contentId' => $contentInfo->id]); | ||||||
| } | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3610,7 +3610,8 @@ public function testLoadRelationsSkipsArchivedContent() | |||||||||||
| $demoDesign | ||||||||||||
| ); | ||||||||||||
|
|
||||||||||||
| $demoDesignLocation = $this->locationService->loadLocation($demoDesign->mainLocationId); | ||||||||||||
| self::assertNotNull($demoDesign->getMainLocationId(), 'Expected mainLocationId to be set for this test case.'); | ||||||||||||
| $demoDesignLocation = $this->locationService->loadLocation($demoDesign->getMainLocationId()); | ||||||||||||
|
|
||||||||||||
| // Trashing Content's last Location will change its status to archived, | ||||||||||||
| // in this case relation towards it will not be loaded. | ||||||||||||
|
|
@@ -3936,7 +3937,8 @@ public function testLoadReverseRelationsSkipsArchivedContent() | |||||||||||
| $this->contentService->publishVersion($mediaDraft->getVersionInfo()); | ||||||||||||
| $this->contentService->publishVersion($demoDesignDraft->getVersionInfo()); | ||||||||||||
|
|
||||||||||||
| $demoDesignLocation = $this->locationService->loadLocation($demoDesignDraft->contentInfo->mainLocationId); | ||||||||||||
| self::assertNotNull($demoDesignDraft->contentInfo->getMainLocationId(), 'Expected mainLocationId to be set for this test case.'); | ||||||||||||
| $demoDesignLocation = $this->locationService->loadLocation($demoDesignDraft->contentInfo->getMainLocationId()); | ||||||||||||
|
|
||||||||||||
| // Trashing Content's last Location will change its status to archived, | ||||||||||||
| // in this case relation from it will not be loaded. | ||||||||||||
|
|
@@ -4138,7 +4140,8 @@ public function testLoadReverseRelationListSkipsArchivedContent(): void | |||||||||||
| $draft3, | ||||||||||||
| ]); | ||||||||||||
|
|
||||||||||||
| $locationToTrash = $this->locationService->loadLocation($draft3->contentInfo->mainLocationId); | ||||||||||||
| self::assertNotNull($draft3->contentInfo->getMainLocationId(), 'Expected mainLocationId to be set for this test case.'); | ||||||||||||
| $locationToTrash = $this->locationService->loadLocation($draft3->contentInfo->getMainLocationId()); | ||||||||||||
|
|
||||||||||||
| // Trashing Content's last Location will change its status to archived, in this case relation from it will not be loaded. | ||||||||||||
| $trashService->trash($locationToTrash); | ||||||||||||
|
|
@@ -5100,8 +5103,9 @@ public function testURLAliasesCreatedForNewContent() | |||||||||||
| // Automatically creates a new URLAlias for the content | ||||||||||||
| $liveContent = $this->contentService->publishVersion($draft->getVersionInfo()); | ||||||||||||
|
|
||||||||||||
| self::assertNotNull($liveContent->getVersionInfo()->getContentInfo()->getMainLocationId(), 'Expected mainLocationId to be set for this test case.'); | ||||||||||||
| $location = $this->locationService->loadLocation( | ||||||||||||
| $liveContent->getVersionInfo()->getContentInfo()->mainLocationId | ||||||||||||
| $liveContent->getVersionInfo()->getContentInfo()->getMainLocationId() | ||||||||||||
| ); | ||||||||||||
|
|
||||||||||||
| $aliases = $urlAliasService->listLocationAliases($location, false); | ||||||||||||
|
|
@@ -5128,8 +5132,9 @@ public function testURLAliasesCreatedForUpdatedContent() | |||||||||||
|
|
||||||||||||
| $draft = $this->createUpdatedDraftVersion2(); | ||||||||||||
|
|
||||||||||||
| self::assertNotNull($draft->getVersionInfo()->getContentInfo()->getMainLocationId(), 'Expected mainLocationId to be set for this test case.'); | ||||||||||||
| $location = $this->locationService->loadLocation( | ||||||||||||
| $draft->getVersionInfo()->getContentInfo()->mainLocationId | ||||||||||||
| $draft->getVersionInfo()->getContentInfo()->getMainLocationId() | ||||||||||||
| ); | ||||||||||||
|
|
||||||||||||
| // Load and assert URL aliases before publishing updated Content, so that | ||||||||||||
|
|
@@ -5156,8 +5161,9 @@ public function testURLAliasesCreatedForUpdatedContent() | |||||||||||
| // and creates new aliases, based on the changes | ||||||||||||
| $liveContent = $this->contentService->publishVersion($draft->getVersionInfo()); | ||||||||||||
|
|
||||||||||||
| self::assertNotNull($liveContent->getVersionInfo()->getContentInfo()->getMainLocationId(), 'Expected mainLocationId to be set for this test case.'); | ||||||||||||
| $location = $this->locationService->loadLocation( | ||||||||||||
| $liveContent->getVersionInfo()->getContentInfo()->mainLocationId | ||||||||||||
| $liveContent->getVersionInfo()->getContentInfo()->getMainLocationId() | ||||||||||||
| ); | ||||||||||||
|
|
||||||||||||
| $aliases = $urlAliasService->listLocationAliases($location, false); | ||||||||||||
|
|
@@ -5195,10 +5201,11 @@ public function testCustomURLAliasesNotHistorizedOnUpdatedContent() | |||||||||||
|
|
||||||||||||
| $content = $this->createContentVersion1(); | ||||||||||||
|
|
||||||||||||
| self::assertNotNull($content->getVersionInfo()->getContentInfo()->getMainLocationId(), 'Expected mainLocationId to be set for this test case.'); | ||||||||||||
| // Create a custom URL alias | ||||||||||||
| $urlAliasService->createUrlAlias( | ||||||||||||
| $this->locationService->loadLocation( | ||||||||||||
| $content->getVersionInfo()->getContentInfo()->mainLocationId | ||||||||||||
| $content->getVersionInfo()->getContentInfo()->getMainLocationId() | ||||||||||||
| ), | ||||||||||||
| '/my/fancy/story-about-ibexa-dxp', | ||||||||||||
| self::ENG_US | ||||||||||||
|
|
@@ -5219,8 +5226,9 @@ public function testCustomURLAliasesNotHistorizedOnUpdatedContent() | |||||||||||
| // the custom one is left untouched | ||||||||||||
| $liveContent = $this->contentService->publishVersion($draftVersion2->getVersionInfo()); | ||||||||||||
|
|
||||||||||||
| self::assertNotNull($liveContent->getVersionInfo()->getContentInfo()->getMainLocationId(), 'Expected mainLocationId to be set for this test case.'); | ||||||||||||
| $location = $this->locationService->loadLocation( | ||||||||||||
| $liveContent->getVersionInfo()->getContentInfo()->mainLocationId | ||||||||||||
| $liveContent->getVersionInfo()->getContentInfo()->getMainLocationId() | ||||||||||||
| ); | ||||||||||||
|
|
||||||||||||
| $aliases = $urlAliasService->listLocationAliases($location); | ||||||||||||
|
|
@@ -5391,7 +5399,8 @@ public function testDeleteTranslationUpdatesUrlAlias() | |||||||||||
| $urlAliasService = $this->getRepository()->getURLAliasService(); | ||||||||||||
|
|
||||||||||||
| $content = $this->createContentVersion2(); | ||||||||||||
| $mainLocation = $this->locationService->loadLocation($content->contentInfo->mainLocationId); | ||||||||||||
| self::assertNotNull($content->contentInfo->getMainLocationId(), 'Expected mainLocationId to be set for this test case.'); | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| $mainLocation = $this->locationService->loadLocation($content->contentInfo->getMainLocationId()); | ||||||||||||
|
|
||||||||||||
| // create custom URL alias for Content main Location | ||||||||||||
| $urlAliasService->createUrlAlias($mainLocation, '/my-custom-url', self::ENG_GB); | ||||||||||||
|
|
@@ -6229,6 +6238,74 @@ function (Location $parentLocation) { | |||||||||||
| $this->assertEquals($hiddenLocations, $hiddenLocationsAfterReveal); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * @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); | ||||||||||||
| self::assertNotNull($publishedContent->contentInfo->getMainLocationId(), 'Expected mainLocationId to be set for this test case.'); | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| $location = $this->locationService->loadLocation($publishedContent->contentInfo->getMainLocationId()); | ||||||||||||
|
|
||||||||||||
| $content = $this->contentService->loadContent($publishedContent->contentInfo->id); | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there
Suggested change
|
||||||||||||
| self::assertTrue($content->contentInfo->isHidden, 'Content is not hidden'); | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| 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); | ||||||||||||
| self::assertNotNull($publishedContent->contentInfo->getMainLocationId(), 'Expected mainLocationId to be set for this test case.'); | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| $location = $this->locationService->loadLocation($publishedContent->contentInfo->getMainLocationId()); | ||||||||||||
|
|
||||||||||||
| $content = $this->contentService->loadContent($publishedContent->contentInfo->id); | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| self::assertFalse($content->contentInfo->isHidden, 'Content is hidden'); | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| self::assertFalse($location->isHidden(), 'Location is hidden'); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException | ||||||||||||
| * @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 | ||||||||||||
| */ | ||||||||||||
|
|
@@ -6270,7 +6347,9 @@ public function testRevealContentWithHiddenParent() | |||||||||||
| $this->contentService->revealContent($contents[2]->contentInfo); | ||||||||||||
|
|
||||||||||||
| $parentContent = $this->contentService->loadContent($contents[0]->id); | ||||||||||||
| $parentLocation = $this->locationService->loadLocation($parentContent->contentInfo->mainLocationId); | ||||||||||||
|
|
||||||||||||
| self::assertNotNull($parentContent->contentInfo->getMainLocationId(), 'Expected mainLocationId to be set for this test case.'); | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| $parentLocation = $this->locationService->loadLocation($parentContent->contentInfo->getMainLocationId()); | ||||||||||||
| $parentSublocations = $this->locationService->loadLocationList([ | ||||||||||||
| $contents[1]->contentInfo->mainLocationId, | ||||||||||||
| $contents[2]->contentInfo->mainLocationId, | ||||||||||||
|
|
@@ -6328,9 +6407,11 @@ public function testRevealContentWithHiddenChildren() | |||||||||||
| $this->contentService->revealContent($contents[0]->contentInfo); | ||||||||||||
|
|
||||||||||||
| $directChildContent = $this->contentService->loadContent($contents[1]->id); | ||||||||||||
| $directChildLocation = $this->locationService->loadLocation($directChildContent->contentInfo->mainLocationId); | ||||||||||||
| self::assertNotNull($directChildContent->contentInfo->getMainLocationId(), 'Expected mainLocationId to be set for this test case.'); | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| $directChildLocation = $this->locationService->loadLocation($directChildContent->contentInfo->getMainLocationId()); | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
|
||||||||||||
| $childContent = $this->contentService->loadContent($contents[2]->id); | ||||||||||||
| self::assertNotNull($childContent->contentInfo->mainLocationId, 'Expected mainLocationId to be set for this test case.'); | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| $childLocation = $this->locationService->loadLocation($childContent->contentInfo->mainLocationId); | ||||||||||||
| $childSublocations = $this->locationService->loadLocationList([ | ||||||||||||
| $contents[3]->contentInfo->mainLocationId, | ||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this mean, with this change, that for drafts every user has ability to hide & reveal?
Because we won't be checking permission resolver for drafts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. Fixed in ca2b306.
Unsure if it 100% safe to have
$targets=[]in parameter tocanUser()though, but seems to work fine for me when I test with limitation oncontent/hidepolicy@Steveb-p