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

Prefer polymorphism over `is_a?`

parent c9262213781d
......@@ -18,7 +18,7 @@ def index
@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 @@ def note_json(note)
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 @@ def upvote?
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 @@ def supports_discussions?
DiscussionNote::NOTEABLE_TYPES.include?(base_class_name)
end
def discussions_rendered_on_frontend?
false
end
def discussion_notes
notes
end
......
......@@ -269,6 +269,10 @@ def as_json(options = {})
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 @@ def in_reply_to?(other)
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