Merge pull request #5685 from G-Chubinidze/gc_SCI_8693

Parsing (import) protocols - Notifications update [SCI-8693]
This commit is contained in:
artoscinote 2023-06-30 14:54:14 +02:00 committed by GitHub
commit 940ca1f096
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 15 deletions

View file

@ -591,7 +591,7 @@ class ProtocolsController < ApplicationController
message_items: {
protocol: protocol.id
})
generate_import_protocol_notification(current_user, protocol)
format.json do
render json: { status: :ok }, status: :ok
end
@ -766,20 +766,7 @@ class ProtocolsController < ApplicationController
end
z_output_stream.rewind
protocol_name = get_protocol_name(@protocols[0])
# Now generate filename of the archive and send file to user
if @protocols.count == 1
# Try to construct an OS-safe file name
file_name = 'protocol.eln'
unless protocol_name.nil?
escaped_name = protocol_name.gsub(/[^0-9a-zA-Z\-.,_]/i, '_')
.downcase[0..Constants::NAME_MAX_LENGTH]
file_name = escaped_name + '.eln' unless escaped_name.blank?
end
elsif @protocols.length > 1
file_name = 'protocols.eln'
end
file_name = export_protocol_file_name(@protocols)
@protocols.each do |protocol|
if params[:my_module_id]
@ -942,6 +929,46 @@ class ProtocolsController < ApplicationController
end
end
def generate_import_protocol_notification(user, protocol)
protocol_download_link = "<a data-id='#{protocol.id}' " \
"data-turbolinks='false' " \
"href='#{Rails.application
.routes
.url_helpers
.export_protocols_path(protocol_ids: [protocol.id])}'>" \
"#{export_protocol_file_name([protocol])}</a>"
notification = Notification.create(
type_of: :deliver,
title: I18n.t('protocols.import_export.import_protocol_notification.title', link: protocol_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)}'>" \
"#{protocol.name}</a>"
)
UserNotification.create(notification: notification, user: user)
end
def export_protocol_file_name(protocols)
protocol_name = get_protocol_name(protocols[0])
if protocols.count == 1
file_name = 'protocol.eln'
unless protocol_name.nil?
escaped_name = protocol_name.gsub(/[^0-9a-zA-Z\-.,_]/i, '_')
.downcase[0..Constants::NAME_MAX_LENGTH]
file_name = escaped_name + '.eln' unless escaped_name.blank?
end
elsif protocols.length > 1
file_name = 'protocols.eln'
end
file_name
end
def valid_protocol_json(json)
JSON.parse(json)
return true

View file

@ -2775,6 +2775,9 @@ en:
import_to_team_protocols_label: "Import to Team Protocols"
import_to_private_protocols_label: "Import to My Protocols"
import_protocols_label: "Import"
import_protocol_notification:
title: "The import process has been successfully completed. You can download original file here: %{link}"
message: "Protocol template:"
export:
export_results:
title: "Export results"