修复:删除、更改逻辑测试修改
This commit is contained in:
parent
404a6a00e7
commit
2899f3b18e
|
@ -1,6 +1,6 @@
|
||||||
class Api::V1::IssuesController < Api::V1::BaseController
|
class Api::V1::IssuesController < Api::V1::BaseController
|
||||||
|
|
||||||
before_action :require_public_and_member_above, only: [:index, :show, :create, :update, :destroy]
|
before_action :require_public_and_member_above, only: [:index, :show, :create, :update, :destroy, :batch_update, :batch_destroy]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@object_results = Api::V1::Issues::ListService.call(@project, query_params, current_user)
|
@object_results = Api::V1::Issues::ListService.call(@project, query_params, current_user)
|
||||||
|
@ -22,17 +22,31 @@ class Api::V1::IssuesController < Api::V1::BaseController
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@object_result = Api::V1::Issues::DeleteService.call(@project, @issue, current_user)
|
@object_result = Api::V1::Issues::DeleteService.call(@project, @issue, current_user)
|
||||||
|
if @object_result
|
||||||
|
render_ok
|
||||||
|
else
|
||||||
|
render_error("删除疑修失败!")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
before_action :load_issues, only: [:batch_update, :batch_destroy]
|
before_action :load_issues, only: [:batch_update, :batch_destroy]
|
||||||
|
|
||||||
def batch_update
|
def batch_update
|
||||||
@object_result = Api::V1::Issues::BatchUpdateService.call(@project, @issues, batch_issue_params, current_user)
|
@object_result = Api::V1::Issues::BatchUpdateService.call(@project, @issues, batch_issue_params, current_user)
|
||||||
|
if @object_result
|
||||||
|
render_ok
|
||||||
|
else
|
||||||
|
render_error("批量更新疑修失败!")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def batch_destroy
|
def batch_destroy
|
||||||
@object_result = Api::V1::Issues::BatchDeleteService.call(@project, @issues, current_user)
|
@object_result = Api::V1::Issues::BatchDeleteService.call(@project, @issues, current_user)
|
||||||
|
if @object_result
|
||||||
|
render_ok
|
||||||
|
else
|
||||||
|
render_error("批量删除疑修失败!")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -55,7 +69,8 @@ class Api::V1::IssuesController < Api::V1::BaseController
|
||||||
:subject, :description,
|
:subject, :description,
|
||||||
:issue_tag_ids => [],
|
:issue_tag_ids => [],
|
||||||
:assigner_ids => [],
|
:assigner_ids => [],
|
||||||
:attachment_ids => [])
|
:attachment_ids => [],
|
||||||
|
:receivers_login => [])
|
||||||
end
|
end
|
||||||
|
|
||||||
def batch_issue_params
|
def batch_issue_params
|
||||||
|
@ -77,14 +92,14 @@ class Api::V1::IssuesController < Api::V1::BaseController
|
||||||
def load_issues
|
def load_issues
|
||||||
return render_error("请输入正确的ID数组!") unless params[:ids].is_a?(Array)
|
return render_error("请输入正确的ID数组!") unless params[:ids].is_a?(Array)
|
||||||
params[:ids].each do |id|
|
params[:ids].each do |id|
|
||||||
@issue = @project.issues.where(project_issues_index: id).where.not(id: id).take || Issue.find_by_id(id)
|
@issue = Issue.find_by_id(id)
|
||||||
if @issue.blank?
|
if @issue.blank?
|
||||||
return render_not_found("ID为#{id}的疑修不存在!")
|
return render_not_found("ID为#{id}的疑修不存在!")
|
||||||
elsif if @issue.present? && @issue.is_lock &&!(@project.member?(current_user) || current_user.admin?)
|
elsif @issue.present? && @issue.is_lock &&!(@project.member?(current_user) || current_user.admin?)
|
||||||
return render_forbidden("ID为#{id}的疑修您没有权限操作!")
|
return render_forbidden("ID为#{id}的疑修您没有权限操作!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@issues = @project.issues.where(project_issues_index: params[:ids]).where.not(id: params[:ids]) || Issue.where(id: params[:ids])
|
@issues = Issue.where(id: params[:ids])
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
|
@ -26,10 +26,16 @@ class Api::V1::Issues::BatchDeleteService < ApplicationService
|
||||||
end
|
end
|
||||||
|
|
||||||
unlock
|
unlock
|
||||||
|
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def delete_issues
|
||||||
|
raise Error, "批量删除疑修失败!" unless @issues.destroy_all
|
||||||
|
end
|
||||||
|
|
||||||
def try_lock
|
def try_lock
|
||||||
raise Error, "请稍后再试!" unless $redis_cache.set("Api::V1::Issues::BatchDeleteService:#{project.id}", 1, nx: true, ex: 60.seconds)
|
raise Error, "请稍后再试!" unless $redis_cache.set("Api::V1::Issues::BatchDeleteService:#{project.id}", 1, nx: true, ex: 60.seconds)
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,6 +22,8 @@ class Api::V1::Issues::BatchUpdateService < ApplicationService
|
||||||
@issues.each do |issue|
|
@issues.each do |issue|
|
||||||
Api::V1::Issues::UpdateService.call(project, issue, params, current_user)
|
Api::V1::Issues::UpdateService.call(project, issue, params, current_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -47,8 +47,8 @@ class Api::V1::Issues::CreateService < ApplicationService
|
||||||
@created_issue = Issue.new(issue_attributes)
|
@created_issue = Issue.new(issue_attributes)
|
||||||
build_author_participants
|
build_author_participants
|
||||||
build_assigner_participants unless assigner_ids.blank?
|
build_assigner_participants unless assigner_ids.blank?
|
||||||
build_issue_journal_details if @updated_issue.previous_changes.present? # 操作记录
|
build_issue_journal_details
|
||||||
build_issue_project_trends if status_id.present? # 开关时间
|
build_issue_project_trends
|
||||||
@created_issue.attachments = @attachments unless attachment_ids.blank?
|
@created_issue.attachments = @attachments unless attachment_ids.blank?
|
||||||
@created_issue.issue_tags = @issue_tags unless issue_tag_ids.blank?
|
@created_issue.issue_tags = @issue_tags unless issue_tag_ids.blank?
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ class Api::V1::Issues::CreateService < ApplicationService
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_issue_journal_details
|
def build_issue_journal_details
|
||||||
journal = @updated_issue.journals.new({user_id: current_user.id})
|
journal = @created_issue.journals.new({user_id: current_user.id})
|
||||||
journal.journal_details.new({property: "issue", prop_key: 1, old_value: '', value: ''})
|
journal.journal_details.new({property: "issue", prop_key: 1, old_value: '', value: ''})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,8 @@ class Api::V1::Issues::DeleteService < ApplicationService
|
||||||
end
|
end
|
||||||
|
|
||||||
unlock
|
unlock
|
||||||
|
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -47,7 +47,7 @@ class Api::V1::Issues::UpdateService < ApplicationService
|
||||||
|
|
||||||
try_lock
|
try_lock
|
||||||
@updated_issue = @issue
|
@updated_issue = @issue
|
||||||
@updated_issue.load_attributes
|
issue_load_attributes
|
||||||
build_issue_journal_details if @updated_issue.previous_changes.present? # 操作记录
|
build_issue_journal_details if @updated_issue.previous_changes.present? # 操作记录
|
||||||
build_issue_project_trends if status_id.present? # 开关时间记录
|
build_issue_project_trends if status_id.present? # 开关时间记录
|
||||||
build_assigner_participants unless assigner_ids.blank? # 负责人
|
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?
|
AtmeService.call(current_user, @atme_receivers, @issue) unless receivers_login.blank?
|
||||||
# 消息发送
|
# 消息发送
|
||||||
if Site.has_notice_menu?
|
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?
|
SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id, add_assigner_ids) unless add_assigner_ids.blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
unlock
|
unlock
|
||||||
|
|
||||||
|
return @updated_issue
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
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
|
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|
|
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})
|
@updated_issue.issue_participants.new({participant_type: "assigned", participant_id: aid})
|
||||||
@add_assigner_ids << aid
|
@add_assigner_ids << aid
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_previous_issue_changes
|
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?
|
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])
|
@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
|
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})
|
@updated_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE})
|
||||||
end
|
end
|
||||||
if @updated_issue.previous_changes[:status_id].present? && @updated_issue.previous_changes[:status_id][0] == 5
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ end
|
||||||
json.assigners issue.assigners.each do |assigner|
|
json.assigners issue.assigners.each do |assigner|
|
||||||
json.partial! "api/v1/users/simple_user", locals: {user: assigner}
|
json.partial! "api/v1/users/simple_user", locals: {user: assigner}
|
||||||
end
|
end
|
||||||
json.participants issue.participants.each do |participant|
|
json.participants issue.participants.distinct.each do |participant|
|
||||||
json.partial! "api/v1/users/simple_user", locals: {user: participant}
|
json.partial! "api/v1/users/simple_user", locals: {user: participant}
|
||||||
end
|
end
|
||||||
json.comment_journals_count issue.comment_journals.size
|
json.comment_journals_count issue.comment_journals.size
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
json.partial! "api/v1/issues/detail", locals: {issue: @object_result}
|
Loading…
Reference in New Issue