From 9dd09e453beaedefb01fe6c98ff524b7a4b074a9 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Wed, 25 Jan 2017 01:45:29 +0530 Subject: [PATCH] FEATURE: add explicit confirmation button to accept the invite --- app/controllers/invites_controller.rb | 16 ++++++++--- .../perform_accept_invitation.html.erb | 7 +++++ app/views/invites/show.html.erb | 6 ++++ config/locales/server.en.yml | 10 +++++-- config/routes.rb | 1 + spec/controllers/invites_controller_spec.rb | 28 +++++++++---------- 6 files changed, 46 insertions(+), 22 deletions(-) create mode 100644 app/views/invites/perform_accept_invitation.html.erb diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rb index 5b614bc3dc6..7c539b46ebd 100644 --- a/app/controllers/invites_controller.rb +++ b/app/controllers/invites_controller.rb @@ -7,10 +7,15 @@ class InvitesController < ApplicationController skip_before_filter :redirect_to_login_if_required before_filter :ensure_logged_in, only: [:destroy, :create, :create_invite_link, :resend_invite, :resend_all_invites, :upload_csv] - before_filter :ensure_new_registrations_allowed, only: [:show, :redeem_disposable_invite] - before_filter :ensure_not_logged_in, only: [:show, :redeem_disposable_invite] + before_filter :ensure_new_registrations_allowed, only: [:show, :perform_accept_invitation, :redeem_disposable_invite] + before_filter :ensure_not_logged_in, only: [:show, :perform_accept_invitation, :redeem_disposable_invite] def show + expires_now + render layout: 'no_ember' + end + + def perform_accept_invitation invite = Invite.find_by(invite_key: params[:id]) if invite.present? @@ -27,9 +32,12 @@ class InvitesController < ApplicationController return end end - end - redirect_to path("/") + redirect_to path("/") + else + flash.now[:error] = I18n.t('invite.not_found') + render layout: 'no_ember' + end end def create diff --git a/app/views/invites/perform_accept_invitation.html.erb b/app/views/invites/perform_accept_invitation.html.erb new file mode 100644 index 00000000000..cc4b0acc1e7 --- /dev/null +++ b/app/views/invites/perform_accept_invitation.html.erb @@ -0,0 +1,7 @@ +
+ <%if flash[:error]%> +
+ <%=flash[:error]%> +
+ <%end%> +
diff --git a/app/views/invites/show.html.erb b/app/views/invites/show.html.erb index cc4b0acc1e7..1fdd39e3ee3 100644 --- a/app/views/invites/show.html.erb +++ b/app/views/invites/show.html.erb @@ -3,5 +3,11 @@
<%=flash[:error]%>
+ <%else%> +

<%= t 'activation.welcome_to', site_name: SiteSetting.title %>

+
+ <%= button_to(perform_accept_invite_path, method: :put, class: 'btn btn-primary') do %> + <%= t 'invite.accept_invite' %> + <% end %> <%end%> diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 6c751415b7c..eb2e54eed1d 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -136,10 +136,17 @@ en: errors: <<: *errors + invite: + accept_invite: "Accept Invitation" + not_found: "Your invite token is invalid. Please contact the site's administrator." + bulk_invite: file_should_be_csv: "The uploaded file should be of csv format." error: "There was an error uploading that file. Please try again later." + topic_invite: + user_exists: "Sorry, that user has already been invited. You may only invite a user to a topic once." + backup: operation_already_running: "An operation is currently running. Can't start a new job right now." backup_file_should_be_tar_gz: "The backup file should be a .tar.gz archive." @@ -3243,9 +3250,6 @@ en: initial_post_raw: This topic includes daily performance reports for your site. initial_topic_title: Website performance reports - topic_invite: - user_exists: "Sorry, that user has already been invited. You may only invite a user to a topic once." - tags: title: "Tags" staff_tag_disallowed: "The tag \"%{tag}\" may only be applied by staff." diff --git a/config/routes.rb b/config/routes.rb index 11ae9d435f8..3f1a5be6c72 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -624,6 +624,7 @@ Discourse::Application.routes.draw do post "invites/disposable" => "invites#create_disposable_invite" get "invites/redeem/:token" => "invites#redeem_disposable_invite" delete "invites" => "invites#destroy" + put "invites/show/:id" => "invites#perform_accept_invitation", as: 'perform_accept_invite' resources :export_csv do collection do diff --git a/spec/controllers/invites_controller_spec.rb b/spec/controllers/invites_controller_spec.rb index be07bb78943..6c9ace61b2a 100644 --- a/spec/controllers/invites_controller_spec.rb +++ b/spec/controllers/invites_controller_spec.rb @@ -123,15 +123,16 @@ describe InvitesController do end end - context '.show' do + context '.perform_accept_invitation' do context 'with an invalid invite id' do before do - get :show, id: "doesn't exist" + put :perform_accept_invitation, id: "doesn't exist" end it "redirects to the root" do - expect(response).to redirect_to("/") + expect(response).to be_success + expect(flash[:error]).to be_present end it "should not change the session" do @@ -144,11 +145,12 @@ describe InvitesController do let(:invite) { topic.invite_by_email(topic.user, "iceking@adventuretime.ooo") } let(:deleted_invite) { invite.destroy; invite } before do - get :show, id: deleted_invite.invite_key + put :perform_accept_invitation, id: deleted_invite.invite_key end it "redirects to the root" do - expect(response).to redirect_to("/") + expect(response).to be_success + expect(flash[:error]).to be_present end it "should not change the session" do @@ -160,10 +162,9 @@ describe InvitesController do let(:topic) { Fabricate(:topic) } let(:invite) { topic.invite_by_email(topic.user, "iceking@adventuretime.ooo") } - it 'redeems the invite' do Invite.any_instance.expects(:redeem) - get :show, id: invite.invite_key + put :perform_accept_invitation, id: invite.invite_key end context 'when redeem returns a user' do @@ -172,7 +173,7 @@ describe InvitesController do context 'success' do before do Invite.any_instance.expects(:redeem).returns(user) - get :show, id: invite.invite_key + put :perform_accept_invitation, id: invite.invite_key end it 'logs in the user' do @@ -193,18 +194,15 @@ describe InvitesController do it 'sends a welcome message if set' do user.send_welcome_message = true user.expects(:enqueue_welcome_message).with('welcome_invite') - get :show, id: invite.invite_key + put :perform_accept_invitation, id: invite.invite_key end it "doesn't send a welcome message if not set" do user.expects(:enqueue_welcome_message).with('welcome_invite').never - get :show, id: invite.invite_key + put :perform_accept_invitation, id: invite.invite_key end - end - end - end context 'new registrations are disabled' do @@ -214,7 +212,7 @@ describe InvitesController do it "doesn't redeem the invite" do Invite.any_instance.stubs(:redeem).never - get :show, id: invite.invite_key + put :perform_accept_invitation, id: invite.invite_key end end @@ -225,7 +223,7 @@ describe InvitesController do it "doesn't redeem the invite" do Invite.any_instance.stubs(:redeem).never - get :show, id: invite.invite_key + put :perform_accept_invitation, id: invite.invite_key end end end