|
|
|
@@ -32,17 +32,20 @@ class Api::V1::Issues::CreateService < ApplicationService |
|
|
|
check_issue_status |
|
|
|
check_issue_priority |
|
|
|
check_milestone if milestone_id.present? |
|
|
|
check_issue_tags unless issue_tag_ids.blank? |
|
|
|
check_assigners unless assigner_ids.blank? |
|
|
|
check_attachments unless attachment_ids.blank? |
|
|
|
load_assigners unless assigner_ids.blank? |
|
|
|
load_attachments unless attachment_ids.blank? |
|
|
|
load_issue_tags unless issue_tag_ids.blank? |
|
|
|
load_participants |
|
|
|
|
|
|
|
@created_issue = Issue.new(issue_attributes) |
|
|
|
@created_issue.assigners = @assigners unless assigner_ids.blank? |
|
|
|
@created_issue.attachments = @attachments unless attachment_ids.blank? |
|
|
|
@created_issue.issue_tags = @issue_tags unless issue_tag_ids.blank? |
|
|
|
@created_issue.participants = @participants |
|
|
|
|
|
|
|
build_author_participants |
|
|
|
build_assinger_participants unless assigner_ids.blank? |
|
|
|
|
|
|
|
@created_issue.save! |
|
|
|
|
|
|
|
project.del_project_issue_cache_delete_count # 把缓存里存储项目删除issue的个数清除掉 |
|
|
|
@@ -67,6 +70,29 @@ class Api::V1::Issues::CreateService < ApplicationService |
|
|
|
raise Error, "Milestone不存在!" unless Version.find_by_id(milestone_id).present? |
|
|
|
end |
|
|
|
|
|
|
|
def check_issue_tags |
|
|
|
raise Error, "请输入正确的标记ID数组!" unless issue_tag_ids.is_a?(Array) |
|
|
|
raise Error, "最多可选择3个标记" if issue_tag_ids.size > 3 |
|
|
|
issue_tag_ids.each do |tid| |
|
|
|
raise Error, "请输入正确的标记ID!" unless IssueTag.exists?(id: tid) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
def check_assigners |
|
|
|
raise Error, "请输入正确的负责人ID数组!" unless assigner_ids.is_a?(Array) |
|
|
|
raise Error, "最多可选择5个负责人" if assigner_ids.size > 5 |
|
|
|
assigner_ids.each do |aid| |
|
|
|
raise Error, "请输入正确的负责人ID!" unless User.exists?(id: aid) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
def check_attachments |
|
|
|
raise Error, "请输入正确的附件ID数组!" unless assigner_ids.is_a?(Array) |
|
|
|
attachment_ids.each do |aid| |
|
|
|
raise Error, "请输入正确的附件ID!" unless Attachment.exists?(id: aid) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
def load_assigners |
|
|
|
@assigners = User.where(id: assigner_ids) |
|
|
|
end |
|
|
|
@@ -79,10 +105,6 @@ class Api::V1::Issues::CreateService < ApplicationService |
|
|
|
@attachments = Attachment.where(id: attachment_ids) |
|
|
|
end |
|
|
|
|
|
|
|
def load_participants |
|
|
|
@participants = User.where(id: assigner_ids).or(User.where(id: current_user.id)) |
|
|
|
end |
|
|
|
|
|
|
|
def issue_attributes |
|
|
|
issue_attributes = { |
|
|
|
subject: subject, |
|
|
|
@@ -104,4 +126,14 @@ class Api::V1::Issues::CreateService < ApplicationService |
|
|
|
|
|
|
|
issue_attributes |
|
|
|
end |
|
|
|
|
|
|
|
def build_author_participants |
|
|
|
@created_issue.issue_participants.new({participant_type: "authored", participant_id: current_user.id}) |
|
|
|
end |
|
|
|
|
|
|
|
def build_assinger_participants |
|
|
|
assigner_ids.each do |aid| |
|
|
|
@created_issue.issue_participants.new({participant_type: "assigned", participant_id: aid}) |
|
|
|
end |
|
|
|
end |
|
|
|
end |