FEATURE: check `blocked_onebox_domains` setting for inline oneboxes (#11944)
This commit is contained in:
parent
2309032e68
commit
7f86a310ef
|
@ -50,9 +50,10 @@ class InlineOneboxer
|
||||||
end
|
end
|
||||||
|
|
||||||
always_allow = SiteSetting.enable_inline_onebox_on_all_domains
|
always_allow = SiteSetting.enable_inline_onebox_on_all_domains
|
||||||
domains = SiteSetting.allowed_inline_onebox_domains&.split('|') unless always_allow
|
allowed_domains = SiteSetting.allowed_inline_onebox_domains&.split('|') unless always_allow
|
||||||
|
blocked_domains = SiteSetting.blocked_onebox_domains&.split('|')
|
||||||
|
|
||||||
if always_allow || domains
|
if always_allow || allowed_domains
|
||||||
uri = begin
|
uri = begin
|
||||||
URI(url)
|
URI(url)
|
||||||
rescue URI::Error
|
rescue URI::Error
|
||||||
|
@ -60,7 +61,8 @@ class InlineOneboxer
|
||||||
|
|
||||||
if uri.present? &&
|
if uri.present? &&
|
||||||
uri.hostname.present? &&
|
uri.hostname.present? &&
|
||||||
(always_allow || domains.include?(uri.hostname))
|
(always_allow || allowed_domains.include?(uri.hostname)) &&
|
||||||
|
!blocked_domains.include?(uri.hostname)
|
||||||
title = RetrieveTitle.crawl(url)
|
title = RetrieveTitle.crawl(url)
|
||||||
title = nil if title && title.length < MIN_TITLE_LENGTH
|
title = nil if title && title.length < MIN_TITLE_LENGTH
|
||||||
return onebox_for(url, title, opts)
|
return onebox_for(url, title, opts)
|
||||||
|
|
|
@ -153,6 +153,12 @@ describe InlineOneboxer do
|
||||||
expect(onebox).to be_blank
|
expect(onebox).to be_blank
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "will not crawl domains that are blocked" do
|
||||||
|
SiteSetting.blocked_onebox_domains = "eviltrout.com"
|
||||||
|
onebox = InlineOneboxer.lookup("https://eviltrout.com", skip_cache: true)
|
||||||
|
expect(onebox).to be_blank
|
||||||
|
end
|
||||||
|
|
||||||
it "will crawl anything if allowed to" do
|
it "will crawl anything if allowed to" do
|
||||||
SiteSetting.enable_inline_onebox_on_all_domains = true
|
SiteSetting.enable_inline_onebox_on_all_domains = true
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue