cleans experiment form report if moved [fixes SCI-335]

This commit is contained in:
zmagod 2016-08-17 15:21:53 +02:00
parent da735a51f4
commit c27c6c19e5

View file

@ -103,21 +103,17 @@ class ReportElement < ActiveRecord::Base
# removes element that are archived or deleted # removes element that are archived or deleted
def clean_removed_or_archived_elements def clean_removed_or_archived_elements
parent_model = '' parent_model = ''
[ 'project', %w(project experiment my_module step result checklist asset table)
'experiment', .each do |el|
'my_module', parent_model = el if send el
'step',
'result',
'checklist',
'asset',
'table'
].each do |el|
parent_model = el if self.send el
end end
if parent_model == 'step'
self.destroy unless self.send(parent_model).completed if parent_model == 'experiment'
destroy unless send(parent_model).project == report.project
elsif parent_model == 'step'
destroy unless send(parent_model).completed
else else
self.destroy unless (self.send(parent_model).active? rescue self.send(parent_model)) destroy unless (send(parent_model).active? rescue send(parent_model))
end end
end end