Commit e5d8ca9e authored by Yorick Peterse's avatar Yorick Peterse

Refactor API noteable types constants

This replaces API::Notes::NOTEABLE_TYPES and
API::Discussions::NOTEABLE_TYPES with class methods defined in a
separate helper modules. This allows EE to extend the list of noteable
types, without having to modify the constant in-place. We can't define
these methods directly in the API classes, as they would be used before
we're able to extend them in EE.
parent 2eea8e1b
# frozen_string_literal: true
module EE
module API
module Helpers
module DiscussionsHelpers
extend ActiveSupport::Concern
class_methods do
extend ::Gitlab::Utils::Override
override :noteable_types
def noteable_types
[::Epic, *super]
end
end
end
end
end
end
......@@ -4,6 +4,17 @@ module EE
module API
module Helpers
module NotesHelpers
extend ActiveSupport::Concern
class_methods do
extend ::Gitlab::Utils::Override
override :noteable_types
def noteable_types
[::Epic, *super]
end
end
def find_group_epic(id)
finder_params = { group_id: user_group.id }
EpicsFinder.new(current_user, finder_params).find(id)
......
......@@ -7,9 +7,7 @@ module API
before { authenticate! }
NOTEABLE_TYPES = [Issue, Snippet, Epic, MergeRequest, Commit].freeze
NOTEABLE_TYPES.each do |noteable_type|
Helpers::DiscussionsHelpers.noteable_types.each do |noteable_type|
parent_type = noteable_type.parent_class.to_s.underscore
noteables_str = noteable_type.to_s.underscore.pluralize
noteables_path = noteable_type == Commit ? "repository/#{noteables_str}" : noteables_str
......
# frozen_string_literal: true
module API
module Helpers
module DiscussionsHelpers
def self.noteable_types
# This is a method instead of a constant, allowing EE to more easily
# extend it.
[Issue, Snippet, MergeRequest, Commit]
end
end
end
end
API::Helpers::DiscussionsHelpers.prepend(EE::API::Helpers::DiscussionsHelpers)
......@@ -3,7 +3,11 @@
module API
module Helpers
module NotesHelpers
prepend EE::API::Helpers::NotesHelpers # rubocop: disable Cop/InjectEnterpriseEditionModule
def self.noteable_types
# This is a method instead of a constant, allowing EE to more easily
# extend it.
[Issue, MergeRequest, Snippet]
end
def update_note(noteable, note_id)
note = noteable.notes.find(params[:note_id])
......@@ -113,3 +117,5 @@ module API
end
end
end
API::Helpers::NotesHelpers.prepend(EE::API::Helpers::NotesHelpers)
......@@ -7,9 +7,7 @@ module API
before { authenticate! }
NOTEABLE_TYPES = [Issue, MergeRequest, Snippet, Epic].freeze
NOTEABLE_TYPES.each do |noteable_type|
Helpers::NotesHelpers.noteable_types.each do |noteable_type|
parent_type = noteable_type.parent_class.to_s.underscore
noteables_str = noteable_type.to_s.underscore.pluralize
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment