Skip to content

IBX-6773: Fixed loading Bookmarks for non-accessible content items#476

Open
vidarl wants to merge 29 commits into4.6from
IBX-6773_Bookmarks_for_non-accessible_contents_cause_exception_4.6
Open

IBX-6773: Fixed loading Bookmarks for non-accessible content items#476
vidarl wants to merge 29 commits into4.6from
IBX-6773_Bookmarks_for_non-accessible_contents_cause_exception_4.6

Conversation

@vidarl
Copy link
Copy Markdown
Contributor

@vidarl vidarl commented Feb 11, 2025

Question Answer
JIRA issue IBX-6773
Type bug
Target Ibexa version v4.6
BC breaks yes

Related PRs:

Description:

If user bookmark some location which he later looses access too, then the bookmark list in admin-ui fails with an exception.
Simply fixing BookmarkService::loadBookmarks() would be easy. The problem is to implement countUserBookmarks() in persistence layer and having it taking into account user permissions so that BC would be kept.

Talked with Adam on how to solve this without breaking BC and he suggested implementing it using filtering

The Bookmark filter will only work with location filtering (LocationService::find()), not with content (ContentService::find())

This is a port of ezsystems/ezplatform-kernel#408 which was not approved and merge in time before 3.3 went EOL.

For QA:

Read ticket for info on how to reproduce

Documentation:

Documentation for the new filter needs to be made, indeed

@sonarqubecloud
Copy link
Copy Markdown

@vidarl vidarl requested a review from a team February 12, 2025 12:28
@vidarl vidarl added the Doc needed The changes require some documentation label Feb 12, 2025
@adamwojs adamwojs changed the title IBX:6773 bookmarks for non accessible contents cause exception IBX:6773: Bookmarks for non accessible contents cause exception Feb 23, 2025
@vidarl vidarl force-pushed the IBX-6773_Bookmarks_for_non-accessible_contents_cause_exception_4.6 branch from 9164daa to ec96060 Compare February 23, 2026 15:43
Comment thread src/contracts/Repository/Values/Content/Query/Criterion/IsBookmarked.php Outdated
Comment thread src/lib/Repository/BookmarkService.php Outdated
Comment thread phpstan-baseline.neon Outdated
Comment thread phpstan-baseline.neon Outdated
Comment thread phpstan-baseline.neon Outdated
@konradoboza konradoboza requested a review from a team February 24, 2026 08:56
Comment thread src/contracts/Persistence/Bookmark/Handler.php Outdated
Copy link
Copy Markdown
Contributor

@konradoboza konradoboza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you make sure none of the deprecated classes are still in use?

@vidarl
Copy link
Copy Markdown
Contributor Author

vidarl commented Feb 24, 2026

@konradoboza : FYI : Had to add related PR : ibexa/admin-ui#1835

Comment on lines +1993 to +1994
$this->assertEquals($contactUsLocationId, $afterSwap->items[0]->id);
$this->assertEquals($beforeSwap->items[1]->id, $afterSwap->items[1]->id);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? It's not clear at first glance.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@konradoboza
The testcase initially tests swapping two locations that are both bookmarked.
I modified the test to check behavior when 1 location is bookmarked and the other is not

@vidarl vidarl force-pushed the IBX-6773_Bookmarks_for_non-accessible_contents_cause_exception_4.6 branch from 5343730 to 6c862de Compare April 21, 2026 07:36
@vidarl vidarl requested a review from alongosz April 21, 2026 10:45
/** @var \Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\IsBookmarked $criterion */
$isBookmarked = $criterion->value;
$userId = $criterion->userId ?? $this->permissionResolver->getCurrentUserReference()->getUserId();

Copy link
Copy Markdown
Contributor Author

@vidarl vidarl Apr 23, 2026

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 case

I 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->getExistingTableAliasJoinCondition but 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 ?

Suggested change
$isContentQuery = $queryBuilder->getExistingTableAliasJoinCondition('location') === null;
if ($isContentQuery) {
$connection = $queryBuilder->getConnection();
$subQb = $connection->createQueryBuilder();
$paramName = $queryBuilder->createNamedParameter(
$userId,
ParameterType::INTEGER
);
$subQuerySql = $subQb
->select('1')
->from(Gateway::CONTENT_TREE_TABLE, 'l')
->innerJoin('l', DoctrineDatabase::TABLE_BOOKMARKS, 'b', 'l.node_id = b.node_id')
->where('l.contentobject_id = content.id')
->andWhere("b.user_id = $paramName")
->getSQL();
return $isBookmarked
? "EXISTS ($subQuerySql)"
: "NOT EXISTS ($subQuerySql)";
}

* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace Ibexa\Tests\Integration\Core\Repository\Filtering;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alongosz : I created a integration test for IsBookmarked. Didn't actually find any other similar integration tests for other criterieons, so added it here. Not sure if there is a better place to put it ?

@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Doc needed The changes require some documentation Ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants