From 66ea039c100a4c37ccb422615991553c1a9e2143 Mon Sep 17 00:00:00 2001 From: Christoph Haas Date: Fri, 26 Jun 2015 21:17:07 +0200 Subject: [PATCH] Image uniqueness validation improved Screenshots will be accepted now even if the same image (determined by its image_fingerprint) exists on other packages. However the upload will be rejected if the very same screenshot exists on the same package. --- app/models/screenshot.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/models/screenshot.rb b/app/models/screenshot.rb index 6e59c7a..4724664 100644 --- a/app/models/screenshot.rb +++ b/app/models/screenshot.rb @@ -17,10 +17,13 @@ class Screenshot < ActiveRecord::Base # Validator that checks if the image has already been uploaded. # A generic uniqueness validator does not work because it would attribute # the error to the :image_fingerprint field and not the actual :image field. + # Currently this check makes sure that the same screenshot is not uploaded + # twice for the same package. However it allows the screenshot to be uploaded + # for two different packages. Restricting that further may happen later. def validate_image_is_unique # Look for images with the same checksum / image_fingerprint - if Screenshot.find_by(image_fingerprint: image_fingerprint) - errors.add(:image, "has already been uploaded") + if Screenshot.find_by(image_fingerprint: image_fingerprint, package_id: self.package.id) + errors.add(:image, "has already been uploaded for this package") end end