Skip to content

Commit 9011e3f

Browse files
authored
Merge from docusealco/wip
2 parents 00af69c + 0b45ce5 commit 9011e3f

24 files changed

+522
-175
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ Style/MultipleComparison:
4848
Style/NumericPredicate:
4949
Enabled: false
5050

51+
Style/MinMaxComparison:
52+
Enabled: false
53+
5154
Naming/PredicateMethod:
5255
Enabled: false
5356

Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ RUN apk --no-cache add fontforge wget && \
99
wget https://cdn.jsdelivr.net/gh/notofonts/notofonts.github.io/fonts/NotoSansSymbols2/hinted/ttf/NotoSansSymbols2-Regular.ttf && \
1010
wget https://github.com/Maxattax97/gnu-freefont/raw/master/ttf/FreeSans.ttf && \
1111
wget https://github.com/impallari/DancingScript/raw/master/OFL.txt && \
12-
wget -O /model.onnx "https://github.com/docusealco/fields-detection/releases/download/2.0.0/model_704_int8.onnx" && \
12+
wget -O /model.onnx "https://github.com/docusealco/fields-detection/releases/download/2.1.0/model_704_int8.onnx" && \
1313
wget -O pdfium-linux.tgz "https://github.com/docusealco/pdfium-binaries/releases/latest/download/pdfium-linux-$(uname -m | sed 's/x86_64/x64/;s/aarch64/arm64/').tgz" && \
1414
mkdir -p /pdfium-linux && \
1515
tar -xzf pdfium-linux.tgz -C /pdfium-linux
@@ -53,6 +53,8 @@ WORKDIR /app
5353

5454
RUN apk add --no-cache sqlite-dev libpq-dev mariadb-dev vips-dev yaml-dev redis libheif vips-heif gcompat ttf-freefont && mkdir /fonts && rm /usr/share/fonts/freefont/FreeSans.otf
5555

56+
RUN addgroup -g 2000 docuseal && adduser -u 2000 -G docuseal -s /bin/sh -D -h /home/docuseal docuseal
57+
5658
RUN echo $'.include = /etc/ssl/openssl.cnf\n\
5759
\n\
5860
[provider_sect]\n\
@@ -92,7 +94,10 @@ COPY --from=webpack /app/public/packs ./public/packs
9294
RUN ln -s /fonts /app/public/fonts
9395
RUN bundle exec bootsnap precompile -j 1 --gemfile app/ lib/
9496

97+
RUN chown -R docuseal:docuseal /app
98+
9599
WORKDIR /data/docuseal
100+
ENV HOME=/home/docuseal
96101
ENV WORKDIR=/data/docuseal
97102

98103
EXPOSE 3000

app/controllers/api/submission_documents_controller.rb

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,17 @@ class SubmissionDocumentsController < ApiBaseController
55
load_and_authorize_resource :submission
66

77
def index
8+
is_merge = params[:merge] == 'true' &&
9+
(@submission.schema_documents || @submission.template.schema_documents).size > 1
10+
811
documents =
912
if @submission.submitters.all?(&:completed_at?)
10-
last_submitter = @submission.submitters.max_by(&:completed_at)
11-
12-
if last_submitter.documents_attachments.blank?
13-
last_submitter.documents_attachments = Submissions::EnsureResultGenerated.call(last_submitter)
14-
end
15-
16-
last_submitter.documents_attachments
13+
build_completed_documents(@submission, merge: is_merge)
1714
else
18-
values_hash = Submissions::GeneratePreviewAttachments.build_values_hash(@submission)
19-
20-
if @submission.preview_documents.present? &&
21-
@submission.preview_documents.all? { |s| s.metadata['values_hash'] == values_hash }
22-
@submission.preview_documents
23-
else
24-
ApplicationRecord.no_touching do
25-
@submission.preview_documents.each(&:destroy)
26-
end
27-
28-
Submissions::GeneratePreviewAttachments.call(@submission, values_hash:)
29-
end
15+
build_preview_documents(@submission, merge: is_merge)
3016
end
3117

32-
ActiveRecord::Associations::Preloader.new(
33-
records: documents,
34-
associations: [:blob]
35-
).call
18+
ActiveRecord::Associations::Preloader.new(records: documents, associations: [:blob]).call
3619

3720
expires_at = Accounts.link_expires_at(current_account)
3821

@@ -43,5 +26,50 @@ def index
4326
end
4427
}
4528
end
29+
30+
private
31+
32+
def build_completed_documents(submission, merge: false)
33+
last_submitter = submission.submitters.max_by(&:completed_at)
34+
35+
if merge
36+
if submission.merged_document_attachment.blank?
37+
submission.merged_document_attachment =
38+
Submissions::GenerateCombinedAttachment.call(last_submitter, with_audit: false)
39+
end
40+
41+
[submission.merged_document_attachment]
42+
else
43+
if last_submitter.documents_attachments.blank?
44+
last_submitter.documents_attachments = Submissions::EnsureResultGenerated.call(last_submitter)
45+
end
46+
47+
last_submitter.documents_attachments
48+
end
49+
end
50+
51+
def build_preview_documents(submission, merge: false)
52+
values_hash = Submissions::GeneratePreviewAttachments.build_values_hash(submission)
53+
54+
if merge
55+
if submission.preview_merged_document_attachment.present? &&
56+
submission.preview_merged_document_attachment.metadata['values_hash'] == values_hash
57+
[submission.preview_merged_document_attachment]
58+
else
59+
ApplicationRecord.no_touching { submission.preview_merged_document_attachment&.destroy }
60+
61+
Submissions::GeneratePreviewAttachments.call(submission, values_hash:, merge: true)
62+
end
63+
elsif submission.preview_documents.present? &&
64+
submission.preview_documents.all? { |s| s.metadata['values_hash'] == values_hash }
65+
submission.preview_documents
66+
else
67+
ApplicationRecord.no_touching do
68+
submission.preview_documents.each(&:destroy)
69+
end
70+
71+
Submissions::GeneratePreviewAttachments.call(submission, values_hash:)
72+
end
73+
end
4674
end
4775
end

app/controllers/application_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class ApplicationController < ActionController::Base
1717

1818
helper_method :button_title,
1919
:current_account,
20+
:true_ability,
2021
:form_link_host,
2122
:svg_icon
2223

@@ -102,6 +103,10 @@ def current_account
102103
current_user&.account
103104
end
104105

106+
def true_ability
107+
@true_ability ||= Ability.new(true_user)
108+
end
109+
105110
def maybe_redirect_to_setup
106111
redirect_to setup_index_path unless User.exists?
107112
end
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# frozen_string_literal: true
2+
3+
class TemplatesCloneController < ApplicationController
4+
load_and_authorize_resource :template, instance_name: :base_template
5+
6+
def new
7+
authorize!(:create, Template)
8+
9+
@template = Template.new(name: "#{@base_template.name} (#{I18n.t('clone')})")
10+
end
11+
12+
def create
13+
ActiveRecord::Associations::Preloader.new(
14+
records: [@base_template],
15+
associations: [schema_documents: :preview_images_attachments]
16+
).call
17+
18+
@template = Templates::Clone.call(@base_template, author: current_user,
19+
name: params.dig(:template, :name),
20+
folder_name: params[:folder_name])
21+
22+
authorize!(:create, @template)
23+
24+
if params[:account_id].present? && true_ability.authorize!(:manage, Account.find(params[:account_id]))
25+
@template.account_id = params[:account_id]
26+
@template.author = true_user if true_user.account_id == @template.account_id
27+
@template.folder = @template.account.default_template_folder if @template.account_id != current_account.id
28+
else
29+
@template.account = current_account
30+
end
31+
32+
Templates.maybe_assign_access(@template)
33+
34+
if @template.save
35+
Templates::CloneAttachments.call(template: @template, original_template: @base_template)
36+
37+
SearchEntries.enqueue_reindex(@template)
38+
39+
WebhookUrls.enqueue_events(@template, 'template.created')
40+
41+
maybe_redirect_to_template(@template)
42+
else
43+
render turbo_stream: turbo_stream.replace(:modal, partial: 'templates_clone/form'), status: :unprocessable_content
44+
end
45+
end
46+
47+
private
48+
49+
def maybe_redirect_to_template(template)
50+
if template.account == current_account
51+
redirect_to(edit_template_path(template))
52+
else
53+
redirect_back(fallback_location: root_path, notice: I18n.t('template_has_been_cloned'))
54+
end
55+
end
56+
end

app/controllers/templates_controller.rb

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
class TemplatesController < ApplicationController
44
load_and_authorize_resource :template
55

6-
before_action :load_base_template, only: %i[new create]
7-
86
def show
97
submissions = @template.submissions.accessible_by(current_ability)
108
submissions = submissions.active if @template.archived_at.blank?
@@ -26,9 +24,7 @@ def show
2624
redirect_to root_path
2725
end
2826

29-
def new
30-
@template.name = "#{@base_template.name} (#{I18n.t('clone')})" if @base_template
31-
end
27+
def new; end
3228

3329
def edit
3430
ActiveRecord::Associations::Preloader.new(
@@ -48,37 +44,18 @@ def edit
4844
end
4945

5046
def create
51-
if @base_template
52-
ActiveRecord::Associations::Preloader.new(
53-
records: [@base_template],
54-
associations: [schema_documents: :preview_images_attachments]
55-
).call
56-
57-
@template = Templates::Clone.call(@base_template, author: current_user,
58-
name: params.dig(:template, :name),
59-
folder_name: params[:folder_name])
60-
else
61-
@template.author = current_user
62-
@template.folder = TemplateFolders.find_or_create_by_name(current_user, params[:folder_name])
63-
end
64-
65-
if params[:account_id].present? && authorized_clone_account_id?(params[:account_id])
66-
@template.account_id = params[:account_id]
67-
@template.folder = @template.account.default_template_folder if @template.account_id != current_account.id
68-
else
69-
@template.account = current_account
70-
end
47+
@template.author = current_user
48+
@template.folder = TemplateFolders.find_or_create_by_name(current_user, params[:folder_name])
49+
@template.account = current_account
7150

7251
Templates.maybe_assign_access(@template)
7352

7453
if @template.save
75-
Templates::CloneAttachments.call(template: @template, original_template: @base_template) if @base_template
76-
7754
SearchEntries.enqueue_reindex(@template)
7855

7956
WebhookUrls.enqueue_events(@template, 'template.created')
8057

81-
maybe_redirect_to_template(@template)
58+
redirect_to(edit_template_path(@template))
8259
else
8360
render turbo_stream: turbo_stream.replace(:modal, template: 'templates/new'), status: :unprocessable_content
8461
end
@@ -132,23 +109,4 @@ def template_params
132109
areas: [%i[x y w h cell_w attachment_uuid option_uuid page]] }]] }
133110
)
134111
end
135-
136-
def authorized_clone_account_id?(account_id)
137-
true_user.account_id.to_s == account_id.to_s ||
138-
true_user.account.linked_accounts.accessible_by(current_ability).exists?(id: account_id)
139-
end
140-
141-
def maybe_redirect_to_template(template)
142-
if template.account == current_account
143-
redirect_to(edit_template_path(@template))
144-
else
145-
redirect_back(fallback_location: root_path, notice: I18n.t('template_has_been_cloned'))
146-
end
147-
end
148-
149-
def load_base_template
150-
return if params[:base_template_id].blank?
151-
152-
@base_template = Template.accessible_by(current_ability).find_by(id: params[:base_template_id])
153-
end
154112
end

app/javascript/submission_form/area.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ export default {
461461
phone: IconPhoneCheck,
462462
payment: IconCreditCard,
463463
verification: IconId,
464-
kba: IconUserScan,
464+
kba: IconUserScan
465465
}
466466
},
467467
image () {

0 commit comments

Comments
 (0)