Skip to content

Commit

Permalink
Merge from docusealco/wip
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexBTurchyn authored Feb 4, 2025
2 parents c67c80d + 9edbb88 commit 66c1831
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04-arm

steps:
- name: Checkout code
Expand Down
2 changes: 1 addition & 1 deletion lib/submitters/maybe_assign_default_browser_signature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def call(submitter, params, cookies = nil, attachments = [])

def find_or_create_signature_from_value(submitter, value, attachments)
_, attachment = Submitters::NormalizeValues.normalize_attachment_value(value,
'signature',
{ 'type' => 'signature' },
submitter.account,
attachments,
submitter)
Expand Down
18 changes: 13 additions & 5 deletions lib/submitters/normalize_values.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def call(template, values, submitter_name: nil, for_submitter: nil, throw_errors

if field['type'].in?(%w[initials signature image file stamp]) && value.present?
new_value, new_attachments =
normalize_attachment_value(value, field['type'], template.account, attachments, for_submitter)
normalize_attachment_value(value, field, template.account, attachments, for_submitter)

attachments.push(*new_attachments)

Expand Down Expand Up @@ -109,17 +109,17 @@ def build_fields_index(fields)
.merge(fields.index_by { |e| e['name'].to_s.downcase })
end

def normalize_attachment_value(value, type, account, attachments, for_submitter = nil)
def normalize_attachment_value(value, field, account, attachments, for_submitter = nil)
if value.is_a?(Array)
new_attachments = value.map do |v|
new_attachment = find_or_build_attachment(v, type, account, for_submitter)
new_attachment = find_or_build_attachment(v, field, account, for_submitter)

attachments.find { |a| a.blob_id == new_attachment.blob_id } || new_attachment
end

[new_attachments.map(&:uuid), new_attachments]
else
new_attachment = find_or_build_attachment(value, type, account, for_submitter)
new_attachment = find_or_build_attachment(value, field, account, for_submitter)

existing_attachment = attachments.find { |a| a.blob_id == new_attachment.blob_id }

Expand All @@ -129,7 +129,9 @@ def normalize_attachment_value(value, type, account, attachments, for_submitter
end
end

def find_or_build_attachment(value, type, account, for_submitter = nil)
def find_or_build_attachment(value, field, account, for_submitter = nil)
type = field['type']

blob =
if value.match?(%r{\Ahttps?://})
find_or_create_blob_from_url(account, value)
Expand All @@ -138,6 +140,8 @@ def find_or_build_attachment(value, type, account, for_submitter = nil)
elsif (data = Base64.decode64(value.sub(BASE64_PREFIX_REGEXP, ''))) &&
Marcel::MimeType.for(data).exclude?('octet-stream')
find_or_create_blob_from_base64(account, data, type)
elsif type == 'image' && (value.starts_with?('<html>') || value.starts_with?('<!DOCTYPE'))
find_or_create_blob_from_html(account, value, field)
else
raise InvalidDefaultValue, "Invalid value, url, base64 or text < 60 chars is expected: #{value.first(200)}..."
end
Expand All @@ -152,6 +156,10 @@ def find_or_build_attachment(value, type, account, for_submitter = nil)
attachment
end

def find_or_create_blob_from_html(_account, value, _field)
raise InvalidDefaultValue, "HTML content is not allowed: #{value.first(200)}..."
end

def find_or_create_blob_from_base64(account, data, type)
checksum = Digest::MD5.base64digest(data)

Expand Down

0 comments on commit 66c1831

Please sign in to comment.