A platform for community discussion. Free, open, simple.
FEATURE: New site setting `embed_unlisted` (#9391)
Robin Wardb6b92a562c48
diff --git a/app/assets/javascripts/admin/templates/embedding.hbs b/app/assets/javascripts/admin/templates/embedding.hbsindex b9422bbb110..4bf9135fce1 100644--- a/app/assets/javascripts/admin/templates/embedding.hbs+++ b/app/assets/javascripts/admin/templates/embedding.hbs@@ -38,6 +38,7 @@value=embedding.embed_title_scrubberplaceholder="- site.com$"}}{{embedding-setting field="embed_truncate" value=embedding.embed_truncate type="checkbox"}}+ {{embedding-setting field="embed_unlisted" value=embedding.embed_unlisted type="checkbox"}}</div><div class='embedding-secondary'>diff --git a/app/models/embedding.rb b/app/models/embedding.rbindex 1f2be1ee0f4..055cb2b32cb 100644--- a/app/models/embedding.rb+++ b/app/models/embedding.rb@@ -10,6 +10,7 @@ class Embedding < OpenStructembed_post_limitembed_title_scrubberembed_truncate+ embed_unlistedembed_whitelist_selectorembed_blacklist_selectorembed_classname_whitelist)diff --git a/app/models/post.rb b/app/models/post.rbindex 1fe1bed9850..86dafde6bce 100644--- a/app/models/post.rb+++ b/app/models/post.rb@@ -127,7 +127,8 @@ class Post < ActiveRecord::Baseflagged_by_tl3_user: 4,email_spam_header_found: 5,flagged_by_tl4_user: 6,- email_authentication_result_header: 7)+ email_authentication_result_header: 7,+ imported_as_unlisted: 8)enddef self.typesdiff --git a/app/models/topic_embed.rb b/app/models/topic_embed.rbindex 15922f7c4cd..1947a3c6401 100644--- a/app/models/topic_embed.rb+++ b/app/models/topic_embed.rb@@ -53,12 +53,18 @@ class TopicEmbed < ActiveRecord::BasePost.cook_methods[:raw_html]end- creator = PostCreator.new(user,- title: title,- raw: absolutize_urls(url, contents),- skip_validations: true,- cook_method: cook_method,- category: eh.try(:category_id))+ create_args = {+ title: title,+ raw: absolutize_urls(url, contents),+ skip_validations: true,+ cook_method: cook_method,+ category: eh.try(:category_id)+ }+ if SiteSetting.embed_unlisted?+ create_args[:visible] = false+ end++ creator = PostCreator.new(user, create_args)post = creator.createif post.present?TopicEmbed.create!(topic_id: post.topic_id,diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex f395e62717c..4b7b33fa589 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -4620,6 +4620,7 @@ en:embed_post_limit: "Maximum number of posts to embed"embed_title_scrubber: "Regular expression used to scrub the title of posts"embed_truncate: "Truncate the embedded posts"+ embed_unlisted: "Imported topics will be unlisted until there is a reply."embed_whitelist_selector: "CSS selector for elements that are allowed in embeds"embed_blacklist_selector: "CSS selector for elements that are removed from embeds"embed_classname_whitelist: "Allowed CSS class names"diff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 4fd326065f6..df6709c2625 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -2068,6 +2068,7 @@ en:embed_topics_list: "Support HTML embedding of topics lists"embed_set_canonical_url: "Set the canonical URL for embeded topics to the embeded content's URL."embed_truncate: "Truncate the embedded posts."+ embed_unlisted: "Imported topics will be unlisted until a user replies."embed_support_markdown: "Support Markdown formatting for embedded posts."embed_whitelist_selector: "A comma separated list of CSS elements that are allowed in embeds."allowed_href_schemes: "Schemes allowed in links in addition to http and https."diff --git a/config/site_settings.yml b/config/site_settings.ymlindex e2fc35aac48..c5b7a3d5ccb 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -901,12 +901,10 @@ posting:embed_any_origin: falseembed_topics_list: falseembed_set_canonical_url: false- embed_truncate:- default: true- embed_support_markdown:- default: false- embed_whitelist_selector:- default: ""+ embed_unlisted: false+ embed_truncate: true+ embed_support_markdown: false+ embed_whitelist_selector: ""allowed_href_schemes:client: truedefault: ""diff --git a/lib/post_creator.rb b/lib/post_creator.rbindex fab3de19543..0d3d61a99ee 100644--- a/lib/post_creator.rb+++ b/lib/post_creator.rb@@ -186,6 +186,7 @@ class PostCreator@post.link_post_uploadsupdate_uploads_secure_statusensure_in_allowed_users if guardian.is_staff?+ make_visibleunarchive_messageif !@opts[:import_mode]DraftSequence.next!(@user, draft_key)@@ -414,6 +415,16 @@ class PostCreatorendend+ def make_visible+ return unless SiteSetting.embed_unlisted?+ return unless @post.post_number > 1+ return if @post.topic.visible?++ if embed = @post.topic.topic_embed+ @post.topic.update_status('visible', true, @user)+ end+ end+def unarchive_messagereturn unless @topic.private_message? && @topic.iddiff --git a/spec/models/topic_embed_spec.rb b/spec/models/topic_embed_spec.rbindex 4e931f4f99c..f15f55fff8f 100644--- a/spec/models/topic_embed_spec.rb+++ b/spec/models/topic_embed_spec.rb@@ -41,6 +41,7 @@ describe TopicEmbed doexpect(TopicEmbed.where(topic_id: post.topic_id)).to be_presentexpect(post.topic.category).to eq(embeddable_host.category)+ expect(post.topic).to be_visibleendit "Supports updating the post content" do@@ -71,6 +72,20 @@ describe TopicEmbed dopost = TopicEmbed.import(user, cased_url, title, "some random content")expect(post.cooked).to match(/#{cased_url}/)end++ it "will make the topic unlisted if `embed_unlisted` is set until someone replies" do+ SiteSetting.embed_unlisted = true+ imported_post = TopicEmbed.import(user, "http://eviltrout.com/abcd", title, "some random content")+ expect(imported_post.topic).not_to be_visible+ pc = PostCreator.new(+ Fabricate(:user),+ raw: "this is a reply that will make the topic visible",+ topic_id: imported_post.topic_id,+ reply_to_post_number: 1+ )+ pc.create+ expect(imported_post.topic.reload).to be_visible+ endendcontext "post creation supports markdown rendering" do