ActiveStorage fixies after latest master merge [SCI-3757]

This commit is contained in:
Oleksii Kriuchykhin 2019-08-09 14:56:00 +02:00
parent 6e5f078dea
commit c352a73d79
12 changed files with 23 additions and 41 deletions

View file

@ -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',

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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]

View file

@ -1,19 +0,0 @@
<% if asset.file.processing? && display_image_tag && asset.is_image? %>
<%= image_tag 'medium/processing.gif' %>
<span>
<%= truncate(asset.file_file_name, length: Constants::FILENAME_TRUNCATION_LENGTH) %>
</span>
<% else %>
<% if asset.is_image? && display_image_tag %>
<%= image_tag asset.url(:medium) %>
<% end %>
<% if display_image_tag %>
<p>
<%= truncate(asset.file_file_name, length: Constants::FILENAME_TRUNCATION_LENGTH) %>
</p>
<% else %>
<span>
<%= truncate(asset.file_file_name, length: Constants::FILENAME_TRUNCATION_LENGTH) %>
</span>
<% end %>
<% end %>

View file

@ -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 %>

View file

@ -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'

View file

@ -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