-
Notifications
You must be signed in to change notification settings - Fork 14
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
IBX-8426: Fixed duplicate relations #390
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ce7683e
IBX-8426: Fixed duplicate relations
reithor 5227bc9
Integration test
reithor 5694358
fix errors from phpstan
reithor f6bf7a8
minor change
reithor 993cc19
Apply suggestions from code review
reithor 7737be3
added createUser to RepositoryTestCase
reithor 1ec290d
fixed unit test: ContentTest
reithor 0f8fe40
undo changes in internalLoadRelations
reithor 960a671
Update tests/integration/Core/RepositoryTestCase.php
reithor 5cf5734
apply suggestion from code review
reithor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
155 changes: 155 additions & 0 deletions
155
tests/integration/Core/Repository/ContentService/UpdateContentTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Tests\Integration\Core\Repository\ContentService; | ||
|
||
use Ibexa\Contracts\Core\Repository\Values\Content\Content; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Section; | ||
use Ibexa\Contracts\Core\Repository\Values\User\Limitation\SectionLimitation; | ||
use Ibexa\Contracts\Core\Repository\Values\User\User; | ||
use Ibexa\Tests\Integration\Core\RepositoryTestCase; | ||
|
||
/** | ||
* @covers \Ibexa\Contracts\Core\Repository\ContentService | ||
*/ | ||
final class UpdateContentTest extends RepositoryTestCase | ||
{ | ||
/** | ||
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception | ||
*/ | ||
public function testUpdateContentHavingPrivateRelation(): void | ||
{ | ||
$sectionService = self::getSectionService(); | ||
$contentService = self::getContentService(); | ||
$permissionResolver = self::getPermissionResolver(); | ||
|
||
$this->addRelationFieldToFolderContentType(); | ||
|
||
$privateSection = $this->createPrivateSection(); | ||
|
||
$folderPrivate = $this->createFolder(['eng-GB' => 'Private Folder'], 2); | ||
$sectionService->assignSection($folderPrivate->getContentInfo(), $privateSection); | ||
|
||
// Create folder with relation to 'Private Folder' | ||
$folder = $this->createFolderWithRelations([$folderPrivate->getId()]); | ||
|
||
$userWithRoleLimitation = $this->createUserWithNoAccessToPrivateSection(); | ||
|
||
// Create & publish new $folder version as $editor | ||
$permissionResolver->setCurrentUserReference($userWithRoleLimitation); | ||
$folder = $this->publishVersionWithoutChanges($folder->getContentInfo()); | ||
|
||
// Read relations & check if count($relations) is unchanged | ||
self::setAdministratorUser(); | ||
$relations = $contentService->loadRelations($folder->getVersionInfo()); | ||
self::assertCount(1, (array)$relations); | ||
reithor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/** | ||
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception | ||
*/ | ||
private function addRelationFieldToFolderContentType(): void | ||
{ | ||
$contentTypeService = self::getContentTypeService(); | ||
$folderType = $contentTypeService->loadContentTypeByIdentifier('folder'); | ||
$folderTypeDraft = $contentTypeService->createContentTypeDraft($folderType); | ||
|
||
$relationsFieldCreateStruct = $contentTypeService->newFieldDefinitionCreateStruct( | ||
'relations', | ||
'ezobjectrelationlist' | ||
); | ||
$relationsFieldCreateStruct->names = ['eng-GB' => 'Relations']; | ||
$contentTypeService->addFieldDefinition($folderTypeDraft, $relationsFieldCreateStruct); | ||
$contentTypeService->publishContentTypeDraft($folderTypeDraft); | ||
} | ||
|
||
/** | ||
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException | ||
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException | ||
*/ | ||
private function createPrivateSection(): Section | ||
{ | ||
$sectionService = self::getSectionService(); | ||
|
||
$sectionCreateStruct = $sectionService->newSectionCreateStruct(); | ||
$sectionCreateStruct->identifier = 'private'; | ||
$sectionCreateStruct->name = 'Private Section'; | ||
|
||
return $sectionService->createSection($sectionCreateStruct); | ||
} | ||
|
||
/** | ||
* @param int[] $relationListTarget | ||
* | ||
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception | ||
*/ | ||
private function createFolderWithRelations(array $relationListTarget): Content | ||
{ | ||
$contentService = self::getContentService(); | ||
|
||
$folder = $this->createFolder(['eng-GB' => 'Folder with private relation'], 2); | ||
$folderDraft = $contentService->createContentDraft($folder->getContentInfo()); | ||
$folderUpdateStruct = $contentService->newContentUpdateStruct(); | ||
$folderUpdateStruct->setField('relations', $relationListTarget); | ||
|
||
$folder = $contentService->updateContent($folderDraft->getVersionInfo(), $folderUpdateStruct); | ||
|
||
return $contentService->publishVersion($folder->getVersionInfo()); | ||
} | ||
|
||
/** | ||
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException | ||
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException | ||
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException | ||
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\LimitationValidationException | ||
*/ | ||
private function assignToUserRoleWithStandardSectionLimitation(User $user): void | ||
{ | ||
$sectionService = self::getSectionService(); | ||
$roleService = self::getRoleService(); | ||
|
||
$roleCreateStruct = $roleService->newRoleCreateStruct('limited_access'); | ||
$roleCreateStruct->addPolicy($roleService->newPolicyCreateStruct('*', '*')); | ||
$role = $roleService->createRole($roleCreateStruct); | ||
$roleService->publishRoleDraft($role); | ||
|
||
// limit access to standard section only on the role assignment level | ||
$standardSection = $sectionService->loadSectionByIdentifier('standard'); | ||
$roleService->assignRoleToUser( | ||
$role, | ||
$user, | ||
new SectionLimitation(['limitationValues' => [$standardSection->id]]) | ||
); | ||
} | ||
|
||
/** | ||
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception | ||
*/ | ||
private function createUserWithNoAccessToPrivateSection(): User | ||
{ | ||
$user = $this->createUser('test.editor', 'Editor', 'Test'); | ||
$this->assignToUserRoleWithStandardSectionLimitation($user); | ||
|
||
return $user; | ||
} | ||
|
||
/** | ||
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception | ||
*/ | ||
private function publishVersionWithoutChanges(ContentInfo $contentInfo): Content | ||
{ | ||
$contentService = self::getContentService(); | ||
|
||
$folderDraft = $contentService->createContentDraft($contentInfo); | ||
$folderUpdateStruct = $contentService->newContentUpdateStruct(); | ||
$folder = $contentService->updateContent($folderDraft->getVersionInfo(), $folderUpdateStruct); | ||
|
||
return $contentService->publishVersion($folder->getVersionInfo()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ | |
namespace Ibexa\Tests\Integration\Core; | ||
|
||
use Ibexa\Contracts\Core\Repository\Values\Content\Content; | ||
use Ibexa\Contracts\Core\Repository\Values\User\User; | ||
use Ibexa\Contracts\Core\Repository\Values\User\UserGroup; | ||
use Ibexa\Contracts\Core\Test\IbexaKernelTestCase; | ||
use InvalidArgumentException; | ||
|
||
|
@@ -17,6 +19,7 @@ abstract class RepositoryTestCase extends IbexaKernelTestCase | |
public const CONTENT_TREE_ROOT_ID = 2; | ||
|
||
private const CONTENT_TYPE_FOLDER_IDENTIFIER = 'folder'; | ||
private const MAIN_USER_GROUP_REMOTE_ID = 'f5c88a2209584891056f987fd965b0ba'; | ||
|
||
protected function setUp(): void | ||
{ | ||
|
@@ -41,6 +44,37 @@ public function createFolder(array $names, int $parentLocationId = self::CONTENT | |
return $contentService->publishVersion($draft->getVersionInfo()); | ||
} | ||
|
||
/** | ||
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException | ||
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\ContentValidationException | ||
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException | ||
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\ContentFieldValidationException | ||
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException | ||
*/ | ||
protected function createUser(string $login, string $firstName, string $lastName, UserGroup $userGroup = null): User | ||
reithor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
$userService = self::getUserService(); | ||
|
||
if (null === $userGroup) { | ||
$userGroup = $userService->loadUserGroupByRemoteId(self::MAIN_USER_GROUP_REMOTE_ID); | ||
} | ||
|
||
$userCreateStruct = $userService->newUserCreateStruct( | ||
$login, | ||
"[email protected]", | ||
'secret', | ||
'eng-US' | ||
); | ||
$userCreateStruct->enabled = true; | ||
|
||
// Set some fields required by the user ContentType | ||
$userCreateStruct->setField('first_name', $firstName); | ||
$userCreateStruct->setField('last_name', $lastName); | ||
|
||
// Create a new user instance. | ||
return $userService->createUser($userCreateStruct, [$userGroup]); | ||
} | ||
|
||
/** | ||
* @param array<string, string> $names | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Review note: it's done like that because there are some architecture issues that are not easy to fix, see #390 (review)