individual_note_discussion.rb 904 Bytes
Newer Older
1 2
# frozen_string_literal: true

Douwe Maan's avatar
Douwe Maan committed
3
# A discussion to wrap a single `Note` note on the root of an issue, merge request,
Douwe Maan's avatar
Douwe Maan committed
4
# commit, or snippet, that is not displayed as a discussion.
5 6
#
# A discussion of this type is never resolvable.
7
class IndividualNoteDiscussion < Discussion
8 9
  def self.note_class
    Note
10 11
  end

Douwe Maan's avatar
Douwe Maan committed
12
  def individual_note?
13 14
    true
  end
15

16
  def can_convert_to_discussion?
17
    noteable.supports_replying_to_individual_notes? && Feature.enabled?(:reply_to_individual_notes, default_enabled: true)
18 19
  end

20 21 22 23 24 25
  def convert_to_discussion!(save: false)
    first_note.becomes!(Discussion.note_class).to_discussion.tap do
      # Save needs to be called on first_note instead of the transformed note
      # because of https://gitlab.com/gitlab-org/gitlab-ce/issues/57324
      first_note.save if save
    end
26 27
  end

28 29 30
  def reply_attributes
    super.tap { |attrs| attrs.delete(:discussion_id) }
  end
31
end