diff --git a/app/models/my_module.rb b/app/models/my_module.rb index caebcffea..57361e5eb 100644 --- a/app/models/my_module.rb +++ b/app/models/my_module.rb @@ -8,7 +8,7 @@ class MyModule < ApplicationRecord before_create :create_blank_protocol before_validation :set_completed_on, if: :state_changed? - before_create :assign_default_status_flow + before_validation :assign_default_status_flow before_save :exec_status_consequences, if: :my_module_status_id_changed? auto_strip_attributes :name, :description, nullify: false @@ -517,7 +517,7 @@ class MyModule < ApplicationRecord end def assign_default_status_flow - return unless MyModuleStatusFlow.global.any? + return if my_module_status.present? || MyModuleStatusFlow.global.blank? self.my_module_status = MyModuleStatusFlow.global.first.initial_status end diff --git a/app/services/model_exporters/experiment_exporter.rb b/app/services/model_exporters/experiment_exporter.rb index 51a19898d..eebd9e838 100644 --- a/app/services/model_exporters/experiment_exporter.rb +++ b/app/services/model_exporters/experiment_exporter.rb @@ -52,6 +52,7 @@ module ModelExporters def my_module(my_module) { my_module: my_module, + my_module_status_name: my_module.my_module_status&.name, outputs: my_module.outputs, my_module_tags: my_module.my_module_tags, task_comments: my_module.task_comments, diff --git a/app/services/team_importer.rb b/app/services/team_importer.rb index badc1f8de..2f2efd55e 100644 --- a/app/services/team_importer.rb +++ b/app/services/team_importer.rb @@ -646,7 +646,7 @@ class TeamImporter def create_my_modules(my_modules_json, experiment, user_id = nil) puts('Creating my_modules...') my_modules_json.each do |my_module_json| - my_module = MyModule.new(my_module_json['my_module']) + my_module = MyModule.new(my_module_json['my_module'].except('my_module_status_name')) orig_my_module_id = my_module.id my_module.id = nil my_module.my_module_group_id = @@ -658,6 +658,16 @@ class TeamImporter my_module.archived_by_id = find_user(my_module.archived_by_id) my_module.restored_by_id = find_user(my_module.restored_by_id) my_module.experiment = experiment + + # Find matching status from default flow + default_flow = MyModuleStatusFlow.global.first + + if default_flow.present? + status = default_flow.my_module_statuses.find_by(name: my_module_json['my_module']['my_module_status_name']) + status ||= default_flow.initial_status + my_module.my_module_status = status + end + my_module.save! @my_module_mappings[orig_my_module_id] = my_module.id @my_module_counter += 1 diff --git a/app/services/user_data_deletion.rb b/app/services/user_data_deletion.rb index c9cd0e5c4..21d11aa66 100644 --- a/app/services/user_data_deletion.rb +++ b/app/services/user_data_deletion.rb @@ -1,7 +1,6 @@ class UserDataDeletion def self.delete_team_data(team) ActiveRecord::Base.logger = Logger.new(STDOUT) - Step.skip_callback(:destroy, :after, :cascade_after_destroy) team.transaction do # Destroy tiny_mce_assets if team.tiny_mce_assets.present? @@ -86,7 +85,6 @@ class UserDataDeletion team.destroy! # raise ActiveRecord::Rollback end - Step.set_callback(:destroy, :after, :cascade_after_destroy) end def self.destroy_protocol(protocol)