Skip to content

Commit 2521eb5

Browse files
authored
Merge from docusealco/wip
2 parents 4e23089 + bf6afc5 commit 2521eb5

29 files changed

+1043
-46
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ yarn-debug.log*
3737
/docuseal
3838
/ee
3939
dump.rdb
40+
*.onnx

Dockerfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +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/1.0.0/model_704_int8.onnx" && \
1213
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" && \
1314
mkdir -p /pdfium-linux && \
1415
tar -xzf pdfium-linux.tgz -C /pdfium-linux
@@ -50,7 +51,7 @@ ENV OPENSSL_CONF=/app/openssl_legacy.cnf
5051

5152
WORKDIR /app
5253

53-
RUN echo '@edge https://dl-cdn.alpinelinux.org/alpine/edge/community' >> /etc/apk/repositories && apk add --no-cache sqlite-dev libpq-dev mariadb-dev vips-dev@edge yaml-dev redis libheif@edge vips-heif@edge gcompat ttf-freefont && mkdir /fonts && rm /usr/share/fonts/freefont/FreeSans.otf
54+
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
5455

5556
RUN echo $'.include = /etc/ssl/openssl.cnf\n\
5657
\n\
@@ -66,7 +67,9 @@ activate = 1' >> /app/openssl_legacy.cnf
6667

6768
COPY ./Gemfile ./Gemfile.lock ./
6869

69-
RUN apk add --no-cache build-base && bundle install && apk del --no-cache build-base && rm -rf ~/.bundle /usr/local/bundle/cache && ruby -e "puts Dir['/usr/local/bundle/**/{spec,rdoc,resources/shared,resources/collation,resources/locales}']" | xargs rm -rf
70+
RUN apk add --no-cache build-base && bundle install && apk del --no-cache build-base && rm -rf ~/.bundle /usr/local/bundle/cache && ruby -e "puts Dir['/usr/local/bundle/**/{spec,rdoc,resources/shared,resources/collation,resources/locales}']" | xargs rm -rf && ln -sf /usr/lib/libonnxruntime.so.1 $(ruby -e "print Dir[Gem::Specification.find_by_name('onnxruntime').gem_dir + '/vendor/*.so'].first")
71+
72+
RUN echo 'https://dl-cdn.alpinelinux.org/alpine/edge/main' >> /etc/apk/repositories && echo 'https://dl-cdn.alpinelinux.org/alpine/edge/community' >> /etc/apk/repositories && apk add --no-cache onnxruntime
7073

7174
COPY ./bin ./bin
7275
COPY ./app ./app
@@ -83,6 +86,7 @@ COPY --from=download /fonts/GoNotoKurrent-Regular.ttf /fonts/GoNotoKurrent-Bold.
8386
COPY --from=download /fonts/FreeSans.ttf /usr/share/fonts/freefont
8487
COPY --from=download /pdfium-linux/lib/libpdfium.so /usr/lib/libpdfium.so
8588
COPY --from=download /pdfium-linux/licenses/pdfium.txt /usr/lib/libpdfium-LICENSE.txt
89+
COPY --from=download /model.onnx /app/tmp/model.onnx
8690
COPY --from=webpack /app/public/packs ./public/packs
8791

8892
RUN ln -s /fonts /app/public/fonts

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ gem 'image_processing'
2424
gem 'jwt'
2525
gem 'lograge'
2626
gem 'mysql2', require: false
27+
gem 'numo-narray'
2728
gem 'oj'
29+
gem 'onnxruntime'
2830
gem 'pagy'
2931
gem 'pg', require: false
3032
gem 'premailer-rails'

Gemfile.lock

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,18 @@ GEM
357357
racc (~> 1.4)
358358
nokogiri (1.18.9-x86_64-linux-musl)
359359
racc (~> 1.4)
360+
numo-narray (0.9.2.1)
360361
oj (3.16.11)
361362
bigdecimal (>= 3.0)
362363
ostruct (>= 0.2)
364+
onnxruntime (0.10.1)
365+
ffi
366+
onnxruntime (0.10.1-aarch64-linux)
367+
ffi
368+
onnxruntime (0.10.1-arm64-darwin)
369+
ffi
370+
onnxruntime (0.10.1-x86_64-linux)
371+
ffi
363372
openssl (3.3.0)
364373
orm_adapter (0.5.0)
365374
os (1.1.4)
@@ -638,7 +647,9 @@ DEPENDENCIES
638647
letter_opener_web
639648
lograge
640649
mysql2
650+
numo-narray
641651
oj
652+
onnxruntime
642653
pagy
643654
pg
644655
premailer-rails

app/controllers/accounts_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def destroy
4747
authorize!(:manage, current_account)
4848

4949
true_user.update!(locked_at: Time.current, email: true_user.email.sub('@', '+removed@'))
50+
true_user.account.update!(archived_at: Time.current)
5051

5152
# rubocop:disable Layout/LineLength
5253
render turbo_stream: turbo_stream.replace(

app/controllers/api/attachments_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ def create
3434
end
3535

3636
render json: attachment.as_json(only: %i[uuid created_at], methods: %i[url filename content_type])
37+
rescue Submitters::MaliciousFileExtension => e
38+
Rollbar.error(e) if defined?(Rollbar)
39+
40+
render json: { error: e.message }, status: :unprocessable_entity
3741
end
3842

3943
def build_new_cookie_signatures_json(submitter, attachment)

app/controllers/console_redirect_controller.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ def index
1717
scope: :console,
1818
exp: 1.minute.from_now.to_i)
1919

20-
path = Addressable::URI.parse(params[:redir]).path if params[:redir].to_s.starts_with?(Docuseal::CONSOLE_URL)
20+
redir_uri = Addressable::URI.parse(params[:redir])
21+
path = redir_uri.path if params[:redir].to_s.starts_with?(Docuseal::CONSOLE_URL)
2122

22-
redirect_to("#{Docuseal::CONSOLE_URL}#{path}?#{{ auth: }.to_query}", allow_other_host: true)
23+
redirect_to "#{Docuseal::CONSOLE_URL}#{path}?#{{ **redir_uri&.query_values, 'auth' => auth }.to_query}",
24+
allow_other_host: true
2325
end
2426
end

app/controllers/send_submission_email_controller.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def create
2929

3030
RateLimit.call("send-email-#{@submitter.id}", limit: 2, ttl: 5.minutes)
3131

32-
SubmitterMailer.documents_copy_email(@submitter, sig: true).deliver_later! unless already_sent?(@submitter)
32+
SubmitterMailer.documents_copy_email(@submitter, sig: true).deliver_later! if can_send?(@submitter)
3333

3434
respond_to do |f|
3535
f.html { render :success }
@@ -39,8 +39,11 @@ def create
3939

4040
private
4141

42-
def already_sent?(submitter)
43-
EmailEvent.exists?(tag: :submitter_documents_copy, email: submitter.email, emailable: submitter,
44-
event_type: :send, created_at: SEND_DURATION.ago..Time.current)
42+
def can_send?(submitter)
43+
return false if submitter.account.archived_at?
44+
return false if EmailEvent.exists?(tag: :submitter_documents_copy, email: submitter.email, emailable: submitter,
45+
event_type: :send, created_at: SEND_DURATION.ago..Time.current)
46+
47+
true
4548
end
4649
end

app/controllers/submissions_preview_controller.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ def show
4141

4242
def completed
4343
@submission = Submission.find_by!(slug: params[:submissions_preview_slug])
44+
45+
raise ActionController::RoutingError, I18n.t('not_found') if @submission.account.archived_at?
46+
4447
@template = @submission.template
4548

4649
render :completed, layout: 'form'

app/controllers/submit_form_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ def update
7575
render json: { error: e.message }, status: :unprocessable_content
7676
end
7777

78-
def completed; end
78+
def completed
79+
raise ActionController::RoutingError, I18n.t('not_found') if @submitter.account.archived_at?
80+
end
7981

8082
def success; end
8183

0 commit comments

Comments
 (0)