FEATURE: resending invite should include original custom message

https://meta.discourse.org/t/will-resent-invite-include-original-custom-message/64699
This commit is contained in:
Arpit Jalan 2017-06-30 16:09:37 +05:30
parent c1580b9d36
commit 16d356ab4e
5 changed files with 20 additions and 11 deletions

View File

@ -9,7 +9,7 @@ module Jobs
raise Discourse::InvalidParameters.new(:invite_id) unless args[:invite_id].present?
invite = Invite.find_by(id: args[:invite_id])
message = InviteMailer.send_invite(invite, args[:custom_message])
message = InviteMailer.send_invite(invite)
Email::Sender.new(message, :invite).send
end

View File

@ -8,7 +8,7 @@ class InviteMailer < ActionMailer::Base
include EmailHelper
end
def send_invite(invite, custom_message=nil)
def send_invite(invite)
# Find the first topic they were invited to
first_topic = invite.topics.order(:created_at).first
@ -27,7 +27,7 @@ class InviteMailer < ActionMailer::Base
end
template = 'invite_mailer'
if custom_message.present?
if invite.custom_message.present?
template = 'custom_invite_mailer'
end
@ -46,10 +46,10 @@ class InviteMailer < ActionMailer::Base
topic_excerpt: topic_excerpt,
site_description: SiteSetting.site_description,
site_title: SiteSetting.title,
user_custom_message: custom_message)
user_custom_message: invite.custom_message)
else
template = 'invite_forum_mailer'
if custom_message.present?
if invite.custom_message.present?
template = 'custom_invite_forum_mailer'
end
@ -60,7 +60,7 @@ class InviteMailer < ActionMailer::Base
invite_link: "#{Discourse.base_url}/invites/#{invite.invite_key}",
site_description: SiteSetting.site_description,
site_title: SiteSetting.title,
user_custom_message: custom_message)
user_custom_message: invite.custom_message)
end
end

View File

@ -122,6 +122,7 @@ class Invite < ActiveRecord::Base
if !invite
create_args = { invited_by: invited_by, email: lower_email }
create_args[:moderator] = true if opts[:moderator]
create_args[:custom_message] = custom_message if custom_message
invite = Invite.create!(create_args)
end
@ -143,7 +144,7 @@ class Invite < ActiveRecord::Base
end
end
Jobs.enqueue(:invite_email, invite_id: invite.id, custom_message: custom_message) if send_email
Jobs.enqueue(:invite_email, invite_id: invite.id) if send_email
invite.reload
invite
@ -295,6 +296,7 @@ end
# deleted_by_id :integer
# invalidated_at :datetime
# moderator :boolean default(FALSE), not null
# custom_message :text
#
# Indexes
#

View File

@ -0,0 +1,5 @@
class AddCustomMessageToInvite < ActiveRecord::Migration
def change
add_column :invites, :custom_message, :text
end
end

View File

@ -5,9 +5,9 @@ describe InviteMailer do
describe "send_invite" do
context "invite to site" do
let(:invite) { Fabricate(:invite) }
context "default invite message" do
let(:invite) { Fabricate(:invite) }
let(:invite_mail) { InviteMailer.send_invite(invite) }
it 'renders the invitee email' do
@ -36,9 +36,10 @@ describe InviteMailer do
end
context "custom invite message" do
let(:invite) { Fabricate(:invite, custom_message: "Hey, you should join this forum!") }
context "custom message includes invite link" do
let(:custom_invite_mail) { InviteMailer.send_invite(invite, "Hey, you should join this forum!") }
let(:custom_invite_mail) { InviteMailer.send_invite(invite) }
it 'renders the invitee email' do
expect(custom_invite_mail.to).to eql([invite.email])
@ -76,9 +77,9 @@ describe InviteMailer do
context "invite to topic" do
let(:trust_level_2) { build(:user, trust_level: 2) }
let(:topic) { Fabricate(:topic, excerpt: "Topic invite support is now available in Discourse!", user: trust_level_2) }
let(:invite) { topic.invite(topic.user, 'name@example.com') }
context "default invite message" do
let(:invite) { topic.invite(topic.user, 'name@example.com') }
let(:invite_mail) { InviteMailer.send_invite(invite) }
it 'renders the invitee email' do
@ -123,7 +124,8 @@ describe InviteMailer do
end
context "custom invite message" do
let(:custom_invite_mail) { InviteMailer.send_invite(invite, "Hey, I thought you might enjoy this topic!") }
let(:invite) { topic.invite(topic.user, 'name@example.com', nil, "Hey, I thought you might enjoy this topic!") }
let(:custom_invite_mail) { InviteMailer.send_invite(invite) }
it 'renders custom_message' do
expect(custom_invite_mail.body.encoded).to match("Hey, I thought you might enjoy this topic!")