2018-11-20 20:47:30 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
module Emails
|
|
|
|
module Members
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
include MembersHelper
|
|
|
|
|
|
|
|
included do
|
|
|
|
helper_method :member_source, :member
|
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
def member_access_requested_email(member_source_type, member_id, recipient_id)
|
2016-06-16 23:09:34 +05:30
|
|
|
@member_source_type = member_source_type
|
|
|
|
@member_id = member_id
|
|
|
|
|
2020-08-18 19:51:02 +05:30
|
|
|
return unless member_exists?
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
user = User.find(recipient_id)
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
member_email_with_layout(
|
|
|
|
to: user.notification_email_for(notification_group),
|
|
|
|
subject: subject("Request to join the #{member_source.human_name} #{member_source.model_name.singular}"))
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def member_access_granted_email(member_source_type, member_id)
|
|
|
|
@member_source_type = member_source_type
|
|
|
|
@member_id = member_id
|
|
|
|
|
2020-08-18 19:51:02 +05:30
|
|
|
return unless member_exists?
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
member_email_with_layout(
|
|
|
|
to: member.user.notification_email_for(notification_group),
|
|
|
|
subject: subject("Access to the #{member_source.human_name} #{member_source.model_name.singular} was granted"))
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def member_access_denied_email(member_source_type, source_id, user_id)
|
|
|
|
@member_source_type = member_source_type
|
|
|
|
@member_source = member_source_class.find(source_id)
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
user = User.find(user_id)
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
member_email_with_layout(
|
|
|
|
to: user.notification_email_for(notification_group),
|
|
|
|
subject: subject("Access to the #{member_source.human_name} #{member_source.model_name.singular} was denied"))
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def member_invited_email(member_source_type, member_id, token)
|
|
|
|
@member_source_type = member_source_type
|
|
|
|
@member_id = member_id
|
|
|
|
@token = token
|
|
|
|
|
2020-08-18 19:51:02 +05:30
|
|
|
return unless member_exists?
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
subject_line = subject("Invitation to join the #{member_source.human_name} #{member_source.model_name.singular}")
|
|
|
|
|
|
|
|
if member.invite_to_unknown_user? && Feature.enabled?(:invite_email_experiment)
|
|
|
|
subject_line = subject("#{member.created_by.name} invited you to join GitLab") if member.created_by
|
|
|
|
@invite_url_params = { new_user_invite: 'experiment' }
|
|
|
|
|
|
|
|
member_email_with_layout(
|
|
|
|
to: member.invite_email,
|
|
|
|
subject: subject_line,
|
|
|
|
template: 'member_invited_email_experiment',
|
|
|
|
layout: 'experiment_mailer'
|
|
|
|
)
|
|
|
|
|
|
|
|
Gitlab::Tracking.event(Gitlab::Experimentation::EXPERIMENTS[:invite_email][:tracking_category], 'sent', property: 'experiment_group')
|
|
|
|
else
|
|
|
|
@invite_url_params = member.invite_to_unknown_user? ? { new_user_invite: 'control' } : {}
|
|
|
|
|
|
|
|
member_email_with_layout(
|
|
|
|
to: member.invite_email,
|
|
|
|
subject: subject_line
|
|
|
|
)
|
|
|
|
|
|
|
|
if member.invite_to_unknown_user?
|
|
|
|
Gitlab::Tracking.event(Gitlab::Experimentation::EXPERIMENTS[:invite_email][:tracking_category], 'sent', property: 'control_group')
|
|
|
|
end
|
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def member_invite_accepted_email(member_source_type, member_id)
|
|
|
|
@member_source_type = member_source_type
|
|
|
|
@member_id = member_id
|
2020-08-18 19:51:02 +05:30
|
|
|
|
|
|
|
return unless member_exists?
|
2016-06-16 23:09:34 +05:30
|
|
|
return unless member.created_by
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
member_email_with_layout(
|
|
|
|
to: member.created_by.notification_email_for(notification_group),
|
|
|
|
subject: subject('Invitation accepted'))
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def member_invite_declined_email(member_source_type, source_id, invite_email, created_by_id)
|
|
|
|
return unless created_by_id
|
|
|
|
|
|
|
|
@member_source_type = member_source_type
|
|
|
|
@member_source = member_source_class.find(source_id)
|
|
|
|
@invite_email = invite_email
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
user = User.find(created_by_id)
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
member_email_with_layout(
|
|
|
|
to: user.notification_email_for(notification_group),
|
|
|
|
subject: subject('Invitation declined'))
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
2020-08-18 19:51:02 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2016-06-16 23:09:34 +05:30
|
|
|
def member
|
2020-08-18 19:51:02 +05:30
|
|
|
@member ||= Member.find_by(id: @member_id)
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
2020-08-18 19:51:02 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2016-06-16 23:09:34 +05:30
|
|
|
|
|
|
|
def member_source
|
|
|
|
@member_source ||= member.source
|
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
def notification_group
|
|
|
|
@member_source_type.casecmp?('project') ? member_source.group : member_source
|
|
|
|
end
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
private
|
|
|
|
|
2020-08-18 19:51:02 +05:30
|
|
|
def member_exists?
|
|
|
|
Gitlab::AppLogger.info("Tried to send an email invitation for a deleted group. Member id: #{@member_id}") if member.blank?
|
|
|
|
member.present?
|
|
|
|
end
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
def member_source_class
|
|
|
|
@member_source_type.classify.constantize
|
|
|
|
end
|
2019-12-26 22:10:19 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
def member_email_with_layout(to:, subject:, template: nil, layout: 'mailer')
|
2019-12-26 22:10:19 +05:30
|
|
|
mail(to: to, subject: subject) do |format|
|
2020-11-24 15:15:51 +05:30
|
|
|
if template
|
|
|
|
format.html { render template, layout: layout }
|
|
|
|
format.text { render template, layout: layout }
|
|
|
|
else
|
|
|
|
format.html { render layout: layout }
|
|
|
|
format.text { render layout: layout }
|
|
|
|
end
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|