Skip to content

Commit 744d45d

Browse files
authored
Merge from docusealco/wip
2 parents daaa289 + 310b16f commit 744d45d

35 files changed

Lines changed: 166 additions & 111 deletions

app/controllers/api/active_storage_blobs_proxy_controller.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,15 @@ def show
3333
else
3434
http_cache_forever public: true do
3535
response.headers['Accept-Ranges'] = 'bytes'
36-
response.headers['Content-Length'] = blob.byte_size.to_s
3736

38-
send_blob_stream blob, disposition: params[:disposition]
37+
if request.head?
38+
response.headers['Content-Type'] = blob.content_type_for_serving
39+
head :ok
40+
else
41+
send_blob_stream blob, disposition: params[:disposition]
42+
end
43+
44+
response.headers['Content-Length'] = blob.byte_size.to_s
3945
end
4046
end
4147
end
@@ -57,8 +63,6 @@ def authorization_check!(attachment, record, exp)
5763
return if !require_ttl && !require_auth
5864
end
5965

60-
Rollbar.error('Blob unauthorized') if defined?(Rollbar)
61-
6266
raise CanCan::AccessDenied
6367
end
6468
end

app/controllers/api/submitters_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,15 @@ def assign_preferences(submitter, attrs)
203203

204204
submitter.preferences['send_sms'] = submitter_preferences['send_sms'] if submitter_preferences.key?('send_sms')
205205
submitter.preferences['reply_to'] = submitter_preferences['reply_to'] if submitter_preferences.key?('reply_to')
206+
206207
if submitter_preferences.key?('require_phone_2fa')
207208
submitter.preferences['require_phone_2fa'] = submitter_preferences['require_phone_2fa']
208209
end
209210

211+
if submitter_preferences.key?('require_email_2fa')
212+
submitter.preferences['require_email_2fa'] = submitter_preferences['require_email_2fa']
213+
end
214+
210215
if submitter_preferences.key?('go_to_last')
211216
submitter.preferences['go_to_last'] = submitter_preferences['go_to_last']
212217
end

app/controllers/preview_document_page_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def show
4141
end
4242

4343
def find_or_create_document_tempfile_path(attachment)
44-
file_path = "#{Dir.tmpdir}/#{attachment.uuid}"
44+
file_path = "#{Dir.tmpdir}/attachment-#{Digest::SHA1.hexdigest("#{attachment.id}-#{attachment.uuid}")}"
4545

4646
File.open(file_path, File::RDWR | File::CREAT, 0o644) do |f|
4747
f.flock(File::LOCK_EX)

app/controllers/reveal_access_token_controller.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# frozen_string_literal: true
22

33
class RevealAccessTokenController < ApplicationController
4+
rate_limit to: 4, within: 1.minute, only: %i[create], by: -> { current_user.id }, with: lambda {
5+
Rollbar.error('Rate limit api key') if defined?(Rollbar)
6+
7+
render turbo_stream: turbo_stream.replace(:modal, template: 'reveal_access_token/show',
8+
locals: { error_message: I18n.t(:too_many_attempts) }),
9+
status: :unprocessable_content
10+
}
11+
412
def show
513
authorize!(:manage, current_user.access_token)
614
end

app/controllers/send_submission_email_controller.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def create
1414
template = Template.find_by!(slug: params[:template_slug])
1515

1616
@submitter =
17-
Submitter.completed.where(submission: template.submissions).find_by!(email: params[:email].to_s.downcase)
17+
Submitter.completed.where(submission: template.submissions).find_by(email: params[:email].to_s.downcase)
1818
elsif params[:submission_slug]
1919
submission = Submission.find_by(slug: params[:submission_slug])
2020

@@ -27,9 +27,11 @@ def create
2727
@submitter = Submitter.completed.find_by!(slug: params[:submitter_slug])
2828
end
2929

30-
RateLimit.call("send-email-#{@submitter.id}", limit: 2, ttl: 5.minutes)
30+
if @submitter
31+
RateLimit.call("send-email-#{@submitter.id}", limit: 2, ttl: 5.minutes)
3132

32-
SubmitterMailer.documents_copy_email(@submitter, sig: true).deliver_later! if can_send?(@submitter)
33+
SubmitterMailer.documents_copy_email(@submitter, sig: true).deliver_later! if can_send?(@submitter)
34+
end
3335

3436
respond_to do |f|
3537
f.html { render :success }

app/controllers/templates_controller.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
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+
48
load_and_authorize_resource :template
59

610
def show
@@ -33,10 +37,11 @@ def edit
3337
).call
3438

3539
@template_data =
36-
@template.as_json.merge(
40+
@template.as_json(only: TEMPLATE_FIELDS).merge(
3741
documents: @template.schema_documents.as_json(
42+
only: %i[id uuid],
3843
methods: %i[metadata signed_key],
39-
include: { preview_images: { methods: %i[url metadata filename] } }
44+
include: { preview_images: { only: %i[id], methods: %i[url metadata filename] } }
4045
)
4146
).to_json
4247

app/controllers/testing_accounts_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class TestingAccountsController < ApplicationController
44
skip_authorization_check only: :destroy
55

6-
def show
6+
def create
77
authorize!(:manage, current_account)
88
authorize!(:manage, current_user)
99

app/javascript/draw.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ window.customElements.define('draw-signature', class extends HTMLElement {
1111
this.resizeObserver = new ResizeObserver(() => {
1212
requestAnimationFrame(() => {
1313
if (!this.canvas) return
14+
if (!this.canvas.parentNode?.clientWidth) return
1415

1516
const { width, height } = this.canvas
1617

@@ -89,7 +90,7 @@ window.customElements.define('draw-signature', class extends HTMLElement {
8990
}
9091

9192
redrawCanvas (oldWidth, oldHeight) {
92-
if (this.pad && !this.pad.isEmpty() && oldWidth > 0 && oldHeight > 0) {
93+
if (this.pad && !this.pad.isEmpty() && oldWidth > 0 && oldHeight > 0 && this.canvas.width > 0 && this.canvas.height > 0) {
9394
const sx = this.canvas.width / oldWidth
9495
const sy = this.canvas.height / oldHeight
9596

app/javascript/elements/signature_form.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default targetable(class extends HTMLElement {
1414
this.resizeObserver = new ResizeObserver(() => {
1515
requestAnimationFrame(() => {
1616
if (!this.canvas) return
17+
if (!this.canvas.parentNode?.clientWidth) return
1718

1819
const { width, height } = this.canvas
1920

@@ -80,7 +81,7 @@ export default targetable(class extends HTMLElement {
8081
}
8182

8283
redrawCanvas (oldWidth, oldHeight) {
83-
if (this.pad && !this.pad.isEmpty() && oldWidth > 0 && oldHeight > 0) {
84+
if (this.pad && !this.pad.isEmpty() && oldWidth > 0 && oldHeight > 0 && this.canvas.width > 0 && this.canvas.height > 0) {
8485
const sx = this.canvas.width / oldWidth
8586
const sy = this.canvas.height / oldHeight
8687

app/javascript/submission_form/appears_on.vue

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,25 @@ export default {
4242
const areas = {}
4343
4444
this.field.areas?.forEach((area) => {
45-
areas[area.attachment_uuid + area.page] ||= area
45+
areas[area.attachment_uuid] ||= []
46+
areas[area.attachment_uuid].push(area)
4647
})
4748
48-
return Object.values(areas).slice(0, 6)
49+
const sortedAreas = Object.values(areas).reduce((acc, group) => {
50+
const seen = {}
51+
const sortedGroup = [...group].sort((a, b) => a.page - b.page)
52+
53+
sortedGroup.forEach((area) => {
54+
if (!seen[area.page]) {
55+
seen[area.page] = true
56+
acc.push(area)
57+
}
58+
})
59+
60+
return acc
61+
}, [])
62+
63+
return sortedAreas.slice(0, 6)
4964
}
5065
}
5166
}

0 commit comments

Comments
 (0)