A platform for community discussion. Free, open, simple.
FIX: remove 'crawl_images' site setting (#14646)
Arpit Jaland1fc759ac49c
diff --git a/config/environments/test.rb b/config/environments/test.rbindex 502ae6b376d..ce5485047f3 100644--- a/config/environments/test.rb+++ b/config/environments/test.rb@@ -65,7 +65,6 @@ Discourse::Application.configure dos.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.ymlindex 97c315166bd..7fb7f101eb5 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -1293,8 +1293,6 @@ files:default: "1|1.5|2"type: listlist_type: compact- crawl_images:- default: truemax_image_width:client: truedefault: 690diff --git a/db/migrate/20211019092048_remove_crawl_images_site_setting.rb b/db/migrate/20211019092048_remove_crawl_images_site_setting.rbnew file mode 100644index 00000000000..63c28dbc64b--- /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+enddiff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rbindex 9624662c26e..1dae3a22dea 100644--- a/lib/cooked_post_processor.rb+++ b/lib/cooked_post_processor.rb@@ -296,9 +296,6 @@ class CookedPostProcessorreturn 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.rbindex c7fa4b7ee8e..5fce91fea83 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 dofab!(:reset_trigger) { DiscourseNarrativeBot::TrackSelector.reset_trigger }before do+ stub_image_sizeJobs.run_immediately!SiteSetting.discourse_narrative_bot_enabled = trueenddiff --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.rbindex e249d98a441..c421b620df0 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 dofab!(:reset_trigger) { DiscourseNarrativeBot::TrackSelector.reset_trigger }before do+ stub_image_sizeJobs.run_immediately!SiteSetting.discourse_narrative_bot_enabled = trueenddiff --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.rbindex e2e57290716..b93daf2facc 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 doendbefore do+ stub_image_sizestub_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.rbindex d2eb77384b6..de939c61726 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 doendbefore do+ stub_image_sizeJobs.run_immediately!SiteSetting.discourse_narrative_bot_enabled = trueenddiff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rbindex 61a5290e952..1ff425821c6 100644--- a/spec/components/cooked_post_processor_spec.rb+++ b/spec/components/cooked_post_processor_spec.rb@@ -345,6 +345,7 @@ describe CookedPostProcessor dolet(:cpp) { CookedPostProcessor.new(post, image_sizes: image_sizes) }before do+ stub_image_sizecpp.post_processend@@ -462,7 +463,6 @@ describe CookedPostProcessor doit 'should not add lightbox' doFastImage.expects(:size).returns([1750, 2000])- SiteSetting.crawl_images = truecpp.post_processexpect(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 doit "does not create thumbnails or optimize images" doCookedPostProcessor.any_instance.expects(:optimize_image!).neverUpload.any_instance.expects(:create_thumbnail!).never+ stub_image_sizecpp.post_processexpect(cpp.html).not_to match_html cooked_html@@ -828,21 +829,18 @@ describe CookedPostProcessor doit "resizes when only width is specified" doimg = { 'src' => 'http://foo.bar/image3.png', 'width' => 100 }- SiteSetting.crawl_images = trueFastImage.expects(:size).returns([200, 400])expect(cpp.get_size_from_attributes(img)).to eq([100, 200])endit "resizes when only height is specified" doimg = { 'src' => 'http://foo.bar/image3.png', 'height' => 100 }- SiteSetting.crawl_images = trueFastImage.expects(:size).returns([100, 300])expect(cpp.get_size_from_attributes(img)).to eq([33, 100])endit "doesn't raise an error with a weird url" doimg = { 'src' => nil, 'height' => 100 }- SiteSetting.crawl_images = trueexpect(cpp.get_size_from_attributes(img)).to be_nilend@@ -876,39 +874,10 @@ describe CookedPostProcessor doendit "caches the results" do- SiteSetting.crawl_images = trueFastImage.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)- expect(cpp.get_size("http://foo.bar/image3.png")).to eq(nil)- end-- end-endcontext "#is_valid_image_url?" do@@ -1078,15 +1047,17 @@ describe CookedPostProcessor dopost.save_custom_fieldscpp = CookedPostProcessor.new(post, invalidate_oneboxes: true)+ stub_image_size(width: 100, height: 200)cpp.post_process_oneboxes- expect(cpp.doc.to_s).to eq("<p><img class=\"onebox\" src=\"#{upload.url}\" width=\"\" height=\"\"></p>")+ expect(cpp.doc.to_s).to eq("<p><img class=\"onebox\" src=\"#{upload.url}\" width=\"100\" height=\"200\"></p>")upload.destroy!cpp = CookedPostProcessor.new(post, invalidate_oneboxes: true)+ stub_image_size(width: 100, height: 200)cpp.post_process_oneboxes- expect(cpp.doc.to_s).to eq("<p><img class=\"onebox\" src=\"#{image_url}\" width=\"\" height=\"\"></p>")+ expect(cpp.doc.to_s).to eq("<p><img class=\"onebox\" src=\"#{image_url}\" width=\"100\" height=\"200\"></p>")Oneboxer.unstub(:onebox)end@@ -1112,9 +1083,10 @@ describe CookedPostProcessor doUrlHelper.expects(:cook_url).with(upload.url, secure: true).returns(cooked_url)cpp = CookedPostProcessor.new(post, invalidate_oneboxes: true)+ stub_image_size(width: 100, height: 200)cpp.post_process_oneboxes- expect(cpp.doc.to_s).to eq("<p><img class=\"onebox\" src=\"#{cooked_url}\" width=\"\" height=\"\"></p>")+ expect(cpp.doc.to_s).to eq("<p><img class=\"onebox\" src=\"#{cooked_url}\" width=\"100\" height=\"200\"></p>")endendend@@ -1206,8 +1178,6 @@ describe CookedPostProcessor docontext "#post_process_oneboxes with square image" doit "generates a onebox-avatar class" do- SiteSetting.crawl_images = true-url = 'https://square-image.com/onebox'body = <<~HTML@@ -1226,7 +1196,7 @@ describe CookedPostProcessor do# not an ideal stub but shipping the whole image to fast image can add# a lot of cost to this test- FastImage.stubs(:size).returns([200, 200])+ stub_image_size(width: 200, height: 200)post = Fabricate.build(:post, raw: url)cpp = CookedPostProcessor.new(post, invalidate_oneboxes: true)@@ -1817,10 +1787,13 @@ describe CookedPostProcessor doFabricate(:post, topic: topic, post_type: Post.types[:small_action])reply = PostCreator.create!(topic.user, topic_id: topic.id, raw: raw)+ stub_image_sizeCookedPostProcessor.new(reply).post_processexpect(reply.raw).to eq(raw)PostRevisor.new(reply).revise!(Discourse.system_user, raw: raw, edit_reason: "put back full quote")++ stub_image_sizeCookedPostProcessor.new(reply).post_process(new_post: true)expect(reply.raw).to eq("and this is the third reply")enddiff --git a/spec/components/post_revisor_spec.rb b/spec/components/post_revisor_spec.rbindex 48fc17e0f6e..207f2177830 100644--- a/spec/components/post_revisor_spec.rb+++ b/spec/components/post_revisor_spec.rb@@ -1185,6 +1185,7 @@ describe PostRevisor doendit "updates the upload secure status, which is secure by default from the composer. set to false for a public topic" do+ stub_image_sizesubject.revise!(user, raw: <<~RAW)This is a post with a secure upload@@ -1196,6 +1197,7 @@ describe PostRevisor doit "does not update the upload secure status, which is secure by default from the composer for a private" dopost.topic.update(category: Fabricate(:private_category, group: Fabricate(:group)))+ stub_image_sizesubject.revise!(user, raw: <<~RAW)This is a post with a secure uploaddiff --git a/spec/jobs/process_post_spec.rb b/spec/jobs/process_post_spec.rbindex 0bc38d6fde5..335af635f4c 100644--- a/spec/jobs/process_post_spec.rb+++ b/spec/jobs/process_post_spec.rb@@ -37,6 +37,7 @@ describe Jobs::ProcessPost doit 'processes posts' dopost = Fabricate(:post, raw: "<img src='#{Discourse.base_url_no_prefix}/awesome/picture.png'>")expect(post.cooked).to match(/http/)+ stub_image_sizeJobs::ProcessPost.new.execute(post_id: post.id)post.reload@@ -53,6 +54,7 @@ describe Jobs::ProcessPost doit "extracts links to quoted posts" doquoted_post = Fabricate(:post, raw: "This is a post with a link to https://www.discourse.org", post_number: 42)post.update_columns(raw: "This quote is the best\n\n[quote=\"#{quoted_post.user.username}, topic:#{quoted_post.topic_id}, post:#{quoted_post.post_number}\"]\n#{quoted_post.excerpt}\n[/quote]")+ stub_image_size# when creating a quote, we also create the reflexion linkexpect { Jobs::ProcessPost.new.execute(post_id: post.id) }.to change { TopicLink.count }.by(2)end@@ -60,6 +62,7 @@ describe Jobs::ProcessPost doit "extracts links to oneboxed topics" dooneboxed_post = Fabricate(:post)post.update_columns(raw: "This post is the best\n\n#{oneboxed_post.full_url}")+ stub_image_size# when creating a quote, we also create the reflexion linkexpect { Jobs::ProcessPost.new.execute(post_id: post.id) }.to change { TopicLink.count }.by(2)enddiff --git a/spec/jobs/pull_hotlinked_images_spec.rb b/spec/jobs/pull_hotlinked_images_spec.rbindex 3faa9195b81..1a67b1dbce8 100644--- a/spec/jobs/pull_hotlinked_images_spec.rb+++ b/spec/jobs/pull_hotlinked_images_spec.rb@@ -31,7 +31,6 @@ describe Jobs::PullHotlinkedImages do"#{Discourse.base_url}/#{upload_path}/original/1X/c530c06cf89c410c0355d7852644a73fc3ec8c04.png")- SiteSetting.crawl_images = trueSiteSetting.download_remote_images_to_local = trueSiteSetting.max_image_size_kb = 2SiteSetting.download_remote_images_threshold = 0@@ -62,6 +61,7 @@ describe Jobs::PullHotlinkedImages doit 'replaces images' dopost = Fabricate(:post, raw: "<img src='#{image_url}'>")+ stub_image_sizeexpect doJobs::PullHotlinkedImages.new.execute(post_id: post.id)@@ -73,6 +73,7 @@ describe Jobs::PullHotlinkedImages doit 'removes downloaded images when they are no longer needed' dopost = Fabricate(:post, raw: "<img src='#{image_url}'>")+ stub_image_sizepost.rebake!post.reloadexpect(post.post_uploads.count).to eq(1)@@ -85,6 +86,7 @@ describe Jobs::PullHotlinkedImages doit 'replaces images again after edit' dopost = Fabricate(:post, raw: "<img src='#{image_url}'>")+ stub_image_sizeexpect dopost.rebake!@@ -104,6 +106,7 @@ describe Jobs::PullHotlinkedImages doit 'replaces encoded image urls' dopost = Fabricate(:post, raw: "<img src='#{encoded_image_url}'>")+ stub_image_sizeexpect doJobs::PullHotlinkedImages.new.execute(post_id: post.id)end.to change { Upload.count }.by(1)@@ -143,6 +146,7 @@ describe Jobs::PullHotlinkedImages doit 'replaces correct image URL' dourl = image_url.sub("/2e/Longcat1.png", '')post = Fabricate(:post, raw: "[Images](#{url})\n")+ stub_image_sizeexpect doJobs::PullHotlinkedImages.new.execute(post_id: post.id)@@ -154,6 +158,7 @@ describe Jobs::PullHotlinkedImages doit 'replaces images without protocol' dourl = image_url.sub(/^https?\:/, '')post = Fabricate(:post, raw: "<img alt='test' src='#{url}'>")+ stub_image_sizeexpect doJobs::PullHotlinkedImages.new.execute(post_id: post.id)@@ -166,6 +171,7 @@ describe Jobs::PullHotlinkedImages dourl = image_url.sub(/\.[a-zA-Z0-9]+$/, '')stub_request(:get, url).to_return(body: png, headers: { "Content-Type" => "image/png" })post = Fabricate(:post, raw: "<img src='#{url}'>")+ stub_image_sizeexpect doJobs::PullHotlinkedImages.new.execute(post_id: post.id)@@ -182,6 +188,7 @@ describe Jobs::PullHotlinkedImages do.to_return(status: 200, body: file_from_fixtures("smallest.png"))post = Fabricate(:post, raw: "<img src='#{url}'>")+ stub_image_sizeexpect { Jobs::PullHotlinkedImages.new.execute(post_id: post.id) }.to change { Upload.count }.by(1)@@ -261,6 +268,7 @@ describe Jobs::PullHotlinkedImages doMD+ stub_image_sizeexpect { Jobs::PullHotlinkedImages.new.execute(post_id: post.id) }.to change { Upload.count }.by(1)@@ -281,6 +289,7 @@ describe Jobs::PullHotlinkedImages doMD+ stub_image_sizeexpect { Jobs::PullHotlinkedImages.new.execute(post_id: post.id) }.to change { Upload.count }.by(1)@@ -296,6 +305,7 @@ describe Jobs::PullHotlinkedImages do#{image_url}[/img]MD+ stub_image_sizeexpect { Jobs::PullHotlinkedImages.new.execute(post_id: post.id) }.to change { Upload.count }.by(1)@@ -336,6 +346,8 @@ describe Jobs::PullHotlinkedImages doit 'replaces image src' dopost = Fabricate(:post, raw: "#{url}")+ stub_image_size+post.rebake!post.reload@@ -345,6 +357,7 @@ describe Jobs::PullHotlinkedImages doit 'associates uploads correctly' dopost = Fabricate(:post, raw: "#{url}")+ stub_image_sizepost.rebake!post.reload@@ -364,6 +377,7 @@ describe Jobs::PullHotlinkedImages do<img src='#{broken_image_url}'><a href='#{url}'><img src='#{large_image_url}'></a>BODY+ stub_image_size2.times dopost.rebake!diff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rbindex 45bf725fdb2..82f7ea92f59 100644--- a/spec/models/post_action_spec.rb+++ b/spec/models/post_action_spec.rb@@ -900,6 +900,7 @@ describe PostAction doJobs.run_immediately!post = Fabricate(:post)user = Fabricate(:user)+ stub_image_sizeresult = PostActionCreator.create(user, post, :spam, message: "WAT")topic = result.post_action.related_post.topicreviewable = result.reviewablediff --git a/spec/models/quoted_post_spec.rb b/spec/models/quoted_post_spec.rbindex 35082b5af27..b60722c5e45 100644--- a/spec/models/quoted_post_spec.rb+++ b/spec/models/quoted_post_spec.rb@@ -22,6 +22,7 @@ describe QuotedPost do#{post3.full_url}RAW+ stub_image_sizepost4 = create_post(topic: topic, raw: raw, post_number: 4, reply_to_post_number: post3.post_number)diff --git a/spec/rails_helper.rb b/spec/rails_helper.rbindex ab44d904ea9..61523bc2d7e 100644--- a/spec/rails_helper.rb+++ b/spec/rails_helper.rb@@ -182,6 +182,7 @@ RSpec.configure do |config|config.include SidekiqHelpersconfig.include UploadsHelpersconfig.include OneboxHelpers+ config.include FastImageHelpersconfig.mock_framework = :mochaconfig.order = 'random'config.infer_spec_type_from_file_location!diff --git a/spec/services/search_indexer_spec.rb b/spec/services/search_indexer_spec.rbindex 1721b7b5518..dadcb567a12 100644--- a/spec/services/search_indexer_spec.rb+++ b/spec/services/search_indexer_spec.rb@@ -225,7 +225,6 @@ describe SearchIndexer doit 'should not include lightbox in search' doJobs.run_immediately!- SiteSetting.crawl_images = trueSiteSetting.max_image_width = 1stub_request(:get, "https://meta.discourse.org/some.png")diff --git a/spec/services/user_anonymizer_spec.rb b/spec/services/user_anonymizer_spec.rbindex a150d1e1978..0ed06e82da5 100644--- a/spec/services/user_anonymizer_spec.rb+++ b/spec/services/user_anonymizer_spec.rb@@ -153,6 +153,8 @@ describe UserAnonymizer dotopic = Fabricate(:topic, user: user)quoted_post = create_post(user: user, topic: topic, post_number: 1, raw: "quoted post")++ stub_image_sizepost = create_post(raw: <<~RAW)Lorem ipsumdiff --git a/spec/services/username_changer_spec.rb b/spec/services/username_changer_spec.rbindex b23cbcf1d4d..65d0802b137 100644--- a/spec/services/username_changer_spec.rb+++ b/spec/services/username_changer_spec.rb@@ -107,6 +107,7 @@ describe UsernameChanger doenddef create_post_and_change_username(args = {}, &block)+ stub_image_sizepost = create_post(args.merge(topic_id: topic.id))args.delete(:revisions)&.each do |revision|diff --git a/spec/support/fast_image_helpers.rb b/spec/support/fast_image_helpers.rbnew file mode 100644index 00000000000..55ad54ba422--- /dev/null+++ b/spec/support/fast_image_helpers.rb@@ -0,0 +1,7 @@+# frozen_string_literal: true++module FastImageHelpers+ def stub_image_size(width: nil, height: nil)+ FastImage.stubs(:size).returns([width, height])+ end+end