FEATURE: allow for notification of up to 20 group owners (#13081)

The 5 limit appears to be too low. Limiting to 20 group owners, though high
seems like a fairer limit.

Also... spec cleanup
This commit is contained in:
Sam 2021-05-20 15:28:36 +10:00 committed by GitHub
parent 130160537c
commit 1a620cb01f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 8 deletions

View File

@ -480,6 +480,8 @@ class GroupsController < ApplicationController
) )
end end
MAX_NOTIFIED_OWNERS ||= 20
def request_membership def request_membership
params.require(:reason) params.require(:reason)
@ -487,14 +489,14 @@ class GroupsController < ApplicationController
begin begin
GroupRequest.create!(group: group, user: current_user, reason: params[:reason]) GroupRequest.create!(group: group, user: current_user, reason: params[:reason])
rescue ActiveRecord::RecordNotUnique => e rescue ActiveRecord::RecordNotUnique
return render json: failed_json.merge(error: I18n.t("groups.errors.already_requested_membership")), status: 409 return render json: failed_json.merge(error: I18n.t("groups.errors.already_requested_membership")), status: 409
end end
usernames = [current_user.username].concat( usernames = [current_user.username].concat(
group.users.where('group_users.owner') group.users.where('group_users.owner')
.order("users.last_seen_at DESC") .order("users.last_seen_at DESC")
.limit(5) .limit(MAX_NOTIFIED_OWNERS)
.pluck("users.username") .pluck("users.username")
) )

View File

@ -1405,10 +1405,7 @@ describe GroupsController do
it "will invite the user if their username and email are both invited" do it "will invite the user if their username and email are both invited" do
new_user = Fabricate(:user) new_user = Fabricate(:user)
put "/groups/#{group.id}/members.json", params: { usernames: new_user.username, emails: new_user.email } put "/groups/#{group.id}/members.json", params: { usernames: new_user.username, emails: new_user.email }
expect(response.status).to eq(200) expect(response.status).to eq(200)
body = response.parsed_body
expect(new_user.reload.group_ids.include?(group.id)).to eq(true) expect(new_user.reload.group_ids.include?(group.id)).to eq(true)
end end
@ -1471,8 +1468,6 @@ describe GroupsController do
it "raises an error if user to be removed is not found" do it "raises an error if user to be removed is not found" do
delete "/groups/#{group.id}/members.json", params: { user_id: -10 } delete "/groups/#{group.id}/members.json", params: { user_id: -10 }
response_body = response.parsed_body
expect(response.status).to eq(400) expect(response.status).to eq(400)
end end
@ -1627,7 +1622,7 @@ describe GroupsController do
end end
it "sends a private message when accepted" do it "sends a private message when accepted" do
group_request = GroupRequest.create!(group: group, user: other_user) GroupRequest.create!(group: group, user: other_user)
expect { put "/groups/#{group.id}/handle_membership_request.json", params: { user_id: other_user.id, accept: true } } expect { put "/groups/#{group.id}/handle_membership_request.json", params: { user_id: other_user.id, accept: true } }
.to change { Topic.count }.by(1) .to change { Topic.count }.by(1)
.and change { Post.count }.by(1) .and change { Post.count }.by(1)