mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Throw error when removing a user from group fails (#9162)
This commit ensures that an error is thrown when a user fails to be removed from a group instead of silently failing. This means when using the api you will receive a 400 instead of a 200 if there is a failure. The remove group endpoint allows the removal of multiple users, this change means that if you try to delete 10 users, but 1 of them fails you will receive a 400 instead of 200 even though the other 9 were removed successfully. Rather than adding a bunch more complexity I think this is more than adequate for most use cases.
This commit is contained in:
@@ -1192,6 +1192,11 @@ describe GroupsController do
|
||||
expect(response.status).to eq(400)
|
||||
end
|
||||
|
||||
it "raises an error when removing a valid user but is not a member of that group" do
|
||||
delete "/groups/#{group.id}/members.json", params: { user_id: -1 }
|
||||
expect(response.status).to eq(400)
|
||||
end
|
||||
|
||||
context "is able to remove a member" do
|
||||
it "removes by id" do
|
||||
expect do
|
||||
@@ -1314,12 +1319,10 @@ describe GroupsController do
|
||||
end
|
||||
|
||||
it "only removes users in that group" do
|
||||
expect do
|
||||
delete "/groups/#{group1.id}/members.json",
|
||||
params: { usernames: [user.username, user2.username].join(",") }
|
||||
end.to change { group1.users.count }.by(-1)
|
||||
delete "/groups/#{group1.id}/members.json",
|
||||
params: { usernames: [user.username, user2.username].join(",") }
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.status).to eq(400)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user