71 lines
2.9 KiB
Ruby
71 lines
2.9 KiB
Ruby
# == Schema Information
|
|
#
|
|
# Table name: message_templates
|
|
#
|
|
# id :integer not null, primary key
|
|
# type :string(255)
|
|
# sys_notice :text(65535)
|
|
# email :text(65535)
|
|
# created_at :datetime not null
|
|
# updated_at :datetime not null
|
|
# notification_url :string(255)
|
|
# email_title :string(255)
|
|
#
|
|
|
|
# 我管理的仓库有里程碑完成
|
|
class MessageTemplate::ProjectMilestoneCompleted < MessageTemplate
|
|
|
|
# MessageTemplate::ProjectMilestoneCompleted.get_message_content(User.where(login: 'yystopf'))
|
|
def self.get_message_content(receivers, milestone)
|
|
receivers.each do |receiver|
|
|
if receiver.user_template_message_setting.present?
|
|
send_setting = receiver.user_template_message_setting.notification_body["ManageProject::MilestoneCompleted"]
|
|
send_setting = send_setting.nil? ? UserTemplateMessageSetting.init_notification_body["ManageProject::MilestoneCompleted"] : send_setting
|
|
receivers = receivers.where.not(id: receiver.id) unless send_setting
|
|
end
|
|
end
|
|
return '', '', '' if receivers.blank?
|
|
project = milestone&.project
|
|
owner = project&.owner
|
|
content = sys_notice.gsub('{nickname}', owner&.real_name).gsub('{repository}', project&.name).gsub('{name}', milestone&.name)
|
|
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', milestone&.id.to_s)
|
|
|
|
return receivers_string(receivers), content, url
|
|
rescue => e
|
|
Rails.logger.info("MessageTemplate::ProjectMilestoneCompleted.get_message_content [ERROR] #{e}")
|
|
return '', '', ''
|
|
end
|
|
|
|
def self.get_email_message_content(receiver, milestone)
|
|
if receiver.user_template_message_setting.present?
|
|
send_setting = receiver.user_template_message_setting.email_body["ManageProject::MilestoneCompleted"]
|
|
send_setting = send_setting.nil? ? UserTemplateMessageSetting.init_email_body["ManageProject::MilestoneCompleted"] : send_setting
|
|
return '', '', '' unless send_setting
|
|
project = milestone&.project
|
|
owner = project&.owner
|
|
title = email_title
|
|
title.gsub!('{nickname}', owner&.real_name)
|
|
title.gsub!('{repository}', project&.name)
|
|
|
|
content = email
|
|
content.gsub!('{receiver}', receiver&.real_name)
|
|
content.gsub!('{baseurl}', base_url)
|
|
content.gsub!('{nickname}', owner&.real_name)
|
|
content.gsub!('{repository}', project&.name)
|
|
content.gsub!('{login}', owner&.login)
|
|
content.gsub!('{identifier}', project&.identifier)
|
|
content.gsub!('{id}', milestone&.id.to_s)
|
|
content.gsub!('{name}', milestone&.name)
|
|
content.gsub!('{platform}', PLATFORM)
|
|
|
|
return receiver&.mail, title, content
|
|
else
|
|
return '', '', ''
|
|
end
|
|
|
|
rescue => e
|
|
Rails.logger.info("MessageTemplate::ProjectMilestoneCompleted.get_email_message_content [ERROR] #{e}")
|
|
return '', '', ''
|
|
end
|
|
end
|