From 9f1c668a10adc1b61391641785265f0cdf5cbd4c Mon Sep 17 00:00:00 2001 From: ajugo Date: Tue, 17 Oct 2023 11:35:16 +0200 Subject: [PATCH] Fix result assets download for shareable links [SCI-9542] (#6460) --- .../my_module_shareable_links_controller.rb | 26 +++++-------------- app/models/my_module.rb | 2 +- .../shareable_links/my_modules/_step.html.erb | 2 +- .../my_modules/results/_result.html.erb | 2 +- .../step_attachments/_context_menu.html.erb | 2 +- .../step_attachments/_file_preview.html.erb | 17 +++--------- .../step_attachments/_thumbnail.html.erb | 2 +- config/routes.rb | 7 ++--- 8 files changed, 17 insertions(+), 43 deletions(-) diff --git a/app/controllers/my_module_shareable_links_controller.rb b/app/controllers/my_module_shareable_links_controller.rb index 2104255a1..ff67f30de 100644 --- a/app/controllers/my_module_shareable_links_controller.rb +++ b/app/controllers/my_module_shareable_links_controller.rb @@ -4,29 +4,25 @@ class MyModuleShareableLinksController < ApplicationController before_action :load_my_module, except: %i(protocol_show repository_index_dt repository_snapshot_index_dt - download_step_asset - download_result_asset + download_asset results_show) before_action :check_view_permissions, only: :show before_action :check_manage_permissions, except: %i(protocol_show repository_index_dt repository_snapshot_index_dt - download_step_asset - download_result_asset + download_asset results_show) before_action :shareable_link_load_my_module, only: %i(protocol_show repository_index_dt repository_snapshot_index_dt - download_step_asset - download_result_asset + download_asset results_show) before_action :load_repository, only: :repository_index_dt before_action :load_repository_snapshot, only: :repository_snapshot_index_dt skip_before_action :authenticate_user!, only: %i(protocol_show repository_index_dt repository_snapshot_index_dt - download_step_asset - download_result_asset + download_asset results_show) skip_before_action :verify_authenticity_token, only: %i(protocol_show repository_index_dt @@ -98,17 +94,9 @@ class MyModuleShareableLinksController < ApplicationController render 'repository_rows/simple_view_index' end - def download_step_asset - @asset = @my_module.assets_in_steps.find_by(id: params[:id]) - - return render_404 if @asset.blank? - - redirect_to @asset.file.url(expires_in: Constants::URL_SHORT_EXPIRE_TIME.minutes, disposition: 'attachment'), - allow_other_host: true - end - - def download_result_asset - @asset = @my_module.assets_in_results.find_by(id: params[:id]) + def download_asset + @asset = @my_module.assets_in_steps.find_by(id: params[:id]) || + @my_module.assets_in_results.find_by(id: params[:id]) return render_404 if @asset.blank? diff --git a/app/models/my_module.rb b/app/models/my_module.rb index 15b53b201..95537bfff 100644 --- a/app/models/my_module.rb +++ b/app/models/my_module.rb @@ -71,7 +71,7 @@ class MyModule < ApplicationRecord 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 + has_many :assets_in_results, class_name: 'Asset', source: :assets, through: :results # Associations for old activity type has_many :activities, inverse_of: :my_module diff --git a/app/views/shareable_links/my_modules/_step.html.erb b/app/views/shareable_links/my_modules/_step.html.erb index a93b51b13..16a7ab55d 100644 --- a/app/views/shareable_links/my_modules/_step.html.erb +++ b/app/views/shareable_links/my_modules/_step.html.erb @@ -52,7 +52,7 @@ <% end %> <% end %> <% if step.step_assets.present? %> - <%= render partial: "shareable_links/my_modules/attachments", locals: { attachments: step.assets, step: step } %> + <%= render partial: "shareable_links/my_modules/attachments", locals: { attachments: step.assets } %> <% end %> diff --git a/app/views/shareable_links/my_modules/results/_result.html.erb b/app/views/shareable_links/my_modules/results/_result.html.erb index 32a78c7e9..6fa3604b5 100644 --- a/app/views/shareable_links/my_modules/results/_result.html.erb +++ b/app/views/shareable_links/my_modules/results/_result.html.erb @@ -34,7 +34,7 @@ <% end %> <% end %> <% if result.result_assets.present? %> - <%= render partial: "shareable_links/my_modules/attachments", locals: { attachments: result.assets, step: result } %> + <%= render partial: "shareable_links/my_modules/attachments", locals: { attachments: result.assets } %> <% end %> diff --git a/app/views/shareable_links/my_modules/step_attachments/_context_menu.html.erb b/app/views/shareable_links/my_modules/step_attachments/_context_menu.html.erb index e97a2783c..bef5c80df 100644 --- a/app/views/shareable_links/my_modules/step_attachments/_context_menu.html.erb +++ b/app/views/shareable_links/my_modules/step_attachments/_context_menu.html.erb @@ -5,7 +5,7 @@