add pdf generation

This commit is contained in:
Alex Turchyn
2023-05-28 23:20:48 +03:00
parent 170cb1ecea
commit 6a41f82e5b
21 changed files with 383 additions and 49 deletions
@@ -5,13 +5,14 @@ module Api
skip_before_action :authenticate_user!
def create
submission = Submission.find_by!(slug: params[:submission_slug])
submission = Submission.find_by!(slug: params[:submission_slug]) unless current_account
blob = ActiveStorage::Blob.find_signed(params[:blob_signed_id])
attachment = ActiveStorage::Attachment.create!(
blob:,
name: params[:name],
record: submission
record: submission || current_account
)
render json: attachment.as_json(only: %i[uuid], methods: %i[url filename content_type])
@@ -0,0 +1,26 @@
# frozen_string_literal: true
class EsignSettingsController < ApplicationController
before_action :load_encrypted_config
def create
attachment = ActiveStorage::Attachment.find_by!(uuid: params[:attachment_uuid])
pdf = HexaPDF::Document.new(io: StringIO.new(attachment.download))
pdf.signatures
end
private
def load_encrypted_config
@encrypted_config =
EncryptedConfig.find_or_initialize_by(account: current_account, key: EncryptedConfig::ESIGN_CERTS_KEY)
end
def storage_configs
params.require(:encrypted_config).permit(value: {}).tap do |e|
e[:value].compact_blank!
end
end
end
+3
View File
@@ -17,6 +17,9 @@ class SetupController < ApplicationController
@user = @account.users.new(user_params)
if @user.save
@account.encrypted_configs.create!(key: EncryptedConfig::ESIGN_CERTS_KEY,
value: GenerateCertificate.call)
sign_in(@user)
redirect_to root_path
@@ -0,0 +1,27 @@
# frozen_string_literal: true
class SubmissionsDebugController < ApplicationController
layout 'flow'
skip_before_action :authenticate_user!
def index
@submission = Submission.preload({ attachments_attachments: :blob },
flow: { documents_attachments: :blob })
.find_by(slug: params[:submission_slug])
respond_to do |f|
f.html do
render 'submit_flow/show'
end
f.pdf do
Submissions::GenerateResultAttachments.call(@submission)
send_data ActiveStorage::Attachment.where(name: :documents).last.download,
filename: 'debug.pdf',
disposition: 'inline',
type: 'application/pdf'
end
end
end
end