Merge branch 'standalone_develop' into pre_trustie_server

This commit is contained in:
2024-09-14 08:40:33 +08:00
152 changed files with 4203 additions and 331 deletions

View File

@@ -0,0 +1,38 @@
class Api::Pm::Issues::BatchDeleteService < ApplicationService
include ActiveModel::Model
attr_reader :project, :issues, :current_user
validates :project, :issues, :current_user, presence: true
def initialize(project, issues, current_user = nil)
@project = project
@issues = issues.includes(:assigners)
@current_user = current_user
end
def call
raise Error, errors.full_messages.join(", ") unless valid?
try_lock("Api::V1::Issues::DeleteService:#{project.id}") # 开始写数据,加锁
delete_issues
project.incre_project_issue_cache_delete_count(@issues.size)
if Site.has_notice_menu? && !project.id.zero?
@issues.each do |issue|
SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, @issue&.subject, @issue.assigners.pluck(:id), @issue.author_id)
end
end
unlock("Api::V1::Issues::DeleteService:#{project.id}")
return true
end
private
def delete_issues
raise Error, "批量删除疑修失败!" unless @issues.destroy_all
end
end

View File

@@ -0,0 +1,33 @@
class Api::Pm::Issues::BatchUpdateService < ApplicationService
include ActiveModel::Model
include Api::V1::Issues::Concerns::Checkable
include Api::V1::Issues::Concerns::Loadable
attr_reader :project, :issues, :params, :current_user
attr_reader :status_id, :priority_id, :milestone_id, :project_id
attr_reader :issue_tag_ids, :assigner_ids
validates :project, :issues, :current_user, presence: true
def initialize(project, issues, params, current_user = nil)
@project = project
@issues = issues
@params = params
@current_user = current_user
end
def call
raise Error, errors.full_messages.join(", ") unless valid?
ActiveRecord::Base.transaction do
@issues.each do |issue|
if issue.issue_classify == "issue"
Api::Pm::Issues::UpdateService.call(project, issue, params, current_user)
end
end
return true
end
end
end

View File

@@ -0,0 +1,181 @@
class Api::Pm::Issues::CreateService < ApplicationService
include ActiveModel::Model
include Api::V1::Issues::Concerns::Checkable
include Api::V1::Issues::Concerns::Loadable
attr_reader :project, :current_user
attr_reader :status_id, :priority_id, :milestone_id, :branch_name, :start_date, :due_date, :subject, :description, :blockchain_token_num, :root_subject
attr_reader :issue_tag_ids, :assigner_ids, :attachment_ids, :receivers_login
attr_accessor :created_issue
validates :subject, presence: true
validates :status_id, :priority_id, presence: true
validates :project, :current_user, presence: true
validates :blockchain_token_num, numericality: {greater_than: 0}, allow_blank: true
def initialize(project, params, current_user = nil)
@project = project
@current_user = current_user
@status_id = params[:status_id]
@priority_id = params[:priority_id]
@milestone_id = params[:milestone_id]
@branch_name = params[:branch_name]
@start_date = params[:start_date]
@due_date = params[:due_date]
@subject = params[:subject]
@description = params[:description]
@blockchain_token_num = params[:blockchain_token_num]
@issue_tag_ids = params[:issue_tag_ids]
@assigner_ids = params[:assigner_ids]
@attachment_ids = params[:attachment_ids]
@receivers_login = params[:receivers_login]
@pm_project_id = params[:pm_project_id]
@pm_sprint_id = params[:pm_sprint_id]
@pm_issue_type = params[:pm_issue_type]
@root_id = params[:root_id]
@time_scale = params[:time_scale]
@linkable_id = params[:link_able_id]
@root_subject = params[:root_subject]
end
def call
raise Error, errors.full_messages.join(', ') unless valid?
ActiveRecord::Base.transaction do
check_issue_status(status_id)
check_issue_priority(priority_id)
check_milestone(milestone_id) if milestone_id.present?
check_issue_tags(issue_tag_ids) unless issue_tag_ids.blank?
check_assigners(assigner_ids) unless assigner_ids.blank?
check_attachments(attachment_ids) unless attachment_ids.blank?
check_atme_receivers(receivers_login) unless receivers_login.blank?
check_blockchain_token_num(current_user.id, project.id, blockchain_token_num) if blockchain_token_num.present?
load_assigners(assigner_ids) unless assigner_ids.blank?
load_attachments(attachment_ids) unless attachment_ids.blank?
load_issue_tags(issue_tag_ids) unless issue_tag_ids.blank?
load_atme_receivers(receivers_login) unless receivers_login.blank?
try_lock("Api::Pm::Issues::CreateService:#{project.id}") # 开始写数据,加锁
@created_issue = Issue.new(issue_attributes)
@created_issue.pm_issue_type = @pm_issue_type
if @root_subject.present? && @pm_issue_type.to_i == 4
@root_issue = Issue.find_by(subject: @root_subject, pm_issue_type: 4, pm_project_id: @pm_project_id)
unless @root_issue.present?
@root_issue = Issue.create(subject: @root_subject, pm_issue_type: 4, pm_project_id: @pm_project_id, status_id: 1, priority_id: 1, tracker_id: Tracker.first.id, project_id: @project.id, author_id: current_user.id)
end
@created_issue.root_id = @root_issue.id
else
@created_issue.root_id = @root_id
end
build_author_participants
build_assigner_participants unless assigner_ids.blank?
build_atme_participants if @atme_receivers.present?
build_issue_journal_details
build_issue_project_trends
@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.pm_project_id = @pm_project_id
@created_issue.pm_sprint_id = @pm_sprint_id
@created_issue.time_scale = @time_scale
@created_issue.issue_tags_value = @issue_tags.order('id asc').pluck(:id).join(',') unless issue_tag_ids.blank?
@created_issue.changer_id = @current_user.id
@created_issue.save!
if @created_issue.parent_issue.present?
parent_issue = @created_issue.parent_issue
if @created_issue.root_id.present? && parent_issue.present?
journal = parent_issue.journals.create!({user_id: current_user.id})
journal.journal_details.create!({property: @created_issue.pm_issue_type_string, prop_key: 'leaf_issue', value: @created_issue.id.to_s})
end
end
if @linkable_id.present?
PmLink.create(be_linkable_type: 'Issue', be_linkable_id: @created_issue.id, linkable_type: 'Issue', linkable_id: @linkable_id)
another_issue = Issue.find_by_id(@linkable_id)
if another_issue.present?
journal = another_issue.journals.create!({user_id: @current_user.id})
journal.journal_details.create!({property: 'link_issue', prop_key: "1", value: @created_issue.id.to_s})
end
end
if Site.has_blockchain? && @project.use_blockchain
if @created_issue.blockchain_token_num.present? && @created_issue.blockchain_token_num > 0
Blockchain::CreateIssue.call({user_id: current_user.id, project_id: @created_issue.project_id, token_num: @created_issue.blockchain_token_num})
end
push_activity_2_blockchain('issue_create', @created_issue)
end
project.del_project_issue_cache_delete_count # 把缓存里存储项目删除issue的个数清除掉
unless @project.id.zero?
# 新增时向grimoirelab推送事件
IssueWebhookJob.set(wait: 5.seconds).perform_later(@created_issue.id)
# @信息发送
AtmeService.call(current_user, @atme_receivers, @created_issue) unless receivers_login.blank?
# 发消息
if Site.has_notice_menu?
SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @created_issue&.id, assigner_ids) unless assigner_ids.blank?
SendTemplateMessageJob.perform_later('ProjectIssue', current_user.id, @created_issue&.id)
end
# 触发webhook
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueCreate', @created_issue&.id, current_user.id)
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueLabel', @created_issue&.id, current_user.id, {issue_tag_ids: [[], issue_tag_ids]}) unless issue_tag_ids.blank?
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueAssign', @created_issue&.id, current_user.id, {assigner_ids: [[], assigner_ids]}) unless assigner_ids.blank?
end
unlock("Api::Pm::Issues::CreateService:#{project.id}") # 结束写数据,解锁
end
return @created_issue
end
private
def issue_attributes
issue_attributes = {
subject: subject,
project_id: project.id,
author_id: current_user.id,
tracker_id: Tracker.first.id,
status_id: status_id,
priority_id: priority_id,
project_issues_index: (project.get_last_project_issues_index + 1),
issue_type: '1',
issue_classify: 'issue'
}
issue_attributes.merge!({description: description}) if description.present?
issue_attributes.merge!({fixed_version_id: milestone_id}) if milestone_id.present?
issue_attributes.merge!({start_date: start_date}) if start_date.present?
issue_attributes.merge!({due_date: due_date}) if due_date.present?
issue_attributes.merge!({branch_name: branch_name}) if branch_name.present?
issue_attributes.merge!({blockchain_token_num: blockchain_token_num}) if blockchain_token_num.present?
issue_attributes
end
def build_author_participants
@created_issue.issue_participants.new({participant_type: 'authored', participant_id: current_user.id})
end
def build_assigner_participants
assigner_ids.each do |aid|
@created_issue.issue_participants.new({participant_type: 'assigned', participant_id: aid})
end
end
def build_atme_participants
@atme_receivers.each do |receiver|
@created_issue.issue_participants.new({participant_type: 'atme', participant_id: receiver.id})
end
end
def build_issue_project_trends
return if @project.id == 0
@created_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: 'create'})
@created_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE}) if status_id.to_i == 5
end
def build_issue_journal_details
journal = @created_issue.journals.new({user_id: current_user.id})
journal.journal_details.new({property: @created_issue.pm_issue_type_string, prop_key: 1, old_value: '', value: ''})
end
end

View File

@@ -0,0 +1,48 @@
class Api::Pm::Issues::DeleteService < ApplicationService
include ActiveModel::Model
attr_reader :project, :issue, :current_user
validates :project, :issue, :current_user, presence: true
def initialize(project, issue, current_user = nil)
@project = project
@issue = issue
@current_user = current_user
end
def call
raise Error, errors.full_messages.join(", ") unless valid?
try_lock("Api::V1::Issues::DeleteService:#{project.id}") # 开始写数据,加锁
ActiveRecord::Base.transaction do
parent_issue = @issue.parent_issue
if @issue.root_id.present? && parent_issue.present?
journal = parent_issue.journals.create!({user_id: current_user.id})
journal.journal_details.create!({property: @issue.pm_issue_type_string, prop_key: 'leaf_issue', old_value: @issue.id.to_s})
end
delete_issue
#删除双向关联
PmLink.where(be_linkable_id: @issue.id, be_linkable_type: 'Issue').or(PmLink.where(linkable_id: @issue.id, linkable_type: 'Issue')).map(&:destroy)
project.incre_project_issue_cache_delete_count
if Site.has_blockchain? && @project.use_blockchain && !project.id.zero?
unlock_balance_on_blockchain(@issue.author_id.to_s, @project.id.to_s, @issue.blockchain_token_num.to_i) if @issue.blockchain_token_num.present?
end
if Site.has_notice_menu? && !project.id.zero?
SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, @issue&.subject, @issue.assigners.pluck(:id), @issue.author_id)
end
end
unlock("Api::V1::Issues::DeleteService:#{project.id}")
return true
end
private
def delete_issue
raise Error, "删除疑修失败!" unless issue.destroy!
end
end

View File

@@ -0,0 +1,326 @@
class Api::Pm::Issues::UpdateService < ApplicationService
include ActiveModel::Model
include Api::V1::Issues::Concerns::Checkable
include Api::V1::Issues::Concerns::Loadable
attr_reader :project, :issue, :current_user
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 :issue_tag_ids, :assigner_ids, :attachment_ids, :receivers_login, :before_issue_tag_ids, :before_assigner_ids, :project_id
attr_accessor :add_assigner_ids, :previous_issue_changes, :updated_issue, :atme_receivers
validates :project, :issue, :current_user, presence: true
validates :blockchain_token_num, numericality: {greater_than: 0}, allow_blank: true
def initialize(project, issue, params, current_user = nil)
@project = project
@issue = issue
@current_user = current_user
@status_id = params[:status_id]
@priority_id = params[:priority_id]
@milestone_id = params[:milestone_id]
@branch_name = params[:branch_name]
@start_date = params[:start_date]
@due_date = params[:due_date]
@subject = params[:subject]
@description = params[:description]
@blockchain_token_num = params[:blockchain_token_num]
@issue_tag_ids = params[:issue_tag_ids]
@assigner_ids = params[:assigner_ids]
@before_issue_tag_ids = issue.issue_tags.pluck(:id)
@before_assigner_ids = issue.assigners.pluck(:id)
@attachment_ids = params[:attachment_ids]
@receivers_login = params[:receivers_login]
@target_pm_project_id = params[:target_pm_project_id]
@pm_sprint_id = params[:pm_sprint_id]
@pm_issue_type = params[:pm_issue_type]
@root_id = params[:root_id]
@time_scale = params[:time_scale]
@project_id = params[:project_id]
@add_assigner_ids = []
@previous_issue_changes = {}
end
def call
raise Error, errors.full_messages.join(", ") unless valid?
ActiveRecord::Base.transaction do
check_issue_status(status_id) if status_id.present?
check_issue_priority(priority_id) if priority_id.present?
check_milestone(milestone_id) if milestone_id.present?
check_root_issue(issue, root_id) if root_id.present?
check_issue_tags(issue_tag_ids) unless issue_tag_ids.nil?
check_assigners(assigner_ids) unless assigner_ids.nil?
check_attachments(attachment_ids) unless attachment_ids.nil?
check_atme_receivers(receivers_login) unless receivers_login.nil?
check_blockchain_token_num(issue.author_id, project.id, blockchain_token_num, (@issue.blockchain_token_num || 0)) if blockchain_token_num.present? && current_user.id == @issue.author_id && !PullAttachedIssue.exists?(issue_id: @issue, fixed: true)
load_assigners(assigner_ids)
load_attachments(attachment_ids)
load_issue_tags(issue_tag_ids)
load_atme_receivers(receivers_login) unless receivers_login.nil?
try_lock("Api::Pm::Issues::UpdateService:#{project.id}:#{issue.id}")
@updated_issue = @issue
issue_load_attributes
build_assigner_issue_journal_details unless assigner_ids.nil?# 操作记录
build_attachment_issue_journal_details unless attachment_ids.nil?
build_issue_tag_issue_journal_details unless issue_tag_ids.nil?
build_issue_project_trends if status_id.present? # 开关时间记录
build_assigner_participants unless assigner_ids.nil? # 负责人
build_edit_participants
build_atme_participants if @atme_receivers.present?
unless assigner_ids.nil?
@previous_issue_changes.merge!(assigned_to_id: [@updated_issue.assigners.pluck(:id), @assigners.pluck(:id)])
@updated_issue.assigners = @assigners || User.none
end
@updated_issue.attachments = @attachments || Attachment.none unless attachment_ids.nil?
@updated_issue.issue_tags_relates.destroy_all & @updated_issue.issue_tags = @issue_tags || IssueTag.none unless issue_tag_ids.nil?
@updated_issue.issue_tags_value = @issue_tags.order("id asc").pluck(:id).join(",") unless issue_tag_ids.nil?
#Pm相关
@updated_issue.pm_project_id = @target_pm_project_id unless @target_pm_project_id.nil?
@updated_issue.pm_sprint_id = @pm_sprint_id unless @pm_sprint_id.nil?
if @updated_issue.children_issues.count == 0 && @updated_issue.parent_id.nil?
@updated_issue.pm_issue_type = @pm_issue_type unless @pm_issue_type.nil?
end
@updated_issue.root_id = @root_id unless @root_id.nil? #不为 nil的时候更新
@updated_issue.root_id = nil if @root_id.try(:zero?) #为 0 的时候设置为 nil
@updated_issue.time_scale = @time_scale unless @time_scale.nil?
@updated_issue.project_id = @project_id unless @project_id.nil?
@updated_issue.updated_on = Time.now
@updated_issue.changer_id = @current_user.id
@updated_issue.save!
build_after_issue_journal_details if @updated_issue.previous_changes.present? # 操作记录
build_previous_issue_changes
build_cirle_blockchain_token if blockchain_token_num.present?
unless @project.id.zero?
# @信息发送
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_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
# 触发webhook
Rails.logger.info "################### 触发webhook"
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueUpdate', @updated_issue&.id, current_user.id, previous_issue_changes.except(:issue_tags_value, :assigned_to_id))
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueLabel', @issue&.id, current_user.id, {issue_tag_ids: [before_issue_tag_ids, issue_tag_ids]}) unless issue_tag_ids.nil?
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueAssign', @issue&.id, current_user.id, {assigner_ids: [before_assigner_ids, assigner_ids]}) unless assigner_ids.nil?
end
unlock("Api::Pm::Issues::UpdateService:#{project.id}:#{issue.id}")
return @updated_issue
end
end
private
def issue_load_attributes
if current_user.id == @updated_issue.author_id && !PullAttachedIssue.exists?(issue_id: @updated_issue, fixed: true)
@updated_issue.blockchain_token_num = blockchain_token_num unless blockchain_token_num.nil?
end
@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 unless milestone_id.nil?
@updated_issue.branch_name = branch_name unless branch_name.nil?
@updated_issue.start_date = start_date unless start_date.nil?
@updated_issue.due_date = due_date unless due_date.nil?
@updated_issue.subject = subject if subject.present?
@updated_issue.description = description unless description.nil?
end
def build_assigner_participants
if assigner_ids.blank?
@updated_issue.issue_participants.where(participant_type: "assigned").each(&:destroy!)
else
@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_type: "assigned", participant_id: aid)
@updated_issue.issue_participants.new({participant_type: "assigned", participant_id: aid})
@add_assigner_ids << aid
end
end
end
def build_edit_participants
@updated_issue.issue_participants.new({participant_type: "edited", participant_id: current_user.id}) unless @updated_issue.issue_participants.exists?(participant_type: "edited", participant_id: current_user.id)
end
def build_atme_participants
@atme_receivers.each do |receiver|
next if @updated_issue.issue_participants.exists?(participant_type: "atme", participant_id: receiver.id)
@updated_issue.issue_participants.new({participant_type: "atme", participant_id: receiver.id})
end
end
def build_previous_issue_changes
@previous_issue_changes.merge!(@updated_issue.previous_changes.slice("status_id", "priority_id", "fixed_version_id", "issue_tags_value", "branch_name", "subject").symbolize_keys)
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
if @updated_issue.previous_changes[:due_date].present?
@previous_issue_changes.merge!(due_date: [@updated_issue.previous_changes[:due_date][0].to_s, @updated_issue.previous_changes[:due_date][1].to_s])
end
end
def build_cirle_blockchain_token
if @updated_issue.previous_changes["blockchain_token_num"].present?
unlock_balance_on_blockchain(@updated_issue&.author_id.to_s, @updated_issue.project_id.to_s, @updated_issue.previous_changes["blockchain_token_num"][0].to_i) if @updated_issue.previous_changes["blockchain_token_num"][0].present?
lock_balance_on_blockchain(@updated_issue&.author_id.to_s, @updated_issue.project_id.to_s, @updated_issue.previous_changes["blockchain_token_num"][1].to_i) if @updated_issue.previous_changes["blockchain_token_num"][1].present?
end
end
def build_issue_project_trends
if @updated_issue.previous_changes["status_id"].present? && @updated_issue.previous_changes["status_id"][1] == 5
@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!)
end
end
def build_after_issue_journal_details
begin
# 更改标题
if @updated_issue.previous_changes["subject"].present?
journal = @updated_issue.journals.create!({user_id: current_user.id})
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
# 更改描述
if @updated_issue.previous_changes["description"].present?
journal = @updated_issue.journals.create!({user_id: current_user.id})
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
# 修改状态
if @updated_issue.previous_changes["status_id"].present?
journal = @updated_issue.journals.create!({user_id: current_user.id})
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
# 修改优先级
if @updated_issue.previous_changes["priority_id"].present?
journal = @updated_issue.journals.create!({user_id: current_user.id})
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
# 修改工作项类型
if @updated_issue.previous_changes["pm_issue_type"].present?
journal = @updated_issue.journals.create!({user_id: current_user.id})
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
# 修改迭代
if @updated_issue.previous_changes["pm_sprint_id"].present?
journal = @updated_issue.journals.create!({user_id: current_user.id})
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
# 修改代码库
if @updated_issue.previous_changes["project_id"].present?
journal = @updated_issue.journals.create!({user_id: current_user.id})
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
# 修改里程碑
if @updated_issue.previous_changes["fixed_version_id"].present?
journal = @updated_issue.journals.create!({user_id: current_user.id})
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
# 更改分支
if @updated_issue.previous_changes["branch_name"].present?
journal = @updated_issue.journals.create!({user_id: current_user.id})
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
# 更改开始时间
if @updated_issue.previous_changes["start_date"].present?
journal = @updated_issue.journals.create!({user_id: current_user.id})
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
# 更改结束时间
if @updated_issue.previous_changes["due_date"].present?
journal = @updated_issue.journals.create!({user_id: current_user.id})
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
# 更改预估工时
if @updated_issue.previous_changes["time_scale"].present?
journal = @updated_issue.journals.create!({user_id: current_user.id})
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
# 更改父工作项
if @updated_issue.previous_changes["root_id"].present?
journal = @updated_issue.journals.create!({user_id: current_user.id})
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])
if before_parent_issue.present?
journal = before_parent_issue.journals.create!({user_id: current_user.id})
journal.journal_details.create!({property: @updated_issue.pm_issue_type_string, prop_key: "tag_leaf_issue", old_value: @updated_issue.id.to_s})
end
after_parent_issue = Issue.find_by_id(@updated_issue.previous_changes["root_id"][1])
if after_parent_issue.present?
journal = after_parent_issue.journals.create!({user_id: current_user.id})
journal.journal_details.create!({property: @updated_issue.pm_issue_type_string, prop_key: "tag_leaf_issue", value: @updated_issue.id.to_s})
end
end
rescue
raise Error, "创建操作记录失败!"
end
end
def build_assigner_issue_journal_details
begin
# 更改负责人
new_assigner_ids = @assigner_ids
new_assigner_ids = [] if @assigner_ids.nil?
now_assigner_ids = @updated_issue.assigners.pluck(:id)
if !(now_assigner_ids.sort == new_assigner_ids.sort)
journal = @updated_issue.journals.create!({user_id: current_user.id})
journal.journal_details.create!({property: "assigner", prop_key: "#{new_assigner_ids.size}", old_value: now_assigner_ids.join(","), value: new_assigner_ids.join(",")})
end
rescue
raise Error, "创建操作记录失败!"
end
end
def build_issue_tag_issue_journal_details
begin
# 更改标记
new_issue_tag_ids = @issue_tag_ids
new_issue_tag_ids = [] if @issue_tag_ids.nil?
now_issue_tag_ids = @updated_issue.issue_tags.pluck(:id)
if !(now_issue_tag_ids.sort == new_issue_tag_ids.sort)
journal = @updated_issue.journals.create!({user_id: current_user.id})
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
rescue
raise Error, "创建操作记录失败!"
end
end
def build_attachment_issue_journal_details
begin
# 更改附件
new_attachment_ids = @attachment_ids
new_attachment_ids = [] if @attachment_ids.nil?
now_attachment_ids = @updated_issue.attachments.pluck(:id)
if !(now_attachment_ids.sort == new_attachment_ids.sort)
journal = @updated_issue.journals.create!({user_id: current_user.id})
journal.journal_details.create!({property: "attachment", prop_key: "#{new_attachment_ids.size}", old_value: now_attachment_ids.join(","), value: new_attachment_ids.join(",")})
end
rescue
raise Error, "创建操作记录失败!"
end
end
end

View File

@@ -0,0 +1,65 @@
class Api::Pm::SprintIssues::ListService < ApplicationService
include ActiveModel::Model
attr_reader :category, :pm_project_id, :pm_issue_type, :assigner_id, :priority_id, :status_id, :keyword, :current_user
attr_reader :status_ids, :pm_issue_types
attr_reader :sort_by, :sort_direction
attr_accessor :queried_issues
validates :category, inclusion: { in: %w[linked unlink], message: '请输入正确的Category'}
validates :sort_by, inclusion: { in: %w[issues.status_id issues.created_on issues.updated_on issue_priorities.position] , message: '请输入正确的SortBy'}, allow_blank: true
validates :sort_direction, inclusion: { in: %w[asc desc], message: '请输入正确的SortDirection'}, allow_blank: true
validates :pm_project_id, :current_user, presence: true
def initialize(params, current_user = nil)
@category = params[:category] || "unlink"
@pm_project_id = params[:pm_project_id]
@pm_issue_type = params[:pm_issue_type]
@assigner_id = params[:assigner_id]
@priority_id = params[:priority_id]
@status_id = params[:status_id]
@keyword = params[:keyword]
@status_ids = params[:status_ids].present? ? params[:status_ids].split(',') : []
@pm_issue_types = params[:pm_issue_types].present? ? params[:pm_issue_types].split(',') : []
@sort_by = params[:sort_by].present? ? params[:sort_by] : 'issues.updated_on'
@sort_direction = (params[:sort_direction].present? ? params[:sort_direction] : 'desc').downcase
@current_user = current_user
end
def call
raise Error, errors.full_messages.join(', ') unless valid?
issue_query_data
@queried_issues
end
private
def issue_query_data
issues = @category == "unlink" ? Issue.where(pm_project_id: @pm_project_id, pm_sprint_id: [nil, 0]) : Issue.where(pm_project_id: @pm_project_id).where.not(pm_sprint_id: [nil, 0])
issues = issues.where(pm_issue_type: @pm_issue_type) if @pm_issue_type.present?
issues = issues.joins(:assigners).where(users: {id: @assigner_id}) if @assigner_id.present?
issues = issues.where(priority_id: @priority_id) if @priority_id.present?
issues = issues.where(status_id: @status_id) if @status_id.present?
# status_ids
issues = issues.where(status_id: @status_ids) unless @status_ids.blank?
# pm_issue_types
issues = issues.where(pm_issue_type: @pm_issue_types) unless @pm_issue_types.blank?
issues = issues.ransack(subject_cont: @keyword).result if @keyword.present?
scope = issues.includes(:priority, :issue_status, :user, :show_assigners, :show_issue_tags, :version, :comment_journals)
scope = scope.reorder("#{sort_by} #{sort_direction}").distinct
@queried_issues = scope
end
end

View File

@@ -19,7 +19,7 @@ class Api::V1::Issues::BatchDeleteService < ApplicationService
project.incre_project_issue_cache_delete_count(@issues.size)
if Site.has_notice_menu?
if Site.has_notice_menu? && !project.id.zero?
@issues.each do |issue|
SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, @issue&.subject, @issue.assigners.pluck(:id), @issue.author_id)
end

View File

@@ -4,7 +4,7 @@ class Api::V1::Issues::BatchUpdateService < ApplicationService
include Api::V1::Issues::Concerns::Loadable
attr_reader :project, :issues, :params, :current_user
attr_reader :status_id, :priority_id, :milestone_id
attr_reader :status_id, :priority_id, :milestone_id, :project_id
attr_reader :issue_tag_ids, :assigner_ids
validates :project, :issues, :current_user, presence: true

View File

@@ -12,6 +12,10 @@ module Api::V1::Issues::Concerns::Checkable
raise ApplicationService::Error, "Milestone不存在" unless Version.find_by_id(milestone_id).present?
end
def check_root_issue(issue, root_id)
raise ApplicationService::Error, "父工作项与当前工作项已存在父子关系!" if Issue.full_children_issues(issue).map{|i| i.id}.include?(root_id)
end
def check_issue_tags(issue_tag_ids)
raise ApplicationService::Error, "请输入正确的标记ID数组" unless issue_tag_ids.is_a?(Array)
raise ApplicationService::Error, "最多可选择3个标记" if issue_tag_ids.size > 3
@@ -47,6 +51,7 @@ module Api::V1::Issues::Concerns::Checkable
end
def check_blockchain_token_num(user_id, project_id, blockchain_token_num, now_blockchain_token_num=0)
return if project_id.zero?
left_blockchain_token_num = Blockchain::BalanceQueryOneProject.call({"user_id": user_id, "project_id": project_id}) rescue 0
raise ApplicationService::Error, "用户Token不足。" if blockchain_token_num.to_i > (left_blockchain_token_num+now_blockchain_token_num).to_i
end

View File

@@ -9,7 +9,7 @@ module Api::V1::Issues::Concerns::Loadable
end
def load_attachments(attachment_ids)
@attachments = Attachment.where("id in (?) or uuid in (?)", attachment_ids, attachment_ids)
@attachments = Attachment.where("BINARY id in (?) or uuid in (?)", attachment_ids, attachment_ids)
end
def load_atme_receivers(receivers_login)

View File

@@ -4,7 +4,7 @@ class Api::V1::Issues::CreateService < ApplicationService
include Api::V1::Issues::Concerns::Loadable
attr_reader :project, :current_user
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, :root_subject
attr_reader :issue_tag_ids, :assigner_ids, :attachment_ids, :receivers_login
attr_accessor :created_issue
@@ -29,10 +29,17 @@ class Api::V1::Issues::CreateService < ApplicationService
@assigner_ids = params[:assigner_ids]
@attachment_ids = params[:attachment_ids]
@receivers_login = params[:receivers_login]
@pm_project_id = params[:pm_project_id]
@pm_sprint_id = params[:pm_sprint_id]
@pm_issue_type = params[:pm_issue_type]
@root_id = params[:root_id]
@time_scale = params[:time_scale]
@linkable_id = params[:link_able_id]
@root_subject = params[:root_subject]
end
def call
raise Error, errors.full_messages.join(", ") unless valid?
def call
raise Error, errors.full_messages.join(', ') unless valid?
ActiveRecord::Base.transaction do
check_issue_status(status_id)
check_issue_priority(priority_id)
@@ -46,7 +53,6 @@ class Api::V1::Issues::CreateService < ApplicationService
load_attachments(attachment_ids) unless attachment_ids.blank?
load_issue_tags(issue_tag_ids) unless issue_tag_ids.blank?
load_atme_receivers(receivers_login) unless receivers_login.blank?
try_lock("Api::V1::Issues::CreateService:#{project.id}") # 开始写数据,加锁
@created_issue = Issue.new(issue_attributes)
build_author_participants
@@ -57,39 +63,54 @@ class Api::V1::Issues::CreateService < ApplicationService
@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.issue_tags_value = @issue_tags.order("id asc").pluck(:id).join(",") unless issue_tag_ids.blank?
@created_issue.pm_project_id = @pm_project_id
@created_issue.pm_sprint_id = @pm_sprint_id
@created_issue.pm_issue_type = @pm_issue_type
if @root_subject.present? && @pm_issue_type.to_i == 4
@root_issue = Issue.find_by(subject: @root_subject, pm_issue_type: 4, pm_project_id: @pm_project_id)
unless @root_issue.present?
@root_issue = Issue.create(subject: @root_subject, pm_issue_type: 4, pm_project_id: @pm_project_id, status_id: 1, priority_id: 1, tracker_id: Tracker.first.id, project_id: @project.id, author_id: current_user.id)
end
@created_issue.root_id = @root_issue.id
else
@created_issue.root_id = @root_id
end
@created_issue.time_scale = @time_scale
@created_issue.issue_tags_value = @issue_tags.order('id asc').pluck(:id).join(',') unless issue_tag_ids.blank?
@created_issue.changer_id = @current_user.id
@created_issue.save!
if Site.has_blockchain? && @project.use_blockchain
PmLink.create(be_linkable_type: 'Issue', be_linkable_id: @created_issue.id, linkable_type: 'Issue', linkable_id: @linkable_id) if @linkable_id.present?
if Site.has_blockchain? && @project.use_blockchain
if @created_issue.blockchain_token_num.present? && @created_issue.blockchain_token_num > 0
Blockchain::CreateIssue.call({user_id: current_user.id, project_id: @created_issue.project_id, token_num: @created_issue.blockchain_token_num})
end
push_activity_2_blockchain("issue_create", @created_issue)
push_activity_2_blockchain('issue_create', @created_issue)
end
project.del_project_issue_cache_delete_count # 把缓存里存储项目删除issue的个数清除掉
unless @project.id.zero?
# 新增时向grimoirelab推送事件
IssueWebhookJob.set(wait: 5.seconds).perform_later(@created_issue.id)
# 新增时向grimoirelab推送事件
IssueWebhookJob.set(wait: 5.seconds).perform_later(@created_issue.id)
# @信息发送
AtmeService.call(current_user, @atme_receivers, @created_issue) unless receivers_login.blank?
# @信息发送
AtmeService.call(current_user, @atme_receivers, @created_issue) unless receivers_login.blank?
# 发消息
if Site.has_notice_menu?
SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @created_issue&.id, assigner_ids) unless assigner_ids.blank?
SendTemplateMessageJob.perform_later('ProjectIssue', current_user.id, @created_issue&.id)
end
# 发消息
if Site.has_notice_menu?
SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @created_issue&.id, assigner_ids) unless assigner_ids.blank?
SendTemplateMessageJob.perform_later('ProjectIssue', current_user.id, @created_issue&.id)
# 触发webhook
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueCreate', @created_issue&.id, current_user.id)
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueLabel', @created_issue&.id, current_user.id, {issue_tag_ids: [[], issue_tag_ids]}) unless issue_tag_ids.blank?
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueAssign', @created_issue&.id, current_user.id, {assigner_ids: [[], assigner_ids]}) unless assigner_ids.blank?
end
# 触发webhook
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueCreate', @created_issue&.id, current_user.id)
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueLabel', @created_issue&.id, current_user.id, {issue_tag_ids: [[], issue_tag_ids]}) unless issue_tag_ids.blank?
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueAssign', @created_issue&.id, current_user.id, {assigner_ids: [[], assigner_ids]}) unless assigner_ids.blank?
unlock("Api::V1::Issues::CreateService:#{project.id}") # 结束写数据,解锁
end
return @created_issue
end
@@ -104,8 +125,8 @@ class Api::V1::Issues::CreateService < ApplicationService
status_id: status_id,
priority_id: priority_id,
project_issues_index: (project.get_last_project_issues_index + 1),
issue_type: "1",
issue_classify: "issue"
issue_type: '1',
issue_classify: 'issue'
}
issue_attributes.merge!({description: description}) if description.present?
@@ -119,28 +140,29 @@ class Api::V1::Issues::CreateService < ApplicationService
end
def build_author_participants
@created_issue.issue_participants.new({participant_type: "authored", participant_id: current_user.id})
@created_issue.issue_participants.new({participant_type: 'authored', participant_id: current_user.id})
end
def build_assigner_participants
assigner_ids.each do |aid|
@created_issue.issue_participants.new({participant_type: "assigned", participant_id: aid})
@created_issue.issue_participants.new({participant_type: 'assigned', participant_id: aid})
end
end
def build_atme_participants
@atme_receivers.each do |receiver|
@created_issue.issue_participants.new({participant_type: "atme", participant_id: receiver.id})
@created_issue.issue_participants.new({participant_type: 'atme', participant_id: receiver.id})
end
end
def build_issue_project_trends
@created_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: "create"})
return if @project.id == 0
@created_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: 'create'})
@created_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE}) if status_id.to_i == 5
end
def build_issue_journal_details
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

View File

@@ -16,14 +16,16 @@ class Api::V1::Issues::DeleteService < ApplicationService
try_lock("Api::V1::Issues::DeleteService:#{project.id}") # 开始写数据,加锁
delete_issue
#删除双向关联
PmLink.where(be_linkable_id: @issue.id, be_linkable_type: 'Issue').or(PmLink.where(linkable_id: @issue.id, linkable_type: 'Issue')).map(&:destroy)
project.incre_project_issue_cache_delete_count
if Site.has_blockchain? && @project.use_blockchain
if Site.has_blockchain? && @project.use_blockchain && !project.id.zero?
unlock_balance_on_blockchain(@issue.author_id.to_s, @project.id.to_s, @issue.blockchain_token_num.to_i) if @issue.blockchain_token_num.present?
end
if Site.has_notice_menu?
if Site.has_notice_menu? && !project.id.zero?
SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, @issue&.subject, @issue.assigners.pluck(:id), @issue.author_id)
end
@@ -37,5 +39,4 @@ class Api::V1::Issues::DeleteService < ApplicationService
def delete_issue
raise Error, "删除疑修失败!" unless issue.destroy!
end
end

View File

@@ -2,17 +2,18 @@ class Api::V1::Issues::ListService < ApplicationService
include ActiveModel::Model
attr_reader :project, :only_name, :category, :participant_category, :keyword, :author_id, :issue_tag_ids
attr_reader :begin_date, :end_date
attr_reader :milestone_id, :assigner_id, :status_id, :sort_by, :sort_direction, :current_user
attr_accessor :queried_issues, :total_issues_count, :closed_issues_count, :opened_issues_count
attr_reader :begin_date, :end_date, :update_begin_date, :update_end_date
attr_reader :milestone_id, :assigner_id, :status_id, :priority_id, :sort_by, :sort_direction, :current_user
attr_reader :pm_project_id, :pm_project_ids, :pm_sprint_id, :root_id, :pm_issue_type, :status_ids, :ids, :exclude_ids, :pm_issue_types
attr_accessor :queried_issues, :total_issues_count, :closed_issues_count, :opened_issues_count, :complete_issues_count, :participator
validates :category, inclusion: {in: %w(all opened closed), message: '请输入正确的Category'}
validates :participant_category, inclusion: {in: %w(all aboutme authoredme assignedme atme), message: '请输入正确的ParticipantCategory'}
validates :sort_by, inclusion: {in: ['issues.created_on', 'issues.updated_on', 'issues.blockchain_token_num', 'issue_priorities.position'], message: '请输入正确的SortBy'}, allow_blank: true
validates :sort_direction, inclusion: {in: %w(asc desc), message: '请输入正确的SortDirection'}, allow_blank: true
validates :category, inclusion: { in: %w[all opened closed], message: '请输入正确的Category'}
validates :participant_category, inclusion: { in: %w[all aboutme authoredme assignedme atme], message: '请输入正确的ParticipantCategory'}
validates :sort_by, inclusion: { in: %w[issues.created_on issues.updated_on issues.blockchain_token_num issue_priorities.position issues.start_date issues.due_date issues.status_id] , message: '请输入正确的SortBy'}, allow_blank: true
validates :sort_direction, inclusion: { in: %w[asc desc], message: '请输入正确的SortDirection'}, allow_blank: true
validates :current_user, presence: true
def initialize(project, params, current_user=nil)
def initialize(project, params, current_user = nil)
@project = project
@only_name = params[:only_name]
@category = params[:category] || 'all'
@@ -22,20 +23,39 @@ class Api::V1::Issues::ListService < ApplicationService
@issue_tag_ids = params[:issue_tag_ids].present? ? params[:issue_tag_ids].split(',') : []
@milestone_id = params[:milestone_id]
@assigner_id = params[:assigner_id]
@priority_id = params[:priority_id]
@status_id = params[:status_id]
@begin_date = params[:begin_date]
@end_date = params[:end_date]
@update_begin_date = params[:update_begin_date]
@update_end_date = params[:update_end_date]
@sort_by = params[:sort_by].present? ? params[:sort_by] : 'issues.updated_on'
@pm_project_id = params[:pm_project_id]
@pm_project_ids = params[:pm_project_ids]
@pm_sprint_id = params[:pm_sprint_id]
@root_id = params[:root_id]
@pm_issue_type = params[:pm_issue_type]
@ids = params[:ids]
@exclude_ids = params[:exclude_ids]
@status_ids = params[:status_ids].present? ? params[:status_ids].split(',') : []
@pm_issue_types = params[:pm_issue_types].present? ? params[:pm_issue_types].split(',') : []
@sort_direction = (params[:sort_direction].present? ? params[:sort_direction] : 'desc').downcase
@participator = params[:participator_id].present? ? User.find_by_id(params[:participator_id]) : current_user
@current_user = current_user
end
def call
raise Error, errors.full_messages.join(', ') unless valid?
# begin
issue_query_data
issue_query_data
return {data: queried_issues, total_issues_count: @total_issues_count, closed_issues_count: @closed_issues_count, opened_issues_count: @opened_issues_count}
{
data: queried_issues,
total_issues_count: @total_issues_count,
closed_issues_count: @closed_issues_count,
opened_issues_count: @opened_issues_count,
complete_issues_count: @complete_issues_count
}
# rescue
# raise Error, "服务器错误,请联系系统管理员!"
# end
@@ -43,19 +63,18 @@ class Api::V1::Issues::ListService < ApplicationService
private
def issue_query_data
issues = @project.issues.issue_issue
issues = @project&.id.zero? ? Issue.issue_issue : @project.issues.issue_issue
@total_issues_count = issues.where(pm_issue_type:[1, 2, 3]).distinct.size
case participant_category
when 'aboutme' # 关于我的
issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: %w(authored assigned atme), participant_id: current_user&.id})
issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: %w[authored assigned atme], participant_id: participator&.id})
when 'authoredme' # 我创建的
issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: 'authored', participant_id: current_user&.id})
issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: 'authored', participant_id: participator&.id})
when 'assignedme' # 我负责的
issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: 'assigned', participant_id: current_user&.id})
issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: 'assigned', participant_id: participator&.id})
when 'atme' # @我的
issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: 'atme', participant_id: current_user&.id})
issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: 'atme', participant_id: participator&.id})
end
# author_id
issues = issues.where(author_id: author_id) if author_id.present?
@@ -77,6 +96,26 @@ class Api::V1::Issues::ListService < ApplicationService
end
end
#pm相关
# root_id# -1 查一级目录
issues = if root_id.to_i == -1
issues.where(root_id: nil)
elsif root_id.to_i.positive?
issues.where(root_id: root_id)
else
issues
end
# pm_issue_type
issues = issues.where(pm_issue_type: pm_issue_type) if pm_issue_type.present?
# pm_project_id
issues = issues.where(pm_project_id: pm_project_id) if pm_project_id.present?
issues = issues.where(pm_project_id: pm_project_ids.to_s.split(",")) if pm_project_ids.present?
# pm_sprint_id
issues = issues.where(pm_sprint_id: pm_sprint_id) if pm_sprint_id.present?
# assigner_id
if assigner_id.present?
if assigner_id.to_i == -1
@@ -89,16 +128,36 @@ class Api::V1::Issues::ListService < ApplicationService
# status_id
issues = issues.where(status_id: status_id) if status_id.present? && category != 'closed'
# priority_id
issues = issues.where(priority_id: priority_id) if priority_id.present?
# status_ids
issues = issues.where(status_id: status_ids) unless status_ids.blank?
# pm_issue_types
issues = issues.where(pm_issue_type: pm_issue_types) unless pm_issue_types.blank?
# ids
issues = issues.where(id: ids.to_s.split(",")) if ids.present?
# exclude_ids
issues = issues.where.not(id: exclude_ids.to_s.split(",")) if exclude_ids.present?
if begin_date&.present? || end_date&.present?
issues = issues.where('issues.created_on between ? and ?', begin_date&.present? ? begin_date.to_time : Time.now.beginning_of_day, end_date&.present? ? end_date.to_time.end_of_day : Time.now.end_of_day)
end
if update_begin_date&.present? || update_end_date&.present?
issues = issues.where('issues.updated_on between ? and ?', update_begin_date&.present? ? update_begin_date.to_time : Time.now.beginning_of_day, update_end_date&.present? ? update_end_date.to_time.end_of_day : Time.now.end_of_day)
end
# keyword
issues = issues.ransack(id_or_project_issues_index_eq: keyword).result.or(issues.ransack(subject_or_description_cont: keyword).result) if keyword.present?
@total_issues_count = issues.distinct.size
@closed_issues_count = issues.closed.distinct.size
@opened_issues_count = issues.opened.distinct.size
@complete_issues_count = issues.closed.distinct.size + issues.where(status_id: 3).distinct.size - issues.where(pm_issue_type: 3, status_id: 3).distinct.size
case category
when 'closed'

View File

@@ -5,7 +5,8 @@ class Api::V1::Issues::UpdateService < ApplicationService
attr_reader :project, :issue, :current_user
attr_reader :status_id, :priority_id, :milestone_id, :branch_name, :start_date, :due_date, :subject, :description, :blockchain_token_num
attr_reader :issue_tag_ids, :assigner_ids, :attachment_ids, :receivers_login, :before_issue_tag_ids, :before_assigner_ids
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_accessor :add_assigner_ids, :previous_issue_changes, :updated_issue, :atme_receivers
validates :project, :issue, :current_user, presence: true
@@ -30,6 +31,12 @@ class Api::V1::Issues::UpdateService < ApplicationService
@before_assigner_ids = issue.assigners.pluck(:id)
@attachment_ids = params[:attachment_ids]
@receivers_login = params[:receivers_login]
@target_pm_project_id = params[:target_pm_project_id]
@pm_sprint_id = params[:pm_sprint_id]
@pm_issue_type = params[:pm_issue_type]
@root_id = params[:root_id]
@time_scale = params[:time_scale]
@project_id = params[:project_id]
@add_assigner_ids = []
@previous_issue_changes = {}
end
@@ -40,6 +47,7 @@ class Api::V1::Issues::UpdateService < ApplicationService
check_issue_status(status_id) if status_id.present?
check_issue_priority(priority_id) if priority_id.present?
check_milestone(milestone_id) if milestone_id.present?
check_root_issue(issue, root_id) if root_id.present?
check_issue_tags(issue_tag_ids) unless issue_tag_ids.nil?
check_assigners(assigner_ids) unless assigner_ids.nil?
check_attachments(attachment_ids) unless attachment_ids.nil?
@@ -68,28 +76,39 @@ class Api::V1::Issues::UpdateService < ApplicationService
@updated_issue.issue_tags_relates.destroy_all & @updated_issue.issue_tags = @issue_tags || IssueTag.none unless issue_tag_ids.nil?
@updated_issue.issue_tags_value = @issue_tags.order("id asc").pluck(:id).join(",") unless issue_tag_ids.nil?
#Pm相关
@updated_issue.pm_project_id = @target_pm_project_id unless @target_pm_project_id.nil?
@updated_issue.pm_sprint_id = @pm_sprint_id unless @pm_sprint_id.nil?
if @updated_issue.children_issues.count == 0 && @updated_issue.parent_id.nil?
@updated_issue.pm_issue_type = @pm_issue_type unless @pm_issue_type.nil?
end
@updated_issue.root_id = @root_id unless @root_id.nil? #不为 nil的时候更新
@updated_issue.root_id = nil if @root_id.try(:zero?) #为 0 的时候设置为 nil
@updated_issue.time_scale = @time_scale unless @time_scale.nil?
@updated_issue.project_id = @project_id unless @project_id.nil?
@updated_issue.updated_on = Time.now
@updated_issue.changer_id = @current_user.id
@updated_issue.save!
build_after_issue_journal_details if @updated_issue.previous_changes.present? # 操作记录
build_previous_issue_changes
build_cirle_blockchain_token if blockchain_token_num.present?
# @信息发送
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_issue_changes) unless previous_issue_changes.blank?
SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id, add_assigner_ids) unless add_assigner_ids.blank?
unless @project.id.zero?
# @信息发送
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_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
# 触发webhook
Rails.logger.info "################### 触发webhook"
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueUpdate', @updated_issue&.id, current_user.id, previous_issue_changes.except(:issue_tags_value, :assigned_to_id))
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueLabel', @issue&.id, current_user.id, {issue_tag_ids: [before_issue_tag_ids, issue_tag_ids]}) unless issue_tag_ids.nil?
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueAssign', @issue&.id, current_user.id, {assigner_ids: [before_assigner_ids, assigner_ids]}) unless assigner_ids.nil?
end
unlock("Api::V1::Issues::UpdateService:#{project.id}:#{issue.id}")
# 触发webhook
Rails.logger.info "################### 触发webhook"
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueUpdate', @updated_issue&.id, current_user.id, previous_issue_changes.except(:issue_tags_value, :assigned_to_id))
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueLabel', @issue&.id, current_user.id, {issue_tag_ids: [before_issue_tag_ids, issue_tag_ids]}) unless issue_tag_ids.nil?
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueAssign', @issue&.id, current_user.id, {assigner_ids: [before_assigner_ids, assigner_ids]}) unless assigner_ids.nil?
return @updated_issue
end
end

View File

@@ -0,0 +1,33 @@
class Gitea::Repository::ActionSecretsService < Gitea::ClientService
attr_reader :owner, :repo, :secret_name, :secret
def initialize(owner, repo, secret_name, secret)
@owner = owner
@repo = repo
@secret_name = secret_name
@secret = secret
end
def call
response = put(url, request_params)
render_201_response(response)
end
def destroy
response = delete(url, request_params)
render_201_response(response)
end
private
def request_params
Hash.new.merge(token: owner.gitea_token, data: { data: secret } )
end
def url
"/repos/#{owner.login}/#{repo}/actions/secrets/#{secret_name}".freeze
end
end

View File

@@ -10,6 +10,7 @@ class Projects::TransferService < ApplicationService
def call
Rails.logger.info("###### Project transfer_service begin ######")
ActiveRecord::Base.transaction do
update_actions
gitea_update_owner
update_owner
update_repo_url
@@ -32,6 +33,16 @@ class Projects::TransferService < ApplicationService
project.set_owner_permission(new_owner)
end
def update_actions
begin
action_params = { has_actions: false }
Gitea::Repository::UpdateService.call(owner, project.identifier, action_params)
project.update action_params
rescue Exception => e
Rails.logger.info("##### Project transfer_service, gitea transfer error #{e}")
end
end
def update_repo_url
project.repository.update!(user_id: new_owner.id, url: @gitea_repo["clone_url"])
end