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 af344e09c23..30d2dc8c642 100644 --- a/app/assets/javascripts/discourse/templates/components/reviewable-topic-link.hbs +++ b/app/assets/javascripts/discourse/templates/components/reviewable-topic-link.hbs @@ -7,6 +7,9 @@ {{else if (has-block)}} {{yield}} {{else}} - {{i18n "topic.deleted"}} + + {{i18n "review.topics.deleted"}} + {{link-to (i18n "review.topics.original") "topic" "-" reviewable.removed_topic_id}} + {{/if}} diff --git a/app/serializers/reviewable_serializer.rb b/app/serializers/reviewable_serializer.rb index 571993449ef..51775af412e 100644 --- a/app/serializers/reviewable_serializer.rb +++ b/app/serializers/reviewable_serializer.rb @@ -72,19 +72,19 @@ class ReviewableSerializer < ApplicationSerializer end def attributes - data = super + super.tap do |data| + data[:removed_topic_id] = object.topic_id unless object.topic - if object.target.present? - # Automatically add the target id as a "good name" for example a target_type of `User` - # becomes `user_id` - data[:"#{object.target_type.downcase}_id"] = object.target_id + if object.target.present? + # Automatically add the target id as a "good name" for example a target_type of `User` + # becomes `user_id` + data[:"#{object.target_type.downcase}_id"] = object.target_id + end + + if self.class._payload_for_serialization.present? + data[:payload] = (object.payload || {}).slice(*self.class._payload_for_serialization) + end end - - if self.class._payload_for_serialization.present? - data[:payload] = (object.payload || {}).slice(*self.class._payload_for_serialization) - end - - data end def topic_tags diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 9b4c0520c79..38405a1772a 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -404,6 +404,8 @@ en: topic: "Topic" reviewable_count: "Count" reported_by: "Reported by" + deleted: "[Topic Deleted]" + original: '(original topic)' details: "details" unique_users: one: "1 user" diff --git a/spec/serializers/reviewable_serializer_spec.rb b/spec/serializers/reviewable_serializer_spec.rb index 9c5558ad5e2..e2ca4c70186 100644 --- a/spec/serializers/reviewable_serializer_spec.rb +++ b/spec/serializers/reviewable_serializer_spec.rb @@ -6,7 +6,7 @@ describe ReviewableSerializer do let(:admin) { Fabricate(:admin) } it "serializes all the fields" do - json = ReviewableSerializer.new(reviewable, scope: Guardian.new(admin), root: nil).as_json + json = described_class.new(reviewable, scope: Guardian.new(admin), root: nil).as_json expect(json[:id]).to eq(reviewable.id) expect(json[:status]).to eq(reviewable.status) @@ -15,6 +15,15 @@ describe ReviewableSerializer do expect(json[:category_id]).to eq(reviewable.category_id) expect(json[:can_edit]).to eq(true) expect(json[:version]).to eq(0) + expect(json[:removed_topic_id]).to be_nil + end + + 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 it "will not throw an error when the payload is `nil`" do @@ -22,5 +31,4 @@ describe ReviewableSerializer do json = ReviewableQueuedPostSerializer.new(reviewable, scope: Guardian.new(admin), root: nil).as_json expect(json['payload']).to be_blank end - end