Merge pull request #4685 from techAPJ/approve-users-invite-fix

FIX: allow existing users to be invited to topic/message when must_approve_users is enabled
This commit is contained in:
Arpit Jalan
2017-02-03 13:22:18 +05:30
committed by GitHub
9 changed files with 113 additions and 81 deletions

View File

@@ -330,25 +330,24 @@ describe Invite do
end
context 'invited to topics' do
let!(:topic) { Fabricate(:private_message_topic) }
let(:tl2_user) { Fabricate(:user, trust_level: 2) }
let!(:topic) { Fabricate(:private_message_topic, user: tl2_user) }
let!(:invite) {
topic.invite(topic.user, 'jake@adventuretime.ooo')
}
context 'redeem topic invite' do
it 'adds the user to the topic_users' do
user = invite.redeem
topic.reload
expect(topic.allowed_users.include?(user)).to eq(true)
expect(Guardian.new(user).can_see?(topic)).to eq(true)
end
end
context 'invited by another user to the same topic' do
let(:coding_horror) { User.find_by(username: "CodingHorror") }
let!(:another_invite) { topic.invite(coding_horror, 'jake@adventuretime.ooo') }
let(:another_tl2_user) { Fabricate(:user, trust_level: 2) }
let!(:another_invite) { topic.invite(another_tl2_user, 'jake@adventuretime.ooo') }
let!(:user) { invite.redeem }
it 'adds the user to the topic_users' do
@@ -358,25 +357,14 @@ describe Invite do
end
context 'invited by another user to a different topic' do
let!(:another_invite) { another_topic.invite(coding_horror, 'jake@adventuretime.ooo') }
let!(:user) { invite.redeem }
let(:coding_horror) { User.find_by(username: "CodingHorror") }
let(:another_topic) { Fabricate(:topic, category_id: nil, archetype: "private_message", user: coding_horror) }
let(:another_tl2_user) { Fabricate(:user, trust_level: 2) }
let(:another_topic) { Fabricate(:topic, user: another_tl2_user) }
it 'adds the user to the topic_users of the first topic' do
expect(another_topic.invite(another_tl2_user, user.username)).to be_truthy # invited via username
expect(topic.allowed_users.include?(user)).to eq(true)
expect(another_topic.allowed_users.include?(user)).to eq(true)
duplicate_invite = Invite.find_by(id: another_invite.id)
expect(duplicate_invite).to be_nil
end
context 'if they redeem the other invite afterwards' do
it 'wont redeem a duplicate invite' do
expect(another_invite.redeem).to be_blank
end
end
end
end

View File

@@ -502,28 +502,33 @@ describe Topic do
end
it "rate limits topic invitations" do
SiteSetting.stubs(:max_topic_invitations_per_day).returns(2)
RateLimiter.stubs(:disabled?).returns(false)
RateLimiter.clear_all!
context 'rate limits' do
start = Time.now.tomorrow.beginning_of_day
freeze_time(start)
it "rate limits topic invitations" do
SiteSetting.stubs(:max_topic_invitations_per_day).returns(2)
RateLimiter.stubs(:disabled?).returns(false)
RateLimiter.clear_all!
user = Fabricate(:user)
topic = Fabricate(:topic)
start = Time.now.tomorrow.beginning_of_day
freeze_time(start)
freeze_time(start + 10.minutes)
topic.invite(topic.user, user.username)
user = Fabricate(:user)
trust_level_2 = Fabricate(:user, trust_level: 2)
topic = Fabricate(:topic, user: trust_level_2)
freeze_time(start + 20.minutes)
topic.invite(topic.user, "walter@white.com")
freeze_time(start + 10.minutes)
topic.invite(topic.user, user.username)
freeze_time(start + 30.minutes)
freeze_time(start + 20.minutes)
topic.invite(topic.user, "walter@white.com")
freeze_time(start + 30.minutes)
expect {
topic.invite(topic.user, "user@example.com")
}.to raise_error(RateLimiter::LimitExceeded)
end
expect {
topic.invite(topic.user, "user@example.com")
}.to raise_error(RateLimiter::LimitExceeded)
end
context 'bumping topics' do