Merge pull request #5919 from okriuchykhin/ok_SCI_8974

Fix file URL generation on shared task page [SCI-8974]
This commit is contained in:
ajugo 2023-08-07 08:56:05 +02:00 committed by GitHub
commit 9a55889264
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 9 deletions

View file

@ -72,7 +72,8 @@ class MyModuleShareableLinksController < ApplicationController
end end
def download_asset 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 end
def create def create
@ -123,9 +124,7 @@ class MyModuleShareableLinksController < ApplicationController
end end
def load_asset def load_asset
@asset = Asset.joins(step: { protocol: :my_module }) @asset = @my_module.assets_in_steps.find_by(id: params[:id])
.find_by(my_modules: { id: @my_module.id },
assets: { id: params[:id] })
return render_404 if @asset.blank? return render_404 if @asset.blank?
end end

View file

@ -69,6 +69,9 @@ class MyModule < ApplicationRecord
has_many :designated_users, through: :user_my_modules, source: :user has_many :designated_users, through: :user_my_modules, source: :user
has_many :report_elements, inverse_of: :my_module, dependent: :destroy has_many :report_elements, inverse_of: :my_module, dependent: :destroy
has_many :protocols, 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 # Associations for old activity type
has_many :activities, inverse_of: :my_module has_many :activities, inverse_of: :my_module

View file

@ -22,7 +22,7 @@
</div> </div>
<div class="modal-body"> <div class="modal-body">
<div class="file-preview-container"> <div class="file-preview-container">
<% if asset.previewable? %> <% if asset.previewable? && !asset.file_processing %>
<% if wopi_enabled? && wopi_file?(asset) %> <% if wopi_enabled? && wopi_file?(asset) %>
<iframe class="wopi-file-preview" src="<%= asset.get_action_url(nil, 'embedview', false) %>"></iframe> <iframe class="wopi-file-preview" src="<%= asset.get_action_url(nil, 'embedview', false) %>"></iframe>
<% elsif asset.pdf_previewable? %> <% elsif asset.pdf_previewable? %>
@ -46,7 +46,7 @@
class: "previous-asset shareable-gallery-switcher", class: "previous-asset shareable-gallery-switcher",
data: { id: previous_asset.id } do %> data: { id: previous_asset.id } do %>
<i class="sn-icon sn-icon-arrow-left"></i> <i class="sn-icon sn-icon-arrow-left"></i>
<% if previous_asset.previewable? %> <% if previous_asset.previewable? && !previous_asset.file_processing %>
<%= image_tag previous_asset.file.representation(resize_to_limit: Constants::MEDIUM_PIC_FORMAT).url(expires_in: Constants::URL_SHORT_EXPIRE_TIME.minutes), <%= image_tag previous_asset.file.representation(resize_to_limit: Constants::MEDIUM_PIC_FORMAT).url(expires_in: Constants::URL_SHORT_EXPIRE_TIME.minutes),
class: 'asset-image', class: 'asset-image',
style: 'opacity: 0' %> style: 'opacity: 0' %>
@ -63,7 +63,7 @@
<%= link_to '#', <%= link_to '#',
class: "next-asset shareable-gallery-switcher", class: "next-asset shareable-gallery-switcher",
data: { id: next_asset.id } do %> data: { id: next_asset.id } do %>
<% if next_asset.previewable? %> <% if next_asset.previewable? && !next_asset.file_processing %>
<%= image_tag next_asset.file.representation(resize_to_limit: Constants::MEDIUM_PIC_FORMAT).url(expires_in: Constants::URL_SHORT_EXPIRE_TIME.minutes), <%= image_tag next_asset.file.representation(resize_to_limit: Constants::MEDIUM_PIC_FORMAT).url(expires_in: Constants::URL_SHORT_EXPIRE_TIME.minutes),
class: 'asset-image', class: 'asset-image',
style: 'opacity: 0' %> style: 'opacity: 0' %>

View file

@ -25,7 +25,7 @@
<iframe class="wopi-file-preview" src="<%= asset.get_action_url(nil, 'embedview', false) %>"></iframe> <iframe class="wopi-file-preview" src="<%= asset.get_action_url(nil, 'embedview', false) %>"></iframe>
<% elsif asset.pdf_previewable? %> <% elsif asset.pdf_previewable? %>
<%= render partial: 'shared/pdf_viewer', locals: { asset: asset, report_document: false, shareable_document: true } %> <%= render partial: 'shared/pdf_viewer', locals: { asset: asset, report_document: false, shareable_document: true } %>
<% elsif asset.previewable? %> <% elsif asset.previewable? && !asset.file_processing %>
<div class="image-container"> <div class="image-container">
<%= image_tag asset.file.representation(resize_to_limit: Constants::LARGE_PIC_FORMAT).url(expires_in: Constants::URL_SHORT_EXPIRE_TIME.minutes), <%= image_tag asset.file.representation(resize_to_limit: Constants::LARGE_PIC_FORMAT).url(expires_in: Constants::URL_SHORT_EXPIRE_TIME.minutes),
class: 'asset-preview-image', class: 'asset-preview-image',

View file

@ -7,7 +7,7 @@
id: asset.id id: asset.id
} do %> } do %>
<div class="attachment-preview <%= asset.file.attached? ? asset.file.metadata['asset_type'] : '' %>"> <div class="attachment-preview <%= asset.file.attached? ? asset.file.metadata['asset_type'] : '' %>">
<% if asset.previewable? %> <% if asset.previewable? && !asset.file_processing %>
<%= image_tag asset.file.representation(resize_to_limit: Constants::MEDIUM_PIC_FORMAT).url(expires_in: Constants::URL_SHORT_EXPIRE_TIME.minutes), <%= image_tag asset.file.representation(resize_to_limit: Constants::MEDIUM_PIC_FORMAT).url(expires_in: Constants::URL_SHORT_EXPIRE_TIME.minutes),
class: 'asset-preview-image', class: 'asset-preview-image',
style: 'opacity: 0' %> style: 'opacity: 0' %>