add better messages telling a user that they sent share requests if they try and email exsisting users
This commit is contained in:
parent
2c47262d54
commit
6beeecefd8
5 changed files with 26 additions and 10 deletions
|
|
@ -87,14 +87,19 @@ class InvitationsController < Devise::InvitationsController
|
|||
def extract_messages(invites)
|
||||
success_message = "Invites Successfully Sent to: "
|
||||
failure_message = "There was a problem with: "
|
||||
following_message = " already are on Diaspora, so you are now sharing with them."
|
||||
successes, failures = invites.partition{|x| x.persisted? }
|
||||
|
||||
success_message += successes.map{|k| k.identifier }.join(', ')
|
||||
failure_message += failures.map{|k| k.identifier }.join(', ')
|
||||
followings, real_failures = failures.partition{|x| x.errors[:recipient].present? }
|
||||
|
||||
success_message += successes.map{|k| k.identifier }.to_sentence
|
||||
failure_message += real_failures.map{|k| k.identifier }.to_sentence
|
||||
following_message += followings.map{|k| k.identifier}.to_sentence
|
||||
|
||||
messages = []
|
||||
messages << success_message if successes.present?
|
||||
messages << failure_message if failures.present?
|
||||
messages << following_message if followings.present?
|
||||
|
||||
messages.join('\n')
|
||||
end
|
||||
|
|
|
|||
|
|
@ -12,8 +12,10 @@ class Invitation < ActiveRecord::Base
|
|||
|
||||
before_validation :set_email_as_default_service
|
||||
|
||||
# before_create :share_with_exsisting_user, :if => :recipient_id?
|
||||
validates_presence_of :identifier, :service
|
||||
validate :valid_identifier?
|
||||
validate :recipient_not_on_pod?
|
||||
validates_presence_of :sender, :aspect, :unless => :admin?
|
||||
validate :ensure_not_inviting_self, :on => :create, :unless => :admin?
|
||||
validate :sender_owns_aspect?, :unless => :admin?
|
||||
|
|
@ -36,11 +38,11 @@ class Invitation < ActiveRecord::Base
|
|||
users_on_pod = User.where(:email => emails, :invitation_token => nil)
|
||||
|
||||
#share with anyone whose email you entered who is on the pod
|
||||
emails = emails - users_on_pod.map{|u| u.email}
|
||||
users_on_pod.each{|u| opts[:sender].share_with(u.person, opts[:aspect])}
|
||||
|
||||
emails.map! do |e|
|
||||
Invitation.create(opts.merge(:identifier => e))
|
||||
user = users_on_pod.find{|u| u.email == e}
|
||||
Invitation.create(opts.merge(:identifier => e, :recipient => user))
|
||||
end
|
||||
emails
|
||||
end
|
||||
|
|
@ -140,6 +142,13 @@ class Invitation < ActiveRecord::Base
|
|||
end
|
||||
|
||||
|
||||
def recipient_not_on_pod?
|
||||
return true if self.recipient.nil?
|
||||
if self.recipient.username?
|
||||
errors[:recipient] << "The user '#{self.identifier}' (#{self.recipient.diaspora_handle}) is already on this pod, so we sent them a share request"
|
||||
end
|
||||
end
|
||||
|
||||
# @note Validation
|
||||
def valid_identifier?
|
||||
return false unless self.identifier
|
||||
|
|
|
|||
|
|
@ -146,7 +146,9 @@ describe ServicesController do
|
|||
end
|
||||
|
||||
it 'does not create a duplicate invitation' do
|
||||
inv = Invitation.create!(:sender => @user, :recipient => eve, :aspect => @user.aspects.first, :identifier => eve.email)
|
||||
invited_user = Factory.build(:user, :username =>nil)
|
||||
invited_user.save(:validate => false)
|
||||
inv = Invitation.create!(:sender => @user, :recipient => invited_user, :aspect => @user.aspects.first, :identifier => eve.email)
|
||||
@invite_params[:invitation_id] = inv.id
|
||||
|
||||
lambda {
|
||||
|
|
|
|||
|
|
@ -13,12 +13,12 @@ describe Invitation do
|
|||
end
|
||||
describe 'validations' do
|
||||
before do
|
||||
@invitation = Factory.build(:invitation, :sender => user, :recipient => eve, :aspect => user.aspects.first)
|
||||
@invitation = Factory.build(:invitation, :sender => user, :recipient => nil, :aspect => user.aspects.first)
|
||||
end
|
||||
|
||||
it 'is valid' do
|
||||
@invitation.sender.should == user
|
||||
@invitation.recipient.should == eve
|
||||
@invitation.recipient.should == nil
|
||||
@invitation.aspect.should == user.aspects.first
|
||||
@invitation.should be_valid
|
||||
end
|
||||
|
|
@ -89,13 +89,13 @@ describe Invitation do
|
|||
invites.all?{|x| x.persisted?}.should be_true
|
||||
end
|
||||
|
||||
it 'shares with people who are already on the pod and does not create an invite for them' do
|
||||
it 'shares with people who are already on the pod' do
|
||||
Factory(:user, :email => @emails.first)
|
||||
invites = nil
|
||||
expect{
|
||||
invites = Invitation.batch_invite(@emails, @opts)
|
||||
}.to change(eve.contacts, :count).by(1)
|
||||
invites.count.should be 1
|
||||
invites.count.should be 2
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -565,7 +565,7 @@ describe User do
|
|||
end
|
||||
|
||||
it 'removes invitations to the user' do
|
||||
Invitation.create!(:sender => eve, :recipient => alice, :identifier => alice.email, :aspect => eve.aspects.first)
|
||||
Invitation.new(:sender => eve, :recipient => alice, :identifier => alice.email, :aspect => eve.aspects.first).save(:validate => false)
|
||||
lambda {
|
||||
alice.destroy
|
||||
}.should change {alice.invitations_to_me(true).count }.by(-1)
|
||||
|
|
|
|||
Loading…
Reference in a new issue