Files
docuseal/lib/submitters.rb
T
2023-08-14 00:48:42 +03:00

32 lines
959 B
Ruby

# frozen_string_literal: true
module Submitters
module_function
def select_attachments_for_download(submitter)
original_documents = submitter.submission.template.documents.preload(:blob)
is_more_than_two_images = original_documents.count(&:image?) > 1
submitter.documents.preload(:blob).reject do |attachment|
is_more_than_two_images && original_documents.find { |a| a.uuid == attachment.uuid }&.image?
end
end
def create_attachment!(submitter, params)
blob =
if (file = params[:file])
ActiveStorage::Blob.create_and_upload!(io: file.open,
filename: file.original_filename,
content_type: file.content_type)
else
ActiveStorage::Blob.find_signed(params[:blob_signed_id])
end
ActiveStorage::Attachment.create!(
blob:,
name: params[:name],
record: submitter
)
end
end