FIX: remove 'crawl_images' site setting (#14646)

FIX: remove ‘crawl_images’ site setting (#14646)

diff --git a/config/environments/test.rb b/config/environments/test.rb
index 502ae6b..ce54850 100644
--- a/config/environments/test.rb
+++ b/config/environments/test.rb
@@ -65,7 +65,6 @@ Discourse::Application.configure do
       s.set_regardless_of_locale(:min_post_length, 5)
       s.set_regardless_of_locale(:min_first_post_length, 5)
       s.set_regardless_of_locale(:min_personal_message_post_length, 10)
-      s.set_regardless_of_locale(:crawl_images, false)
       s.set_regardless_of_locale(:download_remote_images_to_local, false)
       s.set_regardless_of_locale(:unique_posts_mins, 0)
       s.set_regardless_of_locale(:max_consecutive_replies, 0)
diff --git a/config/site_settings.yml b/config/site_settings.yml
index 97c3151..7fb7f10 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -1293,8 +1293,6 @@ files:
     default: "1|1.5|2"
     type: list
     list_type: compact
-  crawl_images:
-    default: true
   max_image_width:
     client: true
     default: 690
diff --git a/db/migrate/20211019092048_remove_crawl_images_site_setting.rb b/db/migrate/20211019092048_remove_crawl_images_site_setting.rb
new file mode 100644
index 0000000..63c28db
--- /dev/null
+++ b/db/migrate/20211019092048_remove_crawl_images_site_setting.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class RemoveCrawlImagesSiteSetting < ActiveRecord::Migration[6.1]
+  def up
+    execute <<~SQL
+      DELETE
+      FROM site_settings
+      WHERE name = 'crawl_images';
+    SQL
+  end
+
+  def down
+    raise ActiveRecord::IrreversibleMigration
+  end
+end
diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb
index 9624662..1dae3a2 100644
--- a/lib/cooked_post_processor.rb
+++ b/lib/cooked_post_processor.rb
@@ -296,9 +296,6 @@ class CookedPostProcessor
 
     return unless is_valid_image_url?(absolute_url)
 
-    # we can *always* crawl our own images
-    return unless SiteSetting.crawl_images? || Discourse.store.has_been_uploaded?(url)
-
     @size_cache[url] = FastImage.size(absolute_url)
   rescue Zlib::BufError, URI::Error, OpenSSL::SSL::SSLError
     # FastImage.size raises BufError for some gifs, leave it.
diff --git a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb
index c7fa4b7..5fce91f 100644
--- a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb
+++ b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb
@@ -26,6 +26,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
   fab!(:reset_trigger) { DiscourseNarrativeBot::TrackSelector.reset_trigger }
 
   before do
+    stub_image_size
     Jobs.run_immediately!
     SiteSetting.discourse_narrative_bot_enabled = true
   end
diff --git a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rb b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rb
index e249d98..c421b62 100644
--- a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rb
+++ b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rb
@@ -29,6 +29,7 @@ describe DiscourseNarrativeBot::NewUserNarrative do
   fab!(:reset_trigger) { DiscourseNarrativeBot::TrackSelector.reset_trigger }
 
   before do
+    stub_image_size
     Jobs.run_immediately!
     SiteSetting.discourse_narrative_bot_enabled = true
   end
diff --git a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/track_selector_spec.rb b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/track_selector_spec.rb
index e2e5729..b93daf2 100644
--- a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/track_selector_spec.rb
+++ b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/track_selector_spec.rb
@@ -17,6 +17,7 @@ describe DiscourseNarrativeBot::TrackSelector do
   end
 
   before do
+    stub_image_size
     stub_request(:get, "http://api.forismatic.com/api/1.0/?format=json&lang=en&method=getQuote").
       to_return(status: 200, body: "{\"quoteText\":\"Be Like Water\",\"quoteAuthor\":\"Bruce Lee\"}")
 
diff --git a/plugins/discourse-narrative-bot/spec/user_spec.rb b/plugins/discourse-narrative-bot/spec/user_spec.rb
index d2eb773..de939c6 100644
--- a/plugins/discourse-narrative-bot/spec/user_spec.rb
+++ b/plugins/discourse-narrative-bot/spec/user_spec.rb
@@ -15,6 +15,7 @@ describe User do
   end
 
   before do
+    stub_image_size
     Jobs.run_immediately!
     SiteSetting.discourse_narrative_bot_enabled = true
   end
diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb
index 61a5290..1ff4258 100644
--- a/spec/components/cooked_post_processor_spec.rb
+++ b/spec/components/cooked_post_processor_spec.rb
@@ -345,6 +345,7 @@ describe CookedPostProcessor do
         let(:cpp) { CookedPostProcessor.new(post, image_sizes: image_sizes) }
 
         before do
+          stub_image_size
           cpp.post_process
         end
 
@@ -462,7 +463,6 @@ describe CookedPostProcessor do
             it 'should not add lightbox' do
               FastImage.expects(:size).returns([1750, 2000])
 
-              SiteSetting.crawl_images = true
               cpp.post_process
 
               expect(cpp.html).to match_html("<p><img src=\"http://test.discourse/#{upload_path}/original/1X/1234567890123456.svg?somepamas\" width=\"690\"\ height=\"788\"></p>")
@@ -526,6 +526,7 @@ describe CookedPostProcessor do
             it "does not create thumbnails or optimize images" do
               CookedPostProcessor.any_instance.expects(:optimize_image!).never
               Upload.any_instance.expects(:create_thumbnail!).never
+              stub_image_size
               cpp.post_process
 
               expect(cpp.html).not_to match_html cooked_html
@@ -828,21 +829,18 @@ describe CookedPostProcessor do
 
     it "resizes when only width is specified" do
       img = { 'src' => 'http://foo.bar/image3.png', 'width' => 100 }
-      SiteSetting.crawl_images = true
       FastImage.expects(:size).returns([200, 400])
       expect(cpp.get_size_from_attributes(img)).to eq([100, 200])
     end
 
     it "resizes when only height is specified" do
       img = { 'src' => 'http://foo.bar/image3.png', 'height' => 100 }
-      SiteSetting.crawl_images = true
       FastImage.expects(:size).returns([100, 300])
       expect(cpp.get_size_from_attributes(img)).to eq([33, 100])
     end
 
     it "doesn't raise an error with a weird url" do
       img = { 'src' => nil, 'height' => 100 }
-      SiteSetting.crawl_images = true
       expect(cpp.get_size_from_attributes(img)).to be_nil
     end
 
@@ -876,39 +874,10 @@ describe CookedPostProcessor do
     end
 
     it "caches the results" do
-      SiteSetting.crawl_images = true
       FastImage.expects(:size).returns([200, 400])
       cpp.get_size("http://foo.bar/image3.png")
       expect(cpp.get_size("http://foo.bar/image3.png")).to eq([200, 400])
     end
-
-    context "when crawl_images is disabled" do
-
-      before do
-        SiteSetting.crawl_images = false
-      end
-
-      it "doesn't call FastImage" do
-        FastImage.expects(:size).never
-        expect(cpp.get_size("http://foo.bar/image1.png")).to eq(nil)
-      end
-
-      it "is always allowed to crawl our own images" do
-        store = stub
-        Discourse.expects(:store).returns(store).at_least_once
-        store.expects(:has_been_uploaded?).returns(true)
-        FastImage.expects(:size).returns([100, 200])
-        expect(cpp.get_size("http://foo.bar/image2.png")).to eq([100, 200])
-      end
-
-      it "returns nil if FastImage can't get the original size" do
-        Discourse.store.class.any_instance.expects(:has_been_uploaded?).returns(true)
-        FastImage.expects(:size).returns(nil)

[... diff too long, it was truncated ...]

GitHub sha: d1fc759ac49c618c6a735d5765c208c7148a805c

This commit appears in #14646 which was approved by davidtaylorhq. It was merged by techAPJ.