From 673cd4196f3d4d772916b2411b8e67cd9e9f0ec6 Mon Sep 17 00:00:00 2001 From: Penar Musaraj Date: Thu, 9 Mar 2023 09:53:27 -0500 Subject: [PATCH] FIX: Don't send image sizes for emojis/avatars (#20589) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When using the "review media unless trust level" setting, posts with emojis or quotes will end up in the review queue even though they don't have any uploaded media. That is because our heuristic for this in the new post manager relies on image_sizes. This commit skips sending image_sizes for emojis and avatars. Co-authored-by: RĂ©gis Hanol --- .../app/components/composer-editor.hbs | 6 +++- .../discourse/app/controllers/composer.js | 4 ++- .../review_media_unless_trust_level_spec.rb | 36 +++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 spec/system/composer/review_media_unless_trust_level_spec.rb diff --git a/app/assets/javascripts/discourse/app/components/composer-editor.hbs b/app/assets/javascripts/discourse/app/components/composer-editor.hbs index bb3c6513aa7..273f5f0176e 100644 --- a/app/assets/javascripts/discourse/app/components/composer-editor.hbs +++ b/app/assets/javascripts/discourse/app/components/composer-editor.hbs @@ -23,5 +23,9 @@ {{#if this.allowUpload}} - + {{/if}} \ No newline at end of file diff --git a/app/assets/javascripts/discourse/app/controllers/composer.js b/app/assets/javascripts/discourse/app/controllers/composer.js index 125204ecc7b..0691d25158b 100644 --- a/app/assets/javascripts/discourse/app/controllers/composer.js +++ b/app/assets/javascripts/discourse/app/controllers/composer.js @@ -1008,7 +1008,9 @@ export default Controller.extend({ // TODO: This should not happen in model const imageSizes = {}; document - .querySelectorAll("#reply-control .d-editor-preview img") + .querySelectorAll( + "#reply-control .d-editor-preview img:not(.avatar, .emoji)" + ) .forEach((e) => { const src = e.src; diff --git a/spec/system/composer/review_media_unless_trust_level_spec.rb b/spec/system/composer/review_media_unless_trust_level_spec.rb new file mode 100644 index 00000000000..dc9047d03ad --- /dev/null +++ b/spec/system/composer/review_media_unless_trust_level_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +describe "Composer using review_media", type: :system, js: true do + fab!(:user) { Fabricate(:user) } + fab!(:topic) { Fabricate(:topic, category: Category.find(SiteSetting.uncategorized_category_id)) } + fab!(:post) { Fabricate(:post, topic: topic) } + fab!(:upload) { Fabricate(:upload) } + let(:topic_page) { PageObjects::Pages::Topic.new } + + before do + SiteSetting.review_media_unless_trust_level = 3 + sign_in user + end + + it "does not flag a post with an emoji" do + topic_page.visit_topic_and_open_composer(topic) + topic_page.fill_in_composer(" this one has an emoji: :mask: ") + + within(".d-editor-preview") { expect(page).to have_css(".emoji") } + topic_page.send_reply + + expect(topic_page).to have_post_number(2) + expect(page).not_to have_css(".post-enqueued-modal") + end + + it "flags a post with an image" do + topic_page.visit_topic_and_open_composer(topic) + topic_page.fill_in_composer(" this one has an upload: ") + + attach_file "file-uploader", "#{Rails.root}/spec/fixtures/images/logo.jpg", make_visible: true + within(".d-editor-preview") { expect(page).to have_css("img") } + topic_page.send_reply + + expect(page).to have_css(".post-enqueued-modal") + end +end