media assets: remove image links for deleted images.
Don't show dead direct image links, reverse search links, or source links for deleted media assets.
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
100%
|
100%
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% if media_asset.expunged? || media_asset.deleted? %>
|
<% if media_asset.removed? %>
|
||||||
<p>Image deleted.</p>
|
<p>Image deleted.</p>
|
||||||
<% elsif media_asset.processing? %>
|
<% elsif media_asset.processing? %>
|
||||||
<p><%= spinner_icon(class: "h-8") %></p>
|
<p><%= spinner_icon(class: "h-8") %></p>
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ class MediaAsset < ApplicationRecord
|
|||||||
scope :public_only, -> { where(is_public: true) }
|
scope :public_only, -> { where(is_public: true) }
|
||||||
scope :private_only, -> { where(is_public: false) }
|
scope :private_only, -> { where(is_public: false) }
|
||||||
scope :without_ai_tags, -> { where.not(AITag.where("ai_tags.media_asset_id = media_assets.id").select(1).arel.exists) }
|
scope :without_ai_tags, -> { where.not(AITag.where("ai_tags.media_asset_id = media_assets.id").select(1).arel.exists) }
|
||||||
|
scope :removed, -> { where(status: [:deleted, :expunged]) }
|
||||||
|
scope :expired, -> { processing.where(created_at: ..4.hours.ago) }
|
||||||
|
|
||||||
# Processing: The asset's files are currently being resized and distributed to the backend servers.
|
# Processing: The asset's files are currently being resized and distributed to the backend servers.
|
||||||
# Active: The asset has been successfully uploaded and is ready to use.
|
# Active: The asset has been successfully uploaded and is ready to use.
|
||||||
@@ -51,8 +53,6 @@ class MediaAsset < ApplicationRecord
|
|||||||
|
|
||||||
before_create :initialize_file_key
|
before_create :initialize_file_key
|
||||||
|
|
||||||
scope :expired, -> { processing.where(created_at: ..4.hours.ago) }
|
|
||||||
|
|
||||||
def self.prune!
|
def self.prune!
|
||||||
expired.update_all(status: :failed)
|
expired.update_all(status: :failed)
|
||||||
end
|
end
|
||||||
@@ -321,6 +321,10 @@ class MediaAsset < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def removed?
|
||||||
|
deleted? || expunged?
|
||||||
|
end
|
||||||
|
|
||||||
# @return [Mime::Type] The file's MIME type.
|
# @return [Mime::Type] The file's MIME type.
|
||||||
def mime_type
|
def mime_type
|
||||||
Mime::Type.lookup_by_extension(file_ext)
|
Mime::Type.lookup_by_extension(file_ext)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class MediaAssetPolicy < ApplicationPolicy
|
|||||||
end
|
end
|
||||||
|
|
||||||
def can_see_image?
|
def can_see_image?
|
||||||
record.post.blank? || record.post.visible?(user)
|
!record.removed? && (record.post.blank? || record.post.visible?(user))
|
||||||
end
|
end
|
||||||
|
|
||||||
def api_attributes
|
def api_attributes
|
||||||
|
|||||||
@@ -159,11 +159,13 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% @media_asset.source_urls.each do |url| %>
|
<% if policy(@media_asset).can_see_image? %>
|
||||||
<tr>
|
<% @media_asset.source_urls.each do |url| %>
|
||||||
<th class="text-left">Source</th>
|
<tr>
|
||||||
<td class="break-all"><%= external_link_to url %></td>
|
<th class="text-left">Source</th>
|
||||||
</tr>
|
<td class="break-all"><%= external_link_to url %></td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% @media_asset.metadata.to_h.group_by { |key, value| key.split(":").first }.sort.each do |group, pairs| %>
|
<% @media_asset.metadata.to_h.group_by { |key, value| key.split(":").first }.sort.each do |group, pairs| %>
|
||||||
|
|||||||
Reference in New Issue
Block a user