From 467a4f0b94f481ba70a08a995b5c89d1c224c278 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 18 Oct 2023 15:16:14 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20issue=E6=8F=8F=E8=BF=B0=E9=87=8C?= =?UTF-8?q?=E7=9A=84=E9=99=84=E4=BB=B6=E8=A7=A3=E6=9E=90=E5=85=B3=E8=81=94?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=BC=BA=E9=99=84=E4=BB=B6=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/issues_controller.rb | 3 ++- app/controllers/issues_controller.rb | 1 + app/models/issue.rb | 14 +++++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/issues_controller.rb b/app/controllers/api/v1/issues_controller.rb index 7238254db..ebba95e2b 100644 --- a/app/controllers/api/v1/issues_controller.rb +++ b/app/controllers/api/v1/issues_controller.rb @@ -23,7 +23,8 @@ class Api::V1::IssuesController < Api::V1::BaseController before_action :load_issue, only: [:show, :update, :destroy] before_action :check_issue_operate_permission, only: [:update, :destroy] - def show + def show + @issue.associate_attachment_container @user_permission = current_user.present? && current_user.logged? && (@project.member?(current_user) || current_user.admin? || @issue.user == current_user) end diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 0015b518e..cb7beb402 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -321,6 +321,7 @@ class IssuesController < ApplicationController @issue_user = @issue.user @issue_assign_to = @issue.get_assign_user @join_users = join_users(@issue) + @issue.associate_attachment_container #总耗时 # cost_time(@issue) diff --git a/app/models/issue.rb b/app/models/issue.rb index 14876da63..f568e028c 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -94,7 +94,7 @@ class Issue < ApplicationRecord 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_save :change_versions_count, :send_update_message_to_notice_system, :associate_attachment_container after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic def incre_project_common @@ -222,6 +222,18 @@ class Issue < ApplicationRecord SendTemplateMessageJob.perform_later('IssueExpire', self.id) if Site.has_notice_menu? && self.due_date == Date.today + 1.days end + # 关附件到功能 + def associate_attachment_container + att_ids = [] + # 附件的格式为(/api/attachments/ + 附件id)的形式,提取出id进行附件属性关联,做附件访问权限控制 + att_ids += self.description.to_s.scan(/\(\/api\/attachments\/.+\)/).map{|s|s.match(/\d+/)[0]} + att_ids += self.description.to_s.scan(/\/api\/attachments\/.+\"/).map{|s|s.match(/\d+/)[0]} + att_ids += self.description.to_s.scan(/\/api\/attachments\/\d+/).map{|s|s.match(/\d+/)[0]} + if att_ids.present? + Attachment.where(id: att_ids).where(container_type: nil).update_all(container_id: self.id, container_type: self.class.name) + end + end + def to_builder Jbuilder.new do |issue| issue.(self, :id, :project_issues_index, :subject, :description, :branch_name, :start_date, :due_date)