Can invite new members to a table
This commit is contained in:
parent
3e7909c02b
commit
d00bde60b1
|
@ -13,20 +13,17 @@ class TableInvitesController < ApplicationController
|
|||
end
|
||||
|
||||
def create
|
||||
@user = User.find_by(email: table_invite_params[:email])
|
||||
if @user.blank?
|
||||
# TODO: Allow inviting non-users, we can send an email invite
|
||||
flash[:alert] = t(".user_not_found")
|
||||
render :new, status: :unprocessable_entity and return
|
||||
@table_invite = @table.table_invites.new(table_invite_params)
|
||||
unless @table_invite.save
|
||||
render :new, status: :unprocessable_entity, alert: t(".error") and return
|
||||
end
|
||||
|
||||
@table_invite = @table.table_invites.new(table_invite_params)
|
||||
if @table_invite.save
|
||||
if User.exists?(email: table_invite_params[:email])
|
||||
TableInviteMailer.with(table_invite: @table_invite).invite_user.deliver_later
|
||||
redirect_to @table, notice: t(".success", email: @table_invite.email)
|
||||
else
|
||||
render :new, status: :unprocessable_entity, alert: t(".error")
|
||||
TableInviteMailer.with(table_invite: @table_invite).invite_new_user.deliver_later
|
||||
end
|
||||
redirect_to @table, notice: t(".success", email: @table_invite.email)
|
||||
end
|
||||
|
||||
def edit
|
||||
|
|
|
@ -8,4 +8,10 @@ class TableInviteMailer < ApplicationMailer
|
|||
|
||||
mail(to: @table_invite.email, subject: "[Tabletop Companion] Invite to join a table")
|
||||
end
|
||||
|
||||
def invite_new_user
|
||||
@table_invite = params[:table_invite]
|
||||
|
||||
mail(to: @table_invite.email, subject: "[Tabletop Companion] You’ve been invited to a game!")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
<%= htmlify_email(t(".content", table_name: @table_invite.table.name)) %>
|
||||
|
||||
<%= link_to t(".sign_up"), new_user_url %>
|
|
@ -0,0 +1,3 @@
|
|||
<%= t(".content", table_name: @table_invite.table.name) %>
|
||||
|
||||
<%= new_user_url %>
|
|
@ -62,6 +62,11 @@ en:
|
|||
log_out: Log out
|
||||
success: "You have signed out."
|
||||
table_invite_mailer:
|
||||
invite_new_user:
|
||||
content: |-
|
||||
You’ve been invited to join a game on Tabletop Companion. To start playing, sign up at the
|
||||
link below and accept your invitation!
|
||||
sign_up: Sign up now
|
||||
invite_user:
|
||||
content: |-
|
||||
You have been invited to join the table “%{table_name}” on Tabletop Companion. To
|
||||
|
|
|
@ -35,13 +35,16 @@ class TableInviteInvitesControllerTest < ActionDispatch::IntegrationTest
|
|||
assert_redirected_to table_path(tables(:table))
|
||||
end
|
||||
|
||||
test "can’t invite a user who doesn’t exist" do
|
||||
test "can invite a non-user to join" do
|
||||
sign_in users(:trevor)
|
||||
assert_no_changes("TableInvite.count") do
|
||||
post(table_table_invites_url(tables(:table)), params: { table_invite: { email: "not_real@example.com" } })
|
||||
assert_changes("TableInvite.count", +1) do
|
||||
assert_emails(+1) do
|
||||
post(table_table_invites_url(tables(:table)), params: { table_invite: { email: "not_a_member@example.com" } })
|
||||
end
|
||||
assert_response :unprocessable_entity
|
||||
end
|
||||
assert_redirected_to table_path(tables(:table))
|
||||
end
|
||||
|
||||
test "should email user when an invite is created" do
|
||||
sign_in users(:trevor)
|
||||
assert_emails(+1) do
|
||||
|
|
Loading…
Reference in New Issue