Skip to content

Commit

Permalink
feat(duplication_tracing): add functionality to trace duplication for…
Browse files Browse the repository at this point in the history
… lesson plan items
  • Loading branch information
bivanalhar committed Feb 28, 2023
1 parent 64a198b commit 7ce047e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/course/lesson_plan/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class Course::LessonPlan::Item < ApplicationRecord
belongs_to :course, inverse_of: :lesson_plan_items
has_many :todos, class_name: Course::LessonPlan::Todo.name, inverse_of: :item, dependent: :destroy
has_one :duplication_traceable, class_name: DuplicationTraceable::LessonPlanItem.name,
inverse_of: :lesson_plan_item, dependent: :destroy
inverse_of: :lesson_plan_item, dependent: :destroy, foreign_key: :lesson_plan_item_id

delegate :start_at, :start_at=, :start_at_changed?, :bonus_end_at, :bonus_end_at=, :bonus_end_at_changed?,
:end_at, :end_at=, :end_at_changed?,
Expand Down
10 changes: 9 additions & 1 deletion lib/autoload/duplicator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,21 @@ def duplicate_object(source_object) # rubocop:disable Metrics/AbcSize
@duplicated_objects[key] = duplicate
duplicate.initialize_duplicate(self, key)

# Set duplication source, if it's being tracked for this class.
# Set duplication source, if it's being tracked for this class or has its actable class being tracked
if duplicate.class.method_defined?(:duplication_traceable)
traceable = duplicate.class.reflect_on_association(:duplication_traceable).options[:class_name].constantize
duplicate.duplication_traceable = traceable.initialize_with_dest(duplicate,
source_id: source_object.id,
creator: @options[:current_user],
updater: @options[:current_user])
elsif duplicate.respond_to?(:acting_as) && duplicate.acting_as.class.method_defined?(:duplication_traceable)
dup_parent = duplicate.acting_as
traceable = dup_parent.class.reflect_on_association(:duplication_traceable).options[:class_name].constantize
dup_parent.duplication_traceable = traceable.initialize_with_dest(dup_parent,
source_id: source_object.acting_as.id,
creator: @options[:current_user],
updater: @options[:current_user])
byebug
end
end
end
Expand Down

0 comments on commit 7ce047e

Please sign in to comment.