store original doc uuid in metadata

pull/220/head^2
Pete Matsyburka 2 years ago
parent 92f8901a67
commit 345fe674d4

@ -271,9 +271,10 @@ module Submissions
end end
ActiveStorage::Attachment.create!( ActiveStorage::Attachment.create!(
uuid:,
blob: ActiveStorage::Blob.create_and_upload!(io: StringIO.new(io.string), filename: "#{name}.pdf"), blob: ActiveStorage::Blob.create_and_upload!(io: StringIO.new(io.string), filename: "#{name}.pdf"),
metadata: { sha256: Base64.urlsafe_encode64(Digest::SHA256.digest(io.string)) }, metadata: { original_uuid: uuid,
analyzed: true,
sha256: Base64.urlsafe_encode64(Digest::SHA256.digest(io.string)) },
name: 'documents', name: 'documents',
record: submitter record: submitter
) )
@ -284,11 +285,7 @@ module Submissions
end end
def build_pdfs_index(submitter) def build_pdfs_index(submitter)
latest_submitter = latest_submitter = find_last_submitter(submitter)
submitter.submission.submitters
.select(&:completed_at?)
.select { |e| e.id != submitter.id && e.completed_at <= submitter.completed_at }
.max_by(&:completed_at)
Submissions::EnsureResultGenerated.call(latest_submitter) if latest_submitter Submissions::EnsureResultGenerated.call(latest_submitter) if latest_submitter
@ -309,10 +306,17 @@ module Submissions
Rollbar.error(e) if defined?(Rollbar) Rollbar.error(e) if defined?(Rollbar)
end end
[attachment.uuid, pdf] [attachment.metadata['original_uuid'] || attachment.uuid, pdf]
end end
end end
def find_last_submitter(submitter)
submitter.submission.submitters
.select(&:completed_at?)
.select { |e| e.id != submitter.id && e.completed_at <= submitter.completed_at }
.max_by(&:completed_at)
end
def build_pdf_from_image(attachment) def build_pdf_from_image(attachment)
pdf = HexaPDF::Document.new pdf = HexaPDF::Document.new
page = pdf.pages.add page = pdf.pages.add

@ -24,7 +24,8 @@ module Submitters
is_more_than_two_images = original_documents.count(&:image?) > 1 is_more_than_two_images = original_documents.count(&:image?) > 1
submitter.documents.preload(:blob).reject do |attachment| submitter.documents.preload(:blob).reject do |attachment|
is_more_than_two_images && original_documents.find { |a| a.uuid == attachment.uuid }&.image? is_more_than_two_images &&
original_documents.find { |a| a.uuid == (attachment.metadata['original_uuid'] || attachment.uuid) }&.image?
end end
end end

Loading…
Cancel
Save