mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 03:59:50 +08:00
35b748e7f4
This commit fixes a bug where the silence button is incorrectly displayed on the admin page of a staff user. It's not actually possible to silence a staff user because the backend correctly prevents it, but the frontend isn't checking if the button should be displayed. Another small bug that this commit fixes is the similar users list not showing up inside the silence/suspend modals due to also a bug in the frontend. I've also changed the way similar users are loaded so that they're not returned by the `admin/users#show` endpoint anymore and moved them into a new endpoint that the penalize modals (suspend and silence) can call directly to retrieve the list of users. This is done because the similar users list is never shown on the admin user page (`/admin/users/:user_id/:username`); they're only needed when the suspend or silence modals are opened. Internal topic: t/130014.
70 lines
2.4 KiB
Ruby
70 lines
2.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
describe "Admin User Page", type: :system do
|
|
fab!(:current_user) { Fabricate(:admin) }
|
|
|
|
let(:admin_user_page) { PageObjects::Pages::AdminUser.new }
|
|
let(:suspend_user_modal) { PageObjects::Modals::PenalizeUser.new("suspend") }
|
|
let(:silence_user_modal) { PageObjects::Modals::PenalizeUser.new("silence") }
|
|
|
|
before { sign_in(current_user) }
|
|
|
|
context "when visiting an admin's page" do
|
|
fab!(:admin)
|
|
|
|
before { admin_user_page.visit(admin) }
|
|
|
|
it "doesn't display the suspend or silence buttons" do
|
|
expect(admin_user_page).to have_no_suspend_button
|
|
expect(admin_user_page).to have_no_silence_button
|
|
end
|
|
end
|
|
|
|
context "when visiting a moderator's page" do
|
|
fab!(:moderator)
|
|
|
|
before { admin_user_page.visit(moderator) }
|
|
|
|
it "doesn't display the suspend or silence buttons" do
|
|
expect(admin_user_page).to have_no_suspend_button
|
|
expect(admin_user_page).to have_no_silence_button
|
|
end
|
|
end
|
|
|
|
context "when visting a regular user's page" do
|
|
fab!(:user) { Fabricate(:user, ip_address: "93.123.44.90") }
|
|
fab!(:similar_user) { Fabricate(:user, ip_address: user.ip_address) }
|
|
fab!(:another_mod) { Fabricate(:moderator, ip_address: user.ip_address) }
|
|
fab!(:another_admin) { Fabricate(:admin, ip_address: user.ip_address) }
|
|
|
|
before { admin_user_page.visit(user) }
|
|
|
|
it "displays the suspend and silence buttons" do
|
|
expect(admin_user_page).to have_suspend_button
|
|
expect(admin_user_page).to have_silence_button
|
|
end
|
|
|
|
describe "the suspend user modal" do
|
|
it "displays the list of users who share the same IP but are not mods or admins" do
|
|
admin_user_page.click_suspend_button
|
|
|
|
expect(suspend_user_modal.similar_users).to contain_exactly(similar_user.username)
|
|
expect(admin_user_page.similar_users_warning).to include(
|
|
I18n.t("admin_js.admin.user.other_matches", count: 1, username: user.username),
|
|
)
|
|
end
|
|
end
|
|
|
|
describe "the silence user modal" do
|
|
it "displays the list of users who share the same IP but are not mods or admins" do
|
|
admin_user_page.click_silence_button
|
|
|
|
expect(silence_user_modal.similar_users).to contain_exactly(similar_user.username)
|
|
expect(admin_user_page.similar_users_warning).to include(
|
|
I18n.t("admin_js.admin.user.other_matches", count: 1, username: user.username),
|
|
)
|
|
end
|
|
end
|
|
end
|
|
end
|