2019-06-14 22:15:30 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
class AssetsController < ApplicationController
|
2016-09-29 21:30:55 +08:00
|
|
|
include WopiUtil
|
2019-06-19 21:19:47 +08:00
|
|
|
include AssetsActions
|
2019-11-06 22:21:56 +08:00
|
|
|
include ActiveStorage::SetCurrent
|
2017-03-13 20:20:49 +08:00
|
|
|
include ActionView::Helpers::AssetTagHelper
|
2016-12-09 20:59:49 +08:00
|
|
|
include ActionView::Helpers::TextHelper
|
2017-03-13 20:20:49 +08:00
|
|
|
include ActionView::Helpers::UrlHelper
|
|
|
|
include ActionView::Context
|
2020-12-16 19:13:42 +08:00
|
|
|
include ActiveStorageFileUtil
|
2019-05-10 22:25:18 +08:00
|
|
|
include ApplicationHelper
|
2017-03-13 20:20:49 +08:00
|
|
|
include InputSanitizeHelper
|
|
|
|
include FileIconsHelper
|
2019-07-03 21:35:49 +08:00
|
|
|
include MyModulesHelper
|
2016-09-29 21:30:55 +08:00
|
|
|
|
2020-10-22 19:41:17 +08:00
|
|
|
helper_method :wopi_file_edit_button_status
|
|
|
|
|
2019-03-16 03:59:15 +08:00
|
|
|
before_action :load_vars, except: :create_wopi_file
|
2024-03-08 18:37:35 +08:00
|
|
|
before_action :check_read_permission, except: %i(edit destroy duplicate create_wopi_file toggle_view_mode)
|
2024-03-28 18:00:14 +08:00
|
|
|
before_action :check_manage_permission, only: %i(edit destroy duplicate toggle_view_mode rename)
|
2019-05-13 22:53:58 +08:00
|
|
|
|
2018-03-30 17:50:28 +08:00
|
|
|
def file_preview
|
2020-10-22 19:41:17 +08:00
|
|
|
render json: { html: render_to_string(
|
2023-06-21 20:13:20 +08:00
|
|
|
partial: 'shared/file_preview/content',
|
2020-10-22 19:41:17 +08:00
|
|
|
locals: {
|
|
|
|
asset: @asset,
|
|
|
|
can_edit: can_manage_asset?(@asset),
|
2020-11-26 22:35:06 +08:00
|
|
|
gallery: params[:gallery],
|
|
|
|
preview: params[:preview]
|
2023-07-05 18:43:23 +08:00
|
|
|
},
|
|
|
|
formats: :html
|
2020-10-22 19:41:17 +08:00
|
|
|
) }
|
2019-03-08 19:22:35 +08:00
|
|
|
end
|
|
|
|
|
2020-08-28 17:05:52 +08:00
|
|
|
def toggle_view_mode
|
2020-09-25 21:06:09 +08:00
|
|
|
@asset.view_mode = toggle_view_mode_params[:view_mode]
|
2023-06-21 20:13:20 +08:00
|
|
|
@asset.save!(touch: false)
|
2023-10-09 19:15:54 +08:00
|
|
|
|
|
|
|
render json: AssetSerializer.new(@asset, scope: { user: current_user }).as_json
|
2020-08-28 17:05:52 +08:00
|
|
|
end
|
|
|
|
|
2021-03-22 19:55:05 +08:00
|
|
|
def load_asset
|
|
|
|
gallery_view_id = if @assoc.is_a?(Step)
|
|
|
|
@assoc.id
|
|
|
|
elsif @assoc.is_a?(Result)
|
|
|
|
@assoc.my_module.id
|
|
|
|
end
|
2023-06-21 20:13:20 +08:00
|
|
|
render json: { html: render_to_string(partial: 'assets/asset',
|
2021-03-22 19:55:05 +08:00
|
|
|
locals: {
|
|
|
|
asset: @asset,
|
|
|
|
gallery_view_id: gallery_view_id
|
2023-07-05 18:43:23 +08:00
|
|
|
},
|
|
|
|
formats: :html) }
|
2021-03-22 19:55:05 +08:00
|
|
|
end
|
|
|
|
|
2023-08-24 21:55:20 +08:00
|
|
|
def move_targets
|
|
|
|
if @assoc.is_a?(Step)
|
|
|
|
protocol = @assoc.protocol
|
2023-08-25 15:46:53 +08:00
|
|
|
render json: { targets: protocol.steps.order(:position).where.not(id: @assoc.id).map { |i| [i.id, i.name] } }
|
2023-08-24 21:55:20 +08:00
|
|
|
elsif @assoc.is_a?(Result)
|
|
|
|
my_module = @assoc.my_module
|
2023-09-29 20:32:33 +08:00
|
|
|
render json: { targets: my_module.results.active.where.not(id: @assoc.id).map { |i| [i.id, i.name] } }
|
2023-08-24 21:55:20 +08:00
|
|
|
else
|
|
|
|
render json: { targets: [] }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def move
|
2023-09-29 20:32:33 +08:00
|
|
|
case @assoc
|
|
|
|
when Step
|
|
|
|
target = @assoc.protocol.steps.find_by(id: params[:target_id])
|
|
|
|
when Result
|
|
|
|
target = @assoc.my_module.results.active.find_by(id: params[:target_id])
|
|
|
|
return render_404 unless target
|
|
|
|
end
|
|
|
|
|
2023-08-24 21:55:20 +08:00
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
if @assoc.is_a?(Step)
|
|
|
|
object_to_update = @asset.step_asset
|
|
|
|
object_to_update.update!(step: target)
|
2023-09-19 07:17:30 +08:00
|
|
|
|
|
|
|
if @assoc.protocol.in_module?
|
|
|
|
log_step_activity(
|
2023-09-19 16:50:45 +08:00
|
|
|
@asset.file.metadata[:asset_type] == 'marvinjs' ? :move_chemical_structure_on_step : :task_step_file_moved,
|
2023-09-19 07:17:30 +08:00
|
|
|
@assoc,
|
|
|
|
@assoc.my_module.project,
|
|
|
|
my_module: @assoc.my_module.id,
|
|
|
|
file: @asset.file_name,
|
|
|
|
user: current_user.id,
|
|
|
|
step_position_original: @asset.step.position + 1,
|
|
|
|
step_original: @asset.step.id,
|
|
|
|
step_position_destination: target.position + 1,
|
|
|
|
step_destination: target.id
|
|
|
|
)
|
|
|
|
else
|
|
|
|
log_step_activity(
|
2023-09-19 16:50:45 +08:00
|
|
|
@asset.file.metadata[:asset_type] == 'marvinjs' ? :move_chemical_structure_on_step_in_repository : :protocol_step_file_moved,
|
2023-09-19 07:17:30 +08:00
|
|
|
@assoc,
|
|
|
|
nil,
|
|
|
|
protocol: @assoc.protocol.id,
|
|
|
|
file: @asset.file_name,
|
|
|
|
user: current_user.id,
|
|
|
|
step_position_original: @asset.step.position + 1,
|
|
|
|
step_original: @asset.step.id,
|
|
|
|
step_position_destination: target.position + 1,
|
|
|
|
step_destination: target.id
|
|
|
|
)
|
|
|
|
end
|
2023-09-19 16:50:45 +08:00
|
|
|
|
2023-08-30 17:48:16 +08:00
|
|
|
render json: {}
|
2023-08-24 21:55:20 +08:00
|
|
|
elsif @assoc.is_a?(Result)
|
|
|
|
object_to_update = @asset.result_asset
|
|
|
|
object_to_update.update!(result: target)
|
2023-09-19 07:17:30 +08:00
|
|
|
|
2023-09-27 07:45:29 +08:00
|
|
|
type_of = {
|
|
|
|
'marvinjs' => :move_chemical_structure_on_result,
|
|
|
|
'gene_sequence' => :sequence_on_result_moved
|
|
|
|
}.fetch(@asset.file.metadata[:asset_type], :result_file_moved)
|
2023-09-27 18:47:35 +08:00
|
|
|
|
2023-09-19 07:17:30 +08:00
|
|
|
log_result_activity(
|
2023-09-27 07:45:29 +08:00
|
|
|
type_of,
|
2023-09-19 07:17:30 +08:00
|
|
|
@assoc,
|
|
|
|
file: @asset.file_name,
|
|
|
|
user: current_user.id,
|
2023-09-19 16:50:45 +08:00
|
|
|
result_original: @assoc.id,
|
2023-09-19 07:17:30 +08:00
|
|
|
result_destination: target.id
|
|
|
|
)
|
|
|
|
|
2023-08-30 17:48:16 +08:00
|
|
|
render json: {}
|
2023-08-24 21:55:20 +08:00
|
|
|
end
|
|
|
|
rescue ActiveRecord::RecordInvalid
|
|
|
|
render json: object_to_update.errors, status: :unprocessable_entity
|
2023-08-30 17:48:16 +08:00
|
|
|
raise ActiveRecord::Rollback
|
2023-08-24 21:55:20 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-09 20:56:00 +08:00
|
|
|
def file_url
|
|
|
|
return render_404 unless @asset.file.attached?
|
|
|
|
|
2023-07-12 21:42:34 +08:00
|
|
|
render plain: @asset.file.blob.url
|
2019-08-09 20:56:00 +08:00
|
|
|
end
|
|
|
|
|
2020-05-27 22:59:28 +08:00
|
|
|
def download
|
|
|
|
redirect_to rails_blob_path(@asset.file, disposition: 'attachment')
|
|
|
|
end
|
|
|
|
|
2024-02-07 18:26:40 +08:00
|
|
|
def show
|
|
|
|
if @asset
|
|
|
|
render json: @asset, serializer: AssetSerializer, user: current_user
|
|
|
|
else
|
|
|
|
render json: { error: 'Asset not found' }, status: :not_found
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-10 23:49:25 +08:00
|
|
|
def edit
|
2019-07-02 05:30:20 +08:00
|
|
|
action = @asset.file_size.zero? && !@asset.locked? ? 'editnew' : 'edit'
|
|
|
|
@action_url = append_wd_params(@asset.get_action_url(current_user, action, false))
|
2016-09-29 18:19:29 +08:00
|
|
|
@favicon_url = @asset.favicon_url('edit')
|
2016-11-30 23:48:42 +08:00
|
|
|
tkn = current_user.get_wopi_token
|
|
|
|
@token = tkn.token
|
|
|
|
@ttl = (tkn.ttl * 1000).to_s
|
2020-10-22 19:41:17 +08:00
|
|
|
@asset.step&.protocol&.update(updated_at: Time.zone.now)
|
2019-05-20 22:09:43 +08:00
|
|
|
|
2016-09-29 21:30:55 +08:00
|
|
|
create_wopi_file_activity(current_user, true)
|
2016-10-04 02:02:13 +08:00
|
|
|
|
|
|
|
render layout: false
|
2016-08-10 23:49:25 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def view
|
2019-07-02 05:30:20 +08:00
|
|
|
@action_url = append_wd_params(@asset.get_action_url(current_user, 'view', false))
|
2016-09-29 18:19:29 +08:00
|
|
|
@favicon_url = @asset.favicon_url('view')
|
2016-11-30 23:48:42 +08:00
|
|
|
tkn = current_user.get_wopi_token
|
|
|
|
@token = tkn.token
|
|
|
|
@ttl = (tkn.ttl * 1000).to_s
|
2016-10-04 02:02:13 +08:00
|
|
|
|
|
|
|
render layout: false
|
2016-08-10 23:49:25 +08:00
|
|
|
end
|
|
|
|
|
2020-12-16 19:13:42 +08:00
|
|
|
def pdf_preview
|
|
|
|
return render plain: '', status: :not_acceptable unless previewable_document?(@asset.blob)
|
|
|
|
return render plain: '', status: :accepted unless @asset.pdf_preview_ready?
|
|
|
|
|
2023-07-12 21:42:34 +08:00
|
|
|
redirect_to @asset.file_pdf_preview.url
|
2020-12-16 19:13:42 +08:00
|
|
|
end
|
|
|
|
|
2019-06-19 21:19:47 +08:00
|
|
|
def create_start_edit_image_activity
|
|
|
|
create_edit_image_activity(@asset, current_user, :start_editing)
|
2019-06-14 22:15:30 +08:00
|
|
|
end
|
|
|
|
|
2018-10-19 16:00:58 +08:00
|
|
|
def update_image
|
|
|
|
@asset = Asset.find(params[:id])
|
2019-07-02 05:30:20 +08:00
|
|
|
orig_file_size = @asset.file_size
|
|
|
|
orig_file_name = @asset.file_name
|
2018-10-19 16:00:58 +08:00
|
|
|
return render_403 unless can_read_team?(@asset.team)
|
2019-04-15 15:49:44 +08:00
|
|
|
|
2024-01-24 22:18:34 +08:00
|
|
|
@asset.last_modified_by = current_user
|
2024-02-07 22:31:13 +08:00
|
|
|
@asset.file.attach(io: params.require(:image), filename: orig_file_name)
|
2018-10-19 16:00:58 +08:00
|
|
|
@asset.save!
|
2019-06-19 21:19:47 +08:00
|
|
|
create_edit_image_activity(@asset, current_user, :finish_editing)
|
2019-04-11 15:20:05 +08:00
|
|
|
# release previous image space
|
|
|
|
@asset.team.release_space(orig_file_size)
|
2018-10-19 16:00:58 +08:00
|
|
|
# Post process file here
|
2024-02-05 23:24:06 +08:00
|
|
|
@asset.post_process_file
|
2020-10-22 19:41:17 +08:00
|
|
|
@asset.step&.protocol&.update(updated_at: Time.zone.now)
|
2018-11-16 00:52:31 +08:00
|
|
|
|
2020-12-04 18:47:24 +08:00
|
|
|
render_html = if [Result, Step].include?(@assoc.class)
|
|
|
|
gallery_view_id = if @assoc.is_a?(Step)
|
|
|
|
@assoc.id
|
|
|
|
elsif @assoc.is_a?(Result)
|
|
|
|
@assoc.my_module.id
|
|
|
|
end
|
|
|
|
|
2019-09-26 22:49:56 +08:00
|
|
|
render_to_string(
|
2023-06-21 20:13:20 +08:00
|
|
|
partial: 'assets/asset',
|
2020-12-04 18:47:24 +08:00
|
|
|
locals: {
|
|
|
|
asset: @asset,
|
|
|
|
gallery_view_id: gallery_view_id
|
|
|
|
},
|
2019-09-26 22:49:56 +08:00
|
|
|
formats: :html
|
|
|
|
)
|
2019-05-13 16:54:16 +08:00
|
|
|
else
|
|
|
|
render_to_string(
|
2023-06-21 20:13:20 +08:00
|
|
|
partial: 'assets/asset_link',
|
2019-05-13 16:54:16 +08:00
|
|
|
locals: { asset: @asset, display_image_tag: true },
|
|
|
|
formats: :html
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2023-06-21 20:13:20 +08:00
|
|
|
render json: { html: render_html }
|
2018-10-19 16:00:58 +08:00
|
|
|
end
|
|
|
|
|
2019-03-18 02:23:17 +08:00
|
|
|
# POST: create_wopi_file_path
|
2019-03-16 03:59:15 +08:00
|
|
|
def create_wopi_file
|
2019-03-18 02:23:17 +08:00
|
|
|
# Presence validation
|
2019-03-21 15:47:52 +08:00
|
|
|
params.require(%i(element_type element_id file_type))
|
2019-03-19 17:19:27 +08:00
|
|
|
|
2019-03-18 02:23:17 +08:00
|
|
|
# File type validation
|
2019-03-19 17:19:27 +08:00
|
|
|
render_403 && return unless %w(docx xlsx pptx).include?(params[:file_type])
|
2019-03-18 02:23:17 +08:00
|
|
|
|
|
|
|
# Asset validation
|
2019-10-04 20:24:19 +08:00
|
|
|
asset = Asset.new(created_by: current_user, team: current_team)
|
2019-07-02 05:30:20 +08:00
|
|
|
asset.file.attach(io: StringIO.new,
|
|
|
|
filename: "#{params[:file_name]}.#{params[:file_type]}",
|
|
|
|
content_type: wopi_content_type(params[:file_type]))
|
2019-03-18 02:23:17 +08:00
|
|
|
|
2019-03-21 15:47:52 +08:00
|
|
|
unless asset.valid?(:wopi_file_creation)
|
|
|
|
render json: {
|
|
|
|
message: asset.errors
|
2020-09-25 21:06:09 +08:00
|
|
|
}, status: :bad_request and return
|
2019-03-19 17:19:27 +08:00
|
|
|
end
|
2019-03-18 02:23:17 +08:00
|
|
|
|
2019-03-19 17:19:27 +08:00
|
|
|
# Create file depending on the type
|
2019-03-18 02:23:17 +08:00
|
|
|
if params[:element_type] == 'Step'
|
|
|
|
step = Step.find(params[:element_id].to_i)
|
2021-10-08 18:43:26 +08:00
|
|
|
render_403 && return unless can_manage_step?(step)
|
|
|
|
|
2019-03-18 02:23:17 +08:00
|
|
|
step_asset = StepAsset.create!(step: step, asset: asset)
|
2021-01-05 16:11:22 +08:00
|
|
|
asset.update!(view_mode: step.assets_view_mode)
|
2020-10-22 19:41:17 +08:00
|
|
|
step.protocol&.update(updated_at: Time.zone.now)
|
2019-03-18 02:23:17 +08:00
|
|
|
|
|
|
|
edit_url = edit_asset_url(step_asset.asset_id)
|
|
|
|
elsif params[:element_type] == 'Result'
|
2023-09-27 16:55:03 +08:00
|
|
|
result = Result.find(params[:element_id].to_i)
|
|
|
|
render_403 and return unless can_manage_result?(result)
|
2019-03-18 02:23:17 +08:00
|
|
|
|
|
|
|
result_asset = ResultAsset.create!(result: result, asset: asset)
|
2023-09-27 16:55:03 +08:00
|
|
|
asset.update!(view_mode: result.assets_view_mode)
|
2019-03-18 02:23:17 +08:00
|
|
|
|
|
|
|
edit_url = edit_asset_url(result_asset.asset_id)
|
|
|
|
else
|
2019-03-21 15:47:52 +08:00
|
|
|
render_404 and return
|
2018-11-16 00:52:31 +08:00
|
|
|
end
|
2019-03-18 02:23:17 +08:00
|
|
|
|
2022-05-24 17:13:47 +08:00
|
|
|
# Return edit url and asset info
|
2023-11-08 20:47:53 +08:00
|
|
|
render json: asset, scope: { user: current_user }
|
2018-10-19 16:00:58 +08:00
|
|
|
end
|
|
|
|
|
2020-11-04 20:08:40 +08:00
|
|
|
def destroy
|
|
|
|
if @asset.destroy
|
2021-08-20 20:45:33 +08:00
|
|
|
case @assoc
|
|
|
|
when Step
|
|
|
|
if @assoc.protocol.in_module?
|
2022-06-01 18:30:09 +08:00
|
|
|
log_step_activity(
|
|
|
|
:task_step_file_deleted,
|
|
|
|
@assoc,
|
2022-11-24 22:19:17 +08:00
|
|
|
@assoc.my_module.project,
|
2022-06-01 18:30:09 +08:00
|
|
|
my_module: @assoc.my_module.id,
|
2022-06-02 17:32:31 +08:00
|
|
|
file: @asset.file_name
|
2022-06-01 18:30:09 +08:00
|
|
|
)
|
2021-08-20 20:45:33 +08:00
|
|
|
else
|
|
|
|
log_step_activity(
|
2022-08-09 16:13:43 +08:00
|
|
|
:protocol_step_file_deleted,
|
2021-08-20 20:45:33 +08:00
|
|
|
@assoc,
|
|
|
|
nil,
|
2022-06-01 18:30:09 +08:00
|
|
|
protocol: @assoc.protocol.id,
|
2022-06-02 17:32:31 +08:00
|
|
|
file: @asset.file_name
|
2021-08-20 20:45:33 +08:00
|
|
|
)
|
|
|
|
end
|
|
|
|
when Result
|
2023-09-07 22:34:33 +08:00
|
|
|
log_result_activity(
|
2023-09-27 07:45:29 +08:00
|
|
|
@asset.file.metadata[:asset_type] == 'gene_sequence' ? :sequence_on_result_deleted : :result_file_deleted,
|
2023-09-07 22:34:33 +08:00
|
|
|
@assoc,
|
|
|
|
file: @asset.file_name
|
|
|
|
)
|
2021-08-20 20:45:33 +08:00
|
|
|
end
|
|
|
|
|
2023-03-15 22:56:47 +08:00
|
|
|
render json: { flash: I18n.t('assets.file_deleted', file_name: escape_input(@asset.file_name)) }
|
2020-11-04 20:08:40 +08:00
|
|
|
else
|
|
|
|
render json: {}, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-03-08 18:37:35 +08:00
|
|
|
def duplicate
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
case @asset.parent
|
|
|
|
when Step, Result
|
|
|
|
new_asset = @asset.duplicate(
|
|
|
|
new_name:
|
|
|
|
"#{@asset.file.filename.base} (1).#{@asset.file.filename.extension}"
|
|
|
|
)
|
|
|
|
|
|
|
|
@asset.parent.assets << new_asset
|
|
|
|
end
|
|
|
|
|
2024-03-28 16:52:58 +08:00
|
|
|
case @asset.parent
|
|
|
|
when Step
|
|
|
|
message_items = { file: @asset.file_name }
|
|
|
|
message_items[:my_module] = @assoc.protocol.my_module.id if @assoc.protocol.in_module?
|
|
|
|
|
|
|
|
log_step_activity(
|
|
|
|
"#{@assoc.protocol.in_module? ? 'task' : 'protocol'}_step_file_duplicated",
|
|
|
|
@assoc,
|
|
|
|
@assoc.my_module&.project,
|
|
|
|
message_items
|
|
|
|
)
|
|
|
|
when Result
|
|
|
|
log_result_activity(
|
|
|
|
:result_file_duplicated,
|
|
|
|
@assoc,
|
|
|
|
file: @asset.file_name,
|
|
|
|
user: current_user.id,
|
|
|
|
my_module: @assoc.my_module.id
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2024-03-08 18:37:35 +08:00
|
|
|
render json: new_asset, serializer: AssetSerializer, user: current_user
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-03-13 16:45:37 +08:00
|
|
|
def rename
|
|
|
|
new_name = params.require(:asset).permit(:name)[:name]
|
|
|
|
|
|
|
|
if new_name.empty?
|
2024-03-27 18:33:33 +08:00
|
|
|
render json: { error: I18n.t('assets.rename_modal.min_length_error') }, status: :unprocessable_entity
|
2024-03-13 16:45:37 +08:00
|
|
|
return
|
|
|
|
elsif new_name.length > Constants::NAME_MAX_LENGTH
|
2024-03-27 18:33:33 +08:00
|
|
|
render json: { error: I18n.t('assets.rename_modal.max_length_error') }, status: :unprocessable_entity
|
2024-03-13 16:45:37 +08:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
ActiveRecord::Base.transaction do
|
2024-03-27 18:33:33 +08:00
|
|
|
old_name = @asset.name
|
2024-03-13 16:45:37 +08:00
|
|
|
@asset.last_modified_by = current_user
|
|
|
|
@asset.rename_file(new_name)
|
|
|
|
@asset.save!
|
2024-03-27 18:33:33 +08:00
|
|
|
|
|
|
|
case @asset.parent
|
|
|
|
when Step
|
2024-03-28 18:00:14 +08:00
|
|
|
message_items = { old_name: old_name, new_name: new_name, user: current_user.id }
|
2024-03-27 18:33:33 +08:00
|
|
|
message_items[:my_module] = @assoc.protocol.my_module.id if @assoc.protocol.in_module?
|
|
|
|
|
|
|
|
log_step_activity(
|
|
|
|
"#{@assoc.protocol.in_module? ? 'task' : 'protocol'}_step_asset_renamed",
|
|
|
|
@assoc,
|
|
|
|
@assoc.my_module&.project,
|
|
|
|
message_items
|
|
|
|
)
|
|
|
|
when Result
|
|
|
|
log_result_activity(
|
|
|
|
:result_asset_renamed,
|
|
|
|
@assoc,
|
2024-03-28 18:00:14 +08:00
|
|
|
old_name: old_name,
|
|
|
|
new_name: new_name,
|
2024-03-27 18:33:33 +08:00
|
|
|
user: current_user.id,
|
|
|
|
my_module: @assoc.my_module.id
|
|
|
|
)
|
|
|
|
end
|
2024-03-13 16:45:37 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
render json: @asset, serializer: AssetSerializer, user: current_user
|
|
|
|
end
|
|
|
|
|
2024-02-07 18:26:40 +08:00
|
|
|
def checksum
|
|
|
|
render json: { checksum: @asset.file.blob.checksum }
|
|
|
|
end
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
private
|
|
|
|
|
|
|
|
def load_vars
|
2020-09-25 21:06:09 +08:00
|
|
|
@asset = Asset.find_by(id: params[:id])
|
2018-01-25 21:30:04 +08:00
|
|
|
return render_404 unless @asset
|
2016-02-12 23:52:43 +08:00
|
|
|
|
2023-09-27 20:13:34 +08:00
|
|
|
current_user.permission_team = @asset.team
|
|
|
|
|
2019-05-13 22:53:58 +08:00
|
|
|
@assoc ||= @asset.step
|
|
|
|
@assoc ||= @asset.result
|
|
|
|
@assoc ||= @asset.repository_cell
|
2016-02-12 23:52:43 +08:00
|
|
|
|
2016-07-21 19:11:15 +08:00
|
|
|
if @assoc.class == Step
|
|
|
|
@protocol = @asset.step.protocol
|
2018-03-10 00:04:54 +08:00
|
|
|
elsif @assoc.class == Result
|
2016-07-21 19:11:15 +08:00
|
|
|
@my_module = @assoc.my_module
|
2018-05-21 21:48:48 +08:00
|
|
|
elsif @assoc.class == RepositoryCell
|
|
|
|
@repository = @assoc.repository_column.repository
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def check_read_permission
|
2020-11-12 20:21:47 +08:00
|
|
|
render_403 and return unless can_read_asset?(@asset)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2024-03-27 18:33:33 +08:00
|
|
|
def check_manage_permission
|
2020-11-12 20:21:47 +08:00
|
|
|
render_403 and return unless can_manage_asset?(@asset)
|
2020-10-22 19:41:17 +08:00
|
|
|
end
|
|
|
|
|
2016-10-05 00:00:08 +08:00
|
|
|
def append_wd_params(url)
|
2019-05-22 16:34:16 +08:00
|
|
|
exclude_params = %w(wdPreviousSession wdPreviousCorrelation)
|
|
|
|
wd_params = params.as_json.select { |key, _value| key[/^wd.*/] && !(exclude_params.include? key) }.to_query
|
2019-05-21 21:53:34 +08:00
|
|
|
url + '&' + wd_params
|
2016-10-05 00:00:08 +08:00
|
|
|
end
|
|
|
|
|
2016-08-05 23:00:29 +08:00
|
|
|
def asset_params
|
2019-07-02 05:30:20 +08:00
|
|
|
params.permit(:file)
|
2016-08-05 23:00:29 +08:00
|
|
|
end
|
2017-03-13 20:20:49 +08:00
|
|
|
|
2020-08-28 17:05:52 +08:00
|
|
|
def toggle_view_mode_params
|
|
|
|
params.require(:asset).permit(:view_mode)
|
|
|
|
end
|
|
|
|
|
2017-03-13 20:20:49 +08:00
|
|
|
def asset_data_type(asset)
|
|
|
|
return 'wopi' if wopi_file?(asset)
|
2019-06-28 14:17:09 +08:00
|
|
|
return 'image' if asset.image?
|
2019-05-10 22:25:18 +08:00
|
|
|
|
2017-03-13 20:20:49 +08:00
|
|
|
'file'
|
|
|
|
end
|
2021-08-20 20:45:33 +08:00
|
|
|
|
|
|
|
def log_step_activity(type_of, step, project = nil, message_items = {})
|
|
|
|
default_items = { step: step.id,
|
|
|
|
step_position: { id: step.id, value_for: 'position_plus_one' } }
|
|
|
|
message_items = default_items.merge(message_items)
|
|
|
|
|
|
|
|
Activities::CreateActivityService
|
|
|
|
.call(activity_type: type_of,
|
|
|
|
owner: current_user,
|
|
|
|
subject: step.protocol,
|
2022-11-24 22:19:17 +08:00
|
|
|
team: step.protocol.team,
|
2021-08-20 20:45:33 +08:00
|
|
|
project: project,
|
|
|
|
message_items: message_items)
|
|
|
|
end
|
|
|
|
|
2023-09-07 22:34:33 +08:00
|
|
|
def log_result_activity(type_of, result, message_items)
|
2021-08-20 20:45:33 +08:00
|
|
|
Activities::CreateActivityService
|
|
|
|
.call(activity_type: type_of,
|
|
|
|
owner: current_user,
|
|
|
|
subject: result,
|
2022-11-24 22:19:17 +08:00
|
|
|
team: result.my_module.team,
|
|
|
|
project: result.my_module.project,
|
2021-08-20 20:45:33 +08:00
|
|
|
message_items: {
|
2023-09-07 22:34:33 +08:00
|
|
|
result: result.id
|
|
|
|
}.merge(message_items))
|
2021-08-20 20:45:33 +08:00
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|