From c61a075818d3d2a4a242eca6bd1bf33795b6ded6 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Fri, 4 Aug 2023 15:09:59 +0200 Subject: [PATCH] Fix file URL generation on shared task page [SCI-8974] --- app/controllers/my_module_shareable_links_controller.rb | 7 +++---- app/models/my_module.rb | 3 +++ .../my_modules/step_attachments/_file_preview.html.erb | 6 +++--- .../my_modules/step_attachments/_inline.html.erb | 2 +- .../my_modules/step_attachments/_thumbnail.html.erb | 2 +- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/controllers/my_module_shareable_links_controller.rb b/app/controllers/my_module_shareable_links_controller.rb index 266d794cd..1a566ff5c 100644 --- a/app/controllers/my_module_shareable_links_controller.rb +++ b/app/controllers/my_module_shareable_links_controller.rb @@ -68,7 +68,8 @@ class MyModuleShareableLinksController < ApplicationController end def download_asset - redirect_to @asset.file.url(disposition: 'attachment') + redirect_to @asset.file.url(expires_in: Constants::URL_SHORT_EXPIRE_TIME.minutes, disposition: 'attachment'), + allow_other_host: true end def create @@ -119,9 +120,7 @@ class MyModuleShareableLinksController < ApplicationController end def load_asset - @asset = Asset.joins(step: { protocol: :my_module }) - .find_by(my_modules: { id: @my_module.id }, - assets: { id: params[:id] }) + @asset = @my_module.assets_in_steps.find_by(id: params[:id]) return render_404 if @asset.blank? end diff --git a/app/models/my_module.rb b/app/models/my_module.rb index 11e0e5ee8..15b53b201 100644 --- a/app/models/my_module.rb +++ b/app/models/my_module.rb @@ -69,6 +69,9 @@ class MyModule < ApplicationRecord has_many :designated_users, through: :user_my_modules, source: :user has_many :report_elements, inverse_of: :my_module, dependent: :destroy has_many :protocols, inverse_of: :my_module, dependent: :destroy + has_many :steps, through: :protocols + has_many :assets_in_steps, class_name: 'Asset', source: :assets, through: :steps + has_many :assets_in_results, class_name: 'Asset', source: :asset, through: :results # Associations for old activity type has_many :activities, inverse_of: :my_module diff --git a/app/views/shareable_links/my_modules/step_attachments/_file_preview.html.erb b/app/views/shareable_links/my_modules/step_attachments/_file_preview.html.erb index 414e29dc1..347cfd96a 100644 --- a/app/views/shareable_links/my_modules/step_attachments/_file_preview.html.erb +++ b/app/views/shareable_links/my_modules/step_attachments/_file_preview.html.erb @@ -22,7 +22,7 @@