-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IBX-6773: Bookmarks for non-accessible contents cause exception
- Loading branch information
Showing
14 changed files
with
270 additions
and
52 deletions.
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/Bookmark.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; | ||
|
||
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 Bookmark extends Criterion implements FilteringCriterion | ||
{ | ||
/** | ||
* Creates a new Bookmark 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 Bookmark criterion. | ||
*/ | ||
class BookmarkId extends SortClause implements FilteringSortClause | ||
{ | ||
/** | ||
* Constructs a new BookmarkId SortClause. | ||
* | ||
* @param string $sortDirection | ||
*/ | ||
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\Bookmark; | ||
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 Bookmark; | ||
} | ||
|
||
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 | ||
*/ | ||
final class BookmarkQueryBuilderTest extends BaseCriterionVisitorQueryBuilderTestCase | ||
{ | ||
public function getFilteringCriteriaQueryData(): iterable | ||
{ | ||
yield 'Bookmarks locations for user_id=14' => [ | ||
new Criterion\Bookmark(14), | ||
'bookmark.user_id = :dcValue1', | ||
['dcValue1' => 14], | ||
]; | ||
|
||
yield 'Bookmarks locations for user_id=14 OR user_id=7' => [ | ||
new Criterion\LogicalOr( | ||
[ | ||
new Criterion\Bookmark(14), | ||
new Criterion\Bookmark(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.