Merge branch 'master' of github.com:diaspora/diaspora
This commit is contained in:
commit
c29bc0ce65
6 changed files with 17 additions and 22 deletions
|
|
@ -13,14 +13,13 @@ class InvitationsController < Devise::InvitationsController
|
||||||
redirect_to :back
|
redirect_to :back
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
params[:user][:aspect_id] = params[:user].delete(:aspects)
|
aspect = params[:user].delete(:aspects)
|
||||||
message = params[:user].delete(:invite_messages)
|
message = params[:user].delete(:invite_messages)
|
||||||
params[:user][:invite_message] = message unless message == ""
|
|
||||||
emails = params[:user][:email].split(/, */)
|
emails = params[:user][:email].split(/, */)
|
||||||
|
|
||||||
good_emails, bad_emails = emails.partition{|e| e.try(:match, Devise.email_regexp)}
|
good_emails, bad_emails = emails.partition{|e| e.try(:match, Devise.email_regexp)}
|
||||||
|
|
||||||
good_emails.each{|e| Resque.enqueue(Jobs::InviteUser, current_user.id, params[:user].merge({:email => e}))}
|
good_emails.each{|e| Resque.enqueue(Jobs::InviteUser, current_user.id, e, aspect, message)}
|
||||||
|
|
||||||
if bad_emails.any?
|
if bad_emails.any?
|
||||||
flash[:error] = I18n.t('invitations.create.sent') + good_emails.join(', ') + " "+ I18n.t('invitations.create.rejected') + bad_emails.join(', ')
|
flash[:error] = I18n.t('invitations.create.sent') + good_emails.join(', ') + " "+ I18n.t('invitations.create.rejected') + bad_emails.join(', ')
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ class Invitation
|
||||||
validates_presence_of :from, :to, :into
|
validates_presence_of :from, :to, :into
|
||||||
|
|
||||||
def self.invite(opts = {})
|
def self.invite(opts = {})
|
||||||
|
return false if opts[:email] == opts[:from].email
|
||||||
existing_user = User.find_by_email(opts[:email])
|
existing_user = User.find_by_email(opts[:email])
|
||||||
if existing_user
|
if existing_user
|
||||||
if opts[:from].contact_for(opts[:from].person)
|
if opts[:from].contact_for(opts[:from].person)
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
module Jobs
|
module Jobs
|
||||||
class InviteUser
|
class InviteUser
|
||||||
@queue = :email
|
@queue = :email
|
||||||
def self.perform(sender_id, params)
|
def self.perform(sender_id, email, aspect_id, invite_message)
|
||||||
user = User.find(sender_id)
|
user = User.find(sender_id)
|
||||||
user.invite_user(params)
|
user.invite_user(email, aspect_id, invite_message)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -362,14 +362,13 @@ class User
|
||||||
end
|
end
|
||||||
|
|
||||||
###Invitations############
|
###Invitations############
|
||||||
def invite_user(opts = {})
|
def invite_user(email, aspect_id, invite_message = "")
|
||||||
aspect_id = opts.delete(:aspect_id)
|
aspect_object = Aspect.first(:user_id => self.id, :id => aspect_id)
|
||||||
aspect_object = self.aspects.find_by_id(aspect_id)
|
|
||||||
if aspect_object
|
if aspect_object
|
||||||
Invitation.invite(:email => opts[:email],
|
Invitation.invite(:email => email,
|
||||||
:from => self,
|
:from => self,
|
||||||
:into => aspect_object,
|
:into => aspect_object,
|
||||||
:message => opts[:invite_message])
|
:message => invite_message)
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ describe InvitationsController do
|
||||||
describe "#update" do
|
describe "#update" do
|
||||||
before do
|
before do
|
||||||
user.invites = 5
|
user.invites = 5
|
||||||
@invited_user = user.invite_user(:email => "a@a.com", :aspect_id => user.aspects.first.id)
|
@invited_user = user.invite_user("a@a.com", user.aspects.first.id)
|
||||||
@accept_params = {:user=>
|
@accept_params = {:user=>
|
||||||
{:password_confirmation =>"password",
|
{:password_confirmation =>"password",
|
||||||
:username=>"josh",
|
:username=>"josh",
|
||||||
|
|
|
||||||
|
|
@ -13,32 +13,28 @@ describe User do
|
||||||
let(:aspect2) {inviter_with_3_invites.aspects.create(:name => "Jersey Girls")}
|
let(:aspect2) {inviter_with_3_invites.aspects.create(:name => "Jersey Girls")}
|
||||||
|
|
||||||
context "creating invites" do
|
context "creating invites" do
|
||||||
it 'requires an apect' do
|
|
||||||
inviter.invite_user(:email => "maggie@example.com").should == false
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'requires your aspect' do
|
it 'requires your aspect' do
|
||||||
inviter.invite_user(:email => "maggie@example.com", :aspect_id => wrong_aspect.id).should == false
|
inviter.invite_user("maggie@example.com", wrong_aspect.id).should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'calls Invitation.invite' do
|
it 'calls Invitation.invite' do
|
||||||
Invitation.should_receive(:invite)
|
Invitation.should_receive(:invite)
|
||||||
inviter.invite_user(:email => @email, :aspect_id => aspect.id)
|
inviter.invite_user(@email, aspect.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'has an invitation' do
|
it 'has an invitation' do
|
||||||
inviter.invite_user(:email => "joe@example.com", :aspect_id => aspect.id).invitations_to_me.count.should == 1
|
inviter.invite_user("joe@example.com", aspect.id).invitations_to_me.count.should == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates it with an email' do
|
it 'creates it with an email' do
|
||||||
inviter.invite_user(:email => "joe@example.com", :aspect_id => aspect.id).email.should == "joe@example.com"
|
inviter.invite_user("joe@example.com", aspect.id).email.should == "joe@example.com"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
it 'throws if you try to add someone you"re connected to' do
|
it 'throws if you try to add someone you"re connected to' do
|
||||||
connect_users(inviter, aspect, another_user, wrong_aspect)
|
connect_users(inviter, aspect, another_user, wrong_aspect)
|
||||||
inviter.reload
|
inviter.reload
|
||||||
proc{inviter.invite_user(:email => another_user.email, :aspect_id => aspect.id)}.should raise_error /already connected/
|
proc{inviter.invite_user(another_user.email, aspect.id)}.should raise_error /already connected/
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
@ -46,8 +42,8 @@ describe User do
|
||||||
context "limit on invites" do
|
context "limit on invites" do
|
||||||
|
|
||||||
it 'does not invite people I already invited' do
|
it 'does not invite people I already invited' do
|
||||||
inviter_with_3_invites.invite_user(:email => "email1@example.com", :aspect_id => aspect2.id)
|
inviter_with_3_invites.invite_user("email1@example.com", aspect2.id)
|
||||||
proc{inviter_with_3_invites.invite_user(:email => "email1@example.com", :aspect_id => aspect2.id)}.should raise_error /You already invited this person/
|
proc{inviter_with_3_invites.invite_user("email1@example.com", aspect2.id)}.should raise_error /You already invited this person/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue