DEV: Add `import_embed_unlisted` site setting (#26222)
This commit is contained in:
parent
f79f9e236a
commit
7dc552c9cc
|
@ -79,6 +79,7 @@ class TopicEmbed < ActiveRecord::Base
|
||||||
embed_url: url,
|
embed_url: url,
|
||||||
embed_content_sha1: content_sha1,
|
embed_content_sha1: content_sha1,
|
||||||
}
|
}
|
||||||
|
create_args[:visible] = false if SiteSetting.import_embed_unlisted?
|
||||||
|
|
||||||
post = PostCreator.create(user, create_args)
|
post = PostCreator.create(user, create_args)
|
||||||
post.topic.topic_embed.update!(embed_content_cache: original_contents)
|
post.topic.topic_embed.update!(embed_content_cache: original_contents)
|
||||||
|
|
|
@ -2381,6 +2381,7 @@ en:
|
||||||
embed_set_canonical_url: "Set the canonical URL for embedded topics to the embedded content's URL."
|
embed_set_canonical_url: "Set the canonical URL for embedded topics to the embedded content's URL."
|
||||||
embed_truncate: "Shorten the contents of posts that are embedded from external sources. This setting ensures that only the initial part of content is displayed when a post from an external URL is embedded on your site. If you prefer to display full content from the external posts, you can disable this setting."
|
embed_truncate: "Shorten the contents of posts that are embedded from external sources. This setting ensures that only the initial part of content is displayed when a post from an external URL is embedded on your site. If you prefer to display full content from the external posts, you can disable this setting."
|
||||||
embed_unlisted: "Embedded topics will be unlisted until a user replies."
|
embed_unlisted: "Embedded topics will be unlisted until a user replies."
|
||||||
|
import_embed_unlisted: "Imported embedded topics will be unlisted until a user replies (even when the `embed unlisted` site setting is unchecked)."
|
||||||
embed_support_markdown: "Support Markdown formatting for embedded posts."
|
embed_support_markdown: "Support Markdown formatting for embedded posts."
|
||||||
allowed_embed_selectors: "A comma separated list of CSS elements that are allowed in embeds."
|
allowed_embed_selectors: "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."
|
allowed_href_schemes: "Schemes allowed in links in addition to http and https."
|
||||||
|
|
|
@ -1104,7 +1104,8 @@ posting:
|
||||||
embed_any_origin: false
|
embed_any_origin: false
|
||||||
embed_topics_list: false
|
embed_topics_list: false
|
||||||
embed_set_canonical_url: false
|
embed_set_canonical_url: false
|
||||||
embed_unlisted: true
|
embed_unlisted: false
|
||||||
|
import_embed_unlisted: true
|
||||||
embed_truncate: true
|
embed_truncate: true
|
||||||
embed_support_markdown: false
|
embed_support_markdown: false
|
||||||
allowed_embed_selectors: ""
|
allowed_embed_selectors: ""
|
||||||
|
|
|
@ -43,7 +43,7 @@ class PostJobsEnqueuer
|
||||||
|
|
||||||
def make_visible
|
def make_visible
|
||||||
return if @topic.private_message?
|
return if @topic.private_message?
|
||||||
return unless SiteSetting.embed_unlisted?
|
return unless SiteSetting.embed_unlisted? || SiteSetting.import_embed_unlisted?
|
||||||
return if @post.post_number == 1
|
return if @post.post_number == 1
|
||||||
return if @topic.visible?
|
return if @topic.visible?
|
||||||
return if @post.post_type != Post.types[:regular]
|
return if @post.post_type != Post.types[:regular]
|
||||||
|
|
|
@ -1487,6 +1487,23 @@ RSpec.describe PostCreator do
|
||||||
expect(creator.errors).to be_blank
|
expect(creator.errors).to be_blank
|
||||||
expect(TopicEmbed.where(content_sha1: content_sha1).exists?).to eq(true)
|
expect(TopicEmbed.where(content_sha1: content_sha1).exists?).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when embed_unlisted is true" do
|
||||||
|
before { SiteSetting.embed_unlisted = true }
|
||||||
|
|
||||||
|
it "unlists the topic" do
|
||||||
|
creator =
|
||||||
|
PostCreator.new(
|
||||||
|
user,
|
||||||
|
embed_url: embed_url,
|
||||||
|
title: "Reviews of Science Ovens",
|
||||||
|
raw: "Did you know that you can use microwaves to cook your dinner? Science!",
|
||||||
|
)
|
||||||
|
post = creator.create
|
||||||
|
expect(creator.errors).to be_blank
|
||||||
|
expect(post.topic).not_to be_visible
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "read credit for creator" do
|
describe "read credit for creator" do
|
||||||
|
|
|
@ -129,29 +129,55 @@ RSpec.describe TopicEmbed do
|
||||||
expect(post.cooked).to match(/#{cased_url}/)
|
expect(post.cooked).to match(/#{cased_url}/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "will make the topic unlisted if `embed_unlisted` is set until someone replies" do
|
shared_examples "topic is unlisted" do
|
||||||
Jobs.run_immediately!
|
it "unlists the topic until someone replies" do
|
||||||
SiteSetting.embed_unlisted = true
|
Jobs.run_immediately!
|
||||||
imported_post =
|
imported_post =
|
||||||
TopicEmbed.import(user, "http://eviltrout.com/abcd", title, "some random content")
|
TopicEmbed.import(user, "http://eviltrout.com/abcd", title, "some random content")
|
||||||
expect(imported_post.topic).not_to be_visible
|
expect(imported_post.topic).not_to be_visible
|
||||||
pc =
|
pc =
|
||||||
PostCreator.new(
|
PostCreator.new(
|
||||||
Fabricate(:user),
|
Fabricate(:user),
|
||||||
raw: "this is a reply that will make the topic visible",
|
raw: "this is a reply that will make the topic visible",
|
||||||
topic_id: imported_post.topic_id,
|
topic_id: imported_post.topic_id,
|
||||||
reply_to_post_number: 1,
|
reply_to_post_number: 1,
|
||||||
)
|
)
|
||||||
pc.create
|
pc.create
|
||||||
expect(imported_post.topic.reload).to be_visible
|
expect(imported_post.topic.reload).to be_visible
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "won't be invisible if `embed_unlisted` is set to false" do
|
context "when import embed unlisted is true" do
|
||||||
Jobs.run_immediately!
|
before { SiteSetting.import_embed_unlisted = true }
|
||||||
SiteSetting.embed_unlisted = false
|
|
||||||
imported_post =
|
include_examples "topic is unlisted"
|
||||||
TopicEmbed.import(user, "http://eviltrout.com/abcd", title, "some random content")
|
|
||||||
expect(imported_post.topic).to be_visible
|
context "when embed unlisted is false" do
|
||||||
|
before { SiteSetting.embed_unlisted = false }
|
||||||
|
|
||||||
|
include_examples "topic is unlisted"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when import embed unlisted is false" do
|
||||||
|
before { SiteSetting.import_embed_unlisted = false }
|
||||||
|
|
||||||
|
context "when embed unlisted is false" do
|
||||||
|
before { SiteSetting.embed_unlisted = false }
|
||||||
|
|
||||||
|
it "lists the topic" do
|
||||||
|
Jobs.run_immediately!
|
||||||
|
imported_post =
|
||||||
|
TopicEmbed.import(user, "http://eviltrout.com/abcd", title, "some random content")
|
||||||
|
expect(imported_post.topic).to be_visible
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when embed unlisted is true" do
|
||||||
|
before { SiteSetting.embed_unlisted = true }
|
||||||
|
|
||||||
|
include_examples "topic is unlisted"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "creates the topic in the category passed as a parameter" do
|
it "creates the topic in the category passed as a parameter" do
|
||||||
|
|
Loading…
Reference in New Issue