From d4d96759ac8b2907311fd663c63770e1162580d4 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 18 Oct 2023 15:16:14 +0800 Subject: [PATCH 1/3] =?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 4420ed18e..fff3e55d5 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -92,7 +92,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 @@ -220,6 +220,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) From cf190632a1f8e9beb28b5ee2b9537f6c8c26eb09 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 18 Oct 2023 15:24:39 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fixed=20issue=E8=AF=84=E8=AE=BA=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/models/journal.rb | 14 ++++++++++++++ .../api/v1/issues/journals/index.json.jbuilder | 1 + 2 files changed, 15 insertions(+) diff --git a/app/models/journal.rb b/app/models/journal.rb index ce69c1f3a..3229ae886 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -53,10 +53,24 @@ class Journal < ApplicationRecord enum state: {opened: 0, resolved: 1, disabled: 2} + after_save :associate_attachment_container + def is_journal_detail? self.notes.blank? && self.journal_details.present? end + # 关附件到功能 + def associate_attachment_container + att_ids = [] + # 附件的格式为(/api/attachments/ + 附件id)的形式,提取出id进行附件属性关联,做附件访问权限控制 + att_ids += self.notes.to_s.scan(/\(\/api\/attachments\/.+\)/).map{|s|s.match(/\d+/)[0]} + att_ids += self.notes.to_s.scan(/\/api\/attachments\/.+\"/).map{|s|s.match(/\d+/)[0]} + att_ids += self.notes.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 operate_content content = "" detail = self.journal_details.take diff --git a/app/views/api/v1/issues/journals/index.json.jbuilder b/app/views/api/v1/issues/journals/index.json.jbuilder index 49f94aa37..453c39c59 100644 --- a/app/views/api/v1/issues/journals/index.json.jbuilder +++ b/app/views/api/v1/issues/journals/index.json.jbuilder @@ -3,5 +3,6 @@ json.total_operate_journals_count @total_operate_journals_count json.total_comment_journals_count @total_comment_journals_count json.total_count @journals.total_count json.journals @journals do |journal| + journal.associate_attachment_container json.partial! "detail", journal: journal end \ No newline at end of file From 2e2f7b2bd54f02fee093a6576d41635999999725 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 24 Oct 2023 20:41:02 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fixed=20issue=E5=92=8C=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E9=87=8C=E7=9A=84=E9=99=84=E4=BB=B6=E8=A7=A3=E6=9E=90=E5=85=B3?= =?UTF-8?q?=E8=81=94=EF=BC=8C=E5=A2=9E=E5=BC=BA=E9=99=84=E4=BB=B6=E8=AE=BF?= =?UTF-8?q?=E9=97=AE=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6,=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E5=88=B0=20=E9=A1=B9=E7=9B=AE=E4=BF=9D=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 3 +++ app/models/issue.rb | 2 +- app/models/journal.rb | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index cfce8b7a7..2bbccb495 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -224,6 +224,9 @@ class AttachmentsController < ApplicationController elsif @file.container.is_a?(Journal) project = @file.container.issue.project candown = project.is_public || (current_user.logged? && project.member?(current_user)) + elsif @file.container.is_a?(Project) + project = @file.container + candown = project.is_public || (current_user.logged? && project.member?(current_user)) else project = nil end diff --git a/app/models/issue.rb b/app/models/issue.rb index fff3e55d5..a7ce93f86 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -228,7 +228,7 @@ class Issue < ApplicationRecord 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) + Attachment.where(id: att_ids).where("container_type IS NULL OR container_type = 'Issue'").update_all(container_id: self.project_id, container_type: "Project") end end diff --git a/app/models/journal.rb b/app/models/journal.rb index 3229ae886..30cd94143 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -67,7 +67,7 @@ class Journal < ApplicationRecord att_ids += self.notes.to_s.scan(/\/api\/attachments\/.+\"/).map{|s|s.match(/\d+/)[0]} att_ids += self.notes.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) + Attachment.where(id: att_ids).where("container_type IS NULL OR container_type = 'Journal'").update_all(container_id: self.issue.project_id, container_type: "Project") end end