FIX: Do not require trust level to invite to group (#13230)

It used to require SiteSetting.min_trust_level_to_allow_invite to
invite a user to a group, even if the user existed and the inviter was
a group owner.
This commit is contained in:
Dan Ungureanu 2021-06-02 16:28:21 +03:00 committed by GitHub
parent 9d6780f03d
commit d2135b23c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -328,8 +328,6 @@ class GroupsController < ApplicationController
unless current_user.staff? unless current_user.staff?
RateLimiter.new(current_user, "public_group_membership", 3, 1.minute).performed! RateLimiter.new(current_user, "public_group_membership", 3, 1.minute).performed!
end end
elsif !current_user.has_trust_level?(SiteSetting.min_trust_level_to_allow_invite.to_i)
raise Discourse::InvalidAccess
end end
emails = [] emails = []
@ -340,6 +338,8 @@ class GroupsController < ApplicationController
end end
end end
guardian.ensure_can_invite_to_forum!([group]) if emails.present?
if users.empty? && emails.empty? if users.empty? && emails.empty?
raise Discourse::InvalidParameters.new(I18n.t("groups.errors.usernames_or_emails_required")) raise Discourse::InvalidParameters.new(I18n.t("groups.errors.usernames_or_emails_required"))
end end

View File

@ -1212,12 +1212,18 @@ describe GroupsController do
end end
it 'does not add users without sufficient permission' do it 'does not add users without sufficient permission' do
group.add_owner(user)
sign_in(user) sign_in(user)
SiteSetting.min_trust_level_to_allow_invite = user.trust_level + 1
user2 = Fabricate(:user)
put "/groups/#{group.id}/members.json", params: { usernames: user2.username } put "/groups/#{group.id}/members.json", params: { usernames: Fabricate(:user).username }
expect(response.status).to eq(200)
end
it 'does not send invites if user cannot invite' do
group.add_owner(user)
sign_in(user)
put "/groups/#{group.id}/members.json", params: { emails: "test@example.com" }
expect(response.status).to eq(403) expect(response.status).to eq(403)
end end