diff --git a/app/controllers/claims_controller.rb b/app/controllers/claims_controller.rb
index d9959bafd..9132f823f 100644
--- a/app/controllers/claims_controller.rb
+++ b/app/controllers/claims_controller.rb
@@ -39,6 +39,7 @@ class ClaimsController < ApplicationController
journal = Journal.new(journal_params)
if journal.save
+ SendTemplateMessageJob.perform_later('IssueClaim', current_user.id, @issue&.id)
render file: 'app/views/claims/list.json.jbuilder'
else
normal_status(-1,"新建声明关联评论操作失败")
diff --git a/app/jobs/send_template_message_job.rb b/app/jobs/send_template_message_job.rb
index c40a3c9bd..da289857e 100644
--- a/app/jobs/send_template_message_job.rb
+++ b/app/jobs/send_template_message_job.rb
@@ -56,13 +56,21 @@ class SendTemplateMessageJob < ApplicationJob
operator = User.find_by_id(operator_id)
issue = Issue.find_by_id(issue_id)
return unless operator.present? && issue.present?
- receivers = User.where(id: issue.assigners.pluck(:id).append(issue&.author_id)).where.not(id: operator&.id)
+ receivers = User.where(id: (issue.assigners.pluck(:id).append(issue&.author_id) + issue.claim_users.pluck(:id)).uniq).where.not(id: operator&.id)
receivers_string, content, notification_url = MessageTemplate::IssueChanged.get_message_content(receivers, operator, issue, change_params.symbolize_keys)
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, issue_id: issue.id, change_params: change_params.symbolize_keys})
receivers.find_each do |receiver|
receivers_email_string, email_title, email_content = MessageTemplate::IssueChanged.get_email_message_content(receiver, operator, issue, change_params)
Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content)
end
+ when 'IssueClaim'
+ 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?
+ receivers = User.where(id: issue.author_id).where.not(id: operator&.id)
+ receivers_string, content, notification_url = MessageTemplate::IssueClaim.get_message_content(receivers, operator, issue)
+ Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, issue_id: issue.id})
when 'IssueExpire'
issue_id = args[0]
issue = Issue.find_by_id(issue_id)
diff --git a/app/models/claim.rb b/app/models/claim.rb
index 963b5f55a..25f333e3e 100644
--- a/app/models/claim.rb
+++ b/app/models/claim.rb
@@ -17,5 +17,6 @@
class Claim < ApplicationRecord
belongs_to :user, foreign_key: :user_id
+ belongs_to :issue
scope :claim_includes, ->{includes(:user)}
end
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 9c61f3ec3..0d38f7a2a 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -65,6 +65,7 @@ class Issue < ApplicationRecord
has_many :journals, :as => :journalized, :dependent => :destroy
has_many :journal_details, through: :journals
has_many :claims, :dependent => :destroy
+ has_many :claim_users, through: :claims, source: :user
has_many :issue_tags_relates, dependent: :destroy
has_many :issue_tags, through: :issue_tags_relates
has_many :issue_times, dependent: :destroy
diff --git a/app/models/message_template.rb b/app/models/message_template.rb
index 200c2f676..7ab7fdad8 100644
--- a/app/models/message_template.rb
+++ b/app/models/message_template.rb
@@ -24,6 +24,7 @@ class MessageTemplate < ApplicationRecord
self.create(type: 'MessageTemplate::IssueAtme', sys_notice: '{nickname} 在疑修 {title} 中@我', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}')
email_html = File.read("#{email_template_html_dir}/issue_changed.html")
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}', email: email_html, email_title: "#{PLATFORM}: 疑修 {title} 有状态变更", notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}')
+ self.create(type: 'MessageTemplate::IssueClaim', sys_notice: '在 {nickname2}/{repository} 的疑修 {title} 中, {nickname1} 新建了一条声明', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}')
email_html = File.read("#{email_template_html_dir}/issue_expire.html")
self.create(type: 'MessageTemplate::IssueExpire', sys_notice: '疑修 {title} 已临近截止日期,请尽快处理', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}', email: email_html, email_title: "#{PLATFORM}: 疑修截止日期到达最后一天")
email_html = File.read("#{email_template_html_dir}/issue_deleted.html")
diff --git a/app/models/message_template/issue_claim.rb b/app/models/message_template/issue_claim.rb
new file mode 100644
index 000000000..0a7b6e4e0
--- /dev/null
+++ b/app/models/message_template/issue_claim.rb
@@ -0,0 +1,31 @@
+# == 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::IssueClaim < MessageTemplate
+
+ # MessageTemplate::IssueAtme.get_message_content(User.where(login: 'yystopf'), User.last, Issue.last)
+ def self.get_message_content(receivers, operator, issue)
+ return '', '', '' if receivers.blank?
+ project = issue&.project
+ owner = project&.owner
+ content = sys_notice.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&.project_issues_index.to_s)
+
+ return receivers_string(receivers), content, url
+ rescue => e
+ Rails.logger.info("MessageTemplate::IssueClaim.get_message_content [ERROR] #{e}")
+ return 0, '', ''
+ end
+end