-
Notifications
You must be signed in to change notification settings - Fork 19
IBX-6773: Fixed loading Bookmarks for non-accessible content items #476
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
Open
vidarl
wants to merge
29
commits into
4.6
Choose a base branch
from
IBX-6773_Bookmarks_for_non-accessible_contents_cause_exception_4.6
base: 4.6
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
54a8758
IBX-6773: Bookmarks for non-accessible contents cause exception
vidarl 5324ef2
Fixed PHPStan error for URLAliasService
vidarl e8062af
fixup! IBX-6773: Bookmarks for non-accessible contents cause exceptio…
vidarl 070e342
fixup! IBX-6773: Bookmarks for non-accessible contents cause exceptio…
vidarl 245cba0
fixup! IBX-6773: Bookmarks for non-accessible contents cause exceptio…
vidarl 9635474
Update tests/lib/Persistence/Legacy/Filter/CriterionQueryBuilder/Loca…
vidarl 6cc6903
[PHPStan] Aligned baseline with the upstream changes
alongosz 0d293e5
Apply suggestions from code review
vidarl 8e63f7e
Added integration test for using Criterion\IsBookmarked and LocationS…
vidarl 310d457
fixup! Added integration test for using Criterion\IsBookmarked and Lo…
vidarl 3594b4f
fixup! Added integration test for using Criterion\IsBookmarked and Lo…
vidarl 5fb1a53
fixup! fixup! Added integration test for using Criterion\IsBookmarked…
vidarl 6c862de
Apply suggestion from @konradoboza
vidarl ca42c8d
Fixed deprecation notices
vidarl 2e5d7c7
Removed dependency to Criterion
vidarl c700f40
Fixed so that Bookmark criterion has parameters isBookmarked and userId
vidarl 7368c0d
tests/integration/Core/Repository/BookmarkServiceTest.php
vidarl abf0fff
Removed use of magic property
vidarl fb61a41
fixup! Fixed so that Bookmark criterion has parameters isBookmarked a…
vidarl 690322f
Revert "Removed dependency to Criterion"
vidarl 4d3f4b7
fixup! tests/integration/Core/Repository/BookmarkServiceTest.php
vidarl 80cb93e
fixup! Revert "Removed dependency to Criterion"
vidarl 89d995e
fixup! Fixed so that Bookmark criterion has parameters isBookmarked a…
vidarl 6a32843
Fixed test Ibexa\Tests\Core\Repository\Service\Mock\BookmarkTest::tes…
vidarl 2f69957
Fixed PHPstan error
vidarl 83deac2
fixup! fixup! Fixed so that Bookmark criterion has parameters isBookm…
vidarl ba5cf53
Added integration test for Criterion\IsBookmarked
vidarl 4d5dc1e
fixup! Added integration test for Criterion\IsBookmarked
vidarl 0c025cd
fixup! fixup! Fixed so that Bookmark criterion has parameters isBookm…
vidarl 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
39 changes: 39 additions & 0 deletions
39
src/contracts/Repository/Values/Content/Query/Criterion/IsBookmarked.php
This file contains hidden or 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,39 @@ | ||
| <?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\Contracts\Core\Repository\Values\Content\Query\Criterion; | ||
|
|
||
| use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; | ||
| use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Operator\Specifications; | ||
| use Ibexa\Contracts\Core\Repository\Values\Filter\FilteringCriterion; | ||
|
|
||
| /** | ||
| * A criterion that matches locations of bookmarks for a given user id. | ||
| * | ||
| * Supported operators: | ||
| * - EQ: matches against a unique user id | ||
| */ | ||
| final class IsBookmarked extends Criterion implements FilteringCriterion | ||
| { | ||
| public ?int $userId = null; | ||
|
|
||
| public function __construct( | ||
| bool $isBookmarked = true, | ||
| ?int $userId = null | ||
| ) { | ||
| $this->userId = $userId; | ||
| parent::__construct(null, null, $isBookmarked); | ||
| } | ||
|
|
||
| public function getSpecifications(): array | ||
| { | ||
| return [ | ||
| new Specifications(Operator::EQ, Specifications::FORMAT_SINGLE, Specifications::TYPE_BOOLEAN), | ||
| ]; | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
src/contracts/Repository/Values/Content/Query/SortClause/BookmarkId.php
This file contains hidden or 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,24 @@ | ||
| <?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\Contracts\Core\Repository\Values\Content\Query\SortClause; | ||
|
|
||
| use Ibexa\Contracts\Core\Repository\Values\Content\Query; | ||
| use Ibexa\Contracts\Core\Repository\Values\Content\Query\SortClause; | ||
| use Ibexa\Contracts\Core\Repository\Values\Filter\FilteringSortClause; | ||
|
|
||
| /** | ||
| * Sets sort direction on the bookmark id for a location query containing IsBookmarked criterion. | ||
| */ | ||
| final class BookmarkId extends SortClause implements FilteringSortClause | ||
| { | ||
| public function __construct(string $sortDirection = Query::SORT_ASC) | ||
| { | ||
| parent::__construct('id', $sortDirection); | ||
| } | ||
| } |
This file contains hidden or 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
76 changes: 76 additions & 0 deletions
76
src/lib/Persistence/Legacy/Filter/CriterionQueryBuilder/Location/BookmarkQueryBuilder.php
This file contains hidden or 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,76 @@ | ||
| <?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\Core\Persistence\Legacy\Filter\CriterionQueryBuilder\Location; | ||
|
|
||
| use Doctrine\DBAL\ParameterType; | ||
| use Ibexa\Contracts\Core\Persistence\Filter\Doctrine\FilteringQueryBuilder; | ||
| use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\IsBookmarked; | ||
| use Ibexa\Contracts\Core\Repository\Values\Filter\FilteringCriterion; | ||
| use Ibexa\Core\Persistence\Legacy\Bookmark\Gateway\DoctrineDatabase; | ||
| use Ibexa\Core\Repository\Permission\PermissionResolver; | ||
|
|
||
| /** | ||
| * @internal for internal use by Repository Filtering | ||
| */ | ||
| final class BookmarkQueryBuilder extends BaseLocationCriterionQueryBuilder | ||
| { | ||
| private PermissionResolver $permissionResolver; | ||
|
|
||
| public function __construct( | ||
| PermissionResolver $permissionResolver | ||
| ) { | ||
| $this->permissionResolver = $permissionResolver; | ||
| } | ||
|
|
||
| public function accepts(FilteringCriterion $criterion): bool | ||
| { | ||
| return $criterion instanceof IsBookmarked; | ||
| } | ||
|
|
||
| public function buildQueryConstraint( | ||
| FilteringQueryBuilder $queryBuilder, | ||
| FilteringCriterion $criterion | ||
| ): string { | ||
| /** @var \Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\IsBookmarked $criterion */ | ||
| $isBookmarked = $criterion->value[0] ?? null; | ||
| if (!is_bool($isBookmarked)) { | ||
| throw new \InvalidArgumentException('IsBookmarked criterion value must be boolean at index 0.'); | ||
| } | ||
| $userId = $criterion->userId ?? $this->permissionResolver->getCurrentUserReference()->getUserId(); | ||
|
|
||
| if ($isBookmarked) { | ||
| $queryBuilder | ||
| ->joinOnce( | ||
| 'location', | ||
| DoctrineDatabase::TABLE_BOOKMARKS, | ||
| 'bookmark', | ||
| 'location.node_id = bookmark.node_id' | ||
| ); | ||
|
|
||
| return $queryBuilder->expr()->eq( | ||
| 'bookmark.user_id', | ||
| $queryBuilder->createNamedParameter( | ||
| $userId, | ||
| ParameterType::INTEGER | ||
| ) | ||
| ); | ||
| } else { | ||
| $queryBuilder | ||
| ->leftJoinOnce( | ||
| 'location', | ||
| DoctrineDatabase::TABLE_BOOKMARKS, | ||
| 'bookmark', | ||
| 'location.node_id = bookmark.node_id AND bookmark.user_id = :userId' | ||
| ) | ||
| ->setParameter('userId', $userId); | ||
|
|
||
| return $queryBuilder->expr()->isNull('bookmark.id'); | ||
| } | ||
| } | ||
| } | ||
38 changes: 38 additions & 0 deletions
38
...ib/Persistence/Legacy/Filter/SortClauseQueryBuilder/Bookmark/IdSortClauseQueryBuilder.php
This file contains hidden or 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,38 @@ | ||
| <?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\Core\Persistence\Legacy\Filter\SortClauseQueryBuilder\Bookmark; | ||
|
|
||
| use Ibexa\Contracts\Core\Persistence\Filter\Doctrine\FilteringQueryBuilder; | ||
| use Ibexa\Contracts\Core\Repository\Values\Content\Query\SortClause\BookmarkId; | ||
| use Ibexa\Contracts\Core\Repository\Values\Filter\FilteringSortClause; | ||
| use Ibexa\Contracts\Core\Repository\Values\Filter\SortClauseQueryBuilder; | ||
|
|
||
| final class IdSortClauseQueryBuilder implements SortClauseQueryBuilder | ||
| { | ||
| public function accepts(FilteringSortClause $sortClause): bool | ||
| { | ||
| return $sortClause instanceof BookmarkId; | ||
| } | ||
|
|
||
| public function buildQuery( | ||
| FilteringQueryBuilder $queryBuilder, | ||
| FilteringSortClause $sortClause | ||
| ): void { | ||
| if (!$sortClause instanceof BookmarkId) { | ||
| throw new \InvalidArgumentException(sprintf( | ||
| 'Expected %s, got %s', | ||
| BookmarkId::class, | ||
| get_class($sortClause), | ||
| )); | ||
| } | ||
| /** @var \Ibexa\Contracts\Core\Repository\Values\Content\Query\SortClause\BookmarkId $sortClause */ | ||
| $queryBuilder->addSelect('bookmark.id'); | ||
| $queryBuilder->addOrderBy('bookmark.id', $sortClause->direction); | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
@alongosz
There is one problem with this queryBuilder.. In Bookmark table, we store node_id, so we need to join with ezcontentobject_tree. That is no problem if
LocationService::find()is used.However, ATM it won't work with Content filtering (
ContentService::find()as that table is already join in that caseI don't see a safe way to detect in the queryBuilder if we are either in Content or Location context..
I have a proposal below using
$queryBuilder->getExistingTableAliasJoinConditionbut not sure if it is really safe. It checks if alias "location" is joined at that time or not. But not sure if order is deterministic and if this good enough, but not sure if there is any other alternative ?The other option is somehow to state that this filter can only use with Location ?