| @@ -26,11 +26,15 @@ class CommitLogsController < ApplicationController | |||||
| # 统计数据新增 | # 统计数据新增 | ||||
| CacheAsyncSetJob.perform_later("project_common_service", {commits: 1}, project.id) | CacheAsyncSetJob.perform_later("project_common_service", {commits: 1}, project.id) | ||||
| commit_user = User.find_by(mail: commit[:committer][:email]) rescue nil | |||||
| commit_user = User.find_by(login: commit[:committer][:name]) if commit_user.blank? rescue nil | |||||
| next if commit_user.blank? | |||||
| # 触发变更issue状态的job | # 触发变更issue状态的job | ||||
| close_issue_content = message.to_s.scan(/\b(Close|Closes|Closed|Closing|close|closes|closed|closing)\s*(#\d+(,\s*#\d+)*)?\b/) | close_issue_content = message.to_s.scan(/\b(Close|Closes|Closed|Closing|close|closes|closed|closing)\s*(#\d+(,\s*#\d+)*)?\b/) | ||||
| ChangeIssueStatusByMessageJob.perform_later(project, user, close_issue_content[0][1], 5) if close_issue_content[0].present? && close_issue_content[0][1].present? | |||||
| ChangeIssueStatusByMessageJob.perform_later(commit_id, project, commit_user, close_issue_content[0][1], 5) if close_issue_content[0].present? && close_issue_content[0][1].present? | |||||
| solve_issue_content = message.to_s.scan(/\b(Fix|Fixes|Fixed|Fixing|fix|fixes|fixed|fixing|Resolve|Resolves|Resolved|Resolving|resolve|resolves|resolved|resolving|Implement|Implements|Implemented|Implementing|implement|implements|implemented|implementing)\s*(#\d+(,\s*#\d+)*)?\b/) | solve_issue_content = message.to_s.scan(/\b(Fix|Fixes|Fixed|Fixing|fix|fixes|fixed|fixing|Resolve|Resolves|Resolved|Resolving|resolve|resolves|resolved|resolving|Implement|Implements|Implemented|Implementing|implement|implements|implemented|implementing)\s*(#\d+(,\s*#\d+)*)?\b/) | ||||
| ChangeIssueStatusByMessageJob.perform_later(project, user, solve_issue_content[0][1], 3) if solve_issue_content[0].present? && solve_issue_content[0][1].present? | |||||
| ChangeIssueStatusByMessageJob.perform_later(commit_id, project, commit_user, solve_issue_content[0][1], 3) if solve_issue_content[0].present? && solve_issue_content[0][1].present? | |||||
| end | end | ||||
| end | end | ||||
| @@ -7,20 +7,20 @@ class ChangeIssueStatusByMessageJob < ApplicationJob | |||||
| # Implement, Implements, Implemented, Implementing, implement, implements, implemented, implementing | # Implement, Implements, Implemented, Implementing, implement, implements, implemented, implementing | ||||
| # 以上关键词后接 issue_id 例如:Closes #234 Closes #123, #245, #992 | # 以上关键词后接 issue_id 例如:Closes #234 Closes #123, #245, #992 | ||||
| def perform(project, user, tag_issue_id_content, status_id=1) | |||||
| def perform(commitsha, project, user, tag_issue_id_content, status_id=1) | |||||
| Rails.logger.info "需要操作的issue_id内容为 #{tag_issue_id_content}" | Rails.logger.info "需要操作的issue_id内容为 #{tag_issue_id_content}" | ||||
| tag_issue_id_content = tag_issue_id_content.gsub(/\s+/, '') | tag_issue_id_content = tag_issue_id_content.gsub(/\s+/, '') | ||||
| tag_issue_id_content.to_s.split(",").each do |tag_issue| | tag_issue_id_content.to_s.split(",").each do |tag_issue| | ||||
| issue_id = tag_issue.gsub('#', '') | issue_id = tag_issue.gsub('#', '') | ||||
| issue = project.issues.issue_issue.where(project_issues_index: issue_id).where.not(id: issue_id).take || Issue.issue_issue.find_by_id(issue_id) | issue = project.issues.issue_issue.where(project_issues_index: issue_id).where.not(id: issue_id).take || Issue.issue_issue.find_by_id(issue_id) | ||||
| next unless issue.present? # issue不存在 跳过 | next unless issue.present? # issue不存在 跳过 | ||||
| next if issue.project.present? && !user.admin? && !project.member?(user) # issue归属项目,用户没有修改issue的权限,跳过 | |||||
| next if issue.project.present? && !user.admin? && !issue.project.member?(user) # issue归属项目,用户没有修改issue的权限,跳过 | |||||
| next if issue.pm_project_id.present? && project.owner.is_a?(Organization) && !project.owner.is_member?(user.id) # issue是组织下工作项,不具备组织的访问权限,跳过 | next if issue.pm_project_id.present? && project.owner.is_a?(Organization) && !project.owner.is_member?(user.id) # issue是组织下工作项,不具备组织的访问权限,跳过 | ||||
| issue_project = issue.project || Project.new(id: 0, user_id: 0, name: 'pm_mm', identifier: 'pm_mm', is_public:true) | issue_project = issue.project || Project.new(id: 0, user_id: 0, name: 'pm_mm', identifier: 'pm_mm', is_public:true) | ||||
| if issue.pm_project_id.present? | if issue.pm_project_id.present? | ||||
| Api::Pm::Issues::UpdateService.call(issue_project, issue, {status_id: status_id}, user) | |||||
| Api::Pm::Issues::UpdateService.call(issue_project, issue, {status_id: status_id}, user, "Project##{project.id}@#{commitsha}") | |||||
| else | else | ||||
| Api::V1::Issues::UpdateService.call(issue_project, issue, {status_id: status_id}, user) | |||||
| Api::V1::Issues::UpdateService.call(issue_project, issue, {status_id: status_id}, user, "Project##{project.id}@#{commitsha}") | |||||
| end | end | ||||
| end | end | ||||
| end | end | ||||
| @@ -22,6 +22,7 @@ | |||||
| # resolveer_id :integer | # resolveer_id :integer | ||||
| # need_respond :boolean default("0") | # need_respond :boolean default("0") | ||||
| # updated_on :datetime | # updated_on :datetime | ||||
| # operate_by :string(255) default("Issue") | |||||
| # | # | ||||
| # Indexes | # Indexes | ||||
| # | # | ||||
| @@ -82,6 +83,17 @@ class Journal < ApplicationRecord | |||||
| end | end | ||||
| end | end | ||||
| def operate_by_content | |||||
| return '' if self.operate_by == "Issue" | |||||
| if self.operate_by.starts_with?("Project#") | |||||
| project_id, commit_sha = self.operate_by.scan(/#(\d+).*?@(\w+)/)[0] | |||||
| project =Project.find_by_id(project_id) | |||||
| return "通过<a href=\"#{Rails.application.config_for(:configuration)['platform_url']}/#{project&.owner&.login}/#{project&.identifier}/commits/#{commit_sha}\">#{project&.owner&.real_name}/#{project&.name} 提交 #{commit_sha[0...10]}</a>" | |||||
| end | |||||
| rescue | |||||
| return '' | |||||
| end | |||||
| def pm_operate_category | def pm_operate_category | ||||
| detail = self.journal_details.take | detail = self.journal_details.take | ||||
| if %w(requirement task bug).include?(detail.property) && detail.prop_key.to_s == "1" | if %w(requirement task bug).include?(detail.property) && detail.prop_key.to_s == "1" | ||||
| @@ -92,7 +104,7 @@ class Journal < ApplicationRecord | |||||
| end | end | ||||
| def pm_operate_content | def pm_operate_content | ||||
| content = "" | |||||
| content = "#{operate_by_content}" | |||||
| detail = self.journal_details.take | detail = self.journal_details.take | ||||
| case detail.property | case detail.property | ||||
| when 'requirement' | when 'requirement' | ||||
| @@ -153,7 +165,7 @@ class Journal < ApplicationRecord | |||||
| end | end | ||||
| return content | return content | ||||
| else | else | ||||
| return "创建了需求" | |||||
| content += "创建了需求" | |||||
| end | end | ||||
| when 'task' | when 'task' | ||||
| case detail.prop_key | case detail.prop_key | ||||
| @@ -213,7 +225,7 @@ class Journal < ApplicationRecord | |||||
| end | end | ||||
| return content | return content | ||||
| else | else | ||||
| return "创建了任务" | |||||
| content += "创建了任务" | |||||
| end | end | ||||
| when 'bug' | when 'bug' | ||||
| case detail.prop_key | case detail.prop_key | ||||
| @@ -273,14 +285,14 @@ class Journal < ApplicationRecord | |||||
| end | end | ||||
| return content | return content | ||||
| else | else | ||||
| return "创建了缺陷" | |||||
| content += "创建了缺陷" | |||||
| end | end | ||||
| when 'attr' | when 'attr' | ||||
| case detail.prop_key | case detail.prop_key | ||||
| when 'subject' | when 'subject' | ||||
| return "修改了<b>标题</b>" | |||||
| content += "修改了<b>标题</b>" | |||||
| when 'description' | when 'description' | ||||
| return "修改了<b>正文</b>" | |||||
| content += "修改了<b>正文</b>" | |||||
| when 'priority_id' | when 'priority_id' | ||||
| old_value = IssuePriority.find_by_id(detail.old_value)&.name | old_value = IssuePriority.find_by_id(detail.old_value)&.name | ||||
| new_value = IssuePriority.find_by_id(detail.value)&.name | new_value = IssuePriority.find_by_id(detail.value)&.name | ||||
| @@ -490,21 +502,23 @@ class Journal < ApplicationRecord | |||||
| issue = self.issue | issue = self.issue | ||||
| case issue.pm_issue_type | case issue.pm_issue_type | ||||
| when 1 | when 1 | ||||
| return "创建了需求" | |||||
| content += "创建了需求" | |||||
| when 2 | when 2 | ||||
| return "创建了任务" | |||||
| content += "创建了任务" | |||||
| when 3 | when 3 | ||||
| return "创建了缺陷" | |||||
| content += "创建了缺陷" | |||||
| end | end | ||||
| end | end | ||||
| return content | |||||
| end | end | ||||
| def operate_content | def operate_content | ||||
| content = "" | |||||
| content = "#{operate_by_content}" | |||||
| detail = self.journal_details.take | detail = self.journal_details.take | ||||
| case detail.property | case detail.property | ||||
| when 'issue' | when 'issue' | ||||
| return "创建了<b>疑修</b>" | |||||
| content += "创建了<b>疑修</b>" | |||||
| when 'attachment' | when 'attachment' | ||||
| old_value = Attachment.where("BINARY id in (?) or uuid in (?)", detail.old_value.to_s.split(","), detail.old_value.to_s.split(",")).pluck(:filename).join("、") | old_value = Attachment.where("BINARY id in (?) or uuid in (?)", detail.old_value.to_s.split(","), detail.old_value.to_s.split(",")).pluck(:filename).join("、") | ||||
| new_value = Attachment.where("BINARY id in (?) or uuid in (?)", detail.value.to_s.split(","), detail.value.to_s.split(",")).pluck(:filename).join("、") | new_value = Attachment.where("BINARY id in (?) or uuid in (?)", detail.value.to_s.split(","), detail.value.to_s.split(",")).pluck(:filename).join("、") | ||||
| @@ -533,12 +547,12 @@ class Journal < ApplicationRecord | |||||
| content += "将负责人由<b>#{old_value}</b>更改为<b>#{new_value}</b>" | content += "将负责人由<b>#{old_value}</b>更改为<b>#{new_value}</b>" | ||||
| end | end | ||||
| when 'attr' | when 'attr' | ||||
| content = "将" | |||||
| content += "将" | |||||
| case detail.prop_key | case detail.prop_key | ||||
| when 'subject' | when 'subject' | ||||
| return "修改了<b>标题</b>" | |||||
| content += "修改了<b>标题</b>" | |||||
| when 'description' | when 'description' | ||||
| return "修改了<b>描述</b>" | |||||
| content += "修改了<b>描述</b>" | |||||
| when 'status_id' | when 'status_id' | ||||
| old_value = IssueStatus.find_by_id(detail.old_value)&.name | old_value = IssueStatus.find_by_id(detail.old_value)&.name | ||||
| new_value = IssueStatus.find_by_id(detail.value)&.name | new_value = IssueStatus.find_by_id(detail.value)&.name | ||||
| @@ -3,7 +3,7 @@ class Api::Pm::Issues::UpdateService < ApplicationService | |||||
| include Api::V1::Issues::Concerns::Checkable | include Api::V1::Issues::Concerns::Checkable | ||||
| include Api::V1::Issues::Concerns::Loadable | include Api::V1::Issues::Concerns::Loadable | ||||
| attr_reader :project, :issue, :current_user | |||||
| attr_reader :project, :issue, :current_user, :operate_by | |||||
| attr_reader :status_id, :priority_id, :milestone_id, :branch_name, :start_date, :due_date, :subject, :description, :blockchain_token_num | attr_reader :status_id, :priority_id, :milestone_id, :branch_name, :start_date, :due_date, :subject, :description, :blockchain_token_num | ||||
| attr_reader :target_pm_project_id, :pm_sprint_id, :pm_issue_type, :root_id, :time_scale | attr_reader :target_pm_project_id, :pm_sprint_id, :pm_issue_type, :root_id, :time_scale | ||||
| attr_reader :issue_tag_ids, :assigner_ids, :attachment_ids, :receivers_login, :before_issue_tag_ids, :before_assigner_ids, :project_id | attr_reader :issue_tag_ids, :assigner_ids, :attachment_ids, :receivers_login, :before_issue_tag_ids, :before_assigner_ids, :project_id | ||||
| @@ -12,10 +12,11 @@ class Api::Pm::Issues::UpdateService < ApplicationService | |||||
| validates :project, :issue, :current_user, presence: true | validates :project, :issue, :current_user, presence: true | ||||
| validates :blockchain_token_num, numericality: {greater_than: 0}, allow_blank: true | validates :blockchain_token_num, numericality: {greater_than: 0}, allow_blank: true | ||||
| def initialize(project, issue, params, current_user = nil) | |||||
| def initialize(project, issue, params, current_user = nil, operate_by='Issue') | |||||
| @project = project | @project = project | ||||
| @issue = issue | @issue = issue | ||||
| @current_user = current_user | @current_user = current_user | ||||
| @operate_by = operate_by | |||||
| @status_id = params[:status_id] | @status_id = params[:status_id] | ||||
| @priority_id = params[:priority_id] | @priority_id = params[:priority_id] | ||||
| @milestone_id = params[:milestone_id] | @milestone_id = params[:milestone_id] | ||||
| @@ -183,91 +184,91 @@ class Api::Pm::Issues::UpdateService < ApplicationService | |||||
| begin | begin | ||||
| # 更改标题 | # 更改标题 | ||||
| if @updated_issue.previous_changes["subject"].present? | if @updated_issue.previous_changes["subject"].present? | ||||
| journal = @updated_issue.journals.create!({user_id: current_user.id}) | |||||
| journal = @updated_issue.journals.create!({user_id: current_user.id, operate_by: @operate_by}) | |||||
| journal.journal_details.create!({property: "attr", prop_key: "subject", old_value: @updated_issue.previous_changes["subject"][0], value: @updated_issue.previous_changes["subject"][1]}) | journal.journal_details.create!({property: "attr", prop_key: "subject", old_value: @updated_issue.previous_changes["subject"][0], value: @updated_issue.previous_changes["subject"][1]}) | ||||
| end | end | ||||
| # 更改描述 | # 更改描述 | ||||
| if @updated_issue.previous_changes["description"].present? | if @updated_issue.previous_changes["description"].present? | ||||
| journal = @updated_issue.journals.create!({user_id: current_user.id}) | |||||
| journal = @updated_issue.journals.create!({user_id: current_user.id, operate_by: @operate_by}) | |||||
| journal.journal_details.create!({property: "attr", prop_key: "description", old_value: @updated_issue.previous_changes["description"][0], value: @updated_issue.previous_changes["description"][1]}) | journal.journal_details.create!({property: "attr", prop_key: "description", old_value: @updated_issue.previous_changes["description"][0], value: @updated_issue.previous_changes["description"][1]}) | ||||
| end | end | ||||
| # 修改状态 | # 修改状态 | ||||
| if @updated_issue.previous_changes["status_id"].present? | if @updated_issue.previous_changes["status_id"].present? | ||||
| journal = @updated_issue.journals.create!({user_id: current_user.id}) | |||||
| journal = @updated_issue.journals.create!({user_id: current_user.id, operate_by: @operate_by}) | |||||
| journal.journal_details.create!({property: @updated_issue.pm_issue_type_string, prop_key: "status_id", old_value: @updated_issue.previous_changes["status_id"][0], value: @updated_issue.previous_changes["status_id"][1]}) | journal.journal_details.create!({property: @updated_issue.pm_issue_type_string, prop_key: "status_id", old_value: @updated_issue.previous_changes["status_id"][0], value: @updated_issue.previous_changes["status_id"][1]}) | ||||
| end | end | ||||
| # 修改优先级 | # 修改优先级 | ||||
| if @updated_issue.previous_changes["priority_id"].present? | if @updated_issue.previous_changes["priority_id"].present? | ||||
| journal = @updated_issue.journals.create!({user_id: current_user.id}) | |||||
| journal = @updated_issue.journals.create!({user_id: current_user.id, operate_by: @operate_by}) | |||||
| journal.journal_details.create!({property: "attr", prop_key: "priority_id", old_value: @updated_issue.previous_changes["priority_id"][0], value: @updated_issue.previous_changes["priority_id"][1]}) | journal.journal_details.create!({property: "attr", prop_key: "priority_id", old_value: @updated_issue.previous_changes["priority_id"][0], value: @updated_issue.previous_changes["priority_id"][1]}) | ||||
| end | end | ||||
| # 修改工作项类型 | # 修改工作项类型 | ||||
| if @updated_issue.previous_changes["pm_issue_type"].present? | if @updated_issue.previous_changes["pm_issue_type"].present? | ||||
| journal = @updated_issue.journals.create!({user_id: current_user.id}) | |||||
| journal = @updated_issue.journals.create!({user_id: current_user.id, operate_by: @operate_by}) | |||||
| journal.journal_details.create!({property: "attr", prop_key: "pm_issue_type", old_value: @updated_issue.previous_changes["pm_issue_type"][0], value: @updated_issue.previous_changes["pm_issue_type"][1]}) | journal.journal_details.create!({property: "attr", prop_key: "pm_issue_type", old_value: @updated_issue.previous_changes["pm_issue_type"][0], value: @updated_issue.previous_changes["pm_issue_type"][1]}) | ||||
| end | end | ||||
| # 修改迭代 | # 修改迭代 | ||||
| if @updated_issue.previous_changes["pm_sprint_id"].present? | if @updated_issue.previous_changes["pm_sprint_id"].present? | ||||
| journal = @updated_issue.journals.create!({user_id: current_user.id}) | |||||
| journal = @updated_issue.journals.create!({user_id: current_user.id, operate_by: @operate_by}) | |||||
| journal.journal_details.create!({property: "attr", prop_key: "pm_sprint_id", old_value: @updated_issue.previous_changes["pm_sprint_id"][0], value: @updated_issue.previous_changes["pm_sprint_id"][1]}) | journal.journal_details.create!({property: "attr", prop_key: "pm_sprint_id", old_value: @updated_issue.previous_changes["pm_sprint_id"][0], value: @updated_issue.previous_changes["pm_sprint_id"][1]}) | ||||
| end | end | ||||
| # 修改代码库 | # 修改代码库 | ||||
| if @updated_issue.previous_changes["project_id"].present? | if @updated_issue.previous_changes["project_id"].present? | ||||
| journal = @updated_issue.journals.create!({user_id: current_user.id}) | |||||
| journal = @updated_issue.journals.create!({user_id: current_user.id, operate_by: @operate_by}) | |||||
| journal.journal_details.create!({property: "attr", prop_key: "project_id", old_value: @updated_issue.previous_changes["project_id"][0], value: @updated_issue.previous_changes["project_id"][1]}) | journal.journal_details.create!({property: "attr", prop_key: "project_id", old_value: @updated_issue.previous_changes["project_id"][0], value: @updated_issue.previous_changes["project_id"][1]}) | ||||
| end | end | ||||
| # 修改里程碑 | # 修改里程碑 | ||||
| if @updated_issue.previous_changes["fixed_version_id"].present? | if @updated_issue.previous_changes["fixed_version_id"].present? | ||||
| journal = @updated_issue.journals.create!({user_id: current_user.id}) | |||||
| journal = @updated_issue.journals.create!({user_id: current_user.id, operate_by: @operate_by}) | |||||
| journal.journal_details.create!({property: "attr", prop_key: "fixed_version_id", old_value: @updated_issue.previous_changes["fixed_version_id"][0], value: @updated_issue.previous_changes["fixed_version_id"][1]}) | journal.journal_details.create!({property: "attr", prop_key: "fixed_version_id", old_value: @updated_issue.previous_changes["fixed_version_id"][0], value: @updated_issue.previous_changes["fixed_version_id"][1]}) | ||||
| end | end | ||||
| # 更改分支 | # 更改分支 | ||||
| if @updated_issue.previous_changes["branch_name"].present? | if @updated_issue.previous_changes["branch_name"].present? | ||||
| journal = @updated_issue.journals.create!({user_id: current_user.id}) | |||||
| journal = @updated_issue.journals.create!({user_id: current_user.id, operate_by: @operate_by}) | |||||
| journal.journal_details.create!({property: "attr", prop_key: "branch_name", old_value: @updated_issue.previous_changes["branch_name"][0], value: @updated_issue.previous_changes["branch_name"][1]}) | journal.journal_details.create!({property: "attr", prop_key: "branch_name", old_value: @updated_issue.previous_changes["branch_name"][0], value: @updated_issue.previous_changes["branch_name"][1]}) | ||||
| end | end | ||||
| # 更改开始时间 | # 更改开始时间 | ||||
| if @updated_issue.previous_changes["start_date"].present? | if @updated_issue.previous_changes["start_date"].present? | ||||
| journal = @updated_issue.journals.create!({user_id: current_user.id}) | |||||
| journal = @updated_issue.journals.create!({user_id: current_user.id, operate_by: @operate_by}) | |||||
| journal.journal_details.create!({property: "attr", prop_key: "start_date", old_value: @updated_issue.previous_changes["start_date"][0], value: @updated_issue.previous_changes["start_date"][1]}) | journal.journal_details.create!({property: "attr", prop_key: "start_date", old_value: @updated_issue.previous_changes["start_date"][0], value: @updated_issue.previous_changes["start_date"][1]}) | ||||
| end | end | ||||
| # 更改结束时间 | # 更改结束时间 | ||||
| if @updated_issue.previous_changes["due_date"].present? | if @updated_issue.previous_changes["due_date"].present? | ||||
| journal = @updated_issue.journals.create!({user_id: current_user.id}) | |||||
| journal = @updated_issue.journals.create!({user_id: current_user.id, operate_by: @operate_by}) | |||||
| journal.journal_details.create!({property: "attr", prop_key: "due_date", old_value: @updated_issue.previous_changes["due_date"][0], value: @updated_issue.previous_changes["due_date"][1]}) | journal.journal_details.create!({property: "attr", prop_key: "due_date", old_value: @updated_issue.previous_changes["due_date"][0], value: @updated_issue.previous_changes["due_date"][1]}) | ||||
| end | end | ||||
| # 更改预估工时 | # 更改预估工时 | ||||
| if @updated_issue.previous_changes["time_scale"].present? | if @updated_issue.previous_changes["time_scale"].present? | ||||
| journal = @updated_issue.journals.create!({user_id: current_user.id}) | |||||
| journal = @updated_issue.journals.create!({user_id: current_user.id, operate_by: @operate_by}) | |||||
| journal.journal_details.create!({property: "attr", prop_key: "time_scale", old_value: @updated_issue.previous_changes["time_scale"][0], value: @updated_issue.previous_changes["time_scale"][1]}) | journal.journal_details.create!({property: "attr", prop_key: "time_scale", old_value: @updated_issue.previous_changes["time_scale"][0], value: @updated_issue.previous_changes["time_scale"][1]}) | ||||
| end | end | ||||
| # 更改父工作项 | # 更改父工作项 | ||||
| if @updated_issue.previous_changes["root_id"].present? | if @updated_issue.previous_changes["root_id"].present? | ||||
| journal = @updated_issue.journals.create!({user_id: current_user.id}) | |||||
| journal = @updated_issue.journals.create!({user_id: current_user.id, operate_by: @operate_by}) | |||||
| journal.journal_details.create!({property: @updated_issue.pm_issue_type_string, prop_key: "root_id", old_value: @updated_issue.previous_changes["root_id"][0], value: @updated_issue.previous_changes["root_id"][1]}) | journal.journal_details.create!({property: @updated_issue.pm_issue_type_string, prop_key: "root_id", old_value: @updated_issue.previous_changes["root_id"][0], value: @updated_issue.previous_changes["root_id"][1]}) | ||||
| # 更改子工作项 | # 更改子工作项 | ||||
| before_parent_issue = Issue.find_by_id(@updated_issue.previous_changes["root_id"][0]) | before_parent_issue = Issue.find_by_id(@updated_issue.previous_changes["root_id"][0]) | ||||
| if before_parent_issue.present? | if before_parent_issue.present? | ||||
| journal = before_parent_issue.journals.create!({user_id: current_user.id}) | |||||
| journal = before_parent_issue.journals.create!({user_id: current_user.id, operate_by: @operate_by}) | |||||
| journal.journal_details.create!({property: @updated_issue.pm_issue_type_string, prop_key: "tag_leaf_issue", old_value: @updated_issue.id.to_s}) | journal.journal_details.create!({property: @updated_issue.pm_issue_type_string, prop_key: "tag_leaf_issue", old_value: @updated_issue.id.to_s}) | ||||
| end | end | ||||
| after_parent_issue = Issue.find_by_id(@updated_issue.previous_changes["root_id"][1]) | after_parent_issue = Issue.find_by_id(@updated_issue.previous_changes["root_id"][1]) | ||||
| if after_parent_issue.present? | if after_parent_issue.present? | ||||
| journal = after_parent_issue.journals.create!({user_id: current_user.id}) | |||||
| journal = after_parent_issue.journals.create!({user_id: current_user.id, operate_by: @operate_by}) | |||||
| journal.journal_details.create!({property: @updated_issue.pm_issue_type_string, prop_key: "tag_leaf_issue", value: @updated_issue.id.to_s}) | journal.journal_details.create!({property: @updated_issue.pm_issue_type_string, prop_key: "tag_leaf_issue", value: @updated_issue.id.to_s}) | ||||
| end | end | ||||
| end | end | ||||
| @@ -283,7 +284,7 @@ class Api::Pm::Issues::UpdateService < ApplicationService | |||||
| new_assigner_ids = [] if @assigner_ids.nil? | new_assigner_ids = [] if @assigner_ids.nil? | ||||
| now_assigner_ids = @updated_issue.assigners.pluck(:id) | now_assigner_ids = @updated_issue.assigners.pluck(:id) | ||||
| if !(now_assigner_ids.sort == new_assigner_ids.sort) | if !(now_assigner_ids.sort == new_assigner_ids.sort) | ||||
| journal = @updated_issue.journals.create!({user_id: current_user.id}) | |||||
| journal = @updated_issue.journals.create!({user_id: current_user.id, operate_by: @operate_by}) | |||||
| journal.journal_details.create!({property: "assigner", prop_key: "#{new_assigner_ids.size}", old_value: now_assigner_ids.join(","), value: new_assigner_ids.join(",")}) | journal.journal_details.create!({property: "assigner", prop_key: "#{new_assigner_ids.size}", old_value: now_assigner_ids.join(","), value: new_assigner_ids.join(",")}) | ||||
| end | end | ||||
| @@ -299,7 +300,7 @@ class Api::Pm::Issues::UpdateService < ApplicationService | |||||
| new_issue_tag_ids = [] if @issue_tag_ids.nil? | new_issue_tag_ids = [] if @issue_tag_ids.nil? | ||||
| now_issue_tag_ids = @updated_issue.issue_tags.pluck(:id) | now_issue_tag_ids = @updated_issue.issue_tags.pluck(:id) | ||||
| if !(now_issue_tag_ids.sort == new_issue_tag_ids.sort) | if !(now_issue_tag_ids.sort == new_issue_tag_ids.sort) | ||||
| journal = @updated_issue.journals.create!({user_id: current_user.id}) | |||||
| journal = @updated_issue.journals.create!({user_id: current_user.id, operate_by: @operate_by}) | |||||
| 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(",")}) | 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 | end | ||||
| rescue | rescue | ||||
| @@ -315,7 +316,7 @@ class Api::Pm::Issues::UpdateService < ApplicationService | |||||
| new_attachment_ids = [] if @attachment_ids.nil? | new_attachment_ids = [] if @attachment_ids.nil? | ||||
| now_attachment_ids = @updated_issue.attachments.pluck(:id) | now_attachment_ids = @updated_issue.attachments.pluck(:id) | ||||
| if !(now_attachment_ids.sort == new_attachment_ids.sort) | if !(now_attachment_ids.sort == new_attachment_ids.sort) | ||||
| journal = @updated_issue.journals.create!({user_id: current_user.id}) | |||||
| journal = @updated_issue.journals.create!({user_id: current_user.id, operate_by: @operate_by}) | |||||
| journal.journal_details.create!({property: "attachment", prop_key: "#{new_attachment_ids.size}", old_value: now_attachment_ids.join(","), value: new_attachment_ids.join(",")}) | journal.journal_details.create!({property: "attachment", prop_key: "#{new_attachment_ids.size}", old_value: now_attachment_ids.join(","), value: new_attachment_ids.join(",")}) | ||||
| end | end | ||||
| rescue | rescue | ||||
| @@ -3,7 +3,7 @@ class Api::V1::Issues::UpdateService < ApplicationService | |||||
| include Api::V1::Issues::Concerns::Checkable | include Api::V1::Issues::Concerns::Checkable | ||||
| include Api::V1::Issues::Concerns::Loadable | include Api::V1::Issues::Concerns::Loadable | ||||
| attr_reader :project, :issue, :current_user | |||||
| attr_reader :project, :issue, :current_user, :operate_by | |||||
| attr_reader :status_id, :priority_id, :milestone_id, :branch_name, :start_date, :due_date, :subject, :description, :blockchain_token_num | attr_reader :status_id, :priority_id, :milestone_id, :branch_name, :start_date, :due_date, :subject, :description, :blockchain_token_num | ||||
| attr_reader :target_pm_project_id, :pm_sprint_id, :pm_issue_type, :root_id, :time_scale | attr_reader :target_pm_project_id, :pm_sprint_id, :pm_issue_type, :root_id, :time_scale | ||||
| attr_reader :issue_tag_ids, :assigner_ids, :attachment_ids, :receivers_login, :before_issue_tag_ids, :before_assigner_ids, :project_id | attr_reader :issue_tag_ids, :assigner_ids, :attachment_ids, :receivers_login, :before_issue_tag_ids, :before_assigner_ids, :project_id | ||||
| @@ -12,10 +12,11 @@ class Api::V1::Issues::UpdateService < ApplicationService | |||||
| validates :project, :issue, :current_user, presence: true | validates :project, :issue, :current_user, presence: true | ||||
| validates :blockchain_token_num, numericality: {greater_than: 0}, allow_blank: true | validates :blockchain_token_num, numericality: {greater_than: 0}, allow_blank: true | ||||
| def initialize(project, issue, params, current_user = nil) | |||||
| def initialize(project, issue, params, current_user = nil, operate_by='Issue') | |||||
| @project = project | @project = project | ||||
| @issue = issue | @issue = issue | ||||
| @current_user = current_user | @current_user = current_user | ||||
| @operate_by = operate_by | |||||
| @status_id = params[:status_id] | @status_id = params[:status_id] | ||||
| @priority_id = params[:priority_id] | @priority_id = params[:priority_id] | ||||
| @milestone_id = params[:milestone_id] | @milestone_id = params[:milestone_id] | ||||
| @@ -183,49 +184,49 @@ class Api::V1::Issues::UpdateService < ApplicationService | |||||
| begin | begin | ||||
| # 更改标题 | # 更改标题 | ||||
| if @updated_issue.previous_changes["subject"].present? | if @updated_issue.previous_changes["subject"].present? | ||||
| journal = @updated_issue.journals.create!({user_id: current_user.id}) | |||||
| journal = @updated_issue.journals.create!({user_id: current_user.id, operate_by: @operate_by}) | |||||
| journal.journal_details.create!({property: "attr", prop_key: "subject", old_value: @updated_issue.previous_changes["subject"][0], value: @updated_issue.previous_changes["subject"][1]}) | journal.journal_details.create!({property: "attr", prop_key: "subject", old_value: @updated_issue.previous_changes["subject"][0], value: @updated_issue.previous_changes["subject"][1]}) | ||||
| end | end | ||||
| # 更改描述 | # 更改描述 | ||||
| if @updated_issue.previous_changes["description"].present? | if @updated_issue.previous_changes["description"].present? | ||||
| journal = @updated_issue.journals.create!({user_id: current_user.id}) | |||||
| journal = @updated_issue.journals.create!({user_id: current_user.id, operate_by: @operate_by}) | |||||
| journal.journal_details.create!({property: "attr", prop_key: "description", old_value: @updated_issue.previous_changes["description"][0], value: @updated_issue.previous_changes["description"][1]}) | journal.journal_details.create!({property: "attr", prop_key: "description", old_value: @updated_issue.previous_changes["description"][0], value: @updated_issue.previous_changes["description"][1]}) | ||||
| end | end | ||||
| # 修改状态 | # 修改状态 | ||||
| if @updated_issue.previous_changes["status_id"].present? | if @updated_issue.previous_changes["status_id"].present? | ||||
| journal = @updated_issue.journals.create!({user_id: current_user.id}) | |||||
| journal = @updated_issue.journals.create!({user_id: current_user.id, operate_by: @operate_by}) | |||||
| journal.journal_details.create!({property: "attr", prop_key: "status_id", old_value: @updated_issue.previous_changes["status_id"][0], value: @updated_issue.previous_changes["status_id"][1]}) | journal.journal_details.create!({property: "attr", prop_key: "status_id", old_value: @updated_issue.previous_changes["status_id"][0], value: @updated_issue.previous_changes["status_id"][1]}) | ||||
| end | end | ||||
| # 修改优先级 | # 修改优先级 | ||||
| if @updated_issue.previous_changes["priority_id"].present? | if @updated_issue.previous_changes["priority_id"].present? | ||||
| journal = @updated_issue.journals.create!({user_id: current_user.id}) | |||||
| journal = @updated_issue.journals.create!({user_id: current_user.id, operate_by: @operate_by}) | |||||
| journal.journal_details.create!({property: "attr", prop_key: "priority_id", old_value: @updated_issue.previous_changes["priority_id"][0], value: @updated_issue.previous_changes["priority_id"][1]}) | journal.journal_details.create!({property: "attr", prop_key: "priority_id", old_value: @updated_issue.previous_changes["priority_id"][0], value: @updated_issue.previous_changes["priority_id"][1]}) | ||||
| end | end | ||||
| # 修改里程碑 | # 修改里程碑 | ||||
| if @updated_issue.previous_changes["fixed_version_id"].present? | if @updated_issue.previous_changes["fixed_version_id"].present? | ||||
| journal = @updated_issue.journals.create!({user_id: current_user.id}) | |||||
| journal = @updated_issue.journals.create!({user_id: current_user.id, operate_by: @operate_by}) | |||||
| journal.journal_details.create!({property: "attr", prop_key: "fixed_version_id", old_value: @updated_issue.previous_changes["fixed_version_id"][0], value: @updated_issue.previous_changes["fixed_version_id"][1]}) | journal.journal_details.create!({property: "attr", prop_key: "fixed_version_id", old_value: @updated_issue.previous_changes["fixed_version_id"][0], value: @updated_issue.previous_changes["fixed_version_id"][1]}) | ||||
| end | end | ||||
| # 更改分支 | # 更改分支 | ||||
| if @updated_issue.previous_changes["branch_name"].present? | if @updated_issue.previous_changes["branch_name"].present? | ||||
| journal = @updated_issue.journals.create!({user_id: current_user.id}) | |||||
| journal = @updated_issue.journals.create!({user_id: current_user.id, operate_by: @operate_by}) | |||||
| journal.journal_details.create!({property: "attr", prop_key: "branch_name", old_value: @updated_issue.previous_changes["branch_name"][0], value: @updated_issue.previous_changes["branch_name"][1]}) | journal.journal_details.create!({property: "attr", prop_key: "branch_name", old_value: @updated_issue.previous_changes["branch_name"][0], value: @updated_issue.previous_changes["branch_name"][1]}) | ||||
| end | end | ||||
| # 更改开始时间 | # 更改开始时间 | ||||
| if @updated_issue.previous_changes["start_date"].present? | if @updated_issue.previous_changes["start_date"].present? | ||||
| journal = @updated_issue.journals.create!({user_id: current_user.id}) | |||||
| journal = @updated_issue.journals.create!({user_id: current_user.id, operate_by: @operate_by}) | |||||
| journal.journal_details.create!({property: "attr", prop_key: "start_date", old_value: @updated_issue.previous_changes["start_date"][0], value: @updated_issue.previous_changes["start_date"][1]}) | journal.journal_details.create!({property: "attr", prop_key: "start_date", old_value: @updated_issue.previous_changes["start_date"][0], value: @updated_issue.previous_changes["start_date"][1]}) | ||||
| end | end | ||||
| # 更改结束时间 | # 更改结束时间 | ||||
| if @updated_issue.previous_changes["due_date"].present? | if @updated_issue.previous_changes["due_date"].present? | ||||
| journal = @updated_issue.journals.create!({user_id: current_user.id}) | |||||
| journal = @updated_issue.journals.create!({user_id: current_user.id, operate_by: @operate_by}) | |||||
| journal.journal_details.create!({property: "attr", prop_key: "due_date", old_value: @updated_issue.previous_changes["due_date"][0], value: @updated_issue.previous_changes["due_date"][1]}) | journal.journal_details.create!({property: "attr", prop_key: "due_date", old_value: @updated_issue.previous_changes["due_date"][0], value: @updated_issue.previous_changes["due_date"][1]}) | ||||
| end | end | ||||
| rescue | rescue | ||||
| @@ -240,7 +241,7 @@ class Api::V1::Issues::UpdateService < ApplicationService | |||||
| new_assigner_ids = [] if @assigner_ids.nil? | new_assigner_ids = [] if @assigner_ids.nil? | ||||
| now_assigner_ids = @updated_issue.assigners.pluck(:id) | 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 & assigner_ids).empty? || !(now_assigner_ids.empty? && new_assigner_ids.empty?) | ||||
| journal = @updated_issue.journals.create!({user_id: current_user.id}) | |||||
| journal = @updated_issue.journals.create!({user_id: current_user.id, operate_by: @operate_by}) | |||||
| journal.journal_details.create!({property: "assigner", prop_key: "#{new_assigner_ids.size}", old_value: now_assigner_ids.join(","), value: new_assigner_ids.join(",")}) | journal.journal_details.create!({property: "assigner", prop_key: "#{new_assigner_ids.size}", old_value: now_assigner_ids.join(","), value: new_assigner_ids.join(",")}) | ||||
| end | end | ||||
| @@ -256,7 +257,7 @@ class Api::V1::Issues::UpdateService < ApplicationService | |||||
| new_issue_tag_ids = [] if @issue_tag_ids.nil? | new_issue_tag_ids = [] if @issue_tag_ids.nil? | ||||
| now_issue_tag_ids = @updated_issue.issue_tags.pluck(:id) | 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 & new_issue_tag_ids).empty? || !(now_issue_tag_ids.empty? && new_issue_tag_ids.empty?) | ||||
| journal = @updated_issue.journals.create!({user_id: current_user.id}) | |||||
| journal = @updated_issue.journals.create!({user_id: current_user.id, operate_by: @operate_by}) | |||||
| 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(",")}) | 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 | end | ||||
| rescue | rescue | ||||
| @@ -272,7 +273,7 @@ class Api::V1::Issues::UpdateService < ApplicationService | |||||
| new_attachment_ids = [] if @attachment_ids.nil? | new_attachment_ids = [] if @attachment_ids.nil? | ||||
| now_attachment_ids = @updated_issue.attachments.pluck(:id) | 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 & new_attachment_ids).empty? || !(now_attachment_ids.empty? && new_attachment_ids.empty?) | ||||
| journal = @updated_issue.journals.create!({user_id: current_user.id}) | |||||
| journal = @updated_issue.journals.create!({user_id: current_user.id, operate_by: @operate_by}) | |||||
| journal.journal_details.create!({property: "attachment", prop_key: "#{new_attachment_ids.size}", old_value: now_attachment_ids.join(","), value: new_attachment_ids.join(",")}) | journal.journal_details.create!({property: "attachment", prop_key: "#{new_attachment_ids.size}", old_value: now_attachment_ids.join(","), value: new_attachment_ids.join(",")}) | ||||
| end | end | ||||
| rescue | rescue | ||||
| @@ -0,0 +1,5 @@ | |||||
| class AddOperateByToJournals < ActiveRecord::Migration[5.2] | |||||
| def change | |||||
| add_column :journals, :operate_by, :string, default: 'Issue' | |||||
| end | |||||
| end | |||||