Dropdown on details page allows image management for users and admins
This commit is contained in:
parent
263f6cd33f
commit
16999260ca
8 changed files with 75 additions and 35 deletions
|
|
@ -36,15 +36,4 @@ class Package < ActiveRecord::Base
|
|||
def self.screenshots_approved
|
||||
self.screenshots.find_by(approved: true)
|
||||
end
|
||||
|
||||
# Return a query of all screenshots that the current user may see
|
||||
# Consists of:
|
||||
# - approved (public) screenshots
|
||||
# - screenshots uploaded by the user (determined by cookie session)
|
||||
def screenshots_visible_to_user(token)
|
||||
self.screenshots.where(
|
||||
# "approved=true"
|
||||
"approved=true OR uploaderhash=?", token
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -20,10 +20,14 @@ class Screenshot < ActiveRecord::Base
|
|||
# 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.
|
||||
|
||||
# TODO: will fail if screenshot is updated because it finds its own image
|
||||
def validate_image_is_unique
|
||||
# Look for images with the same checksum / image_fingerprint
|
||||
if Screenshot.find_by(image_fingerprint: image_fingerprint, package_id: self.package.id)
|
||||
errors.add(:image, "has already been uploaded for this package")
|
||||
if screenshot=Screenshot.find_by(image_fingerprint: image_fingerprint, package_id: self.package.id)
|
||||
unless screenshot.id == self.id
|
||||
errors.add(:image, "has already been uploaded for this package")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue