Ignore missing attachments
This commit is contained in:
@@ -57,11 +57,17 @@ class Account::DataTransfer::ActionTextRichTextRecordSet < Account::DataTransfer
|
||||
|
||||
content.send(:attachment_nodes).each do |node|
|
||||
sgid = SignedGlobalID.parse(node["sgid"], for: ActionText::Attachable::LOCATOR_NAME)
|
||||
record = sgid&.find
|
||||
next if record&.account_id != account.id
|
||||
|
||||
node["gid"] = record.to_global_id.to_s
|
||||
node.remove_attribute("sgid")
|
||||
record = begin
|
||||
sgid&.find
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
nil
|
||||
end
|
||||
|
||||
if record&.account_id == account.id
|
||||
node["gid"] = record.to_global_id.to_s
|
||||
node.remove_attribute("sgid")
|
||||
end
|
||||
end
|
||||
|
||||
content.fragment.source.to_html
|
||||
@@ -74,11 +80,12 @@ class Account::DataTransfer::ActionTextRichTextRecordSet < Account::DataTransfer
|
||||
|
||||
fragment.css("action-text-attachment[gid]").each do |node|
|
||||
gid = GlobalID.parse(node["gid"])
|
||||
next unless gid
|
||||
|
||||
record = gid.find
|
||||
node["sgid"] = record.attachable_sgid
|
||||
node.remove_attribute("gid")
|
||||
if gid
|
||||
record = gid.find
|
||||
node["sgid"] = record.attachable_sgid
|
||||
node.remove_attribute("gid")
|
||||
end
|
||||
end
|
||||
|
||||
fragment.to_html
|
||||
|
||||
@@ -59,4 +59,21 @@ class Account::ExportTest < ActiveSupport::TestCase
|
||||
assert entry, "Expected blob file in zip"
|
||||
end
|
||||
end
|
||||
|
||||
test "build succeeds when rich text references missing blob" do
|
||||
blob = ActiveStorage::Blob.create_and_upload!(
|
||||
io: file_fixture("moon.jpg").open,
|
||||
filename: "moon.jpg",
|
||||
content_type: "image/jpeg"
|
||||
)
|
||||
card = cards(:logo)
|
||||
card.update!(description: "<action-text-attachment sgid=\"#{blob.attachable_sgid}\"></action-text-attachment>")
|
||||
ActiveStorage::Blob.where(id: blob.id).delete_all
|
||||
|
||||
export = Account::Export.create!(account: Current.account, user: users(:david))
|
||||
|
||||
export.build
|
||||
|
||||
assert export.completed?
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user