2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-02-05 13:16:51 -06:00
|
|
|
class InviteMailer < ActionMailer::Base
|
2013-06-10 15:46:08 -05:00
|
|
|
include Email::BuildEmailHelper
|
2013-02-07 09:45:24 -06:00
|
|
|
|
2019-07-30 14:05:08 -05:00
|
|
|
layout 'email_template'
|
2016-06-05 12:22:46 -05:00
|
|
|
|
2017-06-30 05:39:37 -05:00
|
|
|
def send_invite(invite)
|
2013-02-05 13:16:51 -06:00
|
|
|
# Find the first topic they were invited to
|
|
|
|
first_topic = invite.topics.order(:created_at).first
|
|
|
|
|
2014-07-10 00:27:40 -05:00
|
|
|
# get invitee name (based on site setting)
|
2017-12-04 02:29:24 -06:00
|
|
|
inviter_name = invite.invited_by.username
|
2015-02-05 10:43:30 -06:00
|
|
|
if SiteSetting.enable_names && invite.invited_by.name.present?
|
2017-12-04 02:29:24 -06:00
|
|
|
inviter_name = "#{invite.invited_by.name} (#{invite.invited_by.username})"
|
2014-07-10 00:27:40 -05:00
|
|
|
end
|
|
|
|
|
2019-07-05 13:51:03 -05:00
|
|
|
sanitized_message = invite.custom_message.present? ?
|
|
|
|
ActionView::Base.full_sanitizer.sanitize(invite.custom_message.gsub(/\n+/, " ").strip) : nil
|
|
|
|
|
2013-02-05 13:16:51 -06:00
|
|
|
# If they were invited to a topic
|
2013-11-06 11:56:26 -06:00
|
|
|
if first_topic.present?
|
2014-07-08 12:03:11 -05:00
|
|
|
# get topic excerpt
|
|
|
|
topic_excerpt = ""
|
|
|
|
if first_topic.excerpt
|
2016-06-10 21:37:33 -05:00
|
|
|
topic_excerpt = first_topic.excerpt.tr("\n", " ")
|
2014-07-08 12:03:11 -05:00
|
|
|
end
|
|
|
|
|
2017-04-24 14:26:06 -05:00
|
|
|
topic_title = first_topic.try(:title)
|
|
|
|
if SiteSetting.private_email?
|
2017-04-27 10:45:49 -05:00
|
|
|
topic_title = I18n.t("system_messages.private_topic_title", id: first_topic.id)
|
2017-04-24 14:26:06 -05:00
|
|
|
topic_excerpt = ""
|
|
|
|
end
|
|
|
|
|
2013-11-06 11:56:26 -06:00
|
|
|
build_email(invite.email,
|
2019-07-05 13:51:03 -05:00
|
|
|
template: sanitized_message ? 'custom_invite_mailer' : 'invite_mailer',
|
2017-12-04 02:29:24 -06:00
|
|
|
inviter_name: inviter_name,
|
2014-07-09 23:33:09 -05:00
|
|
|
site_domain_name: Discourse.current_hostname,
|
2013-11-06 11:56:26 -06:00
|
|
|
invite_link: "#{Discourse.base_url}/invites/#{invite.invite_key}",
|
2017-04-24 14:26:06 -05:00
|
|
|
topic_title: topic_title,
|
2014-07-08 12:03:11 -05:00
|
|
|
topic_excerpt: topic_excerpt,
|
2014-06-14 17:49:19 -05:00
|
|
|
site_description: SiteSetting.site_description,
|
2016-06-08 07:34:25 -05:00
|
|
|
site_title: SiteSetting.title,
|
2019-07-05 13:51:03 -05:00
|
|
|
user_custom_message: sanitized_message)
|
2013-11-06 11:56:26 -06:00
|
|
|
else
|
|
|
|
build_email(invite.email,
|
2019-07-05 13:51:03 -05:00
|
|
|
template: sanitized_message ? 'custom_invite_forum_mailer' : 'invite_forum_mailer',
|
2017-12-04 02:29:24 -06:00
|
|
|
inviter_name: inviter_name,
|
2014-07-10 00:27:40 -05:00
|
|
|
site_domain_name: Discourse.current_hostname,
|
2014-06-14 17:49:19 -05:00
|
|
|
invite_link: "#{Discourse.base_url}/invites/#{invite.invite_key}",
|
|
|
|
site_description: SiteSetting.site_description,
|
2016-06-08 07:34:25 -05:00
|
|
|
site_title: SiteSetting.title,
|
2019-07-05 13:51:03 -05:00
|
|
|
user_custom_message: sanitized_message)
|
2013-11-06 11:56:26 -06:00
|
|
|
end
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|
|
|
|
|
2014-10-10 10:47:52 -05:00
|
|
|
def send_password_instructions(user)
|
|
|
|
if user.present?
|
|
|
|
email_token = user.email_tokens.create(email: user.email)
|
|
|
|
build_email(user.email,
|
|
|
|
template: 'invite_password_instructions',
|
|
|
|
email_token: email_token.token)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|