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