From e38cb41f855f8f59ea3cbaf3cfc6f5df6bf26409 Mon Sep 17 00:00:00 2001 From: Sarah Mei & Tim Frazer <pair+sarah+tim@joindiaspora.com> Date: Mon, 14 Nov 2011 17:02:13 -0800 Subject: [PATCH] Better error messages for folks coming in with a bad invitation token, whether by clicking the "view this invitation in your browser" link or by clicking the accept invitation button. Get rid of 500 error on the "view this invitation in your browser" link --- app/controllers/invitations_controller.rb | 5 ++-- .../devise/mailer/invitation_instructions.erb | 2 +- .../invitations/token_not_found.html.haml | 3 +++ config/locales/devise/devise.en.yml | 6 ++--- .../invitations_controller_spec.rb | 24 ++++++++++++++++--- 5 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 app/views/invitations/token_not_found.html.haml diff --git a/app/controllers/invitations_controller.rb b/app/controllers/invitations_controller.rb index 3f4e954351..1b45619727 100644 --- a/app/controllers/invitations_controller.rb +++ b/app/controllers/invitations_controller.rb @@ -4,7 +4,7 @@ class InvitationsController < Devise::InvitationsController - before_filter :check_token, :only => [:edit] + before_filter :check_token, :only => [:edit, :email] before_filter :check_if_invites_open, :only =>[:create] def new @@ -73,8 +73,7 @@ class InvitationsController < Devise::InvitationsController protected def check_token if User.find_by_invitation_token(params[:invitation_token]).nil? - flash[:error] = I18n.t 'invitations.check_token.not_found' - redirect_to root_url + render 'invitations/token_not_found' end end diff --git a/app/views/devise/mailer/invitation_instructions.erb b/app/views/devise/mailer/invitation_instructions.erb index f3fe8a240a..78b55067e0 100644 --- a/app/views/devise/mailer/invitation_instructions.erb +++ b/app/views/devise/mailer/invitation_instructions.erb @@ -1,5 +1,5 @@ <%- self.extend NotifierHelper -%> -<% @invites = @resource.invitations_to_me.includes(:sender =>{:person => :profile}).where(:admin => false).all%> +<% @invites = @resource.invitations_to_me.includes(:sender =>{:person => :profile}).where(:admin => false).all %> <head> <title><%=invite_email_title %></title> </head> diff --git a/app/views/invitations/token_not_found.html.haml b/app/views/invitations/token_not_found.html.haml new file mode 100644 index 0000000000..81712492c6 --- /dev/null +++ b/app/views/invitations/token_not_found.html.haml @@ -0,0 +1,3 @@ +.span-15.last + %h2 + = t('devise.invitations.invitation_token_invalid') diff --git a/config/locales/devise/devise.en.yml b/config/locales/devise/devise.en.yml index 77abe5e1a6..cb69e049c6 100644 --- a/config/locales/devise/devise.en.yml +++ b/config/locales/devise/devise.en.yml @@ -52,7 +52,7 @@ en: resend_unlock: "Resend unlock instructions" invitations: send_instructions: 'Your invitation has been sent.' - invitation_token_invalid: 'The invitation token provided is not valid!' + invitation_token_invalid: 'Our apologies! That invitation token is not valid.' updated: 'Your password was set successfully. You are now signed in.' mailer: welcome: "Welcome %{email}!" @@ -73,8 +73,8 @@ en: click_to_unlock: "Click the link below to unlock your account:" unlock: "Unlock my account" invitation_instructions: - displaying_correctly: "Email not displaying correctly? %{link} in your browser" - view_in: "View in" + displaying_correctly: "Email not displaying correctly? %{link}" + view_in: "View it in your browser." finally: "Finally - it's here" arrived: "The social network you have been waiting for has arrived. Revamped, more secure, and more fun, %{strong_diaspora} is ready to help you share and explore the web in a whole new way." sign_up_now: "Sign up now →" diff --git a/spec/controllers/invitations_controller_spec.rb b/spec/controllers/invitations_controller_spec.rb index bf723ed3da..2b56db0da1 100644 --- a/spec/controllers/invitations_controller_spec.rb +++ b/spec/controllers/invitations_controller_spec.rb @@ -24,20 +24,20 @@ describe InvitationsController do request.env["HTTP_REFERER"]= 'http://test.host/cats/foo' end - it 'saves and invitation' do + it 'saves an invitation' do expect { post :create, :user => @invite }.should change(Invitation, :count).by(1) end - it 'handles a comma seperated list of emails' do + it 'handles a comma-separated list of emails' do expect{ post :create, :user => @invite.merge( :email => "foofoofoofoo@example.com, mbs@gmail.com") }.should change(Invitation, :count).by(2) end - it 'handles a comma seperated list of emails with whitespace' do + it 'handles a comma-separated list of emails with whitespace' do expect { post :create, :user => @invite.merge( :email => "foofoofoofoo@example.com , mbs@gmail.com") @@ -70,6 +70,24 @@ describe InvitationsController do end end + describe "#email" do + before do + invites = Invitation.batch_invite(["foo@example.com"], :message => "hi", :sender => @user, :aspect => @user.aspects.first, :service => 'email', :language => "en-US") + invites.first.send! + @invited_user = User.find_by_email("foo@example.com") + end + + it "succeeds" do + get :email, :invitation_token => @invited_user.invitation_token + response.should be_success + end + + it "shows an error if there's no such invitation token" do + get :email, :invitation_token => 12345 + response.should render_template(:token_not_found) + end + end + describe "#update" do before do invite = Factory(:invitation, :sender => @user, :service => 'email', :identifier => "a@a.com") -- GitLab