diff --git a/app/controllers/assets_controller.rb b/app/controllers/assets_controller.rb index 89a8f7cef..90aad0d11 100644 --- a/app/controllers/assets_controller.rb +++ b/app/controllers/assets_controller.rb @@ -23,7 +23,7 @@ class AssetsController < ApplicationController 'type' => @asset.file.metadata[:asset_type] || (@asset.image? ? 'image' : 'file'), 'filename' => truncate(escape_input(@asset.file_name), length: Constants::FILENAME_TRUNCATION_LENGTH), - 'download-url' => rails_blob_path(@asset.file, disposition: 'attachment') + 'download-url' => asset_file_url_path(@asset) } can_edit = if @assoc.class == Step @@ -94,6 +94,12 @@ class AssetsController < ApplicationController return edit_supported, title end + def file_url + return render_404 unless @asset.file.attached? + + render plain: @asset.file.blob.service_url + end + def edit action = @asset.file_size.zero? && !@asset.locked? ? 'editnew' : 'edit' @action_url = append_wd_params(@asset.get_action_url(current_user, action, false)) @@ -139,8 +145,8 @@ class AssetsController < ApplicationController render_html = if @asset.step assets = @asset.step.assets - order_atoz = az_ordered_assets_index(assets, @asset.id) - order_ztoa = assets.length - az_ordered_assets_index(assets, @asset.id) + order_atoz = az_ordered_assets_index(@asset.step, @asset.id) + order_ztoa = assets.length - az_ordered_assets_index(@asset.step, @asset.id) asset_position = @asset.step.asset_position(@asset) render_to_string( partial: 'steps/attachments/item.html.erb', diff --git a/app/controllers/concerns/assets_actions.rb b/app/controllers/concerns/assets_actions.rb index de32d2f6b..a7c769730 100644 --- a/app/controllers/concerns/assets_actions.rb +++ b/app/controllers/concerns/assets_actions.rb @@ -14,7 +14,7 @@ module AssetsActions default_step_items = { step: asset.step.id, step_position: { id: asset.step.id, value_for: 'position_plus_one' }, - asset_name: { id: asset.id, value_for: 'file_file_name' }, + asset_name: { id: asset.id, value_for: 'file_name' }, action: action } if protocol.in_module? project = protocol.my_module.experiment.project @@ -45,7 +45,7 @@ module AssetsActions project: my_module.experiment.project, message_items: { result: asset.result.id, - asset_name: { id: asset.id, value_for: 'file_file_name' }, + asset_name: { id: asset.id, value_for: 'file_name' }, action: action }) end diff --git a/app/helpers/my_modules_helper.rb b/app/helpers/my_modules_helper.rb index 698015546..682be72b5 100644 --- a/app/helpers/my_modules_helper.rb +++ b/app/helpers/my_modules_helper.rb @@ -13,12 +13,12 @@ module MyModulesHelper view_state = step.current_view_state(current_user) sort = case view_state.state.dig('assets', 'sort') when 'old' then { created_at: :asc } - when 'atoz' then { file_file_name: :asc } - when 'ztoa' then { file_file_name: :desc } + when 'atoz' then { 'active_storage_blobs.filename': :asc } + when 'ztoa' then { 'active_storage_blobs.filename': :desc } else { created_at: :desc } end - step.assets.order(sort) + step.assets.joins(file_attachment: :blob).order(sort) end def az_ordered_assets_index(step, asset_id) diff --git a/app/helpers/repository_datatable_helper.rb b/app/helpers/repository_datatable_helper.rb index 0859f5338..43da17907 100644 --- a/app/helpers/repository_datatable_helper.rb +++ b/app/helpers/repository_datatable_helper.rb @@ -41,7 +41,7 @@ module RepositoryDatatableHelper def display_cell_value(cell, team) if cell.value_type == 'RepositoryAssetValue' # Return simple file_name if we call this method not from controller - return cell.value.asset.file_file_name unless defined?(render) + return cell.value.asset.file_name unless defined?(render) render partial: 'shared/asset_link', locals: { asset: cell.value.asset, display_image_tag: false }, formats: :html diff --git a/app/models/experiment.rb b/app/models/experiment.rb index 5410a8838..65c6fe8e8 100644 --- a/app/models/experiment.rb +++ b/app/models/experiment.rb @@ -223,12 +223,6 @@ class Experiment < ApplicationRecord workflowimg.service.exist?(workflowimg.blob.key) end - def workflowimg_file_name - return '' unless workflowimg.attached? - - workflowimg.blob&.filename&.sanitized - end - # Get projects where user is either owner or user in the same team # as this experiment def projects_with_role_above_user(current_user) diff --git a/app/models/repository_asset_value.rb b/app/models/repository_asset_value.rb index eb63be53e..a8c93e62f 100644 --- a/app/models/repository_asset_value.rb +++ b/app/models/repository_asset_value.rb @@ -17,8 +17,8 @@ class RepositoryAssetValue < ApplicationRecord validates :asset, :repository_cell, presence: true - SORTABLE_COLUMN_NAME = 'assets.file_file_name' - SORTABLE_VALUE_INCLUDE = { repository_asset_value: :asset }.freeze + SORTABLE_COLUMN_NAME = 'active_storage_blobs.filename' + SORTABLE_VALUE_INCLUDE = { repository_asset_value: { asset: { file_attachment: :blob } } }.freeze def formatted asset.file_name diff --git a/app/services/reports/docx/draw_result_asset.rb b/app/services/reports/docx/draw_result_asset.rb index b9b84a3dc..2548a6bfe 100644 --- a/app/services/reports/docx/draw_result_asset.rb +++ b/app/services/reports/docx/draw_result_asset.rb @@ -13,7 +13,7 @@ module DrawResultAsset @docx.p do text result.name, italic: true text ' ' + I18n.t('search.index.archived'), color: color[:gray] if result.archived? - text ' ' + I18n.t('projects.reports.elements.result_asset.file_name', file: asset.file_file_name) + text ' ' + I18n.t('projects.reports.elements.result_asset.file_name', file: asset.file_name) text ' ' + I18n.t('projects.reports.elements.result_asset.user_time', user: result.user.full_name, timestamp: I18n.l(timestamp, format: :full)), color: color[:gray] end diff --git a/app/services/reports/docx/draw_step_asset.rb b/app/services/reports/docx/draw_step_asset.rb index cb970ee01..8b2c114b1 100644 --- a/app/services/reports/docx/draw_step_asset.rb +++ b/app/services/reports/docx/draw_step_asset.rb @@ -10,7 +10,7 @@ module DrawStepAsset color = @color @docx.p @docx.p do - text (I18n.t 'projects.reports.elements.step_asset.file_name', file: asset.file_file_name), italic: true + text (I18n.t 'projects.reports.elements.step_asset.file_name', file: asset.file_name), italic: true text ' ' text I18n.t('projects.reports.elements.step_asset.user_time', timestamp: I18n.l(timestamp, format: :full)), color: color[:gray] diff --git a/app/views/shared/_asset_link_placeholder.html.erb b/app/views/shared/_asset_link_placeholder.html.erb deleted file mode 100644 index d4bdd0093..000000000 --- a/app/views/shared/_asset_link_placeholder.html.erb +++ /dev/null @@ -1,19 +0,0 @@ -<% if asset.file.processing? && display_image_tag && asset.is_image? %> - <%= image_tag 'medium/processing.gif' %> - - <%= truncate(asset.file_file_name, length: Constants::FILENAME_TRUNCATION_LENGTH) %> - -<% else %> - <% if asset.is_image? && display_image_tag %> - <%= image_tag asset.url(:medium) %> - <% end %> - <% if display_image_tag %> -
- <%= truncate(asset.file_file_name, length: Constants::FILENAME_TRUNCATION_LENGTH) %> -
- <% else %> - - <%= truncate(asset.file_file_name, length: Constants::FILENAME_TRUNCATION_LENGTH) %> - - <% end %> -<% end %> diff --git a/app/views/steps/attachments/_list.html.erb b/app/views/steps/attachments/_list.html.erb index 0d619d9ce..bdf7e1342 100644 --- a/app/views/steps/attachments/_list.html.erb +++ b/app/views/steps/attachments/_list.html.erb @@ -15,7 +15,7 @@ <% if !(preview) && (can_manage_protocol_in_module?(@protocol) || can_manage_protocol_in_repository?(@protocol)) %> <%= render partial: '/assets/marvinjs/create_marvin_sketch_button.html.erb', - locals: { element_id: step.id, element_type: 'Step', sketch_container: ".attachments#att-#{step.id}" } %> + locals: { element_id: step.id, element_type: 'Step', sketch_container: ".attachments#att-#{step.id}" } %> <%= render partial: '/assets/wopi/create_wopi_file_button.html.erb', locals: { element_id: step.id, element_type: 'Step' } %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 16449a228..56a466918 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -598,6 +598,7 @@ Rails.application.routes.draw do as: 'asset_file_preview' get 'files/:id/preview', to: 'assets#preview', as: 'preview_asset' get 'files/:id/view', to: 'assets#view', as: 'view_asset' + get 'files/:id/file_url', to: 'assets#file_url', as: 'asset_file_url' get 'files/:id/edit', to: 'assets#edit', as: 'edit_asset' post 'files/:id/update_image', to: 'assets#update_image', as: 'update_asset_image' diff --git a/spec/services/experiments/generate_workflow_image_service_spec.rb b/spec/services/experiments/generate_workflow_image_service_spec.rb index d9b4382de..cafd02326 100644 --- a/spec/services/experiments/generate_workflow_image_service_spec.rb +++ b/spec/services/experiments/generate_workflow_image_service_spec.rb @@ -12,10 +12,10 @@ describe Experiments::GenerateWorkflowImageService do end it 'worklfow image of experiment is updated' do - old_filename = experiment.workflowimg_file_name + old_filename = experiment.workflowimg.blob.filename described_class.call(params) experiment.reload - expect(experiment.workflowimg_file_name).not_to be == old_filename + expect(experiment.workflowimg.blob.filename).not_to be == old_filename end end end