Merge from docusealco/wip

pull/440/head
Alex Turchyn 9 months ago committed by GitHub
commit 33cc0a8ab5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -49,7 +49,7 @@ jobs:
bundle config path vendor/bundle
bundle install --jobs 4 --retry 4
- name: Run Erblint
run: bundle exec erblint ./app
run: bundle exec erb_lint ./app
eslint:
name: ESLint

@ -327,7 +327,7 @@ GEM
mysql2 (0.5.6)
net-http-persistent (4.0.5)
connection_pool (~> 2.2)
net-imap (0.5.3)
net-imap (0.5.6)
date
net-protocol
net-pop (0.1.2)
@ -386,7 +386,7 @@ GEM
puma (6.5.0)
nio4r (~> 2.0)
racc (1.8.1)
rack (3.1.8)
rack (3.1.10)
rack-proxy (0.7.7)
rack
rack-session (2.0.0)

@ -0,0 +1,25 @@
# frozen_string_literal: true
class SubmissionEventsController < ApplicationController
SUBMISSION_EVENT_ICONS = {
'view_form' => 'eye',
'start_form' => 'player_play',
'complete_form' => 'check',
'send_email' => 'mail_forward',
'click_email' => 'hand_click',
'api_complete_form' => 'check',
'send_reminder_email' => 'mail_forward',
'send_2fa_sms' => '2fa',
'send_sms' => 'send',
'phone_verified' => 'phone_check',
'click_sms' => 'hand_click',
'decline_form' => 'x',
'start_verification' => 'player_play',
'complete_verification' => 'check',
'invite_party' => 'user_plus'
}.freeze
load_and_authorize_resource :submission
def index; end
end

@ -0,0 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg" class="<%= local_assigns[:class] %>" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" width="24" height="24" stroke-width="2">
<path d="M7 16h-4l3.47 -4.66a2 2 0 1 0 -3.47 -1.54"></path>
<path d="M10 16v-8h4"></path> <path d="M10 12l3 0"></path>
<path d="M17 16v-6a2 2 0 0 1 4 0v6"></path>
<path d="M17 13l4 0"></path>
</svg>

After

Width:  |  Height:  |  Size: 426 B

@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" class="<%= local_assigns[:class] %>" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M12 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" />
<path d="M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0" />
</svg>

After

Width:  |  Height:  |  Size: 397 B

@ -0,0 +1,10 @@
<svg xmlns="http://www.w3.org/2000/svg" class="<%= local_assigns[:class] %>" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" width="24" height="24" stroke-width="2">
<path d="M8 13v-8.5a1.5 1.5 0 0 1 3 0v7.5"></path>
<path d="M11 11.5v-2a1.5 1.5 0 0 1 3 0v2.5"></path>
<path d="M14 10.5a1.5 1.5 0 0 1 3 0v1.5"></path>
<path d="M17 11.5a1.5 1.5 0 0 1 3 0v4.5a6 6 0 0 1 -6 6h-2h.208a6 6 0 0 1 -5.012 -2.7l-.196 -.3c-.312 -.479 -1.407 -2.388 -3.286 -5.728a1.5 1.5 0 0 1 .536 -2.022a1.867 1.867 0 0 1 2.28 .28l1.47 1.47"></path>
<path d="M5 3l-1 -1"></path>
<path d="M4 7h-1"></path>
<path d="M14 3l1 -1"></path>
<path d="M15 6h1"></path>
</svg>

After

Width:  |  Height:  |  Size: 711 B

@ -0,0 +1,11 @@
<svg xmlns="http://www.w3.org/2000/svg" class="<%= local_assigns[:class] %>" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" width="24" height="24" stroke-width="2">
<path d="M4 12h.01"></path>
<path d="M4 6h.01"></path>
<path d="M4 18h.01"></path>
<path d="M8 18h2"></path>
<path d="M8 12h2"></path>
<path d="M8 6h2"></path>
<path d="M14 6h6"></path>
<path d="M14 12h6"></path>
<path d="M14 18h6"></path>
</svg>

After

Width:  |  Height:  |  Size: 484 B

@ -0,0 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" class="<%= local_assigns[:class] %>" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" width="24" height="24" stroke-width="2">
<path d="M5 4h4l2 5l-2.5 1.5a11 11 0 0 0 5 5l1.5 -2.5l5 2v4a2 2 0 0 1 -2 2a16 16 0 0 1 -15 -15a2 2 0 0 1 2 -2"></path>
<path d="M15 6l2 2l4 -4"></path>
</svg>

After

Width:  |  Height:  |  Size: 382 B

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" class="<%= local_assigns[:class] %>" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" width="24" height="24" stroke-width="2">
<path d="M7 4v16l13 -8z"></path>
</svg>

After

Width:  |  Height:  |  Size: 261 B

@ -0,0 +1,49 @@
<% event_colors = %w[bg-red-200 bg-sky-200 bg-emerald-200 bg-yellow-200 bg-purple-200 bg-pink-200 bg-cyan-200 bg-orange-200 bg-lime-200 bg-indigo-200] %>
<% submitters_uuids = (@submission.template_submitters || @submission.template.submitters).pluck('uuid') %>
<%= render 'shared/turbo_modal_large', title: t('event_log') do %>
<div class="pl-8 pr-4 py-4">
<ol class="relative border-s border-base-300 space-y-6">
<li class="ml-7">
<span class="absolute flex items-center justify-center w-7 h-7 rounded-full -start-3.5 ring-8 ring-base-100 text-base-content bg-gray-200">
<%= svg_icon('file_text', class: 'w-4 h-4') %>
</span>
<p class="text-sm leading-none text-base-content/60 pt-1.5">
<%= l(@submission.created_at.in_time_zone(current_account.timezone), format: :long, locale: current_account.locale) %>
</p>
<p class="text-base-content/80 mt-1">
<% if @submission.source == 'invite' %>
<%= t('submission_created_by_email_html', email: @submission.created_by_user.email) %>
<% elsif @submission.created_by_user %>
<%= t('submission_created_by_email_via_source_html', email: @submission.created_by_user.email, source: t("submission_sources.#{@submission.source}")) %>
<% else %>
<%= t('submission_created_via_source_html', source: t("submission_sources.#{@submission.source}")) %>
<% end %>
</p>
</li>
<% @submission.submission_events.order(:event_timestamp).each do |event| %>
<% submitter = @submission.submitters.find { |e| e.id == event.submitter_id } %>
<% bg_class = event_colors[submitters_uuids.index(submitter.uuid) % event_colors.length] %>
<% submitter_name = event.event_type.include?('sms') || event.event_type.include?('phone') ? (event.data['phone'] || submitter.phone) : (submitter.name || submitter.email || submitter.phone) %>
<li class="ml-7">
<span class="absolute flex items-center justify-center w-7 h-7 rounded-full -start-3.5 ring-8 ring-base-100 text-base-content <%= bg_class %>">
<%= svg_icon(SubmissionEventsController::SUBMISSION_EVENT_ICONS.fetch(event.event_type, 'circle_dot'), class: 'w-4 h-4') %>
</span>
<p class="text-sm leading-none text-base-content/60 pt-1.5">
<%= l(event.event_timestamp.in_time_zone(current_account.timezone), format: :long, locale: current_account.locale) %>
</p>
<p class="text-base-content/80 mt-1">
<% if event.event_type == 'complete_verification' %>
<%= t('submission_event_names.complete_verification_by_html', provider: event.data['method'], submitter_name:) %>
<% elsif event.event_type == 'invite_party' && (invited_submitter = @submission.submitters.find { |e| e.uuid == event.data['uuid'] }) && (name = @submission.template_submitters.find { |e| e['uuid'] == event.data['uuid'] }&.dig('name')) %>
<%= t('submission_event_names.invite_party_by_html', invited_submitter_name: [invited_submitter.name || invited_submitter.email || invited_submitter.phone, name].join(' '), submitter_name:) %>
<% elsif event.event_type.include?('send_') %>
<%= t("submission_event_names.#{event.event_type}_to_html", submitter_name:) %>
<% else %>
<%= t("submission_event_names.#{event.event_type}_by_html", submitter_name:) %>
<% end %>
</p>
</li>
<% end %>
</ol>
</div>
<% end %>

@ -37,13 +37,13 @@
<% config = AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_INVITATION_EMAIL_KEY) %>
<div id="message_field" class="card card-compact bg-base-300/40 hidden">
<div class="card-body">
<%= tag.input id: 'request_email_per_submitter', value: '1', name: 'request_email_per_submitter', class: 'peer', type: 'checkbox', hidden: true, checked: local_assigns[:message_per_submitter] != false && template.preferences['submitters'].to_a.size > 1 %>
<%= tag.input id: toggle_uuid = SecureRandom.uuid, value: '1', name: 'request_email_per_submitter', class: 'peer', type: 'checkbox', hidden: true, checked: local_assigns[:message_per_submitter] != false && template.preferences['submitters'].to_a.size > 1 %>
<div class="peer-checked:hidden form-control space-y-2">
<div class="form-control">
<div class="flex justify-between">
<%= f.label :subject, t('subject'), class: 'label' %>
<% if template.submitters.size > 1 && template.submitters.size < 5 && local_assigns[:message_per_submitter] != false %>
<label for="request_email_per_submitter" class="label underline">
<label for="<%= toggle_uuid %>" class="label underline">
<%= t('edit_per_party') %>
</label>
<% end %>
@ -71,7 +71,8 @@
</div>
<% if template.submitters.size > 1 && template.submitters.size < 5 && local_assigns[:message_per_submitter] != false %>
<div class="hidden peer-checked:block form-control space-y-2">
<% options = template.submitters.map { |e| [e['name'], "request_email_#{e['uuid']}"] } %>
<% uuid = SecureRandom.uuid %>
<% options = template.submitters.map { |e| [e['name'], "request_email_#{uuid}_#{e['uuid']}"] } %>
<toggle-visible data-element-ids="<%= options.map(&:last).to_json %>" class="flex relative px-1">
<ul class="tabs w-full flex flex-nowrap">
<% options.each_with_index do |(label, val), index| %>
@ -84,7 +85,7 @@
</toggle-visible>
<% template.submitters.each_with_index do |submitter, index| %>
<%= fields_for :submitter_preferences, nil, index: submitter['uuid'] do |ff| %>
<div id="request_email_<%= submitter['uuid'] %>" class="<%= 'hidden' if index != 0 %>">
<div id="request_email_<%= uuid %>_<%= submitter['uuid'] %>" class="<%= 'hidden' if index != 0 %>">
<div class="form-control">
<div class="flex justify-between">
<%= ff.label :subject, t('subject'), class: 'label' %>

@ -19,6 +19,11 @@
<%= svg_icon('external_link', class: 'w-6 h-6') %>
<span class="hidden md:inline"><%= t('audit_log') %></span>
</a>
<% else %>
<%= link_to submission_events_path(@submission), class: 'white-button', data: { turbo_frame: :modal } do %>
<%= svg_icon('logs', class: 'w-6 h-6') %>
<span class="hidden md:block"><%= t('event_log') %></span>
<% end %>
<% end %>
<% if last_submitter %>
<% if is_all_completed || !is_combined_enabled %>

@ -0,0 +1 @@
<%= render partial: 'submissions/annotation', collection: annots, as: :annot %>

@ -47,8 +47,8 @@
<div class="relative my-4 shadow-md">
<img loading="lazy" src="<%= page.url %>" width="<%= page.metadata['width'] %>" height="<%= page.metadata['height'] %>">
<div id="page-<%= [document.uuid, index].join('-') %>" class="top-0 bottom-0 left-0 right-0 absolute">
<% document_annots_index[index]&.each do |annot| %>
<%= render 'submissions/annotation', annot: %>
<% if annots = document_annots_index[index] %>
<%= render 'submit_form/annotations', annots: %>
<% end %>
<% fields_index.dig(document.uuid, index)&.each do |(area, field)| %>
<% value = values[field['uuid']].presence || (field['default_value'].present? ? Submitters::SubmitValues.template_default_value_for_submitter(field['default_value'], @submitter.submission.submitters.find { |e| e.uuid == field['submitter_uuid'] }, with_time: false) : nil) %>

@ -695,6 +695,17 @@ en: &en
overdue_payment: Overdue Payment
your_pro_plan_has_been_suspended_due_to_unpaid_invoices_you_can_update_your_payment_details_to_settle_the_invoice_and_continue_using_docuseal_or_cancel_your_subscription: Your Pro Plan has been suspended due to unpaid invoices. You can update your payment details to settle the invoice and continue using DocuSeal or cancel your subscription.
manage_subscription: Manage Subscription
submission_created_by_email_html: '<b>Submission created</b> by %{email}'
submission_created_by_email_via_source_html: '<b>Submission created</b> by %{email} via %{source}'
submission_created_via_source_html: '<b>Submission created</b> via %{source}'
pro_user_seats_used: Pro user seats used
manage_plan: Manage plan
submission_sources:
api: API
bulk: Bulk Send
embed: Embedding
invie: Invite
link: Link
submission_event_names:
send_email_to_html: '<b>Email sent</b> to %{submitter_name}'
send_reminder_email_to_html: '<b>Reminder email sent</b> to %{submitter_name}'
@ -1410,6 +1421,17 @@ es: &es
overdue_payment: Pago Atrasado
your_pro_plan_has_been_suspended_due_to_unpaid_invoices_you_can_update_your_payment_details_to_settle_the_invoice_and_continue_using_docuseal_or_cancel_your_subscription: Tu plan Pro ha sido suspendido debido a facturas impagas. Puedes actualizar tus datos de pago para liquidar la factura y seguir usando DocuSeal o cancelar tu suscripción.
manage_subscription: Gestionar Suscripción
submission_created_by_email_html: '<b>Envío creado</b> por %{email}'
submission_created_by_email_via_source_html: '<b>Envío creado</b> por %{email} a través de %{source}'
submission_created_via_source_html: '<b>Envío creado</b> a través de %{source}'
pro_user_seats_used: Plazas de usuario Pro en uso
manage_plan: Gestionar plan
submission_sources:
api: API
bulk: Envío masivo
embed: Integración
invite: Invitación
link: Enlace
submission_event_names:
send_email_to_html: '<b>Correo electrónico enviado</b> a %{submitter_name}'
send_reminder_email_to_html: '<b>Correo de recordatorio enviado</b> a %{submitter_name}'
@ -2124,6 +2146,17 @@ it: &it
overdue_payment: Pagamento Scaduto
your_pro_plan_has_been_suspended_due_to_unpaid_invoices_you_can_update_your_payment_details_to_settle_the_invoice_and_continue_using_docuseal_or_cancel_your_subscription: Il tuo piano Pro è stato sospeso a causa di fatture non pagate. Puoi aggiornare i tuoi dati di pagamento per saldare la fattura e continuare a utilizzare DocuSeal o annullare l'abbonamento.
manage_subscription: Gestisci Abbonamento
submission_created_by_email_html: '<b>Invio creato</b> da %{email}'
submission_created_by_email_via_source_html: '<b>Invio creato</b> da %{email} tramite %{source}'
submission_created_via_source_html: '<b>Invio creato</b> tramite %{source}'
pro_user_seats_used: Posti utente Pro in uso
manage_plan: Gestisci piano
submission_sources:
api: API
bulk: Invio massivo
embed: Incorporamento
invite: Invito
link: Link
submission_event_names:
send_email_to_html: '<b>E-mail inviato</b> a %{submitter_name}'
send_reminder_email_to_html: '<b>E-mail di promemoria inviato</b> a %{submitter_name}'
@ -2840,6 +2873,17 @@ fr: &fr
overdue_payment: Paiement En Retard
your_pro_plan_has_been_suspended_due_to_unpaid_invoices_you_can_update_your_payment_details_to_settle_the_invoice_and_continue_using_docuseal_or_cancel_your_subscription: Votre plan Pro a été suspendu en raison de factures impayées. Vous pouvez mettre à jour vos informations de paiement pour régler la facture et continuer à utiliser DocuSeal ou annuler votre abonnement.
manage_subscription: Gérer l'Abonnement
submission_created_by_email_html: '<b>Soumission créée</b> par %{email}'
submission_created_by_email_via_source_html: '<b>Soumission créée</b> par %{email} via %{source}'
submission_created_via_source_html: '<b>Soumission créée</b> via %{source}'
pro_user_seats_used: Places utilisateur Pro en cours d'utilisation
manage_plan: Gérer le plan
submission_sources:
api: API
bulk: Envoi en masse
embed: Intégration
invite: Invitation
link: Lien
submission_event_names:
send_email_to_html: '<b>E-mail envoyé</b> à %{submitter_name}'
send_reminder_email_to_html: '<b>E-mail de rappel envoyé</b> à %{submitter_name}'
@ -3555,6 +3599,17 @@ pt: &pt
overdue_payment: Pagamento Atrasado
your_pro_plan_has_been_suspended_due_to_unpaid_invoices_you_can_update_your_payment_details_to_settle_the_invoice_and_continue_using_docuseal_or_cancel_your_subscription: Seu plano Pro foi suspenso devido a faturas não pagas. Você pode atualizar seus dados de pagamento para quitar a fatura e continuar usando o DocuSeal ou cancelar sua assinatura.
manage_subscription: Gerenciar Assinatura
submission_created_by_email_html: '<b>Envio criado</b> por %{email}'
submission_created_by_email_via_source_html: '<b>Envio criado</b> por %{email} via %{source}'
submission_created_via_source_html: '<b>Envio criado</b> via %{source}'
pro_user_seats_used: Lugares de usuário Pro em uso
manage_plan: Gerenciar plano
submission_sources:
api: API
bulk: Envio em massa
embed: Incorporação
invite: Convite
link: Link
submission_event_names:
send_email_to_html: '<b>E-mail enviado</b> para %{submitter_name}'
send_reminder_email_to_html: '<b>E-mail de lembrete enviado</b> para %{submitter_name}'
@ -4270,6 +4325,17 @@ de: &de
overdue_payment: Überfällige Zahlung
your_pro_plan_has_been_suspended_due_to_unpaid_invoices_you_can_update_your_payment_details_to_settle_the_invoice_and_continue_using_docuseal_or_cancel_your_subscription: Ihr Pro-Plan wurde aufgrund unbezahlter Rechnungen ausgesetzt. Sie können Ihre Zahlungsdaten aktualisieren, um die Rechnung zu begleichen und DocuSeal weiterhin zu nutzen, oder Ihr Abonnement kündigen.
manage_subscription: Abonnement Verwalten
submission_created_by_email_html: '<b>Übermittlung erstellt</b> von %{email}'
submission_created_by_email_via_source_html: '<b>Übermittlung erstellt</b> durch %{email} über %{source}'
submission_created_via_source_html: '<b>Übermittlung erstellt</b> über %{source}'
pro_user_seats_used: Verwendete Pro-Benutzerplätze
manage_plan: Plan verwalten
submission_sources:
api: API
bulk: Massenversand
embed: Einbettung
invite: Einladung
link: Link
submission_event_names:
send_email_to_html: '<b>E-Mail gesendet</b> an %{submitter_name}'
send_reminder_email_to_html: '<b>Erinnerungs-E-Mail gesendet</b> an %{submitter_name}'

@ -72,6 +72,7 @@ Rails.application.routes.draw do
resources :submissions, only: %i[index], controller: 'submissions_dashboard'
resources :submissions, only: %i[show destroy] do
resources :unarchive, only: %i[create], controller: 'submissions_unarchive'
resources :events, only: %i[index], controller: 'submission_events'
end
resources :submitters, only: %i[edit update]
resources :console_redirect, only: %i[index]

@ -23,9 +23,15 @@ module Submissions
**Submissions::GenerateResultAttachments.build_signing_params(submitter, pkcs, tsa_url)
}
pdf.sign(io, **sign_params)
begin
pdf.sign(io, **sign_params)
rescue HexaPDF::MalformedPDFError => e
Rollbar.error(e) if defined?(Rollbar)
pdf.sign(io, write_options: { incremental: false }, **sign_params)
end
else
pdf.write(io)
pdf.write(io, incremental: true, validate: false)
end
Submissions::GenerateResultAttachments.maybe_enable_ltv(io, sign_params)

@ -23,6 +23,7 @@ module Submissions
A4_SIZE = [595, 842].freeze
TESTING_FOOTER = 'Testing Document - NOT LEGALLY BINDING'
DEFAULT_FONTS = %w[Times Helvetica Courier].freeze
MISSING_GLYPH_REPLACE = {
'▪' => '-',
@ -190,7 +191,8 @@ module Submissions
fill_color = field.dig('preferences', 'color').presence
font_name = field.dig('preferences', 'font').presence || FONT_NAME
font_name = field.dig('preferences', 'font')
font_name = FONT_NAME unless font_name.in?(DEFAULT_FONTS)
font = pdf.fonts.add(font_name)
value = submitter.values[field['uuid']]

@ -32,6 +32,7 @@ module Templates
template
end
# rubocop:disable Metrics, Style/CombinableLoops
def update_submitters_and_fields_and_schema(cloned_submitters, cloned_fields, cloned_schema)
submitter_uuids_replacements = {}
field_uuids_replacements = {}
@ -43,6 +44,20 @@ module Templates
submitter['uuid'] = new_submitter_uuid
end
cloned_submitters.each do |submitter|
if submitter['optional_invite_by_uuid'].present?
submitter['optional_invite_by_uuid'] = submitter_uuids_replacements[submitter['optional_invite_by_uuid']]
end
if submitter['invite_by_uuid'].present?
submitter['invite_by_uuid'] = submitter_uuids_replacements[submitter['invite_by_uuid']]
end
if submitter['linked_to_uuid'].present?
submitter['linked_to_uuid'] = submitter_uuids_replacements[submitter['linked_to_uuid']]
end
end
cloned_fields.each do |field|
new_field_uuid = SecureRandom.uuid
@ -75,5 +90,6 @@ module Templates
[cloned_submitters, cloned_fields, cloned_schema]
end
# rubocop:enable Metrics, Style/CombinableLoops
end
end

@ -9,6 +9,7 @@ FactoryBot.define do
transient do
submitter_count { 1 }
attachment_count { 1 }
only_field_types do
%w[text date checkbox radio signature number multiple select initials image file stamp cells phone payment]
end
@ -16,20 +17,6 @@ FactoryBot.define do
end
after(:create) do |template, ev|
blob = ActiveStorage::Blob.create_and_upload!(
io: Rails.root.join('spec/fixtures/sample-document.pdf').open,
filename: 'sample-document.pdf',
content_type: 'application/pdf'
)
attachment = ActiveStorage::Attachment.create!(
blob:,
name: :documents,
record: template
)
Templates::ProcessDocument.call(attachment, attachment.download)
template.schema = [{ attachment_uuid: attachment.uuid, name: 'sample-document' }]
number_words = %w[first second third fourth fifth sixth seventh eighth ninth tenth]
template.submitters = Array.new(ev.submitter_count) do |i|
@ -39,296 +26,319 @@ FactoryBot.define do
}
end
template.fields = template.submitters.reduce([]) do |fields, submitter|
fields += [
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'First Name',
'type' => 'text',
'required' => true,
'preferences' => {},
'areas' => [
{
'x' => 0.09273546006944444,
'y' => 0.1099851117387033,
'w' => 0.2701497395833333,
'h' => 0.0372705365913556,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'Birthday',
'type' => 'date',
'required' => true,
'preferences' => { 'format' => 'DD/MM/YYYY' },
'areas' => [
{
'x' => 0.09166666666666666,
'y' => 0.1762778204144282,
'w' => 0.2763888888888889,
'h' => 0.0359029261474578,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'Do you agree?',
'type' => 'checkbox',
'required' => true,
'preferences' => {},
'areas' => [
{
'x' => 0.09051106770833334,
'y' => 0.227587027259332,
'w' => 0.2784450954861111,
'h' => 0.04113074042239687,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'First child',
'type' => 'radio',
'required' => true,
'preferences' => {},
'options' => [
{ 'value' => 'Girl', 'uuid' => SecureRandom.uuid },
{ 'value' => 'Boy', 'uuid' => SecureRandom.uuid }
],
'areas' => [
{
'x' => 0.09027777777777778,
'y' => 0.3020184190330008,
'w' => 0.2,
'h' => 0.02857142857142857,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'Signature',
'type' => 'signature',
'required' => true,
'preferences' => {},
'areas' => [
{
'x' => 0.08611111111111111,
'y' => 0.3487183422870299,
'w' => 0.2,
'h' => 0.0707269155206287,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'House number',
'type' => 'number',
'required' => true,
'preferences' => {},
'areas' => [
{
'x' => 0.08333333333333333,
'y' => 0.4582041442824252,
'w' => 0.2,
'h' => 0.02857142857142857,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'Colors',
'type' => 'multiple',
'required' => true,
'preferences' => {},
'options' => [
{ 'value' => 'Red', 'uuid' => SecureRandom.uuid },
{ 'value' => 'Green', 'uuid' => SecureRandom.uuid },
{ 'value' => 'Blue', 'uuid' => SecureRandom.uuid }
],
'areas' => [
{
'x' => 0.45,
'y' => 0.1133998465080583,
'w' => 0.2,
'h' => 0.02857142857142857,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'Gender',
'type' => 'select',
'required' => true,
'preferences' => {},
'options' => [
{ 'value' => 'Male', 'uuid' => SecureRandom.uuid },
{ 'value' => 'Female', 'uuid' => SecureRandom.uuid }
],
'areas' => [
{
'x' => 0.4513888888888889,
'y' => 0.1752954719877206,
'w' => 0.2,
'h' => 0.02857142857142857,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'Initials',
'type' => 'initials',
'required' => true,
'preferences' => {},
'areas' => [
{
'x' => 0.4486111111111111,
'y' => 0.2273599386032233,
'w' => 0.1,
'h' => 0.02857142857142857,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'Avatar',
'type' => 'image',
'required' => true,
'preferences' => {},
'areas' => [
{
'x' => 0.7180555555555556,
'y' => 0.1129547198772064,
'w' => 0.2,
'h' => 0.1414538310412574,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'Attachment',
'type' => 'file',
'required' => true,
'preferences' => {},
'areas' => [
{
'x' => 0.7166666666666667,
'y' => 0.3020107444359171,
'w' => 0.2,
'h' => 0.02857142857142857,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'Stamp',
'type' => 'stamp',
'required' => true,
'readonly' => true,
'preferences' => {},
'areas' => [
{
'x' => 0.7166666666666667,
'y' => 0.3771910974673829,
'w' => 0.2,
'h' => 0.0707269155206287,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'Cell code',
'type' => 'cells',
'required' => true,
'preferences' => {},
'areas' => [
{
'x' => 0.4472222222222222,
'y' => 0.3530851880276286,
'w' => 0.2,
'h' => 0.02857142857142857,
'cell_w' => 0.04,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'Payment',
'type' => 'payment',
'required' => true,
'preferences' => { 'currency' => 'EUR', 'price' => 1000 },
'areas' => [
{
'x' => 0.4486111111111111,
'y' => 0.43168073676132,
'w' => 0.2,
'h' => 0.02857142857142857,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => 'Mobile Phone',
'type' => 'phone',
'required' => true,
'preferences' => {},
'areas' => [
{
'x' => 0.44443359375,
'y' => 0.3010283960092095,
'w' => 0.2,
'h' => 0.02857142857142857,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
}
].select { |f| ev.only_field_types.include?(f['type']) && ev.except_field_types.exclude?(f['type']) }
ev.attachment_count.times do |i|
attachment_index = i + 1 if i > 0
field_index = "(#{attachment_index})" if attachment_index
blob = ActiveStorage::Blob.create_and_upload!(
io: Rails.root.join('spec/fixtures/sample-document.pdf').open,
filename: 'sample-document.pdf',
content_type: 'application/pdf'
)
attachment = ActiveStorage::Attachment.create!(
blob:,
name: :documents,
record: template
)
Templates::ProcessDocument.call(attachment, attachment.download)
template.schema << {
attachment_uuid: attachment.uuid,
name: ['sample-document', attachment_index].compact.join('-')
}
template.fields += template.submitters.reduce([]) do |fields, submitter|
fields += [
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => ['First Name', field_index].compact.join(' '),
'type' => 'text',
'required' => true,
'preferences' => {},
'areas' => [
{
'x' => 0.09273546006944444,
'y' => 0.1099851117387033,
'w' => 0.2701497395833333,
'h' => 0.0372705365913556,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => ['Birthday', field_index].compact.join(' '),
'type' => 'date',
'required' => true,
'preferences' => { 'format' => 'DD/MM/YYYY' },
'areas' => [
{
'x' => 0.09166666666666666,
'y' => 0.1762778204144282,
'w' => 0.2763888888888889,
'h' => 0.0359029261474578,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => ['Do you agree?', field_index].compact.join(' '),
'type' => 'checkbox',
'required' => true,
'preferences' => {},
'areas' => [
{
'x' => 0.09051106770833334,
'y' => 0.227587027259332,
'w' => 0.2784450954861111,
'h' => 0.04113074042239687,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => ['First child', field_index].compact.join(' '),
'type' => 'radio',
'required' => true,
'preferences' => {},
'options' => [
{ 'value' => 'Girl', 'uuid' => SecureRandom.uuid },
{ 'value' => 'Boy', 'uuid' => SecureRandom.uuid }
],
'areas' => [
{
'x' => 0.09027777777777778,
'y' => 0.3020184190330008,
'w' => 0.2,
'h' => 0.02857142857142857,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => ['Signature', field_index].compact.join(' '),
'type' => 'signature',
'required' => true,
'preferences' => {},
'areas' => [
{
'x' => 0.08611111111111111,
'y' => 0.3487183422870299,
'w' => 0.2,
'h' => 0.0707269155206287,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => ['House number', field_index].compact.join(' '),
'type' => 'number',
'required' => true,
'preferences' => {},
'areas' => [
{
'x' => 0.08333333333333333,
'y' => 0.4582041442824252,
'w' => 0.2,
'h' => 0.02857142857142857,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => ['Colors', field_index].compact.join(' '),
'type' => 'multiple',
'required' => true,
'preferences' => {},
'options' => [
{ 'value' => 'Red', 'uuid' => SecureRandom.uuid },
{ 'value' => 'Green', 'uuid' => SecureRandom.uuid },
{ 'value' => 'Blue', 'uuid' => SecureRandom.uuid }
],
'areas' => [
{
'x' => 0.45,
'y' => 0.1133998465080583,
'w' => 0.2,
'h' => 0.02857142857142857,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => ['Gender', field_index].compact.join(' '),
'type' => 'select',
'required' => true,
'preferences' => {},
'options' => [
{ 'value' => 'Male', 'uuid' => SecureRandom.uuid },
{ 'value' => 'Female', 'uuid' => SecureRandom.uuid }
],
'areas' => [
{
'x' => 0.4513888888888889,
'y' => 0.1752954719877206,
'w' => 0.2,
'h' => 0.02857142857142857,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => ['Initials', field_index].compact.join(' '),
'type' => 'initials',
'required' => true,
'preferences' => {},
'areas' => [
{
'x' => 0.4486111111111111,
'y' => 0.2273599386032233,
'w' => 0.1,
'h' => 0.02857142857142857,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => ['Avatar', field_index].compact.join(' '),
'type' => 'image',
'required' => true,
'preferences' => {},
'areas' => [
{
'x' => 0.7180555555555556,
'y' => 0.1129547198772064,
'w' => 0.2,
'h' => 0.1414538310412574,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => ['Attachment', field_index].compact.join(' '),
'type' => 'file',
'required' => true,
'preferences' => {},
'areas' => [
{
'x' => 0.7166666666666667,
'y' => 0.3020107444359171,
'w' => 0.2,
'h' => 0.02857142857142857,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => ['Stamp', field_index].compact.join(' '),
'type' => 'stamp',
'required' => true,
'readonly' => true,
'preferences' => {},
'areas' => [
{
'x' => 0.7166666666666667,
'y' => 0.3771910974673829,
'w' => 0.2,
'h' => 0.0707269155206287,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => ['Cell code', field_index].compact.join(' '),
'type' => 'cells',
'required' => true,
'preferences' => {},
'areas' => [
{
'x' => 0.4472222222222222,
'y' => 0.3530851880276286,
'w' => 0.2,
'h' => 0.02857142857142857,
'cell_w' => 0.04,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => ['Payment', field_index].compact.join(' '),
'type' => 'payment',
'required' => true,
'preferences' => { 'currency' => 'EUR', 'price' => 1000 },
'areas' => [
{
'x' => 0.4486111111111111,
'y' => 0.43168073676132,
'w' => 0.2,
'h' => 0.02857142857142857,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
},
{
'uuid' => SecureRandom.uuid,
'submitter_uuid' => submitter['uuid'],
'name' => ['Mobile Phone', field_index].compact.join(' '),
'type' => 'phone',
'required' => true,
'preferences' => {},
'areas' => [
{
'x' => 0.44443359375,
'y' => 0.3010283960092095,
'w' => 0.2,
'h' => 0.02857142857142857,
'attachment_uuid' => attachment.uuid,
'page' => 0
}
]
}
].select { |f| ev.only_field_types.include?(f['type']) && ev.except_field_types.exclude?(f['type']) }
fields
fields
end
end
template.save!

Loading…
Cancel
Save