add clone document params

pull/414/head
Pete Matsyburka 11 months ago
parent a4928268ea
commit f380200e03

@ -23,7 +23,9 @@ module Api
cloned_template.source = :api cloned_template.source = :api
cloned_template.save! cloned_template.save!
schema_documents = Templates::CloneAttachments.call(template: cloned_template, original_template: @template) schema_documents = Templates::CloneAttachments.call(template: cloned_template,
original_template: @template,
documents: params[:documents])
WebhookUrls.for_account_id(cloned_template.account_id, 'template.created').each do |webhook_url| WebhookUrls.for_account_id(cloned_template.account_id, 'template.created').each do |webhook_url|
SendTemplateCreatedWebhookRequestJob.perform_async('template_id' => cloned_template.id, SendTemplateCreatedWebhookRequestJob.perform_async('template_id' => cloned_template.id,

@ -10,7 +10,7 @@ module Templates
template.external_id = external_id template.external_id = external_id
template.author = author template.author = author
template.preferences = original_template.preferences.deep_dup template.preferences = original_template.preferences.deep_dup
template.name = name || "#{original_template.name} (#{I18n.t('clone')})" template.name = name.presence || "#{original_template.name} (#{I18n.t('clone')})"
template.assign_attributes(original_template.slice(:folder_id, :schema)) template.assign_attributes(original_template.slice(:folder_id, :schema))

@ -4,17 +4,21 @@ module Templates
module CloneAttachments module CloneAttachments
module_function module_function
def call(template:, original_template:) def call(template:, original_template:, documents: [])
schema_uuids_replacements = {} schema_uuids_replacements = {}
cloned_schema = original_template.schema.deep_dup cloned_schema = original_template.schema.deep_dup
cloned_fields = template.fields.deep_dup cloned_fields = template.fields.deep_dup
cloned_schema.each do |schema_item| cloned_schema.each_with_index do |schema_item, index|
new_schema_item_uuid = SecureRandom.uuid new_schema_item_uuid = SecureRandom.uuid
schema_uuids_replacements[schema_item['attachment_uuid']] = new_schema_item_uuid schema_uuids_replacements[schema_item['attachment_uuid']] = new_schema_item_uuid
schema_item['attachment_uuid'] = new_schema_item_uuid schema_item['attachment_uuid'] = new_schema_item_uuid
new_name = documents&.dig(index, 'name')
schema_item['name'] = new_name if new_name.present?
end end
cloned_fields.each do |field| cloned_fields.each do |field|

Loading…
Cancel
Save