From 80b42f56d5a8671872d94e40f27ed4f55d0ef175 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 10 Mar 2023 18:01:53 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E8=80=85=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/repositories/_contributor.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/repositories/_contributor.json.jbuilder b/app/views/repositories/_contributor.json.jbuilder index d2caa53cd..bd1a037f7 100644 --- a/app/views/repositories/_contributor.json.jbuilder +++ b/app/views/repositories/_contributor.json.jbuilder @@ -14,5 +14,5 @@ else json.name user["name"] json.image_url user["avatar_url"] db_user = User.find_by_id(user["id"]) - json.contribution_perc db_user.contribution_perc(project) + json.contribution_perc db_user.contribution_perc(project) if db_user.present? end From 9c5d1e29007448c81ec2a6ed10de39a34ed94013 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 10 Mar 2023 18:09:17 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E6=97=A5=E5=BF=97=E5=85=BC=E5=AE=B9=E6=97=A7=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=B4=9F=E8=B4=A3=E4=BA=BA=E6=8C=87=E6=B4=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/journal.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/journal.rb b/app/models/journal.rb index a789f28cd..74b26b26e 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -121,6 +121,10 @@ class Journal < ApplicationRecord old_value = detail.old_value new_value = detail.value content += "结束日期" + when 'assigned_to_id' + old_value = User.find_by_id(detail.old_value)&.nickname + new_value = User.find_by_id(detail.value)&.nickname + content += "负责人" end if old_value.nil? || old_value.blank? content += "设置为#{new_value}" From 2b63d48ecb8404b1604cc8b3b4fa976e99a97276 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 13 Mar 2023 14:36:32 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=A3=B0?= =?UTF-8?q?=E6=98=8E=E6=84=9F=E7=9F=A5=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/claims_controller.rb | 1 + app/jobs/send_template_message_job.rb | 10 ++++++- app/models/claim.rb | 1 + app/models/issue.rb | 1 + app/models/message_template.rb | 1 + app/models/message_template/issue_claim.rb | 31 ++++++++++++++++++++++ 6 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 app/models/message_template/issue_claim.rb 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 From b33c0408747997cf212f048b1f97701c83b9f3a6 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 13 Mar 2023 14:41:54 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E6=A0=87?= =?UTF-8?q?=E8=AE=B0=E9=BB=98=E8=AE=A4=E6=96=87=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/issue_tag.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/issue_tag.rb b/app/models/issue_tag.rb index c6b6af8aa..ad6a82763 100644 --- a/app/models/issue_tag.rb +++ b/app/models/issue_tag.rb @@ -30,9 +30,9 @@ class IssueTag < ApplicationRecord def self.init_data(project_id) data = [ - ["缺陷", "表示项目存在问题", "#d92d4c"], + ["缺陷", "表示存在意外问题或错误", "#d92d4c"], ["功能", "表示新功能申请", "#ee955a"], - ["疑问", "表示存在的问题", "#2d6ddc"], + ["疑问", "表示存在疑惑", "#2d6ddc"], ["支持", "表示特定功能或特定需求", "#019549"], ["任务", "表示需要分配的任务", "#c1a30d"], ["协助", "表示需要社区用户协助", "#2a0dc1"], From d3f10d0814c4e8d49909bd861be15c2a3c3b6f77 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 13 Mar 2023 15:37:45 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E7=96=91?= =?UTF-8?q?=E4=BF=AE=E5=88=9B=E5=BB=BA=E6=97=B6=E9=97=B4=E8=8C=83=E5=9B=B4?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/issues_controller.rb | 1 + app/services/api/v1/issues/list_service.rb | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/app/controllers/api/v1/issues_controller.rb b/app/controllers/api/v1/issues_controller.rb index 6f615e498..433432048 100644 --- a/app/controllers/api/v1/issues_controller.rb +++ b/app/controllers/api/v1/issues_controller.rb @@ -91,6 +91,7 @@ class Api::V1::IssuesController < Api::V1::BaseController :keyword, :author_id, :milestone_id, :assigner_id, :status_id, + :begin_date, :end_date, :sort_by, :sort_direction, :issue_tag_ids) end diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index fa27f4ee4..0aeca052d 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -2,6 +2,7 @@ class Api::V1::Issues::ListService < ApplicationService include ActiveModel::Model attr_reader :project, :category, :participant_category, :keyword, :author_id, :issue_tag_ids + attr_reader :begin_date, :end_date attr_reader :milestone_id, :assigner_id, :status_id, :sort_by, :sort_direction, :current_user attr_accessor :queried_issues, :total_issues_count, :closed_issues_count, :opened_issues_count @@ -21,6 +22,8 @@ class Api::V1::Issues::ListService < ApplicationService @milestone_id = params[:milestone_id] @assigner_id = params[:assigner_id] @status_id = params[:status_id] + @begin_date = params[:begin_date] + @end_date = params[:end_date] @sort_by = params[:sort_by].present? ? params[:sort_by] : 'issues.updated_on' @sort_direction = (params[:sort_direction].present? ? params[:sort_direction] : 'desc').downcase @current_user = current_user @@ -67,6 +70,10 @@ class Api::V1::Issues::ListService < ApplicationService # status_id issues = issues.where(status_id: status_id) if status_id.present? + if begin_date&.present? || end_date&.present? + issues = issues.where("issues.created_on between ? and ?",begin_date&.present? ? begin_date.to_date : Time.now.to_date, end_date&.present? ? end_date.to_date : Time.now.to_date) + end + # keyword issues = issues.ransack(subject_or_description_cont: keyword).result if keyword.present? From 4318293c1f2bb372dba2adf7d328c0e0bd870ecc Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 14 Mar 2023 13:52:46 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E8=8C=83=E5=9B=B4=E9=9C=80=E5=8C=85=E6=8B=AC=E4=B8=B4?= =?UTF-8?q?=E7=95=8C=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/issues/list_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index 0aeca052d..9804d63c2 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -71,7 +71,7 @@ class Api::V1::Issues::ListService < ApplicationService issues = issues.where(status_id: status_id) if status_id.present? if begin_date&.present? || end_date&.present? - issues = issues.where("issues.created_on between ? and ?",begin_date&.present? ? begin_date.to_date : Time.now.to_date, end_date&.present? ? end_date.to_date : Time.now.to_date) + issues = issues.where("issues.created_on between ? and ?", begin_date&.present? ? begin_date.to_time : Time.now.beginning_of_day, end_date&.present? ? end_date.to_time.end_of_day : Time.now.end_of_day) end # keyword From fca06c9816a824027e6db9b5aab0ab8aa08d6c09 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 14 Mar 2023 14:02:39 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E6=97=A5=E5=BF=97=E7=94=A8=E6=88=B7=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E4=B8=BAreal=5Fname?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/journal.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/journal.rb b/app/models/journal.rb index 74b26b26e..5f56b6f78 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -82,8 +82,8 @@ class Journal < ApplicationRecord content += "将标记由#{old_value}更改为#{new_value}" end when 'assigner' - old_value = User.where(id: detail.old_value.split(",")).pluck(:nickname).join("、") - new_value = User.where(id: detail.value.split(",")).pluck(:nickname).join("、") + old_value = User.where(id: detail.old_value.split(",")).map{|u| u.real_name}.join("、") + new_value = User.where(id: detail.value.split(",")).map{|u| u.real_name}.join("、") if old_value.nil? || old_value.blank? content += "添加负责人#{new_value}" else @@ -122,8 +122,8 @@ class Journal < ApplicationRecord new_value = detail.value content += "结束日期" when 'assigned_to_id' - old_value = User.find_by_id(detail.old_value)&.nickname - new_value = User.find_by_id(detail.value)&.nickname + old_value = User.find_by_id(detail.old_value)&.real_name + new_value = User.find_by_id(detail.value)&.real_name content += "负责人" end if old_value.nil? || old_value.blank? From 91f2fab851c1be25ebb4310f35a050a8ee3b1675 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 14 Mar 2023 15:23:31 +0800 Subject: [PATCH 08/10] =?UTF-8?q?fixed=20bot=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index 3379af47c..d299f6710 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -37,7 +37,7 @@ class InstallationsController < ApplicationController # 注册bot对应oauth应用 Doorkeeper::Application.create!(name: @bot.name, uid: @bot.client_id, secret: @bot.client_secret, redirect_uri: "https://gitlink.org.cn") # 注册bot对应用户 - result = autologin_register(User.generate_user_login('b'), nil, "#{SecureRandom.hex(6)}", 'bot', nil, nickname: @bot.name) + result = autologin_register(User.generate_user_login('b'), nil, "#{SecureRandom.hex(6)}", 'bot', nil, @bot.name) tip_exception(-1, result[:message]) if result[:message].present? @bot.uid = result[:user][:id] @bot.save From 7bda0fd126c0d875e41c73611d205f754c5543ea Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 15 Mar 2023 10:30:02 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=A3=B0?= =?UTF-8?q?=E6=98=8E=E6=B6=88=E6=81=AF=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/send_template_message_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/send_template_message_job.rb b/app/jobs/send_template_message_job.rb index da289857e..05572d451 100644 --- a/app/jobs/send_template_message_job.rb +++ b/app/jobs/send_template_message_job.rb @@ -68,7 +68,7 @@ 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.author_id).where.not(id: operator&.id) + receivers = User.where(id: issue.claim_users.pluck(:id).append(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' From 5207d901742fe5c1dc9e688957ca6b8416f11964 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 16 Mar 2023 09:42:12 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E7=96=91=E4=BF=AE=E5=BA=8F=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/api/v1/issues/index.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/api/v1/issues/index.json.jbuilder b/app/views/api/v1/issues/index.json.jbuilder index 39a467dd4..cde117fdc 100644 --- a/app/views/api/v1/issues/index.json.jbuilder +++ b/app/views/api/v1/issues/index.json.jbuilder @@ -5,7 +5,7 @@ json.total_count @issues.total_count json.has_created_issues @project.issues.size > 0 json.issues @issues.each do |issue| if params[:only_name].present? - json.(issue, :id, :subject) + json.(issue, :id, :subject, :project_issues_index) else json.partial! "simple_detail", locals: {issue: issue} end