diff options
Diffstat (limited to 'app/services/issuable/clone')
-rw-r--r-- | app/services/issuable/clone/base_service.rb | 32 | ||||
-rw-r--r-- | app/services/issuable/clone/content_rewriter.rb | 74 |
2 files changed, 27 insertions, 79 deletions
diff --git a/app/services/issuable/clone/base_service.rb b/app/services/issuable/clone/base_service.rb index 0d1640924e5..b2f9c083b5b 100644 --- a/app/services/issuable/clone/base_service.rb +++ b/app/services/issuable/clone/base_service.rb @@ -24,12 +24,34 @@ module Issuable private + def copy_award_emoji + AwardEmojis::CopyService.new(original_entity, new_entity).execute + end + + def copy_notes + Notes::CopyService.new(current_user, original_entity, new_entity).execute + end + def update_new_entity - rewriters = [ContentRewriter, AttributesRewriter] + update_new_entity_description + update_new_entity_attributes + copy_award_emoji + copy_notes + end - rewriters.each do |rewriter| - rewriter.new(current_user, original_entity, new_entity).execute - end + def update_new_entity_description + rewritten_description = MarkdownContentRewriterService.new( + current_user, + original_entity.description, + original_entity.project, + new_parent + ).execute + + new_entity.update!(description: rewritten_description) + end + + def update_new_entity_attributes + AttributesRewriter.new(current_user, original_entity, new_entity).execute end def update_old_entity @@ -47,7 +69,7 @@ module Issuable end def new_parent - new_entity.project || new_entity.group + new_entity.resource_parent end def group diff --git a/app/services/issuable/clone/content_rewriter.rb b/app/services/issuable/clone/content_rewriter.rb deleted file mode 100644 index 67d2f9fd3fe..00000000000 --- a/app/services/issuable/clone/content_rewriter.rb +++ /dev/null @@ -1,74 +0,0 @@ -# frozen_string_literal: true - -module Issuable - module Clone - class ContentRewriter < ::Issuable::Clone::BaseService - def initialize(current_user, original_entity, new_entity) - @current_user = current_user - @original_entity = original_entity - @new_entity = new_entity - @project = original_entity.project - end - - def execute - rewrite_description - rewrite_award_emoji(original_entity, new_entity) - rewrite_notes - end - - private - - def rewrite_description - new_entity.update(description: rewrite_content(original_entity.description)) - end - - def rewrite_notes - new_discussion_ids = {} - original_entity.notes_with_associations.find_each do |note| - new_note = note.dup - new_discussion_ids[note.discussion_id] ||= Discussion.discussion_id(new_note) - new_params = { - project: new_entity.project, - noteable: new_entity, - discussion_id: new_discussion_ids[note.discussion_id], - note: rewrite_content(new_note.note), - note_html: nil, - created_at: note.created_at, - updated_at: note.updated_at - } - - if note.system_note_metadata - new_params[:system_note_metadata] = note.system_note_metadata.dup - - # TODO: Implement copying of description versions when an issue is moved - # https://gitlab.com/gitlab-org/gitlab/issues/32300 - new_params[:system_note_metadata].description_version = nil - end - - new_note.update(new_params) - - rewrite_award_emoji(note, new_note) - end - end - - def rewrite_content(content) - return unless content - - rewriters = [Gitlab::Gfm::ReferenceRewriter, Gitlab::Gfm::UploadsRewriter] - - rewriters.inject(content) do |text, klass| - rewriter = klass.new(text, old_project, current_user) - rewriter.rewrite(new_parent) - end - end - - def rewrite_award_emoji(old_awardable, new_awardable) - old_awardable.award_emoji.each do |award| - new_award = award.dup - new_award.awardable = new_awardable - new_award.save - end - end - end - end -end |