-
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
15
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
15 commits
Select commit
Hold shift + click to select a range
0cc8091
IBX-6773: Bookmarks for non-accessible contents cause exception
vidarl 8906ad5
Aligned PHPStan baseline with the bookmark changes
vidarl 22773af
Consolidate IsBookmarked criterion into Criterion\Location\IsBookmarked
vidarl 87679d7
Tests: Extend IsBookmarked true/false coverage to Content filtering
vidarl c0dddfd
Review comment: Throw Core InvalidArgumentException from IsBookmarked…
vidarl 8953c21
Move IsBookmarked integration tests into LocationFilteringTest/Conten…
vidarl 0c995ac
Review comment: Use ALIAS/COLUMN_LOCATION_ID consts and @param docblo…
vidarl 4e223f8
Review comment: Document Content filtering matches main Locations onl…
vidarl 976d801
Review comment: Use Core InvalidArgumentException, and(), and @intern…
vidarl 7c4d80f
Review comment: Extend SortClause\Location instead of SortClause in B…
vidarl c035aa5
Review comment: Simplify BookmarkService constructor doc, catch Repos…
vidarl cb6bddb
Review comment: Rename BookmarkQueryBuilderTest to IsBookmarkedQueryB…
vidarl 5a63326
Review comment: Bump Bookmark deprecation tags to 4.6.32
vidarl a0dcc03
Review comment: Reuse BaseLocationSortClauseQueryBuilder in bookmark …
vidarl daec766
Added regression tests for bookmarks of inaccessible and removed items
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
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
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
24 changes: 24 additions & 0 deletions
24
src/contracts/Repository/Values/Content/Query/SortClause/Location/Bookmark/Id.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\Location\Bookmark; | ||
|
|
||
| use Ibexa\Contracts\Core\Repository\Values\Content\Query; | ||
| use Ibexa\Contracts\Core\Repository\Values\Content\Query\SortClause\Location; | ||
| use Ibexa\Contracts\Core\Repository\Values\Filter\FilteringSortClause; | ||
|
|
||
| /** | ||
| * Sets sort direction on the bookmark id for a location query containing IsBookmarked criterion. | ||
| */ | ||
| final class Id extends Location 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
81 changes: 81 additions & 0 deletions
81
...lib/Persistence/Legacy/Filter/CriterionQueryBuilder/Location/IsBookmarkedQueryBuilder.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,81 @@ | ||
| <?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 Doctrine\DBAL\Query\QueryBuilder; | ||
| use Ibexa\Contracts\Core\Persistence\Filter\Doctrine\FilteringQueryBuilder; | ||
| use Ibexa\Contracts\Core\Repository\PermissionResolver; | ||
| use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Location\IsBookmarked; | ||
| use Ibexa\Contracts\Core\Repository\Values\Filter\FilteringCriterion; | ||
| use Ibexa\Core\Base\Exceptions\InvalidArgumentException; | ||
| use Ibexa\Core\Persistence\Legacy\Bookmark\Gateway\DoctrineDatabase; | ||
|
|
||
| /** | ||
| * @internal for internal use by Repository Filtering | ||
| */ | ||
| final class IsBookmarkedQueryBuilder extends BaseLocationCriterionQueryBuilder | ||
| { | ||
| private const ALIAS = 'bookmark'; | ||
|
|
||
| private PermissionResolver $permissionResolver; | ||
|
|
||
| public function __construct( | ||
| PermissionResolver $permissionResolver | ||
| ) { | ||
| $this->permissionResolver = $permissionResolver; | ||
| } | ||
|
|
||
| public function accepts(FilteringCriterion $criterion): bool | ||
| { | ||
| return $criterion instanceof IsBookmarked; | ||
| } | ||
|
|
||
| /** | ||
| * @param \Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Location\IsBookmarked $criterion | ||
| * | ||
| * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException | ||
| */ | ||
| public function buildQueryConstraint( | ||
| FilteringQueryBuilder $queryBuilder, | ||
| FilteringCriterion $criterion | ||
| ): string { | ||
| parent::buildQueryConstraint($queryBuilder, $criterion); | ||
|
vidarl marked this conversation as resolved.
|
||
|
|
||
| $isBookmarked = $criterion->value[0] ?? null; | ||
| if (!is_bool($isBookmarked)) { | ||
| throw new InvalidArgumentException( | ||
| '$criterion', | ||
| 'IsBookmarked criterion value must be boolean at index 0.' | ||
| ); | ||
| } | ||
|
|
||
|
vidarl marked this conversation as resolved.
|
||
| $userId = $this->permissionResolver->getCurrentUserReference()->getUserId(); | ||
|
|
||
| $subQueryBuilder = new QueryBuilder($queryBuilder->getConnection()); | ||
| $subQueryBuilder | ||
| ->select('1') | ||
| ->from(DoctrineDatabase::TABLE_BOOKMARKS, self::ALIAS) | ||
| ->where( | ||
| $subQueryBuilder->expr()->eq( | ||
| self::ALIAS . '.' . DoctrineDatabase::COLUMN_USER_ID, | ||
| $queryBuilder->createNamedParameter($userId, ParameterType::INTEGER) | ||
| ), | ||
| $subQueryBuilder->expr()->eq( | ||
| self::ALIAS . '.' . DoctrineDatabase::COLUMN_LOCATION_ID, | ||
| 'location.node_id' | ||
| ) | ||
| ); | ||
|
|
||
| return sprintf( | ||
| $isBookmarked ? 'EXISTS (%s)' : 'NOT EXISTS (%s)', | ||
| $subQueryBuilder->getSQL() | ||
| ); | ||
| } | ||
| } | ||
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
95 changes: 95 additions & 0 deletions
95
...tence/Legacy/Filter/SortClauseQueryBuilder/Location/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,95 @@ | ||
| <?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\Location\Bookmark; | ||
|
|
||
| use Doctrine\DBAL\ParameterType; | ||
| use Ibexa\Contracts\Core\Persistence\Filter\Doctrine\FilteringQueryBuilder; | ||
| use Ibexa\Contracts\Core\Repository\PermissionResolver; | ||
| use Ibexa\Contracts\Core\Repository\Values\Content\Query\SortClause\Location\Bookmark\Id; | ||
| use Ibexa\Contracts\Core\Repository\Values\Filter\FilteringSortClause; | ||
| use Ibexa\Core\Base\Exceptions\InvalidArgumentException; | ||
| use Ibexa\Core\Persistence\Legacy\Bookmark\Gateway\DoctrineDatabase; | ||
| use Ibexa\Core\Persistence\Legacy\Filter\SortClauseQueryBuilder\Location\BaseLocationSortClauseQueryBuilder; | ||
|
|
||
| /** | ||
| * @internal | ||
| */ | ||
| final class IdSortClauseQueryBuilder extends BaseLocationSortClauseQueryBuilder | ||
| { | ||
| private const ALIAS = 'ibexa_sort_bookmark'; | ||
|
|
||
| private PermissionResolver $permissionResolver; | ||
|
|
||
| public function __construct(PermissionResolver $permissionResolver) | ||
| { | ||
| $this->permissionResolver = $permissionResolver; | ||
| } | ||
|
|
||
| public function accepts(FilteringSortClause $sortClause): bool | ||
| { | ||
| return $sortClause instanceof Id; | ||
| } | ||
|
|
||
| /** | ||
| * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException | ||
| */ | ||
| public function buildQuery( | ||
| FilteringQueryBuilder $queryBuilder, | ||
| FilteringSortClause $sortClause | ||
| ): void { | ||
| if (!$sortClause instanceof Id) { | ||
| throw new InvalidArgumentException( | ||
| '$sortClause', | ||
| sprintf('Expected %s, got %s', Id::class, get_class($sortClause)) | ||
| ); | ||
| } | ||
|
|
||
| parent::buildQuery($queryBuilder, $sortClause); | ||
| } | ||
|
|
||
| protected function joinAdditionalTables( | ||
| FilteringQueryBuilder $queryBuilder, | ||
| string $locationAlias | ||
| ): void { | ||
| $userId = $this->permissionResolver->getCurrentUserReference()->getUserId(); | ||
|
|
||
| $queryBuilder->leftJoinOnce( | ||
| $locationAlias, | ||
| DoctrineDatabase::TABLE_BOOKMARKS, | ||
| self::ALIAS, | ||
| (string)$queryBuilder->expr()->and( | ||
| sprintf( | ||
| '%s.node_id = %s.%s', | ||
| $locationAlias, | ||
| self::ALIAS, | ||
| DoctrineDatabase::COLUMN_LOCATION_ID | ||
| ), | ||
| $queryBuilder->expr()->eq( | ||
| sprintf('%s.%s', self::ALIAS, DoctrineDatabase::COLUMN_USER_ID), | ||
| $queryBuilder->createNamedParameter($userId, ParameterType::INTEGER) | ||
| ) | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| protected function getSortingExpression(): string | ||
| { | ||
| return self::ALIAS . '.' . DoctrineDatabase::COLUMN_ID; | ||
| } | ||
|
|
||
| protected function getSortingExpressionForAlias(string $locationAlias): string | ||
| { | ||
| return $this->getSortingExpression(); | ||
| } | ||
|
|
||
| protected function getSortFieldName(string $sortExpression): string | ||
| { | ||
| return 'bookmark_id'; | ||
| } | ||
| } |
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.
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.