FEATURE: Show similar users when penalizing a user (#19334)

* FEATURE: Show similar users when penalizing a user

Moderators will be notified if other users with the same IP address
exist before penalizing a user.

* FEATURE: Allow staff to penalize multiple users

This allows staff members to suspend or silence multiple users belonging
to the same person.
This commit is contained in:
Bianca Nenciu
2022-12-08 14:42:33 +02:00
committed by GitHub
parent ae40965896
commit 187b0bfb43
13 changed files with 259 additions and 56 deletions

View File

@@ -103,6 +103,18 @@ RSpec.describe Admin::UsersController do
expect(response.status).to eq(200)
expect(response.parsed_body["id"]).to eq(user.id)
end
it 'returns similar users' do
Fabricate(:user, ip_address: '88.88.88.88')
similar_user = Fabricate(:user, ip_address: user.ip_address)
get "/admin/users/#{user.id}.json"
expect(response.status).to eq(200)
expect(response.parsed_body["id"]).to eq(user.id)
expect(response.parsed_body["similar_users_count"]).to eq(1)
expect(response.parsed_body["similar_users"].map { |u| u["id"] }).to contain_exactly(similar_user.id)
end
end
context "when logged in as a non-staff user" do
@@ -229,6 +241,7 @@ RSpec.describe Admin::UsersController do
describe '#suspend' do
fab!(:created_post) { Fabricate(:post) }
fab!(:other_user) { Fabricate(:user) }
let(:suspend_params) do
{ suspend_until: 5.hours.from_now,
reason: "because of this post",
@@ -421,6 +434,18 @@ RSpec.describe Admin::UsersController do
}, headers: { HTTP_API_KEY: api_key.key }
expect(response.status).to eq(403)
end
it "can silence multiple users" do
put "/admin/users/#{user.id}/suspend.json", params: {
suspend_until: 10.days.from_now,
reason: "short reason",
message: "long reason",
other_user_ids: [other_user.id],
}
expect(response.status).to eq(200)
expect(user.reload).to be_suspended
expect(other_user.reload).to be_suspended
end
end
context "when logged in as a moderator" do
@@ -1386,6 +1411,7 @@ RSpec.describe Admin::UsersController do
describe '#silence' do
fab!(:reg_user) { Fabricate(:user) }
fab!(:other_user) { Fabricate(:user) }
context "when logged in as an admin" do
before { sign_in(admin) }
@@ -1471,6 +1497,13 @@ RSpec.describe Admin::UsersController do
)
)
end
it "can silence multiple users" do
put "/admin/users/#{reg_user.id}/silence.json", params: { other_user_ids: [other_user.id] }
expect(response.status).to eq(200)
expect(reg_user.reload).to be_silenced
expect(other_user.reload).to be_silenced
end
end
context "when logged in as a moderator" do