修复:删除、更改逻辑测试修改

This commit is contained in:
2023-02-15 09:48:56 +08:00
parent 404a6a00e7
commit 2899f3b18e
8 changed files with 55 additions and 16 deletions

View File

@@ -47,7 +47,7 @@ class Api::V1::Issues::UpdateService < ApplicationService
try_lock
@updated_issue = @issue
@updated_issue.load_attributes
issue_load_attributes
build_issue_journal_details if @updated_issue.previous_changes.present? # 操作记录
build_issue_project_trends if status_id.present? # 开关时间记录
build_assigner_participants unless assigner_ids.blank? # 负责人
@@ -63,27 +63,40 @@ class Api::V1::Issues::UpdateService < ApplicationService
AtmeService.call(current_user, @atme_receivers, @issue) unless receivers_login.blank?
# 消息发送
if Site.has_notice_menu?
SendTemplateMessageJob.perform_later('IssueChanged', current_user.id, @issue&.id, previous_changes) unless previous_issue_changes.blank?
SendTemplateMessageJob.perform_later('IssueChanged', current_user.id, @issue&.id, previous_issue_changes) unless previous_issue_changes.blank?
SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id, add_assigner_ids) unless add_assigner_ids.blank?
end
unlock
return @updated_issue
end
end
private
def issue_load_attributes
@updated_issue.status_id = status_id if status_id.present?
@updated_issue.priority_id = priority_id if priority_id.present?
@updated_issue.fixed_version_id = milestone_id if milestone_id.present?
@updated_issue.branch_name = branch_name if branch_name.present?
@updated_issue.start_date = start_date if start_date.present?
@updated_issue.due_date = due_date if due_date.present?
@updated_issue.subject = subject if subject.present?
@updated_issue.description = description if description.present?
end
def build_assigner_participants
@updated_issue.issue_participants.where.not(id: assigner_ids).each(&:destroy!)
@updated_issue.issue_participants.where(participant_type: "assigned").where.not(participant_id: assigner_ids).each(&:destroy!)
assigner_ids.each do |aid|
next if @updated_issue.issue_participants.exists?(participant_id: aid)
next if @updated_issue.issue_participants.exists?(participant_type: "assigned", participant_id: aid)
@updated_issue.issue_participants.new({participant_type: "assigned", participant_id: aid})
@add_assigner_ids << aid
end
end
def build_previous_issue_changes
@previous_issue_changes = @updated_issue.previous_changes
@previous_issue_changes = @updated_issue.previous_changes.except("updated_on", "created_on")
if @updated_issue.previous_changes[:start_date].present?
@previous_issue_changes.merge!(start_date: [@updated_issue.previous_changes[:start_date][0].to_s, @updated_issue.previous_changes[:start_date][1].to_s])
end
@@ -97,7 +110,7 @@ class Api::V1::Issues::UpdateService < ApplicationService
@updated_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE})
end
if @updated_issue.previous_changes[:status_id].present? && @updated_issue.previous_changes[:status_id][0] == 5
@updated_issue.project_trends.where(action_type: ProjectTrend::CLOSE).each(:&destroy!)
@updated_issue.project_trends.where(action_type: ProjectTrend::CLOSE).each(&:destroy!)
end
end