Avoid displaying unapproved screenshots in Any view

This commit is contained in:
Christoph Haas 2021-03-01 01:23:52 +01:00
parent ce9e1d8877
commit 7227f769c0
2 changed files with 6 additions and 2 deletions

View file

@ -288,7 +288,7 @@ class PackagesController < ApplicationController
# Return packages matching the criteria given by parameters
def query_packages
# Eager load the screenshots to avoid N+1 queries to check Screenshot.accessibly_by later
# Eager load the screenshots to avoid N+1 queries to check Screenshot.accessible_by later
packages = Package.includes(:screenshots).order(visits: :desc)
# text search
@ -305,6 +305,10 @@ class PackagesController < ApplicationController
when 'without'
packages = packages.without_screenshots
logger.debug 'Limiting packages to those without screenshots'
else
packages = packages.where(screenshots: Screenshot.accessible_by(current_ability, :view)).or(
packages.without_screenshots)
end
return packages