Skip to content

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.gjs
index 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.rb
index 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::ActionBase
delegate :user, to: :guardian, private: true
def call
- return if post.blank? || post_action.blank?
+ return if post.blank? || post_action.blank? || post_action == "none"
send(post_action)
rescue NoMethodError
end
diff --git a/app/services/user/silence.rb b/app/services/user/silence.rb
index 13b70112c0d..c993ba21cb4 100644
--- a/app/services/user/silence.rb
+++ b/app/services/user/silence.rb
@@ -17,7 +17,11 @@ class User::Silence
validates :reason, presence: true, length: { maximum: 300 }
validates :silenced_till, presence: true
validates :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: true
end
model :user
diff --git a/app/services/user/suspend.rb b/app/services/user/suspend.rb
index 1802b1c056b..91eacad8919 100644
--- a/app/services/user/suspend.rb
+++ b/app/services/user/suspend.rb
@@ -17,7 +17,11 @@ class User::Suspend
validates :reason, presence: true, length: { maximum: 300 }
validates :suspend_until, presence: true
validates :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: true
end
model :user
diff --git a/spec/services/user/action/trigger_post_action_spec.rb b/spec/services/user/action/trigger_post_action_spec.rb
index 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 do
end
end
+ 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" do
context "when post_action is 'delete'" do
let(:post_action) { "delete" }
diff --git a/spec/services/user/silence_spec.rb b/spec/services/user/silence_spec.rb
index 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 do
end
it do
is_expected.to validate_inclusion_of(:post_action).in_array(
- %w[delete delete_replies edit],
+ %w[delete delete_replies edit none],
).allow_blank
end
end
diff --git a/spec/services/user/suspend_spec.rb b/spec/services/user/suspend_spec.rb
index 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 do
end
it do
is_expected.to validate_inclusion_of(:post_action).in_array(
- %w[delete delete_replies edit],
+ %w[delete delete_replies edit none],
).allow_blank
end
end
diff --git a/spec/system/admin_user_spec.rb b/spec/system/admin_user_spec.rb
index 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 do
I18n.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
+ end
end
describe "the silence user modal" do
diff --git a/spec/system/page_objects/modals/penalize_user.rb b/spec/system/page_objects/modals/penalize_user.rb
index 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 PageObjects
def modal
find(".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)
+ end
end
end
end