A platform for community discussion. Free, open, simple.
FIX: Alter "Take Action" default behaviour to hide post (#24088)
Martin Brennan0a4b1b655d44
diff --git a/app/assets/javascripts/discourse/app/components/modal/flag.hbs b/app/assets/javascripts/discourse/app/components/modal/flag.hbsindex 8fc67e7dc97..b8ebc6d6750 100644--- a/app/assets/javascripts/discourse/app/components/modal/flag.hbs+++ b/app/assets/javascripts/discourse/app/components/modal/flag.hbs@@ -32,7 +32,7 @@</:body><:footer><DButton- class="btn-primary"+ class="btn-primary flag-modal__create-flag"@action={{this.createFlag}}@disabled={{not this.submitEnabled}}@title="flagging.submit_tooltip"@@ -42,7 +42,7 @@{{#if this.canSendWarning}}<DButton- class="btn-danger"+ class="btn-danger flag-modal__send-warning"@action={{this.createFlagAsWarning}}@disabled={{not this.submitEnabled}}@icon="exclamation-triangle"@@ -52,13 +52,14 @@{{#if this.canTakeAction}}<ReviewableBundledAction+ class="flag-modal__take-action"@bundle={{this.flagActions}}@performAction={{this.takeAction}}@reviewableUpdating={{not this.submitEnabled}}/><DButton- class="btn-danger"+ class="btn-danger flag-modal__flag-for-review"@action={{this.flagForReview}}@disabled={{not this.submitEnabled this.notifyModeratorsFlag}}@icon="exclamation-triangle"@@ -68,7 +69,7 @@{{#if this.showDeleteSpammer}}<DButton- class="btn-danger delete-spammer"+ class="btn-danger delete-spammer flag-modal__delete-spammer"@action={{this.deleteSpammer}}@disabled={{not this.submitEnabled}}@icon="exclamation-triangle"diff --git a/app/assets/javascripts/discourse/app/components/modal/flag.js b/app/assets/javascripts/discourse/app/components/modal/flag.jsindex 74c556ccf1a..701a70e83e4 100644--- a/app/assets/javascripts/discourse/app/components/modal/flag.js+++ b/app/assets/javascripts/discourse/app/components/modal/flag.js@@ -36,7 +36,7 @@ export default class Flag extends Component {label: I18n.t("flagging.take_action"),actions: [{- id: "agree_and_keep",+ id: "agree_and_hide",icon: "thumbs-up",label: I18n.t("flagging.take_action_options.default.title"),description: I18n.t("flagging.take_action_options.default.details"),diff --git a/app/assets/javascripts/discourse/tests/acceptance/flag-post-test.js b/app/assets/javascripts/discourse/tests/acceptance/flag-post-test.jsindex 73e4f83f17b..2006a2947ae 100644--- a/app/assets/javascripts/discourse/tests/acceptance/flag-post-test.js+++ b/app/assets/javascripts/discourse/tests/acceptance/flag-post-test.js@@ -109,8 +109,14 @@ acceptance("flagging", function (needs) {exists("[data-value='agree_and_silence']"),"it shows the silence action option");- await click("[data-value='agree_and_silence']");- assert.ok(exists(".silence-user-modal"), "it shows the silence modal");+ assert.ok(+ exists("[data-value='agree_and_suspend']"),+ "it shows the suspend action option"+ );+ assert.ok(+ exists("[data-value='agree_and_hide']"),+ "it shows the hide action option"+ );});test("Can silence from take action", async function (assert) {@@ -119,6 +125,7 @@ acceptance("flagging", function (needs) {await click("#radio_inappropriate");await selectKit(".reviewable-action-dropdown").expand();await click("[data-value='agree_and_silence']");+ assert.ok(exists(".silence-user-modal"), "it shows the silence modal");const silenceUntilCombobox = selectKit(".silence-until .combobox");await silenceUntilCombobox.expand();diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex 83160fd0ede..3b3ca1e2469 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -3855,8 +3855,8 @@ en:take_action: "Take Action…"take_action_options:default:- title: "Take Action"- details: "Reach the flag threshold immediately, rather than waiting for more community flags"+ title: "Hide Post"+ details: "Reach the flag threshold immediately, hide the post, and agree with all pending flags"suspend:title: "Suspend User"details: "Reach the flag threshold, and suspend the user"@@ -3882,7 +3882,7 @@ en:ip_address_missing: "(N/A)"hidden_email_address: "(hidden)"submit_tooltip: "Submit the private flag"- take_action_tooltip: "Reach the flag threshold immediately, rather than waiting for more community flags"+ take_action_tooltip: "Reach the flag threshold immediately, hide the post, and agree with all pending flags"cant: "Sorry, you can't flag this post at this time."notify_staff: "Notify staff privately"formatted_name:diff --git a/lib/post_action_creator.rb b/lib/post_action_creator.rbindex f1e46d855ca..7eda9c95567 100644--- a/lib/post_action_creator.rb+++ b/lib/post_action_creator.rb@@ -250,7 +250,9 @@ class PostActionCreatorendscore = ReviewableFlaggedPost.find_by(target: @post)&.score || 0- @post.hide!(@post_action_type_id) if score >= Reviewable.score_required_to_hide_post+ if score >= Reviewable.score_required_to_hide_post || @take_action+ @post.hide!(@post_action_type_id)+ endend# Special case: If you have TL3 and the user is TL0, and the flag is spam,diff --git a/spec/lib/post_action_creator_spec.rb b/spec/lib/post_action_creator_spec.rbindex fef228d75b3..36e723d56ec 100644--- a/spec/lib/post_action_creator_spec.rb+++ b/spec/lib/post_action_creator_spec.rb@@ -271,18 +271,38 @@ RSpec.describe PostActionCreator doenddescribe "take_action" do- before { PostActionCreator.create(Fabricate(:user), post, :inappropriate) }+ it "will hide the post" do+ PostActionCreator+ .new(Fabricate(:moderator), post, PostActionType.types[:spam], take_action: true)+ .perform+ .reviewable+ expect(post.reload).to be_hidden+ end++ context "when there is another reviewable on the post" do+ before { PostActionCreator.create(Fabricate(:user), post, :inappropriate) }++ it "will agree with the old reviewable" do+ reviewable =+ PostActionCreator+ .new(Fabricate(:moderator), post, PostActionType.types[:spam], take_action: true)+ .perform+ .reviewable+ expect(reviewable.reload).to be_approved+ expect(reviewable.reviewable_scores).to all(be_agreed)+ end+ end++ context "when hide_post_sensitivity is low" do+ before { SiteSetting.hide_post_sensitivity = Reviewable.sensitivities[:low] }- it "will agree with the old reviewable" do- reviewable =+ it "still hides the post without considering the score" doPostActionCreator.new(Fabricate(:moderator), post, PostActionType.types[:spam], take_action: true).perform.reviewable- scores = reviewable.reviewable_scores- expect(scores[0]).to be_agreed- expect(scores[1]).to be_agreed- expect(reviewable.reload).to be_approved+ expect(post.reload).to be_hidden+ endendend@@ -307,7 +327,7 @@ RSpec.describe PostActionCreator doscore = result.reviewable.reviewable_scores.lastexpect(score.reason).to eq("queued_by_staff")- expect(post.reload.hidden?).to eq(true)+ expect(post.reload).to be_hiddenendit "hides the topic even if it has replies" dodiff --git a/spec/system/flagging_post_spec.rb b/spec/system/flagging_post_spec.rbnew file mode 100644index 00000000000..b760335838e--- /dev/null+++ b/spec/system/flagging_post_spec.rb@@ -0,0 +1,30 @@+# frozen_string_literal: true++# frozen_string_literal: true++describe "Flagging post", type: :system, js: true do+ fab!(:current_user) { Fabricate(:admin) }+ fab!(:first_post) { Fabricate(:post) }+ fab!(:post_to_flag) { Fabricate(:post, topic: first_post.topic) }++ let(:topic_page) { PageObjects::Pages::Topic.new }+ let(:flag_modal) { PageObjects::Modals::Flag.new }++ before { sign_in(current_user) }++ describe "Using Take Action" do+ it "can select the default action to hide the post, agree with other flags, and reach the flag threshold" do+ other_flag = Fabricate(:flag, post: post_to_flag, user: Fabricate(:moderator))+ expect(other_flag.reload.agreed_at).to be_nil+ topic_page.visit_topic(post_to_flag.topic)+ topic_page.expand_post_actions(post_to_flag)+ topic_page.click_post_action_button(post_to_flag, :flag)+ flag_modal.choose_type(:off_topic)+ flag_modal.take_action(:agree_and_hide)+ expect(+ topic_page.post_by_number(post_to_flag).ancestor(".topic-post.post-hidden"),+ ).to be_present+ expect(other_flag.reload.agreed_at).to be_present+ end+ end+enddiff --git a/spec/system/page_objects/modals/base.rb b/spec/system/page_objects/modals/base.rbindex daa81e5eea9..3b8025ee3e8 100644--- a/spec/system/page_objects/modals/base.rb+++ b/spec/system/page_objects/modals/base.rb@@ -6,6 +6,16 @@ module PageObjectsinclude Capybara::DSLinclude RSpec::Matchers+ BODY_SELECTOR = ""++ def body+ find(".modal-body#{BODY_SELECTOR}")+ end++ def footer+ find(".modal-footer")+ end+def closefind(".modal-close").clickend@@ -19,11 +29,11 @@ module PageObjectsenddef click_primary_button- find(".modal-footer .btn-primary").click+ footer.find(".btn-primary").clickenddef has_content?(content)- find(".modal-body").has_content?(content)+ body.has_content?(content)enddef open?diff --git a/spec/system/page_objects/modals/flag.rb b/spec/system/page_objects/modals/flag.rbnew file mode 100644index 00000000000..1e2da7cba0a--- /dev/null+++ b/spec/system/page_objects/modals/flag.rb@@ -0,0 +1,25 @@+# frozen_string_literal: true++module PageObjects+ module Modals+ class Flag < PageObjects::Modals::Base+ BODY_SELECTOR = ".flag-modal-body"+ MODAL_SELECTOR = ".flag-modal"++ def choose_type(type)+ body.find("#radio_#{type}").click+ end++ def confirm_flag+ click_primary_button+ end++ def take_action(action)+ select_kit =+ PageObjects::Components::SelectKit.new(".modal-footer .reviewable-action-dropdown")+ select_kit.expand+ select_kit.select_row_by_value(action)+ end+ end+ end+enddiff --git a/spec/system/page_objects/pages/topic.rb b/spec/system/page_objects/pages/topic.rbindex 988151d0508..2061ff5ce53 100644--- a/spec/system/page_objects/pages/topic.rb+++ b/spec/system/page_objects/pages/topic.rb@@ -84,6 +84,8 @@ module PageObjectspost_by_number(post).find(".bookmark.with-reminder").clickwhen :replypost_by_number(post).find(".post-controls .reply").click+ when :flag+ post_by_number(post).find(".post-controls .create-flag").clickendend