Files
docuseal/app/controllers/template_documents_controller.rb
T

34 lines
1.1 KiB
Ruby
Raw Normal View History

2024-03-23 23:16:40 +02:00
# frozen_string_literal: true
class TemplateDocumentsController < ApplicationController
load_and_authorize_resource :template
def create
2024-05-30 00:35:35 +03:00
if params[:blobs].blank? && params[:files].blank?
2024-09-18 19:47:47 +03:00
return render json: { error: I18n.t('file_is_missing') }, status: :unprocessable_entity
2024-05-30 00:35:35 +03:00
end
2024-03-23 23:16:40 +02:00
2024-04-06 21:44:44 +03:00
old_fields_hash = @template.fields.hash
2024-06-22 13:16:22 +03:00
documents = Templates::CreateAttachments.call(@template, params, extract_fields: true)
2024-03-23 23:16:40 +02:00
schema = documents.map do |doc|
{ attachment_uuid: doc.uuid, name: doc.filename.base }
end
render json: {
schema:,
2024-04-06 21:44:44 +03:00
fields: old_fields_hash == @template.fields.hash ? nil : @template.fields,
submitters: old_fields_hash == @template.fields.hash ? nil : @template.submitters,
2024-03-23 23:16:40 +02:00
documents: documents.as_json(
methods: %i[metadata signed_uuid],
include: {
preview_images: { methods: %i[url metadata filename] }
}
)
}
rescue Templates::CreateAttachments::PdfEncrypted
2024-09-18 19:47:47 +03:00
render json: { error: 'PDF encrypted', status: 'pdf_encrypted' }, status: :unprocessable_entity
2024-03-23 23:16:40 +02:00
end
end