adopt move/clone my module logic to work with new user assignments (SCI-5805)

This commit is contained in:
zmagoD 2021-06-12 18:51:55 +02:00
parent 9f3195aa76
commit 25802d7043
3 changed files with 20 additions and 1 deletions

View file

@ -330,6 +330,9 @@ class Experiment < ApplicationRecord
end
next unless my_module.save
# regenerate user assignments
my_module.user_assignments.destroy_all
UserAssignments::GenerateUserAssignmentsJob.perform_later(my_module, current_user)
Activities::CreateActivityService.call(activity_type: :move_task,
owner: current_user,

View file

@ -38,7 +38,14 @@ module Experiments
@c_exp.my_module_groups << g.deep_clone_to_experiment(@user, @c_exp)
end
raise ActiveRecord::Rollback unless @c_exp.save
# Copy user assignments to the experiment
@exp.user_assignments.map do |user_assignment|
new_user_assigment = user_assignment.dup
new_user_assigment.assignable = @c_exp
new_user_assigment.save!
end
@c_exp.save!
end
@errors.merge!(@c_exp.errors.to_hash) unless @c_exp.valid?

View file

@ -21,6 +21,7 @@ module Experiments
@exp.project = @project
@exp.my_modules.each do |my_module|
sync_user_assignments(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)
@ -33,6 +34,7 @@ module Experiments
end
@exp.save!
sync_user_assignments(@exp)
rescue
@errors.merge!(@exp.errors.to_hash) unless @exp.valid?
raise ActiveRecord::Rollback
@ -69,6 +71,13 @@ module Experiments
end
end
def sync_user_assignments(object)
# remove user assignments where the user are not present on the project
object.user_assignments.destroy_all
UserAssignments::GenerateUserAssignmentsJob.perform_later(object, @user)
end
def track_activity
Activities::CreateActivityService
.call(activity_type: :move_experiment,