Skip to content

Commit 1f89acc

Browse files
authored
Merge from docusealco/wip
2 parents 9c700a3 + 9fcaef4 commit 1f89acc

46 files changed

Lines changed: 349 additions & 144 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ ENV OPENSSL_CONF=/etc/openssl_legacy.cnf
4848

4949
WORKDIR /app
5050

51-
RUN apk add --no-cache libpq vips redis onnxruntime
51+
RUN apk add --no-cache libpq vips redis onnxruntime && \
52+
rm -f /usr/bin/onnx_test_runner /usr/bin/onnxruntime_test
5253

5354
RUN addgroup -g 2000 docuseal && adduser -u 2000 -G docuseal -s /bin/sh -D -h /home/docuseal docuseal
5455

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ gem 'faraday'
2121
gem 'faraday-follow_redirects'
2222
gem 'google-cloud-storage', require: false
2323
gem 'hexapdf'
24-
gem 'image_processing'
2524
gem 'jwt', require: false
2625
gem 'lograge'
2726
gem 'numo-narray-alt', require: false

Gemfile.lock

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,14 @@ GEM
264264
strscan (>= 3.1.2)
265265
i18n (1.14.8)
266266
concurrent-ruby (~> 1.0)
267-
image_processing (1.14.0)
268-
mini_magick (>= 4.9.5, < 6)
269-
ruby-vips (>= 2.0.17, < 3)
270267
io-console (0.8.2)
271268
irb (1.18.0)
272269
pp (>= 0.6.0)
273270
prism (>= 1.3.0)
274271
rdoc (>= 4.0.0)
275272
reline (>= 0.4.2)
276273
jmespath (1.6.2)
277-
json (2.19.5)
274+
json (2.19.7)
278275
jwt (3.2.0)
279276
base64
280277
language_server-protocol (3.17.0.5)
@@ -308,8 +305,6 @@ GEM
308305
marcel (1.1.0)
309306
matrix (0.4.3)
310307
method_source (1.1.0)
311-
mini_magick (5.3.1)
312-
logger
313308
mini_mime (1.1.5)
314309
minitest (6.0.6)
315310
drb (~> 2.0)
@@ -434,7 +429,7 @@ GEM
434429
erb
435430
psych (>= 4.0.0)
436431
tsort
437-
redis-client (0.28.0)
432+
redis-client (0.29.0)
438433
connection_pool
439434
regexp_parser (2.11.3)
440435
reline (0.6.3)
@@ -516,12 +511,12 @@ GEM
516511
rack-proxy (>= 0.6.1)
517512
railties (>= 5.2)
518513
semantic_range (>= 2.3.0)
519-
sidekiq (8.1.2)
514+
sidekiq (8.1.6)
520515
connection_pool (>= 3.0.0)
521516
json (>= 2.16.0)
522517
logger (>= 1.7.0)
523518
rack (>= 3.2.0)
524-
redis-client (>= 0.26.0)
519+
redis-client (>= 0.29.0)
525520
signet (0.21.0)
526521
addressable (~> 2.8)
527522
faraday (>= 0.17.5, < 3.a)
@@ -624,7 +619,6 @@ DEPENDENCIES
624619
foreman
625620
google-cloud-storage
626621
hexapdf
627-
image_processing
628622
jwt
629623
letter_opener_web
630624
lograge

app/controllers/api/attachments_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ def create
1111
@submitter = Submitter.find_by!(slug: params[:submitter_slug])
1212

1313
unless can_upload?(@submitter)
14-
Rollbar.error("Can't upload: #{@submitter.id}") if defined?(Rollbar)
15-
1614
return render json: { error: I18n.t('form_has_been_archived') }, status: :unprocessable_content
1715
end
1816

@@ -33,9 +31,11 @@ def create
3331
return render json: { error: "#{params[:type]} error, try to sign on another device" },
3432
status: :unprocessable_content
3533
end
34+
35+
metadata = { analyzed: true, identified: true, width: image.width, height: image.height }
3636
end
3737

38-
attachment = Submitters.create_attachment!(@submitter, file)
38+
attachment = Submitters.create_attachment!(@submitter, file, metadata:)
3939

4040
if params[:remember_signature] == 'true' && @submitter.email.present?
4141
cookies.encrypted[:signature_uuids] = build_new_cookie_signatures_json(@submitter, attachment)

app/controllers/api/templates_controller.rb

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,15 @@ def index
99

1010
templates = paginate(templates.preload(:author, folder: :parent_folder))
1111

12-
schema_documents =
13-
ActiveStorage::Attachment.where(record_id: templates.map(&:id),
14-
record_type: 'Template',
15-
name: :documents,
16-
uuid: templates.flat_map { |t| t.schema.pluck('attachment_uuid') })
17-
.preload(:blob)
18-
19-
preview_image_attachments =
20-
ActiveStorage::Attachment.joins(:blob)
21-
.where(blob: { filename: ['0.png', '0.jpg'] })
22-
.where(record_id: schema_documents.map(&:id),
23-
record_type: 'ActiveStorage::Attachment',
24-
name: :preview_images)
25-
.preload(:blob)
12+
schema_documents, dynamic_documents, preview_image_attachments = preload_relations(templates)
2613

2714
expires_at = Accounts.link_expires_at(current_account)
2815

2916
render json: {
3017
data: templates.map do |t|
3118
Templates::SerializeForApi.call(t,
3219
schema_documents: schema_documents.select { |e| e.record_id == t.id },
20+
dynamic_documents:,
3321
preview_image_attachments:,
3422
expires_at:)
3523
end,
@@ -88,6 +76,41 @@ def destroy
8876

8977
private
9078

79+
def preload_relations(templates)
80+
schema_documents =
81+
ActiveStorage::Attachment.where(record_id: templates.map(&:id),
82+
record_type: 'Template',
83+
name: :documents,
84+
uuid: templates.flat_map { |t| t.schema.pluck('attachment_uuid') })
85+
.preload(:blob)
86+
87+
dynamic_document_uuids =
88+
templates.flat_map { |t| t.schema.select { |item| item['dynamic'] }.pluck('attachment_uuid') }
89+
90+
dynamic_documents =
91+
if dynamic_document_uuids.present?
92+
DynamicDocument.where(template: templates.map(&:id))
93+
.where(uuid: dynamic_document_uuids)
94+
.preload(current_version: { document_attachment: :blob })
95+
.select(:id, :uuid, :template_id, :sha1, :created_at, :updated_at)
96+
else
97+
DynamicDocument.none
98+
end
99+
100+
preview_attachment_ids =
101+
schema_documents.map(&:id) + dynamic_documents.filter_map { |d| d.current_version&.document_attachment&.id }
102+
103+
preview_image_attachments =
104+
ActiveStorage::Attachment.joins(:blob)
105+
.where(blob: { filename: ['0.png', '0.jpg'] })
106+
.where(record_id: preview_attachment_ids,
107+
record_type: 'ActiveStorage::Attachment',
108+
name: :preview_images)
109+
.preload(:blob)
110+
111+
[schema_documents, dynamic_documents, preview_image_attachments]
112+
end
113+
91114
def filter_templates(templates, params)
92115
templates = Templates.search(current_user, templates, params[:q])
93116
templates = params[:archived].in?(['true', true]) ? templates.archived : templates.active

app/controllers/start_form_controller.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,18 @@ def enqueue_new_submitter_jobs(submitter)
101101
def load_resubmit_submitter
102102
@resubmit_submitter =
103103
if params[:resubmit].present? && !params[:resubmit].in?([true, 'true'])
104-
Submitter.find_by(slug: params[:resubmit])
104+
submitter = Submitter.find_by(slug: params[:resubmit])
105+
106+
submitter if submitter && can_resubmit?(submitter)
105107
end
106108
end
107109

110+
def can_resubmit?(submitter)
111+
submitter.account.account_configs.find_or_initialize_by(key: AccountConfig::ALLOW_TO_RESUBMIT).value != false
112+
end
113+
108114
def authorize_start!
115+
return redirect_to submit_form_path(@resubmit_submitter.slug) if @resubmit_submitter && @template.archived_at?
109116
return redirect_to start_form_path(@template.slug) if @template.archived_at?
110117

111118
return if @resubmit_submitter

app/controllers/templates_controller.rb

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
# frozen_string_literal: true
22

33
class TemplatesController < ApplicationController
4-
TEMPLATE_FIELDS = %i[id author_id folder_id external_id name slug
5-
schema fields submitters variables_schema preferences
6-
shared_link source archived_at created_at updated_at].freeze
7-
84
load_and_authorize_resource :template
95

106
def show
@@ -31,19 +27,7 @@ def show
3127
def new; end
3228

3329
def edit
34-
ActiveRecord::Associations::Preloader.new(
35-
records: [@template],
36-
associations: [{ schema_documents: [:blob, { preview_images_attachments: :blob }] }]
37-
).call
38-
39-
@template_data =
40-
@template.as_json(only: TEMPLATE_FIELDS).merge(
41-
documents: @template.schema_documents.as_json(
42-
only: %i[id uuid],
43-
methods: %i[metadata signed_key],
44-
include: { preview_images: { only: %i[id], methods: %i[url metadata filename] } }
45-
)
46-
).to_json
30+
@template_data = Templates.serialize_for_builder(@template)
4731

4832
render :edit, layout: 'plain'
4933
end

app/controllers/templates_detect_fields_controller.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ def create
1616
page_number = params[:page].presence&.to_i
1717

1818
documents.each do |document|
19-
io = StringIO.new(document.download)
19+
io =
20+
if document.image?
21+
StringIO.new(document.preview_images.joins(:blob).find_by(blob: { filename: ['0.png', '0.jpg'] }).download)
22+
else
23+
StringIO.new(document.download)
24+
end
2025

2126
Templates::DetectFields.call(io, attachment: document, page_number:) do |(attachment_uuid, page, fields)|
2227
sse.write({ attachment_uuid:, page:, fields: })

app/controllers/templates_preview_controller.rb

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,7 @@ class TemplatesPreviewController < ApplicationController
44
load_and_authorize_resource :template
55

66
def show
7-
ActiveRecord::Associations::Preloader.new(
8-
records: [@template],
9-
associations: [{ schema_documents: { preview_images_attachments: :blob } }]
10-
).call
11-
12-
@template_data =
13-
@template.as_json.merge(
14-
documents: @template.schema_documents.as_json(
15-
methods: %i[metadata signed_key],
16-
include: { preview_images: { methods: %i[url metadata filename] } }
17-
)
18-
).to_json
7+
@template_data = Templates.serialize_for_builder(@template)
198

209
render :show, layout: 'plain'
2110
end

app/controllers/templates_uploads_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ class TemplatesUploadsController < ApplicationController
55

66
layout 'plain'
77

8-
def show; end
8+
def show
9+
redirect_to root_path if params[:url].blank?
10+
end
911

1012
def create
1113
url_params = create_file_params_from_url if params[:url].present?

0 commit comments

Comments
 (0)