mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 06:13:40 +08:00
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:
parent
c1580b9d36
commit
16d356ab4e
|
@ -9,7 +9,7 @@ module Jobs
|
||||||
raise Discourse::InvalidParameters.new(:invite_id) unless args[:invite_id].present?
|
raise Discourse::InvalidParameters.new(:invite_id) unless args[:invite_id].present?
|
||||||
|
|
||||||
invite = Invite.find_by(id: args[:invite_id])
|
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
|
Email::Sender.new(message, :invite).send
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ class InviteMailer < ActionMailer::Base
|
||||||
include EmailHelper
|
include EmailHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_invite(invite, custom_message=nil)
|
def send_invite(invite)
|
||||||
# Find the first topic they were invited to
|
# Find the first topic they were invited to
|
||||||
first_topic = invite.topics.order(:created_at).first
|
first_topic = invite.topics.order(:created_at).first
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ class InviteMailer < ActionMailer::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
template = 'invite_mailer'
|
template = 'invite_mailer'
|
||||||
if custom_message.present?
|
if invite.custom_message.present?
|
||||||
template = 'custom_invite_mailer'
|
template = 'custom_invite_mailer'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -46,10 +46,10 @@ class InviteMailer < ActionMailer::Base
|
||||||
topic_excerpt: topic_excerpt,
|
topic_excerpt: topic_excerpt,
|
||||||
site_description: SiteSetting.site_description,
|
site_description: SiteSetting.site_description,
|
||||||
site_title: SiteSetting.title,
|
site_title: SiteSetting.title,
|
||||||
user_custom_message: custom_message)
|
user_custom_message: invite.custom_message)
|
||||||
else
|
else
|
||||||
template = 'invite_forum_mailer'
|
template = 'invite_forum_mailer'
|
||||||
if custom_message.present?
|
if invite.custom_message.present?
|
||||||
template = 'custom_invite_forum_mailer'
|
template = 'custom_invite_forum_mailer'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ class InviteMailer < ActionMailer::Base
|
||||||
invite_link: "#{Discourse.base_url}/invites/#{invite.invite_key}",
|
invite_link: "#{Discourse.base_url}/invites/#{invite.invite_key}",
|
||||||
site_description: SiteSetting.site_description,
|
site_description: SiteSetting.site_description,
|
||||||
site_title: SiteSetting.title,
|
site_title: SiteSetting.title,
|
||||||
user_custom_message: custom_message)
|
user_custom_message: invite.custom_message)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -122,6 +122,7 @@ class Invite < ActiveRecord::Base
|
||||||
if !invite
|
if !invite
|
||||||
create_args = { invited_by: invited_by, email: lower_email }
|
create_args = { invited_by: invited_by, email: lower_email }
|
||||||
create_args[:moderator] = true if opts[:moderator]
|
create_args[:moderator] = true if opts[:moderator]
|
||||||
|
create_args[:custom_message] = custom_message if custom_message
|
||||||
invite = Invite.create!(create_args)
|
invite = Invite.create!(create_args)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -143,7 +144,7 @@ class Invite < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
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.reload
|
||||||
invite
|
invite
|
||||||
|
@ -295,6 +296,7 @@ end
|
||||||
# deleted_by_id :integer
|
# deleted_by_id :integer
|
||||||
# invalidated_at :datetime
|
# invalidated_at :datetime
|
||||||
# moderator :boolean default(FALSE), not null
|
# moderator :boolean default(FALSE), not null
|
||||||
|
# custom_message :text
|
||||||
#
|
#
|
||||||
# Indexes
|
# Indexes
|
||||||
#
|
#
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddCustomMessageToInvite < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :invites, :custom_message, :text
|
||||||
|
end
|
||||||
|
end
|
|
@ -5,9 +5,9 @@ describe InviteMailer do
|
||||||
describe "send_invite" do
|
describe "send_invite" do
|
||||||
|
|
||||||
context "invite to site" do
|
context "invite to site" do
|
||||||
let(:invite) { Fabricate(:invite) }
|
|
||||||
|
|
||||||
context "default invite message" do
|
context "default invite message" do
|
||||||
|
let(:invite) { Fabricate(:invite) }
|
||||||
let(:invite_mail) { InviteMailer.send_invite(invite) }
|
let(:invite_mail) { InviteMailer.send_invite(invite) }
|
||||||
|
|
||||||
it 'renders the invitee email' do
|
it 'renders the invitee email' do
|
||||||
|
@ -36,9 +36,10 @@ describe InviteMailer do
|
||||||
end
|
end
|
||||||
|
|
||||||
context "custom invite message" do
|
context "custom invite message" do
|
||||||
|
let(:invite) { Fabricate(:invite, custom_message: "Hey, you should join this forum!") }
|
||||||
|
|
||||||
context "custom message includes invite link" do
|
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
|
it 'renders the invitee email' do
|
||||||
expect(custom_invite_mail.to).to eql([invite.email])
|
expect(custom_invite_mail.to).to eql([invite.email])
|
||||||
|
@ -76,9 +77,9 @@ describe InviteMailer do
|
||||||
context "invite to topic" do
|
context "invite to topic" do
|
||||||
let(:trust_level_2) { build(:user, trust_level: 2) }
|
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(: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
|
context "default invite message" do
|
||||||
|
let(:invite) { topic.invite(topic.user, 'name@example.com') }
|
||||||
let(:invite_mail) { InviteMailer.send_invite(invite) }
|
let(:invite_mail) { InviteMailer.send_invite(invite) }
|
||||||
|
|
||||||
it 'renders the invitee email' do
|
it 'renders the invitee email' do
|
||||||
|
@ -123,7 +124,8 @@ describe InviteMailer do
|
||||||
end
|
end
|
||||||
|
|
||||||
context "custom invite message" do
|
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
|
it 'renders custom_message' do
|
||||||
expect(custom_invite_mail.body.encoded).to match("Hey, I thought you might enjoy this topic!")
|
expect(custom_invite_mail.body.encoded).to match("Hey, I thought you might enjoy this topic!")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user