user/image rating not checked when navigating to previous/next image
Closed this issue · 2 comments
Server Software
(You can get all these stats from http://<your site>/system_info
)
- Shimmie version: 2.10.0-alpha
- Database: pgsql PostgreSQL 15.5
- Web server: PHP 8.2.7 Development Server
Client Software (please complete the following information)
- Device: windows/linux desktop
- Browser: Firefox, MS Edge
What steps trigger this bug
- enable and configure the Ratings extension
- have two images with different ratings
- login with a user with permissions to see both ratings
- configure Account > User Options > Default Rating Filter so that one of the two ratings is enabled and the other is disabled
- go to /post/list which will only show images with the enabled rating
- click on any image to get to /view
- use the Prev/Next links to get to the previous or next image
What did you expect to happen?
If the previous or next image has a rating matching the user's default rating filter, display the image. If the previous or next image has a rating outside the user's default rating filter, or if it's unrated, do not display the image or display the next-best image which matches the user's default rating filter.
What actually happened?
The previous/next image is shown regardless of the user's default rating filter and the image's rating.
--
I was able to at least hide the image in case ratings don't match by adding a new function to /ext/rating/main.php which checks the user's default ratings:
public function check_user_ratings(Image $image): bool {
$user_ratings = Ratings::get_user_default_ratings();
if (!in_array($image->rating, $user_ratings)) {
return false;
}
return true;
}
public function onDisplayingImage(DisplayingImageEvent $event)
{
global $page;
/**
* Deny images upon insufficient permissions.
**/
if (!$this->check_permissions($event->image)) {
$page->set_mode(PageMode::REDIRECT);
$page->set_redirect(make_link());
}
# added this:
if(!$this->check_user_ratings($event->image)) {
$page->set_mode(PageMode::REDIRECT);
$page->set_redirect(make_link());
error_log("don't want to see this!");
}
}
This way, if the previous or next image does not match the user's default rating filter, the user is sent back to the index page /post/list. Not pretty but at least it hides unwanted images.
A more ideal solution, if possible, would be to either dynamically find the "next wanted" image which matches the user's filter and point the previous/next links to that, or to sort of auto-navigate to the next-best image once the Prev/Next link is clicked.
Aha - when searching with no tags, the next/prev buttons do a simple "next ID number / prev ID number" search, which ignores the fact that the Ratings extension adds extra filtering even when there are no tags. I'll write a test to check that I can repro this, and then make it so that the next/prev buttons always use the full search with no shortcuts
awesome, thank you