diff --git a/app/services/user_destroyer.rb b/app/services/user_destroyer.rb index edf842f9f6c..4b56229a346 100644 --- a/app/services/user_destroyer.rb +++ b/app/services/user_destroyer.rb @@ -31,15 +31,17 @@ class UserDestroyer # block all external urls if opts[:block_urls] post.topic_links.each do |link| - unless link.internal or Oneboxer.oneboxer_exists_for_url?(link.url) - ScreenedUrl.watch(link.url, link.domain, ip_address: user.ip_address).try(:record_match!) + unless link.internal || + (Oneboxer.engine(link.url) != Onebox::Engine::WhitelistedGenericOnebox) + + ScreenedUrl.watch(link.url, link.domain, ip_address: user.ip_address)&.record_match! end end end PostDestroyer.new(@actor.staff? ? @actor : Discourse.system_user, post).destroy - if post.topic and post.is_first_post? + if post.topic && post.is_first_post? Topic.unscoped.where(id: post.topic.id).update_all(user_id: nil) end end diff --git a/lib/oneboxer.rb b/lib/oneboxer.rb index 5a2b656525a..db043464381 100644 --- a/lib/oneboxer.rb +++ b/lib/oneboxer.rb @@ -46,10 +46,6 @@ module Oneboxer "" end - def self.oneboxer_exists_for_url?(url) - Onebox.has_matcher?(url) - end - def self.invalidate(url) Rails.cache.delete(onebox_cache_key(url)) end @@ -124,6 +120,10 @@ module Oneboxer $redis.del(preview_key(user_id)) end + def self.engine(url) + Onebox::Matcher.new(url).oneboxed + end + private def self.preview_key(user_id) diff --git a/spec/services/user_destroyer_spec.rb b/spec/services/user_destroyer_spec.rb index e4043e93705..a31a8ffaaa3 100644 --- a/spec/services/user_destroyer_spec.rb +++ b/spec/services/user_destroyer_spec.rb @@ -239,12 +239,12 @@ describe UserDestroyer do it "doesn't add ScreenedUrl records by default" do ScreenedUrl.expects(:watch).never - UserDestroyer.new(@admin).destroy(@user, {delete_posts: true}) + UserDestroyer.new(@admin).destroy(@user, delete_posts: true) end it "adds ScreenedUrl records when :block_urls is true" do ScreenedUrl.expects(:watch).with(anything, anything, has_key(:ip_address)).at_least_once - UserDestroyer.new(@admin).destroy(@user, {delete_posts: true, block_urls: true}) + UserDestroyer.new(@admin).destroy(@user, delete_posts: true, block_urls: true) end end