FIX: limit number of users addable to group at once (#10510)

When someone wants to add > 1000 users at once they will hit a timeout.
Therefore, we should introduce limit and inform the user when limit is exceeded.
This commit is contained in:
Krzysztof Kotlarek
2020-08-25 08:55:21 +10:00
committed by GitHub
parent ed30f49315
commit 7b6f8517bf
3 changed files with 34 additions and 0 deletions

View File

@@ -1245,6 +1245,33 @@ describe GroupsController do
count: 3
))
end
it 'display error when try to add to many users at once' do
begin
GroupsController.send(:remove_const, "ADD_MEMBERS_LIMIT")
GroupsController.const_set("ADD_MEMBERS_LIMIT", 4)
user1.update!(username: 'john')
user2.update!(username: 'alice')
user3 = Fabricate(:user, username: 'bob')
user4 = Fabricate(:user, username: 'anna')
user5 = Fabricate(:user, username: 'sarah')
expect do
put "/groups/#{group.id}/members.json",
params: { user_emails: [user1.email, user2.email, user3.email, user4.email, user5.email].join(",") }
end.to change { group.users.count }.by(0)
expect(response.status).to eq(422)
expect(response.parsed_body["errors"]).to include(I18n.t(
"groups.errors.adding_too_many_users",
limit: 4
))
ensure
GroupsController.send(:remove_const, "ADD_MEMBERS_LIMIT")
GroupsController.const_set("ADD_MEMBERS_LIMIT", 1000)
end
end
end
it "returns 422 if member already exists" do