Also move activities when moving experiment to another project [SCI-6047] (#3535)

* Also move activities when moving experiment to another project [SCI-6047]

* Changed update to update! [SCI-6047]
This commit is contained in:
artoscinote 2021-10-28 16:35:47 +02:00 committed by GitHub
parent 17a4afc6fa
commit 1bb30b2c49
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 14 deletions

View file

@ -20,17 +20,8 @@ module Experiments
ActiveRecord::Base.transaction do
@exp.project = @project
@exp.my_modules.each do |my_module|
new_tags = []
my_module.tags.each do |tag|
new_tag = @project.tags.where.not(id: new_tags).find_by(name: tag.name, color: tag.color)
new_tag ||=
@project.tags.create!(name: tag.name, color: tag.color, created_by: @user, last_modified_by: @user)
new_tags << new_tag
end
my_module.tags.destroy_all
my_module.tags = new_tags
end
move_tags!
move_activities!(@exp)
@exp.save!
rescue
@ -69,6 +60,34 @@ module Experiments
end
end
def move_tags!
@exp.my_modules.each do |my_module|
new_tags = []
my_module.tags.each do |tag|
new_tag = @project.tags.where.not(id: new_tags).find_by(name: tag.name, color: tag.color)
new_tag ||=
@project.tags.create!(name: tag.name, color: tag.color, created_by: @user, last_modified_by: @user)
new_tags << new_tag
end
my_module.tags.destroy_all
my_module.tags = new_tags
end
end
# recursively move all activities in child associations to new project
def move_activities!(subject)
Activity.where(subject: subject).update!(project: @project)
child_associations = Extends::ACTIVITY_SUBJECT_CHILDREN[subject.class.name.underscore.to_sym]
return unless child_associations
child_associations.each do |child_association|
[subject.public_send(child_association)].flatten.each do |child_subject|
move_activities!(child_subject)
end
end
end
def track_activity
Activities::CreateActivityService
.call(activity_type: :move_experiment,

View file

@ -147,10 +147,10 @@ class Extends
report: nil,
project: nil,
experiment: [:my_modules],
my_module: [:results, :protocols],
result: nil,
my_module: %i(results protocols),
result: [:asset],
protocol: [:steps],
step: nil
step: [:assets]
}
ACTIVITY_MESSAGE_ITEMS_TYPES =