更改:participants创建规则
This commit is contained in:
parent
4a8e3324af
commit
db2d398d94
|
@ -72,6 +72,7 @@ class Issue < ApplicationRecord
|
|||
has_many :assigners, through: :issue_assigners
|
||||
has_many :issue_participants
|
||||
has_many :participants, through: :issue_participants
|
||||
has_many :show_participants, -> {joins(:issue_participants).where.not(issue_participants: {participant_type: "atme"}).distinct}, through: :issue_participants, source: :participant
|
||||
has_many :comment_journals, -> {where.not(notes: nil)}, class_name: "Journal", :as => :journalized
|
||||
has_many :operate_journals, -> {where(notes: nil)}, class_name: "Journal", :as => :journalized
|
||||
|
||||
|
|
|
@ -429,7 +429,7 @@ class Project < ApplicationRecord
|
|||
last_issue = self.issues.last
|
||||
deleted_issue_count = ($redis_cache.hget("issue_cache_delete_count", self.id) || 0).to_i
|
||||
|
||||
last_issue&.project_issues_index.present? ? last_issue.project_issues_index + deleted_issue_count : 1
|
||||
last_issue&.project_issues_index.present? ? last_issue.project_issues_index + deleted_issue_count : 0
|
||||
end
|
||||
|
||||
def incre_project_issue_cache_delete_count
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue