parent
0e1c66f5b6
commit
cf847d61ba
2 changed files with 41 additions and 7 deletions
|
|
@ -26,27 +26,37 @@ class InvitationsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def email
|
def email
|
||||||
if params[:invitation_token]
|
@invitation_code =
|
||||||
# this is for legacy invites.
|
if params[:invitation_token]
|
||||||
user = User.find_by_invitation_token(params[:invitation_token])
|
# this is for legacy invites.
|
||||||
@invitation_code = user.ugly_accept_invitation_code
|
user = User.find_by_invitation_token(params[:invitation_token])
|
||||||
|
|
||||||
|
user.ugly_accept_invitation_code if user
|
||||||
|
else
|
||||||
|
params[:invitation_code]
|
||||||
|
end
|
||||||
|
|
||||||
|
if @invitation_code.present?
|
||||||
|
render 'notifier/invite', :layout => false
|
||||||
else
|
else
|
||||||
@invitation_code = params[:invitation_code]
|
flash[:error] = t('invitations.check_token.not_found')
|
||||||
|
|
||||||
|
redirect_to root_url
|
||||||
end
|
end
|
||||||
render 'notifier/invite', :layout => false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
inviter = EmailInviter.new(params[:email_inviter][:emails], current_user, params[:email_inviter])
|
inviter = EmailInviter.new(params[:email_inviter][:emails], current_user, params[:email_inviter])
|
||||||
inviter.send!
|
inviter.send!
|
||||||
|
|
||||||
redirect_to :back, :notice => "Great! Invites were sent off to #{inviter.emails.join(', ')}"
|
redirect_to :back, :notice => "Great! Invites were sent off to #{inviter.emails.join(', ')}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_if_invites_open
|
def check_if_invites_open
|
||||||
unless AppConfig[:open_invitations]
|
unless AppConfig[:open_invitations]
|
||||||
flash[:error] = I18n.t 'invitations.create.no_more'
|
flash[:error] = I18n.t 'invitations.create.no_more'
|
||||||
|
|
||||||
redirect_to :back
|
redirect_to :back
|
||||||
return
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -42,10 +42,34 @@ describe InvitationsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#email' do
|
describe '#email' do
|
||||||
|
|
||||||
it 'succeeds' do
|
it 'succeeds' do
|
||||||
get :email, :invitation_code => "anycode"
|
get :email, :invitation_code => "anycode"
|
||||||
response.should be_success
|
response.should be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'legacy invite tokens' do
|
||||||
|
def get_email
|
||||||
|
get :email, :invitation_token => @invitation_token
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'invalid token' do
|
||||||
|
@invitation_token = "invalidtoken"
|
||||||
|
|
||||||
|
it 'redirects and flashes if the invitation token is invalid' do
|
||||||
|
get_email
|
||||||
|
|
||||||
|
response.should be_redirect
|
||||||
|
response.should redirect_to root_url
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'flashes an error if the invitation token is invalid' do
|
||||||
|
get_email
|
||||||
|
|
||||||
|
flash[:error].should == I18n.t("invitations.check_token.not_found")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#new' do
|
describe '#new' do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue