Fix link to original file in docx protocol parser notification [SCI-9123] (#6070)

This commit is contained in:
Alex Kriuchykhin 2023-08-24 15:13:41 +02:00 committed by GitHub
parent 0faad52f6c
commit c1e2128b04
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 7 deletions

View file

@ -31,6 +31,8 @@ module ActiveStorage
true
when 'ZipExport', 'TeamZipExport'
check_zip_export_read_permissions(attachment.record)
when 'TempFile'
check_temp_file_read_permissions(attachment.record)
else
render_403
end
@ -87,5 +89,9 @@ module ActiveStorage
def check_zip_export_read_permissions(zip_export)
render_403 unless zip_export.user == current_user
end
def check_temp_file_read_permissions(temp_file)
render_403 unless temp_file.session_id == request.session_options[:id].to_s
end
end
end

View file

@ -9,7 +9,8 @@ module Protocols
def perform(temp_files_ids, user_id, team_id)
@user = User.find(user_id)
@team = @user.teams.find(team_id)
TempFile.where(id: temp_files_ids).each do |temp_file|
@tmp_files = TempFile.where(id: temp_files_ids)
@tmp_files.each do |temp_file|
temp_file.file.open do |protocol_file|
parse_protocol(protocol_file)
end
@ -135,15 +136,14 @@ module Protocols
end
def create_notification!
# TODO: Add proper protocol original file link
protocol_download_link = "<a data-id='#{@protocol.id}' " \
"data-turbolinks='false' " \
"href='#'>" \
"#{@protocol.name}</a>"
original_file_download_link =
"<a data-turbolinks='false' " \
"href='#{Rails.application.routes.url_helpers.rails_blob_path(@tmp_files.take.file)}'>" \
"#{@tmp_files.take.file.filename}</a>"
notification = Notification.create!(
type_of: :deliver,
title: I18n.t('protocols.import_export.import_protocol_notification.title', link: protocol_download_link),
title: I18n.t('protocols.import_export.import_protocol_notification.title', link: original_file_download_link),
message: "#{I18n.t('protocols.import_export.import_protocol_notification.message')} " \
"<a data-id='#{@protocol.id}' data-turbolinks='false' " \
"href='#{Rails.application.routes.url_helpers.protocol_path(@protocol)}'>" \