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