-
Notifications
You must be signed in to change notification settings - Fork 29
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-6773: Bookmarks for non accessible contents cause exception #408
Open
vidarl
wants to merge
13
commits into
1.3
Choose a base branch
from
IBX-6773_Bookmarks_for_non-accessible_contents_cause_exception
base: 1.3
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 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ddca556
IBX-6773: Bookmarks for non-accessible contents cause exception
vidarl 023111b
fixup! IBX-6773: Bookmarks for non-accessible contents cause exception
vidarl 8c2de22
Apply suggestions from code review
vidarl 6091d1d
fixup! IBX-6773: Bookmarks for non-accessible contents cause exceptio…
vidarl fabbe47
fixup! IBX-6773: Bookmarks for non-accessible contents cause exceptio…
vidarl 7aa2651
fixup! fixup! IBX-6773: Bookmarks for non-accessible contents cause e…
vidarl 8483861
fixup! fixup! IBX-6773: Bookmarks for non-accessible contents cause e…
vidarl 9c9b56e
fixup! fixup! IBX-6773: Bookmarks for non-accessible contents cause e…
vidarl f620af5
fixup! IBX-6773: Bookmarks for non-accessible contents cause exception
vidarl 2665578
fixup! IBX-6773: Bookmarks for non-accessible contents cause exception
vidarl f208d3d
fixup! IBX-6773: Bookmarks for non-accessible contents cause exceptio…
vidarl ffa945c
fixup! fixup! IBX-6773: Bookmarks for non-accessible contents cause e…
vidarl 203853c
Apply suggestions from code review
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 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
43 changes: 43 additions & 0 deletions
43
eZ/Publish/API/Repository/Values/Content/Query/Criterion/IsBookmarked.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,43 @@ | ||
<?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 eZ\Publish\API\Repository\Values\Content\Query\Criterion; | ||
vidarl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
use eZ\Publish\API\Repository\Values\Content\Query\Criterion; | ||
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator\Specifications; | ||
use eZ\Publish\SPI\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 | ||
*/ | ||
class IsBookmarked extends Criterion implements FilteringCriterion | ||
{ | ||
/** | ||
* Creates a new IsBookmarked criterion. | ||
* | ||
* @param int $value UserID for which bookmarked locations must be matched against | ||
* | ||
* @throws \InvalidArgumentException if a non numeric id is given | ||
* @throws \InvalidArgumentException if the value type doesn't match the operator | ||
*/ | ||
public function __construct($value) | ||
{ | ||
parent::__construct(null, null, $value); | ||
} | ||
|
||
public function getSpecifications(): array | ||
{ | ||
return [ | ||
new Specifications(Operator::EQ, Specifications::FORMAT_SINGLE, Specifications::TYPE_INTEGER), | ||
]; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
eZ/Publish/API/Repository/Values/Content/Query/SortClause/BookmarkId.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,29 @@ | ||
<?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 eZ\Publish\API\Repository\Values\Content\Query\SortClause; | ||
|
||
use eZ\Publish\API\Repository\Values\Content\Query; | ||
use eZ\Publish\API\Repository\Values\Content\Query\SortClause; | ||
use eZ\Publish\SPI\Repository\Values\Filter\FilteringSortClause; | ||
|
||
/** | ||
* Sets sort direction on the Bookmark ID for a location query containing a IsBookmarked criterion. | ||
*/ | ||
class BookmarkId extends SortClause implements FilteringSortClause | ||
{ | ||
/** | ||
* Constructs a new BookmarkId SortClause. | ||
* | ||
* @param string $sortDirection | ||
*/ | ||
vidarl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public function __construct(string $sortDirection = Query::SORT_ASC) | ||
{ | ||
parent::__construct('id', $sortDirection); | ||
} | ||
} |
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
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
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
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
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
47 changes: 47 additions & 0 deletions
47
...sh/Core/Persistence/Legacy/Filter/CriterionQueryBuilder/Location/BookmarkQueryBuilder.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,47 @@ | ||
<?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 eZ\Publish\Core\Persistence\Legacy\Filter\CriterionQueryBuilder\Location; | ||
|
||
use Doctrine\DBAL\ParameterType; | ||
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\IsBookmarked; | ||
use eZ\Publish\Core\Persistence\Legacy\Bookmark\Gateway\DoctrineDatabase; | ||
use eZ\Publish\SPI\Persistence\Filter\Doctrine\FilteringQueryBuilder; | ||
use eZ\Publish\SPI\Repository\Values\Filter\FilteringCriterion; | ||
|
||
/** | ||
* @internal for internal use by Repository Filtering | ||
*/ | ||
final class BookmarkQueryBuilder extends BaseLocationCriterionQueryBuilder | ||
{ | ||
public function accepts(FilteringCriterion $criterion): bool | ||
{ | ||
return $criterion instanceof IsBookmarked; | ||
} | ||
|
||
public function buildQueryConstraint( | ||
FilteringQueryBuilder $queryBuilder, | ||
FilteringCriterion $criterion | ||
): ?string { | ||
$queryBuilder | ||
->joinOnce( | ||
'location', | ||
DoctrineDatabase::TABLE_BOOKMARKS, | ||
'bookmark', | ||
'location.node_id = bookmark.node_id' | ||
); | ||
|
||
return $queryBuilder->expr()->eq( | ||
'bookmark.user_id', | ||
$queryBuilder->createNamedParameter( | ||
(int)$criterion->value[0], | ||
ParameterType::INTEGER | ||
) | ||
); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...re/Persistence/Legacy/Filter/SortClauseQueryBuilder/Bookmark/IdSortClauseQueryBuilder.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,31 @@ | ||
<?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 eZ\Publish\Core\Persistence\Legacy\Filter\SortClauseQueryBuilder\Bookmark; | ||
|
||
use eZ\Publish\API\Repository\Values\Content\Query\SortClause\BookmarkId; | ||
use eZ\Publish\SPI\Persistence\Filter\Doctrine\FilteringQueryBuilder; | ||
use eZ\Publish\SPI\Repository\Values\Filter\FilteringSortClause; | ||
use eZ\Publish\SPI\Repository\Values\Filter\SortClauseQueryBuilder; | ||
|
||
class IdSortClauseQueryBuilder implements SortClauseQueryBuilder | ||
{ | ||
public function accepts(FilteringSortClause $sortClause): bool | ||
{ | ||
return $sortClause instanceof BookmarkId; | ||
} | ||
|
||
public function buildQuery( | ||
FilteringQueryBuilder $queryBuilder, | ||
FilteringSortClause $sortClause | ||
): void { | ||
/** @var \eZ\Publish\API\Repository\Values\Content\Query\SortClause $sortClause */ | ||
$queryBuilder->addSelect('bookmark.id'); | ||
$queryBuilder->addOrderBy('bookmark.id', $sortClause->direction); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...rsistence/Legacy/Tests/Filter/CriterionQueryBuilder/Location/BookmarkQueryBuilderTest.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,45 @@ | ||
<?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 eZ\Publish\Core\Persistence\Legacy\Tests\Filter\CriterionQueryBuilder\Location; | ||
|
||
use eZ\Publish\API\Repository\Values\Content\Query\Criterion; | ||
use eZ\Publish\Core\Persistence\Legacy\Filter\CriterionQueryBuilder\Location\BookmarkQueryBuilder; | ||
use eZ\Publish\Core\Persistence\Legacy\Tests\Filter\BaseCriterionVisitorQueryBuilderTestCase; | ||
|
||
/** | ||
* @covers \eZ\Publish\Core\Persistence\Legacy\Filter\CriterionQueryBuilder\Location\BookmarkQueryBuilder::buildQueryConstraint | ||
* @covers \eZ\Publish\Core\Persistence\Legacy\Filter\CriterionQueryBuilder\Location\BookmarkQueryBuilder::accepts | ||
*/ | ||
vidarl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
final class BookmarkQueryBuilderTest extends BaseCriterionVisitorQueryBuilderTestCase | ||
{ | ||
public function getFilteringCriteriaQueryData(): iterable | ||
{ | ||
yield 'Bookmarks locations for user_id=14' => [ | ||
new Criterion\IsBookmarked(14), | ||
'bookmark.user_id = :dcValue1', | ||
['dcValue1' => 14], | ||
]; | ||
|
||
yield 'Bookmarks locations for user_id=14 OR user_id=7' => [ | ||
new Criterion\LogicalOr( | ||
[ | ||
new Criterion\IsBookmarked(14), | ||
new Criterion\IsBookmarked(7), | ||
] | ||
), | ||
'(bookmark.user_id = :dcValue1) OR (bookmark.user_id = :dcValue2)', | ||
['dcValue1' => 14, 'dcValue2' => 7], | ||
]; | ||
} | ||
|
||
protected function getCriterionQueryBuilders(): iterable | ||
{ | ||
return [new BookmarkQueryBuilder()]; | ||
} | ||
} |
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.
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.
Why is this mapping necessary? In particular, why is there a special case for
$demoDesignLocationId
+$contactUsLocationId
?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.
The mapping is no longer needed. In first version of PR, I did not implement
SortClause\BookmarkId
, so order of the result needed to be normalized.I will revert the mapping.
I think the test is better when adding
$contactUsLocation
. In original test we test the edge case where two bookmarked locations are swapped... In my version of the test, only one of the locations that are swapped are bookmarked.Edit: Fixed cut&paste error that made the second paragraph meaningless
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.
Done in 8483861
ok?
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.
@Steveb-p @ViniTou : Could you have a second look on this please?
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.
ping @Steveb-p @ViniTou
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.
ping @Steveb-p @ViniTou