Compare commits

..
21 Commits
Author SHA1 Message Date
Pete Matsyburka 16e5c13633 fix erblint 2024-07-01 08:05:09 +03:00
Pete Matsyburka fff1831768 add gpt link 2024-06-30 16:21:19 +03:00
Pete Matsyburka f91a318e94 fix drawer 2024-06-29 20:10:28 +03:00
Pete Matsyburka ed06e17b23 adjust field attrs 2024-06-29 11:29:59 +03:00
Pete Matsyburka 63e1be7dfe remove border 2024-06-29 08:52:16 +03:00
Pete Matsyburka 16044612bd fix form fields 2024-06-29 08:44:19 +03:00
Pete Matsyburka 27d8880414 border alert 2024-06-29 00:04:10 +03:00
Pete Matsyburka a0aae6a9de add currencies 2024-06-28 23:34:15 +03:00
Alex Turchyn 749043dfbb process acro form fields 2024-06-28 21:42:39 +03:00
Pete Matsyburka 320fe02e35 remove upload signature button from drawn type 2024-06-28 16:56:51 +03:00
Pete Matsyburka 6f4b9d4a4e double click on builder checkbox 2024-06-28 16:28:37 +03:00
Pete Matsyburka a589cf9471 focus field input 2024-06-27 17:41:08 +03:00
Pete Matsyburka 7fc7283191 copy and paste fields 2024-06-27 15:14:39 +03:00
Pete Matsyburka af03560494 add radio select default value settings 2024-06-27 13:11:48 +03:00
Pete Matsyburka 988d1b93a5 double click to toggle signing date 2024-06-27 12:40:10 +03:00
Pete Matsyburka ab0278198a adjust phone step 2024-06-26 16:18:33 +03:00
Pete Matsyburka fbc649ab59 add extra links 2024-06-26 13:34:47 +03:00
Pete Matsyburka 6b5adc2504 select us date format 2024-06-25 21:49:44 +03:00
Pete Matsyburka 7c4307ef10 fix query 2024-06-25 21:11:48 +03:00
Pete Matsyburka de744e2f6c adjust invite email 2024-06-25 19:05:50 +03:00
Pete Matsyburka c171597c7f adjust max retries 2024-06-25 08:45:38 +03:00
26 changed files with 562 additions and 44 deletions

No files matched your search

@@ -10,7 +10,7 @@ class TemplateDocumentsController < ApplicationController
old_fields_hash = @template.fields.hash
documents = Templates::CreateAttachments.call(@template, params)
documents = Templates::CreateAttachments.call(@template, params, extract_fields: true)
schema = documents.map do |doc|
{ attachment_uuid: doc.uuid, name: doc.filename.base }
@@ -0,0 +1,33 @@
# frozen_string_literal: true
class TemplatesDebugController < ApplicationController
load_and_authorize_resource :template
def show
attachment = @template.documents.first
pdf = HexaPDF::Document.new(io: StringIO.new(attachment.download))
fields = Templates::FindAcroFields.call(pdf, attachment)
attachment.metadata['pdf'] ||= {}
attachment.metadata['pdf']['fields'] = fields
@template.update!(fields: Templates::ProcessDocument.normalize_attachment_fields(@template, [attachment]))
ActiveRecord::Associations::Preloader.new(
records: [@template],
associations: [schema_documents: { preview_images_attachments: :blob }]
).call
@template_data =
@template.as_json.merge(
documents: @template.schema_documents.as_json(
methods: %i[metadata signed_uuid],
include: { preview_images: { methods: %i[url metadata filename] } }
)
).to_json
render 'templates/edit', layout: 'plain'
end
end
@@ -12,11 +12,14 @@ class TemplatesUploadsController < ApplicationController
save_template!(@template, url_params)
documents = Templates::CreateAttachments.call(@template, url_params || params)
documents = Templates::CreateAttachments.call(@template, url_params || params, extract_fields: true)
schema = documents.map { |doc| { attachment_uuid: doc.uuid, name: doc.filename.base } }
@template.update!(schema:)
fields = Templates::ProcessDocument.normalize_attachment_fields(@template, documents)
schema.each { |item| item['pending_fields'] = true } if fields.present?
@template.update!(schema:, fields:)
SendTemplateCreatedWebhookRequestJob.perform_async('template_id' => @template.id)
+8 -3
View File
@@ -697,6 +697,7 @@ export default {
isFormVisible: this.expand !== false,
showFillAllRequiredFields: false,
currentStep: 0,
enableScrollIntoField: true,
phoneVerifiedValues: {},
orientation: screen?.orientation?.type,
isSubmitting: false,
@@ -992,10 +993,12 @@ export default {
if (!this.isCompleted) {
if (scrollToArea) {
this.scrollIntoField(step[0])
this.$refs.form.querySelector('input[type="date"], input[type="number"], input[type="text"], select')?.focus()
}
this.enableScrollIntoField = false
this.$refs.form.querySelector('input[type="date"], input[type="number"], input[type="text"], select')?.focus()
this.enableScrollIntoField = true
if (clickUpload && !this.values[this.currentField.uuid] && ['file', 'image'].includes(this.currentField.type)) {
this.$refs.form.querySelector('input[type="file"]')?.click()
}
@@ -1028,7 +1031,9 @@ export default {
}
},
scrollIntoField (field) {
return this.$refs.areas.scrollIntoField(field)
if (this.enableScrollIntoField) {
return this.$refs.areas.scrollIntoField(field)
}
},
scrollIntoArea (area) {
return this.$refs.areas.scrollIntoArea(area)
+13
View File
@@ -11,6 +11,7 @@ const en = {
number: 'Number',
image: 'Image',
take_photo: 'Take photo',
number_phone_is_invalid: '{number} phone is invalid',
file: 'File',
select: 'Select',
checkbox: 'Checkbox',
@@ -85,6 +86,7 @@ const es = {
file: 'Archivo',
select: 'Seleccionar',
checkbox: 'Casilla',
number_phone_is_invalid: '{number} teléfono es inválido',
multiple: 'Múltiple',
radio: 'Radio',
cells: 'Celdas',
@@ -160,6 +162,7 @@ const it = {
cells: 'Celle',
stamp: 'Timbro',
payment: 'Pagamento',
number_phone_is_invalid: '{number} telefono non è valido',
phone: 'Telefono',
submit_form: 'Invia Modulo',
sign_now: 'Firma ora',
@@ -230,6 +233,7 @@ const de = {
cells: 'Zellen',
stamp: 'Stempel',
payment: 'Zahlung',
number_phone_is_invalid: '{number} Telefonnummer ist ungültig',
phone: 'Telefon',
submit_form: 'Formular absenden',
sign_now: 'Jetzt unterschreiben',
@@ -300,6 +304,7 @@ const fr = {
cells: 'Cellules',
stamp: 'Tampon',
payment: 'Paiement',
number_phone_is_invalid: '{number} téléphone est invalide',
phone: 'Téléphone',
submit_form: 'Envoyer le Formulaire',
sign_now: 'Signer maintenant',
@@ -370,6 +375,7 @@ const pl = {
cells: 'Komórki',
stamp: 'Pieczątka',
payment: 'Płatność',
number_phone_is_invalid: '{number} telefon jest nieprawidłowy',
phone: 'Telefon',
submit_form: 'Wyślij Formularz',
sign_now: 'Podpisz teraz',
@@ -440,6 +446,7 @@ const uk = {
cells: 'Клітинки',
stamp: 'Штамп',
payment: 'Платіж',
number_phone_is_invalid: '{number} телефон недійсний',
phone: 'Телефон',
submit_form: 'Надіслати Форму',
sign_now: 'Підписати зараз',
@@ -511,6 +518,7 @@ const cs = {
stamp: 'Razítko',
payment: 'Platba',
phone: 'Telefon',
number_phone_is_invalid: '{number} telefon je neplatný',
submit_form: 'Odeslat formulář',
sign_now: 'Podepsat nyní',
type_here_: 'Zadejte zde',
@@ -580,6 +588,7 @@ const pt = {
cells: 'Células',
stamp: 'Carimbo',
payment: 'Pagamento',
number_phone_is_invalid: '{number} telefone é inválido',
phone: 'Telefone',
submit_form: 'Enviar Formulário',
sign_now: 'Assinar agora',
@@ -651,6 +660,7 @@ const he = {
stamp: 'חותמת',
payment: 'תשלום',
phone: 'טלפון',
number_phone_is_invalid: '{number} טלפון אינו חוקי',
submit_form: 'שלח טופס',
sign_now: 'חתום כעת',
type_here_: 'הקלד כאן',
@@ -723,6 +733,7 @@ const nl = {
stamp: 'Stempel',
payment: 'Betaling',
phone: 'Telefoon',
number_phone_is_invalid: '{number} telefoon is ongeldig',
submit_form: 'Formulier verzenden',
sign_now: 'Nu ondertekenen',
type_here_: 'Typ hier...',
@@ -794,6 +805,7 @@ const ar = {
minimize: 'تصغير',
payment: 'الدفع',
phone: 'هاتف',
number_phone_is_invalid: '{number} هاتف غير صالح',
submit_form: 'إرسال النموذج',
sign_now: 'وقع الآن',
type_here_: 'اكتب هنا',
@@ -865,6 +877,7 @@ const ko = {
minimize: '최소화',
payment: '결제',
phone: '전화',
number_phone_is_invalid: '{number} 전화번호가 유효하지 않습니다',
submit_form: '양식 제출',
sign_now: '지금 서명',
type_here_: '여기에 입력...',
+13 -5
View File
@@ -174,6 +174,14 @@ export default {
phone: this.$refs.phone.value
}),
headers: { 'Content-Type': 'application/json' }
}).then(async (resp) => {
if (resp.status === 422) {
const data = await resp.json()
alert(this.t('number_phone_is_invalid').replace('{number}', this.$refs.phone.value))
return Promise.reject(new Error(data.error))
}
})
},
async submit () {
@@ -186,13 +194,13 @@ export default {
return Promise.reject(new Error('phone invalid'))
} else if (!this.isCodeSent) {
this.sendVerificationCode()
return this.sendVerificationCode().then(() => {
this.$emit('update:model-value', this.$refs.phone.value)
this.$emit('update:model-value', this.$refs.phone.value)
this.isCodeSent = true
this.isCodeSent = true
return Promise.reject(new Error('verify with code'))
return Promise.reject(new Error('verify with code'))
})
} else {
return Promise.resolve({})
}
@@ -54,7 +54,7 @@
</a>
</span>
<span
v-if="field.preferences?.format !== 'typed'"
v-if="field.preferences?.format !== 'typed' && field.preferences?.format !== 'drawn'"
class="tooltip"
:data-tip="t('take_photo')"
>
+47 -7
View File
@@ -164,16 +164,16 @@
<span
v-if="field"
class="flex justify-center items-center space-x-1 h-full"
:class="{'w-full h-full': field.type == 'checkbox'}"
:class="{ 'w-full h-full': ['cells', 'checkbox'].includes(field.type) }"
>
<div
v-if="isDefaultValuePresent || isContenteditable"
:class="{ 'w-full h-full': field.type == 'checkbox', 'text-[1.5vw] lg:text-base': !textOverflowChars, 'text-[1.0vw] lg:text-xs': textOverflowChars }"
:class="{ 'w-full h-full': ['cells', 'checkbox'].includes(field.type), 'text-[1.5vw] lg:text-base': !textOverflowChars, 'text-[1.0vw] lg:text-xs': textOverflowChars }"
>
<div
ref="textContainer"
class="flex items-center px-0.5"
:class="{'w-full h-full': field.type == 'checkbox'}"
:class="{ 'w-full h-full': ['cells', 'checkbox'].includes(field.type) }"
>
<IconCheck
v-if="field.type == 'checkbox'"
@@ -184,6 +184,24 @@
v-else-if="field.type === 'number' && !isContenteditable"
class="whitespace-pre-wrap"
>{{ formatNumber(field.default_value, field.preferences?.format) }}</span>
<span
v-else-if="field.default_value === '{{date}}'"
>
{{ t('signing_date') }}
</span>
<div
v-else-if="field.type === 'cells' && field.default_value"
class="w-full flex items-center"
>
<div
v-for="(char, index) in field.default_value"
:key="index"
class="text-center flex-none"
:style="{ width: (area.cell_w / area.w * 100) + '%' }"
>
{{ char }}
</div>
</div>
<span
v-else
ref="defaultValue"
@@ -211,7 +229,7 @@
ref="touchTarget"
class="absolute top-0 bottom-0 right-0 left-0"
:class="isDragged ? 'cursor-grab' : 'cursor-pointer'"
@dblclick="maybeFocusDefaultValue"
@dblclick="maybeToggleDefaultValue"
/>
<span
v-if="field?.type && editable"
@@ -330,7 +348,11 @@ export default {
fieldNames: FieldType.computed.fieldNames,
fieldIcons: FieldType.computed.fieldIcons,
isDefaultValuePresent () {
return this.field?.default_value || this.field?.default_value === 0
if (this.field?.type === 'radio' && this.field?.areas?.length > 1) {
return false
} else {
return this.field?.default_value || this.field?.default_value === 0
}
},
modalContainerEl () {
return this.$el.getRootNode().querySelector('#docuseal_modal_container')
@@ -454,7 +476,7 @@ export default {
closeDropdown () {
document.activeElement.blur()
},
maybeFocusDefaultValue () {
maybeToggleDefaultValue () {
if (['text', 'number'].includes(this.field.type)) {
this.isContenteditable = true
@@ -468,6 +490,16 @@ export default {
)
}
})
} else if (this.field.type === 'checkbox') {
this.field.readonly = !this.field.readonly
this.field.default_value === true ? delete this.field.default_value : this.field.default_value = true
this.save()
} else if (this.field.type === 'date') {
this.field.readonly = !this.field.readonly
this.field.default_value === '{{date}}' ? delete this.field.default_value : this.field.default_value = '{{date}}'
this.save()
}
},
formatNumber (number, format) {
@@ -513,7 +545,15 @@ export default {
this.save()
},
onPaste (e) {
e.target.innerText = (e.clipboardData || window.clipboardData).getData('text/plain')
const text = (e.clipboardData || window.clipboardData).getData('text/plain')
const selection = window.getSelection()
if (selection.rangeCount) {
selection.deleteFromDocument()
selection.getRangeAt(0).insertNode(document.createTextNode(text))
selection.collapseToEnd()
}
},
onResizeCell (e) {
if (e.target.id === 'mask') {
+102 -4
View File
@@ -3,6 +3,31 @@
style="max-width: 1600px"
class="mx-auto pl-3 md:pl-4 h-full"
>
<div
v-if="pendingFieldAttachmentUuids.length"
class="top-1.5 sticky h-0 z-20 max-w-2xl mx-auto"
>
<div class="alert border-base-content/30 py-2 px-2.5">
<IconInfoCircle
class="stroke-info shrink-0 w-6 h-6"
/>
<span>{{ t('uploaded_pdf_contains_form_fields_keep_or_remove_them') }}</span>
<div>
<button
class="btn btn-sm"
@click.prevent="removePendingFields"
>
{{ t('remove') }}
</button>
<button
class="btn btn-sm btn-neutral text-white"
@click.prevent="save"
>
{{ t('keep') }}
</button>
</div>
</div>
</div>
<div
v-if="$slots.buttons || withTitle"
id="title_container"
@@ -296,7 +321,7 @@ import Contenteditable from './contenteditable'
import DocumentPreview from './preview'
import DocumentControls from './controls'
import MobileFields from './mobile_fields'
import { IconUsersPlus, IconDeviceFloppy, IconWritingSign, IconInnerShadowTop } from '@tabler/icons-vue'
import { IconUsersPlus, IconDeviceFloppy, IconWritingSign, IconInnerShadowTop, IconInfoCircle } from '@tabler/icons-vue'
import { v4 } from 'uuid'
import { ref, computed } from 'vue'
import { en as i18nEn } from './i18n'
@@ -307,6 +332,7 @@ export default {
Upload,
Document,
Fields,
IconInfoCircle,
MobileDrawField,
IconWritingSign,
MobileFields,
@@ -512,7 +538,9 @@ export default {
isSaving: false,
selectedSubmitter: null,
showDrawField: false,
pendingFieldAttachmentUuids: [],
drawField: null,
copiedArea: null,
drawFieldType: null,
drawOption: null,
dragField: null
@@ -593,6 +621,12 @@ export default {
document.querySelector('form[action="/auth/stripe_connect"]')?.closest('.dropdown')?.querySelector('label')?.focus()
}
})
this.template.schema.forEach((item) => {
if (item.pending_fields) {
this.pendingFieldAttachmentUuids.push(item.attachment_uuid)
}
})
},
unmounted () {
document.removeEventListener('keyup', this.onKeyUp)
@@ -607,6 +641,13 @@ export default {
t (key) {
return this.i18n[key] || i18nEn[key] || key
},
removePendingFields () {
this.template.fields = this.template.fields.filter((f) => {
return this.template.schema.find((item) => item.attachment_uuid === f.attachment_uuid && item.pending_fields)
})
this.save()
},
addField (type, area = null) {
const field = {
name: '',
@@ -627,7 +668,7 @@ export default {
if (type === 'date') {
field.preferences = {
format: Intl.DateTimeFormat().resolvedOptions().locale.endsWith('-US') ? 'MM/DD/YYYY' : 'DD/MM/YYYY'
format: Intl.DateTimeFormat().resolvedOptions().locale.endsWith('-US') || new Intl.DateTimeFormat('en-US', { timeZoneName: 'short' }).format(new Date()).match(/\s(?:CST|CDT|PST|PDT|EST|EDT)$/) ? 'MM/DD/YYYY' : 'DD/MM/YYYY'
}
}
@@ -660,7 +701,7 @@ export default {
if (type === 'date') {
field.preferences = {
format: Intl.DateTimeFormat().resolvedOptions().locale.endsWith('-US') ? 'MM/DD/YYYY' : 'DD/MM/YYYY'
format: Intl.DateTimeFormat().resolvedOptions().locale.endsWith('-US') || new Intl.DateTimeFormat('en-US', { timeZoneName: 'short' }).format(new Date()).match(/\s(?:CST|CDT|PST|PDT|EST|EDT)$/) ? 'MM/DD/YYYY' : 'DD/MM/YYYY'
}
}
@@ -747,6 +788,14 @@ export default {
event.preventDefault()
this.undo()
} else if ((event.ctrlKey || event.metaKey) && event.key === 'c' && document.activeElement === document.body) {
event.preventDefault()
this.copiedArea = this.selectedAreaRef?.value
} else if ((event.ctrlKey || event.metaKey) && event.key === 'v' && this.copiedArea && document.activeElement === document.body) {
event.preventDefault()
this.pasteField()
}
},
removeArea (area) {
@@ -760,6 +809,39 @@ export default {
this.save()
},
pasteField () {
const field = this.template.fields.find((f) => f.areas?.includes(this.copiedArea))
const currentArea = this.selectedAreaRef?.value || this.copiedArea
if (field && currentArea) {
const area = {
...JSON.parse(JSON.stringify(this.copiedArea)),
attachment_uuid: currentArea.attachment_uuid,
page: currentArea.page,
x: currentArea.x,
y: currentArea.y + currentArea.h * 1.3
}
if (['radio', 'multiple'].includes(field.type)) {
this.copiedArea.option_uuid ||= field.options[0].uuid
area.option_uuid = v4()
field.options.push({ uuid: area.option_uuid })
field.areas.push(area)
} else {
this.template.fields.push({
...JSON.parse(JSON.stringify(field)),
uuid: v4(),
areas: [area]
})
}
this.selectedAreaRef.value = area
this.save()
}
},
pushUndo () {
const stringData = JSON.stringify(this.template)
@@ -914,7 +996,7 @@ export default {
if (field.type === 'date') {
field.preferences = {
format: Intl.DateTimeFormat().resolvedOptions().locale.endsWith('-US') ? 'MM/DD/YYYY' : 'DD/MM/YYYY'
format: Intl.DateTimeFormat().resolvedOptions().locale.endsWith('-US') || new Intl.DateTimeFormat('en-US', { timeZoneName: 'short' }).format(new Date()).match(/\s(?:CST|CDT|PST|PDT|EST|EDT)$/) ? 'MM/DD/YYYY' : 'DD/MM/YYYY'
}
}
}
@@ -990,6 +1072,8 @@ export default {
}
this.save()
document.activeElement?.blur()
},
updateFromUpload (data) {
this.template.schema.push(...data.schema)
@@ -1022,6 +1106,18 @@ export default {
}
this.save()
data.documents.forEach((attachment) => {
if (attachment.metadata?.pdf?.fields?.length) {
this.pendingFieldAttachmentUuids.push(attachment.uuid)
attachment.metadata.pdf.fields.forEach((field) => {
field.submitter_uuid = this.selectedSubmitter.uuid
this.template.fields.push(field)
})
}
})
},
updateName (value) {
this.template.name = value
@@ -1188,6 +1284,8 @@ export default {
})
},
save ({ force } = { force: false }) {
this.pendingFieldAttachmentUuids = []
if (this.onChange) {
this.onChange(this.template)
}
@@ -99,7 +99,15 @@ export default {
},
methods: {
onPaste (e) {
e.target.innerText = (e.clipboardData || window.clipboardData).getData('text/plain')
const text = (e.clipboardData || window.clipboardData).getData('text/plain')
const selection = window.getSelection()
if (selection.rangeCount) {
selection.deleteFromDocument()
selection.getRangeAt(0).insertNode(document.createTextNode(text))
selection.collapseToEnd()
}
},
selectContent () {
const el = this.$refs.contenteditable
+1 -1
View File
@@ -339,7 +339,7 @@ export default {
if (this.field.type === 'date') {
this.field.preferences.format ||=
(Intl.DateTimeFormat().resolvedOptions().locale.endsWith('-US') ? 'MM/DD/YYYY' : 'DD/MM/YYYY')
(Intl.DateTimeFormat().resolvedOptions().locale.endsWith('-US') || new Intl.DateTimeFormat('en-US', { timeZoneName: 'short' }).format(new Date()).match(/\s(?:CST|CDT|PST|PDT|EST|EDT)$/) ? 'MM/DD/YYYY' : 'DD/MM/YYYY')
}
},
methods: {
@@ -52,6 +52,40 @@
{{ t('align') }}
</label>
</div>
<div
v-if="['select', 'radio'].includes(field.type) && !defaultField"
class="py-1.5 px-1 relative"
@click.stop
>
<select
:placeholder="t('default_value')"
dir="auto"
class="select select-bordered select-xs w-full max-w-xs h-7 !outline-0 font-normal bg-transparent"
@change="[field.default_value = $event.target.value, !field.default_value && delete field.default_value, save()]"
>
<option
value=""
:selected="!field.default_value"
>
{{ t('none') }}
</option>
<option
v-for="(option, index) in field.options || []"
:key="option.uuid"
:value="option.value || `${t('option')} ${index + 1}`"
:selected="field.default_value === (option.value || `${t('option')} ${index + 1}`)"
>
{{ option.value || `${t('option')} ${index + 1}` }}
</option>
</select>
<label
:style="{ backgroundColor }"
class="absolute -top-1 left-2.5 px-1 h-4"
style="font-size: 8px"
>
{{ t('default_value') }}
</label>
</div>
<div
v-if="['text', 'number'].includes(field.type) && !defaultField"
class="py-1.5 px-1 relative"
+3
View File
@@ -5,6 +5,8 @@ const en = {
clear: 'Clear',
align: 'Align',
add_all_required_fields_to_continue: 'Add all required fields to continue',
uploaded_pdf_contains_form_fields_keep_or_remove_them: 'Uploaded PDF contains form fields. Keep or remove them?',
keep: 'Keep',
left: 'Left',
validation: 'Validation',
right: 'Right',
@@ -27,6 +29,7 @@ const en = {
are_you_sure: 'Are you sure?',
sign_yourself: 'Sign Yourself',
set_signing_date: 'Set signing date',
signing_date: 'Signing Date',
send: 'Send',
remove: 'Remove',
edit: 'Edit',
@@ -204,7 +204,7 @@ export default {
return document.location.origin + '/auth/stripe_connect/callback'
},
defaultCurrencies () {
return ['USD', 'EUR', 'GBP']
return ['USD', 'EUR', 'GBP', 'CAD', 'AUD']
},
currenciesList () {
return this.currencies.length ? this.currencies : this.defaultCurrencies
@@ -226,6 +226,10 @@ export default {
return 'EUR'
} else if (userTimezone.includes('London') || userTimezone.includes('Belfast')) {
return 'GBP'
} else if (userTimezone.includes('Vancouver') || userTimezone.includes('Toronto') || userTimezone.includes('Halifax') || userTimezone.includes('Edmonton')) {
return 'CAD'
} else if (userTimezone.startsWith('Australia')) {
return 'AUD'
} else {
return 'USD'
}
+1 -1
View File
@@ -9,6 +9,6 @@ class UserMailer < ApplicationMailer
assign_message_metadata('user_invitation', @user)
mail(to: @user.friendly_name,
subject: 'You are invited to DocuSeal')
subject: "You are invited to #{Docuseal.product_name}")
end
end
+9
View File
@@ -0,0 +1,9 @@
<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="M11.217 19.384a3.501 3.501 0 0 0 6.783 -1.217v-5.167l-6 -3.35" />
<path d="M5.214 15.014a3.501 3.501 0 0 0 4.446 5.266l4.34 -2.534v-6.946" />
<path d="M6 7.63c-1.391 -.236 -2.787 .395 -3.534 1.689a3.474 3.474 0 0 0 1.271 4.745l4.263 2.514l6 -3.348" />
<path d="M12.783 4.616a3.501 3.501 0 0 0 -6.783 1.217v5.067l6 3.45" />
<path d="M18.786 8.986a3.501 3.501 0 0 0 -4.446 -5.266l-4.34 2.534v6.946" />
<path d="M18 16.302c1.391 .236 2.787 -.395 3.534 -1.689a3.474 3.474 0 0 0 -1.271 -4.745l-4.308 -2.514l-5.955 3.42" />
</svg>

After

Width:  |  Height:  |  Size: 822 B

+8 -5
View File
@@ -86,6 +86,7 @@
<%= link_to 'SSO', settings_sso_index_path, class: 'text-base hover:bg-base-300' %>
</li>
<% end %>
<%= render 'shared/settings_nav_extra2' %>
<% if (can?(:manage, EncryptedConfig) && current_user == true_user) || (current_user != true_user && current_account.testing?) %>
<li>
<%= form_for '', url: testing_account_path, method: current_account.testing? ? :delete : :get, html: { class: 'flex w-full' } do |f| %>
@@ -117,11 +118,13 @@
<%= svg_icon('brand_discord', class: 'w-8 h-8') %>
</a>
</div>
<div class="tooltip" data-tip="Twitter">
<a href="<%= Docuseal::TWITTER_URL %>" target="_blank" class="btn btn-circle btn-primary btn-md">
<%= svg_icon('brand_twitter', class: 'w-8 h-8') %>
</a>
</div>
<%= content_for(:gpt_link) || capture do %>
<div class="tooltip" data-tip="AI Assistant">
<a href="<%= Docuseal::CHATGPT_URL %>" target="_blank" class="btn btn-circle btn-primary btn-md">
<%= svg_icon('brand_openai', class: 'w-8 h-8') %>
</a>
</div>
<% end %>
</div>
<a href="mailto:<%= Docuseal::SUPPORT_EMAIL %>" target="_blank" class="w-full block mt-4 underline text-center">
<%= Docuseal::SUPPORT_EMAIL %>
Whitespace-only changes.
+1 -1
View File
@@ -1,7 +1,7 @@
<turbo-frame id="drawer">
<turbo-modal class="modal modal-open items-start !animate-none justify-end overflow-y-auto !justify-normal md:!justify-end" data-close-after-submit="<%= local_assigns.key?(:close_after_submit) ? local_assigns[:close_after_submit] : true %>">
<div class="absolute top-0 bottom-0 right-0 left-0" data-action="click:turbo-modal#close"></div>
<div class="bg-base-100 min-h-screen max-h-screen relative w-full relative overflow-y-auto">
<div class="bg-base-100 min-h-screen max-h-screen relative w-full relative">
<% if local_assigns[:title] %>
<div class="flex justify-between bg-base-100 py-2 px-4 items-center border-b pb-2 font-medium">
<span>
+1
View File
@@ -76,6 +76,7 @@ Rails.application.routes.draw do
resources :template_sharings_testing, only: %i[create]
resources :templates, only: %i[index], controller: 'templates_dashboard'
resources :templates, only: %i[new create edit update show destroy] do
resource :debug, only: %i[show], controller: 'templates_debug' if Rails.env.development?
resources :documents, only: %i[create], controller: 'template_documents'
resources :restore, only: %i[create], controller: 'templates_restore'
resources :archived, only: %i[index], controller: 'templates_archived_submissions'
+1
View File
@@ -7,3 +7,4 @@ queues:
production:
:concurrency: 15
:max_retries: 5
+1 -1
View File
@@ -13,7 +13,7 @@ module Abilities
.select(:template_id)
join_query = Template.arel_table
.join(template_ids.arel.union(shared_ids.arel).as('union_ids'))
.join(Arel::Nodes::TableAlias.new(template_ids.arel.union(shared_ids.arel), 'union_ids'))
.on(Template.arel_table[:id].eq(Arel::Table.new(:union_ids)[:id]))
Template.joins(join_query.join_sources.first)
+1
View File
@@ -11,6 +11,7 @@ module Docuseal
DISCORD_URL = 'https://discord.gg/qygYCDGck9'
TWITTER_URL = 'https://twitter.com/docusealco'
TWITTER_HANDLE = '@docusealco'
CHATGPT_URL = 'https://chatgpt.com/g/g-9hg8AAw0r-docuseal'
SUPPORT_EMAIL = 'support@docuseal.co'
HOST = ENV.fetch('HOST', 'localhost')
CONSOLE_URL = if Rails.env.development?
+4 -4
View File
@@ -9,17 +9,17 @@ module Templates
module_function
def call(template, params)
def call(template, params, extract_fields: false)
Array.wrap(params[:files].presence || params[:file]).map do |file|
if file.content_type.exclude?('image') && file.content_type != PDF_CONTENT_TYPE
next handle_file_types(template, file, params)
end
handle_pdf_or_image(template, file, file.read, params)
handle_pdf_or_image(template, file, file.read, params, extract_fields:)
end
end
def handle_pdf_or_image(template, file, document_data = nil, params = {})
def handle_pdf_or_image(template, file, document_data = nil, params = {}, extract_fields: false)
document_data ||= file.read
if file.content_type == PDF_CONTENT_TYPE
@@ -44,7 +44,7 @@ module Templates
document = template.documents.create!(blob:)
Templates::ProcessDocument.call(document, document_data)
Templates::ProcessDocument.call(document, document_data, extract_fields:)
end
def maybe_decrypt_pdf_or_raise(data, params)
+234
View File
@@ -0,0 +1,234 @@
# frozen_string_literal: true
module Templates
module FindAcroFields
PDF_CONTENT_TYPE = 'application/pdf'
FIELD_NAME_REGEXP = /\A(?=.*\p{L})[\p{L}\d\s]+\z/
module_function
# rubocop:disable Metrics
def call(pdf, attachment)
return [] unless pdf.acro_form
fields, annots_index = build_fields_with_pages(pdf)
fields.filter_map do |field|
areas = Array.wrap(field[:Kids] || field).filter_map do |child_field|
page = annots_index[child_field.hash]
media_box = page[:MediaBox]
crop_box = page[:CropBox] || media_box
media_box_start = [media_box[0], media_box[1]]
crop_shift = [crop_box[0] - media_box[0], crop_box[1] - media_box[1]]
x0, y0, x1, y1 = child_field[:Rect]
x0, y0 = correct_coordinates(x0, y0, crop_shift, media_box_start)
x1, y1 = correct_coordinates(x1, y1, crop_shift, media_box_start)
page_width = media_box[2] - media_box[0]
page_height = media_box[3] - media_box[1]
x = x0
y = y0
w = x1 - x0
h = y1 - y0
transformed_y = page_height - y - h
attrs = {
page: page.index,
x: x / page_width,
y: transformed_y / page_height,
w: w / page_width,
h: h / page_height,
attachment_uuid: attachment.uuid
}
next if attrs[:w].zero? || attrs[:h].zero?
if child_field[:MaxLen] && child_field.concrete_field_type == :comb_text_field
attrs[:cell_w] = w / page_width / child_field[:MaxLen].to_f
end
attrs
end
next if areas.blank?
field_properties = build_field_properties(field)
next if field_properties.blank?
next if field_properties[:default_value].present?
if field_properties[:type].in?(%w[radio multiple])
if areas.size != field_properties[:options].size
field_properties[:options] = build_options(Array.new(areas.size, ''))
end
areas.each_with_index do |area, index|
area[:option_uuid] = field_properties[:options][index][:uuid]
end
end
{
uuid: SecureRandom.uuid,
required: false,
preferences: {},
areas:,
**field_properties
}
end
rescue StandardError => e
raise if Rails.env.local?
Rollbar.error(e) if defined?(Rollbar)
[]
end
def correct_coordinates(x_coord, y_coord, shift, media_box_start)
corrected_x = x_coord + shift[0] - media_box_start[0]
corrected_y = y_coord + shift[1] - media_box_start[1]
[corrected_x, corrected_y]
end
def build_field_properties(field)
field_name = field.full_field_name if field.full_field_name.to_s.match?(FIELD_NAME_REGEXP)
field_name = field_name&.encode('utf-8', invalid: :replace, undef: :replace, replace: '')
if field.field_type == :Btn && field.concrete_field_type == :radio_button && field[:Opt].present?
selected_option_index = (field.allowed_values || []).find_index(field.field_value)
selected_option = field[:Opt][selected_option_index] if selected_option_index
{
name: field_name.to_s,
type: 'radio',
description: field[:TU],
options: build_options(field[:Opt], 'radio'),
default_value: selected_option
}
elsif field.field_type == :Btn && field.concrete_field_type == :check_box &&
field[:Kids].present? && field[:Kids].size > 1 && field.allowed_values.size > 1
selected_option = (field.allowed_values || []).find { |v| v == field.field_value }
return {} if field.allowed_values.include?(:BBox)
{
name: field_name.to_s,
type: 'radio',
description: field[:TU],
options: build_options(field.allowed_values, 'radio'),
default_value: selected_option
}
elsif field.field_type == :Btn && field.concrete_field_type == :check_box
{
name: field_name.to_s,
type: 'checkbox',
description: field[:TU],
default_value: field.field_value.present?
}
elsif field.field_type == :Ch &&
%i[combo_box editable_combo_box].include?(field.concrete_field_type) && field[:Opt].present?
{
name: field_name.to_s,
type: 'select',
description: field[:TU],
options: build_options(field[:Opt]),
default_value: field.field_value
}
elsif field.field_type == :Ch && field.concrete_field_type == :multi_select && field[:Opt].present?
{
name: field_name.to_s,
type: 'multiple',
description: field[:TU],
options: build_options(field[:Opt], 'multiple'),
default_value: field.field_value
}
elsif field.field_type == :Tx && field.concrete_field_type == :comb_text_field
{
name: field_name.to_s,
type: 'cells',
description: field[:TU],
default_value: field.field_value
}
elsif field.field_type == :Tx
{
name: field_name.to_s,
type: 'text',
description: field[:TU],
default_value: field.field_value
}
elsif field.field_type == :Sig
{
name: field_name.to_s,
type: 'signature',
description: field[:TU]
}
else
{}
end.compact
end
def build_options(values, type = nil)
is_skip_single_value = type.in?(%w[radio multiple]) && values.uniq.size == 1
values.map do |option|
is_option_number = option.is_a?(Symbol) && option.to_s.match?(/\A\d+\z/)
option = option.encode('utf-8', invalid: :replace, undef: :replace, replace: '') if option.is_a?(String)
{
uuid: SecureRandom.uuid,
value: is_option_number || is_skip_single_value ? '' : option
}
end
end
def build_fields_with_pages(pdf)
fields_index = {}
annots_index = {}
pdf.pages.each do |page|
page.each_annotation do |annot|
annots_index[annot.hash] = page
if !annot.key?(:Parent) && annot.key?(:FT)
fields_index[annot.hash] ||= HexaPDF::Type::AcroForm::Field.wrap(pdf, annot)
elsif annot.key?(:Parent)
field = annot[:Parent]
field = field[:Parent] while field[:Parent]
fields_index[field.hash] ||= HexaPDF::Type::AcroForm::Field.wrap(pdf, field)
end
end
end
[process_fields_array(pdf, fields_index.values), annots_index]
end
def process_fields_array(pdf, array, acc = [])
array.each_with_index do |field, index|
next if field.nil?
unless field.respond_to?(:type) && field.type == :XXAcroFormField
array[index] = field = HexaPDF::Type::AcroForm::Field.wrap(pdf, field)
end
if field.terminal_field?
acc << field
else
process_fields_array(pdf, field[:Kids], acc)
end
end
acc
end
# rubocop:enable Metrics
end
end
+25 -5
View File
@@ -10,14 +10,22 @@ module Templates
Q = 35
MAX_WIDTH = 1400
MAX_NUMBER_OF_PAGES_PROCESSED = 15
MAX_FLATTEN_FILE_SIZE = 15.megabytes
MAX_FLATTEN_FILE_SIZE = 20.megabytes
GENERATE_PREVIEW_SIZE_LIMIT = 50.megabytes
module_function
def call(attachment, data)
def call(attachment, data, extract_fields: false)
if attachment.content_type == PDF_CONTENT_TYPE
generate_pdf_preview_images(attachment, data)
if extract_fields && data.size < MAX_FLATTEN_FILE_SIZE
pdf = HexaPDF::Document.new(io: StringIO.new(data))
fields = Templates::FindAcroFields.call(pdf, attachment)
end
generate_pdf_preview_images(attachment, data, pdf)
attachment.metadata['pdf']['fields'] = fields if fields
elsif attachment.image?
generate_preview_image(attachment, data)
end
@@ -43,10 +51,10 @@ module Templates
)
end
def generate_pdf_preview_images(attachment, data)
def generate_pdf_preview_images(attachment, data, pdf = nil)
ActiveStorage::Attachment.where(name: ATTACHMENT_NAME, record: attachment).destroy_all
pdf = HexaPDF::Document.new(io: StringIO.new(data))
pdf ||= HexaPDF::Document.new(io: StringIO.new(data))
number_of_pages = pdf.pages.size
data = maybe_flatten_form(data, pdf)
@@ -97,6 +105,18 @@ module Templates
data
end
def normalize_attachment_fields(template, attachments = template.documents)
attachments.flat_map do |a|
pdf_fields = a.metadata['pdf'].delete('fields').to_a if a.metadata['pdf'].present?
next [] if pdf_fields.blank?
pdf_fields.each { |f| f['submitter_uuid'] = template.submitters.first['uuid'] }
pdf_fields
end
end
def generate_pdf_preview_from_file(attachment, file_path, page_number)
io = StringIO.new