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)
|
def extract_messages(invites)
|
||||||
success_message = "Invites Successfully Sent to: "
|
success_message = "Invites Successfully Sent to: "
|
||||||
failure_message = "There was a problem with: "
|
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? }
|
successes, failures = invites.partition{|x| x.persisted? }
|
||||||
|
|
||||||
success_message += successes.map{|k| k.identifier }.join(', ')
|
followings, real_failures = failures.partition{|x| x.errors[:recipient].present? }
|
||||||
failure_message += failures.map{|k| k.identifier }.join(', ')
|
|
||||||
|
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 = []
|
||||||
messages << success_message if successes.present?
|
messages << success_message if successes.present?
|
||||||
messages << failure_message if failures.present?
|
messages << failure_message if failures.present?
|
||||||
|
messages << following_message if followings.present?
|
||||||
|
|
||||||
messages.join('\n')
|
messages.join('\n')
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,10 @@ class Invitation < ActiveRecord::Base
|
||||||
|
|
||||||
before_validation :set_email_as_default_service
|
before_validation :set_email_as_default_service
|
||||||
|
|
||||||
|
# before_create :share_with_exsisting_user, :if => :recipient_id?
|
||||||
validates_presence_of :identifier, :service
|
validates_presence_of :identifier, :service
|
||||||
validate :valid_identifier?
|
validate :valid_identifier?
|
||||||
|
validate :recipient_not_on_pod?
|
||||||
validates_presence_of :sender, :aspect, :unless => :admin?
|
validates_presence_of :sender, :aspect, :unless => :admin?
|
||||||
validate :ensure_not_inviting_self, :on => :create, :unless => :admin?
|
validate :ensure_not_inviting_self, :on => :create, :unless => :admin?
|
||||||
validate :sender_owns_aspect?, :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)
|
users_on_pod = User.where(:email => emails, :invitation_token => nil)
|
||||||
|
|
||||||
#share with anyone whose email you entered who is on the pod
|
#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])}
|
users_on_pod.each{|u| opts[:sender].share_with(u.person, opts[:aspect])}
|
||||||
|
|
||||||
emails.map! do |e|
|
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
|
end
|
||||||
emails
|
emails
|
||||||
end
|
end
|
||||||
|
|
@ -140,6 +142,13 @@ class Invitation < ActiveRecord::Base
|
||||||
end
|
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
|
# @note Validation
|
||||||
def valid_identifier?
|
def valid_identifier?
|
||||||
return false unless self.identifier
|
return false unless self.identifier
|
||||||
|
|
|
||||||
|
|
@ -146,7 +146,9 @@ describe ServicesController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not create a duplicate invitation' do
|
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
|
@invite_params[:invitation_id] = inv.id
|
||||||
|
|
||||||
lambda {
|
lambda {
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,12 @@ describe Invitation do
|
||||||
end
|
end
|
||||||
describe 'validations' do
|
describe 'validations' do
|
||||||
before 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
|
end
|
||||||
|
|
||||||
it 'is valid' do
|
it 'is valid' do
|
||||||
@invitation.sender.should == user
|
@invitation.sender.should == user
|
||||||
@invitation.recipient.should == eve
|
@invitation.recipient.should == nil
|
||||||
@invitation.aspect.should == user.aspects.first
|
@invitation.aspect.should == user.aspects.first
|
||||||
@invitation.should be_valid
|
@invitation.should be_valid
|
||||||
end
|
end
|
||||||
|
|
@ -89,13 +89,13 @@ describe Invitation do
|
||||||
invites.all?{|x| x.persisted?}.should be_true
|
invites.all?{|x| x.persisted?}.should be_true
|
||||||
end
|
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)
|
Factory(:user, :email => @emails.first)
|
||||||
invites = nil
|
invites = nil
|
||||||
expect{
|
expect{
|
||||||
invites = Invitation.batch_invite(@emails, @opts)
|
invites = Invitation.batch_invite(@emails, @opts)
|
||||||
}.to change(eve.contacts, :count).by(1)
|
}.to change(eve.contacts, :count).by(1)
|
||||||
invites.count.should be 1
|
invites.count.should be 2
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -565,7 +565,7 @@ describe User do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'removes invitations to the user' do
|
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 {
|
lambda {
|
||||||
alice.destroy
|
alice.destroy
|
||||||
}.should change {alice.invitations_to_me(true).count }.by(-1)
|
}.should change {alice.invitations_to_me(true).count }.by(-1)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue