app/models/task.rb
# This method is for copying a task and its ancestors to a new appeal stream
This method is for copying a task and its ancestors to a new appeal stream
This method is for copying a task and its ancestors to a new appeal stream
def copy_with_ancestors_to_stream(new_appeal_stream, extra_excluded_attributes: [], new_attributes: {})
    return unless parent
    new_task_attributes = attributes
      .except(*ATTRIBUTES_EXCLUDED_FROM_TASK_COPY, *extra_excluded_attributes)
      .merge(new_attributes)
    new_task_attributes["appeal_id"] = new_appeal_stream.id
    existing_new_parent = new_appeal_stream.reload.tasks.find { |task| task.type == parent.type }
    new_parent = existing_new_parent || parent.copy_with_ancestors_to_stream(new_appeal_stream)
    return unless new_parent
    new_task_attributes["parent_id"] = new_parent.id
    new_stream_task = self.class.new(new_task_attributes)
    new_stream_task.save(validate: false)
    new_stream_task
  end
def copy_with_ancestors_to_stream ( new_appeal_stream , extra_excluded_attributes : [ ] , new_attributes : { } ) return unless parent new_task_attributes = attributes . except ( * ATTRIBUTES_EXCLUDED_FROM_TASK_COPY , * extra_excluded_attributes ) . merge ( new_attributes ) new_task_attributes [ "appeal_id" ] = new_appeal_stream . id existing_new_parent = new_appeal_stream . reload . tasks . find { | task | task . type == parent . type } new_parent = existing_new_parent || parent . copy_with_ancestors_to_stream ( new_appeal_stream ) return unless new_parent new_task_attributes [ "parent_id" ] = new_parent . id new_stream_task = self . class . new ( new_task_attributes ) new_stream_task . save ( validate : false ) new_stream_task end
This method is for copying a task and its ancestors to a new appeal stream
This method is for copying a task and its ancestors to a new appeal stream
# This method recurses until the parent is nil or a task of its type is already present on the new stream # We reload the new_appeal_stream to ensure we are always working off an updated snapshot of task tree # Do not copy orphaned branches # Skip validation since these are not new tasks (and don't need to have a status of assigned, for example) # Note that if we also want to skip 'before_create', 'after_create', 'before_save', and 'after_save' callbacks # (such as in TimedHoldTask) or even things like 'validate :status_is_valid_on_create on: :create', # see SanitizedJsonImporter::SkipCallbacks for a possible solution.
new_appeal_stream
extra_excluded_attributes
new_attributes