Merge pull request #4674 from techAPJ/invite-accept

FEATURE: add explicit confirmation button to accept the invite
This commit is contained in:
Arpit Jalan 2017-01-25 16:28:02 +05:30 committed by GitHub
commit 1c8d53125c
6 changed files with 46 additions and 22 deletions

View File

@ -7,10 +7,15 @@ class InvitesController < ApplicationController
skip_before_filter :redirect_to_login_if_required 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_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_new_registrations_allowed, only: [:show, :perform_accept_invitation, :redeem_disposable_invite]
before_filter :ensure_not_logged_in, only: [:show, :redeem_disposable_invite] before_filter :ensure_not_logged_in, only: [:show, :perform_accept_invitation, :redeem_disposable_invite]
def show def show
expires_now
render layout: 'no_ember'
end
def perform_accept_invitation
invite = Invite.find_by(invite_key: params[:id]) invite = Invite.find_by(invite_key: params[:id])
if invite.present? if invite.present?
@ -27,9 +32,12 @@ class InvitesController < ApplicationController
return return
end end
end end
end
redirect_to path("/") redirect_to path("/")
else
flash.now[:error] = I18n.t('invite.not_found')
render layout: 'no_ember'
end
end end
def create def create

View File

@ -0,0 +1,7 @@
<div id='simple-container'>
<%if flash[:error]%>
<div class='alert alert-error'>
<%=flash[:error]%>
</div>
<%end%>
</div>

View File

@ -3,5 +3,11 @@
<div class='alert alert-error'> <div class='alert alert-error'>
<%=flash[:error]%> <%=flash[:error]%>
</div> </div>
<%else%>
<h2><%= t 'activation.welcome_to', site_name: SiteSetting.title %></h2>
<br/>
<%= button_to(perform_accept_invite_path, method: :put, class: 'btn btn-primary') do %>
<%= t 'invite.accept_invite' %>
<% end %>
<%end%> <%end%>
</div> </div>

View File

@ -136,10 +136,17 @@ en:
errors: errors:
<<: *errors <<: *errors
invite:
accept_invite: "Accept Invitation"
not_found: "Your invite token is invalid. Please contact the site's administrator."
bulk_invite: bulk_invite:
file_should_be_csv: "The uploaded file should be of csv format." file_should_be_csv: "The uploaded file should be of csv format."
error: "There was an error uploading that file. Please try again later." 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: backup:
operation_already_running: "An operation is currently running. Can't start a new job right now." 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." 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_post_raw: This topic includes daily performance reports for your site.
initial_topic_title: Website performance reports 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: tags:
title: "Tags" title: "Tags"
staff_tag_disallowed: "The tag \"%{tag}\" may only be applied by staff." staff_tag_disallowed: "The tag \"%{tag}\" may only be applied by staff."

View File

@ -624,6 +624,7 @@ Discourse::Application.routes.draw do
post "invites/disposable" => "invites#create_disposable_invite" post "invites/disposable" => "invites#create_disposable_invite"
get "invites/redeem/:token" => "invites#redeem_disposable_invite" get "invites/redeem/:token" => "invites#redeem_disposable_invite"
delete "invites" => "invites#destroy" delete "invites" => "invites#destroy"
put "invites/show/:id" => "invites#perform_accept_invitation", as: 'perform_accept_invite'
resources :export_csv do resources :export_csv do
collection do collection do

View File

@ -123,15 +123,16 @@ describe InvitesController do
end end
end end
context '.show' do context '.perform_accept_invitation' do
context 'with an invalid invite id' do context 'with an invalid invite id' do
before do before do
get :show, id: "doesn't exist" put :perform_accept_invitation, id: "doesn't exist"
end end
it "redirects to the root" do it "redirects to the root" do
expect(response).to redirect_to("/") expect(response).to be_success
expect(flash[:error]).to be_present
end end
it "should not change the session" do 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(:invite) { topic.invite_by_email(topic.user, "iceking@adventuretime.ooo") }
let(:deleted_invite) { invite.destroy; invite } let(:deleted_invite) { invite.destroy; invite }
before do before do
get :show, id: deleted_invite.invite_key put :perform_accept_invitation, id: deleted_invite.invite_key
end end
it "redirects to the root" do it "redirects to the root" do
expect(response).to redirect_to("/") expect(response).to be_success
expect(flash[:error]).to be_present
end end
it "should not change the session" do it "should not change the session" do
@ -160,10 +162,9 @@ describe InvitesController do
let(:topic) { Fabricate(:topic) } let(:topic) { Fabricate(:topic) }
let(:invite) { topic.invite_by_email(topic.user, "iceking@adventuretime.ooo") } let(:invite) { topic.invite_by_email(topic.user, "iceking@adventuretime.ooo") }
it 'redeems the invite' do it 'redeems the invite' do
Invite.any_instance.expects(:redeem) Invite.any_instance.expects(:redeem)
get :show, id: invite.invite_key put :perform_accept_invitation, id: invite.invite_key
end end
context 'when redeem returns a user' do context 'when redeem returns a user' do
@ -172,7 +173,7 @@ describe InvitesController do
context 'success' do context 'success' do
before do before do
Invite.any_instance.expects(:redeem).returns(user) Invite.any_instance.expects(:redeem).returns(user)
get :show, id: invite.invite_key put :perform_accept_invitation, id: invite.invite_key
end end
it 'logs in the user' do it 'logs in the user' do
@ -193,18 +194,15 @@ describe InvitesController do
it 'sends a welcome message if set' do it 'sends a welcome message if set' do
user.send_welcome_message = true user.send_welcome_message = true
user.expects(:enqueue_welcome_message).with('welcome_invite') user.expects(:enqueue_welcome_message).with('welcome_invite')
get :show, id: invite.invite_key put :perform_accept_invitation, id: invite.invite_key
end end
it "doesn't send a welcome message if not set" do it "doesn't send a welcome message if not set" do
user.expects(:enqueue_welcome_message).with('welcome_invite').never 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
end end
end end
context 'new registrations are disabled' do context 'new registrations are disabled' do
@ -214,7 +212,7 @@ describe InvitesController do
it "doesn't redeem the invite" do it "doesn't redeem the invite" do
Invite.any_instance.stubs(:redeem).never Invite.any_instance.stubs(:redeem).never
get :show, id: invite.invite_key put :perform_accept_invitation, id: invite.invite_key
end end
end end
@ -225,7 +223,7 @@ describe InvitesController do
it "doesn't redeem the invite" do it "doesn't redeem the invite" do
Invite.any_instance.stubs(:redeem).never Invite.any_instance.stubs(:redeem).never
get :show, id: invite.invite_key put :perform_accept_invitation, id: invite.invite_key
end end
end end
end end