Commit 654c4dd9 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 c01e9324
......@@ -7,9 +7,7 @@ module API
before { authenticate! }
NOTEABLE_TYPES = [Issue, Snippet, 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
......@@ -3,6 +3,12 @@
module API
module Helpers
module NotesHelpers
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])
......
......@@ -7,9 +7,7 @@ module API
before { authenticate! }
NOTEABLE_TYPES = [Issue, MergeRequest, Snippet].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