one-off submission

This commit is contained in:
Pete Matsyburka
2025-05-31 15:15:25 +03:00
committed by Pete Matsyburka
parent c59d948d41
commit f03166b4ea
47 changed files with 218 additions and 145 deletions
+16 -17
View File
@@ -4,7 +4,7 @@ module Templates
module CloneAttachments
module_function
def call(template:, original_template:, documents: [], excluded_attachment_uuids: [])
def call(template:, original_template:, documents: [], excluded_attachment_uuids: [], save: true)
schema_uuids_replacements = {}
template.schema.each_with_index do |schema_item, index|
@@ -29,32 +29,31 @@ module Templates
end
end
template.save!
attachments =
original_template.schema_documents.filter_map do |document|
new_attachment_uuid = schema_uuids_replacements[document.uuid]
original_template.schema_documents.filter_map do |document|
new_attachment_uuid = schema_uuids_replacements[document.uuid]
next unless new_attachment_uuid
next unless new_attachment_uuid
new_document =
ApplicationRecord.no_touching do
template.documents_attachments.create!(
new_document =
template.documents_attachments.new(
uuid: new_attachment_uuid,
blob_id: document.blob_id
)
end
clone_document_preview_images_attachments(document:, new_document:)
clone_document_preview_images_attachments(document:, new_document:)
new_document
end
new_document
end
template.save! if save
attachments
end
def clone_document_preview_images_attachments(document:, new_document:)
ApplicationRecord.no_touching do
document.preview_images_attachments.each do |preview_image|
new_document.preview_images_attachments.create!(blob_id: preview_image.blob_id)
end
document.preview_images_attachments.each do |preview_image|
new_document.preview_images_attachments.new(blob_id: preview_image.blob_id)
end
end
end