Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Allow invites if must_approve_users is true #13257

Merged
merged 1 commit into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/guardian.rb
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def can_invite_to_forum?(groups = nil)
return false if !authenticated?

invites_available = SiteSetting.max_invites_per_day.to_i.positive?
trust_level_requirement_met = !SiteSetting.must_approve_users? && @user.has_trust_level?(SiteSetting.min_trust_level_to_allow_invite.to_i)
trust_level_requirement_met = @user.has_trust_level?(SiteSetting.min_trust_level_to_allow_invite.to_i)

if !is_staff?
return false if !invites_available
Expand Down
5 changes: 0 additions & 5 deletions spec/components/guardian_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -506,11 +506,6 @@
expect(Guardian.new(moderator).can_invite_to_forum?).to be_truthy
end

it 'returns false when the site requires approving users and is regular' do
SiteSetting.expects(:must_approve_users?).returns(true)
expect(Guardian.new(user).can_invite_to_forum?).to be_falsey
end

context 'with groups' do
let(:groups) { [group, another_group] }

Expand Down
16 changes: 16 additions & 0 deletions spec/models/invite_redeemer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@
expect(user.approved).to eq(true)
expect(user.active).to eq(false)
end

it "does not automatically approve users if must_approve_users is true" do
SiteSetting.must_approve_users = true

invite = Fabricate(:invite, email: 'test@example.com')
user = InviteRedeemer.create_user_from_invite(invite: invite, email: invite.email, username: 'test')
expect(user.approved).to eq(false)
end

it "approves user if invited by staff" do
SiteSetting.must_approve_users = true

invite = Fabricate(:invite, email: 'test@example.com', invited_by: Fabricate(:admin))
user = InviteRedeemer.create_user_from_invite(invite: invite, email: invite.email, username: 'test')
expect(user.approved).to eq(true)
end
end

describe "#redeem" do
Expand Down