diff --git a/app/jobs/send_template_message_job.rb b/app/jobs/send_template_message_job.rb index 3dc946e76..bc080c689 100644 --- a/app/jobs/send_template_message_job.rb +++ b/app/jobs/send_template_message_job.rb @@ -20,8 +20,10 @@ class SendTemplateMessageJob < ApplicationJob receivers = User.where(id: issue&.assigned_to_id).where.not(id: operator&.id) receivers_string, content, notification_url = MessageTemplate::IssueAssigned.get_message_content(receivers, operator, issue) Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, issue_id: issue.id}) - receivers_email_string, email_content, notification_url = MessageTemplate::IssueAssigned.get_email_message_content(receivers, operator, issue) - Notice::Write::EmailCreateService.call(receivers_email_string, email_content, source) + receivers.find_each do |receiver| + receivers_email_string, email_title, email_content = MessageTemplate::IssueAssigned.get_email_message_content(receiver, operator, issue) + Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content) + end when 'IssueAssignerExpire' issue_id = args[0] issue = Issue.find_by_id(issue_id) @@ -67,8 +69,10 @@ class SendTemplateMessageJob < ApplicationJob receivers = User.where(id: user.id) receivers_string, content, notification_url = MessageTemplate::OrganizationJoined.get_message_content(receivers, organization) Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {user_id: user.id, organization_id: organization.id}) - receivers_email_string, email_content, notification_url = MessageTemplate::OrganizationJoined.get_email_message_content(receivers, organization) - Notice::Write::EmailCreateService.call(receivers_email_string, email_content, source) + receivers.find_each do |receiver| + receivers_email_string, email_title, email_content = MessageTemplate::OrganizationJoined.get_email_message_content(receiver, organization) + Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content) + end when 'OrganizationLeft' user_id, organization_id = args[0], args[1] user = User.find_by_id(user_id) @@ -77,8 +81,10 @@ class SendTemplateMessageJob < ApplicationJob receivers = User.where(id: user.id) receivers_string, content, notification_url = MessageTemplate::OrganizationLeft.get_message_content(receivers, organization) Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {user_id: user.id, organization_id: organization.id}) - receivers_email_string, email_content, notification_url = MessageTemplate::OrganizationLeft.get_email_message_content(receivers, organization) - Notice::Write::EmailCreateService.call(receivers_email_string, email_content, source) + receivers.find_each do |receiver| + receivers_email_string, email_title, email_content = MessageTemplate::OrganizationLeft.get_email_message_content(receiver, organization) + Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content) + end when 'OrganizationRole' user_id, organization_id, role = args[0], args[1], args[2] user = User.find_by_id(user_id) @@ -87,19 +93,27 @@ class SendTemplateMessageJob < ApplicationJob receivers = User.where(id: user.id) receivers_string, content, notification_url = MessageTemplate::OrganizationRole.get_message_content(receivers, organization, role) Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {user_id: user.id, organization_id: organization.id, role: role}) - receivers_email_string, email_content, notification_url = MessageTemplate::OrganizationRole.get_email_message_content(receivers, organization, role) - Notice::Write::EmailCreateService.call(receivers_email_string, email_content, source) + receivers.find_each do |receiver| + receivers_email_string, email_title, email_content = MessageTemplate::OrganizationRole.get_email_message_content(receiver, organization, role) + Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content) + end when 'ProjectIssue' operator_id, issue_id = args[0], args[1] operator = User.find_by_id(operator_id) issue = Issue.find_by_id(issue_id) return unless operator.present? && issue.present? && issue&.project.present? managers = issue&.project&.all_managers.where.not(id: operator&.id) - followers = [] # TODO + followers = User.none # TODO receivers_string, content, notification_url = MessageTemplate::ProjectIssue.get_message_content(managers, followers, operator, issue) Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, issue_id: issue.id}) - receivers_email_string, email_content, notification_url = MessageTemplate::ProjectIssue.get_email_message_content(managers, followers, operator, issue) - Notice::Write::EmailCreateService.call(receivers_email_string, email_content, source) + managers.find_each do |receiver| + receivers_email_string, email_title, email_content = MessageTemplate::ProjectIssue.get_email_message_content(receiver, true, operator, issue) + Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content) + end + followers.find_each do |receiver| + receivers_email_string, email_title, email_content = MessageTemplate::ProjectIssue.get_email_message_content(receiver, false, operator, issue) + Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content) + end when 'ProjectJoined' operator_id, user_id, project_id = args[0], args[1], args[2] operator = User.find_by_id(operator_id) @@ -109,8 +123,10 @@ class SendTemplateMessageJob < ApplicationJob receivers = User.where(id: user.id).where.not(id: operator&.id) receivers_string, content, notification_url = MessageTemplate::ProjectJoined.get_message_content(receivers, project) Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, user_id: user.id, project_id: project.id}) - receivers_emal_string, email_content, notification_url = MessageTemplate::ProjectJoined.get_email_message_content(receivers, project) - Notice::Write::EmailCreateService.call(receivers_email_string, email_content, source) + receivers.find_each do |receiver| + receivers_email_string, email_title, email_content = MessageTemplate::ProjectJoined.get_email_message_content(receiver, project) + Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content) + end when 'ProjectLeft' operator_id, user_id, project_id = args[0], args[1], args[2] operator = User.find_by_id(operator_id) @@ -120,8 +136,10 @@ class SendTemplateMessageJob < ApplicationJob receivers = User.where(id: user.id).where.not(id: operator&.id) receivers_string, content, notification_url = MessageTemplate::ProjectLeft.get_message_content(receivers, project) Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, user_id: user.id, project_id: project.id}) - receivers_email_string, email_content, notification_url = MessageTemplate::ProjectLeft.get_email_message_content(receivers, project) - Notice::Write::EmailCreateService.call(receivers_email_string, email_content, source) + receivers.find_each do |receiver| + receivers_email_string, email_title, email_content = MessageTemplate::ProjectLeft.get_email_message_content(receiver, project) + Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content) + end when 'ProjectMemberJoined' operator_id, user_id, project_id = args[0], args[1], args[2] operator = User.find_by_id(operator_id) @@ -131,8 +149,10 @@ class SendTemplateMessageJob < ApplicationJob receivers = project&.all_managers.where.not(id: operator&.id) receivers_string, content, notification_url = MessageTemplate::ProjectMemberJoined.get_message_content(receivers, user, project) Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, user_id: user.id, project_id: project.id}) - receivers_email_string, email_content, notification_url = MessageTemplate::ProjectMemberJoined.get_email_message_content(receivers, user, project) - Notice::Write::EmailCreateService.call(receivers_email_string, email_content, source) + receivers.find_each do |receiver| + receivers_email_string, email_title, email_content = MessageTemplate::ProjectMemberJoined.get_email_message_content(receiver, user, project) + Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content) + end when 'ProjectMemberLeft' operator_id, user_id, project_id = args[0], args[1], args[2] operator = User.find_by_id(operator_id) @@ -142,19 +162,27 @@ class SendTemplateMessageJob < ApplicationJob receivers = project&.all_managers.where.not(id: operator&.id) receivers_string, content, notification_url = MessageTemplate::ProjectMemberLeft.get_message_content(receivers, user, project) Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, user_id: user.id, project_id: project.id}) - receivers_email_string, email_content, notification_url = MessageTemplate::ProjectMemberLeft.get_email_message_content(receivers, user, project) - Notice::Write::EmailCreateService.call(receivers_email_string, email_content, source) + receivers.find_each do |receiver| + receivers_email_string, email_title, email_content = MessageTemplate::ProjectMemberLeft.get_email_message_content(receiver, user, project) + Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content) + end when 'ProjectPullRequest' operator_id, pull_request_id = args[0], args[1] operator = User.find_by_id(operator_id) pull_request = PullRequest.find_by_id(pull_request_id) return unless operator.present? && pull_request.present? && pull_request&.project.present? managers = pull_request&.project&.all_managers.where.not(id: operator&.id) - followers = [] # TODO + followers = User.none # TODO receivers_string, content, notification_url = MessageTemplate::ProjectPullRequest.get_message_content(managers, followers, operator, pull_request) Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, pull_request_id: pull_request.id}) - receivers_email_string, email_content, notification_url = MessageTemplate::ProjectPullRequest.get_email_message_content(managers, followers, operator, pull_request) - Notice::Write::EmailCreateService.call(receivers_email_string, email_content, source) + managers.find_each do |receiver| + receivers_email_string, email_title, email_content = MessageTemplate::ProjectPullRequest.get_email_message_content(receiver, true, operator, pull_request) + Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content) + end + followers.find_each do |receiver| + receivers_email_string, email_title, email_content = MessageTemplate::ProjectPullRequest.get_email_message_content(receiver, false, operator, pull_request) + Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content) + end when 'ProjectRole' operator_id, user_id, project_id, role = args[0], args[1], args[2], args[3] operator = User.find_by_id(operator_id) @@ -164,8 +192,10 @@ class SendTemplateMessageJob < ApplicationJob receivers = User.where(id: user.id).where.not(id: operator&.id) receivers_string, content, notification_url = MessageTemplate::ProjectRole.get_message_content(receivers, project, role) Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, user_id: user.id, project_id: project.id, role: role}) - receivers_email_string, email_content, notification_url = MessageTemplate::ProjectRole.get_email_message_content(receivers, project, role) - Notice::Write::EmailCreateService.call(receivers_email_string, email_content, source) + receivers.find_each do |receiver| + receivers_email_string, email_title, email_content = MessageTemplate::ProjectRole.get_email_message_content(receivers, project, role) + Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content) + end when 'ProjectSettingChanged' operator_id, project_id, change_params = args[0], args[1], args[2] operator = User.find_by_id(operator_id) @@ -174,8 +204,10 @@ class SendTemplateMessageJob < ApplicationJob receivers = project.all_managers.where.not(id: operator&.id) receivers_string, content, notification_url = MessageTemplate::ProjectSettingChanged.get_message_content(receivers, operator, project, change_params.symbolize_keys) Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, project_id: project.id, change_params: change_params}) - receivers_email_string, email_content, notification_url = MessageTemplate::ProjectSettingChanged.get_email_message_content(receivers, operator, project, change_params.symbolize_keys) - Notice::Write::EmailCreateService.call(receivers_email_string, email_content, source) + receivers.find_each do |receiver| + receivers_email_string, email_title, email_content = MessageTemplate::ProjectSettingChanged.get_email_message_content(receiver, operator, project, change_params.symbolize_keys) + Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content) + end when 'PullRequestAssigned' operator_id, pull_request_id = args[0], args[1] operator = User.find_by_id(operator_id) @@ -185,8 +217,10 @@ class SendTemplateMessageJob < ApplicationJob receivers = User.where(id: issue&.assigned_to_id).where.not(id: operator&.id) receivers_string, content, notification_url = MessageTemplate::PullRequestAssigned.get_message_content(receivers, operator, pull_request) Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, pull_request_id: pull_request.id}) - receivers_email_string, email_content, notification_url = MessageTemplate::PullRequestAssigned.get_email_message_content(receivers, operator, pull_request) - Notice::Write::EmailCreateService.call(receivers_email_string, email_content, source) + receivers.find_each do |receiver| + receivers_email_string, email_title, email_content = MessageTemplate::PullRequestAssigned.get_email_message_content(receiver, operator, pull_request) + Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content) + end when 'PullRequestAtme' receivers, operator_id, pull_request_id = args[0], args[1], args[2] operator = User.find_by_id(operator_id) diff --git a/app/models/message_template.rb b/app/models/message_template.rb index daca02838..2c8c96869 100644 --- a/app/models/message_template.rb +++ b/app/models/message_template.rb @@ -9,13 +9,15 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # class MessageTemplate < ApplicationRecord def self.build_init_data self.create(type: 'MessageTemplate::FollowedTip', sys_notice: '{nickname} 关注了你', notification_url: '{baseurl}/{login}') - self.create(type: 'MessageTemplate::IssueAssigned', sys_notice: '{nickname1}在 {nickname2}/{repository} 指派给你一个易修:{title}', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}') + email_html = File.read("#{email_template_html_dir}/issue_assigned.html") + self.create(type: 'MessageTemplate::IssueAssigned', sys_notice: '{nickname1}在 {nickname2}/{repository} 指派给你一个易修:{title}', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}', email: email_html, email_title: '{nickname1} 在 {nickname2}/{repository} 指派给你一个易修') self.create(type: 'MessageTemplate::IssueAssignerExpire', sys_notice: '您负责的易修 {title} 已临近截止日期,请尽快处理', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}') self.create(type: 'MessageTemplate::IssueAtme', sys_notice: '{nickname} 在易修 {title} 中@我', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}') self.create(type: 'MessageTemplate::IssueChanged', sys_notice: '在项目 {nickname2}/{repository} 的易修 {title} 中:{ifassigner}{nickname1}将负责人从 {assigner1} 修改为 {assigner2} {endassigner}{ifstatus}{nickname1}将状态从 {status1} 修改为 {status2} {endstatus}{iftracker}{nickname1}将类型从 {tracker1} 修改为 {tracker2} {endtracker}{ifpriority}{nickname1}将优先级从 {priority1} 修改为 {priority2} {endpriority}{ifmilestone}{nickname1}将里程碑从 {milestone1} 修改为 {milestone2} {endmilestone}{iftag}{nickname1}将标记从 {tag1} 修改为 {tag2} {endtag}{ifdoneratio}{nickname1}将完成度从 {doneratio1} 修改为 {doneratio2} {enddoneratio}{ifbranch}{nickname1}将指定分支从 {branch1} 修改为 {branch2} {endbranch}{ifstartdate}{nickname1}将开始日期从 {startdate1} 修改为 {startdate2} {endstartdate}{ifduedate}{nickname1}将结束日期从 {duedate1} 修改为 {duedate2} {endduedate}', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}') @@ -23,25 +25,35 @@ class MessageTemplate < ApplicationRecord self.create(type: 'MessageTemplate::IssueDeleted', sys_notice: '{nickname}已将易修 {title} 删除', notification_url: '') self.create(type: 'MessageTemplate::IssueJournal', sys_notice: '{nickname}评论易修{title}:{notes}', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}') self.create(type: 'MessageTemplate::LoginIpTip', sys_notice: '您的账号{nickname}于{login_time)在非常用的IP地址{ip}登录,如非本人操作,请立即修改密码', notification_url: '') - self.create(type: 'MessageTemplate::OrganizationJoined', sys_notice: '你已加入 {organization} 组织', notification_url: '{baseurl}/{login}') - self.create(type: 'MessageTemplate::OrganizationLeft', sys_notice: '你已被移出 {organization} 组织', notification_url: '') + email_html = File.read("#{email_template_html_dir}/organization_joined.html") + self.create(type: 'MessageTemplate::OrganizationJoined', sys_notice: '你已加入 {organization} 组织', notification_url: '{baseurl}/{login}', email: email_html, email_title: '你已加入 {organization} 组织') + email_html = File.read("#{email_template_html_dir}/organization_left.html") + self.create(type: 'MessageTemplate::OrganizationLeft', sys_notice: '你已被移出 {organization} 组织', notification_url: '', email: email_html, email_title: '你已被移出 {organization} 组织') self.create(type: 'MessageTemplate::OrganizationRole', sys_notice: '组织 {organization} 已把你的角色改为 {role}', notification_url: '{baseurl}/{login}') self.create(type: 'MessageTemplate::ProjectDeleted', sys_notice: '你关注的仓库{nickname}/{repository}已被删除', notification_url: '') self.create(type: 'MessageTemplate::ProjectFollowed', sys_notice: '{nickname} 关注了你管理的仓库', notification_url: '{baseurl}/{login}') self.create(type: 'MessageTemplate::ProjectForked', sys_notice: '{nickname1} 复刻了你管理的仓库{nickname1}/{repository1}到{nickname2}/{repository2}', notification_url: '{baseurl}/{owner}/{identifier}') - self.create(type: 'MessageTemplate::ProjectIssue', sys_notice: '{nickname1}在 {nickname2}/{repository} 新建易修:{title}', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}') - self.create(type: 'MessageTemplate::ProjectJoined', sys_notice: '你已加入 {repository} 项目', notification_url: '{baseurl}/{owner}/{identifier}') - self.create(type: 'MessageTemplate::ProjectLeft', sys_notice: '你已被移出 {repository} 项目', notification_url: '') - self.create(type: 'MessageTemplate::ProjectMemberJoined', sys_notice: '{nickname1} 已加入项目 {nickname2}/{repository}', notification_url: '{baseurl}/{owner}/{identifier}') - self.create(type: 'MessageTemplate::ProjectMemberLeft', sys_notice: '{nickname1} 已被移出项目 {nickname2}/{repository}', notification_url: '{baseurl}/{owner}/{identifier}') + email_html = File.read("#{email_template_html_dir}/project_issue.html") + self.create(type: 'MessageTemplate::ProjectIssue', sys_notice: '{nickname1}在 {nickname2}/{repository} 新建易修:{title}', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}', email: email_html, email_title: '{nickname1} 在 {nickname2}/{repository} 新建了一个易修') + email_html = File.read("#{email_template_html_dir}/project_joined.html") + self.create(type: 'MessageTemplate::ProjectJoined', sys_notice: '你已加入 {repository} 项目', notification_url: '{baseurl}/{owner}/{identifier}', email: email_html, email_title: '你已加入 {repository} 项目') + email_html = File.read("#{email_template_html_dir}/project_left.html") + self.create(type: 'MessageTemplate::ProjectLeft', sys_notice: '你已被移出 {repository} 项目', notification_url: '', email: email_html, email_title: '你已被移出 {repository} 项目') + email_html = File.read("#{email_template_html_dir}/project_member_joined.html") + self.create(type: 'MessageTemplate::ProjectMemberJoined', sys_notice: '{nickname1} 已加入项目 {nickname2}/{repository}', notification_url: '{baseurl}/{owner}/{identifier}', email: email_html, email_title: '{nickname1} 已加入项目 {nickname2}/{repository}') + email_html = File.read("#{email_template_html_dir}/project_member_left.html") + self.create(type: 'MessageTemplate::ProjectMemberLeft', sys_notice: '{nickname1} 已被移出项目 {nickname2}/{repository}', notification_url: '{baseurl}/{owner}/{identifier}', email: email_html, email_title: '{nickname1} 已被移出项目 {nickname2}/{repository}') self.create(type: 'MessageTemplate::ProjectMilestone', sys_notice: '{nickname1}在 {nickname2}/{repository} 创建了一个里程碑:{title}', notification_url: '{baseurl}/{owner}/{identifier}/milestones/{id}') self.create(type: 'MessageTemplate::ProjectPraised', sys_notice: '{nickname} 点赞了你管理的仓库', notification_url: '{baseurl}/{login}') - self.create(type: 'MessageTemplate::ProjectPullRequest', sys_notice: '{nickname1}在 {nickname2}/{repository} 提交了一个合并请求:{title}', notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}/Messagecount') + email_html = File.read("#{email_template_html_dir}/project_pull_request.html") + self.create(type: 'MessageTemplate::ProjectPullRequest', sys_notice: '{nickname1}在 {nickname2}/{repository} 提交了一个合并请求:{title}', notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}/Messagecount', email: email_html, email_title: '{nickname1} 在 {nickname2}/{repository} 提交了一个合并请求') self.create(type: 'MessageTemplate::ProjectRole', sys_notice: '仓库 {repository} 已把你的角色改为 {role}', notification_url: '{baseurl}/{owner}/{identifier}') - self.create(type: 'MessageTemplate::ProjectSettingChanged', sys_notice: '{nickname1}更改了 {nickname2}/{repository} 仓库设置:{ifname}更改项目名称为"{name}"{endname}{ifdescription}更改项目简介为"{description}"{enddescription}{ifcategory}更改项目类别为"{category}"{endcategory}{iflanguage}更改项目语言为"{language}"{endlanguage}{ifpermission}将仓库设为"{permission}"{endpermission}{ifnavbar}将项目导航更改为"{navbar}"{endnavbar}', notification_url: '{baseurl}/{owner}/{identifier}/settings') + email_html = File.read("#{email_template_html_dir}/project_setting_changed.html") + self.create(type: 'MessageTemplate::ProjectSettingChanged', sys_notice: '{nickname1}更改了 {nickname2}/{repository} 仓库设置:{ifname}更改项目名称为"{name}"{endname}{ifdescription}更改项目简介为"{description}"{enddescription}{ifcategory}更改项目类别为"{category}"{endcategory}{iflanguage}更改项目语言为"{language}"{endlanguage}{ifpermission}将仓库设为"{permission}"{endpermission}{ifnavbar}将项目导航更改为"{navbar}"{endnavbar}', notification_url: '{baseurl}/{owner}/{identifier}/settings', email: email_html, email_title: '您管理的仓库 {nickname2}/{repository} 仓库设置已被更改') self.create(type: 'MessageTemplate::ProjectTransfer', sys_notice: '你关注的仓库{nickname1}/{repository1}已被转移至{nickname2}/{repository2}', notification_url: '{baseurl}/{owner}/{identifier}') self.create(type: 'MessageTemplate::ProjectVersion', sys_notice: '{nickname1}在 {nickname2}/{repository} 创建了发行版:{title}', notification_url: '{baseurl}/{owner}/{identifier}/releases') - self.create(type: 'MessageTemplate::PullRequestAssigned', sys_notice: '{nickname1}在 {nickname2}/{repository} 指派给你一个合并请求:{title}', notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}/Messagecount') + email_html = File.read("#{email_template_html_dir}/pull_request_assigned.html") + self.create(type: 'MessageTemplate::PullRequestAssigned', sys_notice: '{nickname1}在 {nickname2}/{repository} 指派给你一个合并请求:{title}', notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}/Messagecount', email: email_html, email_title: '{nickname1} 在 {nickname2}/{repository} 指派给你一个合并请求') self.create(type: 'MessageTemplate::PullRequestAtme', sys_notice: '{nickname} 在合并请求 {title} 中@我', notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}/Messagecount') self.create(type: 'MessageTemplate::PullRequestChanged', sys_notice: '在项目{nickname2}/{repository}的合并请求 {title} 中:{ifassigner}{nickname1}将审查成员从 {assigner1} 修改为 {assigner2} {endassigner}{ifmilestone}{nickname1}将里程碑从 {milestone1} 修改为 {milestone2} {endmilestone}{iftag}{nickname1}将标记从 {tag1} 修改为 {tag2} {endtag}{ifpriority}{nickname1}将优先级从 {priority1} 修改为 {priority2} {endpriority}', notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}/Messagecount') self.create(type: 'MessageTemplate::PullRequestClosed', sys_notice: '你提交的合并请求:{title} 被拒绝', notification_url: '') @@ -57,6 +69,10 @@ class MessageTemplate < ApplicationRecord self.last&.email end + def self.email_title + self.last&.email_title + end + def self.notification_url self.last&.notification_url.gsub('{baseurl}', base_url) end @@ -73,6 +89,10 @@ class MessageTemplate < ApplicationRecord receivers.pluck(:mail).join(",") end + def self.email_template_html_dir + "#{Rails.root}/public/message_template" + end + def simple_type self.type.split("::")[-1] end diff --git a/app/models/message_template/followed_tip.rb b/app/models/message_template/followed_tip.rb index d8c6cba20..6231db595 100644 --- a/app/models/message_template/followed_tip.rb +++ b/app/models/message_template/followed_tip.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # 被关注提示 diff --git a/app/models/message_template/issue_assigned.rb b/app/models/message_template/issue_assigned.rb index d29fa03c4..91daa8dcc 100644 --- a/app/models/message_template/issue_assigned.rb +++ b/app/models/message_template/issue_assigned.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # 有新指派给我的易修 @@ -26,12 +27,26 @@ class MessageTemplate::IssueAssigned < MessageTemplate return '', '', '' end - def self.get_email_message_content(receivers, operator, issue) + def self.get_email_message_content(receiver, operator, issue) project = issue&.project owner = project&.owner - content = email.gsub('{nickname1}', operator&.real_name).gsub('{nickname2}', owner&.real_name).gsub('{repository}', project&.name).gsub('{title}', issue&.subject) - url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.id.to_s) - return receivers_email_string(receivers), content, url + title = email_title + title.gsub!('{nickname1}', operator&.real_name) + title.gsub!('{nickname2}', owner&.real_name) + title.gsub!('{repository}', project&.name) + content = email + content.gsub!('{receiver}', receiver&.real_name) + content.gsub!('{nickname1}', operator&.real_name) + content.gsub!('{login1}', operator&.login) + content.gsub!('{nickname2}', owner&.real_name) + content.gsub!('{login2}', owner&.login) + content.gsub!('{identifier}', project&.identifier) + content.gsub!('{repository}', project&.name) + content.gsub!('{baseurl}', base_url) + content.gsub!('{title}', issue&.subject) + content.gsub!('{id}', issue&.id.to_s) + + return receiver&.mail, title, content rescue => e Rails.logger.info("MessageTemplate::IssueAssigned.get_email_message_content [ERROR] #{e}") return '', '', '' diff --git a/app/models/message_template/issue_assigner_expire.rb b/app/models/message_template/issue_assigner_expire.rb index dc7a34fa9..405d44bb4 100644 --- a/app/models/message_template/issue_assigner_expire.rb +++ b/app/models/message_template/issue_assigner_expire.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # 我负责的易修截止日期到达最后一天 diff --git a/app/models/message_template/issue_atme.rb b/app/models/message_template/issue_atme.rb index 5678b31de..d9dfd1957 100644 --- a/app/models/message_template/issue_atme.rb +++ b/app/models/message_template/issue_atme.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # 在易修中@我 diff --git a/app/models/message_template/issue_changed.rb b/app/models/message_template/issue_changed.rb index e1fe764a2..6b9e79763 100644 --- a/app/models/message_template/issue_changed.rb +++ b/app/models/message_template/issue_changed.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # 我创建或负责的易修状态变更 diff --git a/app/models/message_template/issue_creator_expire.rb b/app/models/message_template/issue_creator_expire.rb index 9878f37f3..38ef2fe29 100644 --- a/app/models/message_template/issue_creator_expire.rb +++ b/app/models/message_template/issue_creator_expire.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # 我创建的易修截止日期到达最后一天 diff --git a/app/models/message_template/issue_deleted.rb b/app/models/message_template/issue_deleted.rb index 46d7d6e64..8c4145716 100644 --- a/app/models/message_template/issue_deleted.rb +++ b/app/models/message_template/issue_deleted.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # 我创建或负责的易修删除 diff --git a/app/models/message_template/issue_journal.rb b/app/models/message_template/issue_journal.rb index a24616f1d..0b3851475 100644 --- a/app/models/message_template/issue_journal.rb +++ b/app/models/message_template/issue_journal.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # TODO 我创建或负责的易修有新的评论 diff --git a/app/models/message_template/login_ip_tip.rb b/app/models/message_template/login_ip_tip.rb index f7ecc776b..5c7caa936 100644 --- a/app/models/message_template/login_ip_tip.rb +++ b/app/models/message_template/login_ip_tip.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # TODO 登录异常提示 diff --git a/app/models/message_template/organization_joined.rb b/app/models/message_template/organization_joined.rb index 918374837..9045ac424 100644 --- a/app/models/message_template/organization_joined.rb +++ b/app/models/message_template/organization_joined.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # 账号被拉入组织 @@ -24,10 +25,16 @@ class MessageTemplate::OrganizationJoined < MessageTemplate return '', '', '' end - def self.get_email_message_content(receivers, organization) - content = email.gsub('{organization}', organization&.real_name) - url = notification_url.gsub('{login}', organization&.login) - return receivers_email_string(receivers), content, url + def self.get_email_message_content(receiver, organization) + title = email_title + title.gsub!('{organization}', organization&.real_name) + content = email + content.gsub!('{receiver}', receiver&.real_name) + content.gsub!('{baseurl}', base_url) + content.gsub!('{login}', organization&.login) + content.gsub!('{organization}', organization&.real_name) + + return receiver&.mail, title, content rescue => e Rails.logger.info("MessageTemplate::OrganizationJoined.get_email_message_content [ERROR] #{e}") return '', '', '' diff --git a/app/models/message_template/organization_left.rb b/app/models/message_template/organization_left.rb index 2f63cfca0..fc6ab2306 100644 --- a/app/models/message_template/organization_left.rb +++ b/app/models/message_template/organization_left.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # 账号被移出组织 @@ -24,11 +25,16 @@ class MessageTemplate::OrganizationLeft < MessageTemplate return '', '', '' end - def self.get_email_message_content(receivers, organization) - content = email.gsub('{organization}', organization&.real_name) - url = notification_url.gsub('{login}', organization&.login) + def self.get_email_message_content(receiver, organization) + title = email_title + title.gsub!('{organization}', organization&.real_name) + content = email + content.gsub!('{receiver}', receiver&.real_name) + content.gsub!('{baseurl}', base_url) + content.gsub!('{login}', organization&.login) + content.gsub!('{organization}', organization&.real_name) - return receivers_email_string(receivers), content, url + return receiver, title, content rescue => e Rails.logger.info("MessageTemplate::OrganizationLeft.get_email_message_content [ERROR] #{e}") return '', '', '' diff --git a/app/models/message_template/organization_role.rb b/app/models/message_template/organization_role.rb index f494d5bd9..4bc96a63e 100644 --- a/app/models/message_template/organization_role.rb +++ b/app/models/message_template/organization_role.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # 账号组织权限变更 @@ -24,10 +25,18 @@ class MessageTemplate::OrganizationRole < MessageTemplate return '', '', '' end - def self.get_email_message_content(receivers, organization, role) - content = email.gsub('{organization}', organization&.real_name).gsub('{role}', role) - url = notification_url.gsub('{login}', organization&.login) - return receivers_email_string(receivers), content, url + def self.get_email_message_content(receiver, organization, role) + title = email_title + title.gsub!('{organization}', organization&.real_name) + title.gsub!('{role}', role) + content = email + content.gsub!('{receiver}', receiver&.real_name) + content.gsub!('{baseurl}', base_url) + content.gsub!('{login}', organization&.login) + content.gsub!('{organization}', organization&.real_name) + content.gsub!('{role}', role) + + return receiver&.mail, title, content rescue => e Rails.logger.info("MessageTemplate::OrganizationRole.get_email_message_content [ERROR] #{e}") return '', '', '' diff --git a/app/models/message_template/project_deleted.rb b/app/models/message_template/project_deleted.rb index 69f094526..aa45e818e 100644 --- a/app/models/message_template/project_deleted.rb +++ b/app/models/message_template/project_deleted.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # TODO 我关注的仓库被删除 diff --git a/app/models/message_template/project_followed.rb b/app/models/message_template/project_followed.rb index 07dadb7c1..e9dd9a2a8 100644 --- a/app/models/message_template/project_followed.rb +++ b/app/models/message_template/project_followed.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # TODO 我管理的仓库被关注 diff --git a/app/models/message_template/project_forked.rb b/app/models/message_template/project_forked.rb index a419bc8ff..7cd17222d 100644 --- a/app/models/message_template/project_forked.rb +++ b/app/models/message_template/project_forked.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # TODO 我管理的仓库被复刻 diff --git a/app/models/message_template/project_issue.rb b/app/models/message_template/project_issue.rb index e7126237e..8e319bf3b 100644 --- a/app/models/message_template/project_issue.rb +++ b/app/models/message_template/project_issue.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # TODO 我管理/关注的仓库有新的易修 @@ -28,14 +29,27 @@ class MessageTemplate::ProjectIssue < MessageTemplate return '', '', '' end - def self.get_email_message_content(managers, followers, operator, issue) + def self.get_email_message_content(receiver, is_manager, operator, issue) project = issue&.project owner = project&.owner - receivers = managers + followers - content = email.gsub('{nickname1}', operator&.real_name).gsub('{nickname2}', owner&.real_name).gsub('{repository}', project&.name).gsub('{title}', issue&.subject) - url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.id.to_s) + title = email_title + title.gsub!('{nickname1}', operator&.real_name) + title.gsub!('{nickname2}', owner&.real_name) + title.gsub!('{repository}', project&.name) + + content = email + content.gsub!('{receiver}', receiver&.real_name) + content.gsub!('{baseurl}', base_url) + content.gsub!('{login1}', operator&.login) + content.gsub!('{nickname1}', operator&.real_name) + content.gsub!('{nickname2}', owner&.real_name) + content.gsub!('{repository}', project&.name) + content.gsub!('{login2}', owner&.login) + content.gsub!('{identifier}', project&.identifier) + content.gsub!('{id}', issue&.id.to_s) + content.gsub!('{title}', issue&.subject) - return receivers_email_string(receivers), content, url + return receiver&.mail, title, content rescue => e Rails.logger.info("MessageTemplate::ProjectIssue.get_email_message_content [ERROR] #{e}") return '', '', '' diff --git a/app/models/message_template/project_joined.rb b/app/models/message_template/project_joined.rb index 91836a595..3ff1d23d7 100644 --- a/app/models/message_template/project_joined.rb +++ b/app/models/message_template/project_joined.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # 账号被拉入项目 @@ -24,9 +25,19 @@ class MessageTemplate::ProjectJoined < MessageTemplate return '', '', '' end - def self.get_email_message_content(receivers, project) - content = email.gsub('{repository}', project&.name) - url = notification_url.gsub('{owner}', project&.owner&.login).gsub('{identifier}', project&.identifier) + def self.get_email_message_content(receiver, project) + title = email_title + title.gsub!('{repository}', project&.name) + + content = email + content.gsub!('{receiver}', receiver&.real_name) + content.gsub!('{baseurl}', base_url) + content.gsub!('{login}', project&.owner&.login) + content.gsub!('{identifier}', project&.identifier) + content.gsub!('{nickname}', project&.owner&.real_name) + content.gsub!('{repository}', project&.name) + + return receiver&.mail, title, content rescue => e Rails.logger.info("MessageTemplate::ProjectJoined.get_email_message_content [ERROR] #{e}") return '', '', '' diff --git a/app/models/message_template/project_left.rb b/app/models/message_template/project_left.rb index dabb31d11..3244e59a0 100644 --- a/app/models/message_template/project_left.rb +++ b/app/models/message_template/project_left.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # 账号被移出项目 @@ -24,11 +25,19 @@ class MessageTemplate::ProjectLeft < MessageTemplate return '', '', '' end - def self.get_email_message_content(receivers, project) - content = email.gsub('{repository}', project&.name) - url = notification_url.gsub('{owner}', project&.owner&.login).gsub('{identifier}', project&.identifier) + def self.get_email_message_content(receiver, project) + title = email_title + title.gsub!('{repository}', project&.name) + + content = email + content.gsub!('{receiver}', receiver&.real_name) + content.gsub!('{baseurl}', base_url) + content.gsub!('{login}', project&.owner&.login) + content.gsub!('{identifier}', project&.identifier) + content.gsub!('{nickname}', project&.owner&.real_name) + content.gsub!('{repository}', project&.name) - return receivers_email_string(receivers), content, url + return receiver&.mail, title, content rescue => e Rails.logger.info("MessageTemplate::ProjectLeft.get_email_message_content [ERROR] #{e}") return '', '', '' diff --git a/app/models/message_template/project_member_joined.rb b/app/models/message_template/project_member_joined.rb index f08a99ff8..e2ab7d610 100644 --- a/app/models/message_template/project_member_joined.rb +++ b/app/models/message_template/project_member_joined.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # 我管理的仓库有成员加入 @@ -24,10 +25,23 @@ class MessageTemplate::ProjectMemberJoined < MessageTemplate return '', '', '' end - def self.get_email_message_content(receivers, user, project) - content = email.gsub('{nickname}', user&.real_name).gsub('{nickname2}', project&.owner&.real_name).gsub('{repository}', project&.name) - url = notification_url.gsub('{owner}', project&.owner&.login).gsub('{identifier}', project&.identifier) - return receivers_email_string(receivers), content, url + def self.get_email_message_content(receiver, user, project) + title = email_title + title.gsub!('{nickname1}', user&.real_name) + title.gsub!('{nickname2}', project&.owner&.real_name) + title.gsub!('{repository}', project&.name) + + content = email + content.gsub!('{receiver}', receiver&.real_name) + content.gsub!('{baseurl}', base_url) + content.gsub!('{login1}', user&.login) + content.gsub!('{login2}', project&.owner&.login) + content.gsub!('{identifier}', project&.identifier) + content.gsub!('{nickname1}', user&.real_name) + content.gsub!('{nickname2}', project&.owner&.real_name) + content.gsub!('{repository}', project&.name) + + return receiver&.mail, title, content rescue => e Rails.logger.info("MessageTemplate::ProjectMemberJoined.get_email_message_content [ERROR] #{e}") return '', '', '' diff --git a/app/models/message_template/project_member_left.rb b/app/models/message_template/project_member_left.rb index 846a496ee..a7d9911d6 100644 --- a/app/models/message_template/project_member_left.rb +++ b/app/models/message_template/project_member_left.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # 我管理的仓库有成员移出 @@ -24,10 +25,23 @@ class MessageTemplate::ProjectMemberLeft < MessageTemplate return '', '', '' end - def self.get_email_message_content(receivers, user, project) - content = email.gsub('{nickname1}', user&.real_name).gsub('{nickname2}', project&.owner&.real_name).gsub("{repository}", project&.name) - url = notification_url.gsub('{owner}', project&.owner&.login).gsub('{identifier}', project&.identifier) - return receivers_email_string(receivers), content, url + def self.get_email_message_content(receiver, user, project) + title = email_title + title.gsub!('{nickname1}', user&.real_name) + title.gsub!('{nickname2}', project&.owner&.real_name) + title.gsub!('{repository}', project&.name) + + content = email + content.gsub!('{receiver}', receiver&.real_name) + content.gsub!('{baseurl}', base_url) + content.gsub!('{login1}', user&.login) + content.gsub!('{login2}', project&.owner&.login) + content.gsub!('{identifier}', project&.identifier) + content.gsub!('{nickname1}', user&.real_name) + content.gsub!('{nickname2}', project&.owner&.real_name) + content.gsub!('{repository}', project&.name) + + return receiver&.mail, title, content rescue => e Rails.logger.info("MessageTemplate::ProjectMemberLeft.get_email_message_content [ERROR] #{e}") return '', '', '' diff --git a/app/models/message_template/project_milestone.rb b/app/models/message_template/project_milestone.rb index 79e83485f..14f992cdd 100644 --- a/app/models/message_template/project_milestone.rb +++ b/app/models/message_template/project_milestone.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # TODO 我管理的仓库有新的里程碑 diff --git a/app/models/message_template/project_praised.rb b/app/models/message_template/project_praised.rb index 1af2ce88f..e6acee6f5 100644 --- a/app/models/message_template/project_praised.rb +++ b/app/models/message_template/project_praised.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # TODO 我管理的仓库被点赞 diff --git a/app/models/message_template/project_pull_request.rb b/app/models/message_template/project_pull_request.rb index 70c0ab541..704936f54 100644 --- a/app/models/message_template/project_pull_request.rb +++ b/app/models/message_template/project_pull_request.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # TODO 我管理/关注的仓库有新的合并请求 @@ -28,14 +29,27 @@ class MessageTemplate::ProjectPullRequest < MessageTemplate return '', '', '' end - def self.get_email_message_content(managers, followers, operator, pull_request) + def self.get_email_message_content(receiver, is_manager, operator, pull_request) project = pull_request&.project owner = project&.owner - receivers = managers + followers - content = email.gsub('{nickname1}', operator&.real_name).gsub('{nickname2}', owner&.real_name).gsub('{repository}', project&.name).gsub('{title}', pull_request&.title) - url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', pull_request&.id.to_s) + title = email_title + title.gsub!('{nickname1}', operator&.real_name) + title.gsub!('{nickname2}', owner&.real_name) + title.gsub!('{repository}', project&.name) - return receivers_email_string(receivers), content, url + content = email + content.gsub!('{receiver}', receiver&.real_name) + content.gsub!('{baseurl}', base_url) + content.gsub!('{login1}', operator&.login) + content.gsub!('{nickname1}', operator&.real_name) + content.gsub!('{nickname2}', owner&.real_name) + content.gsub!('{repository}', project&.name) + content.gsub!('{login2}', owner&.login) + content.gsub!('{identifier}', project&.identifier) + content.gsub!('{id}', pull_request&.id.to_s) + content.gsub!('{title}', pull_request&.title) + + return receiver&.mail, title, content rescue => e Rails.logger.info("MessageTemplate::ProjectPullRequest.get_email_message_content [ERROR] #{e}") return '', '', '' diff --git a/app/models/message_template/project_role.rb b/app/models/message_template/project_role.rb index 459b6fd19..4db81ab47 100644 --- a/app/models/message_template/project_role.rb +++ b/app/models/message_template/project_role.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # 账号仓库权限变更 @@ -25,9 +26,18 @@ class MessageTemplate::ProjectRole < MessageTemplate end def self.get_email_message_content(receivers, project, role) - content = email.gsub('{repository}', project&.name).gsub('{role}', role) - url = notification_url.gsub('{owner}', project&.owner&.login).gsub('{identifier}', project&.identifier) - return receivers_email_string(receivers), content, url + title = email_title + title.gsub!('{repository}', project&.name) + title.gsub!('{role}', role) + content = email + content.gsub!('{receiver}', receiver&.real_name) + content.gsub!('{baseurl}', base_url) + content.gsub!('{login}', project&.owner&.login) + content.gsub!('{identifier}', project&.identifier) + content.gsub!('{repository}', project&.name) + content.gsub!('{role}', role) + + return receiver&.mail, title, content rescue => e Rails.logger.info("MessageTemplate::ProjectRole.get_email_message_content [ERROR] #{e}") return '', '', '' diff --git a/app/models/message_template/project_setting_changed.rb b/app/models/message_template/project_setting_changed.rb index 9bd11986b..3a8df5ffc 100644 --- a/app/models/message_template/project_setting_changed.rb +++ b/app/models/message_template/project_setting_changed.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # 我管理的仓库项目设置被更改 @@ -139,11 +140,22 @@ class MessageTemplate::ProjectSettingChanged < MessageTemplate return '', '', '' end - def self.get_email_message_content(receivers, operator, project, change_params) + def self.get_email_message_content(receiver, operator, project, change_params) return '', '', '' if change_params.blank? owner = project&.owner - content = email.gsub('{nickname1}', operator&.real_name).gsub('{nickname2}', owner&.real_name).gsub('{repository}', project&.name) - url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier) + title = email_title + title.gsub!('{nickname2}', owner&.real_name) + title.gsub!('{repository}', project&.name) + + content = email + content.gsub!('{receiver}', receiver&.real_name) + content.gsub!('{baseurl}', base_url) + content.gsub!('{login1}', operator&.login) + content.gsub!('{nickname1}', operator&.real_name) + content.gsub!('{login2}', owner&.login) + content.gsub!('{nickname2}', owner&.real_name) + content.gsub!('{identifier}', project&.identifier) + content.gsub!('{repository}', project&.name) change_count = change_params.keys.size # 项目名称更改 if change_params[:name].present? @@ -257,7 +269,7 @@ class MessageTemplate::ProjectSettingChanged < MessageTemplate content.gsub!(/({ifnavbar})(.*)({endnavbar})/, '') end - return receivers_email_string(receivers), content, url + return receiver&.mail, title, content rescue => e Rails.logger.info("MessageTemplate::ProjectSettingChanged.get_email_message_content [ERROR] #{e}") return '', '', '' diff --git a/app/models/message_template/project_transfer.rb b/app/models/message_template/project_transfer.rb index e931e7b1f..7a99276ba 100644 --- a/app/models/message_template/project_transfer.rb +++ b/app/models/message_template/project_transfer.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # TODO 我关注的仓库被转移 diff --git a/app/models/message_template/project_version.rb b/app/models/message_template/project_version.rb index 26067b7f4..14ae46306 100644 --- a/app/models/message_template/project_version.rb +++ b/app/models/message_template/project_version.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # TODO 我关注的仓库有新的发行版 diff --git a/app/models/message_template/pull_request_assigned.rb b/app/models/message_template/pull_request_assigned.rb index 1cd901642..54d51f3f3 100644 --- a/app/models/message_template/pull_request_assigned.rb +++ b/app/models/message_template/pull_request_assigned.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # 有新指派给我的合并请求 @@ -26,12 +27,26 @@ class MessageTemplate::PullRequestAssigned < MessageTemplate return '', '', '' end - def self.get_email_message_content(receivers, operator, pull_request) - project = pull_request&.project + def self.get_email_message_content(receiver, operator, pull_request) + project = pull_request&.project owner = project&.owner - content = email.gsub('{nickname1}', operator&.real_name).gsub('{nickname2}', owner&.real_name).gsub('{repository}', project&.name).gsub('{title}', pull_request&.title) - url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', pull_request&.id.to_s) - return receivers_email_string(receivers), content, url + title = email_title + title.gsub!('{nickname1}', operator&.real_name) + title.gsub!('{nickname2}', owner&.real_name) + title.gsub!('{repository}', project&.name) + content = email + content.gsub!('{receiver}', receiver&.real_name) + content.gsub!('{nickname1}', operator&.real_name) + content.gsub!('{login1}', operator&.login) + content.gsub!('{nickname2}', owner&.real_name) + content.gsub!('{login2}', owner&.login) + content.gsub!('{identifier}', project&.identifier) + content.gsub!('{repository}', project&.name) + content.gsub!('{baseurl}', base_url) + content.gsub!('{title}', pull_request&.title) + content.gsub!('{id}', pull_request&.id.to_s) + + return receiver&.mail, title, content rescue => e Rails.logger.info("MessageTemplate::PullRequestAssigned.get_email_message_content [ERROR] #{e}") return '', '', '' diff --git a/app/models/message_template/pull_request_atme.rb b/app/models/message_template/pull_request_atme.rb index b9764e2be..54f8c9585 100644 --- a/app/models/message_template/pull_request_atme.rb +++ b/app/models/message_template/pull_request_atme.rb @@ -2,12 +2,14 @@ # # 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 +# 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) # # 在合并请求中@我 @@ -24,4 +26,4 @@ class MessageTemplate::PullRequestAtme < MessageTemplate Rails.logger.info("MessageTemplate::PullRequestAtme.get_message_content [ERROR] #{e}") return '', '', '' end -end \ No newline at end of file +end diff --git a/app/models/message_template/pull_request_changed.rb b/app/models/message_template/pull_request_changed.rb index e7ebc6709..099607fbe 100644 --- a/app/models/message_template/pull_request_changed.rb +++ b/app/models/message_template/pull_request_changed.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # 我创建或负责的合并请求状态变更 diff --git a/app/models/message_template/pull_request_closed.rb b/app/models/message_template/pull_request_closed.rb index 6e5bfbe17..6ebb23a63 100644 --- a/app/models/message_template/pull_request_closed.rb +++ b/app/models/message_template/pull_request_closed.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # 我创建或负责的合并请求被关闭 diff --git a/app/models/message_template/pull_request_journal.rb b/app/models/message_template/pull_request_journal.rb index 9c68e64f4..9b2fae949 100644 --- a/app/models/message_template/pull_request_journal.rb +++ b/app/models/message_template/pull_request_journal.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # TODO 我创建或负责的合并请求有新的评论 diff --git a/app/models/message_template/pull_request_merged.rb b/app/models/message_template/pull_request_merged.rb index 2d229bb6b..8df4255a0 100644 --- a/app/models/message_template/pull_request_merged.rb +++ b/app/models/message_template/pull_request_merged.rb @@ -9,6 +9,7 @@ # created_at :datetime not null # updated_at :datetime not null # notification_url :string(255) +# email_title :string(255) # # 我创建或负责的合并请求被合并 diff --git a/app/services/notice/write/email_create_service.rb b/app/services/notice/write/email_create_service.rb index 0e95e86a4..070b42689 100644 --- a/app/services/notice/write/email_create_service.rb +++ b/app/services/notice/write/email_create_service.rb @@ -1,7 +1,7 @@ class Notice::Write::EmailCreateService < Notice::Write::ClientService attr_accessor :receivers, :sender, :content, :subject - def initialize(receivers, content, subject, sender=-1) + def initialize(receivers, subject, content, sender=-1) @receivers = receivers @sender = sender @content = content @@ -20,12 +20,16 @@ class Notice::Write::EmailCreateService < Notice::Write::ClientService receivers.is_a?(Array) ? receivers.join(",") : receivers end + def request_subject + "Trustie: #{subject}" + end + def request_params Hash.new.merge(data: { emails: request_receivers, sender: sender, content: content, - subject: subject + subject: request_subject }.stringify_keys) end diff --git a/app/views/admins/message_templates/_form.html.erb b/app/views/admins/message_templates/_form.html.erb index 823c4408a..d5c6b6cca 100644 --- a/app/views/admins/message_templates/_form.html.erb +++ b/app/views/admins/message_templates/_form.html.erb @@ -9,39 +9,51 @@
- <%= f.text_area :sys_notice, class:"form-control", rows: "10", cols: "20",placeholer: "站内信模版" %> + <%= f.text_area :sys_notice, class:"form-control", rows: "10", cols: "20",placeholer: "请输入站内信" %>
+
+
+ +
+ <%= f.text_field :email_title, class: "form-control input-lg", maxlength: "60", placeholder: "请输入邮件标题" %> +
+
- <%= f.text_area :email, class:"form-control", style: 'display: none;', rows: "10", cols: "20", placeholer: "请输入邮件模版" %> + <%= f.text_area :email, class:"form-control", style: 'display: none;', rows: "10", cols: "20", placeholer: "请输入邮件正文" %>
- <%= f.text_field :notification_url, class: "form-control input-lg", maxlength: "60", placeholder: "跳转地址" %> + <%= f.text_field :notification_url, class: "form-control input-lg", maxlength: "60", placeholder: "请输入站内信跳转地址" %>
diff --git a/app/views/admins/message_templates/_list.html.erb b/app/views/admins/message_templates/_list.html.erb index a5a1a7265..4082735f5 100644 --- a/app/views/admins/message_templates/_list.html.erb +++ b/app/views/admins/message_templates/_list.html.erb @@ -2,11 +2,11 @@ 序号 - 类型 + 类型 系统消息模版 - 邮件模版 + 邮件模版 通知地址 - 操作 + 操作 @@ -20,7 +20,7 @@ <%= message_template.sys_notice.to_s.truncate(200) %> - <%= message_template.email.to_s.truncate(200) %> + <%= message_template.email.to_s.truncate(100) %> <%= message_template.notification_url.to_s.truncate(200) %> diff --git a/db/migrate/20210924021337_add_email_title_to_message_templates.rb b/db/migrate/20210924021337_add_email_title_to_message_templates.rb new file mode 100644 index 000000000..33d84b243 --- /dev/null +++ b/db/migrate/20210924021337_add_email_title_to_message_templates.rb @@ -0,0 +1,5 @@ +class AddEmailTitleToMessageTemplates < ActiveRecord::Migration[5.2] + def change + add_column :message_templates, :email_title, :string + end +end diff --git a/public/message_template/issue_assigned.html b/public/message_template/issue_assigned.html new file mode 100755 index 000000000..8b78dbdaf --- /dev/null +++ b/public/message_template/issue_assigned.html @@ -0,0 +1,52 @@ + + + 有新的易修指派给我 + + + + +
+
+
+ +

确实让创新更美好

+
+
+
+

+ {receiver},您好!
+ {nickname1}在 {nickname2}/{repository} 指派给你一个易修:{title}
+

+
+ +

+ 扫一扫,关注trustie微信公众号,更方便获取平台动态,消息推送等提醒
+ 想了解更多信息,请访问 www.trustie.net +

+
+
+

如果您在使用中有任何的疑问和建议,欢迎您给我们反馈意见
+ QQ群:1071514693

+

Trustie团队

+
+
+
+
+ + \ No newline at end of file diff --git a/public/message_template/organization_joined.html b/public/message_template/organization_joined.html new file mode 100755 index 000000000..cc0c68ed2 --- /dev/null +++ b/public/message_template/organization_joined.html @@ -0,0 +1,52 @@ + + + 加入组织 + + + + +
+
+
+ +

确实让创新更美好

+
+
+
+

+ {receiver},您好!
+ 你已加入 {organization} 组织
+

+
+ +

+ 扫一扫,关注trustie微信公众号,更方便获取平台动态,消息推送等提醒
+ 想了解更多信息,请访问 www.trustie.net +

+
+
+

如果您在使用中有任何的疑问和建议,欢迎您给我们反馈意见
+ QQ群:1071514693

+

Trustie团队

+
+
+
+
+ + \ No newline at end of file diff --git a/public/message_template/organization_left.html b/public/message_template/organization_left.html new file mode 100755 index 000000000..5355129fd --- /dev/null +++ b/public/message_template/organization_left.html @@ -0,0 +1,52 @@ + + + 移出组织 + + + + +
+
+
+ +

确实让创新更美好

+
+
+
+

+ {receiver},您好!
+ 你已被移出 {organization} 组织
+

+
+ +

+ 扫一扫,关注trustie微信公众号,更方便获取平台动态,消息推送等提醒
+ 想了解更多信息,请访问 www.trustie.net +

+
+
+

如果您在使用中有任何的疑问和建议,欢迎您给我们反馈意见
+ QQ群:1071514693

+

Trustie团队

+
+
+
+
+ + \ No newline at end of file diff --git a/public/message_template/project_issue.html b/public/message_template/project_issue.html new file mode 100755 index 000000000..d9999e70c --- /dev/null +++ b/public/message_template/project_issue.html @@ -0,0 +1,52 @@ + + + 管理的仓库有新的易修 + + + + +
+
+
+ +

确实让创新更美好

+
+
+
+

+ {receiver},您好!
+ {nickname1}在 {nickname2}/{repository} 新建了一个易修:{title}
+

+
+ +

+ 扫一扫,关注trustie微信公众号,更方便获取平台动态,消息推送等提醒
+ 想了解更多信息,请访问 www.trustie.net +

+
+
+

如果您在使用中有任何的疑问和建议,欢迎您给我们反馈意见
+ QQ群:1071514693

+

Trustie团队

+
+
+
+
+ + \ No newline at end of file diff --git a/public/message_template/project_joined.html b/public/message_template/project_joined.html new file mode 100755 index 000000000..c144da01a --- /dev/null +++ b/public/message_template/project_joined.html @@ -0,0 +1,52 @@ + + + 加入项目 + + + + +
+
+
+ +

确实让创新更美好

+
+
+
+

+ {receiver},您好!
+ 你已加入 {nickname}/{repository} 项目
+

+
+ +

+ 扫一扫,关注trustie微信公众号,更方便获取平台动态,消息推送等提醒
+ 想了解更多信息,请访问 www.trustie.net +

+
+
+

如果您在使用中有任何的疑问和建议,欢迎您给我们反馈意见
+ QQ群:1071514693

+

Trustie团队

+
+
+
+
+ + \ No newline at end of file diff --git a/public/message_template/project_left.html b/public/message_template/project_left.html new file mode 100755 index 000000000..5a87e8ba4 --- /dev/null +++ b/public/message_template/project_left.html @@ -0,0 +1,52 @@ + + + 移出项目 + + + + +
+
+
+ +

确实让创新更美好

+
+
+
+

+ {receiver},您好!
+ 你已被移出 {nickname}/{repository} 项目
+

+
+ +

+ 扫一扫,关注trustie微信公众号,更方便获取平台动态,消息推送等提醒
+ 想了解更多信息,请访问 www.trustie.net +

+
+
+

如果您在使用中有任何的疑问和建议,欢迎您给我们反馈意见
+ QQ群:1071514693

+

Trustie团队

+
+
+
+
+ + \ No newline at end of file diff --git a/public/message_template/project_member_joined.html b/public/message_template/project_member_joined.html new file mode 100755 index 000000000..9f376d4f3 --- /dev/null +++ b/public/message_template/project_member_joined.html @@ -0,0 +1,52 @@ + + + 管理的仓库有成员变更 + + + + +
+
+
+ +

确实让创新更美好

+
+
+
+

+ {receiver},您好!
+ {nickname1} 已加入项目 {nickname2}/{repository}
+

+
+ +

+ 扫一扫,关注trustie微信公众号,更方便获取平台动态,消息推送等提醒
+ 想了解更多信息,请访问 www.trustie.net +

+
+
+

如果您在使用中有任何的疑问和建议,欢迎您给我们反馈意见
+ QQ群:1071514693

+

Trustie团队

+
+
+
+
+ + \ No newline at end of file diff --git a/public/message_template/project_member_left.html b/public/message_template/project_member_left.html new file mode 100755 index 000000000..f1c6b6d95 --- /dev/null +++ b/public/message_template/project_member_left.html @@ -0,0 +1,52 @@ + + + 管理的仓库有成员变更 + + + + +
+
+
+ +

确实让创新更美好

+
+
+
+

+ {receiver},您好!
+ {nickname1} 已被移出项目 {nickname2}/{repository}
+

+
+ +

+ 扫一扫,关注trustie微信公众号,更方便获取平台动态,消息推送等提醒
+ 想了解更多信息,请访问 www.trustie.net +

+
+
+

如果您在使用中有任何的疑问和建议,欢迎您给我们反馈意见
+ QQ群:1071514693

+

Trustie团队

+
+
+
+
+ + \ No newline at end of file diff --git a/public/message_template/project_pull_request.html b/public/message_template/project_pull_request.html new file mode 100755 index 000000000..0f75e0b8c --- /dev/null +++ b/public/message_template/project_pull_request.html @@ -0,0 +1,52 @@ + + + 管理的仓库有新的合并请求 + + + + +
+
+
+ +

确实让创新更美好

+
+
+
+

+ {receiver},您好!
+ {nickname1}在 {nickname2}/{repository} 提交了一个合并请求:{title}
+

+
+ +

+ 扫一扫,关注trustie微信公众号,更方便获取平台动态,消息推送等提醒
+ 想了解更多信息,请访问 www.trustie.net +

+
+
+

如果您在使用中有任何的疑问和建议,欢迎您给我们反馈意见
+ QQ群:1071514693

+

Trustie团队

+
+
+
+
+ + \ No newline at end of file diff --git a/public/message_template/project_setting_changed.html b/public/message_template/project_setting_changed.html new file mode 100755 index 000000000..ca51e262c --- /dev/null +++ b/public/message_template/project_setting_changed.html @@ -0,0 +1,58 @@ + + + 管理的仓库设置被更改 + + + + +
+
+
+ +

确实让创新更美好

+
+
+
+

+ {receiver},您好!
+ {nickname1} 更改 {nickname2}/{repository} 的仓库设置: + {ifname}更改项目名称为"{name}"{endname} + {ifdescription}更改项目简介为"{description}"{enddescription} + {ifcategory}更改项目类别为"{category}"{endcategory} + {iflanguage}更改项目语言为"{language}"{endlanguage} + {ifpermission}将仓库设为"{permission}"{endpermission} + {ifnavbar}将项目导航更改为"{navbar}"{endnavbar} +

+
+ +

+ 扫一扫,关注trustie微信公众号,更方便获取平台动态,消息推送等提醒
+ 想了解更多信息,请访问 www.trustie.net +

+
+
+

如果您在使用中有任何的疑问和建议,欢迎您给我们反馈意见
+ QQ群:1071514693

+

Trustie团队

+
+
+
+
+ + \ No newline at end of file diff --git a/public/message_template/pull_request_assigned.html b/public/message_template/pull_request_assigned.html new file mode 100755 index 000000000..3898336e4 --- /dev/null +++ b/public/message_template/pull_request_assigned.html @@ -0,0 +1,52 @@ + + + 有新的合并请求指派给我 + + + + +
+
+
+ +

确实让创新更美好

+
+
+
+

+ {receiver},您好!
+ {nickname1}在 {nickname2}/{repository} 指派给你一个合并请求:{title}
+

+
+ +

+ 扫一扫,关注trustie微信公众号,更方便获取平台动态,消息推送等提醒
+ 想了解更多信息,请访问 www.trustie.net +

+
+
+

如果您在使用中有任何的疑问和建议,欢迎您给我们反馈意见
+ QQ群:1071514693

+

Trustie团队

+
+
+
+
+ + \ No newline at end of file