Make invitation view with no inviters sensible
This commit is contained in:
parent
70bcab3abc
commit
1b39b79446
7 changed files with 63 additions and 46 deletions
2
Gemfile
2
Gemfile
|
|
@ -8,7 +8,7 @@ gem "chef", :require => false
|
||||||
#Security
|
#Security
|
||||||
gem 'devise', '1.1.3'
|
gem 'devise', '1.1.3'
|
||||||
gem 'devise-mongo_mapper', :git => 'git://github.com/collectiveidea/devise-mongo_mapper'
|
gem 'devise-mongo_mapper', :git => 'git://github.com/collectiveidea/devise-mongo_mapper'
|
||||||
gem 'devise_invitable', '~> 0.3.4'
|
gem 'devise_invitable','0.3.5'
|
||||||
|
|
||||||
#Authentication
|
#Authentication
|
||||||
gem 'omniauth'
|
gem 'omniauth'
|
||||||
|
|
|
||||||
|
|
@ -381,7 +381,7 @@ DEPENDENCIES
|
||||||
database_cleaner (= 0.5.2)
|
database_cleaner (= 0.5.2)
|
||||||
devise (= 1.1.3)
|
devise (= 1.1.3)
|
||||||
devise-mongo_mapper!
|
devise-mongo_mapper!
|
||||||
devise_invitable (~> 0.3.4)
|
devise_invitable (= 0.3.5)
|
||||||
em-http-request!
|
em-http-request!
|
||||||
em-websocket
|
em-websocket
|
||||||
factory_girl_rails
|
factory_girl_rails
|
||||||
|
|
|
||||||
|
|
@ -25,15 +25,9 @@ class Invitation
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
invited_user = create_invitee(:email => opts[:email])
|
invited_user = create_invitee(opts)
|
||||||
if invited_user.persisted?
|
if invited_user.persisted?
|
||||||
Invitation.create!(:from => opts[:from],
|
|
||||||
:to => invited_user,
|
|
||||||
:into => opts[:into],
|
|
||||||
:message => opts[:message])
|
|
||||||
|
|
||||||
opts[:from].invites -= 1
|
|
||||||
opts[:from].save!
|
|
||||||
invited_user
|
invited_user
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
|
|
@ -41,16 +35,29 @@ class Invitation
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.create_invitee(opts = {})
|
def self.create_invitee(opts = {})
|
||||||
invitable = User.find_or_initialize_with_error_by(:email, opts[:email])
|
invitee = User.find_or_initialize_with_error_by(:email, opts[:email])
|
||||||
|
|
||||||
if invitable.new_record?
|
if invitee.new_record?
|
||||||
invitable.errors.clear if invitable.email.try(:match, Devise.email_regexp)
|
invitee.errors.clear if invitee.email.try(:match, Devise.email_regexp)
|
||||||
else
|
else
|
||||||
invitable.errors.add(:email, :taken) unless invitable.invited?
|
invitee.errors.add(:email, :taken) unless invitee.invited?
|
||||||
end
|
end
|
||||||
|
|
||||||
invitable.invite! if invitable.errors.empty?
|
if opts[:from]
|
||||||
invitable
|
invitee.save(:validate => false)
|
||||||
|
Invitation.create!(:from => opts[:from],
|
||||||
|
:to => invitee,
|
||||||
|
:into => opts[:into],
|
||||||
|
:message => opts[:message])
|
||||||
|
|
||||||
|
opts[:from].invites -= 1
|
||||||
|
opts[:from].save!
|
||||||
|
invitee.reload
|
||||||
|
end
|
||||||
|
|
||||||
|
invitee.send(:generate_invitation_token)
|
||||||
|
invitee.invite! if invitee.errors.empty?
|
||||||
|
invitee
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_request!
|
def to_request!
|
||||||
|
|
|
||||||
11
app/views/devise/mailer/_inviters.haml
Normal file
11
app/views/devise/mailer/_inviters.haml
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
%p
|
||||||
|
- if @invs.count == 1
|
||||||
|
= t('.has_invited_you', :name => @invs.first.from.real_name + " (#{@invs.first.from.diaspora_handle})")
|
||||||
|
- else
|
||||||
|
= t('.have_invited_you', :names => (@invs.map{|inv| inv.from.real_name + " (#{inv.from.diaspora_handle})"}.join(",")))
|
||||||
|
= t('.accept_at', :url => root_url)
|
||||||
|
- @invs.each do |inv|
|
||||||
|
- if inv.message
|
||||||
|
= "#{inv.from.real_name}:"
|
||||||
|
= "\"#{inv.message}\""
|
||||||
|
%p
|
||||||
|
|
@ -10,17 +10,8 @@
|
||||||
- @invs = @resource.invitations_to_me
|
- @invs = @resource.invitations_to_me
|
||||||
%p
|
%p
|
||||||
= t('devise.mailer.welcome', :email => @resource.email)
|
= t('devise.mailer.welcome', :email => @resource.email)
|
||||||
%p
|
-if @invs.count > 0
|
||||||
- if @invs.count == 1
|
= render :partial => 'inviters'
|
||||||
= t('.has_invited_you', :name => @invs.first.real_name + " (#{@invs.first.diaspora_handle})")
|
|
||||||
- else
|
|
||||||
= t('.have_invited_you', :names => (@invs.map{|inv| inv.from.real_name + " (#{inv.from.diaspora_handle})"}.join(",")))
|
|
||||||
= t('.accept_at', :url => root_url)
|
|
||||||
- @invs.each do |inv|
|
|
||||||
- if inv.message
|
|
||||||
= "#{inv.from.real_name}:"
|
|
||||||
= "\"#{inv.message}\""
|
|
||||||
%p
|
|
||||||
%p= link_to t('.accept'), accept_invitation_url(@resource, :invitation_token => @resource.invitation_token), :class => "large_text"
|
%p= link_to t('.accept'), accept_invitation_url(@resource, :invitation_token => @resource.invitation_token), :class => "large_text"
|
||||||
%p.small
|
%p.small
|
||||||
= t('.ignore')
|
= t('.ignore')
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ en:
|
||||||
click_to_unlock: "Click the link below to unlock your account:"
|
click_to_unlock: "Click the link below to unlock your account:"
|
||||||
unlock: "Unlock my account"
|
unlock: "Unlock my account"
|
||||||
invitation:
|
invitation:
|
||||||
subject: 'A friend wants you to join Diaspora!'
|
subject: "You've been invited to join Diaspora!"
|
||||||
has_invited_you: "%{name} has invited you to join Diaspora"
|
has_invited_you: "%{name} has invited you to join Diaspora"
|
||||||
have_invited_you: "%{names} have invited you to join Diaspora"
|
have_invited_you: "%{names} have invited you to join Diaspora"
|
||||||
accept_at: ", at %{url}, you can accept it through the link below."
|
accept_at: ", at %{url}, you can accept it through the link below."
|
||||||
|
|
|
||||||
|
|
@ -79,11 +79,6 @@ describe Invitation do
|
||||||
new_user.invitations_to_me.first.message.should == message
|
new_user.invitations_to_me.first.message.should == message
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'mails the optional message' do
|
|
||||||
message = "How've you been?"
|
|
||||||
new_user = Invitation.invite(:from => user, :email => @email, :into => aspect, :message => message)
|
|
||||||
Devise.mailer.deliveries.first.to_s.include?(message).should be_true
|
|
||||||
end
|
|
||||||
it 'sends a contact request to a user with that email into the aspect' do
|
it 'sends a contact request to a user with that email into the aspect' do
|
||||||
user2
|
user2
|
||||||
user.should_receive(:send_contact_request_to){ |a, b|
|
user.should_receive(:send_contact_request_to){ |a, b|
|
||||||
|
|
@ -95,24 +90,37 @@ describe Invitation do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '.create_invitee' do
|
describe '.create_invitee' do
|
||||||
it 'creates a user' do
|
context 'with an inviter' do
|
||||||
lambda {
|
it 'sends mail' do
|
||||||
Invitation.create_invitee(:email => @email)
|
message = "How've you been?"
|
||||||
}.should change(User, :count).by(1)
|
lambda {
|
||||||
end
|
Invitation.create_invitee(:from => user, :email => @email, :into => aspect, :message => message)
|
||||||
it 'sends email to the invited user' do
|
}.should change{Devise.mailer.deliveries.size}.by(1)
|
||||||
lambda {
|
end
|
||||||
Invitation.create_invitee(:email => @email)
|
it 'mails the optional message' do
|
||||||
}.should change{Devise.mailer.deliveries.size}.by(1)
|
message = "How've you been?"
|
||||||
end
|
new_user = Invitation.create_invitee(:from => user, :email => @email, :into => aspect, :message => message)
|
||||||
it 'sends an email that includes the right things' do
|
Devise.mailer.deliveries.first.to_s.include?(message).should be_true
|
||||||
Invitation.create_invitee(:email => @email)
|
end
|
||||||
Devise.mailer.deliveries.first.to_s.include?("Welcome #{@email}").should == true
|
|
||||||
end
|
end
|
||||||
context 'with no inviter' do
|
context 'with no inviter' do
|
||||||
|
it 'sends an email that includes the right things' do
|
||||||
|
Invitation.create_invitee(:email => @email)
|
||||||
|
Devise.mailer.deliveries.first.to_s.include?("Welcome #{@email}").should == true
|
||||||
|
end
|
||||||
|
it 'creates a user' do
|
||||||
|
lambda {
|
||||||
|
Invitation.create_invitee(:email => @email)
|
||||||
|
}.should change(User, :count).by(1)
|
||||||
|
end
|
||||||
|
it 'sends email to the invited user' do
|
||||||
|
lambda {
|
||||||
|
Invitation.create_invitee(:email => @email)
|
||||||
|
}.should change{Devise.mailer.deliveries.size}.by(1)
|
||||||
|
end
|
||||||
it 'does not render nonsensical emails' do
|
it 'does not render nonsensical emails' do
|
||||||
Invitation.create_invitee(:email => @email)
|
Invitation.create_invitee(:email => @email)
|
||||||
Devise.mailer.deliveries.first.subject.match(/a friend/i).should be_false
|
Devise.mailer.deliveries.first.body.raw_source.match(/have invited you to join/i).should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue