Do not return unapproved screenshots

This commit is contained in:
Christoph Haas 2024-07-21 23:59:54 +02:00
parent 00ce29d6a5
commit 7fe26d471e
3 changed files with 5 additions and 3 deletions

View file

@ -270,7 +270,7 @@ class PackagesController < ApplicationController
@screenshot = @package.best_screenshot_for_version(params[:version])
# Called as /thumbnail/:name
else
@screenshot = @package.screenshots.first
@screenshot = @package.screenshots.approved.first
end
# Return a 404 if the package has no screenshots or the image was not found
@ -298,7 +298,7 @@ class PackagesController < ApplicationController
@screenshot = @package.best_screenshot_for_version(params[:version])
# Called as /screenshot/:name
else
@screenshot = @package.screenshots.first
@screenshot = @package.screenshots.approved.first
end
# Return a 404 if the package has no screenshots or the image was not found

View file

@ -65,7 +65,7 @@ class Package < ApplicationRecord
# Get all screenshots and have them sorted descendingly by their version number (Debian style).
def screenshots_sorted_by_version
self.screenshots.to_a.sort { |x,y| version_compare(x.version,y.version) }
self.screenshots.approved.to_a.sort { |x,y| version_compare(x.version,y.version) }
end
# Return the newest screenshot that is not newer than the given version.

View file

@ -7,6 +7,8 @@ class Screenshot < ApplicationRecord
# - otherwise show newest first
default_scope { order(approved: :asc, hidden: :asc, created_at: :desc) }
scope :approved, -> { where(approved: true) }
# Shrine
include ImageUploader::Attachment(:simage) # adds an `simage` virtual attribute