diff --git a/app/components/media_asset_component/media_asset_component.html.erb b/app/components/media_asset_component/media_asset_component.html.erb index 45b31f623..18145815a 100644 --- a/app/components/media_asset_component/media_asset_component.html.erb +++ b/app/components/media_asset_component/media_asset_component.html.erb @@ -6,7 +6,7 @@ 100% - <% if media_asset.expunged? || media_asset.deleted? %> + <% if media_asset.removed? %>
Image deleted.
<% elsif media_asset.processing? %><%= spinner_icon(class: "h-8") %>
diff --git a/app/models/media_asset.rb b/app/models/media_asset.rb index bd3407b6f..e91562bea 100644 --- a/app/models/media_asset.rb +++ b/app/models/media_asset.rb @@ -27,6 +27,8 @@ class MediaAsset < ApplicationRecord scope :public_only, -> { where(is_public: true) } 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 :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. # Active: The asset has been successfully uploaded and is ready to use. @@ -51,8 +53,6 @@ class MediaAsset < ApplicationRecord before_create :initialize_file_key - scope :expired, -> { processing.where(created_at: ..4.hours.ago) } - def self.prune! expired.update_all(status: :failed) end @@ -321,6 +321,10 @@ class MediaAsset < ApplicationRecord end end + def removed? + deleted? || expunged? + end + # @return [Mime::Type] The file's MIME type. def mime_type Mime::Type.lookup_by_extension(file_ext) diff --git a/app/policies/media_asset_policy.rb b/app/policies/media_asset_policy.rb index c28e09a9d..29b2f05b8 100644 --- a/app/policies/media_asset_policy.rb +++ b/app/policies/media_asset_policy.rb @@ -14,7 +14,7 @@ class MediaAssetPolicy < ApplicationPolicy end def can_see_image? - record.post.blank? || record.post.visible?(user) + !record.removed? && (record.post.blank? || record.post.visible?(user)) end def api_attributes diff --git a/app/views/media_assets/show.html.erb b/app/views/media_assets/show.html.erb index 6ce901d33..47f112591 100644 --- a/app/views/media_assets/show.html.erb +++ b/app/views/media_assets/show.html.erb @@ -159,11 +159,13 @@ <% end %> - <% @media_asset.source_urls.each do |url| %> -