diff --git a/app/controllers/invitations_controller.rb b/app/controllers/invitations_controller.rb index b5476a3f08e17e764c1e5dc8842c19e4409e0798..15cee4ecee795c7e2703e581798a6413bb57cd99 100644 --- a/app/controllers/invitations_controller.rb +++ b/app/controllers/invitations_controller.rb @@ -23,6 +23,17 @@ class InvitationsController < Devise::InvitationsController good_emails, bad_emails = emails.partition{|e| e.try(:match, Devise.email_regexp)} + if good_emails.include?(current_user.email) + if good_emails.length == 1 + flash[:error] = I18n.t 'invitations.create.own_address' + redirect_to :back + return + else + bad_emails.push(current_user.email) + good_emails.delete(current_user.email) + end + end + good_emails.each{|e| Resque.enqueue(Job::InviteUserByEmail, current_user.id, e, aspect, message)} if bad_emails.any? diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index b29484649348a146e601f36ceec782640ab0e1d9..dc3b552d71b1114addc16bd3e945546a28118163 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -238,7 +238,8 @@ en: rejected: "The following email addresses had problems: " no_more: "You have no more invitations." already_sent: "You already invited this person." - already_contacts: "You are already connected with this person" + already_contacts: "You are already connected with this person" + own_address: "You can't send an invitation to your own address." new: invite_someone_to_join: "Invite someone to join Diaspora!" if_they_accept_info: "if they accept, they will be added to the aspect you invited them." diff --git a/spec/controllers/invitations_controller_spec.rb b/spec/controllers/invitations_controller_spec.rb index 0be7b0c106410f48a2201f0b66559ec68b216129..920290a1bde6b6c0ea09022cffb216ae1d7a6ef2 100644 --- a/spec/controllers/invitations_controller_spec.rb +++ b/spec/controllers/invitations_controller_spec.rb @@ -61,6 +61,15 @@ describe InvitationsController do post :create, :user => @invite response.should redirect_to("http://test.host/cats/foo") end + + it 'strips out your own email' do + lambda { + post :create, :user => @invite.merge(:email => @user.email) + }.should_not change(User, :count) + + Resque.should_receive(:enqueue).once + post :create, :user => @invite.merge(:email => "hello@example.org, #{@user.email}") + end end describe "#update" do