From 8c4e16eafd2f55780fbad6446660a2b4e7ddf7ca Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 10 Jun 2019 11:33:10 -0400 Subject: [PATCH] FIX: In reply to would sometimes have a broken link --- .../components/reviewable-topic-link.hbs | 2 +- app/serializers/reviewable_serializer.rb | 15 ++++++++--- .../serializers/reviewable_serializer_spec.rb | 27 +++++++++++++++++-- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/discourse/templates/components/reviewable-topic-link.hbs b/app/assets/javascripts/discourse/templates/components/reviewable-topic-link.hbs index 30d2dc8c642..4b1704aec4d 100644 --- a/app/assets/javascripts/discourse/templates/components/reviewable-topic-link.hbs +++ b/app/assets/javascripts/discourse/templates/components/reviewable-topic-link.hbs @@ -1,7 +1,7 @@
{{#if reviewable.topic}} {{topic-status topic=reviewable.topic}} - {{reviewable.topic.title}} + {{reviewable.topic.title}} {{category-badge reviewable.category}} {{reviewable-tags tags=reviewable.topic_tags tagName=''}} {{else if (has-block)}} diff --git a/app/serializers/reviewable_serializer.rb b/app/serializers/reviewable_serializer.rb index 8969f472a30..d1a99c8a20c 100644 --- a/app/serializers/reviewable_serializer.rb +++ b/app/serializers/reviewable_serializer.rb @@ -13,6 +13,7 @@ class ReviewableSerializer < ApplicationSerializer :type, :topic_id, :topic_url, + :target_url, :topic_tags, :category_id, :created_at, @@ -107,13 +108,21 @@ class ReviewableSerializer < ApplicationSerializer object.topic.present? && SiteSetting.tagging_enabled? end + def target_url + return object.target.url if object.target.is_a?(Post) && object.target.present? + topic_url + end + + def include_target_url? + target_url.present? + end + def topic_url - return object.target.url if object.target.is_a?(Post) - return object.topic.url + return object.topic&.url end def include_topic_url? - object.topic.present? + topic_url.present? end def include_topic_id? diff --git a/spec/serializers/reviewable_serializer_spec.rb b/spec/serializers/reviewable_serializer_spec.rb index 6ce23e0c14b..8c2e95f1569 100644 --- a/spec/serializers/reviewable_serializer_spec.rb +++ b/spec/serializers/reviewable_serializer_spec.rb @@ -22,9 +22,7 @@ describe ReviewableSerializer do it 'Includes the removed topic id when the topis was deleted' do reviewable.topic.trash!(admin) - json = described_class.new(reviewable.reload, scope: Guardian.new(admin), root: nil).as_json - expect(json[:removed_topic_id]).to eq reviewable.topic_id end @@ -33,4 +31,29 @@ describe ReviewableSerializer do json = ReviewableQueuedPostSerializer.new(reviewable, scope: Guardian.new(admin), root: nil).as_json expect(json['payload']).to be_blank end + + describe "urls" do + + it "links to the flagged post" do + fp = Fabricate(:reviewable_flagged_post) + json = described_class.new(fp, scope: Guardian.new(admin), root: nil).as_json + expect(json[:target_url]).to eq(fp.post.url) + expect(json[:topic_url]).to eq(fp.topic.url) + end + + it "supports deleted topics" do + fp = Fabricate(:reviewable_flagged_post) + fp.topic.trash!(admin) + fp.reload + + json = described_class.new(fp, scope: Guardian.new(admin), root: nil).as_json + expect(json[:topic_url]).to be_blank + end + + it "links to the queued post" do + json = described_class.new(reviewable, scope: Guardian.new(admin), root: nil).as_json + expect(json[:target_url]).to eq(reviewable.topic.url) + expect(json[:topic_url]).to eq(reviewable.topic.url) + end + end end