Skip to content
Snippets Groups Projects
Commit a8bf082e authored by ilya's avatar ilya
Browse files

The invitation now has an optional personal message

parent 41a0718f
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,8 @@ class InvitationsController < Devise::InvitationsController ...@@ -10,6 +10,8 @@ class InvitationsController < Devise::InvitationsController
def create def create
begin begin
params[:user][:aspect_id] = params[:user].delete(:aspects) params[:user][:aspect_id] = params[:user].delete(:aspects)
message = params[:user].delete(:invite_messages)
params[:user][:invite_message] = message unless message == ""
self.resource = current_user.invite_user(params[resource_name]) self.resource = current_user.invite_user(params[resource_name])
flash[:notice] = I18n.t 'invitations.create.sent' flash[:notice] = I18n.t 'invitations.create.sent'
rescue RuntimeError => e rescue RuntimeError => e
......
...@@ -38,6 +38,8 @@ class User ...@@ -38,6 +38,8 @@ class User
key :visible_post_ids, Array key :visible_post_ids, Array
key :visible_person_ids, Array key :visible_person_ids, Array
key :invite_messages, Hash
before_validation :strip_username, :on => :create before_validation :strip_username, :on => :create
validates_presence_of :username validates_presence_of :username
validates_uniqueness_of :username, :case_sensitive => false validates_uniqueness_of :username, :case_sensitive => false
...@@ -290,7 +292,7 @@ class User ...@@ -290,7 +292,7 @@ class User
:into => aspect_id :into => aspect_id
) )
invited_user = User.invite!(:email => opts[:email], :request => request, :inviter => self) invited_user = User.invite!(:email => opts[:email], :request => request, :inviter => self, :invite_message => opts[:invite_message])
self.invites = self.invites - 1 self.invites = self.invites - 1
self.pending_requests << request self.pending_requests << request
...@@ -313,6 +315,10 @@ class User ...@@ -313,6 +315,10 @@ class User
else else
invitable.pending_requests << request invitable.pending_requests << request
invitable.inviters << inviter invitable.inviters << inviter
message = attributes.delete(:invite_message)
if message
invitable.invite_messages[inviter.id.to_s] = message
end
end end
if invitable.new_record? if invitable.new_record?
......
...@@ -2,6 +2,13 @@ ...@@ -2,6 +2,13 @@
Hello #{@resource.email}! Hello #{@resource.email}!
%p %p
#{(@resource.inviters.count == 1)? ( @resource.inviters.first.real_name + " has") : (@resource.inviters.map{|inv| inv.real_name}.join(",") + " have")} invited you to #{root_url}, you can accept it through the link below. #{(@resource.inviters.count == 1)? ( @resource.inviters.first.real_name + " has") : (@resource.inviters.map{|inv| inv.real_name}.join(",") + " have")} invited you to #{root_url}, you can accept it through the link below.
- @resource.inviters.each do |inv|
- if @resource.invite_messages[inv.id.to_s]
= "#{inv.real_name}:"
= @resource.invite_messages[inv.id.to_s]
%p
%p= link_to 'Accept invitation', accept_invitation_url(@resource, :invitation_token => @resource.invitation_token) %p= link_to 'Accept invitation', accept_invitation_url(@resource, :invitation_token => @resource.invitation_token)
%p %p
If you don't want to accept the invitation, please ignore this email. If you don't want to accept the invitation, please ignore this email.
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
= invite.select(:aspects, @aspects_dropdown_array) = invite.select(:aspects, @aspects_dropdown_array)
- else - else
= invite.select(:aspects, @aspects_dropdown_array, :selected => @aspect.id) = invite.select(:aspects, @aspects_dropdown_array, :selected => @aspect.id)
Message:
= invite.text_area :invite_messages
%p= invite.submit "Send an invitation" %p= invite.submit "Send an invitation"
...@@ -28,7 +28,7 @@ $(document).ready(function(){ ...@@ -28,7 +28,7 @@ $(document).ready(function(){
//buttons////// //buttons//////
$("#add_aspect_button").fancybox({ 'titleShow' : false , 'hideOnOverlayClick' : false }); $("#add_aspect_button").fancybox({ 'titleShow' : false , 'hideOnOverlayClick' : false });
$("#add_request_button").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false }); $("#add_request_button").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false });
$("#invite_user_button").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false }); $(".invite_user_button").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false });
$(".add_request_button").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false }); $(".add_request_button").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false });
$(".question_mark").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false }); $(".question_mark").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false });
......
...@@ -46,6 +46,12 @@ describe User do ...@@ -46,6 +46,12 @@ describe User do
invited_user.inviters.include?(inviter).should be_true invited_user.inviters.include?(inviter).should be_true
end end
it 'adds an optional message' do
invited_user = inviter.invite_user(:email => "marcy@example.com", :invite_message => "How've you been?",:aspect_id => aspect.id)
invited_user.reload
invited_user.invite_messages[inviter.id.to_s].should == "How've you been?"
end
it 'adds a pending request to the invited user' do it 'adds a pending request to the invited user' do
invited_user = inviter.invite_user(:email => "marcy@example.com", :aspect_id => aspect.id) invited_user = inviter.invite_user(:email => "marcy@example.com", :aspect_id => aspect.id)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment