Commit 5f758aff authored by Douwe Maan's avatar Douwe Maan

Prefer polymorphism over `is_a?`

parent 9c22974c
......@@ -18,7 +18,7 @@ module NotesActions
@notes = prepare_notes_for_rendering(@notes)
notes_json[:notes] =
if noteable.is_a?(Issue)
if noteable.discussions_rendered_on_frontend?
note_serializer.represent(@notes)
else
@notes.map { |note| note_json(note) }
......@@ -87,7 +87,7 @@ module NotesActions
if note.persisted?
attrs[:valid] = true
if noteable.is_a?(Issue)
if noteable.discussions_rendered_on_frontend?
attrs.merge!(note_serializer.represent(note))
else
attrs.merge!(
......
......@@ -37,7 +37,7 @@ class AwardEmoji < ActiveRecord::Base
end
def expire_etag_cache
return unless awardable.is_a?(Note)
return unless awardable.respond_to?(:expire_etag_cache)
awardable.expire_etag_cache
end
......
......@@ -24,6 +24,10 @@ module Noteable
DiscussionNote::NOTEABLE_TYPES.include?(base_class_name)
end
def discussions_rendered_on_frontend?
false
end
def discussion_notes
notes
end
......
......@@ -269,6 +269,10 @@ class Issue < ActiveRecord::Base
end
end
def discussions_rendered_on_frontend?
true
end
private
# Returns `true` if the given User can read the current Issue.
......
......@@ -300,12 +300,12 @@ class Note < ActiveRecord::Base
end
def expire_etag_cache
return unless for_issue?
return unless noteable.discussions_rendered_on_frontend?
key = Gitlab::Routing.url_helpers.project_noteable_notes_path(
noteable.project,
project,
target_type: noteable_type.underscore,
target_id: noteable.id
target_id: noteable_id
)
Gitlab::EtagCaching::Store.new.touch(key)
end
......
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