FIX: show generic title when quoting off-topic secure category posts

FIX: show generic title when quoting off-topic secure category posts

From 1073634271e330cbf8ce6d9a2f604cd971cfe972 Mon Sep 17 00:00:00 2001
From: Maja Komel <maja.komel@gmail.com>
Date: Sun, 2 Dec 2018 19:22:40 +0100
Subject: [PATCH] FIX: show generic title when quoting off-topic secure
 category posts


diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 9d61367..63b6b31 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -55,6 +55,7 @@ en:
   anonymous: "Anonymous"
   remove_posts_deleted_by_author: "Deleted by author"
   redirect_warning: "We were unable to verify that the link you selected was actually posted to the forum. If you wish to proceed anyway, select the link below."
+  on_another_topic: "On another topic"
 
   themes:
     bad_color_scheme: "Can not update theme, invalid color scheme"
diff --git a/lib/pretty_text/helpers.rb b/lib/pretty_text/helpers.rb
index ecdf284..d66e7e0 100644
--- a/lib/pretty_text/helpers.rb
+++ b/lib/pretty_text/helpers.rb
@@ -85,6 +85,11 @@ module PrettyText
           title: Rack::Utils.escape_html(topic.title),
           href: topic.url
         }
+      elsif topic
+        {
+          title: I18n.t("on_another_topic"),
+          href: Discourse.base_url + topic.slugless_url
+        }
       end
     end
 
diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb
index 32c3220..208b08d 100644
--- a/spec/components/pretty_text_spec.rb
+++ b/spec/components/pretty_text_spec.rb
@@ -46,6 +46,25 @@ describe PrettyText do
         expect(cook("[quote=\"EvilTrout, post:2, topic:#{topic.id}\"]\nddd\n[/quote]", topic_id: 1)).to eq(n(expected))
       end
 
+      it "do off topic quoting of posts from secure categories" do
+        category = Fabricate(:category, read_restricted: true)
+        topic = Fabricate(:topic, title: "this is topic with secret category", category: category)
+
+        expected = <<~HTML
+          <aside class="quote no-group" data-post="3" data-topic="#{topic.id}">
+          <div class="title">
+          <div class="quote-controls"></div>
+          <a href="http://test.localhost/t/#{topic.id}/3">#{I18n.t("on_another_topic")}</a>
+          </div>
+          <blockquote>
+          <p>I have nothing to say.</p>
+          </blockquote>
+          </aside>
+        HTML
+
+        expect(cook("[quote=\"maja, post:3, topic:#{topic.id}\"]\nI have nothing to say.\n[/quote]", topic_id: 1)).to eq(n(expected))
+      end
+
       it "indifferent about missing quotations" do
         md = <<~MD
           [quote=#{user.username}, post:123, topic:456, full:true]

GitHub

1 Like