16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'app/services/collavre/tools/creative_remove_attachment_service.rb', line 16
def call(creative_id:, signed_id:)
raise "Current.user is required" unless Current.user
creative = Creative.find_by(id: creative_id)
return { error: "Creative not found", id: creative_id } unless creative
unless creative.has_permission?(Current.user, :write)
return { error: "No write permission on Creative", id: creative_id }
end
blob = ActiveStorage::Blob.find_signed(signed_id)
attachment = blob && creative.files.attachments.find_by(blob_id: blob.id)
return { error: "Attachment not found on this Creative" } unless attachment
attachment.purge_later
{ success: true, creative_id: creative.id, removed_signed_id: signed_id }
end
|