Merge pull request '平台issue模块升级相关' (#24) from yystopf/forgeplus:hh_issue_upgrade into develop

This commit is contained in:
yystopf 2023-03-01 16:29:19 +08:00
commit cbb0a639b2
71 changed files with 1899 additions and 11 deletions

View File

@ -20,10 +20,19 @@ class Api::V1::BaseController < ApplicationController
# User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token
# end
# end
def kaminary_select_paginate(relation)
limit = params[:limit] || params[:per_page]
limit = (limit.to_i.zero? || limit.to_i > 100) ? 100 : limit.to_i
page = params[:page].to_i.zero? ? 1 : params[:page].to_i
relation.page(page).per(limit)
end
def limit
params.fetch(:limit, 15)
end
def page
params.fetch(:page, 1)
end
@ -43,7 +52,6 @@ class Api::V1::BaseController < ApplicationController
# 具有仓库的操作权限或者fork仓库的操作权限
def require_operate_above_or_fork_project
@project = load_project
puts !current_user.admin? && !@project.operator?(current_user) && !(@project.fork_project.present? && @project.fork_project.operator?(current_user))
return render_forbidden if !current_user.admin? && !@project.operator?(current_user) && !(@project.fork_project.present? && @project.fork_project.operator?(current_user))
end

View File

@ -0,0 +1,12 @@
class Api::V1::Issues::AssignersController < Api::V1::BaseController
before_action :require_public_and_member_above, only: [:index]
# 负责人列表
def index
@assigners = User.joins(assigned_issues: :project).where(projects: {id: @project&.id})
@assigners = @assigners.order("users.id=#{current_user.id} desc").distinct
@assigners = @assigners.ransack(login_or_nickname_cont: params[:keyword]).result if params[:keyword].present?
@assigners = kaminary_select_paginate(@assigners)
end
end

View File

@ -0,0 +1,11 @@
class Api::V1::Issues::AuthorsController < Api::V1::BaseController
before_action :require_public_and_member_above, only: [:index]
# 发布人列表
def index
@authors = User.joins(issues: :project).where(projects: {id: @project&.id})
@authors = @authors.order("users.id=#{current_user.id} desc").distinct
@authors = @authors.ransack(login_or_nickname_cont: params[:keyword]).result if params[:keyword].present?
@authors = kaminary_select_paginate(@authors)
end
end

View File

@ -0,0 +1,10 @@
class Api::V1::Issues::IssuePrioritiesController < Api::V1::BaseController
before_action :require_public_and_member_above, only: [:index]
def index
@priorities = IssuePriority.order(position: :asc)
@priorities = @priorities.ransack(name_cont: params[:keyword]).result if params[:keyword]
@priorities = kaminary_select_paginate(@priorities)
end
end

View File

@ -0,0 +1,65 @@
class Api::V1::Issues::IssueTagsController < Api::V1::BaseController
before_action :require_login, except: [:index]
before_action :require_public_and_member_above, only: [:index]
before_action :require_operate_above, only: [:create, :update, :destroy]
def index
@issue_tags = @project.issue_tags.reorder("#{sort_by} #{sort_direction}")
@issue_tags = @issue_tags.ransack(name_cont: params[:keyword]).result if params[:keyword].present?
if params[:only_name]
@issue_tags = kaminary_select_paginate(@issue_tags.select(:id, :name, :color))
else
@issue_tags = kaminari_paginate(@issue_tags.includes(:project, :user, :issue_issues, :pull_request_issues))
end
end
def create
@issue_tag = @project.issue_tags.new(issue_tag_params)
if @issue_tag.save!
render_ok
else
render_error("创建标记失败!")
end
end
before_action :load_issue_tag, only: [:update, :destroy]
def update
@issue_tag.attributes = issue_tag_params
if @issue_tag.save!
render_ok
else
render_error("更新标记失败!")
end
end
def destroy
if @issue_tag.destroy!
render_ok
else
render_error("删除标记失败!")
end
end
private
def sort_by
sort_by = params.fetch(:sort_by, "created_at")
sort_by = IssueTag.column_names.include?(sort_by) ? sort_by : "created_at"
sort_by
end
def sort_direction
sort_direction = params.fetch(:sort_direction, "desc").downcase
sort_direction = %w(desc asc).include?(sort_direction) ? sort_direction : "desc"
sort_direction
end
def issue_tag_params
params.permit(:name, :description, :color)
end
def load_issue_tag
@issue_tag = @project.issue_tags.find_by_id(params[:id])
end
end

View File

@ -0,0 +1,60 @@
class Api::V1::Issues::JournalsController < Api::V1::BaseController
before_action :require_login, except: [:index, :children_journals]
before_action :require_public_and_member_above
before_action :load_issue
before_action :load_journal, only: [:children_journals, :update, :destroy]
before_action :check_journal_operate_permission, only: [:update, :destroy]
def index
@object_results = Api::V1::Issues::Journals::ListService.call(@issue, query_params, current_user)
@journals = kaminari_paginate(@object_results)
end
def create
@object_result = Api::V1::Issues::Journals::CreateService.call(@issue, journal_params, current_user)
end
def children_journals
@object_results = Api::V1::Issues::Journals::ChildrenListService.call(@issue, @journal, query_params, current_user)
@journals = kaminari_paginate(@object_results)
end
def update
@object_result = Api::V1::Issues::Journals::UpdateService.call(@issue, @journal, journal_params, current_user)
end
def destroy
if @journal.destroy!
render_ok
else
render_error("删除评论失败!")
end
end
private
def query_params
params.permit(:category, :keyword, :sort_by, :sort_direction)
end
def journal_params
params.permit(:notes, :parent_id, :reply_id, :attachment_ids => [], :receivers_login => [])
end
def load_issue
@issue = @project.issues.issue_issue.where(project_issues_index: params[:index]).where.not(id: params[:index]).take || Issue.find_by_id(params[:index])
if @issue.blank?
render_not_found("疑修不存在!")
end
end
def load_journal
@journal = Journal.find_by_id(params[:id])
return render_not_found("评论不存在!") unless @journal.present?
end
def check_journal_operate_permission
return render_forbidden("您没有操作权限!") unless @project.member?(current_user) || current_user.admin? || @issue.user == current_user || @journal.user == current_user || @journal.parent_journal&.user == current_user
end
end

View File

@ -0,0 +1,87 @@
class Api::V1::Issues::MilestonesController < Api::V1::BaseController
before_action :require_login, except: [:index, :show]
before_action :require_public_and_member_above, only: [:index, :show]
before_action :require_operate_above, only: [:create, :update, :destroy]
before_action :load_milestone, only: [:show, :update, :destroy]
# 里程碑列表
def index
@milestones = @project.versions
@milestones = @milestones.ransack(id_eq: params[:keyword]).result.or(@milestones.ransack(name_or_description_cont: params[:keyword]).result) if params[:keyword].present?
@closed_milestone_count = @milestones.closed.size
@opening_milestone_count = @milestones.opening.size
@milestones = params[:category] == "closed" ? @milestones.closed : @milestones.opening
@milestones = @milestones.reorder("versions.#{sort_by} #{sort_direction}")
if params[:only_name]
@milestones = @milestones.select(:id, :name)
@milestones = kaminary_select_paginate(@milestones)
else
@milestones = @milestones.includes(:issues, :closed_issues, :opened_issues)
@milestones = kaminari_paginate(@milestones)
end
end
def create
@milestone = @project.versions.new(milestone_params)
if @milestone.save!
render_ok
else
render_error(@milestone.errors.full_messages.join(","))
end
end
# 里程碑详情
def show
@object_result = Api::V1::Issues::Milestones::DetailIssuesService.call(@project, @milestone, query_params, current_user)
@total_issues_count = @object_result[:total_issues_count]
@opened_issues_count = @object_result[:opened_issues_count]
@closed_issues_count = @object_result[:closed_issues_count]
@issues = kaminari_paginate(@object_result[:data])
end
def update
@milestone.attributes = milestone_params
if @milestone.save!
render_ok
else
render_error(@milestone.errors.full_messages.join(","))
end
end
def destroy
if @milestone.destroy!
render_ok
else
render_error("删除里程碑失败!")
end
end
private
def milestone_params
params.permit(:name, :description, :effective_date)
end
def query_params
params.permit(:category, :author_id, :assigner_id, :sort_by, :sort_direction, :issue_tag_ids)
end
def load_milestone
@milestone = @project.versions.find_by_id(params[:id])
return render_not_found('里程碑不存在!') unless @milestone.present?
end
def sort_by
sort_by = params.fetch(:sort_by, "created_on")
sort_by = Version.column_names.include?(sort_by) ? sort_by : "created_on"
sort_by
end
def sort_direction
sort_direction = params.fetch(:sort_direction, "desc").downcase
sort_direction = %w(desc asc).include?(sort_direction) ? sort_direction : "desc"
sort_direction
end
end

View File

@ -0,0 +1,11 @@
class Api::V1::Issues::StatuesController < Api::V1::BaseController
before_action :require_public_and_member_above, only: [:index]
# 状态列表
def index
@statues = IssueStatus.order("position asc")
@statues = @statues.ransack(name_cont: params[:keyword]).result if params[:keyword].present?
@statues = kaminary_select_paginate(@statues)
end
end

View File

@ -0,0 +1,112 @@
class Api::V1::IssuesController < Api::V1::BaseController
before_action :require_login, except: [:index, :show]
before_action :require_public_and_member_above, only: [:index, :show, :create, :update, :destroy]
before_action :require_operate_above, only: [:batch_update, :batch_destroy]
def index
IssueTag.init_data(@project.id) unless $redis_cache.hget("project_init_issue_tags", @project.id)
@object_result = Api::V1::Issues::ListService.call(@project, query_params, current_user)
@total_issues_count = @object_result[:total_issues_count]
@opened_issues_count = @object_result[:opened_issues_count]
@closed_issues_count = @object_result[:closed_issues_count]
@issues = kaminari_paginate(@object_result[:data])
end
def create
@object_result = Api::V1::Issues::CreateService.call(@project, issue_params, current_user)
end
before_action :load_issue, only: [:show, :update, :destroy]
before_action :check_issue_operate_permission, only: [:update, :destroy]
def show
@user_permission = current_user.present? && current_user.logged? && (@project.member?(current_user) || current_user.admin? || @issue.user == current_user)
end
def update
@object_result = Api::V1::Issues::UpdateService.call(@project, @issue, issue_params, current_user)
end
def destroy
@object_result = Api::V1::Issues::DeleteService.call(@project, @issue, current_user)
if @object_result
render_ok
else
render_error("删除疑修失败!")
end
end
before_action :load_issues, only: [:batch_update, :batch_destroy]
def batch_update
@object_result = Api::V1::Issues::BatchUpdateService.call(@project, @issues, batch_issue_params, current_user)
if @object_result
render_ok
else
render_error("批量更新疑修失败!")
end
end
def batch_destroy
@object_result = Api::V1::Issues::BatchDeleteService.call(@project, @issues, current_user)
if @object_result
render_ok
else
render_error("批量删除疑修失败!")
end
end
private
def load_issue
@issue = @project.issues.issue_issue.where(project_issues_index: params[:index]).where.not(id: params[:index]).take || Issue.find_by_id(params[:index])
if @issue.blank?
render_not_found("疑修不存在!")
end
end
def load_issues
return render_error("请输入正确的ID数组") unless params[:ids].is_a?(Array)
params[:ids].each do |id|
@issue = Issue.find_by_id(id)
if @issue.blank?
return render_not_found("ID为#{id}的疑修不存在!")
end
end
@issues = Issue.where(id: params[:ids])
end
def check_issue_operate_permission
return render_forbidden("您没有操作权限!") unless @project.member?(current_user) || current_user.admin? || @issue.user == current_user
end
def query_params
params.permit(
:category,
:participant_category,
:keyword, :author_id,
:milestone_id, :assigner_id,
:status_id,
:sort_by, :sort_direction,
:issue_tag_ids)
end
def issue_params
params.permit(
:status_id, :priority_id, :milestone_id,
:branch_name, :start_date, :due_date,
:subject, :description,
:issue_tag_ids => [],
:assigner_ids => [],
:attachment_ids => [],
:receivers_login => [])
end
def batch_issue_params
params.permit(
:status_id, :priority_id, :milestone_id,
:issue_tag_ids => [],
:assigner_ids => [])
end
end

View File

@ -0,0 +1,10 @@
class Api::V1::Projects::CollaboratorsController < Api::V1::BaseController
before_action :require_public_and_member_above, only: [:index]
def index
@collaborators = @project.all_collaborators.like(params[:keyword])
@collaborators = kaminary_select_paginate(@collaborators)
end
end

View File

@ -111,7 +111,9 @@ class IssuesController < ApplicationController
issue_params = issue_send_params(params)
Issues::CreateForm.new({subject: issue_params[:subject], description: issue_params[:description].blank? ? issue_params[:description] : issue_params[:description].b}).validate!
@issue = Issue.new(issue_params)
@issue.project_issues_index = @project.get_last_project_issues_index + 1
if @issue.save!
@project.del_project_issue_cache_delete_count
SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id) if Site.has_notice_menu?
SendTemplateMessageJob.perform_later('ProjectIssue', current_user.id, @issue&.id) if Site.has_notice_menu?
if params[:attachment_ids].present?
@ -302,6 +304,7 @@ class IssuesController < ApplicationController
login = @issue.user.try(:login)
SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, @issue&.subject, @issue.assigned_to_id, @issue.author_id) if Site.has_notice_menu?
if @issue.destroy
@project.incre_project_issue_cache_delete_count
if issue_type == "2" && status_id != 5
post_to_chain("add", token, login)
end

View File

@ -34,8 +34,12 @@ class SendTemplateMessageJob < ApplicationJob
operator_id, issue_id = args[0], args[1]
operator = User.find_by_id(operator_id)
issue = Issue.find_by_id(issue_id)
return unless operator.present? && issue.present?
receivers = User.where(id: issue&.assigned_to_id).where.not(id: operator&.id)
return unless operator.present? && issue.present?
if args[2].present?
receivers = User.where(id: args[2]).where.not(id: operator&.id)
else
receivers = User.where(id: issue&.assigned_to_id).where.not(id: operator&.id)
end
receivers_string, content, notification_url = MessageTemplate::IssueAssigned.get_message_content(receivers, operator, issue)
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, issue_id: issue.id})
receivers.find_each do |receiver|
@ -78,7 +82,11 @@ class SendTemplateMessageJob < ApplicationJob
operator_id, issue_title, issue_assigned_to_id, issue_author_id = args[0], args[1], args[2], args[3]
operator = User.find_by_id(operator_id)
return unless operator.present?
receivers = User.where(id: [issue_assigned_to_id, issue_author_id]).where.not(id: operator&.id)
if issue_assigned_to_id.is_a?(Array)
receivers = User.where(id: issue_assigned_to_id.append(issue_author_id)).where.not(id: operator&.id)
else
receivers = User.where(id: [issue_assigned_to_id, issue_author_id]).where.not(id: operator&.id)
end
receivers_string, content, notification_url = MessageTemplate::IssueDeleted.get_message_content(receivers, operator, issue_title)
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, issue_title: issue_title})
receivers.find_each do |receiver|

View File

@ -68,12 +68,24 @@ class Issue < ApplicationRecord
has_many :issue_tags, through: :issue_tags_relates
has_many :issue_times, dependent: :destroy
has_many :issue_depends, dependent: :destroy
has_many :issue_assigners, dependent: :destroy
has_many :assigners, through: :issue_assigners
has_many :issue_participants, dependent: :destroy
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 :show_assigners, -> {joins(:issue_assigners).distinct}, through: :issue_assigners, source: :assigner
has_many :show_issue_tags, -> {joins(:issue_tags_relates).distinct}, through: :issue_tags_relates, source: :issue_tag
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
scope :issue_includes, ->{includes(:user)}
scope :issue_many_includes, ->{includes(journals: :user)}
scope :issue_issue, ->{where(issue_classify: [nil,"issue"])}
scope :issue_pull_request, ->{where(issue_classify: "pull_request")}
scope :issue_index_includes, ->{includes(:tracker, :priority, :version, :issue_status, :journals,:issue_tags,user: :user_extension)}
scope :closed, ->{where(status_id: 5)}
scope :opened, ->{where.not(status_id: 5)}
after_create :incre_project_common, :incre_user_statistic, :incre_platform_statistic
after_save :change_versions_count, :send_update_message_to_notice_system
after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic

View File

@ -0,0 +1,20 @@
# == Schema Information
#
# Table name: issue_assigners
#
# id :integer not null, primary key
# issue_id :integer
# assigner_id :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_issue_assigners_on_assigner_id (assigner_id)
# index_issue_assigners_on_issue_id (issue_id)
#
class IssueAssigner < ApplicationRecord
belongs_to :issue
belongs_to :assigner, class_name: "User"
end

View File

@ -0,0 +1,9 @@
class IssueParticipant < ApplicationRecord
belongs_to :issue
belongs_to :participant, class_name: "User"
enum participant_type: {"authored": 0, "assigned": 1, "commented": 2, "edited": 3, "atme": 4}
end

View File

@ -15,4 +15,21 @@
class IssuePriority < ApplicationRecord
has_many :issues
def self.init_data
map = {
"1" => "",
"2" => "正常",
"3" => "",
"4" => "紧急"
}
IssuePriority.order(id: :asc).each do |prty|
if map["#{prty.id}"] == prty.name
IssuePriority.find_or_create_by(id: prty.id, name: prty.name)
else
Issue.where(priority_id: prty.id).each{|i| i.update_column(:priority_id, 2)}
prty.destroy!
end
end
end
end

View File

@ -20,10 +20,28 @@ class IssueStatus < ApplicationRecord
ADD = 1
SOLVING = 2
SOLVED = 3
FEEDBACK = 4
# FEEDBACK = 4
CLOSED = 5
REJECTED = 6
has_many :issues
belongs_to :project, optional: true
def self.init_data
map = {
"1" => "新增",
"2" => "正在解决",
"3" => "已解决",
"5" => "关闭",
"6" => "拒绝"
}
IssueStatus.order(id: :asc).each do |stat|
if map["#{stat.id}"] == stat.name
IssueStatus.find_or_create_by(id: stat.id, name: stat.name)
else
Issue.where(status_id: stat.id).each{|i| i.update_column(:status_id, 1)}
stat.destroy!
end
end
end
end

View File

@ -23,6 +23,34 @@ class IssueTag < ApplicationRecord
has_many :issue_tags_relates, dependent: :destroy
has_many :issues, through: :issue_tags_relates
has_many :issue_issues, -> {where(issue_classify: [nil,"issue"])}, source: :issue, through: :issue_tags_relates
has_many :pull_request_issues, -> {where(issue_classify: "pull_request")}, source: :issue, through: :issue_tags_relates
belongs_to :project, optional: true, counter_cache: true
belongs_to :user, optional: true
def self.init_data(project_id)
data = [
["缺陷", "表示项目存在问题", "#d92d4c"],
["功能", "表示新功能申请", "#ee955a"],
["疑问", "表示存在的问题", "#2d6ddc"],
["支持", "表示特定功能或特定需求", "#019549"],
["任务", "表示需要分配的任务", "#c1a30d"],
["协助", "表示需要社区用户协助", "#2a0dc1"],
["搁置", "表示此问题暂时不会继续处理", "#892794"],
["文档", "表示文档材料补充", "#9ed600"],
["测试", "表示需要测试的需求", "#2897b9"],
["重复", "表示已存在类似的疑修", "#bb5332"]
]
data.each do |item|
next if IssueTag.exists?(project_id: project_id, name: item[0])
IssueTag.create!(project_id: project_id, name: item[0], description: item[1], color: item[2])
end
$redis_cache.hset("project_init_issue_tags", project_id, 1)
end
def reset_counter_field
self.update_column(:issues_count, issue_issues.size)
self.update_column(:pull_requests_count, pull_request_issues.size)
end
end

View File

@ -15,5 +15,29 @@
class IssueTagsRelate < ApplicationRecord
belongs_to :issue
belongs_to :issue_tag, counter_cache: :issues_count
belongs_to :issue_tag
after_create :increment_issue_tags_counter_cache
after_destroy :decrement_issue_tags_counter_cache
def increment_issue_tags_counter_cache
Rails.logger.info "11111"
Rails.logger.info self.issue.issue_classify
if self.issue.issue_classify == "issue"
IssueTag.increment_counter :issues_count, issue_tag_id
else
IssueTag.increment_counter :pull_requests_count, issue_tag_id
end
end
def decrement_issue_tags_counter_cache
Rails.logger.info "2222222"
Rails.logger.info self.issue.issue_classify
if self.issue.issue_classify == "issue"
IssueTag.decrement_counter :issues_count, issue_tag_id
else
IssueTag.decrement_counter :pull_requests_count, issue_tag_id
end
end
end

View File

@ -40,9 +40,12 @@ class Journal < ApplicationRecord
belongs_to :journalized, polymorphic: true
belongs_to :review, optional: true
belongs_to :resolveer, class_name: 'User', foreign_key: :resolveer_id, optional: true
belongs_to :parent_journal, class_name: 'Journal', foreign_key: :parent_id, optional: true, counter_cache: :comments_count
belongs_to :reply_journal, class_name: 'Journal', foreign_key: :reply_id, optional: true
has_many :journal_details, :dependent => :delete_all
has_many :attachments, as: :container, dependent: :destroy
has_many :children_journals, class_name: 'Journal', foreign_key: :parent_id
has_many :first_ten_children_journals, -> { order(created_on: :asc).limit(10)}, class_name: 'Journal', foreign_key: :parent_id
has_many :children_journals, class_name: 'Journal', foreign_key: :parent_id, dependent: :destroy
scope :journal_includes, ->{includes(:user, :journal_details, :attachments)}
scope :parent_journals, ->{where(parent_id: nil)}
@ -54,6 +57,81 @@ class Journal < ApplicationRecord
self.notes.blank? && self.journal_details.present?
end
def operate_content
content = ""
detail = self.journal_details.take
case detail.property
when 'issue'
return "创建了<b>疑修</b>"
when 'attachment'
old_value = Attachment.where(id: detail.old_value.split(",")).pluck(:filename).join("")
new_value = Attachment.where(id: detail.value.split(",")).pluck(:filename).join("")
if old_value.nil? || old_value.blank?
content += "添加了<b>#{new_value}</b>附件"
else
new_value = "" if new_value.blank?
content += "将附件由<b>#{old_value}</b>更改为<b>#{new_value}</b>"
end
when 'issue_tag'
old_value = IssueTag.where(id: detail.old_value.split(",")).pluck(:name, :color).map{|t| "<span style='color: #{t[1]}'>#{t[0]}</span>"}.join(" ")
new_value = IssueTag.where(id: detail.value.split(",")).pluck(:name, :color).map{|t| "<span style='color: #{t[1]}'>#{t[0]}</span>"}.join(" ")
if old_value.nil? || old_value.blank?
content += "添加了<b>#{new_value}</b>标记"
else
new_value = "" if new_value.blank?
content += "将标记由<b>#{old_value}</b>更改为<b>#{new_value}</b>"
end
when 'assigner'
old_value = User.where(id: detail.old_value.split(",")).pluck(:nickname).join("")
new_value = User.where(id: detail.value.split(",")).pluck(:nickname).join("")
if old_value.nil? || old_value.blank?
content += "添加负责人<b>#{new_value}</b>"
else
new_value = "" if new_value.blank?
content += "将负责人由<b>#{old_value}</b>更改为<b>#{new_value}</b>"
end
when 'attr'
content = ""
case detail.prop_key
when 'subject'
return "修改了<b>标题</b>"
when 'description'
return "修改了<b>描述</b>"
when 'status_id'
old_value = IssueStatus.find_by_id(detail.old_value)&.name
new_value = IssueStatus.find_by_id(detail.value)&.name
content += "状态"
when 'priority_id'
old_value = IssuePriority.find_by_id(detail.old_value)&.name
new_value = IssuePriority.find_by_id(detail.value)&.name
content += "优先级"
when 'fixed_version_id'
old_value = Version.find_by_id(detail.old_value)&.name
new_value = Version.find_by_id(detail.value)&.name
content += "里程碑"
when 'branch_name'
old_value = detail.old_value
new_value = detail.value
content += "关联分支"
when 'start_date'
old_value = detail.old_value
new_value = detail.value
content += "开始日期"
when 'due_date'
old_value = detail.old_value
new_value = detail.value
content += "结束日期"
end
if old_value.nil? || old_value.blank?
content += "设置为<b>#{new_value}</b>"
else
new_value = "" if new_value.blank?
content += "由<b>#{old_value}</b>更改为<b>#{new_value}</b>"
end
end
end
def journal_content
send_details = []
if self.is_journal_detail?

View File

@ -424,4 +424,19 @@ class Project < ApplicationRecord
raise("项目名称包含敏感词汇,请重新输入") if name && !HarmoniousDictionary.clean?(name)
raise("项目描述包含敏感词汇,请重新输入") if description && !HarmoniousDictionary.clean?(description)
end
def get_last_project_issues_index
last_issue = self.issues.issue_issue.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 : 0
end
def incre_project_issue_cache_delete_count(count=1)
$redis_cache.hincrby("issue_cache_delete_count", self.id, count)
end
def del_project_issue_cache_delete_count
$redis_cache.hdel("issue_cache_delete_count", self.id)
end
end

View File

@ -175,6 +175,10 @@ class User < Owner
has_many :system_notifications, through: :system_notification_histories
has_one :trace_user, dependent: :destroy
has_many :feedbacks, dependent: :destroy
has_many :issue_assigners, foreign_key: :assigner_id
has_many :assigned_issues, through: :issue_assigners, source: :issue
has_many :issue_participants, foreign_key: :participant_id
has_many :participant_issues, through: :issue_participants, source: :issue
# Groups and active users
scope :active, lambda { where(status: STATUS_ACTIVE) }
scope :like, lambda { |keywords|

View File

@ -28,6 +28,9 @@ class Version < ApplicationRecord
has_many :issues, class_name: "Issue", foreign_key: "fixed_version_id"
belongs_to :user, optional: true
has_many :opened_issues, -> {where(issue_classify: "issue").where.not(status_id: 5)}, class_name: "Issue", foreign_key: :fixed_version_id
has_many :closed_issues, -> {where(issue_classify: "issue", status_id: 5)}, class_name: "Issue", foreign_key: :fixed_version_id
scope :version_includes, ->{includes(:issues, :user)}
scope :closed, ->{where(status: 'closed')}
scope :opening, ->{where(status: 'open')}
@ -43,6 +46,11 @@ class Version < ApplicationRecord
after_create :send_create_message_to_notice_system
after_save :send_update_message_to_notice_system
def issue_percent
issues_total_count = opened_issues.size + closed_issues.size
issues_total_count.zero? ? 0.0 : closed_issues.size.to_f / issues_total_count
end
def version_user
User.select(:login, :lastname,:firstname, :nickname)&.find_by_id(self.user_id)
end
@ -53,6 +61,6 @@ class Version < ApplicationRecord
end
def send_update_message_to_notice_system
SendTemplateMessageJob.perform_later('ProjectMilestoneCompleted', self.id) if Site.has_notice_menu? && self.percent == 1.0
SendTemplateMessageJob.perform_later('ProjectMilestoneCompleted', self.id) if Site.has_notice_menu? && self.issue_percent == 1.0
end
end

View File

@ -0,0 +1,38 @@
class Api::V1::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?
@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::V1::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
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::V1::Issues::UpdateService.call(project, issue, params, current_user)
end
end
return true
end
end
end

View File

@ -0,0 +1,48 @@
module Api::V1::Issues::Concerns::Checkable
def check_issue_status(status_id)
raise ApplicationService::Error, "IssueStatus不存在" unless IssueStatus.find_by_id(status_id).present?
end
def check_issue_priority(priority_id)
raise ApplicationService::Error, "IssuePriority不存在" unless IssuePriority.find_by_id(priority_id).present?
end
def check_milestone(milestone_id)
raise ApplicationService::Error, "Milestone不存在" unless Version.find_by_id(milestone_id).present?
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
issue_tag_ids.each do |tid|
raise ApplicationService::Error, "请输入正确的标记ID" unless IssueTag.exists?(id: tid)
end
end
def check_assigners(assigner_ids)
raise ApplicationService::Error, "请输入正确的负责人ID数组" unless assigner_ids.is_a?(Array)
raise ApplicationService::Error, "最多可选择5个负责人" if assigner_ids.size > 5
assigner_ids.each do |aid|
raise ApplicationService::Error, "请输入正确的负责人ID" unless User.exists?(id: aid)
end
end
def check_attachments (attachment_ids)
raise ApplicationService::Error, "请输入正确的附件ID数组" unless attachment_ids.is_a?(Array)
attachment_ids.each do |aid|
raise ApplicationService::Error, "请输入正确的附件ID" unless Attachment.exists?(id: aid)
end
end
def check_atme_receivers(receivers_login)
raise ApplicationService::Error, "请输入正确的用户标识数组!" unless receivers_login.is_a?(Array)
receivers_login.each do |rlogin|
raise ApplicationService::Error, "请输入正确的用户标识!" unless User.exists?(login: rlogin)
end
end
def check_parent_journal(parent_id)
raise ApplicationService::Error, "ParentJournal不存在" unless Journal.find_by_id(parent_id).present?
end
end

View File

@ -0,0 +1,19 @@
module Api::V1::Issues::Concerns::Loadable
def load_assigners(assigner_ids)
@assigners = User.where(id: assigner_ids)
end
def load_issue_tags(issue_tag_ids)
@issue_tags = IssueTag.where(id: issue_tag_ids)
end
def load_attachments(attachment_ids)
@attachments = Attachment.where(id: attachment_ids)
end
def load_atme_receivers(receivers_login)
@atme_receivers = User.where(login: receivers_login)
end
end

View File

@ -0,0 +1,126 @@
class Api::V1::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
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
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]
@issue_tag_ids = params[:issue_tag_ids]
@assigner_ids = params[:assigner_ids]
@attachment_ids = params[:attachment_ids]
@receivers_login = params[:receivers_login]
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?
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::V1::Issues::CreateService:#{project.id}") # 开始写数据,加锁
@created_issue = Issue.new(issue_attributes)
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.issue_tags_value = @issue_tags.order("id asc").pluck(:id).join(",") unless issue_tag_ids.blank?
@created_issue.save!
project.del_project_issue_cache_delete_count # 把缓存里存储项目删除issue的个数清除掉
# @信息发送
AtmeService.call(current_user, @atme_receivers, @created_issue) unless receivers_login.blank?
# 发消息
if Site.has_notice_menu?
SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id, assigner_ids) unless assigner_ids.blank?
SendTemplateMessageJob.perform_later('ProjectIssue', current_user.id, @issue&.id)
end
unlock("Api::V1::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
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
@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: ''})
end
end

View File

@ -0,0 +1,37 @@
class Api::V1::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}") # 开始写数据,加锁
delete_issue
project.incre_project_issue_cache_delete_count
if Site.has_notice_menu?
SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, @issue&.subject, @issue.assigners.pluck(:id), @issue.author_id)
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,42 @@
class Api::V1::Issues::Journals::ChildrenListService < ApplicationService
include ActiveModel::Model
attr_reader :issue, :journal, :keyword, :sort_by, :sort_direction
attr_accessor :queried_journals
validates :sort_by, inclusion: {in: Journal.column_names, message: '请输入正确的SortBy'}, allow_blank: true
validates :sort_direction, inclusion: {in: %w(asc desc), message: '请输入正确的SortDirection'}, allow_blank: true
def initialize(issue, journal, params, current_user=nil)
@issue = issue
@journal = journal
@keyword = params[:keyword]
@sort_by = params[:sort_by].present? ? params[:sort_by] : 'created_on'
@sort_direction = (params[:sort_direction].present? ? params[:sort_direction] : 'asc').downcase
end
def call
raise Error, errors.full_messages.join(", ") unless valid?
begin
journal_query_data
return @queried_journals
rescue
raise Error, "服务器错误,请联系系统管理员!"
end
end
private
def journal_query_data
@queried_journals = journal.children_journals
@queried_journals = @queried_journals.ransack(notes_cont: keyword).result if keyword.present?
@queried_journals = @queried_journals.includes(:user, :attachments, :reply_journal)
@queried_journals = @queried_journals.reorder("journals.#{sort_by} #{sort_direction}").distinct
@queried_journals
end
end

View File

@ -0,0 +1,75 @@
class Api::V1::Issues::Journals::CreateService < ApplicationService
include ActiveModel::Model
include Api::V1::Issues::Concerns::Checkable
include Api::V1::Issues::Concerns::Loadable
attr_reader :issue, :current_user, :notes, :parent_id, :reply_id, :attachment_ids, :receivers_login
attr_accessor :created_journal, :atme_receivers
validates :notes, :issue, :current_user, presence: true
def initialize(issue, params, current_user=nil)
@issue = issue
@notes = params[:notes]
@parent_id = params[:parent_id]
@reply_id = params[:reply_id]
@attachment_ids = params[:attachment_ids]
@receivers_login = params[:receivers_login]
@current_user = current_user
end
def call
raise Error, errors.full_messages.join(", ") unless valid?
raise Error, "请输入回复的评论ID" if parent_id.present? && !reply_id.present?
ActiveRecord::Base.transaction do
check_parent_journal(parent_id) if parent_id.present?
check_parent_journal(reply_id) if reply_id.present?
check_attachments(attachment_ids) unless attachment_ids.nil?
check_atme_receivers(receivers_login) unless receivers_login.nil?
load_attachments(attachment_ids) unless attachment_ids.nil?
load_atme_receivers(receivers_login) unless receivers_login.nil?
try_lock("Api::V1::Issues::Journals::CreateService:#{@issue.id}")
@created_journal = @issue.journals.new(journal_attributes)
build_comment_participants
build_atme_participants if @atme_receivers.present?
@created_journal.attachments = @attachments unless attachment_ids.blank?
@created_journal.save!
@issue.save!
# @信息发送
AtmeService.call(current_user, @atme_receivers, @created_journal) unless receivers_login.blank?
unlock("Api::V1::Issues::Journals::CreateService:#{@issue.id}")
@created_journal
end
end
private
def journal_attributes
journal_attributes = {
notes: notes,
user_id: current_user.id
}
journal_attributes.merge!({parent_id: parent_id}) if parent_id.present?
journal_attributes.merge!({reply_id: reply_id}) if reply_id.present?
journal_attributes
end
def build_comment_participants
@issue.issue_participants.new({participant_type: "commented", participant_id: current_user.id}) unless @issue.issue_participants.exists?(participant_type: "commented", participant_id: current_user.id)
end
def build_atme_participants
@atme_receivers.each do |receiver|
next if @issue.issue_participants.exists?(participant_type: "atme", participant_id: receiver.id)
@issue.issue_participants.new({participant_type: "atme", participant_id: receiver.id})
end
end
end

View File

@ -0,0 +1,52 @@
class Api::V1::Issues::Journals::ListService < ApplicationService
include ActiveModel::Model
attr_reader :issue, :category, :keyword, :sort_by, :sort_direction
attr_accessor :queried_journals
validates :category, inclusion: {in: %w(all comment operate), message: "请输入正确的Category"}
validates :sort_by, inclusion: {in: Journal.column_names, message: '请输入正确的SortBy'}, allow_blank: true
validates :sort_direction, inclusion: {in: %w(asc desc), message: '请输入正确的SortDirection'}, allow_blank: true
def initialize(issue, params, current_user=nil)
@issue = issue
@keyword = params[:keyword]
@category = params[:category] || 'all'
@sort_by = params[:sort_by].present? ? params[:sort_by] : 'created_on'
@sort_direction = (params[:sort_direction].present? ? params[:sort_direction] : 'asc').downcase
end
def call
raise Error, errors.full_messages.join(", ") unless valid?
begin
journal_query_data
@queried_journals
rescue
raise Error, "服务器错误,请联系系统管理员!"
end
end
private
def journal_query_data
@queried_journals = issue.journals
case category
when 'comment'
@queried_journals = issue.comment_journals
when 'operate'
@queried_journals = issue.operate_journals
end
@queried_journals = @queried_journals.parent_journals
@queried_journals = @queried_journals.ransack(notes_cont: keyword).result if keyword.present?
@queried_journals = @queried_journals.includes(:journal_details, :user, :attachments, first_ten_children_journals: [:parent_journal, :reply_journal])
@queried_journals = @queried_journals.reorder("journals.#{sort_by} #{sort_direction}").distinct
@queried_journals
end
end

View File

@ -0,0 +1,57 @@
class Api::V1::Issues::Journals::UpdateService < ApplicationService
include ActiveModel::Model
include Api::V1::Issues::Concerns::Checkable
include Api::V1::Issues::Concerns::Loadable
attr_reader :issue, :journal, :current_user, :notes, :attachment_ids, :receivers_login
attr_accessor :updated_journal, :atme_receivers
validates :notes, :issue, :journal, :current_user, presence: true
def initialize(issue, journal, params, current_user=nil)
@issue = issue
@journal = journal
@notes = params[:notes]
@attachment_ids = params[:attachment_ids]
@receivers_login = params[:receivers_login]
@current_user = current_user
end
def call
raise Error, errors.full_messages.join(", ") unless valid?
ActiveRecord::Base.transaction do
check_attachments(attachment_ids) unless attachment_ids.nil?
check_atme_receivers(receivers_login) unless receivers_login.nil?
load_attachments(attachment_ids) unless attachment_ids.nil?
load_atme_receivers(receivers_login) unless receivers_login.nil?
try_lock("Api::V1::Issues::Journals::UpdateService:#{@issue.id}:#{@journal.id}")
@updated_journal = @journal
@updated_journal.notes = notes
build_atme_participants if @atme_receivers.present?
@updated_journal.attachments = @attachments unless attachment_ids.nil?
@updated_journal.save!
@issue.save!
# @信息发送
AtmeService.call(current_user, @atme_receivers, @created_journal) unless receivers_login.blank?
unlock("Api::V1::Issues::Journals::UpdateService:#{@issue.id}:#{@journal.id}")
@updated_journal
end
end
private
def build_atme_participants
@atme_receivers.each do |receiver|
next if @issue.issue_participants.exists?(participant_type: "atme", participant_id: receiver.id)
@issue.issue_participants.new({participant_type: "atme", participant_id: receiver.id})
end
end
end

View File

@ -0,0 +1,91 @@
class Api::V1::Issues::ListService < ApplicationService
include ActiveModel::Model
attr_reader :project, :category, :participant_category, :keyword, :author_id, :issue_tag_ids
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
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', 'issue_priorities.position'], 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)
@project = project
@category = params[:category] || 'all'
@participant_category = params[:participant_category] || 'all'
@keyword = params[:keyword]
@author_id = params[:author_id]
@issue_tag_ids = params[:issue_tag_ids].present? ? params[:issue_tag_ids].split(",") : []
@milestone_id = params[:milestone_id]
@assigner_id = params[:assigner_id]
@status_id = params[:status_id]
@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?
# begin
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}
# rescue
# raise Error, "服务器错误,请联系系统管理员!"
# end
end
private
def issue_query_data
issues = @project.issues.issue_issue
case participant_category
when 'aboutme' # 关于我的
issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: %w(authored assigned atme), participant_id: current_user&.id})
when 'authoredme' # 我创建的
issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: 'authored', participant_id: current_user&.id})
when 'assignedme' # 我负责的
issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: 'assigned', participant_id: current_user&.id})
when 'atme' # @我的
issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: 'atme', participant_id: current_user&.id})
end
# author_id
issues = issues.where(author_id: author_id) if author_id.present?
# issue_tag_ids
issues = issues.ransack(issue_tags_value_cont: issue_tag_ids.sort!.join(",")).result unless issue_tag_ids.blank?
# milestone_id
issues = issues.where(fixed_version_id: milestone_id) if milestone_id.present?
# assigner_id
issues = issues.joins(:assigners).where(users: {id: assigner_id}) if assigner_id.present?
# status_id
issues = issues.where(status_id: status_id) if status_id.present?
# keyword
issues = 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
case category
when 'closed'
issues = issues.closed
when 'opened'
issues = issues.opened
end
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

@ -0,0 +1,65 @@
class Api::V1::Issues::Milestones::DetailIssuesService < ApplicationService
include ActiveModel::Model
attr_reader :project, :category, :author_id, :assigner_id, :issue_tag_ids, :sort_by, :sort_direction, :current_user
attr_accessor :queried_issues, :total_issues_count, :closed_issues_count, :opened_issues_count
validates :category, inclusion: {in: %w(all opened closed), message: "请输入正确的Category"}
validates :sort_by, inclusion: {in: ['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 :current_user, presence: true
def initialize(project, milestone, params, current_user=nil)
@project = project
@milestone = milestone
@category = params[:category] || 'all'
@author_id = params[:author_id]
@assigner_id = params[:assigner_id]
@issue_tag_ids = params[:issue_tag_ids].present? ? params[:issue_tag_ids].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?
begin
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}
rescue
raise Error, "服务器错误,请联系系统管理员!"
end
end
private
def issue_query_data
issues = @milestone.issues.issue_issue
# author_id
issues = issues.where(author_id: author_id) if author_id.present?
# assigner_id
issues = issues.joins(:assigners).where(users: {id: assigner_id}).or(issues.joins(:assigners).where(assigned_to_id: assigner_id)) if assigner_id.present?
issues = issues.ransack(issue_tags_value_cont: issue_tag_ids.sort!.join(",")).result unless issue_tag_ids.blank?
@total_issues_count = issues.distinct.size
@closed_issues_count = issues.closed.distinct.size
@opened_issues_count = issues.opened.distinct.size
case category
when 'closed'
issues = issues.closed
when 'opened'
issues = issues.opened
end
scope = issues.includes(:priority, :issue_status, :user, :show_assigners, :version, :show_issue_tags, :comment_journals).references(:assigners)
scope = scope.reorder("#{sort_by} #{sort_direction}").distinct
@queried_issues = scope
end
end

View File

@ -0,0 +1,240 @@
class Api::V1::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
attr_reader :issue_tag_ids, :assigner_ids, :attachment_ids, :receivers_login
attr_accessor :add_assigner_ids, :previous_issue_changes, :updated_issue, :atme_receivers
validates :project, :issue, :current_user, presence: 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]
@issue_tag_ids = params[:issue_tag_ids]
@assigner_ids = params[:assigner_ids]
@attachment_ids = params[:attachment_ids]
@receivers_login = params[:receivers_login]
@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_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?
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::V1::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?
@updated_issue.assigners = @assigners || User.none unless assigner_ids.nil?
@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?
@updated_issue.updated_on = Time.now
@updated_issue.save!
build_after_issue_journal_details if @updated_issue.previous_changes.present? # 操作记录
build_previous_issue_changes
# @信息发送
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
unlock("Api::V1::Issues::UpdateService:#{project.id}:#{issue.id}")
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 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 = @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
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_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: "attr", 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["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
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 & assigner_ids).empty? || !(now_assigner_ids.empty? && new_assigner_ids.empty?)
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 & new_issue_tag_ids).empty? || !(now_issue_tag_ids.empty? && new_issue_tag_ids.empty?)
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 & new_attachment_ids).empty? || !(now_attachment_ids.empty? && new_attachment_ids.empty?)
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

@ -9,6 +9,15 @@ class ApplicationService
content.gsub(regex, '')
end
protected
def try_lock(key)
raise Error, "请稍后再试!" unless $redis_cache.set(key, 1, nx: true, ex: 60.seconds)
end
def unlock(key)
$redis_cache.del(key)
end
private
def strip(str)

View File

@ -14,6 +14,7 @@ class Projects::CreateService < ApplicationService
ActiveRecord::Base.transaction do
if @project.save!
Project.update_common_projects_count!
IssueTag.init_data(@project.id)
ProjectUnit.init_types(@project.id)
Repositories::CreateService.new(user, @project, repository_params).call
upgrade_project_category_private_projects_count

View File

@ -0,0 +1,7 @@
json.id attachment.id
json.title attachment.title
json.filesize number_to_human_size(attachment.filesize)
json.is_pdf attachment.is_pdf?
json.url attachment.is_pdf? ? download_url(attachment,disposition:"inline") : download_url(attachment)
json.created_on attachment.created_on.strftime("%Y-%m-%d %H:%M")
json.content_type attachment.content_type

View File

@ -0,0 +1,45 @@
json.(issue, :id, :subject, :project_issues_index, :description, :branch_name, :start_date, :due_date)
json.created_at issue.created_on.strftime("%Y-%m-%d %H:%M")
json.updated_at issue.updated_on.strftime("%Y-%m-%d %H:%M")
json.tags issue.show_issue_tags.each do |tag|
json.partial! "api/v1/issues/issue_tags/simple_detail", locals: {tag: tag}
end
json.status do
if issue.issue_status.present?
json.partial! "api/v1/issues/statues/simple_detail", locals: {status: issue.issue_status}
else
json.nil!
end
end
json.priority do
if issue.priority.present?
json.partial! "api/v1/issues/issue_priorities/simple_detail", locals: {priority: issue.priority}
else
json.nil!
end
end
json.milestone do
if issue.version.present?
json.partial! "api/v1/issues/milestones/simple_detail", locals: {milestone: issue.version}
else
json.nil!
end
end
json.author do
if issue.user.present?
json.partial! "api/v1/users/simple_user", locals: {user: issue.user}
else
json.nil!
end
end
json.assigners issue.show_assigners.each do |assigner|
json.partial! "api/v1/users/simple_user", locals: {user: assigner}
end
json.participants issue.participants.distinct.each do |participant|
json.partial! "api/v1/users/simple_user", locals: {user: participant}
end
json.comment_journals_count issue.comment_journals.size
json.operate_journals_count issue.operate_journals.size
json.attachments issue.attachments.each do |attachment|
json.partial! "api/v1/attachments/simple_detail", locals: {attachment: attachment}
end

View File

@ -0,0 +1,20 @@
json.(issue, :id, :subject, :project_issues_index)
json.created_at issue.created_on.strftime("%Y-%m-%d %H:%M")
json.updated_at issue.updated_on.strftime("%Y-%m-%d %H:%M")
json.tags issue.show_issue_tags.each do |tag|
json.partial! "api/v1/issues/issue_tags/simple_detail", locals: {tag: tag}
end
json.status_name issue.issue_status&.name
json.priority_name issue.priority&.name
json.milestone_name issue.version&.name
json.author do
if issue.user.present?
json.partial! "api/v1/users/simple_user", locals: {user: issue.user}
else
json.nil!
end
end
json.assigners issue.show_assigners.each do |assigner|
json.partial! "api/v1/users/simple_user", locals: {user: assigner}
end
json.comment_journals_count issue.comment_journals.size

View File

@ -0,0 +1,4 @@
json.total_count @assigners.total_count
json.assigners @assigners.each do |assigner|
json.partial! 'api/v1/users/simple_user', locals: { user: assigner}
end

View File

@ -0,0 +1,4 @@
json.total_count @authors.total_count
json.authors @authors.each do |author|
json.partial! 'api/v1/users/simple_user', locals: { user: author}
end

View File

@ -0,0 +1 @@
json.partial! "api/v1/issues/detail", locals: {issue: @object_result}

View File

@ -0,0 +1,8 @@
json.total_issues_count @total_issues_count
json.opened_count @opened_issues_count
json.closed_count @closed_issues_count
json.total_count @issues.total_count
json.has_created_issues @project.issues.size > 0
json.issues @issues.each do |issue|
json.partial! "simple_detail", locals: {issue: issue}
end

View File

@ -0,0 +1 @@
json.(priority, :id, :name)

View File

@ -0,0 +1,4 @@
json.total_count @priorities.total_count
json.priorities @priorities.each do |priority|
json.partial! "simple_detail", locals: {priority: priority}
end

View File

@ -0,0 +1,19 @@
json.(tag,:id, :name, :description, :color)
json.issues_count tag.issues_count
json.pull_requests_count tag.pull_requests_count
json.project do
if tag.project.present?
json.partial! "api/v1/projects/simple_detail", project: tag.project
else
json.nil!
end
end
json.user do
if tag.user.present?
json.partial! "api/v1/users/simple_user", user: tag.user
else
json.nil!
end
end
json.created_at tag.created_at.strftime("%Y-%m-%d %H:%M")
json.updated_at tag.updated_at.strftime("%Y-%m-%d %H:%M")

View File

@ -0,0 +1 @@
json.(tag, :id, :name, :color)

View File

@ -0,0 +1,8 @@
json.total_count @issue_tags.total_count
json.issue_tags @issue_tags.each do |tag|
if params[:only_name]
json.partial! "simple_detail", locals: {tag: tag}
else
json.partial! "detail", locals: {tag: tag}
end
end

View File

@ -0,0 +1,20 @@
json.(journal, :id, :notes, :comments_count)
json.created_at journal.created_on.strftime("%Y-%m-%d %H:%M")
json.updated_at journal.updated_on.strftime("%Y-%m-%d %H:%M")
json.user do
if journal.user.present?
json.partial! "api/v1/users/simple_user", user: journal.user
else
json.nil!
end
end
json.reply_user do
if journal.reply_journal&.user&.present?
json.partial! "api/v1/users/simple_user", user: journal.reply_journal.user
else
json.nil!
end
end
json.attachments journal.attachments.each do |attachment|
json.partial! "api/v1/attachments/simple_detail", locals: {attachment: attachment}
end

View File

@ -0,0 +1,25 @@
json.id journal.id
json.is_journal_detail journal.is_journal_detail?
json.created_at journal.created_on.strftime("%Y-%m-%d %H:%M")
json.updated_at journal.updated_on.strftime("%Y-%m-%d %H:%M")
json.user do
if journal.user.present?
json.partial! "api/v1/users/simple_user", user: journal.user
else
json.nil!
end
end
if journal.is_journal_detail?
detail = journal.journal_details.take
json.operate_category detail.property == "attr" ? detail.prop_key : detail.property
json.operate_content journal.is_journal_detail? ? journal.operate_content : nil
else
json.notes journal.notes
json.comments_count journal.comments_count
json.children_journals journal.first_ten_children_journals.each do |journal|
json.partial! "children_detail", journal: journal
end
json.attachments journal.attachments do |attachment|
json.partial! "api/v1/attachments/simple_detail", locals: {attachment: attachment}
end
end

View File

@ -0,0 +1,4 @@
json.total_count @journals.total_count
json.journals @journals do |journal|
json.partial! "children_detail", journal: journal
end

View File

@ -0,0 +1 @@
json.partial! "detail", journal: @object_result

View File

@ -0,0 +1,4 @@
json.total_count @journals.total_count
json.journals @journals do |journal|
json.partial! "detail", journal: journal
end

View File

@ -0,0 +1 @@
json.partial! "detail", journal: @object_result

View File

@ -0,0 +1,7 @@
json.(milestone, :id, :name, :description, :effective_date, :status)
json.issues_count milestone.opened_issues.size + milestone.closed_issues.size
json.opened_issues_count milestone.opened_issues.size
json.close_issues_count milestone.closed_issues.size
json.percent milestone.issue_percent
json.created_at milestone.created_on.strftime("%Y-%m-%d %H:%M")
json.updated_on milestone.updated_on.strftime("%Y-%m-%d %H:%M")

View File

@ -0,0 +1 @@
json.(milestone, :id, :name)

View File

@ -0,0 +1,10 @@
json.closed_milestone_count @closed_milestone_count
json.opening_milestone_count @opening_milestone_count
json.total_count @milestones.total_count
json.milestones @milestones.each do |milestone|
if params[:only_name]
json.partial! "simple_detail", locals: {milestone: milestone}
else
json.partial! "detail", locals: {milestone: milestone}
end
end

View File

@ -0,0 +1,12 @@
json.milestone do
json.partial! "detail", locals: {milestone: @milestone}
end
json.total_issues_count @total_issues_count
json.closed_issues_count @closed_issues_count
json.opened_issues_count @opened_issues_count
json.total_count @issues.total_count
json.issues @issues.each do |issue|
if issue.issue_classify == "issue"
json.partial! "api/v1/issues/simple_detail", locals: {issue: issue}
end
end

View File

@ -0,0 +1,2 @@
json.partial! "api/v1/issues/detail", locals: {issue: @issue}
json.user_permission @user_permission

View File

@ -0,0 +1 @@
json.(status, :id, :name)

View File

@ -0,0 +1,4 @@
json.total_count @statues.total_count
json.statues @statues.each do |status|
json.partial! "simple_detail", locals: {status: status}
end

View File

@ -0,0 +1 @@
json.partial! "api/v1/issues/detail", locals: {issue: @object_result}

View File

@ -0,0 +1,4 @@
json.total_count @collaborators.total_count
json.collaborators @collaborators.each do |collaborator|
json.partial! "api/v1/users/simple_user", locals: {user: collaborator}
end

View File

@ -25,9 +25,31 @@ defaults format: :json do
end
end
resources :issues, param: :index, except: [:new, :edit] do
collection do
patch :batch_update
delete :batch_destroy
end
member do
resources :journals, module: :issues, only: [:index, :create, :update, :destroy] do
member do
get :children_journals
end
end
end
end
scope module: :issues do
resources :issue_tags, except: [:new, :edit]
resources :milestones, except: [:new, :edit]
resources :issue_statues, only: [:index], controller: '/api/v1/issues/statues'
resources :issue_authors, only: [:index], controller: '/api/v1/issues/authors'
resources :issue_assigners, only: [:index], controller: '/api/v1/issues/assigners'
resources :issue_priorities, only: [:index]
end
# projects文件夹下的
scope module: :projects do
resources :issues
resources :pulls, module: 'pulls' do
resources :versions, only: [:index] do
member do
@ -37,8 +59,7 @@ defaults format: :json do
resources :journals, except: [:show, :edit]
resources :reviews, only: [:index, :create]
end
resources :versions
resources :collaborators, only: [:index]
resources :release_versions
resources :webhooks do
member do

View File

@ -0,0 +1,10 @@
class CreateIssueAssigners < ActiveRecord::Migration[5.2]
def change
create_table :issue_assigners do |t|
t.references :issue
t.references :assigner, references: :user
t.timestamps
end
end
end

View File

@ -0,0 +1,11 @@
class CreateIssueParticipants < ActiveRecord::Migration[5.2]
def change
create_table :issue_participants do |t|
t.references :issue
t.references :participant, references: :user
t.integer :participant_type, default: 0
t.timestamps
end
end
end

View File

@ -0,0 +1,5 @@
class AddSomeColumnsToIssueUpgrade < ActiveRecord::Migration[5.2]
def change
add_column :issue_tags, :pull_requests_count, :integer, default: 0
end
end

View File

@ -0,0 +1,59 @@
namespace :upgrade_issue_generate_data do
# 执行示例 bundle exec rake upgrade_issue_generate_data:project_issues_index
# 线上环境执行示例 RAILS_ENV=production bundle exec rake upgrade_issue_generate_data:project_issues_index
desc "upgrade_issue_generate_data: fix issue project_issues_index"
task project_issues_index: :environment do
puts "____________fix start________________"
Issue.issue_issue.update_all(project_issues_index: nil)
count = 0
Issue.issue_issue.where(project_issues_index: nil).group(:project_id).count.each do |pid, count|
p = Project.find_by_id(pid)
issues = p.issues.order(created_on: :asc)
issues.find_each.with_index do |issue, index|
count += 1
issue.update_column(:project_issues_index, index+1)
end
end
puts "____________fix end_______total:#{count}_________"
end
# 执行示例 bundle exec rake upgrade_issue_generate_data:project_init_issue_tags_and_status
# 线上环境执行示例 RAILS_ENV=production bundle exec rake upgrade_issue_generate_data:project_init_issue_tags_and_status
desc "upgrade_issue_generate_data: fix project init issue_tags"
task project_init_issue_tags_and_status: :environment do
puts "____________fix start________________"
IssuePriority.init_data
IssueStatus.init_data
IssueTag.order(created_at: :desc).find_each do |it|
it.reset_counter_field
end
IssueTag.where(user_id: nil).destroy_all
count = 0
Project.order(created_on: :desc).find_each do |project|
count += 1
IssueTag.init_data(project.id)
end
puts "____________fix end____total:#{count}__________"
end
# 执行示例 bundle exec rake upgrade_issue_generate_data:build_assigners_and_participants
# 线上环境执行示例 RAILS_ENV=production bundle exec rake upgrade_issue_generate_data:build_assigners_and_participants
desc "upgrade_issue_generate_data: fix issue assigners and participants"
task build_assigners_and_participants: :environment do
puts "____________fix start________________"
count = 0
Issue.order(created_on: :desc).find_each do |issue|
count += 1
issue.issue_assigners.find_or_create_by(assigner_id: issue.assigned_to_id)
issue.issue_participants.find_or_create_by(participant_id: issue.assigned_to_id, participant_type: 'assigned')
issue.issue_participants.find_or_create_by(participant_id: issue.author_id, participant_type: 'authored')
end
puts "____________fix end____total:#{count}__________"
end
end