diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2019-06-03 16:41:05 +0200 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2019-06-03 16:41:05 +0200 |
commit | 4504959aa6ce6667b9fd5b68ff24a612cb7c027b (patch) | |
tree | be88c9ff22e0ec8ac6af5c31bca7e4f2f318c62c /app/models | |
parent | 2ad5b30b6c02a3e3f84275121a709f5de75dac48 (diff) | |
download | gitlab-ce-4504959aa6ce6667b9fd5b68ff24a612cb7c027b.tar.gz |
Make `resolvable_types` a class method
This turns Notable::RESOLVABLE_TYPES into a
`Notable.resolvable_types`. That allows us to override it in EE.
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/concerns/noteable.rb | 12 | ||||
-rw-r--r-- | app/models/concerns/resolvable_note.rb | 2 | ||||
-rw-r--r-- | app/models/diff_note.rb | 4 |
3 files changed, 12 insertions, 6 deletions
diff --git a/app/models/concerns/noteable.rb b/app/models/concerns/noteable.rb index bfd0c36942b..4b428b0af83 100644 --- a/app/models/concerns/noteable.rb +++ b/app/models/concerns/noteable.rb @@ -3,14 +3,16 @@ module Noteable extend ActiveSupport::Concern - # `Noteable` class names that support resolvable notes. - RESOLVABLE_TYPES = %w(MergeRequest).freeze - class_methods do # `Noteable` class names that support replying to individual notes. def replyable_types %w(Issue MergeRequest) end + + # `Noteable` class names that support resolvable notes. + def resolvable_types + %w(MergeRequest) + end end # The timestamp of the note (e.g. the :created_at or :updated_at attribute if provided via @@ -36,7 +38,7 @@ module Noteable end def supports_resolvable_notes? - RESOLVABLE_TYPES.include?(base_class_name) + self.class.resolvable_types.include?(base_class_name) end def supports_discussions? @@ -131,3 +133,5 @@ module Noteable ) end end + +Noteable.extend(Noteable::ClassMethods) diff --git a/app/models/concerns/resolvable_note.rb b/app/models/concerns/resolvable_note.rb index 16ea330701d..2d2d5fb7168 100644 --- a/app/models/concerns/resolvable_note.rb +++ b/app/models/concerns/resolvable_note.rb @@ -12,7 +12,7 @@ module ResolvableNote validates :resolved_by, presence: true, if: :resolved? # Keep this scope in sync with `#potentially_resolvable?` - scope :potentially_resolvable, -> { where(type: RESOLVABLE_TYPES).where(noteable_type: Noteable::RESOLVABLE_TYPES) } + scope :potentially_resolvable, -> { where(type: RESOLVABLE_TYPES).where(noteable_type: Noteable.resolvable_types) } # Keep this scope in sync with `#resolvable?` scope :resolvable, -> { potentially_resolvable.user } diff --git a/app/models/diff_note.rb b/app/models/diff_note.rb index feabea9b8ba..d4d163f2f38 100644 --- a/app/models/diff_note.rb +++ b/app/models/diff_note.rb @@ -15,7 +15,9 @@ class DiffNote < Note validates :original_position, presence: true validates :position, presence: true validates :line_code, presence: true, line_code: true, if: :on_text? - validates :noteable_type, inclusion: { in: noteable_types } + # We need to evaluate the `noteable` types when running the validation since + # EE might have added a type when the module was prepended + validates :noteable_type, inclusion: { in: -> (_note) { noteable_types } } validate :positions_complete validate :verify_supported validate :diff_refs_match_commit, if: :for_commit? |