FEATURE: allow sending bulk invites to staged users
This commit is contained in:
parent
c32bd8ae48
commit
2ae71b7a87
|
@ -93,7 +93,7 @@ module Jobs
|
|||
topic = get_topic(invite[:topic_id])
|
||||
|
||||
begin
|
||||
if user = User.find_by_email(email)
|
||||
if user = Invite.find_user_by_email(email)
|
||||
if groups.present?
|
||||
Group.transaction do
|
||||
groups.each do |group|
|
||||
|
|
|
@ -165,7 +165,7 @@ class Invite < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.find_user_by_email(email)
|
||||
User.with_email(email).where(staged: false).first
|
||||
User.with_email(Email.downcase(email)).where(staged: false).first
|
||||
end
|
||||
|
||||
def self.get_group_ids(group_names)
|
||||
|
|
|
@ -9,8 +9,9 @@ describe Jobs::BulkInvite do
|
|||
fab!(:group1) { Fabricate(:group, name: 'group1') }
|
||||
fab!(:group2) { Fabricate(:group, name: 'group2') }
|
||||
fab!(:topic) { Fabricate(:topic) }
|
||||
let(:staged_user) { Fabricate(:user, staged: true, active: false) }
|
||||
let(:email) { "test@discourse.org" }
|
||||
let(:invites) { [{ email: 'test2@discourse.org' }, { email: 'test@discourse.org', groups: 'GROUP1;group2', topic_id: topic.id }] }
|
||||
let(:invites) { [{ email: staged_user.email }, { email: 'test2@discourse.org' }, { email: 'test@discourse.org', groups: 'GROUP1;group2', topic_id: topic.id }] }
|
||||
|
||||
it 'raises an error when the invites array is missing' do
|
||||
expect { Jobs::BulkInvite.new.execute(current_user_id: user.id) }
|
||||
|
@ -28,15 +29,14 @@ describe Jobs::BulkInvite do
|
|||
invites: invites
|
||||
)
|
||||
|
||||
invite = Invite.last
|
||||
|
||||
expect(invite.email).to eq(email)
|
||||
expect(Invite.exists?(email: staged_user.email)).to eq(true)
|
||||
expect(Invite.exists?(email: "test2@discourse.org")).to eq(true)
|
||||
|
||||
invite = Invite.last
|
||||
expect(invite.email).to eq(email)
|
||||
expect(invite.invited_groups.pluck(:group_id)).to contain_exactly(
|
||||
group1.id, group2.id
|
||||
)
|
||||
|
||||
expect(invite.topic_invites.pluck(:topic_id)).to contain_exactly(topic.id)
|
||||
end
|
||||
|
||||
|
@ -84,8 +84,9 @@ describe Jobs::BulkInvite do
|
|||
current_user_id: admin.id,
|
||||
invites: invites
|
||||
)
|
||||
end.to change { Invite.count }.by(1)
|
||||
end.to change { Invite.count }.by(2)
|
||||
|
||||
expect(Invite.exists?(email: staged_user.email)).to eq(true)
|
||||
expect(Invite.exists?(email: "test2@discourse.org")).to eq(true)
|
||||
expect(existing_user.reload.groups).to eq([group1])
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue