FEATURE: add explicit confirmation button to accept the invite
This commit is contained in:
parent
06c651f8c9
commit
9dd09e453b
|
@ -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
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
<div id='simple-container'>
|
||||
<%if flash[:error]%>
|
||||
<div class='alert alert-error'>
|
||||
<%=flash[:error]%>
|
||||
</div>
|
||||
<%end%>
|
||||
</div>
|
|
@ -3,5 +3,11 @@
|
|||
<div class='alert alert-error'>
|
||||
<%=flash[:error]%>
|
||||
</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%>
|
||||
</div>
|
||||
|
|
|
@ -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."
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue