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

Prefer polymorphism over `is_a?`

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