Fix saving protocol to repository [SCI-6935] (#4190)

This commit is contained in:
Alex Kriuchykhin 2022-07-06 11:45:04 +02:00 committed by GitHub
parent 7af1684db0
commit 9aeb107635
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 23 deletions

View file

@ -465,7 +465,6 @@ function init() {
initEditMyModuleDescription();
initEditProtocolDescription();
initEditDescription();
initCopyToRepository();
initLinkUpdate();
initLoadFromRepository();
refreshProtocolStatusBar();

View file

@ -331,8 +331,10 @@ class ProtocolsController < ApplicationController
link_protocols,
current_user
)
rescue StandardError
rescue StandardError => e
transaction_error = true
Rails.logger.error(e.message)
Rails.logger.error(e.backtrace.join("\n"))
raise ActiveRecord::Rollback
end

View file

@ -295,28 +295,24 @@ class Protocol < ApplicationRecord
# Copy checklists
step.checklists.asc.each do |checklist|
checklist2 = Checklist.new(
checklist2 = Checklist.create!(
name: checklist.name,
step: step2
step: step2,
created_by: current_user,
last_modified_by: current_user
)
checklist2.created_by = current_user
checklist2.last_modified_by = current_user
checklist2.save!
checklist.checklist_items.each do |item|
item2 = ChecklistItem.new(
ChecklistItem.create!(
text: item.text,
checked: false,
checklist: checklist2,
position: item.position
position: item.position,
created_by: current_user,
last_modified_by: current_user
)
item2.created_by = current_user
item2.last_modified_by = current_user
item2.save!
end
step2.checklists << checklist2
step2.step_orderable_elements.create!(
position: position,
orderable: checklist2
@ -335,18 +331,18 @@ class Protocol < ApplicationRecord
# Copy tables
step.tables.each do |table|
table2 = Table.new(
table2 = Table.create!(
name: table.name,
contents: table.contents.encode('UTF-8', 'UTF-8')
step: step2,
contents: table.contents.encode('UTF-8', 'UTF-8'),
team: dest.team,
created_by: current_user,
last_modified_by: current_user
)
table2.created_by = current_user
table2.last_modified_by = current_user
table2.team = dest.team
step2.tables << table2
step2.step_orderable_elements.create!(
position: position,
orderable: table2.step_tables.first
orderable: table2
)
position += 1

View file

@ -15,7 +15,7 @@ class StepOrderableElement < ApplicationRecord
if step != orderable.step
errors.add(
:step_orderable_element,
I18n.t('activerecord.errors.models.step_orderable_elements.attributes.step.wrong_step')
I18n.t('activerecord.errors.models.step_orderable_element.attributes.step.wrong_step')
)
end
end

View file

@ -25,6 +25,7 @@ class Table < ApplicationRecord
has_one :result_table, inverse_of: :table
has_one :result, through: :result_table
has_many :report_elements, inverse_of: :table, dependent: :destroy
has_many :step_orderable_elements, as: :orderable, dependent: :destroy
after_save :update_ts_index
after_save { result&.touch; step&.touch }