lab
This commit is contained in:
parent
7cd9c68a10
commit
36984ff1d4
20 changed files with 321 additions and 391 deletions
|
|
@ -9,6 +9,7 @@ class Screenshot < ApplicationRecord
|
|||
|
||||
scope :approved, -> { where(approved: true) }
|
||||
scope :visible, -> { where(hidden: false) }
|
||||
scope :publicly, -> { where(hidden: false, approved: true) }
|
||||
|
||||
# Shrine
|
||||
include ImageUploader::Attachment(:simage) # adds an `simage` virtual attribute
|
||||
|
|
@ -17,10 +18,10 @@ class Screenshot < ApplicationRecord
|
|||
# Takes the description of a screenshot if available.
|
||||
# Otherwise it falls back to the general description of its package.
|
||||
def caption
|
||||
if self.description.present?
|
||||
"#{self.description}"
|
||||
if description.present?
|
||||
"#{description}"
|
||||
else
|
||||
"#{self.package.description}"
|
||||
"#{package.description}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -37,25 +38,23 @@ class Screenshot < ApplicationRecord
|
|||
def status
|
||||
text = 'This image '
|
||||
|
||||
if self.approved
|
||||
text << 'is public'
|
||||
else
|
||||
text << 'has to be moderated before being publicly visible'
|
||||
end
|
||||
text << if approved
|
||||
'is public'
|
||||
else
|
||||
'has to be moderated before being publicly visible'
|
||||
end
|
||||
|
||||
if self.markedfordelete
|
||||
text << ' (and was requested to be removed)'
|
||||
end
|
||||
text << ' (and was requested to be removed)' if markedfordelete
|
||||
|
||||
return text
|
||||
text
|
||||
end
|
||||
|
||||
# Brief text describing the status of this screenshots (for admins)
|
||||
def adminstatus
|
||||
if self.approved
|
||||
if approved
|
||||
'Public'
|
||||
else
|
||||
#fa_icon('hourglass') + 'Waiting for approval'
|
||||
# fa_icon('hourglass') + 'Waiting for approval'
|
||||
'Unapproved'
|
||||
end
|
||||
end
|
||||
|
|
@ -63,32 +62,33 @@ class Screenshot < ApplicationRecord
|
|||
# Publish a screenshot from the moderation queue
|
||||
def approve!
|
||||
self.approved = true
|
||||
self.save!
|
||||
save!
|
||||
end
|
||||
|
||||
# Hide a screenshot from the public. Moderator level can do this.
|
||||
def hide!
|
||||
self.hidden = true
|
||||
self.save!
|
||||
save!
|
||||
end
|
||||
|
||||
def unhide!
|
||||
self.hidden = false
|
||||
self.save!
|
||||
save!
|
||||
end
|
||||
|
||||
# Get the newest screenshots regardless of the package it belongs to
|
||||
def self.newest
|
||||
self.order(created_at: :desc)
|
||||
order(created_at: :desc)
|
||||
end
|
||||
|
||||
# Return the part of the version up to the first - or +
|
||||
def upstream_version
|
||||
self.version.split(/[\-\+]/).first
|
||||
version.split(/[-+]/).first
|
||||
end
|
||||
|
||||
# Returns the path to this screenshot's image on disk
|
||||
def disk_path
|
||||
ActiveStorage::Blob.service.send(:path_for, self.image.key)
|
||||
ActiveStorage::Blob.service.send(:path_for, image.key)
|
||||
end
|
||||
|
||||
# Returns the MD5 hex digest of the current screenshot's data
|
||||
|
|
@ -98,8 +98,8 @@ class Screenshot < ApplicationRecord
|
|||
Digest::MD5.hexdigest(disk_path)
|
||||
|
||||
# remote files stored on another person's computer:
|
||||
#url = attachment.url
|
||||
#Digest::MD5.base64digest(Net::HTTP.get(URI(url)))
|
||||
# url = attachment.url
|
||||
# Digest::MD5.base64digest(Net::HTTP.get(URI(url)))
|
||||
end
|
||||
|
||||
private
|
||||
|
|
@ -112,11 +112,9 @@ class Screenshot < ApplicationRecord
|
|||
# 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=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
|
||||
if (screenshot = Screenshot.find_by(image_fingerprint: image_fingerprint,
|
||||
package_id: package.id)) && !(screenshot.id == 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