A platform for community discussion. Free, open, simple.
FIX: bug when silence user and do nothing to post (#33819)
Krzysztof Kotlarekfcee78a32705
diff --git a/app/assets/javascripts/admin/addon/components/modal/penalize-user.gjs b/app/assets/javascripts/admin/addon/components/modal/penalize-user.gjsindex fda56881efd..41e0ea3ca6b 100644--- a/app/assets/javascripts/admin/addon/components/modal/penalize-user.gjs+++ b/app/assets/javascripts/admin/addon/components/modal/penalize-user.gjs@@ -112,8 +112,8 @@ export default class PenalizeUser extends Component {if (this.successCallback) {await this.successCallback(result);}- } catch {- this.flash = extractError(result);+ } catch (error) {+ this.flash = result ? extractError(result) : extractError(error);} finally {this.penalizing = false;}diff --git a/app/services/user/action/trigger_post_action.rb b/app/services/user/action/trigger_post_action.rbindex fd310849ae6..f076e3defac 100644--- a/app/services/user/action/trigger_post_action.rb+++ b/app/services/user/action/trigger_post_action.rb@@ -9,7 +9,7 @@ class User::Action::TriggerPostAction < Service::ActionBasedelegate :user, to: :guardian, private: truedef call- return if post.blank? || post_action.blank?+ return if post.blank? || post_action.blank? || post_action == "none"send(post_action)rescue NoMethodErrorenddiff --git a/app/services/user/silence.rb b/app/services/user/silence.rbindex 13b70112c0d..c993ba21cb4 100644--- a/app/services/user/silence.rb+++ b/app/services/user/silence.rb@@ -17,7 +17,11 @@ class User::Silencevalidates :reason, presence: true, length: { maximum: 300 }validates :silenced_till, presence: truevalidates :other_user_ids, length: { maximum: User::MAX_SIMILAR_USERS }- validates :post_action, inclusion: { in: %w[delete delete_replies edit] }, allow_blank: true+ validates :post_action,+ inclusion: {+ in: %w[delete delete_replies edit none],+ },+ allow_blank: trueendmodel :userdiff --git a/app/services/user/suspend.rb b/app/services/user/suspend.rbindex 1802b1c056b..91eacad8919 100644--- a/app/services/user/suspend.rb+++ b/app/services/user/suspend.rb@@ -17,7 +17,11 @@ class User::Suspendvalidates :reason, presence: true, length: { maximum: 300 }validates :suspend_until, presence: truevalidates :other_user_ids, length: { maximum: User::MAX_SIMILAR_USERS }- validates :post_action, inclusion: { in: %w[delete delete_replies edit] }, allow_blank: true+ validates :post_action,+ inclusion: {+ in: %w[delete delete_replies edit none],+ },+ allow_blank: trueendmodel :userdiff --git a/spec/services/user/action/trigger_post_action_spec.rb b/spec/services/user/action/trigger_post_action_spec.rbindex b732f20ff5f..cdc19bc373e 100644--- a/spec/services/user/action/trigger_post_action_spec.rb+++ b/spec/services/user/action/trigger_post_action_spec.rb@@ -26,6 +26,13 @@ RSpec.describe User::Action::TriggerPostAction doendend+ context "when post_action is 'none'" do+ let(:post_action) { "none" }+ it "does nothing" do+ expect { action }.not_to change { Post.count }+ end+ end+context "when post and post_action are defined" docontext "when post_action is 'delete'" dolet(:post_action) { "delete" }diff --git a/spec/services/user/silence_spec.rb b/spec/services/user/silence_spec.rbindex ca13590f632..fca97d415cd 100644--- a/spec/services/user/silence_spec.rb+++ b/spec/services/user/silence_spec.rb@@ -13,7 +13,7 @@ RSpec.describe User::Silence doendit dois_expected.to validate_inclusion_of(:post_action).in_array(- %w[delete delete_replies edit],+ %w[delete delete_replies edit none],).allow_blankendenddiff --git a/spec/services/user/suspend_spec.rb b/spec/services/user/suspend_spec.rbindex faa0e9af155..12af49b0464 100644--- a/spec/services/user/suspend_spec.rb+++ b/spec/services/user/suspend_spec.rb@@ -13,7 +13,7 @@ RSpec.describe User::Suspend doendit dois_expected.to validate_inclusion_of(:post_action).in_array(- %w[delete delete_replies edit],+ %w[delete delete_replies edit none],).allow_blankendenddiff --git a/spec/system/admin_user_spec.rb b/spec/system/admin_user_spec.rbindex 3c4632148b0..9750996d1a9 100644--- a/spec/system/admin_user_spec.rb+++ b/spec/system/admin_user_spec.rb@@ -69,6 +69,30 @@ describe "Admin User Page", type: :system doI18n.t("admin_js.admin.user.other_matches", count: 1, username: user.username),)end++ it "suspends the user" do+ admin_user_page.click_suspend_button+ suspend_user_modal.fill_in_reason("spamming")+ suspend_user_modal.set_future_date("tomorrow")+ suspend_user_modal.perform+ expect(suspend_user_modal).to be_closed+ end++ it "displays error when used is already suspended" do+ admin_user_page.click_suspend_button+ suspend_user_modal.fill_in_reason("spamming")+ suspend_user_modal.set_future_date("tomorrow")++ user.update!(suspended_till: 1.day.from_now)+ StaffActionLogger.new(current_user).log_user_suspend(user, "spamming")++ suspend_user_modal.perform++ expect(suspend_user_modal).to have_error_message(+ "User was already suspended by #{current_user.username} just now.",+ )+ expect(suspend_user_modal).to be_open+ endenddescribe "the silence user modal" dodiff --git a/spec/system/page_objects/modals/penalize_user.rb b/spec/system/page_objects/modals/penalize_user.rbindex 5ae2fb39ae2..7ad17656b3c 100644--- a/spec/system/page_objects/modals/penalize_user.rb+++ b/spec/system/page_objects/modals/penalize_user.rb@@ -14,6 +14,24 @@ module PageObjectsdef modalfind(".d-modal.#{@penalty_type}-user-modal")end++ def fill_in_reason(reason)+ find("input.suspend-reason").fill_in with: reason+ end++ def set_future_date(date)+ select = PageObjects::Components::SelectKit.new(".future-date-input details")+ select.expand+ select.select_row_by_value(date)+ end++ def perform+ find(".perform-penalize").click+ end++ def has_error_message?(message)+ expect(find("#modal-alert").text).to eq(message)+ endendendend