resending of invitation in resque and works

This commit is contained in:
zhitomirskiyi 2011-01-23 20:13:10 -08:00
parent da6e16b3a4
commit 83a9e916e4
5 changed files with 23 additions and 9 deletions

View file

@ -7,8 +7,8 @@ class InvitationsController < Devise::InvitationsController
before_filter :check_token, :only => [:edit] before_filter :check_token, :only => [:edit]
def new def new
sent_invitations = current_user.invitations_from_me.includes(:recipient) @sent_invitations = current_user.invitations_from_me.includes(:recipient)
@emails_delivered = sent_invitations.map!{ |i| i.recipient.email } #emails_delivered = sent_invitations.map!{ |i| i.recipient.email }
end end
def create def create
@ -59,7 +59,10 @@ class InvitationsController < Devise::InvitationsController
def resend def resend
invitation = current_user.invitations_from_me.where(:id => params[:id]).first invitation = current_user.invitations_from_me.where(:id => params[:id]).first
Resque.enqueue(Job::ResendInvitation, invitation.id) if invitation if invitation
Resque.enqueue(Job::ResendInvitation, invitation.id)
flash[:notice] = I18n.t('invitations.create.sent') + invitation.recipient.email
end
redirect_to :back redirect_to :back
end end

View file

@ -79,6 +79,10 @@ class Invitation < ActiveRecord::Base
invitee invitee
end end
def resend
recipient.invite!
end
def to_request! def to_request!
request = sender.send_contact_request_to(recipient.person, aspect) request = sender.send_contact_request_to(recipient.person, aspect)
destroy if request destroy if request

View file

@ -36,10 +36,11 @@
%p %p
= invite.submit t('.send_an_invitation') = invite.submit t('.send_an_invitation')
- if !@emails_delivered.empty? - if !@sent_invitations.empty?
.span-4.last .span-4.last
#already_invited_pane #already_invited_pane
%h4 %h4
= t('.already_invited') = t('.already_invited')
- for email in @emails_delivered - for invitation in @sent_invitations
= email = invitation.recipient.email
= link_to "Resend", invitation_resend_path(invitation), :confirm => t('are_you_sure')

View file

@ -31,10 +31,15 @@ Diaspora::Application.routes.draw do
match 'photos/make_profile_photo' => 'photos#make_profile_photo' match 'photos/make_profile_photo' => 'photos#make_profile_photo'
resources :photos, :except => [:index] resources :photos, :except => [:index]
match 'invitations/resend/:id' => 'invitations#resend'
devise_for :users, :controllers => {:registrations => "registrations", devise_for :users, :controllers => {:registrations => "registrations",
:password => "devise/passwords", :password => "devise/passwords",
:invitations => "invitations"} :invitations => "invitations"} do
get 'invitations/resend/:id' => 'invitations#resend', :as => 'invitation_resend'
end
# added public route to user # added public route to user
match 'public/:username', :to => 'users#public' match 'public/:username', :to => 'users#public'
match 'getting_started', :to => 'users#getting_started', :as => 'getting_started' match 'getting_started', :to => 'users#getting_started', :as => 'getting_started'

View file

@ -301,7 +301,8 @@ describe Invitation do
describe '.resend' do describe '.resend' do
before do before do
aspect aspect
@invitation = Invitation.new(:sender => user, :recipient => user2, :aspect => aspect) user.invite_user("a@a.com", aspect.id)
@invitation = user.reload.invitations_from_me.first
end end
it 'sends another email' do it 'sends another email' do