From 1a374468eaa1c4fa6c0558fc175bc929bbd625a5 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 21 Aug 2024 17:23:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/pm/issue_links_controller.rb | 2 +- app/models/journal.rb | 108 +++++++++--------- app/services/api/pm/issues/update_service.rb | 10 +- 3 files changed, 60 insertions(+), 60 deletions(-) diff --git a/app/controllers/api/pm/issue_links_controller.rb b/app/controllers/api/pm/issue_links_controller.rb index 370e61d13..867dcaf41 100644 --- a/app/controllers/api/pm/issue_links_controller.rb +++ b/app/controllers/api/pm/issue_links_controller.rb @@ -12,7 +12,7 @@ class Api::Pm::IssueLinksController < Api::Pm::BaseController @issue.pm_links.find_or_create_by!(be_linkable_type: 'Issue', be_linkable_id: e) tag_issue = Issue.find_by_id(e) next unless tag_issue.present? - journal = tag_issue.journals.create!({user_id: current_id.id}) + journal = tag_issue.journals.create!({user_id: current_user.id}) journal.journal_details.create!({property: "tag_link_issue", prop_key: "1", value: @issue.id.to_s}) end journal = @issue.journals.create!({user_id: current_user.id}) diff --git a/app/models/journal.rb b/app/models/journal.rb index d387366aa..4a78ed301 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -84,10 +84,10 @@ class Journal < ApplicationRecord def pm_operate_category detail = self.journal_details.take - if (detail.property == "requirement" || detail.property == "task" || detail.property == "bug") && detail.prop_key.to_s == "1" + if %w(requirement task bug).include?(detail.property) && detail.prop_key.to_s == "1" return "issue" else - return detail.property == "attr" ? detail.prop_key : detail.property + return %w(requirement task bug attr).include?(detail.property) ? detail.prop_key : detail.property end end @@ -101,10 +101,10 @@ class Journal < ApplicationRecord old_value = IssueStatus.find_by_id(detail.old_value)&.name new_value = IssueStatus.find_by_id(detail.value)&.name content += "将状态" - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "设置为#{new_value}" else - new_value = "未设置" if new_value.blank? + new_value = "未设置" if detail.value.blank? content += "由#{old_value}更改为#{new_value}" end content.gsub!('新增', '待评审') @@ -116,10 +116,10 @@ class Journal < ApplicationRecord when 'root_id' old_value = "#{Issue.find_by_id(detail.old_value)&.subject}" new_value = "#{Issue.find_by_id(detail.value)&.subject}" - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "关联了父需求<#{new_value}>" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "取消了关联的父需求<#{old_value}>" else content += "将关联的父需求由<#{old_value}>更改为<#{new_value}>" @@ -129,10 +129,10 @@ class Journal < ApplicationRecord when 'leaf_issue' old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "新建了子需求#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "删除了关联的子需求#{old_value}" else content += "新建了子需求#{new_value}" @@ -142,10 +142,10 @@ class Journal < ApplicationRecord when 'tag_leaf_issue' old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "关联了子需求#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "取消了关联的子需求#{old_value}" else content += "关联了子需求#{new_value}" @@ -161,10 +161,10 @@ class Journal < ApplicationRecord old_value = IssueStatus.find_by_id(detail.old_value)&.name new_value = IssueStatus.find_by_id(detail.value)&.name content += "将状态" - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "设置为#{new_value}" else - new_value = "未设置" if new_value.blank? + new_value = "未设置" if detail.value.blank? content += "由#{old_value}更改为#{new_value}" end content.gsub!('新增', '待处理') @@ -176,10 +176,10 @@ class Journal < ApplicationRecord when 'root_id' old_value = "#{Issue.find_by_id(detail.old_value)&.subject}" new_value = "#{Issue.find_by_id(detail.value)&.subject}" - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "关联了父任务<#{new_value}>" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "取消了关联的父任务<#{old_value}>" else content += "将关联的父任务由<#{old_value}>更改为<#{new_value}>" @@ -189,10 +189,10 @@ class Journal < ApplicationRecord when 'leaf_issue' old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "新建了子任务#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "删除了关联的子任务#{old_value}" else content += "新建了子任务#{new_value}" @@ -202,10 +202,10 @@ class Journal < ApplicationRecord when 'tag_leaf_issue' old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "关联了子任务#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "取消了关联的子任务#{old_value}" else content += "关联了子任务#{new_value}" @@ -221,10 +221,10 @@ class Journal < ApplicationRecord old_value = IssueStatus.find_by_id(detail.old_value)&.name new_value = IssueStatus.find_by_id(detail.value)&.name content += "将状态" - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "设置为#{new_value}" else - new_value = "未设置" if new_value.blank? + new_value = "未设置" if detail.value.blank? content += "由#{old_value}更改为#{new_value}" end content.gsub!('新增', '待修复') @@ -236,10 +236,10 @@ class Journal < ApplicationRecord when 'root_id' old_value = "#{Issue.find_by_id(detail.old_value)&.subject}" new_value = "#{Issue.find_by_id(detail.value)&.subject}" - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "关联了父缺陷<#{new_value}>" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "取消了关联的父缺陷<#{old_value}>" else content += "将关联的父缺陷由<#{old_value}>更改为<#{new_value}>" @@ -249,10 +249,10 @@ class Journal < ApplicationRecord when 'leaf_issue' old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "新建了子缺陷#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "删除了关联的子缺陷#{old_value}" else content += "新建了子缺陷#{new_value}" @@ -262,10 +262,10 @@ class Journal < ApplicationRecord when 'tag_leaf_issue' old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "关联了子缺陷#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "取消了关联的子缺陷#{old_value}" else content += "关联了子缺陷#{new_value}" @@ -284,20 +284,20 @@ class Journal < ApplicationRecord when 'priority_id' old_value = IssuePriority.find_by_id(detail.old_value)&.name new_value = IssuePriority.find_by_id(detail.value)&.name - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "将优先级设置为#{new_value}" else - new_value = "未设置" if new_value.blank? + new_value = "未设置" if detail.value.blank? content += "将优先级由#{old_value}更改为#{new_value}" end return content when 'status_id' old_value = IssueStatus.find_by_id(detail.old_value)&.name new_value = IssueStatus.find_by_id(detail.value)&.name - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "将状态设置为#{new_value}" else - new_value = "未设置" if new_value.blank? + new_value = "未设置" if detail.value.blank? content += "将状态由#{old_value}更改为#{new_value}" end case self.issue.pm_issue_type.to_i @@ -324,10 +324,10 @@ class Journal < ApplicationRecord when 'pm_issue_type' old_value = detail.old_value new_value = detail.value - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "将工作项类型设置为#{new_value}" else - new_value = "未设置" if new_value.blank? + new_value = "未设置" if detail.value.blank? content += "将工作项类型由#{old_value}更改为#{new_value}" end content.gsub!('1', '需求') @@ -337,10 +337,10 @@ class Journal < ApplicationRecord when 'pm_sprint_id' old_value = detail.old_value new_value = detail.value - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "添加了关联迭代" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "将关联迭代更改为未设置" else content += "变更了关联迭代" @@ -350,10 +350,10 @@ class Journal < ApplicationRecord when 'project_id' old_value = Project.find_by_id(detail.old_value)&.name new_value = Project.find_by_id(detail.value)&.name - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "添加关联代码库#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "将关联代码库更改为未设置" else content += "将关联代码库由#{old_value}改为#{new_value}" @@ -363,10 +363,10 @@ class Journal < ApplicationRecord when 'branch_name' old_value = detail.old_value new_value = detail.value - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "添加关联分支#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "将关联分支更改为未设置" else content += "将关联分支由#{old_value}改为#{new_value}" @@ -377,10 +377,10 @@ class Journal < ApplicationRecord when 'start_date' old_value = detail.old_value new_value = detail.value - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "添加开始时间#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "将开始时间更改为未设置" else content += "将开始时间由#{old_value}改为#{new_value}" @@ -391,10 +391,10 @@ class Journal < ApplicationRecord when 'due_date' old_value = detail.old_value new_value = detail.value - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "添加结束时间#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "将结束时间更改为未设置" else content += "将结束时间由#{old_value}改为#{new_value}" @@ -404,10 +404,10 @@ class Journal < ApplicationRecord when 'time_scale' old_value = detail.old_value new_value = detail.value - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "添加预估工时#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "将预估工时更改为未设置" else content += "将预估工时由#{old_value}改为#{new_value}" @@ -418,10 +418,10 @@ class Journal < ApplicationRecord when 'attachment' old_value = detail.old_value.to_s new_value = detail.value.to_s - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "上传了附件" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "删除了附件" else content += "上传了附件" @@ -431,10 +431,10 @@ class Journal < ApplicationRecord when 'assigner' 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? + if detail.old_value.nil? || detail.old_value.blank? content += "添加负责人#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "将负责人更改为未设置" else content += "将负责人由#{old_value}更改为#{new_value}" @@ -444,10 +444,10 @@ class Journal < ApplicationRecord when 'issue_tag' old_value = IssueTag.where(id: detail.old_value.split(",")).map{|t| "#{t.name}"}.join("、") new_value = IssueTag.where(id: detail.value.split(",")).map{|t| "#{t.name}"}.join("、") - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "添加标记#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "将标记更改为未设置" else content += "将标记由#{old_value}更改为#{new_value}" @@ -457,10 +457,10 @@ class Journal < ApplicationRecord when 'link_issue' old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "新建了关联的工作项#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "删除了关联的工作项#{old_value}" else content += "新建了关联的工作项#{new_value}" @@ -473,10 +473,10 @@ class Journal < ApplicationRecord when 'tag_link_issue' old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "关联了工作项#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "取消了关联的工作项#{old_value}" else content += "关联了工作项#{new_value}" diff --git a/app/services/api/pm/issues/update_service.rb b/app/services/api/pm/issues/update_service.rb index 7196a497e..78d62fb2b 100644 --- a/app/services/api/pm/issues/update_service.rb +++ b/app/services/api/pm/issues/update_service.rb @@ -262,13 +262,13 @@ class Api::Pm::Issues::UpdateService < ApplicationService before_parent_issue = Issue.find_by_id(@updated_issue.previous_changes["root_id"][0]) if before_parent_issue.present? journal = before_parent_issue.journals.create!({user_id: current_user.id}) - journal.journal_details.create!({property: @updated_issue.pm_issue_type_string, prop_key: "tag_leaf_issue", old_value: @updated_issue.previous_changes["root_id"][0]}) + journal.journal_details.create!({property: @updated_issue.pm_issue_type_string, prop_key: "tag_leaf_issue", old_value: @updated_issue.id.to_s}) end after_parent_issue = Issue.find_by_id(@updated_issue.previous_changes["root_id"][1]) if after_parent_issue.present? journal = after_parent_issue.journals.create!({user_id: current_user.id}) - journal.journal_details.create!({property: @updated_issue.pm_issue_type_string, prop_key: "tag_leaf_issue", value: @updated_issue.previous_changes["root_id"][1]}) + journal.journal_details.create!({property: @updated_issue.pm_issue_type_string, prop_key: "tag_leaf_issue", value: @updated_issue.id.to_s}) end end rescue @@ -282,7 +282,7 @@ class Api::Pm::Issues::UpdateService < ApplicationService new_assigner_ids = @assigner_ids new_assigner_ids = [] if @assigner_ids.nil? now_assigner_ids = @updated_issue.assigners.pluck(:id) - if !(now_assigner_ids & assigner_ids).empty? || !(now_assigner_ids.empty? && new_assigner_ids.empty?) + if !(now_assigner_ids.sort == new_assigner_ids.sort) journal = @updated_issue.journals.create!({user_id: current_user.id}) journal.journal_details.create!({property: "assigner", prop_key: "#{new_assigner_ids.size}", old_value: now_assigner_ids.join(","), value: new_assigner_ids.join(",")}) end @@ -298,7 +298,7 @@ class Api::Pm::Issues::UpdateService < ApplicationService new_issue_tag_ids = @issue_tag_ids new_issue_tag_ids = [] if @issue_tag_ids.nil? now_issue_tag_ids = @updated_issue.issue_tags.pluck(:id) - if !(now_issue_tag_ids & new_issue_tag_ids).empty? || !(now_issue_tag_ids.empty? && new_issue_tag_ids.empty?) + if !(now_issue_tag_ids.sort == new_issue_tag_ids.sort) journal = @updated_issue.journals.create!({user_id: current_user.id}) journal.journal_details.create!({property: "issue_tag", prop_key: "#{new_issue_tag_ids.size}", old_value: now_issue_tag_ids.join(","), value: new_issue_tag_ids.join(",")}) end @@ -314,7 +314,7 @@ class Api::Pm::Issues::UpdateService < ApplicationService new_attachment_ids = @attachment_ids new_attachment_ids = [] if @attachment_ids.nil? now_attachment_ids = @updated_issue.attachments.pluck(:id) - if !(now_attachment_ids & new_attachment_ids).empty? || !(now_attachment_ids.empty? && new_attachment_ids.empty?) + if !(now_attachment_ids.sort == new_attachment_ids.sort) journal = @updated_issue.journals.create!({user_id: current_user.id}) journal.journal_details.create!({property: "attachment", prop_key: "#{new_attachment_ids.size}", old_value: now_attachment_ids.join(","), value: new_attachment_ids.join(",")}) end