0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-14 13:58:53 +08:00
discourse/spec/system/page_objects/modals/penalize_user.rb
Arpit Jalan 8db91a42d8
FIX: Restore enabled checkboxes for similar users in penalty modals (#41801)
The suspend user modal lists other accounts sharing the same IP address,
with a checkbox next to each so staff can penalize them in the same
action. Since #41227, every one of those checkboxes was disabled, making
it impossible to select anyone.

The modal enables a checkbox only when the user's `can_be_suspended`
attribute is `true` in the similar-users response. That attribute
regressed as a side effect of #41227: it added `can_be_suspended` to the
parent `AdminUserListSerializer` behind an `include_can_be_suspended?`
opt-in guard for the admin users list. `SimilarAdminUserSerializer`
inherited that guard, and since the similar-users endpoint never passes
the opt-in option, the attribute was silently dropped from its response
— and a missing attribute reads as "cannot be suspended", disabling the
checkbox.

This change overrides the guard in `SimilarAdminUserSerializer` so the
attribute is always serialized, as it was before. It also adds a request
spec pinning `can_be_suspended`/`can_be_silenced` in the response, and
extends the suspend system spec to tick a similar user's checkbox and
verify both accounts get suspended — closing the coverage gap that let
this regress unnoticed.
2026-07-17 17:14:39 +05:30

45 lines
1.1 KiB
Ruby
Vendored

# frozen_string_literal: true
module PageObjects
module Modals
class PenalizeUser < PageObjects::Modals::Base
def initialize(penalty_type)
@penalty_type = penalty_type
end
def similar_users
modal.all("table tbody tr td:nth-child(2)").map(&:text)
end
def select_similar_user(username)
modal.find("table tbody tr", text: username).check
end
def modal
find(".d-modal.#{@penalty_type}-user-modal")
end
def fill_in_suspend_reason(reason)
find("input.suspend-reason").fill_in with: reason
end
def fill_in_silence_reason(reason)
find("input.silence-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