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.
This commit is contained in:
parent
49d9e167ac
commit
66ea039c10
1 changed files with 5 additions and 2 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue