| @@ -17,7 +17,22 @@ class Api::V1::IssuesController < Api::V1::BaseController | |||
| end | |||
| def update | |||
| @object_result = Api::V1::Issues::EditService.call(@project, issue_params, current_user) | |||
| @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) | |||
| 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) | |||
| end | |||
| def batch_destroy | |||
| @object_result = Api::V1::Issues::BatchDeleteService.call(@project, @issues, current_user) | |||
| end | |||
| private | |||
| @@ -43,6 +58,13 @@ class Api::V1::IssuesController < Api::V1::BaseController | |||
| :attachment_ids => []) | |||
| end | |||
| def batch_issue_params | |||
| params.permit( | |||
| :status_id, :priority_id, :milestone_id, | |||
| :issue_tag_ids => [], | |||
| :assigner_ids => []) | |||
| end | |||
| def load_issue | |||
| @issue = @project.issues.where(project_issues_index: params[:id]).where.not(id: params[:id]).take || Issue.find_by_id(params[:id]) | |||
| if @issue.blank? | |||
| @@ -52,4 +74,17 @@ class Api::V1::IssuesController < Api::V1::BaseController | |||
| end | |||
| end | |||
| def load_issues | |||
| return render_error("请输入正确的ID数组!") unless params[:ids].is_a?(Array) | |||
| params[:ids].each do |id| | |||
| @issue = @project.issues.where(project_issues_index: id).where.not(id: id).take || Issue.find_by_id(id) | |||
| if @issue.blank? | |||
| return render_not_found("ID为#{id}的疑修不存在!") | |||
| elsif if @issue.present? && @issue.is_lock &&!(@project.member?(current_user) || current_user.admin?) | |||
| return render_forbidden("ID为#{id}的疑修您没有权限操作!") | |||
| end | |||
| end | |||
| @issues = @project.issues.where(project_issues_index: params[:ids]).where.not(id: params[:ids]) || Issue.where(id: params[:ids]) | |||
| end | |||
| end | |||
| @@ -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| | |||
| @@ -68,9 +68,9 @@ 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 | |||
| has_many :issue_assigners, dependent: :destroy | |||
| has_many :assigners, through: :issue_assigners | |||
| has_many :issue_participants | |||
| 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 :comment_journals, -> {where.not(notes: nil)}, class_name: "Journal", :as => :journalized | |||
| @@ -432,11 +432,11 @@ class Project < ApplicationRecord | |||
| last_issue&.project_issues_index.present? ? last_issue.project_issues_index + deleted_issue_count : 0 | |||
| end | |||
| def incre_project_issue_cache_delete_count | |||
| $redis_cache.hincrby("issue_cache_delete_count", self.id, 1) | |||
| 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 | |||
| def del_project_issue_cache_delete_count | |||
| $redis_cache.hdel("issue_cache_delete_count", self.id) | |||
| end | |||
| end | |||
| @@ -0,0 +1,41 @@ | |||
| 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 # 开始写数据,加锁 | |||
| 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 | |||
| end | |||
| private | |||
| def try_lock | |||
| raise Error, "请稍后再试!" unless $redis_cache.set("Api::V1::Issues::BatchDeleteService:#{project.id}", 1, nx: true, ex: 60.seconds) | |||
| end | |||
| def unlock | |||
| $redis_cache.del("Api::V1::Issues::BatchDeleteService:#{project.id}") | |||
| end | |||
| end | |||
| @@ -0,0 +1,29 @@ | |||
| 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| | |||
| Api::V1::Issues::UpdateService.call(project, issue, params, current_user) | |||
| end | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,45 @@ | |||
| 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 | |||
| end | |||
| @@ -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 | |||
| @@ -1,13 +1,16 @@ | |||
| class Api::V1::Issues::CreateService < ApplicationService | |||
| include ActiveModel::Model | |||
| include Api::V1::Issues::Concerns::Checkable | |||
| include Api::V1::Issues::Concerns::Loadable | |||
| attr_reader :project, :created_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 | |||
| 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 :current_user, presence: true | |||
| validates :project, :current_user, presence: true | |||
| def initialize(project, params, current_user = nil) | |||
| @project = project | |||
| @@ -23,87 +26,51 @@ class Api::V1::Issues::CreateService < ApplicationService | |||
| @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? | |||
| begin | |||
| ActiveRecord::Base.transaction do | |||
| check_issue_status | |||
| check_issue_priority | |||
| check_milestone if milestone_id.present? | |||
| check_issue_tags unless issue_tag_ids.blank? | |||
| check_assigners unless assigner_ids.blank? | |||
| check_attachments unless attachment_ids.blank? | |||
| load_assigners unless assigner_ids.blank? | |||
| load_attachments unless attachment_ids.blank? | |||
| load_issue_tags unless issue_tag_ids.blank? | |||
| @created_issue = Issue.new(issue_attributes) | |||
| @created_issue.assigners = @assigners unless assigner_ids.blank? | |||
| @created_issue.attachments = @attachments unless attachment_ids.blank? | |||
| @created_issue.issue_tags = @issue_tags unless issue_tag_ids.blank? | |||
| build_author_participants | |||
| build_assinger_participants unless assigner_ids.blank? | |||
| @created_issue.save! | |||
| project.del_project_issue_cache_delete_count # 把缓存里存储项目删除issue的个数清除掉 | |||
| end | |||
| 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_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 # 开始写数据,加锁 | |||
| @created_issue = Issue.new(issue_attributes) | |||
| build_author_participants | |||
| build_assigner_participants unless assigner_ids.blank? | |||
| build_issue_journal_details if @updated_issue.previous_changes.present? # 操作记录 | |||
| build_issue_project_trends if status_id.present? # 开关时间 | |||
| @created_issue.attachments = @attachments unless attachment_ids.blank? | |||
| @created_issue.issue_tags = @issue_tags unless issue_tag_ids.blank? | |||
| return @created_issue | |||
| rescue | |||
| raise Error, "服务器错误,请联系系统管理员!" | |||
| end | |||
| end | |||
| private | |||
| def check_issue_status | |||
| raise Error, "IssueStatus不存在!" unless IssueStatus.find_by_id(status_id).present? | |||
| end | |||
| def check_issue_priority | |||
| raise Error, "IssuePriority不存在!" unless IssuePriority.find_by_id(priority_id).present? | |||
| end | |||
| @created_issue.save! | |||
| project.del_project_issue_cache_delete_count # 把缓存里存储项目删除issue的个数清除掉 | |||
| def check_milestone | |||
| raise Error, "Milestone不存在!" unless Version.find_by_id(milestone_id).present? | |||
| end | |||
| # @信息发送 | |||
| AtmeService.call(current_user, @atme_receivers, @issue) unless receivers_login.blank? | |||
| def check_issue_tags | |||
| raise Error, "请输入正确的标记ID数组!" unless issue_tag_ids.is_a?(Array) | |||
| raise Error, "最多可选择3个标记" if issue_tag_ids.size > 3 | |||
| issue_tag_ids.each do |tid| | |||
| raise Error, "请输入正确的标记ID!" unless IssueTag.exists?(id: tid) | |||
| # 发消息 | |||
| 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 # 结束写数据,解锁 | |||
| end | |||
| return @created_issue | |||
| end | |||
| def check_assigners | |||
| raise Error, "请输入正确的负责人ID数组!" unless assigner_ids.is_a?(Array) | |||
| raise Error, "最多可选择5个负责人" if assigner_ids.size > 5 | |||
| assigner_ids.each do |aid| | |||
| raise Error, "请输入正确的负责人ID!" unless User.exists?(id: aid) | |||
| end | |||
| end | |||
| def check_attachments | |||
| raise Error, "请输入正确的附件ID数组!" unless assigner_ids.is_a?(Array) | |||
| attachment_ids.each do |aid| | |||
| raise Error, "请输入正确的附件ID!" unless Attachment.exists?(id: aid) | |||
| end | |||
| end | |||
| def load_assigners | |||
| @assigners = User.where(id: assigner_ids) | |||
| end | |||
| def load_issue_tags | |||
| @issue_tags = IssueTag.where(id: issue_tag_ids) | |||
| end | |||
| def load_attachments | |||
| @attachments = Attachment.where(id: attachment_ids) | |||
| end | |||
| private | |||
| def issue_attributes | |||
| issue_attributes = { | |||
| @@ -131,9 +98,27 @@ class Api::V1::Issues::CreateService < ApplicationService | |||
| @created_issue.issue_participants.new({participant_type: "authored", participant_id: current_user.id}) | |||
| end | |||
| def build_assinger_participants | |||
| def build_assigner_participants | |||
| assigner_ids.each do |aid| | |||
| @created_issue.issue_participants.new({participant_type: "assigned", participant_id: aid}) | |||
| 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 = @updated_issue.journals.new({user_id: current_user.id}) | |||
| journal.journal_details.new({property: "issue", prop_key: 1, old_value: '', value: ''}) | |||
| end | |||
| def try_lock | |||
| raise Error, "请稍后再试!" unless $redis_cache.set("Api::V1::Issues::CreateService:#{project.id}", 1, nx: true, ex: 60.seconds) | |||
| end | |||
| def unlock | |||
| $redis_cache.del("Api::V1::Issues::CreateService:#{project.id}") | |||
| end | |||
| end | |||
| @@ -0,0 +1,43 @@ | |||
| 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 # 开始写数据,加锁 | |||
| 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 | |||
| end | |||
| private | |||
| def delete_issue | |||
| raise Error, "删除疑修失败!" unless issue.destroy! | |||
| end | |||
| def try_lock | |||
| raise Error, "请稍后再试!" unless $redis_cache.set("Api::V1::Issues::DeleteService:#{project.id}", 1, nx: true, ex: 60.seconds) | |||
| end | |||
| def unlock | |||
| $redis_cache.del("Api::V1::Issues::DeleteService:#{project.id}") | |||
| end | |||
| end | |||
| @@ -0,0 +1,181 @@ | |||
| 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 | |||
| 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.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 | |||
| @updated_issue = @issue | |||
| @updated_issue.load_attributes | |||
| build_issue_journal_details if @updated_issue.previous_changes.present? # 操作记录 | |||
| build_issue_project_trends if status_id.present? # 开关时间记录 | |||
| build_assigner_participants unless assigner_ids.blank? # 负责人 | |||
| @updated_issue.assigners = @assigners unless assigner_ids.blank? | |||
| @updated_issue.attachments = @attachments unless attachment_ids.blank? | |||
| @updated_issue.issue_tags = @issue_tags unless issue_tag_ids.blank? | |||
| @updated_issue.save! | |||
| 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_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 | |||
| end | |||
| end | |||
| private | |||
| def build_assigner_participants | |||
| @updated_issue.issue_participants.where.not(id: assigner_ids).each(&:destroy!) | |||
| assigner_ids.each do |aid| | |||
| next if @updated_issue.issue_participants.exists?(participant_id: aid) | |||
| @updated_issue.issue_participants.new({participant_type: "assigned", participant_id: aid}) | |||
| @add_assigner_ids << aid | |||
| end | |||
| end | |||
| def build_previous_issue_changes | |||
| @previous_issue_changes = @updated_issue.previous_changes | |||
| 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_issue_journal_details | |||
| # 更改标题 | |||
| if @updated_issue.previous_changes[:subject].present? | |||
| journal = @updated_issue.journals.new({user_id: current_user.id}) | |||
| journal.journal_details.new({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.new({user_id: current_user.id}) | |||
| journal.journal_details.new({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.new({user_id: current_user.id}) | |||
| journal.journal_details.new({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.new({user_id: current_user.id}) | |||
| journal.journal_details.new({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.new({user_id: current_user.id}) | |||
| journal.journal_details.new({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.new({user_id: current_user.id}) | |||
| journal.journal_details.new({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.new({user_id: current_user.id}) | |||
| journal.journal_details.new({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.new({user_id: current_user.id}) | |||
| journal.journal_details.new({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.assigners.pluck(:id).sort! == assigner_ids.sort! | |||
| journal = @updated_issue.journals.new({user_id: current_user.id}) | |||
| journal.journal_details.new({property: "assigner", prop_key: "#{assigner_ids.size}", old_value: @updated_issue.assigners.pluck(:nickname).join(","), value: @assigners.pluck(:nickname).join(",")}) | |||
| end | |||
| # 更改标记 | |||
| if !@updated_issue.issue_tags.pluck(:id).sort! == issue_tag_ids.sort! | |||
| journal = @updated_issue.journals.new({user_id: current_user.id}) | |||
| journal.journal_details.new({property: "issue_tag", prop_key: "#{issue_tag_ids.size}", old_value: @updated_issue.issue_tags.pluck(:name).join(","), value: @issue_tags.pluck(:name).join(",")}) | |||
| end | |||
| # 更改附件 | |||
| if !@updated_issue.attachments.pluck(:id).sort! == attachment_ids.sort! | |||
| journal = @updated_issue.journals.new({user_id: current_user.id}) | |||
| journal.journal_details.new({property: "attachment", prop_key: "#{attachment_ids.size}", old_value: @updated_issue.attachments.pluck(:filename).join(","), value: @attachments.pluck(:filename).join(",")}) | |||
| end | |||
| end | |||
| def try_lock | |||
| raise Error, "请稍后再试!" unless $redis_cache.set("Api::V1::Issues::UpdateService:#{project.id}:#{issue.id}", 1, nx: true, ex: 60.seconds) | |||
| end | |||
| def unlock | |||
| $redis_cache.del("Api::V1::Issues::UpdateService:#{project.id}:#{issue.id}") | |||
| end | |||
| end | |||
| @@ -25,7 +25,12 @@ defaults format: :json do | |||
| end | |||
| end | |||
| resources :issues | |||
| resources :issues, except: [:new, :edit] do | |||
| collection do | |||
| patch :batch_update | |||
| delete :batch_destroy | |||
| end | |||
| end | |||
| scope module: :issues do | |||
| resources :issue_tags, only: [:index] | |||
| resources :milestones, except: [:new, :edit] | |||