Skip to content

Commit 9b935a8

Browse files
authored
Merge from docusealco/wip
2 parents 21299dc + c4a6938 commit 9b935a8

33 files changed

Lines changed: 242 additions & 92 deletions

app/controllers/account_configs_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class AccountConfigsController < ApplicationController
1515
AccountConfig::ESIGNING_PREFERENCE_KEY,
1616
AccountConfig::FORM_WITH_CONFETTI_KEY,
1717
AccountConfig::DOWNLOAD_LINKS_AUTH_KEY,
18+
AccountConfig::DOWNLOAD_LINKS_EXPIRE_KEY,
1819
AccountConfig::FORCE_SSO_AUTH_KEY,
1920
AccountConfig::FLATTEN_RESULT_PDF_KEY,
2021
AccountConfig::ENFORCE_SIGNING_ORDER_KEY,

app/controllers/api/active_storage_blobs_proxy_controller.rb

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ActiveStorageBlobsProxyController < ApiBaseController
1313
def show
1414
blob_uuid, purp, exp = ApplicationRecord.signed_id_verifier.verified(params[:signed_uuid])
1515

16-
if blob_uuid.blank? || (purp.present? && purp != 'blob') || (exp && exp < Time.current.to_i)
16+
if blob_uuid.blank? || purp != 'blob'
1717
Rollbar.error('Blob not found') if defined?(Rollbar)
1818

1919
return head :not_found
@@ -24,8 +24,9 @@ def show
2424
attachment = blob.attachments.take
2525

2626
@record = attachment.record
27+
@record = @record.record if @record.is_a?(ActiveStorage::Attachment)
2728

28-
authorization_check!(attachment) if exp.blank?
29+
authorization_check!(attachment, @record, exp)
2930

3031
if request.headers['Range'].present?
3132
send_blob_byte_range_data blob, request.headers['Range']
@@ -41,14 +42,19 @@ def show
4142

4243
private
4344

44-
def authorization_check!(attachment)
45-
is_authorized = attachment.name.in?(%w[logo preview_images]) ||
46-
(current_user && attachment.record.account.id == current_user.account_id) ||
47-
(current_user && !Docuseal.multitenant? && current_user.role == 'superadmin') ||
48-
!attachment.record.account.account_configs
49-
.find_or_initialize_by(key: AccountConfig::DOWNLOAD_LINKS_AUTH_KEY).value
45+
def authorization_check!(attachment, record, exp)
46+
return if attachment.name == 'logo'
47+
return if exp.to_i >= Time.current.to_i
5048

51-
return if is_authorized
49+
return if current_user && current_ability.can?(:read, record)
50+
51+
configs = record.account.account_configs.where(key: [AccountConfig::DOWNLOAD_LINKS_AUTH_KEY,
52+
AccountConfig::DOWNLOAD_LINKS_EXPIRE_KEY])
53+
54+
require_auth = configs.any? { |c| c.key == AccountConfig::DOWNLOAD_LINKS_AUTH_KEY && c.value }
55+
require_ttl = configs.none? { |c| c.key == AccountConfig::DOWNLOAD_LINKS_EXPIRE_KEY && c.value == false }
56+
57+
return if !require_ttl && !require_auth
5258

5359
Rollbar.error('Blob aunauthorized') if defined?(Rollbar)
5460

app/controllers/api/form_events_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ def index
1818
field: :completed_at
1919
)
2020

21+
expires_at = Accounts.link_expires_at(current_account)
22+
2123
render json: {
2224
data: submitters.map do |s|
2325
{
2426
event_type: 'form.completed',
2527
timestamp: s.completed_at,
26-
data: Submitters::SerializeForWebhook.call(s)
28+
data: Submitters::SerializeForWebhook.call(s, expires_at:)
2729
}
2830
end,
2931
pagination: {

app/controllers/api/submission_documents_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ def index
3434
associations: [:blob]
3535
).call
3636

37+
expires_at = Accounts.link_expires_at(current_account)
38+
3739
render json: {
3840
id: @submission.id,
3941
documents: documents.map do |attachment|
40-
{ name: attachment.filename.base, url: ActiveStorage::Blob.proxy_url(attachment.blob) }
42+
{ name: attachment.filename.base, url: ActiveStorage::Blob.proxy_url(attachment.blob, expires_at:) }
4143
end
4244
}
4345
end

app/controllers/api/submission_events_controller.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,19 @@ def index
1414
:created_by_user, :submission_events,
1515
template: :folder,
1616
submitters: { documents_attachments: :blob, attachments_attachments: :blob },
17-
audit_trail_attachment: :blob
17+
audit_trail_attachment: :blob,
18+
combined_document_attachment: :blob
1819
),
1920
field: :completed_at)
2021

22+
expires_at = Accounts.link_expires_at(current_account)
23+
2124
render json: {
2225
data: submissions.map do |s|
2326
{
2427
event_type: 'submission.completed',
2528
timestamp: s.completed_at,
26-
data: Submissions::SerializeForApi.call(s, s.submitters)
29+
data: Submissions::SerializeForApi.call(s, s.submitters, expires_at:)
2730
}
2831
end,
2932
pagination: {

app/controllers/api/submissions_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ def index
1818
combined_document_attachment: :blob,
1919
audit_trail_attachment: :blob))
2020

21+
expires_at = Accounts.link_expires_at(current_account)
22+
2123
render json: {
2224
data: submissions.map do |s|
2325
Submissions::SerializeForApi.call(s, s.submitters, params,
24-
with_events: false, with_documents: false, with_values: false)
26+
with_events: false, with_documents: false, with_values: false, expires_at:)
2527
end,
2628
pagination: {
2729
count: submissions.size,

app/controllers/api/submitters_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ def index
1414
documents_attachments: :blob, attachments_attachments: :blob)
1515
)
1616

17+
expires_at = Accounts.link_expires_at(current_account)
18+
1719
render json: {
1820
data: submitters.map do |s|
19-
Submitters::SerializeForApi.call(s, with_template: true, with_events: true, params:)
21+
Submitters::SerializeForApi.call(s, with_template: true, with_events: true, params:, expires_at:)
2022
end,
2123
pagination: {
2224
count: submitters.size,

app/controllers/api/templates_clone_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ def create
2626
original_template: @template,
2727
documents: params[:documents])
2828

29+
Templates.maybe_assign_access(cloned_template)
30+
2931
cloned_template.save!
3032

3133
WebhookUrls.enqueue_events(cloned_template, 'template.created')
3234

3335
SearchEntries.enqueue_reindex(cloned_template)
3436

35-
render json: Templates::SerializeForApi.call(cloned_template, schema_documents)
37+
render json: Templates::SerializeForApi.call(cloned_template, schema_documents:)
3638
end
3739
end
3840
end

app/controllers/api/templates_controller.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ def index
2424
name: :preview_images)
2525
.preload(:blob)
2626

27+
expires_at = Accounts.link_expires_at(current_account)
28+
2729
render json: {
2830
data: templates.map do |t|
29-
Templates::SerializeForApi.call(
30-
t,
31-
schema_documents.select { |e| e.record_id == t.id },
32-
preview_image_attachments
33-
)
31+
Templates::SerializeForApi.call(t,
32+
schema_documents: schema_documents.select { |e| e.record_id == t.id },
33+
preview_image_attachments:,
34+
expires_at:)
3435
end,
3536
pagination: {
3637
count: templates.size,

app/controllers/submissions_export_controller.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ def index
1010
attachments_attachments: :blob })
1111
.order(id: :asc)
1212

13+
expires_at = Accounts.link_expires_at(current_account)
14+
1315
if params[:format] == 'csv'
14-
send_data Submissions::GenerateExportFiles.call(submissions, format: params[:format]),
16+
send_data Submissions::GenerateExportFiles.call(submissions, format: params[:format], expires_at:),
1517
filename: "#{@template.name}.csv"
1618
elsif params[:format] == 'xlsx'
17-
send_data Submissions::GenerateExportFiles.call(submissions, format: params[:format]),
19+
send_data Submissions::GenerateExportFiles.call(submissions, format: params[:format], expires_at:),
1820
filename: "#{@template.name}.xlsx"
1921
end
2022
end

0 commit comments

Comments
 (0)