add clone document params
This commit is contained in:
@@ -23,7 +23,9 @@ module Api
|
||||
cloned_template.source = :api
|
||||
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|
|
||||
SendTemplateCreatedWebhookRequestJob.perform_async('template_id' => cloned_template.id,
|
||||
|
||||
@@ -10,7 +10,7 @@ module Templates
|
||||
template.external_id = external_id
|
||||
template.author = author
|
||||
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))
|
||||
|
||||
|
||||
@@ -4,17 +4,21 @@ module Templates
|
||||
module CloneAttachments
|
||||
module_function
|
||||
|
||||
def call(template:, original_template:)
|
||||
def call(template:, original_template:, documents: [])
|
||||
schema_uuids_replacements = {}
|
||||
|
||||
cloned_schema = original_template.schema.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
|
||||
|
||||
schema_uuids_replacements[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
|
||||
|
||||
cloned_fields.each do |field|
|
||||
|
||||
Reference in New Issue
Block a user