mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-03-13 16:34:25 +08:00
Merge pull request #1000 from Zanz2/null_step_crash_sci2043
Fixed big crash that was caused by invalid or null step hash in protocol [SCI-2043]
This commit is contained in:
commit
7b9425321b
4 changed files with 32 additions and 16 deletions
|
@ -640,10 +640,11 @@ class ProtocolsController < ApplicationController
|
|||
return 0 # return 0 stops the rest of the controller code from executing
|
||||
end
|
||||
@json_object = JSON.parse(json_file_contents)
|
||||
|
||||
@json_object['steps'] = protocols_io_guid_reorder_step_json(
|
||||
@json_object['steps']
|
||||
)
|
||||
unless step_hash_null?(@json_object['steps'])
|
||||
@json_object['steps'] = protocols_io_guid_reorder_step_json(
|
||||
@json_object['steps']
|
||||
)
|
||||
end
|
||||
|
||||
@protocol = Protocol.new
|
||||
respond_to do |format|
|
||||
|
@ -658,23 +659,26 @@ class ProtocolsController < ApplicationController
|
|||
@db_json = {}
|
||||
@toolong = false
|
||||
@db_json['name'] = pio_eval_title_len(
|
||||
sanitize_input(params['protocol']['name'])
|
||||
sanitize_input(not_null(params['protocol']['name']))
|
||||
)
|
||||
# since scinote only has description field, and protocols.io has many others
|
||||
# ,here i am putting everything important from protocols.io into description
|
||||
@db_json['authors'] = pio_eval_title_len(
|
||||
sanitize_input(params['protocol']['authors'])
|
||||
sanitize_input(not_null(params['protocol']['authors']))
|
||||
)
|
||||
@db_json['created_at'] = pio_eval_title_len(
|
||||
sanitize_input(params['protocol']['created_at'])
|
||||
sanitize_input(not_null(params['protocol']['created_at']))
|
||||
)
|
||||
@db_json['updated_at'] = pio_eval_title_len(
|
||||
sanitize_input(params['protocol']['last_modified'])
|
||||
sanitize_input(not_null(params['protocol']['last_modified']))
|
||||
)
|
||||
@db_json['steps'] = {}
|
||||
@db_json['steps'] = protocols_io_fill_step(
|
||||
@json_object, @db_json['steps']
|
||||
)
|
||||
|
||||
unless step_hash_null?(@json_object['steps'])
|
||||
@db_json['steps'] = protocols_io_fill_step(
|
||||
@json_object, @db_json['steps']
|
||||
)
|
||||
end
|
||||
protocol = nil
|
||||
respond_to do |format|
|
||||
transaction_error = false
|
||||
|
|
|
@ -102,6 +102,8 @@ module ProtocolsIoHelper
|
|||
@toolong = true
|
||||
end
|
||||
text
|
||||
else
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -128,6 +130,8 @@ module ProtocolsIoHelper
|
|||
@remaining -= text.length - reserved
|
||||
end
|
||||
text
|
||||
else
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -145,10 +149,15 @@ module ProtocolsIoHelper
|
|||
Nokogiri::HTML::DocumentFragment.parse(text).to_html
|
||||
end
|
||||
|
||||
def step_hash_null?(step_json)
|
||||
step_json.dig(0, 'components', 0, 'component_type_id').nil?
|
||||
end
|
||||
|
||||
# Images are allowed in:
|
||||
# Step: description, expected result
|
||||
# Protocol description : description before_start warning
|
||||
# guidelines manuscript_citation
|
||||
|
||||
def prepare_for_view(
|
||||
attribute_text1, size, table = 'no_table', image_allowed = false
|
||||
)
|
||||
|
@ -321,9 +330,12 @@ module ProtocolsIoHelper
|
|||
end
|
||||
|
||||
def protocols_io_guid_reorder_step_json(unordered_step_json)
|
||||
return '' if unordered_step_json.blank?
|
||||
base_step = unordered_step_json.find { |step| step['previous_guid'].nil? }
|
||||
return unordered_step_json if base_step.nil?
|
||||
number_of_steps = unordered_step_json.size
|
||||
return unordered_step_json if number_of_steps == 1
|
||||
base_step = unordered_step_json.find { |step| step['previous_guid'].nil? }
|
||||
step_order = []
|
||||
step_counter = 0
|
||||
step_order[step_counter] = base_step
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
<label><%= t('protocols.import_export.import_modal.name_label') %></label>
|
||||
|
||||
<%= f.text_field :name, :value => pio_eval_title_len(sanitize_input(@json_object['protocol_name'])), class:
|
||||
<%= f.text_field :name, :value => pio_eval_title_len(sanitize_input(not_null(@json_object['protocol_name']))), class:
|
||||
"form-control" %>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
|
@ -52,14 +52,14 @@
|
|||
<div class="col-xs-4">
|
||||
<label><%= t('protocols.import_export.import_modal.created_at_label') %></label>
|
||||
|
||||
<% display_created_at=Time.at(@json_object['created_on'].to_i) %>
|
||||
<% display_created_at=Time.at(not_null(@json_object['created_on']).to_i) %>
|
||||
<%= f.text_field :created_at, :value => display_created_at.to_s,
|
||||
readonly: true, class: "form-control" %>
|
||||
</div>
|
||||
<div class="col-xs-4">
|
||||
<label><%= t('protocols.import_export.import_modal.updated_at_label') %></label>
|
||||
|
||||
<% display_last_modified=Time.at(@json_object['last_modified'].to_i) %>
|
||||
<% display_last_modified=Time.at(not_null(@json_object['last_modified']).to_i) %>
|
||||
<%= f.text_field :last_modified, :value =>
|
||||
display_last_modified.to_s,readonly: true, class:
|
||||
"form-control" %>
|
||||
|
|
|
@ -40,13 +40,13 @@
|
|||
<br>
|
||||
<% case key['component_type_id']
|
||||
when '1' %>
|
||||
<% step_info_string += (key['data']) %>
|
||||
<% step_info_string += not_null(key['data']) %>
|
||||
<br>
|
||||
<strong><%= t('protocols.protocols_io_import.preview.strng_s_desc') %></strong>
|
||||
<%= prepare_for_view(key['data'],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table',true).html_safe %>
|
||||
<br>
|
||||
<% when '17' %>
|
||||
<% step_info_string += (key['data']) %>
|
||||
<% step_info_string += not_null(key['data']) %>
|
||||
<br>
|
||||
<strong><%= t('protocols.protocols_io_import.preview.s_exp_res') %></strong>
|
||||
<%= prepare_for_view(key['data'],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table',true).html_safe %>
|
||||
|
|
Loading…
Reference in a new issue