From f6ffaa82a6436f8cdf07129e9e855b7e233ed01d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 18 Oct 2023 16:13:20 +0800 Subject: [PATCH 001/294] =?UTF-8?q?=E6=A0=B9=E6=8D=AEpm=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E9=9C=80=E6=B1=82=E6=96=B0=E5=A2=9Eissue=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/javascripts/api/v1/pm_issues.js | 2 ++ app/assets/stylesheets/api/v1/pm_issues.scss | 3 +++ .../api/v1/pm_issues_controller.rb | 23 +++++++++++++++++++ app/helpers/api/v1/pm_issues_helper.rb | 2 ++ app/services/api/v1/issues/create_service.rb | 6 ++++- .../api/v1/pm_issues/create.json.jbuilder | 1 + config/routes/api.rb | 10 +++++--- .../api/v1/pm_issues_controller_spec.rb | 5 ++++ spec/helpers/api/v1/pm_issues_helper_spec.rb | 15 ++++++++++++ 9 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 app/assets/javascripts/api/v1/pm_issues.js create mode 100644 app/assets/stylesheets/api/v1/pm_issues.scss create mode 100644 app/controllers/api/v1/pm_issues_controller.rb create mode 100644 app/helpers/api/v1/pm_issues_helper.rb create mode 100644 app/views/api/v1/pm_issues/create.json.jbuilder create mode 100644 spec/controllers/api/v1/pm_issues_controller_spec.rb create mode 100644 spec/helpers/api/v1/pm_issues_helper_spec.rb diff --git a/app/assets/javascripts/api/v1/pm_issues.js b/app/assets/javascripts/api/v1/pm_issues.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/api/v1/pm_issues.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/api/v1/pm_issues.scss b/app/assets/stylesheets/api/v1/pm_issues.scss new file mode 100644 index 000000000..92defb491 --- /dev/null +++ b/app/assets/stylesheets/api/v1/pm_issues.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the api/v1/pm_issues controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/api/v1/pm_issues_controller.rb b/app/controllers/api/v1/pm_issues_controller.rb new file mode 100644 index 000000000..2813389b0 --- /dev/null +++ b/app/controllers/api/v1/pm_issues_controller.rb @@ -0,0 +1,23 @@ +class Api::V1::PmIssuesController < ApplicationController + before_action :require_login, except: [:index, :show] + + def create + project = Project.new( id: 0, user_id: current_user.id, name:"pm_mm", identifier:"pm_mm" ) + @object_result = Api::V1::Issues::CreateService.call(project, issue_params, current_user) + end + + private + def issue_params + params.permit( + :status_id, :priority_id, :milestone_id, + :branch_name, :start_date, :due_date, + :subject, :description, :blockchain_token_num, + :pm_project_id, :pm_sprint_id, + :issue_tag_ids => [], + :assigner_ids => [], + :attachment_ids => [], + :receivers_login => [] + ) + end + +end diff --git a/app/helpers/api/v1/pm_issues_helper.rb b/app/helpers/api/v1/pm_issues_helper.rb new file mode 100644 index 000000000..ced4b55c9 --- /dev/null +++ b/app/helpers/api/v1/pm_issues_helper.rb @@ -0,0 +1,2 @@ +module Api::V1::PmIssuesHelper +end diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index c155b69d4..fc81f4dde 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -29,6 +29,8 @@ class Api::V1::Issues::CreateService < ApplicationService @assigner_ids = params[:assigner_ids] @attachment_ids = params[:attachment_ids] @receivers_login = params[:receivers_login] + @pm_project_id = params[:pm_project_id] + @pm_sprint_id = params[:pm_sprint_id] end def call @@ -57,7 +59,8 @@ class Api::V1::Issues::CreateService < ApplicationService @created_issue.assigners = @assigners unless assigner_ids.blank? @created_issue.attachments = @attachments unless attachment_ids.blank? @created_issue.issue_tags = @issue_tags unless issue_tag_ids.blank? - + @created_issue.pm_project_id = @pm_project_id + @created_issue.pm_sprint_id = @pm_sprint_id @created_issue.issue_tags_value = @issue_tags.order("id asc").pluck(:id).join(",") unless issue_tag_ids.blank? @created_issue.save! @@ -135,6 +138,7 @@ class Api::V1::Issues::CreateService < ApplicationService end def build_issue_project_trends + return if @project.id == 0 @created_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: "create"}) @created_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE}) if status_id.to_i == 5 end diff --git a/app/views/api/v1/pm_issues/create.json.jbuilder b/app/views/api/v1/pm_issues/create.json.jbuilder new file mode 100644 index 000000000..f45ef5b2f --- /dev/null +++ b/app/views/api/v1/pm_issues/create.json.jbuilder @@ -0,0 +1 @@ +json.partial! "api/v1/issues/detail", locals: {issue: @object_result} diff --git a/config/routes/api.rb b/config/routes/api.rb index 41d331168..5b1f37d8d 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -44,6 +44,7 @@ defaults format: :json do collection do patch :batch_update delete :batch_destroy + post :pm_create end member do @@ -54,12 +55,15 @@ defaults format: :json do end end end + + resources :pm_issues + scope module: :issues do resources :issue_tags, except: [:new, :edit] do - collection do - get :pm_index + collection do + get :pm_index + end end - end resources :milestones, except: [:new, :edit] resources :issue_statues, only: [:index], controller: '/api/v1/issues/statues' do collection do diff --git a/spec/controllers/api/v1/pm_issues_controller_spec.rb b/spec/controllers/api/v1/pm_issues_controller_spec.rb new file mode 100644 index 000000000..f68abf45f --- /dev/null +++ b/spec/controllers/api/v1/pm_issues_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Api::V1::PmIssuesController, type: :controller do + +end diff --git a/spec/helpers/api/v1/pm_issues_helper_spec.rb b/spec/helpers/api/v1/pm_issues_helper_spec.rb new file mode 100644 index 000000000..4b67710fb --- /dev/null +++ b/spec/helpers/api/v1/pm_issues_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Api::V1::PmIssuesHelper. For example: +# +# describe Api::V1::PmIssuesHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe Api::V1::PmIssuesHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end From 2e43bab1b5a8585b761ea81af6d98b950d1d7533 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 18 Oct 2023 16:37:35 +0800 Subject: [PATCH 002/294] =?UTF-8?q?=20mp=5Fissues=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=AF=B9product=20id=20=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/pm_issues_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/v1/pm_issues_controller.rb b/app/controllers/api/v1/pm_issues_controller.rb index 2813389b0..2593d2915 100644 --- a/app/controllers/api/v1/pm_issues_controller.rb +++ b/app/controllers/api/v1/pm_issues_controller.rb @@ -2,7 +2,7 @@ class Api::V1::PmIssuesController < ApplicationController before_action :require_login, except: [:index, :show] def create - project = Project.new( id: 0, user_id: current_user.id, name:"pm_mm", identifier:"pm_mm" ) + project = Project.find_by_id(params[:project_id]) || Project.new( id: 0, user_id: current_user.id, name:"pm_mm", identifier:"pm_mm" ) @object_result = Api::V1::Issues::CreateService.call(project, issue_params, current_user) end From da5972698f3c536e59bfbaee7d0df539c97fe088 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 18 Oct 2023 15:16:14 +0800 Subject: [PATCH 003/294] =?UTF-8?q?fixed=20issue=E6=8F=8F=E8=BF=B0?= =?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?= 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) From 34a7add47cb570a1c765a169d214922255f4d64c Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 18 Oct 2023 15:24:39 +0800 Subject: [PATCH 004/294] =?UTF-8?q?fixed=20issue=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?= 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 e4bf925905b41f1d530085005ca9fd79637a4194 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 24 Oct 2023 20:41:02 +0800 Subject: [PATCH 005/294] =?UTF-8?q?fixed=20issue=E5=92=8C=E8=AF=84?= =?UTF-8?q?=E8=AE=BA=E9=87=8C=E7=9A=84=E9=99=84=E4=BB=B6=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E5=85=B3=E8=81=94=EF=BC=8C=E5=A2=9E=E5=BC=BA=E9=99=84=E4=BB=B6?= =?UTF-8?q?=E8=AE=BF=E9=97=AE=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6,?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E5=88=B0=20=E9=A1=B9=E7=9B=AE=E4=BF=9D?= =?UTF-8?q?=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 f568e028c..a5fee95fb 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -230,7 +230,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 From 92cefd34b2a57c4e1ade810e0ab13992684f6a06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 26 Oct 2023 09:36:28 +0800 Subject: [PATCH 006/294] stash --- app/controllers/api/v1/pm_issues_controller.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/controllers/api/v1/pm_issues_controller.rb b/app/controllers/api/v1/pm_issues_controller.rb index 2593d2915..0d720f1eb 100644 --- a/app/controllers/api/v1/pm_issues_controller.rb +++ b/app/controllers/api/v1/pm_issues_controller.rb @@ -1,6 +1,18 @@ class Api::V1::PmIssuesController < ApplicationController before_action :require_login, except: [:index, :show] + def index + 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] + if params[:only_name].present? + @issues = kaminary_select_paginate(@object_result[:data].select(:id, :subject, :project_issues_index, :updated_on, :created_on)) + else + @issues = kaminari_paginate(@object_result[:data]) + end + end + def create project = Project.find_by_id(params[:project_id]) || Project.new( id: 0, user_id: current_user.id, name:"pm_mm", identifier:"pm_mm" ) @object_result = Api::V1::Issues::CreateService.call(project, issue_params, current_user) From 51648e52b3cea728fcb8b1eecc11a00ad008e6f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 31 Oct 2023 09:11:54 +0800 Subject: [PATCH 007/294] issue index for pm --- app/controllers/api/v1/pm_issues_controller.rb | 3 ++- app/services/api/v1/issues/list_service.rb | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/pm_issues_controller.rb b/app/controllers/api/v1/pm_issues_controller.rb index 0d720f1eb..5c2e0f987 100644 --- a/app/controllers/api/v1/pm_issues_controller.rb +++ b/app/controllers/api/v1/pm_issues_controller.rb @@ -2,6 +2,7 @@ class Api::V1::PmIssuesController < ApplicationController before_action :require_login, except: [:index, :show] def index + project = Project.find_by_id(params[:project_id]) || Project.new( id: 0, user_id: 0, name:"pm_mm", identifier:"pm_mm" ) 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] @@ -14,7 +15,7 @@ class Api::V1::PmIssuesController < ApplicationController end def create - project = Project.find_by_id(params[:project_id]) || Project.new( id: 0, user_id: current_user.id, name:"pm_mm", identifier:"pm_mm" ) + project = Project.find_by_id(params[:project_id]) || Project.new( id: 0, user_id: 0, name:"pm_mm", identifier:"pm_mm" ) @object_result = Api::V1::Issues::CreateService.call(project, issue_params, current_user) end diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index b6ef11789..862524bf3 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -4,6 +4,7 @@ class Api::V1::Issues::ListService < ApplicationService attr_reader :project, :only_name, :category, :participant_category, :keyword, :author_id, :issue_tag_ids attr_reader :begin_date, :end_date attr_reader :milestone_id, :assigner_id, :status_id, :sort_by, :sort_direction, :current_user + attr_reader :pm_project_id, :pm_sprint_id attr_accessor :queried_issues, :total_issues_count, :closed_issues_count, :opened_issues_count validates :category, inclusion: {in: %w(all opened closed), message: "请输入正确的Category"} @@ -26,6 +27,8 @@ class Api::V1::Issues::ListService < ApplicationService @begin_date = params[:begin_date] @end_date = params[:end_date] @sort_by = params[:sort_by].present? ? params[:sort_by] : 'issues.updated_on' + @pm_project_id = params[:pm_project_id] + @pm_sprint_id = params[:pm_sprint_id] @sort_direction = (params[:sort_direction].present? ? params[:sort_direction] : 'desc').downcase @current_user = current_user end @@ -65,6 +68,12 @@ class Api::V1::Issues::ListService < ApplicationService # milestone_id issues = issues.where(fixed_version_id: milestone_id) if milestone_id.present? + # pm_project_id + issues = issues.where(pm_project_id: pm_project_id) if pm_project_id.present? + + # pm_sprint_id + issues = issues.where(pm_sprint_id: pm_sprint_id) if pm_sprint_id.present? + # assigner_id issues = issues.joins(:assigners).where(users: {id: assigner_id}) if assigner_id.present? From 770f743750dcf8bd4412b97af323fd5b52c17a9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 31 Oct 2023 17:03:35 +0800 Subject: [PATCH 008/294] issue pm --- app/assets/javascripts/pm/issues.js | 2 + app/assets/javascripts/pm/journals.js | 2 + app/assets/stylesheets/pm/issues.scss | 3 ++ app/assets/stylesheets/pm/journals.scss | 3 ++ app/controllers/pm/issues_controller.rb | 37 +++++++++++++++++++ app/helpers/pm/issues_helper.rb | 2 + app/helpers/pm/journals_helper.rb | 2 + app/models/issue.rb | 1 + app/services/api/v1/issues/create_service.rb | 5 ++- config/routes.rb | 5 +++ config/routes/api.rb | 3 +- ...31031070603_add_pm_issue_type_to_issues.rb | 5 +++ spec/controllers/pm/issues_controller_spec.rb | 5 +++ .../pm/journals_controller_spec.rb | 5 +++ spec/helpers/pm/issues_helper_spec.rb | 15 ++++++++ spec/helpers/pm/journals_helper_spec.rb | 15 ++++++++ 16 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 app/assets/javascripts/pm/issues.js create mode 100644 app/assets/javascripts/pm/journals.js create mode 100644 app/assets/stylesheets/pm/issues.scss create mode 100644 app/assets/stylesheets/pm/journals.scss create mode 100644 app/controllers/pm/issues_controller.rb create mode 100644 app/helpers/pm/issues_helper.rb create mode 100644 app/helpers/pm/journals_helper.rb create mode 100644 db/migrate/20231031070603_add_pm_issue_type_to_issues.rb create mode 100644 spec/controllers/pm/issues_controller_spec.rb create mode 100644 spec/controllers/pm/journals_controller_spec.rb create mode 100644 spec/helpers/pm/issues_helper_spec.rb create mode 100644 spec/helpers/pm/journals_helper_spec.rb diff --git a/app/assets/javascripts/pm/issues.js b/app/assets/javascripts/pm/issues.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/pm/issues.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/pm/journals.js b/app/assets/javascripts/pm/journals.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/pm/journals.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/pm/issues.scss b/app/assets/stylesheets/pm/issues.scss new file mode 100644 index 000000000..cdf9fbc43 --- /dev/null +++ b/app/assets/stylesheets/pm/issues.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the pm/issues controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/pm/journals.scss b/app/assets/stylesheets/pm/journals.scss new file mode 100644 index 000000000..45dbf18b4 --- /dev/null +++ b/app/assets/stylesheets/pm/journals.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the pm/journals controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/pm/issues_controller.rb b/app/controllers/pm/issues_controller.rb new file mode 100644 index 000000000..ec2370cdf --- /dev/null +++ b/app/controllers/pm/issues_controller.rb @@ -0,0 +1,37 @@ +class Pm::IssuesController < ApplicationController + before_action :require_login, except: [:index] + + def index + @project = Project.find_by_id(params[:project_id]) || Project.new(id: 0, user_id: 0, name: 'pm_mm', identifier: 'pm_mm') + @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] + if params[:only_name].present? + @issues = kaminary_select_paginate( + @object_result[:data].select(:id, :subject, :project_issues_index, :updated_on, :created_on)) + else + @issues = kaminari_paginate(@object_result[:data]) + end + end + + def create + project = Project.find_by_id(params[:project_id]) || Project.new(id: 0, user_id: 0, name: 'pm_mm', identifier: 'pm_mm') + @object_result = Api::V1::Issues::CreateService.call(project, issue_params, current_user) + end + + private + + def issue_params + params.permit( + :status_id, :priority_id, :milestone_id, + :branch_name, :start_date, :due_date, + :subject, :description, :blockchain_token_num, + :pm_project_id, :pm_sprint_id, :pm_issue_type, + issue_tag_ids: [], + assigner_ids: [], + attachment_ids: [], + receivers_login: [] + ) + end +end diff --git a/app/helpers/pm/issues_helper.rb b/app/helpers/pm/issues_helper.rb new file mode 100644 index 000000000..79cd6dd3e --- /dev/null +++ b/app/helpers/pm/issues_helper.rb @@ -0,0 +1,2 @@ +module Pm::IssuesHelper +end diff --git a/app/helpers/pm/journals_helper.rb b/app/helpers/pm/journals_helper.rb new file mode 100644 index 000000000..e1a99e5ee --- /dev/null +++ b/app/helpers/pm/journals_helper.rb @@ -0,0 +1,2 @@ +module Pm::JournalsHelper +end diff --git a/app/models/issue.rb b/app/models/issue.rb index a5fee95fb..6325a327f 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -36,6 +36,7 @@ # blockchain_token_num :integer # pm_project_id :integer # pm_sprint_id :integer +# pm_issue_type :integer # # Indexes # diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index fc81f4dde..a5dc3d88e 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -31,9 +31,10 @@ class Api::V1::Issues::CreateService < ApplicationService @receivers_login = params[:receivers_login] @pm_project_id = params[:pm_project_id] @pm_sprint_id = params[:pm_sprint_id] + @pm_issue_type = params[:pm_issue_type] end - def call + def call raise Error, errors.full_messages.join(", ") unless valid? ActiveRecord::Base.transaction do check_issue_status(status_id) @@ -48,7 +49,6 @@ class Api::V1::Issues::CreateService < ApplicationService load_attachments(attachment_ids) unless attachment_ids.blank? load_issue_tags(issue_tag_ids) unless issue_tag_ids.blank? load_atme_receivers(receivers_login) unless receivers_login.blank? - try_lock("Api::V1::Issues::CreateService:#{project.id}") # 开始写数据,加锁 @created_issue = Issue.new(issue_attributes) build_author_participants @@ -61,6 +61,7 @@ class Api::V1::Issues::CreateService < ApplicationService @created_issue.issue_tags = @issue_tags unless issue_tag_ids.blank? @created_issue.pm_project_id = @pm_project_id @created_issue.pm_sprint_id = @pm_sprint_id + @created_issue.pm_issue_type = @pm_issue_type @created_issue.issue_tags_value = @issue_tags.order("id asc").pluck(:id).join(",") unless issue_tag_ids.blank? @created_issue.save! diff --git a/config/routes.rb b/config/routes.rb index 7694a77c0..647405bdb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -792,6 +792,11 @@ Rails.application.routes.draw do end end + namespace :pm do + resource :issues + resource :journals + end + namespace :admins do mount Sidekiq::Web => '/sidekiq' get '/', to: 'dashboards#index' diff --git a/config/routes/api.rb b/config/routes/api.rb index 5b1f37d8d..ceb2d27ce 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -56,8 +56,7 @@ defaults format: :json do end end - resources :pm_issues - + scope module: :issues do resources :issue_tags, except: [:new, :edit] do collection do diff --git a/db/migrate/20231031070603_add_pm_issue_type_to_issues.rb b/db/migrate/20231031070603_add_pm_issue_type_to_issues.rb new file mode 100644 index 000000000..846a760f1 --- /dev/null +++ b/db/migrate/20231031070603_add_pm_issue_type_to_issues.rb @@ -0,0 +1,5 @@ +class AddPmIssueTypeToIssues < ActiveRecord::Migration[5.2] + def change + add_column :issues, :pm_issue_type, :integer + end +end diff --git a/spec/controllers/pm/issues_controller_spec.rb b/spec/controllers/pm/issues_controller_spec.rb new file mode 100644 index 000000000..cb80ebb71 --- /dev/null +++ b/spec/controllers/pm/issues_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Pm::IssuesController, type: :controller do + +end diff --git a/spec/controllers/pm/journals_controller_spec.rb b/spec/controllers/pm/journals_controller_spec.rb new file mode 100644 index 000000000..0a0ced0ba --- /dev/null +++ b/spec/controllers/pm/journals_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Pm::JournalsController, type: :controller do + +end diff --git a/spec/helpers/pm/issues_helper_spec.rb b/spec/helpers/pm/issues_helper_spec.rb new file mode 100644 index 000000000..43b9ba751 --- /dev/null +++ b/spec/helpers/pm/issues_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Pm::IssuesHelper. For example: +# +# describe Pm::IssuesHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe Pm::IssuesHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/helpers/pm/journals_helper_spec.rb b/spec/helpers/pm/journals_helper_spec.rb new file mode 100644 index 000000000..8dd212826 --- /dev/null +++ b/spec/helpers/pm/journals_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Pm::JournalsHelper. For example: +# +# describe Pm::JournalsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe Pm::JournalsHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end From 36a659678d15bfa6f6a91193311f9bce51846d1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 1 Nov 2023 10:42:27 +0800 Subject: [PATCH 009/294] gm issue --- app/controllers/api/pm/issues_controller.rb | 79 +++++++++++++++++++ .../api/v1/issues/concerns/checkable.rb | 1 + app/services/api/v1/issues/create_service.rb | 2 + app/services/api/v1/issues/list_service.rb | 13 ++- app/views/api/v1/issues/_detail.json.jbuilder | 6 +- app/views/api/v1/issues/index.json.jbuilder | 2 +- .../api/v1/pm_issues/create.json.jbuilder | 1 - config/routes/api.rb | 6 +- 8 files changed, 104 insertions(+), 6 deletions(-) create mode 100644 app/controllers/api/pm/issues_controller.rb delete mode 100644 app/views/api/v1/pm_issues/create.json.jbuilder diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb new file mode 100644 index 000000000..9e9bbde2d --- /dev/null +++ b/app/controllers/api/pm/issues_controller.rb @@ -0,0 +1,79 @@ +class Api::Pm::IssuesController < ApplicationController + before_action :require_login, except: [:index] + before_action :load_issue, only: [:show, :children, :update, :destroy] + def index + @project = Project.find_by_id(params[:project_id]) || Project.new(id: 0, user_id: 0, name: 'pm_mm', identifier: 'pm_mm') + @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] + if params[:only_name].present? + @issues = kaminary_select_paginate( + @object_result[:data].select(:id, :subject, :project_issues_index, :updated_on, :created_on)) + else + @issues = kaminari_paginate(@object_result[:data]) + end + render "api/v1/issues/index" + end + + def show + @issue.associate_attachment_container + render "api/v1/issues/show" + end + + def create + project = Project.find_by_id(params[:project_id]) || Project.new(id: 0, user_id: 0, name: 'pm_mm', identifier: 'pm_mm') + @object_result = Api::V1::Issues::CreateService.call(project, issue_params, current_user) + render "api/v1/issues/create" + 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 + private + def load_issue + @project = Project.new(id: params[:project_id], user_id: 0, name: 'pm_mm', identifier: 'pm_mm') + @issue = @project.issues.issue_issue.where(pm_project_id: params[:pm_project_id], pm_sprint_id:params[:pm_sprint_id]).find_by_id(params[:id]) + if @issue.blank? + render_not_found("疑修不存在!") + end + end + + def query_params + params.permit( + :only_name, + :category, + :participant_category, + :keyword, :author_id, + :milestone_id, :assigner_id, + :status_id, + :begin_date, :end_date, + :sort_by, :sort_direction,:parent_id, + :issue_tag_ids, :pm_project_id, :pm_sprint_id, :pm_issue_type + ) + end + + + + def issue_params + params.permit( + :status_id, :priority_id, :milestone_id, + :branch_name, :start_date, :due_date, + :subject, :description, :blockchain_token_num, + :pm_project_id, :pm_sprint_id, :pm_issue_type, :parent_id, + issue_tag_ids: [], + assigner_ids: [], + attachment_ids: [], + receivers_login: [] + ) + end +end diff --git a/app/services/api/v1/issues/concerns/checkable.rb b/app/services/api/v1/issues/concerns/checkable.rb index b19c245ed..d3cc4741d 100644 --- a/app/services/api/v1/issues/concerns/checkable.rb +++ b/app/services/api/v1/issues/concerns/checkable.rb @@ -47,6 +47,7 @@ module Api::V1::Issues::Concerns::Checkable end def check_blockchain_token_num(user_id, project_id, blockchain_token_num, now_blockchain_token_num=0) + return if project_id.zero? left_blockchain_token_num = Blockchain::BalanceQueryOneProject.call({"user_id": user_id, "project_id": project_id}) rescue 0 raise ApplicationService::Error, "用户Token不足。" if blockchain_token_num.to_i > (left_blockchain_token_num+now_blockchain_token_num).to_i end diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index a5dc3d88e..64a42b20d 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -32,6 +32,7 @@ class Api::V1::Issues::CreateService < ApplicationService @pm_project_id = params[:pm_project_id] @pm_sprint_id = params[:pm_sprint_id] @pm_issue_type = params[:pm_issue_type] + @parent_id = params[:parent_id] end def call @@ -62,6 +63,7 @@ class Api::V1::Issues::CreateService < ApplicationService @created_issue.pm_project_id = @pm_project_id @created_issue.pm_sprint_id = @pm_sprint_id @created_issue.pm_issue_type = @pm_issue_type + @created_issue.parent_id = @parent_id @created_issue.issue_tags_value = @issue_tags.order("id asc").pluck(:id).join(",") unless issue_tag_ids.blank? @created_issue.save! diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index 862524bf3..5e442c01f 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -4,7 +4,7 @@ class Api::V1::Issues::ListService < ApplicationService attr_reader :project, :only_name, :category, :participant_category, :keyword, :author_id, :issue_tag_ids attr_reader :begin_date, :end_date attr_reader :milestone_id, :assigner_id, :status_id, :sort_by, :sort_direction, :current_user - attr_reader :pm_project_id, :pm_sprint_id + attr_reader :pm_project_id, :pm_sprint_id, :parent_id, :pm_issue_type attr_accessor :queried_issues, :total_issues_count, :closed_issues_count, :opened_issues_count validates :category, inclusion: {in: %w(all opened closed), message: "请输入正确的Category"} @@ -29,6 +29,8 @@ class Api::V1::Issues::ListService < ApplicationService @sort_by = params[:sort_by].present? ? params[:sort_by] : 'issues.updated_on' @pm_project_id = params[:pm_project_id] @pm_sprint_id = params[:pm_sprint_id] + @parent_id = params[:parent_id] + @pm_issue_type = params[:pm_issue_type] @sort_direction = (params[:sort_direction].present? ? params[:sort_direction] : 'desc').downcase @current_user = current_user end @@ -64,10 +66,17 @@ class Api::V1::Issues::ListService < ApplicationService # 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? + #pm相关 + # parent_id, + issues = issues.where(parent_id: parent_id) if parent_id.present? + + # pm_issue_type + issues = issues.where(pm_issue_type: pm_issue_type) if pm_issue_type.present? + # pm_project_id issues = issues.where(pm_project_id: pm_project_id) if pm_project_id.present? diff --git a/app/views/api/v1/issues/_detail.json.jbuilder b/app/views/api/v1/issues/_detail.json.jbuilder index 7c3adecc3..bec02a555 100644 --- a/app/views/api/v1/issues/_detail.json.jbuilder +++ b/app/views/api/v1/issues/_detail.json.jbuilder @@ -44,4 +44,8 @@ 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 -json.pull_fixed issue.pull_attached_issues.where(fixed: true).present? \ No newline at end of file +json.pull_fixed issue.pull_attached_issues.where(fixed: true).present? +json.parent_id issue.parent_id +json.pm_issue_type issue.pm_issue_type +json.pm_sprint_id issue.pm_sprint_id +json.pm_project_id issue.pm_project_id diff --git a/app/views/api/v1/issues/index.json.jbuilder b/app/views/api/v1/issues/index.json.jbuilder index cde117fdc..8fd915553 100644 --- a/app/views/api/v1/issues/index.json.jbuilder +++ b/app/views/api/v1/issues/index.json.jbuilder @@ -7,6 +7,6 @@ json.issues @issues.each do |issue| if params[:only_name].present? json.(issue, :id, :subject, :project_issues_index) else - json.partial! "simple_detail", locals: {issue: issue} + json.partial! "api/v1/issues/simple_detail", locals: {issue: issue} end end \ No newline at end of file diff --git a/app/views/api/v1/pm_issues/create.json.jbuilder b/app/views/api/v1/pm_issues/create.json.jbuilder deleted file mode 100644 index f45ef5b2f..000000000 --- a/app/views/api/v1/pm_issues/create.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.partial! "api/v1/issues/detail", locals: {issue: @object_result} diff --git a/config/routes/api.rb b/config/routes/api.rb index ceb2d27ce..88b75c740 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -1,5 +1,9 @@ defaults format: :json do - namespace :api do + namespace :api do + namespace :pm do + resources :issues + end + namespace :v1 do resources :users, only: [:index] do From 5c72feb7059644a17e710732698f295f5e2b237a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 1 Nov 2023 16:49:00 +0800 Subject: [PATCH 010/294] pm issue and journal --- app/controllers/api/pm/base_controller.rb | 59 +++++++++++++ app/controllers/api/pm/issues_controller.rb | 88 ++++++++++++++++--- app/controllers/api/pm/journals_controller.rb | 57 ++++++++++++ app/controllers/api/v1/base_controller.rb | 2 +- .../v1/issues/issue_priorities_controller.rb | 8 -- .../api/v1/issues/issue_tags_controller.rb | 7 +- .../api/v1/issues/statues_controller.rb | 7 -- .../issue_priorities/index.json.jbuilder | 2 +- .../v1/issues/issue_tags/index.json.jbuilder | 4 +- .../api/v1/issues/statues/index.json.jbuilder | 2 +- config/routes/api.rb | 37 ++++---- 11 files changed, 215 insertions(+), 58 deletions(-) create mode 100644 app/controllers/api/pm/base_controller.rb create mode 100644 app/controllers/api/pm/journals_controller.rb diff --git a/app/controllers/api/pm/base_controller.rb b/app/controllers/api/pm/base_controller.rb new file mode 100644 index 000000000..3fcc1cfb7 --- /dev/null +++ b/app/controllers/api/pm/base_controller.rb @@ -0,0 +1,59 @@ +class Api::Pm::BaseController < ApplicationController + + include Api::ProjectHelper + include Api::UserHelper + include Api::PullHelper + + # before_action :doorkeeper_authorize! + # skip_before_action :user_setup + + protected + + def kaminary_select_paginate(relation) + limit = params[:limit] || params[:per_page] + limit = (limit.to_i.zero? || limit.to_i > 200) ? 200 : 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 + + def load_project + @project = Project.find_by_id(params[:project_id]) || Project.new(id: 0, user_id: 0, name: 'pm_mm', identifier: 'pm_mm', is_public:true) + end + + def load_issue + @issue = @project.issues.issue_issue.where(pm_project_id: params[:pm_project_id]).find_by_id(params[:id]) + render_not_found('疑修不存在!') if @issue.blank? + end + # 具有对仓库的管理权限 + def require_manager_above + @project = load_project + return render_forbidden if !current_user.admin? && !@project.manager?(current_user) + end + + # 具有对仓库的操作权限 + def require_operate_above + @project = load_project + return render_forbidden if !current_user.admin? && !@project.operator?(current_user) + end + + # 具有仓库的操作权限或者fork仓库的操作权限 + def require_operate_above_or_fork_project + @project = load_project + return render_forbidden if !current_user.admin? && !@project.operator?(current_user) && !(@project.fork_project.present? && @project.fork_project.operator?(current_user)) + end + + # 具有对仓库的访问权限 + def require_public_and_member_above + @project = load_project + return render_forbidden if !@project.is_public && !current_user.admin? && !@project.member?(current_user) + end +end \ No newline at end of file diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 9e9bbde2d..9df5bf7ea 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -1,8 +1,11 @@ -class Api::Pm::IssuesController < ApplicationController +class Api::Pm::IssuesController < Api::Pm::BaseController before_action :require_login, except: [:index] - before_action :load_issue, only: [:show, :children, :update, :destroy] + before_action :load_project + before_action :load_issue, only: %i[show update destroy] + before_action :load_issues, only: [:batch_update, :batch_destroy] + before_action :check_issue_operate_permission, only: [:update, :destroy] + def index - @project = Project.find_by_id(params[:project_id]) || Project.new(id: 0, user_id: 0, name: 'pm_mm', identifier: 'pm_mm') @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] @@ -13,22 +16,64 @@ class Api::Pm::IssuesController < ApplicationController else @issues = kaminari_paginate(@object_result[:data]) end - render "api/v1/issues/index" + render 'api/v1/issues/index' end def show @issue.associate_attachment_container - render "api/v1/issues/show" + render 'api/v1/issues/show' end def create - project = Project.find_by_id(params[:project_id]) || Project.new(id: 0, user_id: 0, name: 'pm_mm', identifier: 'pm_mm') - @object_result = Api::V1::Issues::CreateService.call(project, issue_params, current_user) - render "api/v1/issues/create" + @object_result = Api::V1::Issues::CreateService.call(@project, issue_params, current_user) + render 'api/v1/issues/create' end def update @object_result = Api::V1::Issues::UpdateService.call(@project, @issue, issue_params, current_user) + render 'api/v1/issues/update' + end + + 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 + + def priorities + @priorities = IssuePriority.order(position: :asc) + @priorities = @priorities.ransack(name_cont: params[:keyword]).result if params[:keyword] + @priorities = kaminary_select_paginate(@priorities) + render "api/v1/issues/issue_priorities/index" + end + + def tags + @issue_tags = IssueTag.init_mp_issues_tags + render_ok(@issue_tags) + end + + def statues + @statues = IssueStatus.order("position asc") + @statues = @statues.ransack(name_cont: params[:keyword]).result if params[:keyword].present? + @statues = kaminary_select_paginate(@statues) + render "api/v1/issues/statues/index" + end + + def pm_index + @issue_tags = IssueTag.init_mp_issues_tags + render_ok(@issue_tags) end def destroy @@ -39,15 +84,30 @@ class Api::Pm::IssuesController < ApplicationController render_error('删除疑修失败!') end end + private - def load_issue - @project = Project.new(id: params[:project_id], user_id: 0, name: 'pm_mm', identifier: 'pm_mm') - @issue = @project.issues.issue_issue.where(pm_project_id: params[:pm_project_id], pm_sprint_id:params[:pm_sprint_id]).find_by_id(params[:id]) - if @issue.blank? - render_not_found("疑修不存在!") - end + def check_issue_operate_permission + return if params[:project_id].zero? + render_forbidden('您没有操作权限!') unless @project.member?(current_user) || current_user.admin? || @issue.user == current_user end + def load_issue + @issue = @project.issues.issue_issue.where(pm_project_id: params[:pm_project_id]).find_by_id(params[:id]) + render_not_found('疑修不存在!') if @issue.blank? + 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, pm_project_id: params[:pm_project_id]) + if @issue.blank? + return render_not_found("ID为#{id}的疑修不存在!") + end + end + @issues = Issue.where(id: params[:ids], pm_project_id: params[:pm_project_id]) + end + + def query_params params.permit( :only_name, diff --git a/app/controllers/api/pm/journals_controller.rb b/app/controllers/api/pm/journals_controller.rb new file mode 100644 index 000000000..b4cae5a95 --- /dev/null +++ b/app/controllers/api/pm/journals_controller.rb @@ -0,0 +1,57 @@ +class Api::Pm::JournalsController < Api::Pm::BaseController + before_action :require_login, except: [:index, :children_journals] + before_action :load_project + before_action :load_issue + before_action :load_journal, only: [:children_journals, :update, :destroy] + + def index + @object_result = Api::V1::Issues::Journals::ListService.call(@issue, query_params, current_user) + @total_journals_count = @object_result[:total_journals_count] + @total_operate_journals_count = @object_result[:total_operate_journals_count] + @total_comment_journals_count = @object_result[:total_comment_journals_count] + @journals = kaminary_select_paginate(@object_result[:data]) + 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 + TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueComment', @issue&.id, current_user.id, @journal.id, 'deleted', JSON.parse(@journal.to_builder.target!)) + 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(pm_project_id: params[:pm_project_id]).find_by_id(params[:issue_id]) + render_not_found('疑修不存在!') if @issue.blank? + end + + def load_journal + @journal = Journal.find_by_id(params[:id]) + render_not_found('评论不存在!') unless @journal.present? + end + +end \ No newline at end of file diff --git a/app/controllers/api/v1/base_controller.rb b/app/controllers/api/v1/base_controller.rb index bcb0c4e86..3d88d4672 100644 --- a/app/controllers/api/v1/base_controller.rb +++ b/app/controllers/api/v1/base_controller.rb @@ -57,7 +57,7 @@ class Api::V1::BaseController < ApplicationController # 具有对仓库的访问权限 def require_public_and_member_above - @project = load_project + @project = load_project return render_forbidden if !@project.is_public && !current_user.admin? && !@project.member?(current_user) end end \ No newline at end of file diff --git a/app/controllers/api/v1/issues/issue_priorities_controller.rb b/app/controllers/api/v1/issues/issue_priorities_controller.rb index 2df1288f7..319994a28 100644 --- a/app/controllers/api/v1/issues/issue_priorities_controller.rb +++ b/app/controllers/api/v1/issues/issue_priorities_controller.rb @@ -7,12 +7,4 @@ class Api::V1::Issues::IssuePrioritiesController < Api::V1::BaseController @priorities = @priorities.ransack(name_cont: params[:keyword]).result if params[:keyword] @priorities = kaminary_select_paginate(@priorities) end - - def pm_index - @priorities = IssuePriority.order(position: :asc) - @priorities = @priorities.ransack(name_cont: params[:keyword]).result if params[:keyword] - @priorities = kaminary_select_paginate(@priorities) - render "index" - end - end \ No newline at end of file diff --git a/app/controllers/api/v1/issues/issue_tags_controller.rb b/app/controllers/api/v1/issues/issue_tags_controller.rb index 39534c313..f712a3ba4 100644 --- a/app/controllers/api/v1/issues/issue_tags_controller.rb +++ b/app/controllers/api/v1/issues/issue_tags_controller.rb @@ -13,12 +13,7 @@ class Api::V1::Issues::IssueTagsController < Api::V1::BaseController end end - def pm_index - @issue_tags = IssueTag.init_mp_issues_tags - render_ok(@issue_tags) - end - - def create + def create @issue_tag = @project.issue_tags.new(issue_tag_params) if @issue_tag.save! render_ok diff --git a/app/controllers/api/v1/issues/statues_controller.rb b/app/controllers/api/v1/issues/statues_controller.rb index c6495ee26..5a7fbc338 100644 --- a/app/controllers/api/v1/issues/statues_controller.rb +++ b/app/controllers/api/v1/issues/statues_controller.rb @@ -8,11 +8,4 @@ class Api::V1::Issues::StatuesController < Api::V1::BaseController @statues = @statues.ransack(name_cont: params[:keyword]).result if params[:keyword].present? @statues = kaminary_select_paginate(@statues) end - - def pm_index - @statues = IssueStatus.order("position asc") - @statues = @statues.ransack(name_cont: params[:keyword]).result if params[:keyword].present? - @statues = kaminary_select_paginate(@statues) - render "index" - end end \ No newline at end of file diff --git a/app/views/api/v1/issues/issue_priorities/index.json.jbuilder b/app/views/api/v1/issues/issue_priorities/index.json.jbuilder index c1b8ebb25..04bcd96ff 100644 --- a/app/views/api/v1/issues/issue_priorities/index.json.jbuilder +++ b/app/views/api/v1/issues/issue_priorities/index.json.jbuilder @@ -1,4 +1,4 @@ json.total_count @priorities.total_count json.priorities @priorities.each do |priority| - json.partial! "simple_detail", locals: {priority: priority} + json.partial! "api/v1/issues/issue_priorities/simple_detail", locals: {priority: priority} end \ No newline at end of file diff --git a/app/views/api/v1/issues/issue_tags/index.json.jbuilder b/app/views/api/v1/issues/issue_tags/index.json.jbuilder index 0bd055b57..83fee7f6b 100644 --- a/app/views/api/v1/issues/issue_tags/index.json.jbuilder +++ b/app/views/api/v1/issues/issue_tags/index.json.jbuilder @@ -1,8 +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} + json.partial! "api/v1/issues/issue_tags/simple_detail", locals: {tag: tag} else - json.partial! "detail", locals: {tag: tag} + json.partial! "api/v1/issues/issue_tags/detail", locals: {tag: tag} end end \ No newline at end of file diff --git a/app/views/api/v1/issues/statues/index.json.jbuilder b/app/views/api/v1/issues/statues/index.json.jbuilder index 9fb60acc2..bff73bd8d 100644 --- a/app/views/api/v1/issues/statues/index.json.jbuilder +++ b/app/views/api/v1/issues/statues/index.json.jbuilder @@ -1,4 +1,4 @@ json.total_count @statues.total_count json.statues @statues.each do |status| - json.partial! "simple_detail", locals: {status: status} + json.partial! "api/v1/issues/statues/simple_detail", locals: {status: status} end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index 88b75c740..382843f89 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -1,12 +1,25 @@ defaults format: :json do namespace :api do namespace :pm do - resources :issues + resources :issues do + collection do + patch :batch_update + delete :batch_destroy + get :priorities + get :tags + get :statues + end + + resources :journals do + member do + get :children_journals + end + end + end end namespace :v1 do - - resources :users, only: [:index] do + resources :users, only: [:index] do collection do post :check_user_id post :check_user_login @@ -62,24 +75,12 @@ defaults format: :json do scope module: :issues do - resources :issue_tags, except: [:new, :edit] do - collection do - get :pm_index - end - end + resources :issue_tags, except: [:new, :edit] resources :milestones, except: [:new, :edit] - resources :issue_statues, only: [:index], controller: '/api/v1/issues/statues' do - collection do - get :pm_index - end - end + 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] do - collection do - get :pm_index - end - end + resources :issue_priorities, only: [:index] end # projects文件夹下的 From f00c3931a81d30f6ff2424ed203b1cbcbd2a9708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 2 Nov 2023 09:17:32 +0800 Subject: [PATCH 011/294] update issue tags for pm --- app/assets/javascripts/pm/issues.js | 2 - app/assets/stylesheets/pm/issues.scss | 3 -- app/controllers/api/pm/issues_controller.rb | 22 ++++++++++- app/controllers/pm/issues_controller.rb | 37 ------------------- app/helpers/pm/issues_helper.rb | 2 - app/models/issue_tag.rb | 16 +++++++- .../20231101090823_add_pm_project_id.rb | 5 +++ spec/controllers/pm/issues_controller_spec.rb | 5 --- spec/helpers/pm/issues_helper_spec.rb | 15 -------- 9 files changed, 40 insertions(+), 67 deletions(-) delete mode 100644 app/assets/javascripts/pm/issues.js delete mode 100644 app/assets/stylesheets/pm/issues.scss delete mode 100644 app/controllers/pm/issues_controller.rb delete mode 100644 app/helpers/pm/issues_helper.rb create mode 100644 db/migrate/20231101090823_add_pm_project_id.rb delete mode 100644 spec/controllers/pm/issues_controller_spec.rb delete mode 100644 spec/helpers/pm/issues_helper_spec.rb diff --git a/app/assets/javascripts/pm/issues.js b/app/assets/javascripts/pm/issues.js deleted file mode 100644 index dee720fac..000000000 --- a/app/assets/javascripts/pm/issues.js +++ /dev/null @@ -1,2 +0,0 @@ -// Place all the behaviors and hooks related to the matching controller here. -// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/pm/issues.scss b/app/assets/stylesheets/pm/issues.scss deleted file mode 100644 index cdf9fbc43..000000000 --- a/app/assets/stylesheets/pm/issues.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the pm/issues controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 9df5bf7ea..4b76783d2 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -60,8 +60,12 @@ class Api::Pm::IssuesController < Api::Pm::BaseController end def tags - @issue_tags = IssueTag.init_mp_issues_tags - render_ok(@issue_tags) + IssueTag.pm_init_data(params[:pm_project_id]) unless $redis_cache.hget("pm_project_init_issue_tags", params[:pm_project_id]) + @issue_tags = IssueTag.where(pm_project_id: params[:pm_project_id]).reorder("#{tag_sort_by} #{tag_sort_direction}") + @issue_tags = @issue_tags.ransack(name_cont: params[:keyword]).result if params[:keyword].present? + params[:only_name] = true #强制渲染 不走project + @issue_tags = kaminary_select_paginate(@issue_tags.select(:id, :name, :color)) + render "api/v1/issues/issue_tags/index" end def statues @@ -136,4 +140,18 @@ class Api::Pm::IssuesController < Api::Pm::BaseController receivers_login: [] ) end + + private + def tag_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 tag_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 diff --git a/app/controllers/pm/issues_controller.rb b/app/controllers/pm/issues_controller.rb deleted file mode 100644 index ec2370cdf..000000000 --- a/app/controllers/pm/issues_controller.rb +++ /dev/null @@ -1,37 +0,0 @@ -class Pm::IssuesController < ApplicationController - before_action :require_login, except: [:index] - - def index - @project = Project.find_by_id(params[:project_id]) || Project.new(id: 0, user_id: 0, name: 'pm_mm', identifier: 'pm_mm') - @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] - if params[:only_name].present? - @issues = kaminary_select_paginate( - @object_result[:data].select(:id, :subject, :project_issues_index, :updated_on, :created_on)) - else - @issues = kaminari_paginate(@object_result[:data]) - end - end - - def create - project = Project.find_by_id(params[:project_id]) || Project.new(id: 0, user_id: 0, name: 'pm_mm', identifier: 'pm_mm') - @object_result = Api::V1::Issues::CreateService.call(project, issue_params, current_user) - end - - private - - def issue_params - params.permit( - :status_id, :priority_id, :milestone_id, - :branch_name, :start_date, :due_date, - :subject, :description, :blockchain_token_num, - :pm_project_id, :pm_sprint_id, :pm_issue_type, - issue_tag_ids: [], - assigner_ids: [], - attachment_ids: [], - receivers_login: [] - ) - end -end diff --git a/app/helpers/pm/issues_helper.rb b/app/helpers/pm/issues_helper.rb deleted file mode 100644 index 79cd6dd3e..000000000 --- a/app/helpers/pm/issues_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module Pm::IssuesHelper -end diff --git a/app/models/issue_tag.rb b/app/models/issue_tag.rb index a3782abaf..e8ffa4c0a 100644 --- a/app/models/issue_tag.rb +++ b/app/models/issue_tag.rb @@ -14,6 +14,7 @@ # gid :integer # gitea_url :string(255) # pull_requests_count :integer default("0") +# pm_project_id :integer # # Indexes # @@ -29,7 +30,11 @@ class IssueTag < ApplicationRecord belongs_to :project, optional: true, counter_cache: true belongs_to :user, optional: true - validates :name, uniqueness: {scope: :project_id, message: "已存在" } + validates :name, uniqueness: {scope: :project_id, message: "已存在" }, if: :pm_project? + + def pm_project? + !project_id.zero? + end def self.init_data(project_id) data = init_issue_tag_data @@ -40,6 +45,15 @@ class IssueTag < ApplicationRecord $redis_cache.hset("project_init_issue_tags", project_id, 1) end + def self.pm_init_data(pm_project_id) + data = init_issue_tag_data + data.each do |item| + next if IssueTag.exists?(pm_project_id: pm_project_id, project_id: 0, name: item[0]) + IssueTag.create!(pm_project_id: pm_project_id, project_id: 0, name: item[0], description: item[1], color: item[2]) + end + $redis_cache.hset("pm_project_init_issue_tags", pm_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) diff --git a/db/migrate/20231101090823_add_pm_project_id.rb b/db/migrate/20231101090823_add_pm_project_id.rb new file mode 100644 index 000000000..81ba7130b --- /dev/null +++ b/db/migrate/20231101090823_add_pm_project_id.rb @@ -0,0 +1,5 @@ +class AddPmProjectId < ActiveRecord::Migration[5.2] + def change + add_column :issue_tags, :pm_project_id, :integer + end +end diff --git a/spec/controllers/pm/issues_controller_spec.rb b/spec/controllers/pm/issues_controller_spec.rb deleted file mode 100644 index cb80ebb71..000000000 --- a/spec/controllers/pm/issues_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe Pm::IssuesController, type: :controller do - -end diff --git a/spec/helpers/pm/issues_helper_spec.rb b/spec/helpers/pm/issues_helper_spec.rb deleted file mode 100644 index 43b9ba751..000000000 --- a/spec/helpers/pm/issues_helper_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'rails_helper' - -# Specs in this file have access to a helper object that includes -# the Pm::IssuesHelper. For example: -# -# describe Pm::IssuesHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# expect(helper.concat_strings("this","that")).to eq("this that") -# end -# end -# end -RSpec.describe Pm::IssuesHelper, type: :helper do - pending "add some examples to (or delete) #{__FILE__}" -end From 061b71955f82959e7011fcbc2756a28ed360f676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 2 Nov 2023 10:26:47 +0800 Subject: [PATCH 012/294] =?UTF-8?q?=20pm=20=E5=85=B3=E9=97=ADgrimoirelab?= =?UTF-8?q?=E6=8E=A8=E9=80=81=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/issues/create_service.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index 64a42b20d..7c158ca90 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -71,14 +71,14 @@ class Api::V1::Issues::CreateService < ApplicationService if @created_issue.blockchain_token_num.present? && @created_issue.blockchain_token_num > 0 Blockchain::CreateIssue.call({user_id: current_user.id, project_id: @created_issue.project_id, token_num: @created_issue.blockchain_token_num}) end - + push_activity_2_blockchain("issue_create", @created_issue) end project.del_project_issue_cache_delete_count # 把缓存里存储项目删除issue的个数清除掉 # 新增时向grimoirelab推送事件 - IssueWebhookJob.set(wait: 5.seconds).perform_later(@created_issue.id) + IssueWebhookJob.set(wait: 5.seconds).perform_later(@created_issue.id) unless @project.id.zero? # @信息发送 AtmeService.call(current_user, @atme_receivers, @created_issue) unless receivers_login.blank? From af002c731d7e0b197454a35979b156f1b0b3b02a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 2 Nov 2023 10:46:31 +0800 Subject: [PATCH 013/294] close pm webhook --- app/services/api/v1/issues/create_service.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index 7c158ca90..6e8834fe9 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -90,9 +90,9 @@ class Api::V1::Issues::CreateService < ApplicationService end # 触发webhook - TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueCreate', @created_issue&.id, current_user.id) - TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueLabel', @created_issue&.id, current_user.id, {issue_tag_ids: [[], issue_tag_ids]}) unless issue_tag_ids.blank? - TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueAssign', @created_issue&.id, current_user.id, {assigner_ids: [[], assigner_ids]}) unless assigner_ids.blank? + TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueCreate', @created_issue&.id, current_user.id) unless @project.id.zero? + TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueLabel', @created_issue&.id, current_user.id, {issue_tag_ids: [[], issue_tag_ids]}) unless issue_tag_ids.blank? && @project.id.zero? + TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueAssign', @created_issue&.id, current_user.id, {assigner_ids: [[], assigner_ids]}) unless assigner_ids.blank? && @project.id.zero? unlock("Api::V1::Issues::CreateService:#{project.id}") # 结束写数据,解锁 end From 8e658d4d12ada741ef9ec028a2a4211d55f1d89b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 2 Nov 2023 10:57:09 +0800 Subject: [PATCH 014/294] =?UTF-8?q?=E8=B0=83=E6=95=B4Pm=20webhook=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/issues/create_service.rb | 29 ++++++++++---------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index 6e8834fe9..7df9372a2 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -76,26 +76,27 @@ class Api::V1::Issues::CreateService < ApplicationService end project.del_project_issue_cache_delete_count # 把缓存里存储项目删除issue的个数清除掉 + unless project.id.zero? + # 新增时向grimoirelab推送事件 + IssueWebhookJob.set(wait: 5.seconds).perform_later(@created_issue.id) - # 新增时向grimoirelab推送事件 - IssueWebhookJob.set(wait: 5.seconds).perform_later(@created_issue.id) unless @project.id.zero? + # @信息发送 + AtmeService.call(current_user, @atme_receivers, @created_issue) unless receivers_login.blank? - # @信息发送 - AtmeService.call(current_user, @atme_receivers, @created_issue) unless receivers_login.blank? + # 发消息 + if Site.has_notice_menu? + SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @created_issue&.id, assigner_ids) unless assigner_ids.blank? + SendTemplateMessageJob.perform_later('ProjectIssue', current_user.id, @created_issue&.id) + end - # 发消息 - if Site.has_notice_menu? - SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @created_issue&.id, assigner_ids) unless assigner_ids.blank? - SendTemplateMessageJob.perform_later('ProjectIssue', current_user.id, @created_issue&.id) + # 触发webhook + TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueCreate', @created_issue&.id, current_user.id) + TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueLabel', @created_issue&.id, current_user.id, {issue_tag_ids: [[], issue_tag_ids]}) unless issue_tag_ids.blank? + TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueAssign', @created_issue&.id, current_user.id, {assigner_ids: [[], assigner_ids]}) unless assigner_ids.blank? end - - # 触发webhook - TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueCreate', @created_issue&.id, current_user.id) unless @project.id.zero? - TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueLabel', @created_issue&.id, current_user.id, {issue_tag_ids: [[], issue_tag_ids]}) unless issue_tag_ids.blank? && @project.id.zero? - TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueAssign', @created_issue&.id, current_user.id, {assigner_ids: [[], assigner_ids]}) unless assigner_ids.blank? && @project.id.zero? unlock("Api::V1::Issues::CreateService:#{project.id}") # 结束写数据,解锁 end - + return @created_issue end From 468c5a3c416c78350da179a0a314834a6dd7a535 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 2 Nov 2023 11:38:52 +0800 Subject: [PATCH 015/294] =?UTF-8?q?add=20pm=20issue=20=E7=9A=84=20pm=5Fpro?= =?UTF-8?q?ject=5Fid=20=E5=88=A4=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/base_controller.rb | 1 + app/controllers/api/pm/issues_controller.rb | 10 ++-------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/app/controllers/api/pm/base_controller.rb b/app/controllers/api/pm/base_controller.rb index 3fcc1cfb7..a78d29b38 100644 --- a/app/controllers/api/pm/base_controller.rb +++ b/app/controllers/api/pm/base_controller.rb @@ -30,6 +30,7 @@ class Api::Pm::BaseController < ApplicationController end def load_issue + return render_parameter_missing if params[:pm_project_id].blank? @issue = @project.issues.issue_issue.where(pm_project_id: params[:pm_project_id]).find_by_id(params[:id]) render_not_found('疑修不存在!') if @issue.blank? end diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 4b76783d2..45bc29e3c 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -2,8 +2,8 @@ class Api::Pm::IssuesController < Api::Pm::BaseController before_action :require_login, except: [:index] before_action :load_project before_action :load_issue, only: %i[show update destroy] - before_action :load_issues, only: [:batch_update, :batch_destroy] - before_action :check_issue_operate_permission, only: [:update, :destroy] + before_action :load_issues, only: %i[batch_update batch_destroy] + before_action :check_issue_operate_permission, only: %i[update destroy] def index @object_result = Api::V1::Issues::ListService.call(@project, query_params, current_user) @@ -94,12 +94,6 @@ class Api::Pm::IssuesController < Api::Pm::BaseController return if params[:project_id].zero? render_forbidden('您没有操作权限!') unless @project.member?(current_user) || current_user.admin? || @issue.user == current_user end - - def load_issue - @issue = @project.issues.issue_issue.where(pm_project_id: params[:pm_project_id]).find_by_id(params[:id]) - render_not_found('疑修不存在!') if @issue.blank? - end - def load_issues return render_error('请输入正确的ID数组!') unless params[:ids].is_a?(Array) params[:ids].each do |id| From dd30341f6ecf516c0402d99b6bca46886ad97eb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 2 Nov 2023 14:41:33 +0800 Subject: [PATCH 016/294] fix bug --- app/controllers/api/pm/issues_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 45bc29e3c..788951413 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -91,7 +91,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController private def check_issue_operate_permission - return if params[:project_id].zero? + return if params[:project_id].to_i.zero? render_forbidden('您没有操作权限!') unless @project.member?(current_user) || current_user.admin? || @issue.user == current_user end def load_issues From 840bbff88ade571d8fca69a1c2109c8b43ca4d97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 2 Nov 2023 15:04:43 +0800 Subject: [PATCH 017/294] add project pm --- app/assets/javascripts/api/pm/projects.js | 2 ++ app/assets/stylesheets/api/pm/projects.scss | 3 +++ app/controllers/api/pm/projects_controller.rb | 11 +++++++++++ app/controllers/projects_controller.rb | 9 --------- app/helpers/api/pm/projects_helper.rb | 2 ++ config/routes.rb | 1 - config/routes/api.rb | 5 +++++ .../api/pm/projects_controller_spec.rb | 5 +++++ spec/helpers/api/pm/projects_helper_spec.rb | 15 +++++++++++++++ 9 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 app/assets/javascripts/api/pm/projects.js create mode 100644 app/assets/stylesheets/api/pm/projects.scss create mode 100644 app/controllers/api/pm/projects_controller.rb create mode 100644 app/helpers/api/pm/projects_helper.rb create mode 100644 spec/controllers/api/pm/projects_controller_spec.rb create mode 100644 spec/helpers/api/pm/projects_helper_spec.rb diff --git a/app/assets/javascripts/api/pm/projects.js b/app/assets/javascripts/api/pm/projects.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/api/pm/projects.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/api/pm/projects.scss b/app/assets/stylesheets/api/pm/projects.scss new file mode 100644 index 000000000..7053c94f2 --- /dev/null +++ b/app/assets/stylesheets/api/pm/projects.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the api/pm/projects controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb new file mode 100644 index 000000000..4627b189a --- /dev/null +++ b/app/controllers/api/pm/projects_controller.rb @@ -0,0 +1,11 @@ +class Api::Pm::ProjectsController < Api::Pm::BaseController + + def convert + @project = Project.joins(:owner).find params[:project_id] + data = { + owner: @project.owner.try(:login), + identifier: @project.identifier + } + render_ok(data: data) + end +end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 2045eb7fd..fbc65960a 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -232,15 +232,6 @@ class ProjectsController < ApplicationController def show end - def mp_show - @project = Project.joins(:owner).find params[:project_id] - data={ - owner:@project.owner.try(:login), - identifier:@project.identifier - } - render_ok(data:data) - end - def destroy if current_user.admin? || @project.manager?(current_user) ActiveRecord::Base.transaction do diff --git a/app/helpers/api/pm/projects_helper.rb b/app/helpers/api/pm/projects_helper.rb new file mode 100644 index 000000000..172c270e7 --- /dev/null +++ b/app/helpers/api/pm/projects_helper.rb @@ -0,0 +1,2 @@ +module Api::Pm::ProjectsHelper +end diff --git a/config/routes.rb b/config/routes.rb index 647405bdb..9994206da 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -127,7 +127,6 @@ Rails.application.routes.draw do # blockchain related routes get 'users/blockchain/balance', to: 'users#blockchain_balance' - get 'projects/mp_show', to: 'projects#mp_show' post 'users/blockchain/balance_project', to: 'users#blockchain_balance_one_project' post 'users/blockchain/transfer', to: 'users#blockchain_transfer' post 'users/blockchain/exchange', to: 'users#blockchain_exchange' diff --git a/config/routes/api.rb b/config/routes/api.rb index 382843f89..fc38709ab 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -16,6 +16,11 @@ defaults format: :json do end end end + resources :projects do + collection do + get :convert + end + end end namespace :v1 do diff --git a/spec/controllers/api/pm/projects_controller_spec.rb b/spec/controllers/api/pm/projects_controller_spec.rb new file mode 100644 index 000000000..8b9e3c903 --- /dev/null +++ b/spec/controllers/api/pm/projects_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Api::Pm::ProjectsController, type: :controller do + +end diff --git a/spec/helpers/api/pm/projects_helper_spec.rb b/spec/helpers/api/pm/projects_helper_spec.rb new file mode 100644 index 000000000..b93449cc2 --- /dev/null +++ b/spec/helpers/api/pm/projects_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Api::Pm::ProjectsHelper. For example: +# +# describe Api::Pm::ProjectsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe Api::Pm::ProjectsHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end From b40fcf5d63236081b45c2d7f017527aa694f8521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 2 Nov 2023 17:04:33 +0800 Subject: [PATCH 018/294] update project pm --- app/controllers/api/pm/projects_controller.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index 4627b189a..5d5012885 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -1,11 +1,21 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController - + before_action :require_login, except: [:convert] + before_action :load_project def convert - @project = Project.joins(:owner).find params[:project_id] data = { owner: @project.owner.try(:login), identifier: @project.identifier } render_ok(data: data) end + + def bind_project + return render_forbidden('您没有操作权限!') unless @project.member?(current_user) || current_user.admin? + Issue.where(pm_project_id: params[:pm_project_id], user_id: current_user).update_all(project_id: params[:project_id]) + end + + private + def load_project + @project = Project.joins(:owner).find params[:project_id] + end end From 3362c787656b34055c9da3032a582fd0d0ffe265 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 18 Oct 2023 15:16:14 +0800 Subject: [PATCH 019/294] =?UTF-8?q?fixed=20issue=E6=8F=8F=E8=BF=B0?= =?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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/issue.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 6325a327f..d526b5102 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -231,7 +231,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 IS NULL OR container_type = 'Issue'").update_all(container_id: self.project_id, container_type: "Project") + Attachment.where(id: att_ids).where(container_type: nil).update_all(container_id: self.id, container_type: self.class.name) end end From 5646aadfd6fdae413d5b76c38bd81ecad90df98d Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 18 Oct 2023 15:24:39 +0800 Subject: [PATCH 020/294] =?UTF-8?q?fixed=20issue=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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/journal.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/journal.rb b/app/models/journal.rb index 30cd94143..3229ae886 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 IS NULL OR container_type = 'Journal'").update_all(container_id: self.issue.project_id, container_type: "Project") + Attachment.where(id: att_ids).where(container_type: nil).update_all(container_id: self.id, container_type: self.class.name) end end From 9c7ad15e3821a09b2268b5ee64495c0bb9bc8232 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 24 Oct 2023 20:41:02 +0800 Subject: [PATCH 021/294] =?UTF-8?q?fixed=20issue=E5=92=8C=E8=AF=84?= =?UTF-8?q?=E8=AE=BA=E9=87=8C=E7=9A=84=E9=99=84=E4=BB=B6=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E5=85=B3=E8=81=94=EF=BC=8C=E5=A2=9E=E5=BC=BA=E9=99=84=E4=BB=B6?= =?UTF-8?q?=E8=AE=BF=E9=97=AE=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6,?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E5=88=B0=20=E9=A1=B9=E7=9B=AE=E4=BF=9D?= =?UTF-8?q?=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/issue.rb | 2 +- app/models/journal.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index d526b5102..6325a327f 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -231,7 +231,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 From 289cb08ccd2c9c1df5a85bfd4d6c5988502d9637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 7 Nov 2023 09:40:50 +0800 Subject: [PATCH 022/294] issue time_scale --- app/controllers/api/pm/issues_controller.rb | 2 +- app/models/issue.rb | 1 + app/services/api/v1/issues/create_service.rb | 4 +- app/services/api/v1/issues/update_service.rb | 39 ++++++++++++------- app/views/api/v1/issues/_detail.json.jbuilder | 1 + .../20231107003833_add_hour_to_issues.rb | 5 +++ 6 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 db/migrate/20231107003833_add_hour_to_issues.rb diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 788951413..f9b7fb161 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -125,7 +125,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController def issue_params params.permit( :status_id, :priority_id, :milestone_id, - :branch_name, :start_date, :due_date, + :branch_name, :start_date, :due_date, :time_scale, :subject, :description, :blockchain_token_num, :pm_project_id, :pm_sprint_id, :pm_issue_type, :parent_id, issue_tag_ids: [], diff --git a/app/models/issue.rb b/app/models/issue.rb index 6325a327f..76208bdee 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -37,6 +37,7 @@ # pm_project_id :integer # pm_sprint_id :integer # pm_issue_type :integer +# time_scale :decimal(10, 2) default("0.00") # # Indexes # diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index 7df9372a2..8c6ecb64c 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -33,6 +33,7 @@ class Api::V1::Issues::CreateService < ApplicationService @pm_sprint_id = params[:pm_sprint_id] @pm_issue_type = params[:pm_issue_type] @parent_id = params[:parent_id] + @time_scale = params[:time_scale] end def call @@ -64,10 +65,11 @@ class Api::V1::Issues::CreateService < ApplicationService @created_issue.pm_sprint_id = @pm_sprint_id @created_issue.pm_issue_type = @pm_issue_type @created_issue.parent_id = @parent_id + @created_issue.time_scale = @time_scale @created_issue.issue_tags_value = @issue_tags.order("id asc").pluck(:id).join(",") unless issue_tag_ids.blank? @created_issue.save! - if Site.has_blockchain? && @project.use_blockchain + if Site.has_blockchain? && @project.use_blockchain if @created_issue.blockchain_token_num.present? && @created_issue.blockchain_token_num > 0 Blockchain::CreateIssue.call({user_id: current_user.id, project_id: @created_issue.project_id, token_num: @created_issue.blockchain_token_num}) end diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index d55c0f586..7bf2d5c08 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -30,6 +30,11 @@ class Api::V1::Issues::UpdateService < ApplicationService @before_assigner_ids = issue.assigners.pluck(:id) @attachment_ids = params[:attachment_ids] @receivers_login = params[:receivers_login] + @pm_project_id = params[:pm_project_id] + @pm_sprint_id = params[:pm_sprint_id] + @pm_issue_type = params[:pm_issue_type] + @parent_id = params[:parent_id] + @time_scale = params[:time_scale] @add_assigner_ids = [] @previous_issue_changes = {} end @@ -68,28 +73,34 @@ class Api::V1::Issues::UpdateService < ApplicationService @updated_issue.issue_tags_relates.destroy_all & @updated_issue.issue_tags = @issue_tags || IssueTag.none unless issue_tag_ids.nil? @updated_issue.issue_tags_value = @issue_tags.order("id asc").pluck(:id).join(",") unless issue_tag_ids.nil? + @created_issue.pm_project_id = @pm_project_id + @created_issue.pm_sprint_id = @pm_sprint_id + @created_issue.pm_issue_type = @pm_issue_type + @created_issue.parent_id = @parent_id + @created_issue.time_scale = @time_scale + @updated_issue.updated_on = Time.now @updated_issue.save! build_after_issue_journal_details if @updated_issue.previous_changes.present? # 操作记录 build_previous_issue_changes build_cirle_blockchain_token if blockchain_token_num.present? + unless project.id.zero? + # @信息发送 + AtmeService.call(current_user, @atme_receivers, @issue) unless receivers_login.blank? + # 消息发送 + if Site.has_notice_menu? + SendTemplateMessageJob.perform_later('IssueChanged', current_user.id, @issue&.id, previous_issue_changes) unless previous_issue_changes.blank? + SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id, add_assigner_ids) unless add_assigner_ids.blank? + end - # @信息发送 - 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? + unlock("Api::V1::Issues::UpdateService:#{project.id}:#{issue.id}") + # 触发webhook + Rails.logger.info "################### 触发webhook" + TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueUpdate', @updated_issue&.id, current_user.id, previous_issue_changes.except(:issue_tags_value, :assigned_to_id)) + TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueLabel', @issue&.id, current_user.id, {issue_tag_ids: [before_issue_tag_ids, issue_tag_ids]}) unless issue_tag_ids.nil? + TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueAssign', @issue&.id, current_user.id, {assigner_ids: [before_assigner_ids, assigner_ids]}) unless assigner_ids.nil? end - - unlock("Api::V1::Issues::UpdateService:#{project.id}:#{issue.id}") - # 触发webhook - Rails.logger.info "################### 触发webhook" - TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueUpdate', @updated_issue&.id, current_user.id, previous_issue_changes.except(:issue_tags_value, :assigned_to_id)) - TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueLabel', @issue&.id, current_user.id, {issue_tag_ids: [before_issue_tag_ids, issue_tag_ids]}) unless issue_tag_ids.nil? - TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueAssign', @issue&.id, current_user.id, {assigner_ids: [before_assigner_ids, assigner_ids]}) unless assigner_ids.nil? - return @updated_issue end end diff --git a/app/views/api/v1/issues/_detail.json.jbuilder b/app/views/api/v1/issues/_detail.json.jbuilder index bec02a555..395171873 100644 --- a/app/views/api/v1/issues/_detail.json.jbuilder +++ b/app/views/api/v1/issues/_detail.json.jbuilder @@ -49,3 +49,4 @@ json.parent_id issue.parent_id json.pm_issue_type issue.pm_issue_type json.pm_sprint_id issue.pm_sprint_id json.pm_project_id issue.pm_project_id +json.time_scale issue.time_scale \ No newline at end of file diff --git a/db/migrate/20231107003833_add_hour_to_issues.rb b/db/migrate/20231107003833_add_hour_to_issues.rb new file mode 100644 index 000000000..d0a3e4856 --- /dev/null +++ b/db/migrate/20231107003833_add_hour_to_issues.rb @@ -0,0 +1,5 @@ +class AddHourToIssues < ActiveRecord::Migration[5.2] + def change + add_column :issues, :time_scale, :decimal, precision: 10, scale: 2, default: 0.00 + end +end From 005f1d4aa51933ad6695c18171e0f677abb3f6c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 7 Nov 2023 09:54:50 +0800 Subject: [PATCH 023/294] update issue index render --- app/controllers/api/pm/issues_controller.rb | 5 ++--- app/views/api/v1/issues/_simple_detail.json.jbuilder | 6 ++++++ config/routes/api.rb | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index f9b7fb161..5b50e8c4a 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -75,9 +75,8 @@ class Api::Pm::IssuesController < Api::Pm::BaseController render "api/v1/issues/statues/index" end - def pm_index - @issue_tags = IssueTag.init_mp_issues_tags - render_ok(@issue_tags) + def count + end def destroy diff --git a/app/views/api/v1/issues/_simple_detail.json.jbuilder b/app/views/api/v1/issues/_simple_detail.json.jbuilder index 4a5a433be..0a9d18732 100644 --- a/app/views/api/v1/issues/_simple_detail.json.jbuilder +++ b/app/views/api/v1/issues/_simple_detail.json.jbuilder @@ -9,6 +9,12 @@ json.status_name issue.issue_status&.name json.priority_name issue.priority&.name json.milestone_name issue.version&.name json.milestone_id issue.fixed_version_id +json.parent_id issue.parent_id +json.pm_issue_type issue.pm_issue_type +json.pm_sprint_id issue.pm_sprint_id +json.pm_project_id issue.pm_project_id +json.time_scale issue.time_scale + json.author do if issue.user.present? json.partial! "api/v1/users/simple_user", locals: {user: issue.user} diff --git a/config/routes/api.rb b/config/routes/api.rb index fc38709ab..ea07d393a 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -8,6 +8,7 @@ defaults format: :json do get :priorities get :tags get :statues + get :count end resources :journals do From 8329cc113b1d1c330ba1a471426c370749affc0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 7 Nov 2023 11:44:36 +0800 Subject: [PATCH 024/294] add issue count to pm projects --- app/controllers/api/pm/issues_controller.rb | 2 -- app/controllers/api/pm/projects_controller.rb | 26 ++++++++++++++++++- config/routes/api.rb | 2 +- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 5b50e8c4a..2db60dccb 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -75,9 +75,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController render "api/v1/issues/statues/index" end - def count - end def destroy @object_result = Api::V1::Issues::DeleteService.call(@project, @issue, current_user) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index 5d5012885..1f05d02fb 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -1,6 +1,6 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController before_action :require_login, except: [:convert] - before_action :load_project + before_action :load_project, only: [:convert] def convert data = { owner: @project.owner.try(:login), @@ -9,6 +9,24 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController render_ok(data: data) end + def issues_count + return tip_exception '参数错误' unless params[:pm_project_id].present? + @issues = Issue.where(pm_project_id_params) + data = {} + @issues_count = @issues.group(:pm_project_id).count + # requirement 1 task 2 bug 3 + @issues_type_count = @issues.group(:pm_project_id, :pm_issue_type).count + pm_project_id_params[:pm_project_id].map(&:to_i).map do |project_id| + data[project_id] = { + total: @issues_count[project_id] || 0, + requirement: @issues_type_count[[project_id, 1]] || 0, + task: @issues_type_count[[project_id, 2]] || 0, + bug: @issues_type_count[[project_id, 3]] || 0 + } + end + render_ok(data: data) + end + def bind_project return render_forbidden('您没有操作权限!') unless @project.member?(current_user) || current_user.admin? Issue.where(pm_project_id: params[:pm_project_id], user_id: current_user).update_all(project_id: params[:project_id]) @@ -18,4 +36,10 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController def load_project @project = Project.joins(:owner).find params[:project_id] end + + def pm_project_id_params + params.permit( + pm_project_id: [] + ) + end end diff --git a/config/routes/api.rb b/config/routes/api.rb index ea07d393a..3789100d6 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -8,7 +8,6 @@ defaults format: :json do get :priorities get :tags get :statues - get :count end resources :journals do @@ -20,6 +19,7 @@ defaults format: :json do resources :projects do collection do get :convert + get :issues_count end end end From 00448f0f015c2e2be86bdf756f4af00921cc6e1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 7 Nov 2023 14:30:28 +0800 Subject: [PATCH 025/294] change parent_id to root_id --- app/controllers/api/pm/issues_controller.rb | 4 ++-- app/services/api/v1/issues/create_service.rb | 4 ++-- app/services/api/v1/issues/list_service.rb | 9 ++++----- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 2db60dccb..5ec4d7cfe 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -112,7 +112,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController :milestone_id, :assigner_id, :status_id, :begin_date, :end_date, - :sort_by, :sort_direction,:parent_id, + :sort_by, :sort_direction, :root_id, :issue_tag_ids, :pm_project_id, :pm_sprint_id, :pm_issue_type ) end @@ -124,7 +124,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController :status_id, :priority_id, :milestone_id, :branch_name, :start_date, :due_date, :time_scale, :subject, :description, :blockchain_token_num, - :pm_project_id, :pm_sprint_id, :pm_issue_type, :parent_id, + :pm_project_id, :pm_sprint_id, :pm_issue_type, :root_id, issue_tag_ids: [], assigner_ids: [], attachment_ids: [], diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index 8c6ecb64c..69e2e9464 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -32,7 +32,7 @@ class Api::V1::Issues::CreateService < ApplicationService @pm_project_id = params[:pm_project_id] @pm_sprint_id = params[:pm_sprint_id] @pm_issue_type = params[:pm_issue_type] - @parent_id = params[:parent_id] + @root_id = params[:root_id] @time_scale = params[:time_scale] end @@ -64,7 +64,7 @@ class Api::V1::Issues::CreateService < ApplicationService @created_issue.pm_project_id = @pm_project_id @created_issue.pm_sprint_id = @pm_sprint_id @created_issue.pm_issue_type = @pm_issue_type - @created_issue.parent_id = @parent_id + @created_issue.root_id = @root_id @created_issue.time_scale = @time_scale @created_issue.issue_tags_value = @issue_tags.order("id asc").pluck(:id).join(",") unless issue_tag_ids.blank? @created_issue.save! diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index 5e442c01f..3fd8e3adc 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -4,7 +4,7 @@ class Api::V1::Issues::ListService < ApplicationService attr_reader :project, :only_name, :category, :participant_category, :keyword, :author_id, :issue_tag_ids attr_reader :begin_date, :end_date attr_reader :milestone_id, :assigner_id, :status_id, :sort_by, :sort_direction, :current_user - attr_reader :pm_project_id, :pm_sprint_id, :parent_id, :pm_issue_type + attr_reader :pm_project_id, :pm_sprint_id, :root_id, :pm_issue_type attr_accessor :queried_issues, :total_issues_count, :closed_issues_count, :opened_issues_count validates :category, inclusion: {in: %w(all opened closed), message: "请输入正确的Category"} @@ -29,7 +29,7 @@ class Api::V1::Issues::ListService < ApplicationService @sort_by = params[:sort_by].present? ? params[:sort_by] : 'issues.updated_on' @pm_project_id = params[:pm_project_id] @pm_sprint_id = params[:pm_sprint_id] - @parent_id = params[:parent_id] + @root_id = params[:root_id] @pm_issue_type = params[:pm_issue_type] @sort_direction = (params[:sort_direction].present? ? params[:sort_direction] : 'desc').downcase @current_user = current_user @@ -60,7 +60,6 @@ class Api::V1::Issues::ListService < ApplicationService 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? @@ -71,8 +70,8 @@ class Api::V1::Issues::ListService < ApplicationService issues = issues.where(fixed_version_id: milestone_id) if milestone_id.present? #pm相关 - # parent_id, - issues = issues.where(parent_id: parent_id) if parent_id.present? + # root_id, + issues = issues.where(root_id: root_id) if root_id.present? # pm_issue_type issues = issues.where(pm_issue_type: pm_issue_type) if pm_issue_type.present? From c75267145393b596d023322e5f1099f74360f83b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 7 Nov 2023 17:16:25 +0800 Subject: [PATCH 026/294] issue links --- app/assets/javascripts/api/pm/issue_links.js | 2 + .../stylesheets/api/pm/issue_links.scss | 3 + app/controllers/api/pm/base_controller.rb | 2 +- .../api/pm/issue_links_controller.rb | 25 +++++++++ app/controllers/api/pm/issues_controller.rb | 15 ++++- app/helpers/api/pm/issue_links_helper.rb | 2 + app/models/issue.rb | 56 ++++++++++--------- app/models/pm_link.rb | 25 +++++++++ app/services/api/v1/issues/list_service.rb | 6 +- .../api/pm/issue_links/index.json.jbuilder | 7 +++ config/routes/api.rb | 1 + db/migrate/20231107072541_create_pm_links.rb | 12 ++++ .../api/pm/issue_links_controller_spec.rb | 5 ++ .../helpers/api/pm/issue_links_helper_spec.rb | 15 +++++ spec/models/pm_link_spec.rb | 5 ++ 15 files changed, 150 insertions(+), 31 deletions(-) create mode 100644 app/assets/javascripts/api/pm/issue_links.js create mode 100644 app/assets/stylesheets/api/pm/issue_links.scss create mode 100644 app/controllers/api/pm/issue_links_controller.rb create mode 100644 app/helpers/api/pm/issue_links_helper.rb create mode 100644 app/models/pm_link.rb create mode 100644 app/views/api/pm/issue_links/index.json.jbuilder create mode 100644 db/migrate/20231107072541_create_pm_links.rb create mode 100644 spec/controllers/api/pm/issue_links_controller_spec.rb create mode 100644 spec/helpers/api/pm/issue_links_helper_spec.rb create mode 100644 spec/models/pm_link_spec.rb diff --git a/app/assets/javascripts/api/pm/issue_links.js b/app/assets/javascripts/api/pm/issue_links.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/api/pm/issue_links.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/api/pm/issue_links.scss b/app/assets/stylesheets/api/pm/issue_links.scss new file mode 100644 index 000000000..730f1f3e1 --- /dev/null +++ b/app/assets/stylesheets/api/pm/issue_links.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the api/pm/issue_links controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/api/pm/base_controller.rb b/app/controllers/api/pm/base_controller.rb index a78d29b38..f2850ec95 100644 --- a/app/controllers/api/pm/base_controller.rb +++ b/app/controllers/api/pm/base_controller.rb @@ -31,7 +31,7 @@ class Api::Pm::BaseController < ApplicationController def load_issue return render_parameter_missing if params[:pm_project_id].blank? - @issue = @project.issues.issue_issue.where(pm_project_id: params[:pm_project_id]).find_by_id(params[:id]) + @issue = @project.issues.issue_issue.where(pm_project_id: params[:pm_project_id]).find_by_id(params[:issue_id]) render_not_found('疑修不存在!') if @issue.blank? end # 具有对仓库的管理权限 diff --git a/app/controllers/api/pm/issue_links_controller.rb b/app/controllers/api/pm/issue_links_controller.rb new file mode 100644 index 000000000..01ca9a059 --- /dev/null +++ b/app/controllers/api/pm/issue_links_controller.rb @@ -0,0 +1,25 @@ +class Api::Pm::IssueLinksController < Api::Pm::BaseController + before_action :load_project + before_action :load_issue + def index + @links = @issue.pm_links.where(be_linkable_type: 'Issue') + end + + def create + @link = @issue.pm_links.find_or_create_by(be_linkable_type: 'Issue', be_linkable_id: params[:link_id]) + data = { + data: { + id: @link.id, + issue_id: @link.linkable_id, + linked_issue_id: @link.be_linkable_id + } + } + render_ok(data) + end + + def destroy + @link = @issue.pm_links.find params[:id] + @link.destroy + render_ok + end +end diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 5ec4d7cfe..29a61542c 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -1,7 +1,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController before_action :require_login, except: [:index] before_action :load_project - before_action :load_issue, only: %i[show update destroy] + before_action :load_issue, only: %i[show update destroy link_index] before_action :load_issues, only: %i[batch_update batch_destroy] before_action :check_issue_operate_permission, only: %i[update destroy] @@ -19,6 +19,12 @@ class Api::Pm::IssuesController < Api::Pm::BaseController render 'api/v1/issues/index' end + def link_index + + end + + + def show @issue.associate_attachment_container render 'api/v1/issues/show' @@ -91,6 +97,13 @@ class Api::Pm::IssuesController < Api::Pm::BaseController return if params[:project_id].to_i.zero? render_forbidden('您没有操作权限!') unless @project.member?(current_user) || current_user.admin? || @issue.user == current_user end + + def load_issue + return render_parameter_missing if params[:pm_project_id].blank? + @issue = @project.issues.issue_issue.where(pm_project_id: params[:pm_project_id]).find_by_id(params[:id]) + render_not_found('疑修不存在!') if @issue.blank? + end + def load_issues return render_error('请输入正确的ID数组!') unless params[:ids].is_a?(Array) params[:ids].each do |id| diff --git a/app/helpers/api/pm/issue_links_helper.rb b/app/helpers/api/pm/issue_links_helper.rb new file mode 100644 index 000000000..ff7d1ef33 --- /dev/null +++ b/app/helpers/api/pm/issue_links_helper.rb @@ -0,0 +1,2 @@ +module Api::Pm::IssueLinksHelper +end diff --git a/app/models/issue.rb b/app/models/issue.rb index 76208bdee..c64cfadaa 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -60,16 +60,16 @@ class Issue < ApplicationRecord has_many :project_trends, as: :trend, dependent: :destroy has_one :pull_request # belongs_to :issue_tag,optional: true - belongs_to :priority, :class_name => 'IssuePriority', foreign_key: :priority_id,optional: true + belongs_to :priority, class_name: 'IssuePriority', foreign_key: :priority_id,optional: true belongs_to :version, foreign_key: :fixed_version_id,optional: true, counter_cache: true belongs_to :user,optional: true, foreign_key: :author_id belongs_to :issue_status, foreign_key: :status_id,optional: true has_many :commit_issues has_many :attachments, as: :container, dependent: :destroy # has_many :memos - has_many :journals, :as => :journalized, :dependent => :destroy + has_many :journals, as: :journalized, dependent: :destroy has_many :journal_details, through: :journals - has_many :claims, :dependent => :destroy + has_many :claims, dependent: :destroy has_many :claim_users, through: :claims, source: :user has_many :issue_tags_relates, dependent: :destroy has_many :issue_tags, through: :issue_tags_relates @@ -79,19 +79,21 @@ class Issue < ApplicationRecord 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_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 - has_many :pull_attached_issues, dependent: :destroy + 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 + has_many :pull_attached_issues, dependent: :destroy has_many :attach_pull_requests, through: :pull_attached_issues, source: :pull_request + # PM 关联工作项目 + has_many :pm_links, as: :linkable, dependent: :destroy 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_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)} @@ -100,27 +102,27 @@ class Issue < ApplicationRecord after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic def incre_project_common - CacheAsyncSetJob.perform_later("project_common_service", {issues: 1}, self.project_id) + CacheAsyncSetJob.perform_later('project_common_service', {issues: 1}, self.project_id) end def decre_project_common - CacheAsyncSetJob.perform_later("project_common_service", {issues: -1}, self.project_id) + CacheAsyncSetJob.perform_later('project_common_service', {issues: -1}, self.project_id) end def incre_user_statistic - CacheAsyncSetJob.perform_later("user_statistic_service", {issue_count: 1}, self.author_id) + CacheAsyncSetJob.perform_later('user_statistic_service', {issue_count: 1}, self.author_id) end def decre_user_statistic - CacheAsyncSetJob.perform_later("user_statistic_service", {issue_count: -1}, self.author_id) + CacheAsyncSetJob.perform_later('user_statistic_service', {issue_count: -1}, self.author_id) end def incre_platform_statistic - CacheAsyncSetJob.perform_later("platform_statistic_service", {issue_count: 1}) + CacheAsyncSetJob.perform_later('platform_statistic_service', {issue_count: 1}) end def decre_platform_statistic - CacheAsyncSetJob.perform_later("platform_statistic_service", {issue_count: -1}) + CacheAsyncSetJob.perform_later('platform_statistic_service', {issue_count: -1}) end def get_assign_user @@ -129,20 +131,20 @@ class Issue < ApplicationRecord def create_journal_detail(change_files, issue_files, issue_file_ids, user_id) journal_params = { - journalized_id: self.id, journalized_type: "Issue", user_id: user_id + journalized_id: self.id, journalized_type: 'Issue', user_id: user_id } journal = Journal.new journal_params if journal.save if change_files - old_attachment_names = self.attachments.select(:filename,:id).where(id: issue_file_ids).pluck(:filename).join(",") - new_attachment_name = self.attachments.select(:filename,:id).where(id: issue_files).pluck(:filename).join(",") - journal.journal_details.create(property: "attachment", prop_key: "#{issue_files.size}", old_value: old_attachment_names, value: new_attachment_name) + old_attachment_names = self.attachments.select(:filename,:id).where(id: issue_file_ids).pluck(:filename).join(',') + new_attachment_name = self.attachments.select(:filename,:id).where(id: issue_files).pluck(:filename).join(',') + journal.journal_details.create(property: 'attachment', prop_key: "#{issue_files.size}", old_value: old_attachment_names, value: new_attachment_name) end change_values = %w(subject description is_private assigned_to_id tracker_id status_id priority_id fixed_version_id start_date due_date estimated_hours done_ratio issue_tags_value issue_type token branch_name) change_values.each do |at| if self.send("saved_change_to_#{at}?") - journal.journal_details.create(property: "attr", prop_key: "#{at}", old_value: self.send("#{at}_before_last_save"), value: self.send(at)) + journal.journal_details.create(property: 'attr', prop_key: "#{at}", old_value: self.send("#{at}_before_last_save"), value: self.send(at)) end end end @@ -150,11 +152,11 @@ class Issue < ApplicationRecord def custom_journal_detail(prop_key, old_value, value, user_id) journal_params = { - journalized_id: self.id, journalized_type: "Issue", user_id: user_id + journalized_id: self.id, journalized_type: 'Issue', user_id: user_id } journal = Journal.new journal_params if journal.save - journal.journal_details.create(property: "attr", prop_key: prop_key, old_value: old_value, value: value) + journal.journal_details.create(property: 'attr', prop_key: prop_key, old_value: old_value, value: value) end end @@ -180,14 +182,14 @@ class Issue < ApplicationRecord def get_issue_tags_name if issue_tags.present? - issue_tags.select(:name).uniq.pluck(:name).join(",") + issue_tags.select(:name).uniq.pluck(:name).join(',') else nil end end def only_reply_journals - journals.where.not(notes: [nil, ""]).journal_includes.limit(2) + journals.where.not(notes: [nil, '']).journal_includes.limit(2) end def change_versions_count @@ -232,15 +234,15 @@ 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 IS NULL OR container_type = 'Issue'").update_all(container_id: self.project_id, container_type: "Project") + 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 def to_builder Jbuilder.new do |issue| issue.(self, :id, :project_issues_index, :subject, :description, :branch_name, :start_date, :due_date) - issue.created_at self.created_on.strftime("%Y-%m-%d %H:%M") - issue.updated_at self.updated_on.strftime("%Y-%m-%d %H:%M") + issue.created_at self.created_on.strftime('%Y-%m-%d %H:%M') + issue.updated_at self.updated_on.strftime('%Y-%m-%d %H:%M') issue.tags self.show_issue_tags.map{|t| JSON.parse(t.to_builder.target!)} issue.status self.issue_status.to_builder if self.priority.present? diff --git a/app/models/pm_link.rb b/app/models/pm_link.rb new file mode 100644 index 000000000..91962bf7b --- /dev/null +++ b/app/models/pm_link.rb @@ -0,0 +1,25 @@ +# == Schema Information +# +# Table name: pm_links +# +# id :integer not null, primary key +# be_linkable_type :string(255) not null +# be_linkable_id :integer not null +# linkable_type :string(255) not null +# linkable_id :integer not null +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_pm_links_on_linkable_id (linkable_id) +# index_pm_links_on_linkable_type (linkable_type) +# + +class PmLink < ApplicationRecord + belongs_to :linkable, polymorphic: true + + def be_linkable + be_linkable_type.constantize.find be_linkable_id + end +end diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index 3fd8e3adc..81eff04f7 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -70,8 +70,10 @@ class Api::V1::Issues::ListService < ApplicationService issues = issues.where(fixed_version_id: milestone_id) if milestone_id.present? #pm相关 - # root_id, - issues = issues.where(root_id: root_id) if root_id.present? + # root_id + if pm_project_id.present? + issues = issues.where(root_id: root_id.present? ? nil : root_id) + end # pm_issue_type issues = issues.where(pm_issue_type: pm_issue_type) if pm_issue_type.present? diff --git a/app/views/api/pm/issue_links/index.json.jbuilder b/app/views/api/pm/issue_links/index.json.jbuilder new file mode 100644 index 000000000..066319e13 --- /dev/null +++ b/app/views/api/pm/issue_links/index.json.jbuilder @@ -0,0 +1,7 @@ + +json.links @links.each do |link| + json.id link.id + json.issue do + json.partial! "api/v1/issues/simple_detail", locals: {issue: link.be_linkable} + end +end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index 3789100d6..7f5fb99cf 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -9,6 +9,7 @@ defaults format: :json do get :tags get :statues end + resources :issue_links resources :journals do member do diff --git a/db/migrate/20231107072541_create_pm_links.rb b/db/migrate/20231107072541_create_pm_links.rb new file mode 100644 index 000000000..84cdb00e8 --- /dev/null +++ b/db/migrate/20231107072541_create_pm_links.rb @@ -0,0 +1,12 @@ +class CreatePmLinks < ActiveRecord::Migration[5.2] + def change + create_table :pm_links do |t| + t.string :be_linkable_type, null: false + t.integer :be_linkable_id, null: false + + t.string :linkable_type, null: false, index: true + t.integer :linkable_id, null: false, index: true + t.timestamps + end + end +end diff --git a/spec/controllers/api/pm/issue_links_controller_spec.rb b/spec/controllers/api/pm/issue_links_controller_spec.rb new file mode 100644 index 000000000..a80df2c77 --- /dev/null +++ b/spec/controllers/api/pm/issue_links_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Api::Pm::IssueLinksController, type: :controller do + +end diff --git a/spec/helpers/api/pm/issue_links_helper_spec.rb b/spec/helpers/api/pm/issue_links_helper_spec.rb new file mode 100644 index 000000000..924962a6c --- /dev/null +++ b/spec/helpers/api/pm/issue_links_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Api::Pm::IssueLinksHelper. For example: +# +# describe Api::Pm::IssueLinksHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe Api::Pm::IssueLinksHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/pm_link_spec.rb b/spec/models/pm_link_spec.rb new file mode 100644 index 000000000..d911d5b7e --- /dev/null +++ b/spec/models/pm_link_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe PmLink, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From ec43b9e97d51eb526439d4d80589df32fdaf6291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 8 Nov 2023 09:07:16 +0800 Subject: [PATCH 027/294] add Pm issues link_index --- app/controllers/api/pm/issues_controller.rb | 5 +++-- config/routes/api.rb | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 29a61542c..a0dd63d0f 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -20,11 +20,12 @@ class Api::Pm::IssuesController < Api::Pm::BaseController end def link_index - + object_issues = Issue.includes(:pm_links).where( pm_project_id: params[:pm_project_id], root_id: nil ).where.not(pm_links: { linkable_id: params[:id] } ) + @issues = kaminari_paginate(object_issues) + render 'api/v1/issues/index' end - def show @issue.associate_attachment_container render 'api/v1/issues/show' diff --git a/config/routes/api.rb b/config/routes/api.rb index 7f5fb99cf..2a08425c4 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -9,6 +9,10 @@ defaults format: :json do get :tags get :statues end + member do + get :link_index + end + resources :issue_links resources :journals do From 452890f8255801eb2dcac6bf9c9241d11174b3b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 8 Nov 2023 09:17:13 +0800 Subject: [PATCH 028/294] pm issue link_index add pm_issues_type --- app/controllers/api/pm/issues_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index a0dd63d0f..e22593d0e 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -20,7 +20,8 @@ class Api::Pm::IssuesController < Api::Pm::BaseController end def link_index - object_issues = Issue.includes(:pm_links).where( pm_project_id: params[:pm_project_id], root_id: nil ).where.not(pm_links: { linkable_id: params[:id] } ) + pm_issues_type= params[:pm_issues_type] || 1 + object_issues = Issue.includes(:pm_links).where( pm_project_id: params[:pm_project_id], root_id: nil, pm_issues_type: pm_issues_type).where.not(pm_links: { linkable_id: params[:id] } ) @issues = kaminari_paginate(object_issues) render 'api/v1/issues/index' end From 43be8d1724a64a772cc57732c97f70289b1e613c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 8 Nov 2023 10:54:09 +0800 Subject: [PATCH 029/294] update --- app/controllers/api/pm/issues_controller.rb | 2 +- app/models/issue.rb | 9 ++++++++- app/views/api/v1/issues/_detail.json.jbuilder | 5 +++-- app/views/api/v1/issues/_simple_detail.json.jbuilder | 3 ++- db/migrate/20231108024716_add_child_count_to_issues.rb | 5 +++++ 5 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20231108024716_add_child_count_to_issues.rb diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index e22593d0e..8b7cc73d0 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -21,7 +21,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController def link_index pm_issues_type= params[:pm_issues_type] || 1 - object_issues = Issue.includes(:pm_links).where( pm_project_id: params[:pm_project_id], root_id: nil, pm_issues_type: pm_issues_type).where.not(pm_links: { linkable_id: params[:id] } ) + object_issues = Issue.includes(:pm_links).where(pm_project_id: params[:pm_project_id], root_id: nil, pm_issues_type: pm_issues_type).where.not(pm_links: { linkable_id: params[:id] } ) @issues = kaminari_paginate(object_issues) render 'api/v1/issues/index' end diff --git a/app/models/issue.rb b/app/models/issue.rb index c64cfadaa..85a7d7dd5 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -38,6 +38,7 @@ # pm_sprint_id :integer # pm_issue_type :integer # time_scale :decimal(10, 2) default("0.00") +# child_count :integer default("0") # # Indexes # @@ -97,7 +98,7 @@ class Issue < ApplicationRecord 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_create :incre_project_common, :incre_user_statistic, :incre_platform_statistic, :fresh_root_issue_count 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 @@ -117,6 +118,12 @@ class Issue < ApplicationRecord CacheAsyncSetJob.perform_later('user_statistic_service', {issue_count: -1}, self.author_id) end + def fresh_root_issue_count + return if root_id.nil? || root_id.zero? + root_issue = Issue.find_by(id: root_id) + root_count = Issue.where(root_id: root_id).count + root_issue.update(child_count: root_count) + end def incre_platform_statistic CacheAsyncSetJob.perform_later('platform_statistic_service', {issue_count: 1}) end diff --git a/app/views/api/v1/issues/_detail.json.jbuilder b/app/views/api/v1/issues/_detail.json.jbuilder index 395171873..6e86b6d92 100644 --- a/app/views/api/v1/issues/_detail.json.jbuilder +++ b/app/views/api/v1/issues/_detail.json.jbuilder @@ -45,8 +45,9 @@ json.attachments issue.attachments.each do |attachment| json.partial! "api/v1/attachments/simple_detail", locals: {attachment: attachment} end json.pull_fixed issue.pull_attached_issues.where(fixed: true).present? -json.parent_id issue.parent_id +json.root_id issue.root_id json.pm_issue_type issue.pm_issue_type json.pm_sprint_id issue.pm_sprint_id json.pm_project_id issue.pm_project_id -json.time_scale issue.time_scale \ No newline at end of file +json.time_scale issue.time_scale +json.child_count issue.child_count \ No newline at end of file diff --git a/app/views/api/v1/issues/_simple_detail.json.jbuilder b/app/views/api/v1/issues/_simple_detail.json.jbuilder index 0a9d18732..efcf2e5dd 100644 --- a/app/views/api/v1/issues/_simple_detail.json.jbuilder +++ b/app/views/api/v1/issues/_simple_detail.json.jbuilder @@ -9,11 +9,12 @@ json.status_name issue.issue_status&.name json.priority_name issue.priority&.name json.milestone_name issue.version&.name json.milestone_id issue.fixed_version_id -json.parent_id issue.parent_id +json.root_id issue.root_id json.pm_issue_type issue.pm_issue_type json.pm_sprint_id issue.pm_sprint_id json.pm_project_id issue.pm_project_id json.time_scale issue.time_scale +json.child_count issue.child_count json.author do if issue.user.present? diff --git a/db/migrate/20231108024716_add_child_count_to_issues.rb b/db/migrate/20231108024716_add_child_count_to_issues.rb new file mode 100644 index 000000000..73560b81e --- /dev/null +++ b/db/migrate/20231108024716_add_child_count_to_issues.rb @@ -0,0 +1,5 @@ +class AddChildCountToIssues < ActiveRecord::Migration[5.2] + def change + add_column :issues, :child_count, :integer, default:0 + end +end From 3fa3f3a7cc3b423ff53ff5404d1085eafca8e6c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 8 Nov 2023 10:57:31 +0800 Subject: [PATCH 030/294] issue refresh aftercreate change to aftersave --- app/models/issue.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 85a7d7dd5..ce4154b6d 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -98,8 +98,8 @@ class Issue < ApplicationRecord 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, :fresh_root_issue_count - after_save :change_versions_count, :send_update_message_to_notice_system, :associate_attachment_container + after_create :incre_project_common, :incre_user_statistic, :incre_platform_statistic + after_save :change_versions_count, :send_update_message_to_notice_system, :associate_attachment_container, :fresh_root_issue_count after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic def incre_project_common From a572554102f5023a9904a33d1b0968594b869875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 8 Nov 2023 10:59:30 +0800 Subject: [PATCH 031/294] rename --- app/models/issue.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index ce4154b6d..640d7300b 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -99,7 +99,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, :associate_attachment_container, :fresh_root_issue_count + after_save :change_versions_count, :send_update_message_to_notice_system, :associate_attachment_container, :refresh_root_issue_count after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic def incre_project_common @@ -118,7 +118,7 @@ class Issue < ApplicationRecord CacheAsyncSetJob.perform_later('user_statistic_service', {issue_count: -1}, self.author_id) end - def fresh_root_issue_count + def refresh_root_issue_count return if root_id.nil? || root_id.zero? root_issue = Issue.find_by(id: root_id) root_count = Issue.where(root_id: root_id).count From 778f564e8b2c0326471332133238a8d5081e28b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 8 Nov 2023 14:31:03 +0800 Subject: [PATCH 032/294] fix bug for pm issue --- app/controllers/api/pm/issues_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 8b7cc73d0..1071dae52 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -20,8 +20,8 @@ class Api::Pm::IssuesController < Api::Pm::BaseController end def link_index - pm_issues_type= params[:pm_issues_type] || 1 - object_issues = Issue.includes(:pm_links).where(pm_project_id: params[:pm_project_id], root_id: nil, pm_issues_type: pm_issues_type).where.not(pm_links: { linkable_id: params[:id] } ) + pm_issue_type = params[:pm_issue_type] || [1,2,3] + object_issues = Issue.includes(:pm_links).where(pm_project_id: params[:pm_project_id], root_id: nil, pm_issue_type: pm_issue_type).where.not(pm_links: { linkable_id: params[:id] } ) @issues = kaminari_paginate(object_issues) render 'api/v1/issues/index' end From 086b66d51dcfdc7fea9c81b9cad14d2cacb4f681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 8 Nov 2023 14:45:40 +0800 Subject: [PATCH 033/294] update pm link_index --- app/controllers/api/pm/issues_controller.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 1071dae52..84f3f34a5 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -20,8 +20,14 @@ class Api::Pm::IssuesController < Api::Pm::BaseController end def link_index - pm_issue_type = params[:pm_issue_type] || [1,2,3] - object_issues = Issue.includes(:pm_links).where(pm_project_id: params[:pm_project_id], root_id: nil, pm_issue_type: pm_issue_type).where.not(pm_links: { linkable_id: params[:id] } ) + pm_issue_type = params[:pm_issue_type] || [1, 2, 3] + object_issues = Issue.includes(:pm_links).where( + pm_project_id: params[:pm_project_id], + root_id: nil, + pm_issue_type: pm_issue_type + ).where.not( + id: @issue.pm_links.pluck(:be_linkable_id) + ) @issues = kaminari_paginate(object_issues) render 'api/v1/issues/index' end From e66ae562b7231d1154f7d2617bd977982d18d4f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 8 Nov 2023 14:57:22 +0800 Subject: [PATCH 034/294] fix --- app/controllers/api/pm/issues_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 84f3f34a5..dc477e67a 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -21,13 +21,13 @@ class Api::Pm::IssuesController < Api::Pm::BaseController def link_index pm_issue_type = params[:pm_issue_type] || [1, 2, 3] + not_join_id = @issue.pm_links.pluck(:be_linkable_id) + not_join_id << @issue.id object_issues = Issue.includes(:pm_links).where( pm_project_id: params[:pm_project_id], root_id: nil, pm_issue_type: pm_issue_type - ).where.not( - id: @issue.pm_links.pluck(:be_linkable_id) - ) + ).where.not(id: not_join_id) @issues = kaminari_paginate(object_issues) render 'api/v1/issues/index' end From fcea1193b99724e4996840aea8824c62cea62d57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 8 Nov 2023 16:24:10 +0800 Subject: [PATCH 035/294] issue status and priority color --- app/models/issue_priority.rb | 17 +++++++++++++++ app/models/issue_status.rb | 21 ++++++++++++++++++- .../_simple_detail.json.jbuilder | 2 +- .../statues/_simple_detail.json.jbuilder | 2 +- 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/app/models/issue_priority.rb b/app/models/issue_priority.rb index 5bf70da05..0ccd13b6b 100644 --- a/app/models/issue_priority.rb +++ b/app/models/issue_priority.rb @@ -38,4 +38,21 @@ class IssuePriority < ApplicationRecord priority.(self, :id, :name) end end + + def mp_color + case name + when '低' + '#13b33e' + when '正常' + '#0d5ef8' + when '高' + '#ff6f00' + when '紧急' + '#d20f0f' + when '立刻' + '#f5222d' + else + '13b33e' + end + end end diff --git a/app/models/issue_status.rb b/app/models/issue_status.rb index fde871182..efa0a7d81 100644 --- a/app/models/issue_status.rb +++ b/app/models/issue_status.rb @@ -45,9 +45,28 @@ class IssueStatus < ApplicationRecord end end - def to_builder + def to_builder Jbuilder.new do |status| status.(self, :id, :name) end end + + def mp_color + case name + when '新增' + '#ff6f00' + when '正在解决' + '#0d5ef8' + when '已解决' + '#13b33e' + when '关闭' + '#b1aaa5' + when '反馈' + '#13c2c2' + when '拒绝' + '#ff0000' + else + '#ff6f00' + end + end end diff --git a/app/views/api/v1/issues/issue_priorities/_simple_detail.json.jbuilder b/app/views/api/v1/issues/issue_priorities/_simple_detail.json.jbuilder index b7c37147a..d3644c8f1 100644 --- a/app/views/api/v1/issues/issue_priorities/_simple_detail.json.jbuilder +++ b/app/views/api/v1/issues/issue_priorities/_simple_detail.json.jbuilder @@ -1 +1 @@ -json.(priority, :id, :name) +json.(priority, :id, :name,:mp_color) diff --git a/app/views/api/v1/issues/statues/_simple_detail.json.jbuilder b/app/views/api/v1/issues/statues/_simple_detail.json.jbuilder index f66b6c95a..62cb4fcca 100644 --- a/app/views/api/v1/issues/statues/_simple_detail.json.jbuilder +++ b/app/views/api/v1/issues/statues/_simple_detail.json.jbuilder @@ -1 +1 @@ -json.(status, :id, :name) +json.(status, :id, :name, :mp_color) From 7fb462d2dbb6293f6cf3646d71b25ddbed336b19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 8 Nov 2023 16:28:45 +0800 Subject: [PATCH 036/294] change name --- app/models/issue_priority.rb | 2 +- app/models/issue_status.rb | 2 +- .../api/v1/issues/issue_priorities/_simple_detail.json.jbuilder | 2 +- app/views/api/v1/issues/statues/_simple_detail.json.jbuilder | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/issue_priority.rb b/app/models/issue_priority.rb index 0ccd13b6b..9a3d69392 100644 --- a/app/models/issue_priority.rb +++ b/app/models/issue_priority.rb @@ -39,7 +39,7 @@ class IssuePriority < ApplicationRecord end end - def mp_color + def pm_color case name when '低' '#13b33e' diff --git a/app/models/issue_status.rb b/app/models/issue_status.rb index efa0a7d81..cf1bc9f9b 100644 --- a/app/models/issue_status.rb +++ b/app/models/issue_status.rb @@ -51,7 +51,7 @@ class IssueStatus < ApplicationRecord end end - def mp_color + def pm_color case name when '新增' '#ff6f00' diff --git a/app/views/api/v1/issues/issue_priorities/_simple_detail.json.jbuilder b/app/views/api/v1/issues/issue_priorities/_simple_detail.json.jbuilder index d3644c8f1..f5cf659d8 100644 --- a/app/views/api/v1/issues/issue_priorities/_simple_detail.json.jbuilder +++ b/app/views/api/v1/issues/issue_priorities/_simple_detail.json.jbuilder @@ -1 +1 @@ -json.(priority, :id, :name,:mp_color) +json.(priority, :id, :name,:pm_color) diff --git a/app/views/api/v1/issues/statues/_simple_detail.json.jbuilder b/app/views/api/v1/issues/statues/_simple_detail.json.jbuilder index 62cb4fcca..c649fc37a 100644 --- a/app/views/api/v1/issues/statues/_simple_detail.json.jbuilder +++ b/app/views/api/v1/issues/statues/_simple_detail.json.jbuilder @@ -1 +1 @@ -json.(status, :id, :name, :mp_color) +json.(status, :id, :name, :pm_color) From ed5bf51821de3eeac666ed5c468e7609c5c1e46e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 9 Nov 2023 11:07:03 +0800 Subject: [PATCH 037/294] add issues.start_date and issues.due_date to issue_list service --- .gitignore | 2 +- app/services/api/v1/issues/list_service.rb | 26 +++++++++++----------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 4a01bd5ec..5935e048d 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ # Ignore lock config file *.log - +.rubocop.yml # mac *.DS_Store .bashrc diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index 81eff04f7..c9d9b2bb1 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -7,20 +7,20 @@ class Api::V1::Issues::ListService < ApplicationService attr_reader :pm_project_id, :pm_sprint_id, :root_id, :pm_issue_type 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', 'issues.blockchain_token_num', 'issue_priorities.position'], message: '请输入正确的SortBy'}, allow_blank: true - validates :sort_direction, inclusion: {in: %w(asc desc), message: '请输入正确的SortDirection'}, allow_blank: true + validates :category, inclusion: { in: %w[all opened closed], message: '请输入正确的Category'} + validates :participant_category, inclusion: { in: %w[all aboutme authoredme assignedme atme], message: '请输入正确的ParticipantCategory'} + validates :sort_by, inclusion: { in: %w[issues.created_on issues.updated_on issues.blockchain_token_num issue_priorities.position issues.start_date issues.due_date] , message: '请输入正确的SortBy'}, allow_blank: true + validates :sort_direction, inclusion: { in: %w[asc desc], message: '请输入正确的SortDirection'}, allow_blank: true validates :current_user, presence: true - def initialize(project, params, current_user=nil) + def initialize(project, params, current_user = nil) @project = project @only_name = params[:only_name] @category = params[:category] || 'all' @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(",") : [] + @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] @@ -35,12 +35,12 @@ class Api::V1::Issues::ListService < ApplicationService @current_user = current_user end - def call - raise Error, errors.full_messages.join(", ") unless valid? + def call + raise Error, errors.full_messages.join(', ') unless valid? # begin - issue_query_data + issue_query_data - return {data: queried_issues, total_issues_count: @total_issues_count, closed_issues_count: @closed_issues_count, opened_issues_count: @opened_issues_count} + {data: queried_issues, total_issues_count: @total_issues_count, closed_issues_count: @closed_issues_count, opened_issues_count: @opened_issues_count} # rescue # raise Error, "服务器错误,请联系系统管理员!" # end @@ -52,7 +52,7 @@ class Api::V1::Issues::ListService < ApplicationService case participant_category when 'aboutme' # 关于我的 - issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: %w(authored assigned atme), participant_id: current_user&.id}) + issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: %w[authored assigned atme], participant_id: current_user&.id}) when 'authoredme' # 我创建的 issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: 'authored', participant_id: current_user&.id}) when 'assignedme' # 我负责的 @@ -64,7 +64,7 @@ class Api::V1::Issues::ListService < ApplicationService 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? + 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? @@ -91,7 +91,7 @@ class Api::V1::Issues::ListService < ApplicationService issues = issues.where(status_id: status_id) if status_id.present? && category != 'closed' if begin_date&.present? || end_date&.present? - issues = issues.where("issues.created_on between ? and ?", begin_date&.present? ? begin_date.to_time : Time.now.beginning_of_day, end_date&.present? ? end_date.to_time.end_of_day : Time.now.end_of_day) + issues = issues.where('issues.created_on between ? and ?', begin_date&.present? ? begin_date.to_time : Time.now.beginning_of_day, end_date&.present? ? end_date.to_time.end_of_day : Time.now.end_of_day) end # keyword From 12bf781c8b24cceb2ffba723770039055fc27613 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 9 Nov 2023 11:24:35 +0800 Subject: [PATCH 038/294] remote pm for routes --- config/routes.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 9994206da..312f267da 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -791,11 +791,6 @@ Rails.application.routes.draw do end end - namespace :pm do - resource :issues - resource :journals - end - namespace :admins do mount Sidekiq::Web => '/sidekiq' get '/', to: 'dashboards#index' From b1d8245a22b00801114c8e3e1928748fd6ab7ef2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 9 Nov 2023 14:01:12 +0800 Subject: [PATCH 039/294] update --- app/services/api/v1/issues/update_service.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 7bf2d5c08..a17065654 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -33,7 +33,7 @@ class Api::V1::Issues::UpdateService < ApplicationService @pm_project_id = params[:pm_project_id] @pm_sprint_id = params[:pm_sprint_id] @pm_issue_type = params[:pm_issue_type] - @parent_id = params[:parent_id] + @root_id = params[:root_id] @time_scale = params[:time_scale] @add_assigner_ids = [] @previous_issue_changes = {} @@ -76,7 +76,7 @@ class Api::V1::Issues::UpdateService < ApplicationService @created_issue.pm_project_id = @pm_project_id @created_issue.pm_sprint_id = @pm_sprint_id @created_issue.pm_issue_type = @pm_issue_type - @created_issue.parent_id = @parent_id + @created_issue.root_id = @root_id @created_issue.time_scale = @time_scale @updated_issue.updated_on = Time.now From 6267217c4b6b81bd5c0762369eec5159810a7ce3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 9 Nov 2023 14:20:34 +0800 Subject: [PATCH 040/294] update Api::V1::Issues::UpdateService --- app/controllers/api/pm/issues_controller.rb | 8 +++++++- app/services/api/v1/issues/update_service.rb | 13 ++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index dc477e67a..f71249abf 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -153,7 +153,13 @@ class Api::Pm::IssuesController < Api::Pm::BaseController ) end - private + def batch_issue_params + params.permit( + :status_id, :priority_id, :milestone_id, :pm_sprint_id, :pm_issue_type, :root_id, :target_pm_project_id, + :issue_tag_ids => [], + :assigner_ids => [] ) + end + def tag_sort_by sort_by = params.fetch(:sort_by, "created_at") sort_by = IssueTag.column_names.include?(sort_by) ? sort_by : "created_at" diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index a17065654..9d2e01924 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -30,7 +30,7 @@ class Api::V1::Issues::UpdateService < ApplicationService @before_assigner_ids = issue.assigners.pluck(:id) @attachment_ids = params[:attachment_ids] @receivers_login = params[:receivers_login] - @pm_project_id = params[:pm_project_id] + @target_pm_project_id = params[:target_pm_project_id] @pm_sprint_id = params[:pm_sprint_id] @pm_issue_type = params[:pm_issue_type] @root_id = params[:root_id] @@ -72,12 +72,11 @@ class Api::V1::Issues::UpdateService < ApplicationService @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? - - @created_issue.pm_project_id = @pm_project_id - @created_issue.pm_sprint_id = @pm_sprint_id - @created_issue.pm_issue_type = @pm_issue_type - @created_issue.root_id = @root_id - @created_issue.time_scale = @time_scale + @updated_issue.pm_project_id = @target_pm_project_id + @updated_issue.pm_sprint_id = @pm_sprint_id + @updated_issue.pm_issue_type = @pm_issue_type + @updated_issue.root_id = @root_id + @updated_issue.time_scale = @time_scale @updated_issue.updated_on = Time.now @updated_issue.save! From e4c4518e8b08643ba9ea77ccc2463d982d5b603c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 9 Nov 2023 14:31:55 +0800 Subject: [PATCH 041/294] add rule for update pm --- app/services/api/v1/issues/update_service.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 9d2e01924..594200286 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -72,11 +72,11 @@ class Api::V1::Issues::UpdateService < ApplicationService @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.pm_project_id = @target_pm_project_id - @updated_issue.pm_sprint_id = @pm_sprint_id - @updated_issue.pm_issue_type = @pm_issue_type - @updated_issue.root_id = @root_id - @updated_issue.time_scale = @time_scale + @updated_issue.pm_project_id = @target_pm_project_id unless @target_pm_project_id.nil? + @updated_issue.pm_sprint_id = @pm_sprint_id unless @pm_sprint_id.nil? + @updated_issue.pm_issue_type = @pm_issue_type unless @pm_issue_type.nil? + @updated_issue.root_id = @root_id unless @root_id.nil? + @updated_issue.time_scale = @time_scale unless @time_scale.nil? @updated_issue.updated_on = Time.now @updated_issue.save! From df201d74e0b46864dff850c460701236a90305b7 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 10 Nov 2023 09:44:36 +0800 Subject: [PATCH 042/294] =?UTF-8?q?pm=20issue=E4=BF=AE=E6=94=B9=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E9=94=81=E9=87=8A=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/issues/update_service.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 594200286..8f1fe303b 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -92,14 +92,14 @@ class Api::V1::Issues::UpdateService < ApplicationService 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}") # 触发webhook Rails.logger.info "################### 触发webhook" TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueUpdate', @updated_issue&.id, current_user.id, previous_issue_changes.except(:issue_tags_value, :assigned_to_id)) TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueLabel', @issue&.id, current_user.id, {issue_tag_ids: [before_issue_tag_ids, issue_tag_ids]}) unless issue_tag_ids.nil? TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueAssign', @issue&.id, current_user.id, {assigner_ids: [before_assigner_ids, assigner_ids]}) unless assigner_ids.nil? end + + unlock("Api::V1::Issues::UpdateService:#{project.id}:#{issue.id}") return @updated_issue end end From 71305d73040cc8f7a974ece1ccded1f675ad8876 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 10 Nov 2023 10:14:15 +0800 Subject: [PATCH 043/294] =?UTF-8?q?pm=20issue=20=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=8F=96=E6=B6=88=E5=85=B3=E8=81=94=EF=BC=8C=E9=98=B2=E6=AD=A2?= =?UTF-8?q?=E5=85=B3=E8=81=94=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index f71249abf..02e1736e1 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -108,7 +108,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController def load_issue return render_parameter_missing if params[:pm_project_id].blank? - @issue = @project.issues.issue_issue.where(pm_project_id: params[:pm_project_id]).find_by_id(params[:id]) + @issue = Issue.issue_issue.where(pm_project_id: params[:pm_project_id]).find_by_id(params[:id]) render_not_found('疑修不存在!') if @issue.blank? end From 2437bda410e69d71c6aa4f2f01ae1e5baaa80dee Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 14 Nov 2023 10:17:30 +0800 Subject: [PATCH 044/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=A0=B9=E6=8D=AEroot=5Fid=E6=9F=A5=E8=AF=A2=E5=88=B0?= =?UTF-8?q?=E5=AF=B9=E5=BA=94issue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/issues/list_service.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index c9d9b2bb1..3d5488bba 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -71,8 +71,8 @@ class Api::V1::Issues::ListService < ApplicationService #pm相关 # root_id - if pm_project_id.present? - issues = issues.where(root_id: root_id.present? ? nil : root_id) + if root_id.present? + issues = issues.where(root_id: root_id).or(issues.where(id: root_id)) end # pm_issue_type From 32386c2f66ca265aa4ef44164dd79293644c8cdb Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 14 Nov 2023 10:37:16 +0800 Subject: [PATCH 045/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E5=88=A0=E9=99=A4ids=E4=B8=BA=E7=A9=BA=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=85=A8=E9=83=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 02e1736e1..52411d5db 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -120,7 +120,11 @@ class Api::Pm::IssuesController < Api::Pm::BaseController return render_not_found("ID为#{id}的疑修不存在!") end end - @issues = Issue.where(id: params[:ids], pm_project_id: params[:pm_project_id]) + if params[:ids].blank? + @issues = Issue.where(pm_project_id: params[:pm_project_id]) + else + @issues = Issue.where(id: params[:ids], pm_project_id: params[:pm_project_id]) + end end From 0c553203c1005f1a4b2e8d1595a6bf9c3e7f268d Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 14 Nov 2023 10:52:15 +0800 Subject: [PATCH 046/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Aissue?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=80=85=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/issue.rb | 3 +++ app/services/api/v1/issues/create_service.rb | 1 + app/services/api/v1/issues/update_service.rb | 1 + app/views/api/v1/issues/_detail.json.jbuilder | 7 +++++++ db/migrate/20231114023928_add_changer_to_issues.rb | 5 +++++ 5 files changed, 17 insertions(+) create mode 100644 db/migrate/20231114023928_add_changer_to_issues.rb diff --git a/app/models/issue.rb b/app/models/issue.rb index 640d7300b..67e65593f 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -39,12 +39,14 @@ # pm_issue_type :integer # time_scale :decimal(10, 2) default("0.00") # child_count :integer default("0") +# changer_id :integer # # Indexes # # index_issues_on_assigned_to_id (assigned_to_id) # index_issues_on_author_id (author_id) # index_issues_on_category_id (category_id) +# index_issues_on_changer_id (changer_id) # index_issues_on_created_on (created_on) # index_issues_on_fixed_version_id (fixed_version_id) # index_issues_on_priority_id (priority_id) @@ -90,6 +92,7 @@ class Issue < ApplicationRecord has_many :attach_pull_requests, through: :pull_attached_issues, source: :pull_request # PM 关联工作项目 has_many :pm_links, as: :linkable, dependent: :destroy + belongs_to :changer, class_name: 'User', foreign_key: :changer_id, optional: true scope :issue_includes, ->{includes(:user)} scope :issue_many_includes, ->{includes(journals: :user)} diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index 69e2e9464..1a5e309a8 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -67,6 +67,7 @@ class Api::V1::Issues::CreateService < ApplicationService @created_issue.root_id = @root_id @created_issue.time_scale = @time_scale @created_issue.issue_tags_value = @issue_tags.order("id asc").pluck(:id).join(",") unless issue_tag_ids.blank? + @created_issue.changer_id = @current_user.id @created_issue.save! if Site.has_blockchain? && @project.use_blockchain diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 8f1fe303b..25f5b7d39 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -79,6 +79,7 @@ class Api::V1::Issues::UpdateService < ApplicationService @updated_issue.time_scale = @time_scale unless @time_scale.nil? @updated_issue.updated_on = Time.now + @updated_issue.changer_id = current_user.id @updated_issue.save! build_after_issue_journal_details if @updated_issue.previous_changes.present? # 操作记录 diff --git a/app/views/api/v1/issues/_detail.json.jbuilder b/app/views/api/v1/issues/_detail.json.jbuilder index 6e86b6d92..b01f6058e 100644 --- a/app/views/api/v1/issues/_detail.json.jbuilder +++ b/app/views/api/v1/issues/_detail.json.jbuilder @@ -33,6 +33,13 @@ json.author do json.nil! end end +json.changer do + if issue.changer.present? + json.partial! "api/v1/users/simple_user", locals: {user: issue.changer} + else + json.nil! + end +end json.assigners issue.show_assigners.each do |assigner| json.partial! "api/v1/users/simple_user", locals: {user: assigner} end diff --git a/db/migrate/20231114023928_add_changer_to_issues.rb b/db/migrate/20231114023928_add_changer_to_issues.rb new file mode 100644 index 000000000..4dff74ed1 --- /dev/null +++ b/db/migrate/20231114023928_add_changer_to_issues.rb @@ -0,0 +1,5 @@ +class AddChangerToIssues < ActiveRecord::Migration[5.2] + def change + add_reference :issues, :changer + end +end From 7080b74ebe27efce9812b66510041864111a5dec Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 14 Nov 2023 10:56:44 +0800 Subject: [PATCH 047/294] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=A4=B4?= =?UTF-8?q?=E5=83=8F=E8=BF=94=E5=9B=9E=E7=BB=9D=E5=AF=B9=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/api/v1/users/_simple_user.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/api/v1/users/_simple_user.json.jbuilder b/app/views/api/v1/users/_simple_user.json.jbuilder index ef45bcd94..5e8e970e7 100644 --- a/app/views/api/v1/users/_simple_user.json.jbuilder +++ b/app/views/api/v1/users/_simple_user.json.jbuilder @@ -3,7 +3,7 @@ if user.present? json.type user.type json.name user.real_name json.login user.login - json.image_url url_to_avatar(user) + json.image_url Rails.application.config_for(:configuration)['platform_url'] + "/" + url_to_avatar(user).to_s else json.nil! end \ No newline at end of file From 85322819047a22906d5c14f1b89b25a5f13d31bd Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 14 Nov 2023 11:03:58 +0800 Subject: [PATCH 048/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E6=96=87=E4=BB=B6=E6=96=B0=E5=A2=9E=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/attachments/create.json.jbuilder | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/views/attachments/create.json.jbuilder b/app/views/attachments/create.json.jbuilder index 3c0ef3559..6ddc5ced2 100644 --- a/app/views/attachments/create.json.jbuilder +++ b/app/views/attachments/create.json.jbuilder @@ -1,2 +1,7 @@ json.id @attachment.id -json.filesize @attachment.filesize +json.title @attachment.title +json.filesize number_to_human_size(@attachment.filesize) +json.is_pdf @attachment.is_pdf? +json.url Rails.application.config_for(:configuration)['platform_url'] + (@attachment.is_pdf? ? download_url(@attachment,disposition:"inline") : download_url(@attachment)).to_s +json.created_on @attachment.created_on.strftime("%Y-%m-%d %H:%M") +json.content_type @attachment.content_type From a47493439182ce844bcc3267bd1a713da8f48ac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 14 Nov 2023 14:39:00 +0800 Subject: [PATCH 049/294] =?UTF-8?q?=E6=9B=B4=E6=96=B0issue=20update?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=20changer=E5=8F=96=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/issues/update_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 25f5b7d39..48362f01b 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -79,7 +79,7 @@ class Api::V1::Issues::UpdateService < ApplicationService @updated_issue.time_scale = @time_scale unless @time_scale.nil? @updated_issue.updated_on = Time.now - @updated_issue.changer_id = current_user.id + @updated_issue.changer_id = @current_user.id @updated_issue.save! build_after_issue_journal_details if @updated_issue.previous_changes.present? # 操作记录 From be45e45dbc41f4d291aabe1ee9fb4f1bb7dfef2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 14 Nov 2023 16:02:26 +0800 Subject: [PATCH 050/294] =?UTF-8?q?=E5=B0=86issue=5Flinks=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=94=B9=E4=B8=BA=E6=94=AF=E6=8C=81=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issue_links_controller.rb | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/app/controllers/api/pm/issue_links_controller.rb b/app/controllers/api/pm/issue_links_controller.rb index 01ca9a059..9786c50cb 100644 --- a/app/controllers/api/pm/issue_links_controller.rb +++ b/app/controllers/api/pm/issue_links_controller.rb @@ -6,15 +6,8 @@ class Api::Pm::IssueLinksController < Api::Pm::BaseController end def create - @link = @issue.pm_links.find_or_create_by(be_linkable_type: 'Issue', be_linkable_id: params[:link_id]) - data = { - data: { - id: @link.id, - issue_id: @link.linkable_id, - linked_issue_id: @link.be_linkable_id - } - } - render_ok(data) + params[:link_ids].map { |e| @issue.pm_links.find_or_create_by(be_linkable_type: 'Issue', be_linkable_id: e) } + render_ok end def destroy From a644bfee25c2e3c82aab835626ba023cfa86cedb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 14 Nov 2023 16:50:00 +0800 Subject: [PATCH 051/294] =?UTF-8?q?=E5=88=9B=E5=BB=BAissue=E6=97=B6?= =?UTF-8?q?=E5=8A=A0=E4=B8=8A=E5=B7=A5=E4=BD=9C=E9=A1=B9=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 2 +- app/services/api/v1/issues/create_service.rb | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 52411d5db..39e9c9eb6 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -149,7 +149,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController :status_id, :priority_id, :milestone_id, :branch_name, :start_date, :due_date, :time_scale, :subject, :description, :blockchain_token_num, - :pm_project_id, :pm_sprint_id, :pm_issue_type, :root_id, + :pm_project_id, :pm_sprint_id, :pm_issue_type, :root_id, :link_able_id, issue_tag_ids: [], assigner_ids: [], attachment_ids: [], diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index 1a5e309a8..10390a56d 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -34,6 +34,7 @@ class Api::V1::Issues::CreateService < ApplicationService @pm_issue_type = params[:pm_issue_type] @root_id = params[:root_id] @time_scale = params[:time_scale] + @belink_able_id = params[:link_able_id] end def call @@ -70,6 +71,8 @@ class Api::V1::Issues::CreateService < ApplicationService @created_issue.changer_id = @current_user.id @created_issue.save! + @created_issue.pm_links.find_or_create_by(be_linkable_type: 'Issue', be_linkable_id: @belink_able_id) if @belink_able_id.present? + if Site.has_blockchain? && @project.use_blockchain if @created_issue.blockchain_token_num.present? && @created_issue.blockchain_token_num > 0 Blockchain::CreateIssue.call({user_id: current_user.id, project_id: @created_issue.project_id, token_num: @created_issue.blockchain_token_num}) From efa9ecfcb0dca6f48eb93a1288359435a485a63d Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 15 Nov 2023 09:27:06 +0800 Subject: [PATCH 052/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Astatus=5Fids?= =?UTF-8?q?=E6=95=B0=E7=BB=84=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 3 ++- app/services/api/v1/issues/list_service.rb | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 39e9c9eb6..0d00d93eb 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -138,7 +138,8 @@ class Api::Pm::IssuesController < Api::Pm::BaseController :status_id, :begin_date, :end_date, :sort_by, :sort_direction, :root_id, - :issue_tag_ids, :pm_project_id, :pm_sprint_id, :pm_issue_type + :issue_tag_ids, :pm_project_id, :pm_sprint_id, :pm_issue_type, + :status_ids ) end diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index 3d5488bba..ba11b6636 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -4,7 +4,7 @@ class Api::V1::Issues::ListService < ApplicationService attr_reader :project, :only_name, :category, :participant_category, :keyword, :author_id, :issue_tag_ids attr_reader :begin_date, :end_date attr_reader :milestone_id, :assigner_id, :status_id, :sort_by, :sort_direction, :current_user - attr_reader :pm_project_id, :pm_sprint_id, :root_id, :pm_issue_type + attr_reader :pm_project_id, :pm_sprint_id, :root_id, :pm_issue_type, :status_ids attr_accessor :queried_issues, :total_issues_count, :closed_issues_count, :opened_issues_count validates :category, inclusion: { in: %w[all opened closed], message: '请输入正确的Category'} @@ -31,6 +31,7 @@ class Api::V1::Issues::ListService < ApplicationService @pm_sprint_id = params[:pm_sprint_id] @root_id = params[:root_id] @pm_issue_type = params[:pm_issue_type] + @status_ids = params[:status_ids].present? ? params[:status_ids].split(',') : [] @sort_direction = (params[:sort_direction].present? ? params[:sort_direction] : 'desc').downcase @current_user = current_user end @@ -72,7 +73,7 @@ class Api::V1::Issues::ListService < ApplicationService #pm相关 # root_id if root_id.present? - issues = issues.where(root_id: root_id).or(issues.where(id: root_id)) + issues = issues.where(root_id: root_id) end # pm_issue_type @@ -90,6 +91,9 @@ class Api::V1::Issues::ListService < ApplicationService # status_id issues = issues.where(status_id: status_id) if status_id.present? && category != 'closed' + # status_ids + issues = issues.where(status_id: status_ids) unless status_ids.blank? + if begin_date&.present? || end_date&.present? issues = issues.where('issues.created_on between ? and ?', begin_date&.present? ? begin_date.to_time : Time.now.beginning_of_day, end_date&.present? ? end_date.to_time.end_of_day : Time.now.end_of_day) end From 6dda3ef6b9586ecf4d96e987bffb9cf217a66580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 15 Nov 2023 09:35:35 +0800 Subject: [PATCH 053/294] add pm isssue jornal render --- app/controllers/api/pm/journals_controller.rb | 4 ++++ app/views/api/v1/issues/journals/_detail.json.jbuilder | 2 +- .../api/v1/issues/journals/children_journals.json.jbuilder | 2 +- app/views/api/v1/issues/journals/create.json.jbuilder | 2 +- app/views/api/v1/issues/journals/index.json.jbuilder | 2 +- app/views/api/v1/issues/journals/update.json.jbuilder | 2 +- 6 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/pm/journals_controller.rb b/app/controllers/api/pm/journals_controller.rb index b4cae5a95..2ac494546 100644 --- a/app/controllers/api/pm/journals_controller.rb +++ b/app/controllers/api/pm/journals_controller.rb @@ -10,19 +10,23 @@ class Api::Pm::JournalsController < Api::Pm::BaseController @total_operate_journals_count = @object_result[:total_operate_journals_count] @total_comment_journals_count = @object_result[:total_comment_journals_count] @journals = kaminary_select_paginate(@object_result[:data]) + render 'api/v1/issues/journals/index' end def create @object_result = Api::V1::Issues::Journals::CreateService.call(@issue, journal_params, current_user) + render 'api/v1/issues/journals/show' end def children_journals @object_results = Api::V1::Issues::Journals::ChildrenListService.call(@issue, @journal, query_params, current_user) @journals = kaminari_paginate(@object_results) + render 'api/v1/issues/journals/show' end def update @object_result = Api::V1::Issues::Journals::UpdateService.call(@issue, @journal, journal_params, current_user) + render 'api/v1/issues/journals/show' end def destroy diff --git a/app/views/api/v1/issues/journals/_detail.json.jbuilder b/app/views/api/v1/issues/journals/_detail.json.jbuilder index 264997bbd..21040bc0a 100644 --- a/app/views/api/v1/issues/journals/_detail.json.jbuilder +++ b/app/views/api/v1/issues/journals/_detail.json.jbuilder @@ -17,7 +17,7 @@ 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 + json.partial! "api/v1/issues/journals/children_detail", journal: journal end json.attachments journal.attachments do |attachment| json.partial! "api/v1/attachments/simple_detail", locals: {attachment: attachment} diff --git a/app/views/api/v1/issues/journals/children_journals.json.jbuilder b/app/views/api/v1/issues/journals/children_journals.json.jbuilder index c0cd04501..ddea195d7 100644 --- a/app/views/api/v1/issues/journals/children_journals.json.jbuilder +++ b/app/views/api/v1/issues/journals/children_journals.json.jbuilder @@ -1,4 +1,4 @@ json.total_count @journals.total_count json.journals @journals do |journal| - json.partial! "children_detail", journal: journal + json.partial! "api/v1/issues/journals/children_detail", journal: journal end \ No newline at end of file diff --git a/app/views/api/v1/issues/journals/create.json.jbuilder b/app/views/api/v1/issues/journals/create.json.jbuilder index 91f3f3174..a28523db1 100644 --- a/app/views/api/v1/issues/journals/create.json.jbuilder +++ b/app/views/api/v1/issues/journals/create.json.jbuilder @@ -1 +1 @@ -json.partial! "detail", journal: @object_result \ No newline at end of file +json.partial! "api/v1/issues/journals/detail", journal: @object_result \ No newline at end of file diff --git a/app/views/api/v1/issues/journals/index.json.jbuilder b/app/views/api/v1/issues/journals/index.json.jbuilder index 453c39c59..b113f39a0 100644 --- a/app/views/api/v1/issues/journals/index.json.jbuilder +++ b/app/views/api/v1/issues/journals/index.json.jbuilder @@ -4,5 +4,5 @@ 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 + json.partial! "api/v1/issues/journals/detail", journal: journal end \ No newline at end of file diff --git a/app/views/api/v1/issues/journals/update.json.jbuilder b/app/views/api/v1/issues/journals/update.json.jbuilder index 91f3f3174..a28523db1 100644 --- a/app/views/api/v1/issues/journals/update.json.jbuilder +++ b/app/views/api/v1/issues/journals/update.json.jbuilder @@ -1 +1 @@ -json.partial! "detail", journal: @object_result \ No newline at end of file +json.partial! "api/v1/issues/journals/detail", journal: @object_result \ No newline at end of file From 19458ac963951198b5abb143dd45261208a0bca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 15 Nov 2023 10:25:59 +0800 Subject: [PATCH 054/294] =?UTF-8?q?=E8=B0=83=E6=95=B4=20issues=20=E7=9A=84?= =?UTF-8?q?=20root=20id=20=E5=88=A4=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/issues/list_service.rb | 10 +++++++--- app/services/api/v1/issues/update_service.rb | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index ba11b6636..79b8ac8f3 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -72,9 +72,13 @@ class Api::V1::Issues::ListService < ApplicationService #pm相关 # root_id - if root_id.present? - issues = issues.where(root_id: root_id) - end + issues = if root_id.to_i == -1 ? # -1 查一级目录 + issues.where(root_id: nil) + elsif root_id.to_i.positive? + issues.where(root_id: root_id) + else + issues + end # pm_issue_type issues = issues.where(pm_issue_type: pm_issue_type) if pm_issue_type.present? diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 48362f01b..6e6996314 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -72,10 +72,13 @@ class Api::V1::Issues::UpdateService < ApplicationService @updated_issue.attachments = @attachments || Attachment.none unless attachment_ids.nil? @updated_issue.issue_tags_relates.destroy_all & @updated_issue.issue_tags = @issue_tags || IssueTag.none unless issue_tag_ids.nil? @updated_issue.issue_tags_value = @issue_tags.order("id asc").pluck(:id).join(",") unless issue_tag_ids.nil? + + #Pm相关 @updated_issue.pm_project_id = @target_pm_project_id unless @target_pm_project_id.nil? @updated_issue.pm_sprint_id = @pm_sprint_id unless @pm_sprint_id.nil? @updated_issue.pm_issue_type = @pm_issue_type unless @pm_issue_type.nil? @updated_issue.root_id = @root_id unless @root_id.nil? + @updated_issue.root_id = nil if @root_id.zero? @updated_issue.time_scale = @time_scale unless @time_scale.nil? @updated_issue.updated_on = Time.now From d758b367b1aacb1b8b0f3803a165eabcb5c1bcd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 15 Nov 2023 10:29:41 +0800 Subject: [PATCH 055/294] fix bug --- app/services/api/v1/issues/list_service.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index 79b8ac8f3..588e63236 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -71,13 +71,13 @@ class Api::V1::Issues::ListService < ApplicationService issues = issues.where(fixed_version_id: milestone_id) if milestone_id.present? #pm相关 - # root_id - issues = if root_id.to_i == -1 ? # -1 查一级目录 - issues.where(root_id: nil) + # root_id# -1 查一级目录 + issues = if root_id.to_i == -1 + issues.where(root_id: nil) elsif root_id.to_i.positive? - issues.where(root_id: root_id) + issues.where(root_id: root_id) else - issues + issues end # pm_issue_type From b0ecc0a30b19cf5a3fa13411ca3d3edda8714a28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 15 Nov 2023 11:11:00 +0800 Subject: [PATCH 056/294] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E9=9C=80=E6=B1=82?= =?UTF-8?q?=E8=B0=83=E6=95=B4links=20=E8=BF=94=E5=9B=9E=EF=BC=8C=E8=B0=83?= =?UTF-8?q?=E6=95=B4links=E5=88=A0=E9=99=A4=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issue_links_controller.rb | 9 ++++++--- app/views/api/pm/issue_links/index.json.jbuilder | 7 ++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/controllers/api/pm/issue_links_controller.rb b/app/controllers/api/pm/issue_links_controller.rb index 9786c50cb..844c01597 100644 --- a/app/controllers/api/pm/issue_links_controller.rb +++ b/app/controllers/api/pm/issue_links_controller.rb @@ -11,8 +11,11 @@ class Api::Pm::IssueLinksController < Api::Pm::BaseController end def destroy - @link = @issue.pm_links.find params[:id] - @link.destroy - render_ok + @link = @issue.pm_links.find_by(be_linkable_type: 'Issue', be_linkable_id: params[:id]) + if @link.try(:destroy) + render_ok + else + render_error('删除失败!') + end end end diff --git a/app/views/api/pm/issue_links/index.json.jbuilder b/app/views/api/pm/issue_links/index.json.jbuilder index 066319e13..5a563feba 100644 --- a/app/views/api/pm/issue_links/index.json.jbuilder +++ b/app/views/api/pm/issue_links/index.json.jbuilder @@ -1,7 +1,4 @@ -json.links @links.each do |link| - json.id link.id - json.issue do - json.partial! "api/v1/issues/simple_detail", locals: {issue: link.be_linkable} - end +json.issues @links.each do |link| + json.partial! "api/v1/issues/simple_detail", locals: { issue: link.be_linkable } end \ No newline at end of file From 0fda6721dea4b95d7484c3a90dbf3ca8b679cb14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 15 Nov 2023 11:47:17 +0800 Subject: [PATCH 057/294] issue link_issues --- app/controllers/api/pm/issues_controller.rb | 15 ++++++++++++++- config/routes/api.rb | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 0d00d93eb..c9192ad94 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -1,7 +1,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController before_action :require_login, except: [:index] before_action :load_project - before_action :load_issue, only: %i[show update destroy link_index] + before_action :load_issue, only: %i[show update destroy link_index link_issues] before_action :load_issues, only: %i[batch_update batch_destroy] before_action :check_issue_operate_permission, only: %i[update destroy] @@ -32,6 +32,19 @@ class Api::Pm::IssuesController < Api::Pm::BaseController render 'api/v1/issues/index' end + def link_issues + pm_issue_type = params[:pm_issue_type] || [1, 2, 3] + not_join_id = Issue.where(root_id: @issue.id).pluck(:id) + not_join_id << @issue.id + object_issues = Issue.where( + pm_project_id: params[:pm_project_id], + root_id: nil, + pm_issue_type: pm_issue_type + ).where.not(id: not_join_id) + @issues = kaminari_paginate(object_issues) + render 'api/v1/issues/index' + end + def show @issue.associate_attachment_container diff --git a/config/routes/api.rb b/config/routes/api.rb index 2a08425c4..3a9b4ed88 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -11,6 +11,7 @@ defaults format: :json do end member do get :link_index + get :link_issues end resources :issue_links From dddc4f975248fe8f523187eb0c659476919b6718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 15 Nov 2023 14:18:36 +0800 Subject: [PATCH 058/294] update issue link index --- app/controllers/api/pm/issues_controller.rb | 20 ++++++-------------- config/routes/api.rb | 1 - 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index c9192ad94..7d681ac55 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -21,20 +21,13 @@ class Api::Pm::IssuesController < Api::Pm::BaseController def link_index pm_issue_type = params[:pm_issue_type] || [1, 2, 3] - not_join_id = @issue.pm_links.pluck(:be_linkable_id) - not_join_id << @issue.id - object_issues = Issue.includes(:pm_links).where( - pm_project_id: params[:pm_project_id], - root_id: nil, - pm_issue_type: pm_issue_type - ).where.not(id: not_join_id) - @issues = kaminari_paginate(object_issues) - render 'api/v1/issues/index' - end + not_join_id = case params[:issue_filter_type] + when 'leaf_issue' + @issue.pm_links.pluck(:be_linkable_id) + when 'link_issue' + Issue.where(root_id: @issue.id).pluck(:id) + end - def link_issues - pm_issue_type = params[:pm_issue_type] || [1, 2, 3] - not_join_id = Issue.where(root_id: @issue.id).pluck(:id) not_join_id << @issue.id object_issues = Issue.where( pm_project_id: params[:pm_project_id], @@ -45,7 +38,6 @@ class Api::Pm::IssuesController < Api::Pm::BaseController render 'api/v1/issues/index' end - def show @issue.associate_attachment_container render 'api/v1/issues/show' diff --git a/config/routes/api.rb b/config/routes/api.rb index 3a9b4ed88..2a08425c4 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -11,7 +11,6 @@ defaults format: :json do end member do get :link_index - get :link_issues end resources :issue_links From 7ed4d12e95d1bfbdc5ae2cab0c687fb6d8c3369e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 15 Nov 2023 16:56:37 +0800 Subject: [PATCH 059/294] =?UTF-8?q?=E8=B0=83=E6=95=B4create=20issue=20?= =?UTF-8?q?=E4=B8=AD=E7=9A=84PmLink=E5=88=9B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/issues/create_service.rb | 25 ++++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index 10390a56d..8c6625ff1 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -34,11 +34,11 @@ class Api::V1::Issues::CreateService < ApplicationService @pm_issue_type = params[:pm_issue_type] @root_id = params[:root_id] @time_scale = params[:time_scale] - @belink_able_id = params[:link_able_id] + @linkable_id = params[:link_able_id] end def call - raise Error, errors.full_messages.join(", ") unless valid? + raise Error, errors.full_messages.join(', ') unless valid? ActiveRecord::Base.transaction do check_issue_status(status_id) check_issue_priority(priority_id) @@ -67,18 +67,17 @@ class Api::V1::Issues::CreateService < ApplicationService @created_issue.pm_issue_type = @pm_issue_type @created_issue.root_id = @root_id @created_issue.time_scale = @time_scale - @created_issue.issue_tags_value = @issue_tags.order("id asc").pluck(:id).join(",") unless issue_tag_ids.blank? + @created_issue.issue_tags_value = @issue_tags.order('id asc').pluck(:id).join(',') unless issue_tag_ids.blank? @created_issue.changer_id = @current_user.id @created_issue.save! - @created_issue.pm_links.find_or_create_by(be_linkable_type: 'Issue', be_linkable_id: @belink_able_id) if @belink_able_id.present? - + PmLink.create(be_linkable_type: 'Issue', be_linkable_id: @created_issue.id, linkable_type: 'Issue', linkable_id: @linkable_id) if @linkable_id.present? if Site.has_blockchain? && @project.use_blockchain if @created_issue.blockchain_token_num.present? && @created_issue.blockchain_token_num > 0 Blockchain::CreateIssue.call({user_id: current_user.id, project_id: @created_issue.project_id, token_num: @created_issue.blockchain_token_num}) end - push_activity_2_blockchain("issue_create", @created_issue) + push_activity_2_blockchain('issue_create', @created_issue) end project.del_project_issue_cache_delete_count # 把缓存里存储项目删除issue的个数清除掉 @@ -117,8 +116,8 @@ class Api::V1::Issues::CreateService < ApplicationService status_id: status_id, priority_id: priority_id, project_issues_index: (project.get_last_project_issues_index + 1), - issue_type: "1", - issue_classify: "issue" + issue_type: '1', + issue_classify: 'issue' } issue_attributes.merge!({description: description}) if description.present? @@ -132,29 +131,29 @@ class Api::V1::Issues::CreateService < ApplicationService end def build_author_participants - @created_issue.issue_participants.new({participant_type: "authored", participant_id: current_user.id}) + @created_issue.issue_participants.new({participant_type: 'authored', participant_id: current_user.id}) end def build_assigner_participants assigner_ids.each do |aid| - @created_issue.issue_participants.new({participant_type: "assigned", participant_id: aid}) + @created_issue.issue_participants.new({participant_type: 'assigned', participant_id: aid}) end end def build_atme_participants @atme_receivers.each do |receiver| - @created_issue.issue_participants.new({participant_type: "atme", participant_id: receiver.id}) + @created_issue.issue_participants.new({participant_type: 'atme', participant_id: receiver.id}) end end def build_issue_project_trends return if @project.id == 0 - @created_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: "create"}) + @created_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: 'create'}) @created_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE}) if status_id.to_i == 5 end def build_issue_journal_details journal = @created_issue.journals.new({user_id: current_user.id}) - journal.journal_details.new({property: "issue", prop_key: 1, old_value: '', value: ''}) + journal.journal_details.new({property: 'issue', prop_key: 1, old_value: '', value: ''}) end end \ No newline at end of file From ad30b56b26c27b3d846871ab0a2d045f3c6f365c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 16 Nov 2023 10:10:45 +0800 Subject: [PATCH 060/294] fix issue update bug --- app/services/api/v1/issues/update_service.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 6e6996314..fbcd8df3e 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -77,8 +77,12 @@ class Api::V1::Issues::UpdateService < ApplicationService @updated_issue.pm_project_id = @target_pm_project_id unless @target_pm_project_id.nil? @updated_issue.pm_sprint_id = @pm_sprint_id unless @pm_sprint_id.nil? @updated_issue.pm_issue_type = @pm_issue_type unless @pm_issue_type.nil? - @updated_issue.root_id = @root_id unless @root_id.nil? - @updated_issue.root_id = nil if @root_id.zero? + @updated_issue.root_id = if @root_id.nil? || @root_id.try(:zero?) + nil + else + @root_id + end + @updated_issue.time_scale = @time_scale unless @time_scale.nil? @updated_issue.updated_on = Time.now From c70e43d19bdbc62db56a7aef6206d1d5b14eaefe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 16 Nov 2023 10:26:16 +0800 Subject: [PATCH 061/294] update issue update root id --- app/services/api/v1/issues/update_service.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index fbcd8df3e..4adbd26e4 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -77,12 +77,8 @@ class Api::V1::Issues::UpdateService < ApplicationService @updated_issue.pm_project_id = @target_pm_project_id unless @target_pm_project_id.nil? @updated_issue.pm_sprint_id = @pm_sprint_id unless @pm_sprint_id.nil? @updated_issue.pm_issue_type = @pm_issue_type unless @pm_issue_type.nil? - @updated_issue.root_id = if @root_id.nil? || @root_id.try(:zero?) - nil - else - @root_id - end - + @updated_issue.root_id = @root_id unless @root_id.nil? #不为 nil的时候更新 + @updated_issue.root_id = nil if @root_id.try(:zero?) #为 0 的时候设置为 nil @updated_issue.time_scale = @time_scale unless @time_scale.nil? @updated_issue.updated_on = Time.now From a303f3d01bd9142ebaf10179e3637a7953f30be8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 16 Nov 2023 10:35:27 +0800 Subject: [PATCH 062/294] =?UTF-8?q?issue=20=E5=88=A0=E9=99=A4=E5=BD=93proj?= =?UTF-8?q?ect=20=E4=B8=BA0=E6=97=B6=E4=B8=8D=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/issues/batch_delete_service.rb | 2 +- app/services/api/v1/issues/delete_service.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/services/api/v1/issues/batch_delete_service.rb b/app/services/api/v1/issues/batch_delete_service.rb index 45821b373..15ebd8d0e 100644 --- a/app/services/api/v1/issues/batch_delete_service.rb +++ b/app/services/api/v1/issues/batch_delete_service.rb @@ -19,7 +19,7 @@ class Api::V1::Issues::BatchDeleteService < ApplicationService project.incre_project_issue_cache_delete_count(@issues.size) - if Site.has_notice_menu? + if Site.has_notice_menu? && !project.id.zero? @issues.each do |issue| SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, @issue&.subject, @issue.assigners.pluck(:id), @issue.author_id) end diff --git a/app/services/api/v1/issues/delete_service.rb b/app/services/api/v1/issues/delete_service.rb index b62733181..952f6a404 100644 --- a/app/services/api/v1/issues/delete_service.rb +++ b/app/services/api/v1/issues/delete_service.rb @@ -19,11 +19,11 @@ class Api::V1::Issues::DeleteService < ApplicationService project.incre_project_issue_cache_delete_count - if Site.has_blockchain? && @project.use_blockchain + if Site.has_blockchain? && @project.use_blockchain && !project.id.zero? unlock_balance_on_blockchain(@issue.author_id.to_s, @project.id.to_s, @issue.blockchain_token_num.to_i) if @issue.blockchain_token_num.present? end - if Site.has_notice_menu? + if Site.has_notice_menu? && !project.id.zero? SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, @issue&.subject, @issue.assigners.pluck(:id), @issue.author_id) end From f9f0485e509ee71af8ccfe77adaf4190c260c9ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 16 Nov 2023 10:46:00 +0800 Subject: [PATCH 063/294] =?UTF-8?q?issue=20project=20=E4=B8=BAnil=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E7=89=B9=E6=AE=8A=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/issue.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 67e65593f..210f3a61f 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -187,7 +187,11 @@ class Issue < ApplicationRecord end def is_collaborators? - self.assigned_to_id.present? ? self.project.member?(self.assigned_to_id) : false + if self.assigned_to_id.present? && self.project.present? + self.project.member?(self.assigned_to_id) + else + false + end end def get_issue_tags_name @@ -229,7 +233,7 @@ class Issue < ApplicationRecord end def update_closed_issues_count_in_project! - self.project.decrement!(:closed_issues_count) if self.status_id == 5 + self.project.decrement!(:closed_issues_count) if self.status_id == 5 && self.project.present? end def send_update_message_to_notice_system From 23a1be8ce37c1feeb5010790c514a5ea24c2a78a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 16 Nov 2023 14:15:37 +0800 Subject: [PATCH 064/294] fix issue count error --- app/controllers/api/pm/projects_controller.rb | 10 +++------- app/services/api/v1/issues/create_service.rb | 2 +- app/services/api/v1/issues/update_service.rb | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index 1f05d02fb..063403501 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -11,12 +11,12 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController def issues_count return tip_exception '参数错误' unless params[:pm_project_id].present? - @issues = Issue.where(pm_project_id_params) + @issues = Issue.where(id: params[:pm_project_id]) data = {} @issues_count = @issues.group(:pm_project_id).count # requirement 1 task 2 bug 3 @issues_type_count = @issues.group(:pm_project_id, :pm_issue_type).count - pm_project_id_params[:pm_project_id].map(&:to_i).map do |project_id| + params[:pm_project_id].map(&:to_i).map do |project_id| data[project_id] = { total: @issues_count[project_id] || 0, requirement: @issues_type_count[[project_id, 1]] || 0, @@ -37,9 +37,5 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController @project = Project.joins(:owner).find params[:project_id] end - def pm_project_id_params - params.permit( - pm_project_id: [] - ) - end + end diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index 8c6625ff1..0806a2397 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -81,7 +81,7 @@ class Api::V1::Issues::CreateService < ApplicationService end project.del_project_issue_cache_delete_count # 把缓存里存储项目删除issue的个数清除掉 - unless project.id.zero? + unless @project.id.zero? # 新增时向grimoirelab推送事件 IssueWebhookJob.set(wait: 5.seconds).perform_later(@created_issue.id) diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 4adbd26e4..a10c89bf6 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -88,7 +88,7 @@ class Api::V1::Issues::UpdateService < ApplicationService build_after_issue_journal_details if @updated_issue.previous_changes.present? # 操作记录 build_previous_issue_changes build_cirle_blockchain_token if blockchain_token_num.present? - unless project.id.zero? + unless @project.id.zero? # @信息发送 AtmeService.call(current_user, @atme_receivers, @issue) unless receivers_login.blank? # 消息发送 From b3252ddf85ec93262947d9ab434c7e664460008b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 16 Nov 2023 14:28:37 +0800 Subject: [PATCH 065/294] add organizations/projects/index.json language category --- .../organizations/projects/index.json.jbuilder | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/views/organizations/projects/index.json.jbuilder b/app/views/organizations/projects/index.json.jbuilder index 5a4615fc7..9417f2054 100644 --- a/app/views/organizations/projects/index.json.jbuilder +++ b/app/views/organizations/projects/index.json.jbuilder @@ -6,4 +6,21 @@ json.projects @projects.each do |project| json.praised project.praised_by?(current_user) json.last_update_time render_unix_time(project.updated_on) json.time_ago time_from_now(project.updated_on) + json.language do + if project.project_language.blank? + json.nil! + else + json.id project.project_language.id + json.name project.project_language.name + end + end + + json.category do + if project.project_category.blank? + json.nil! + else + json.id project.project_category.id + json.name project.project_category.name + end + end end \ No newline at end of file From bbc37177376d617cfbd6c6a093308f9de291c6a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 16 Nov 2023 14:37:30 +0800 Subject: [PATCH 066/294] add topic --- app/views/organizations/projects/index.json.jbuilder | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/organizations/projects/index.json.jbuilder b/app/views/organizations/projects/index.json.jbuilder index 9417f2054..c592932d4 100644 --- a/app/views/organizations/projects/index.json.jbuilder +++ b/app/views/organizations/projects/index.json.jbuilder @@ -14,7 +14,6 @@ json.projects @projects.each do |project| json.name project.project_language.name end end - json.category do if project.project_category.blank? json.nil! @@ -23,4 +22,7 @@ json.projects @projects.each do |project| json.name project.project_category.name end end + json.topics project.project_topics.each do |topic| + json.(topic, :id, :name) + end end \ No newline at end of file From 84895231dc0c8b116143f7893453bca2f510f467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 16 Nov 2023 15:08:04 +0800 Subject: [PATCH 067/294] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=9C=AA=E5=85=B3?= =?UTF-8?q?=E8=81=94issue=20=E5=92=8C=E8=AE=BE=E5=AE=9A=E7=BB=84=E7=BB=87?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E7=A9=BA=E9=97=B4=E8=8C=83=E5=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 7 +++---- app/controllers/organizations/projects_controller.rb | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 7d681ac55..ac1f3fce7 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -31,9 +31,10 @@ class Api::Pm::IssuesController < Api::Pm::BaseController not_join_id << @issue.id object_issues = Issue.where( pm_project_id: params[:pm_project_id], - root_id: nil, pm_issue_type: pm_issue_type ).where.not(id: not_join_id) + + object_issues = object_issues.where(root_id: nil, child_count: 0) if params[:issue_filter_type] == 'leaf_issue' @issues = kaminari_paginate(object_issues) render 'api/v1/issues/index' end @@ -121,9 +122,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController return render_error('请输入正确的ID数组!') unless params[:ids].is_a?(Array) params[:ids].each do |id| @issue = Issue.find_by(id: id, pm_project_id: params[:pm_project_id]) - if @issue.blank? - return render_not_found("ID为#{id}的疑修不存在!") - end + return render_not_found("ID为#{id}的疑修不存在!") if @issue.blank? end if params[:ids].blank? @issues = Issue.where(pm_project_id: params[:pm_project_id]) diff --git a/app/controllers/organizations/projects_controller.rb b/app/controllers/organizations/projects_controller.rb index ab5c9ef5d..9f40ff927 100644 --- a/app/controllers/organizations/projects_controller.rb +++ b/app/controllers/organizations/projects_controller.rb @@ -10,6 +10,7 @@ class Organizations::ProjectsController < Organizations::BaseController @projects = Project.from("( #{ public_projects_sql} UNION #{ private_projects_sql } ) AS projects") # 表情处理 keywords = params[:search].to_s.each_char.select { |c| c.bytes.first < 240 }.join('') + @projects = (@projects.where(id: params[:pm_project_repository_ids].split(',')) if params[:pm_project_repository_ids].present?) @projects = @projects.ransack(name_or_identifier_cont: keywords).result if params[:search].present? @projects = @projects.includes(:owner).order("projects.#{sort} #{sort_direction}") @projects = paginate(@projects) From aa9d45dc91cd7067dbc42f61588616e4cb741d5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 16 Nov 2023 15:13:45 +0800 Subject: [PATCH 068/294] =?UTF-8?q?pm=20link=5Findex=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=80=92=E5=BA=8F=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index ac1f3fce7..1f23ed791 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -32,7 +32,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController object_issues = Issue.where( pm_project_id: params[:pm_project_id], pm_issue_type: pm_issue_type - ).where.not(id: not_join_id) + ).where.not(id: not_join_id).order(updated_on: :desc) object_issues = object_issues.where(root_id: nil, child_count: 0) if params[:issue_filter_type] == 'leaf_issue' @issues = kaminari_paginate(object_issues) From 776533be8c109375dd893d9bdd77bb629c641221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 16 Nov 2023 15:30:16 +0800 Subject: [PATCH 069/294] fix bugs --- app/controllers/api/pm/issues_controller.rb | 4 ++-- app/controllers/organizations/projects_controller.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 1f23ed791..74cd1c144 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -23,9 +23,9 @@ class Api::Pm::IssuesController < Api::Pm::BaseController pm_issue_type = params[:pm_issue_type] || [1, 2, 3] not_join_id = case params[:issue_filter_type] when 'leaf_issue' - @issue.pm_links.pluck(:be_linkable_id) - when 'link_issue' Issue.where(root_id: @issue.id).pluck(:id) + when 'link_issue' + @issue.pm_links.pluck(:be_linkable_id) end not_join_id << @issue.id diff --git a/app/controllers/organizations/projects_controller.rb b/app/controllers/organizations/projects_controller.rb index 9f40ff927..753fee5ea 100644 --- a/app/controllers/organizations/projects_controller.rb +++ b/app/controllers/organizations/projects_controller.rb @@ -10,7 +10,7 @@ class Organizations::ProjectsController < Organizations::BaseController @projects = Project.from("( #{ public_projects_sql} UNION #{ private_projects_sql } ) AS projects") # 表情处理 keywords = params[:search].to_s.each_char.select { |c| c.bytes.first < 240 }.join('') - @projects = (@projects.where(id: params[:pm_project_repository_ids].split(',')) if params[:pm_project_repository_ids].present?) + @projects = @projects.where(id: params[:pm_project_repository_ids].split(',')) if params[:pm_project_repository_ids].present? @projects = @projects.ransack(name_or_identifier_cont: keywords).result if params[:search].present? @projects = @projects.includes(:owner).order("projects.#{sort} #{sort_direction}") @projects = paginate(@projects) From d45dab31cbd1350656a681c327c71010850acfe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 16 Nov 2023 16:45:15 +0800 Subject: [PATCH 070/294] fix pm journal render error --- app/controllers/api/pm/journals_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/pm/journals_controller.rb b/app/controllers/api/pm/journals_controller.rb index 2ac494546..d4b653171 100644 --- a/app/controllers/api/pm/journals_controller.rb +++ b/app/controllers/api/pm/journals_controller.rb @@ -15,18 +15,18 @@ class Api::Pm::JournalsController < Api::Pm::BaseController def create @object_result = Api::V1::Issues::Journals::CreateService.call(@issue, journal_params, current_user) - render 'api/v1/issues/journals/show' + render 'api/v1/issues/journals/create' end def children_journals @object_results = Api::V1::Issues::Journals::ChildrenListService.call(@issue, @journal, query_params, current_user) @journals = kaminari_paginate(@object_results) - render 'api/v1/issues/journals/show' + render 'api/v1/issues/journals/children_journals' end def update @object_result = Api::V1::Issues::Journals::UpdateService.call(@issue, @journal, journal_params, current_user) - render 'api/v1/issues/journals/show' + render 'api/v1/issues/journals/update' end def destroy From 3f8a7c7cee346acc394a6c67a36a39c0bb404c5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 16 Nov 2023 16:59:20 +0800 Subject: [PATCH 071/294] =?UTF-8?q?fix=20journal=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/base_controller.rb | 2 +- app/controllers/api/pm/journals_controller.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/pm/base_controller.rb b/app/controllers/api/pm/base_controller.rb index f2850ec95..f9754f33d 100644 --- a/app/controllers/api/pm/base_controller.rb +++ b/app/controllers/api/pm/base_controller.rb @@ -31,7 +31,7 @@ class Api::Pm::BaseController < ApplicationController def load_issue return render_parameter_missing if params[:pm_project_id].blank? - @issue = @project.issues.issue_issue.where(pm_project_id: params[:pm_project_id]).find_by_id(params[:issue_id]) + @issue = Issue.issue_issue.where(pm_project_id: params[:pm_project_id]).find_by_id(params[:issue_id]) render_not_found('疑修不存在!') if @issue.blank? end # 具有对仓库的管理权限 diff --git a/app/controllers/api/pm/journals_controller.rb b/app/controllers/api/pm/journals_controller.rb index d4b653171..14f386860 100644 --- a/app/controllers/api/pm/journals_controller.rb +++ b/app/controllers/api/pm/journals_controller.rb @@ -49,7 +49,7 @@ class Api::Pm::JournalsController < Api::Pm::BaseController end def load_issue - @issue = @project.issues.issue_issue.where(pm_project_id: params[:pm_project_id]).find_by_id(params[:issue_id]) + @issue = Issue.issue_issue.where(pm_project_id: params[:pm_project_id]).find_by_id(params[:issue_id]) render_not_found('疑修不存在!') if @issue.blank? end From c2f64adf1786d6247d9b2c9032532225e3779c9e Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 17 Nov 2023 09:32:30 +0800 Subject: [PATCH 072/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E7=BB=84?= =?UTF-8?q?=E7=BB=87=E9=A1=B9=E7=9B=AE=E5=88=97=E8=A1=A8=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E4=BB=93=E5=BA=93url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/project.rb | 5 +++++ app/views/organizations/projects/index.json.jbuilder | 1 + 2 files changed, 6 insertions(+) diff --git a/app/models/project.rb b/app/models/project.rb index 5f9fcef68..47db6f775 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -485,6 +485,11 @@ class Project < ApplicationRecord return JSON.parse(cache_result) end end + + def full_url + Rails.application.config_for(:configuration)['platform_url'] + '/' + self.owner.try(:login) + '/' + self.identifier + end + def to_builder Jbuilder.new do |project| project.id self.id diff --git a/app/views/organizations/projects/index.json.jbuilder b/app/views/organizations/projects/index.json.jbuilder index c592932d4..c395732f1 100644 --- a/app/views/organizations/projects/index.json.jbuilder +++ b/app/views/organizations/projects/index.json.jbuilder @@ -25,4 +25,5 @@ json.projects @projects.each do |project| json.topics project.project_topics.each do |topic| json.(topic, :id, :name) end + json.url project.full_url end \ No newline at end of file From fe4d563d6b0dad8d1a4d721e29c4442e7a08aaf9 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 17 Nov 2023 09:52:57 +0800 Subject: [PATCH 073/294] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E6=A0=B9?= =?UTF-8?q?=E6=8D=AEpm=5Fproject=5Fid=E6=9F=A5=E8=AF=A2issue=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=AD=A3=E5=B8=B8=E5=B1=95=E7=A4=BA=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/projects_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index 063403501..4b2ede03b 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -11,7 +11,7 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController def issues_count return tip_exception '参数错误' unless params[:pm_project_id].present? - @issues = Issue.where(id: params[:pm_project_id]) + @issues = Issue.where(pm_project_id: params[:pm_project_id]) data = {} @issues_count = @issues.group(:pm_project_id).count # requirement 1 task 2 bug 3 From d84b32f4f6bb82a0d312d5f6f79b102b2a82e802 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 17 Nov 2023 11:39:08 +0800 Subject: [PATCH 074/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Aissue?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=96=B0=E5=A2=9Eid=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/api/v1/issues/_simple_detail.json.jbuilder | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/views/api/v1/issues/_simple_detail.json.jbuilder b/app/views/api/v1/issues/_simple_detail.json.jbuilder index efcf2e5dd..3460c8c65 100644 --- a/app/views/api/v1/issues/_simple_detail.json.jbuilder +++ b/app/views/api/v1/issues/_simple_detail.json.jbuilder @@ -6,7 +6,9 @@ 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.status_id issue.status_id json.priority_name issue.priority&.name +json.priority_id issue.priority_id json.milestone_name issue.version&.name json.milestone_id issue.fixed_version_id json.root_id issue.root_id From cbbd62121c93680b64760c6530a07f81718ffcc0 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 17 Nov 2023 15:28:29 +0800 Subject: [PATCH 075/294] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E5=88=A0=E9=99=A4=E6=95=B0=E7=BB=84=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=E6=97=B6=E8=BF=94=E5=9B=9E=E6=AD=A3=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 74cd1c144..0af8e60cc 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -64,6 +64,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController end def batch_destroy + return render_ok if params[:ids].is_a?(Array) && params[:ids].blank? @object_result = Api::V1::Issues::BatchDeleteService.call(@project, @issues, current_user) if @object_result render_ok From fbad9859e639d9f329b93ea012ff28e275c720d3 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 17 Nov 2023 15:29:19 +0800 Subject: [PATCH 076/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=B7=A5=E4=BD=9C=E9=A1=B9=E5=90=8C=E6=97=B6=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=AD=90=E5=B7=A5=E4=BD=9C=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/issues/delete_service.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/services/api/v1/issues/delete_service.rb b/app/services/api/v1/issues/delete_service.rb index 952f6a404..7210c0eb7 100644 --- a/app/services/api/v1/issues/delete_service.rb +++ b/app/services/api/v1/issues/delete_service.rb @@ -15,6 +15,8 @@ class Api::V1::Issues::DeleteService < ApplicationService raise Error, errors.full_messages.join(", ") unless valid? try_lock("Api::V1::Issues::DeleteService:#{project.id}") # 开始写数据,加锁 + delete_be_linkable_issues + delete_issue project.incre_project_issue_cache_delete_count @@ -38,4 +40,10 @@ class Api::V1::Issues::DeleteService < ApplicationService raise Error, "删除疑修失败!" unless issue.destroy! end + def delete_be_linkable_issues + pmlink_ids = PmLink.where(linkable: issue).pluck(:be_linkable_id) + linkable_issues = Issue.where(id: pmlink_ids) + raise Error, "删除疑修关联项失败!" unless linkable_issues.destroy_all + end + end \ No newline at end of file From a3f0cf87e145d5b1dba8041fff9be3e79a820178 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 17 Nov 2023 16:29:40 +0800 Subject: [PATCH 077/294] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=B7=A5=E4=BD=9C=E9=A1=B9=E9=9C=80=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=AD=90=E5=B7=A5=E4=BD=9C=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/issues/delete_service.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/services/api/v1/issues/delete_service.rb b/app/services/api/v1/issues/delete_service.rb index 7210c0eb7..7f4f5968d 100644 --- a/app/services/api/v1/issues/delete_service.rb +++ b/app/services/api/v1/issues/delete_service.rb @@ -15,7 +15,7 @@ class Api::V1::Issues::DeleteService < ApplicationService raise Error, errors.full_messages.join(", ") unless valid? try_lock("Api::V1::Issues::DeleteService:#{project.id}") # 开始写数据,加锁 - delete_be_linkable_issues + delete_zi_issues delete_issue @@ -40,10 +40,9 @@ class Api::V1::Issues::DeleteService < ApplicationService raise Error, "删除疑修失败!" unless issue.destroy! end - def delete_be_linkable_issues - pmlink_ids = PmLink.where(linkable: issue).pluck(:be_linkable_id) - linkable_issues = Issue.where(id: pmlink_ids) - raise Error, "删除疑修关联项失败!" unless linkable_issues.destroy_all + def delete_zi_issues + zi_issues = Issue.where(pm_project_id:issue.pm_project_id, root_id: issue.id) + raise Error, "删除疑修关联项失败!" unless zi_issues.destroy_all end end \ No newline at end of file From 40c5525e0a836115f20ad9733d3969d35906c8fc Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 17 Nov 2023 17:18:34 +0800 Subject: [PATCH 078/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E9=A1=B9=E5=85=B3=E8=81=94=E9=A1=B9=E7=9B=AE=E6=94=B9?= =?UTF-8?q?=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 4 +-- .../api/v1/issues/batch_update_service.rb | 2 +- app/services/api/v1/issues/update_service.rb | 5 ++-- app/views/api/v1/issues/_detail.json.jbuilder | 9 ++++++- .../api/v1/projects/_detail.json.jbuilder | 26 +++++++++++++++++++ 5 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 app/views/api/v1/projects/_detail.json.jbuilder diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 0af8e60cc..e562a52e8 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -155,7 +155,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController :status_id, :priority_id, :milestone_id, :branch_name, :start_date, :due_date, :time_scale, :subject, :description, :blockchain_token_num, - :pm_project_id, :pm_sprint_id, :pm_issue_type, :root_id, :link_able_id, + :pm_project_id, :pm_sprint_id, :pm_issue_type, :root_id, :link_able_id, :project_id, issue_tag_ids: [], assigner_ids: [], attachment_ids: [], @@ -165,7 +165,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController def batch_issue_params params.permit( - :status_id, :priority_id, :milestone_id, :pm_sprint_id, :pm_issue_type, :root_id, :target_pm_project_id, + :status_id, :priority_id, :milestone_id, :pm_sprint_id, :pm_issue_type, :root_id, :target_pm_project_id, :project_id, :issue_tag_ids => [], :assigner_ids => [] ) end diff --git a/app/services/api/v1/issues/batch_update_service.rb b/app/services/api/v1/issues/batch_update_service.rb index ccf783dca..e826ca190 100644 --- a/app/services/api/v1/issues/batch_update_service.rb +++ b/app/services/api/v1/issues/batch_update_service.rb @@ -4,7 +4,7 @@ class Api::V1::Issues::BatchUpdateService < ApplicationService include Api::V1::Issues::Concerns::Loadable attr_reader :project, :issues, :params, :current_user - attr_reader :status_id, :priority_id, :milestone_id + attr_reader :status_id, :priority_id, :milestone_id, :project_id attr_reader :issue_tag_ids, :assigner_ids validates :project, :issues, :current_user, presence: true diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index a10c89bf6..6938bc946 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -5,7 +5,7 @@ class Api::V1::Issues::UpdateService < ApplicationService attr_reader :project, :issue, :current_user attr_reader :status_id, :priority_id, :milestone_id, :branch_name, :start_date, :due_date, :subject, :description, :blockchain_token_num - attr_reader :issue_tag_ids, :assigner_ids, :attachment_ids, :receivers_login, :before_issue_tag_ids, :before_assigner_ids + attr_reader :issue_tag_ids, :assigner_ids, :attachment_ids, :receivers_login, :before_issue_tag_ids, :before_assigner_ids, :project_id attr_accessor :add_assigner_ids, :previous_issue_changes, :updated_issue, :atme_receivers validates :project, :issue, :current_user, presence: true @@ -35,6 +35,7 @@ class Api::V1::Issues::UpdateService < ApplicationService @pm_issue_type = params[:pm_issue_type] @root_id = params[:root_id] @time_scale = params[:time_scale] + @project_id = params[:project_id] @add_assigner_ids = [] @previous_issue_changes = {} end @@ -80,7 +81,7 @@ class Api::V1::Issues::UpdateService < ApplicationService @updated_issue.root_id = @root_id unless @root_id.nil? #不为 nil的时候更新 @updated_issue.root_id = nil if @root_id.try(:zero?) #为 0 的时候设置为 nil @updated_issue.time_scale = @time_scale unless @time_scale.nil? - + @updated_issue.project_id = @project_id unless @project_id.nil? @updated_issue.updated_on = Time.now @updated_issue.changer_id = @current_user.id @updated_issue.save! diff --git a/app/views/api/v1/issues/_detail.json.jbuilder b/app/views/api/v1/issues/_detail.json.jbuilder index b01f6058e..c22022428 100644 --- a/app/views/api/v1/issues/_detail.json.jbuilder +++ b/app/views/api/v1/issues/_detail.json.jbuilder @@ -57,4 +57,11 @@ json.pm_issue_type issue.pm_issue_type json.pm_sprint_id issue.pm_sprint_id json.pm_project_id issue.pm_project_id json.time_scale issue.time_scale -json.child_count issue.child_count \ No newline at end of file +json.child_count issue.child_count +json.project do + if issue.project.present? + json.partial! "api/v1/projects/detail", locals: {project: issue.project} + else + json.nil! + end +end \ No newline at end of file diff --git a/app/views/api/v1/projects/_detail.json.jbuilder b/app/views/api/v1/projects/_detail.json.jbuilder new file mode 100644 index 000000000..03219f822 --- /dev/null +++ b/app/views/api/v1/projects/_detail.json.jbuilder @@ -0,0 +1,26 @@ +json.(project, :id, :name, :identifier, :description, :forked_count, :praises_count, :forked_from_project_id, :is_public) +json.mirror_url project.repository&.mirror_url +json.type project.numerical_for_project_type +json.praised project.praised_by?(current_user) +json.last_update_time render_unix_time(project.updated_on) +json.time_ago time_from_now(project.updated_on) +json.language do + if project.project_language.blank? + json.nil! + else + json.id project.project_language.id + json.name project.project_language.name + end +end +json.category do + if project.project_category.blank? + json.nil! + else + json.id project.project_category.id + json.name project.project_category.name + end +end +json.topics project.project_topics.each do |topic| + json.(topic, :id, :name) +end +json.url project.full_url \ No newline at end of file From 6d90cbed81ced7ac4cd99ba912da32c16106c51b Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 20 Nov 2023 08:29:18 +0800 Subject: [PATCH 079/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E9=A1=B9=E5=85=B3=E8=81=94=E9=A1=B9=E7=9B=AE=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/project.rb | 2 +- app/views/api/v1/issues/_detail.json.jbuilder | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index 47db6f775..15eb36493 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -487,7 +487,7 @@ class Project < ApplicationRecord end def full_url - Rails.application.config_for(:configuration)['platform_url'] + '/' + self.owner.try(:login) + '/' + self.identifier + Rails.application.config_for(:configuration)['platform_url'].to_s + '/' + self.owner&.try(:login).to_s + '/' + self.identifier.to_s end def to_builder diff --git a/app/views/api/v1/issues/_detail.json.jbuilder b/app/views/api/v1/issues/_detail.json.jbuilder index c22022428..8ccb6d097 100644 --- a/app/views/api/v1/issues/_detail.json.jbuilder +++ b/app/views/api/v1/issues/_detail.json.jbuilder @@ -59,7 +59,7 @@ json.pm_project_id issue.pm_project_id json.time_scale issue.time_scale json.child_count issue.child_count json.project do - if issue.project.present? + if issue.project.present? && issue.owner.present? json.partial! "api/v1/projects/detail", locals: {project: issue.project} else json.nil! From f48ad144112e5913e800e09167bd78001fc3e238 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 20 Nov 2023 08:32:53 +0800 Subject: [PATCH 080/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/api/v1/issues/_detail.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/api/v1/issues/_detail.json.jbuilder b/app/views/api/v1/issues/_detail.json.jbuilder index 8ccb6d097..8b5ff5949 100644 --- a/app/views/api/v1/issues/_detail.json.jbuilder +++ b/app/views/api/v1/issues/_detail.json.jbuilder @@ -59,7 +59,7 @@ json.pm_project_id issue.pm_project_id json.time_scale issue.time_scale json.child_count issue.child_count json.project do - if issue.project.present? && issue.owner.present? + if issue.project.present? && issue.project&.owner.present? json.partial! "api/v1/projects/detail", locals: {project: issue.project} else json.nil! From b305b22a8a7f4e80192a8d4501ca73650f485494 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 20 Nov 2023 09:11:28 +0800 Subject: [PATCH 081/294] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E9=A1=B9?= =?UTF-8?q?=E7=9B=AEid=E4=B8=BA0=E6=97=B6=E6=9F=A5=E8=AF=A2=E5=85=A8?= =?UTF-8?q?=E9=83=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/issues/list_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index 588e63236..17db797a6 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -49,7 +49,7 @@ class Api::V1::Issues::ListService < ApplicationService private def issue_query_data - issues = @project.issues.issue_issue + issues = @project&.id.zero? ? Issue.issue_issue : @project.issues.issue_issue case participant_category when 'aboutme' # 关于我的 From 8030d7db1a732df76eec36e9ac99ab170bf36da0 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 20 Nov 2023 09:38:52 +0800 Subject: [PATCH 082/294] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=B7=A5=E4=BD=9C=E9=A1=B9=E9=9C=80=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=AD=90=E5=B7=A5=E4=BD=9C=E9=A1=B9=E6=94=BE=E5=88=B0=E5=9B=9E?= =?UTF-8?q?=E8=B0=83=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/issue.rb | 1 + app/services/api/v1/issues/delete_service.rb | 8 -------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 210f3a61f..bc09c1340 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -82,6 +82,7 @@ class Issue < ApplicationRecord has_many :assigners, through: :issue_assigners has_many :issue_participants, dependent: :destroy has_many :participants, through: :issue_participants + has_many :children_issues, class_name: 'Issue', foreign_key: :root_id, dependent: :destroy 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 diff --git a/app/services/api/v1/issues/delete_service.rb b/app/services/api/v1/issues/delete_service.rb index 7f4f5968d..02b2b533c 100644 --- a/app/services/api/v1/issues/delete_service.rb +++ b/app/services/api/v1/issues/delete_service.rb @@ -15,8 +15,6 @@ class Api::V1::Issues::DeleteService < ApplicationService raise Error, errors.full_messages.join(", ") unless valid? try_lock("Api::V1::Issues::DeleteService:#{project.id}") # 开始写数据,加锁 - delete_zi_issues - delete_issue project.incre_project_issue_cache_delete_count @@ -39,10 +37,4 @@ class Api::V1::Issues::DeleteService < ApplicationService def delete_issue raise Error, "删除疑修失败!" unless issue.destroy! end - - def delete_zi_issues - zi_issues = Issue.where(pm_project_id:issue.pm_project_id, root_id: issue.id) - raise Error, "删除疑修关联项失败!" unless zi_issues.destroy_all - end - end \ No newline at end of file From 39423ff6ea58740cf92403a781c305e9b1a289bf Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 20 Nov 2023 11:32:14 +0800 Subject: [PATCH 083/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E4=B8=AD=E6=89=80=E6=9C=89=E6=9C=AA=E5=85=B3=E8=81=94?= =?UTF-8?q?=E8=BF=AD=E4=BB=A3=E5=B7=A5=E4=BD=9C=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/pm/sprint_issues_controller.rb | 23 ++++++++ .../api/pm/sprint_issues/list_service.rb | 54 +++++++++++++++++++ app/views/api/v1/issues/index.json.jbuilder | 2 +- config/routes/api.rb | 1 + 4 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 app/controllers/api/pm/sprint_issues_controller.rb create mode 100644 app/services/api/pm/sprint_issues/list_service.rb diff --git a/app/controllers/api/pm/sprint_issues_controller.rb b/app/controllers/api/pm/sprint_issues_controller.rb new file mode 100644 index 000000000..a1f4281c5 --- /dev/null +++ b/app/controllers/api/pm/sprint_issues_controller.rb @@ -0,0 +1,23 @@ +class Api::Pm::SprintIssuesController < Api::Pm::BaseController + + before_action :require_login, except: [:index] + def index + @issues = Api::Pm::SprintIssues::ListService.call(query_params, current_user) + @issues = kaminari_paginate(@issues) + render 'api/v1/issues/index' + end + + def query_params + params.permit( + :category, + :pm_project_id, + :pm_issue_type, #需求1 任务2 缺陷3 + :assigner_id, + :priority_id, + :status_id, + :keyword, + :sort_by, :sort_direction + ) + end + +end \ No newline at end of file diff --git a/app/services/api/pm/sprint_issues/list_service.rb b/app/services/api/pm/sprint_issues/list_service.rb new file mode 100644 index 000000000..884506af0 --- /dev/null +++ b/app/services/api/pm/sprint_issues/list_service.rb @@ -0,0 +1,54 @@ +class Api::Pm::SprintIssues::ListService < ApplicationService + + include ActiveModel::Model + + attr_reader :category, :pm_project_id, :pm_issue_type, :assigner_id, :priority_id, :status_id, :keyword, :current_user + attr_reader :sort_by, :sort_direction + attr_accessor :queried_issues + + validates :category, inclusion: { in: %w[linked unlink], message: '请输入正确的Category'} + validates :sort_by, inclusion: { in: %w[issues.created_on issues.updated_on issue_priorities.position] , message: '请输入正确的SortBy'}, allow_blank: true + validates :sort_direction, inclusion: { in: %w[asc desc], message: '请输入正确的SortDirection'}, allow_blank: true + + validates :pm_project_id, :current_user, presence: true + + def initialize(params, current_user = nil) + @category = params[:category] || "unlink" + @pm_project_id = params[:pm_project_id] + @pm_issue_type = params[:pm_issue_type] + @assigner_id = params[:assigner_id] + @priority_id = params[:priority_id] + @status_id = params[:status_id] + @keyword = params[:keyword] + @current_user = current_user + end + + def call + raise Error, errors.full_messages.join(', ') unless valid? + + issue_query_data + + @queried_issues + end + + private + def issue_query_data + issues = @category == "unlink" ? Issue.where(pm_project_id: @pm_project_id, pm_sprint_id: nil) : Issue.where(pm_project_id: @pm_project_id).where.not(pm_sprint_id: nil) + + issues = issues.where(pm_issue_type: @pm_issue_type) if @pm_issue_type.present? + + issues = issues.joins(:assigners).where(users: {id: @assigner_id}) if @assigner_id.present? + + issues = issues.where(priority_id: @priority_id) if @priority_id.present? + + issues = issues.where(status_id: @status_id) if @status_id.present? + + issues = issues.ransack(subject_cont: @keyword).result if @keyword.present? + + scope = issues.includes(:priority, :issue_status, :user, :show_assigners, :show_issue_tags, :version, :comment_journals) + scope = scope.reorder("#{sort_by} #{sort_direction}").distinct + + @queried_issues = scope + + end +end \ No newline at end of file diff --git a/app/views/api/v1/issues/index.json.jbuilder b/app/views/api/v1/issues/index.json.jbuilder index 8fd915553..c6a5f526c 100644 --- a/app/views/api/v1/issues/index.json.jbuilder +++ b/app/views/api/v1/issues/index.json.jbuilder @@ -2,7 +2,7 @@ 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.has_created_issues @project.present? ? @project.issues.size > 0 : 0 json.issues @issues.each do |issue| if params[:only_name].present? json.(issue, :id, :subject, :project_issues_index) diff --git a/config/routes/api.rb b/config/routes/api.rb index 2a08425c4..3901112df 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -21,6 +21,7 @@ defaults format: :json do end end end + resources :sprint_issues, only: [:index] resources :projects do collection do get :convert From d6fbdd87d0e3873d4873d22f41106306eec5856a Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 20 Nov 2023 16:40:20 +0800 Subject: [PATCH 084/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E8=BF=AD?= =?UTF-8?q?=E4=BB=A3=E4=B8=AD=E5=B7=A5=E4=BD=9C=E9=A1=B9=E8=BF=9B=E5=BA=A6?= =?UTF-8?q?=E5=92=8C=E5=B7=A5=E6=97=B6=E5=AE=B9=E9=87=8F=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/pm/sprint_issues_controller.rb | 33 +++++++++++++++++++ config/routes/api.rb | 7 +++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/pm/sprint_issues_controller.rb b/app/controllers/api/pm/sprint_issues_controller.rb index a1f4281c5..6251690b4 100644 --- a/app/controllers/api/pm/sprint_issues_controller.rb +++ b/app/controllers/api/pm/sprint_issues_controller.rb @@ -1,11 +1,44 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController before_action :require_login, except: [:index] + def index @issues = Api::Pm::SprintIssues::ListService.call(query_params, current_user) @issues = kaminari_paginate(@issues) render 'api/v1/issues/index' end + + def count + pm_sprint_ids = params[:pm_sprint_ids].split(",") rescue [] + return tip_exception '参数错误' if pm_sprint_ids.blank? + @issues = Issue.where(pm_sprint_id: pm_sprint_ids) + data = {} + @issues_count = @issues.group(:pm_sprint_id).count + @issues_type_count = @issues.group(:pm_sprint_id, :status_id).count + pm_sprint_ids.map(&:to_i).map do |sprint_id| + data[sprint_id] = { + total: @issues_count[sprint_id] || 0, + closed: @issues_type_count[[sprint_id, 5]] || 0 + } + end + render_ok(data: data) + end + + def hour + pm_sprint_ids = params[:pm_sprint_ids].split(",") rescue [] + return tip_exception '参数错误' if pm_sprint_ids.blank? + @issues = Issue.where(pm_sprint_id: pm_sprint_ids) + data = {} + @issues_count = @issues.group(:pm_sprint_id).sum(:time_scale) + @issues_type_count = @issues.group(:pm_sprint_id, :status_id).sum(:time_scale) + pm_sprint_ids.map(&:to_i).map do |sprint_id| + data[sprint_id] = { + total: @issues_count[sprint_id] || 0, + closed: @issues_type_count[[sprint_id, 5]] || 0 + } + end + render_ok(data: data) + end def query_params params.permit( diff --git a/config/routes/api.rb b/config/routes/api.rb index 3901112df..487a2abfd 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -21,7 +21,12 @@ defaults format: :json do end end end - resources :sprint_issues, only: [:index] + resources :sprint_issues, only: [:index] do + collection do + get :count + get :hour + end + end resources :projects do collection do get :convert From 0c48eeb52bd59b10f51c18b153a02b76607fc0a4 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 21 Nov 2023 08:28:49 +0800 Subject: [PATCH 085/294] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E8=BF=AD?= =?UTF-8?q?=E4=BB=A3=E5=B7=A5=E4=BD=9C=E9=A1=B9=E8=BF=9B=E5=BA=A6=E5=92=8C?= =?UTF-8?q?=E5=B7=A5=E6=97=B6=E5=AE=B9=E9=87=8F=E6=8E=A5=E5=8F=A3=E5=90=88?= =?UTF-8?q?=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/pm/sprint_issues_controller.rb | 26 +++++-------------- config/routes/api.rb | 3 +-- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/app/controllers/api/pm/sprint_issues_controller.rb b/app/controllers/api/pm/sprint_issues_controller.rb index 6251690b4..49e2398e7 100644 --- a/app/controllers/api/pm/sprint_issues_controller.rb +++ b/app/controllers/api/pm/sprint_issues_controller.rb @@ -8,33 +8,21 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController render 'api/v1/issues/index' end - def count + def statistics pm_sprint_ids = params[:pm_sprint_ids].split(",") rescue [] return tip_exception '参数错误' if pm_sprint_ids.blank? @issues = Issue.where(pm_sprint_id: pm_sprint_ids) data = {} @issues_count = @issues.group(:pm_sprint_id).count @issues_type_count = @issues.group(:pm_sprint_id, :status_id).count + @issues_hour_count = @issues.group(:pm_sprint_id).sum(:time_scale) + @issues_hour_type_count = @issues.group(:pm_sprint_id, :status_id).sum(:time_scale) pm_sprint_ids.map(&:to_i).map do |sprint_id| data[sprint_id] = { - total: @issues_count[sprint_id] || 0, - closed: @issues_type_count[[sprint_id, 5]] || 0 - } - end - render_ok(data: data) - end - - def hour - pm_sprint_ids = params[:pm_sprint_ids].split(",") rescue [] - return tip_exception '参数错误' if pm_sprint_ids.blank? - @issues = Issue.where(pm_sprint_id: pm_sprint_ids) - data = {} - @issues_count = @issues.group(:pm_sprint_id).sum(:time_scale) - @issues_type_count = @issues.group(:pm_sprint_id, :status_id).sum(:time_scale) - pm_sprint_ids.map(&:to_i).map do |sprint_id| - data[sprint_id] = { - total: @issues_count[sprint_id] || 0, - closed: @issues_type_count[[sprint_id, 5]] || 0 + count_total: @issues_count[sprint_id] || 0, + count_closed: @issues_type_count[[sprint_id, 5]] || 0, + hour_total: @issues_hour_count[sprint_id] || 0, + hour_closed: @issues_hour_type_count[[sprint_id, 5]] || 0 } end render_ok(data: data) diff --git a/config/routes/api.rb b/config/routes/api.rb index 487a2abfd..e04218143 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -23,8 +23,7 @@ defaults format: :json do end resources :sprint_issues, only: [:index] do collection do - get :count - get :hour + get :statistics end end resources :projects do From 2985dc790223a7615ae8512d592c288a2d9fcd1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 21 Nov 2023 17:06:43 +0800 Subject: [PATCH 086/294] add uuid --- app/controllers/attachments_controller.rb | 4 +- app/models/attachment.rb | 88 ++++++++++--------- app/models/issue.rb | 7 +- .../20231121084405_add_uuid_to_attachments.rb | 5 ++ 4 files changed, 60 insertions(+), 44 deletions(-) create mode 100644 db/migrate/20231121084405_add_uuid_to_attachments.rb diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 2bbccb495..9ed2632db 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -146,7 +146,7 @@ class AttachmentsController < ApplicationController if params[:type] == 'history' AttachmentHistory.find params[:id] else - Attachment.find params[:id] + Attachment.find params[:id] || Attachment.find_by(uuid: params[:id]) end end @@ -217,7 +217,7 @@ class AttachmentsController < ApplicationController def attachment_candown unless current_user.admin? || current_user.business? candown = true - if @file.container + if @file.container && @file.uuid.nil? if @file.container.is_a?(Issue) project = @file.container.project candown = project.is_public || (current_user.logged? && project.member?(current_user)) diff --git a/app/models/attachment.rb b/app/models/attachment.rb index f79aca153..defc73662 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -1,44 +1,45 @@ -# == Schema Information -# -# Table name: attachments -# -# id :integer not null, primary key -# container_id :integer -# container_type :string(30) -# filename :string(255) default(""), not null -# disk_filename :string(255) default(""), not null -# filesize :integer default("0"), not null -# content_type :string(255) default("") -# digest :string(60) default(""), not null -# downloads :integer default("0"), not null -# author_id :integer default("0"), not null -# created_on :datetime -# description :text(65535) -# disk_directory :string(255) -# attachtype :integer default("1") -# is_public :integer default("1") -# copy_from :integer -# quotes :integer default("0") -# is_publish :integer default("1") -# publish_time :datetime -# resource_bank_id :integer -# unified_setting :boolean default("1") -# cloud_url :string(255) default("") -# course_second_category_id :integer default("0") -# delay_publish :boolean default("0") -# memo_image :boolean default("0") -# extra_type :integer default("0") -# -# Indexes -# -# index_attachments_on_author_id (author_id) -# index_attachments_on_container_id_and_container_type (container_id,container_type) -# index_attachments_on_course_second_category_id (course_second_category_id) -# index_attachments_on_created_on (created_on) -# index_attachments_on_is_public (is_public) -# index_attachments_on_quotes (quotes) -# - +# == Schema Information +# +# Table name: attachments +# +# id :integer not null, primary key +# container_id :integer +# container_type :string(30) +# filename :string(255) default(""), not null +# disk_filename :string(255) default(""), not null +# filesize :integer default("0"), not null +# content_type :string(255) default("") +# digest :string(60) default(""), not null +# downloads :integer default("0"), not null +# author_id :integer default("0"), not null +# created_on :datetime +# description :text(65535) +# disk_directory :string(255) +# attachtype :integer default("1") +# is_public :integer default("1") +# copy_from :integer +# quotes :integer default("0") +# is_publish :integer default("1") +# publish_time :datetime +# resource_bank_id :integer +# unified_setting :boolean default("1") +# cloud_url :string(255) default("") +# course_second_category_id :integer default("0") +# delay_publish :boolean default("0") +# memo_image :boolean default("0") +# extra_type :integer default("0") +# uuid :string(255) +# +# Indexes +# +# index_attachments_on_author_id (author_id) +# index_attachments_on_container_id_and_container_type (container_id,container_type) +# index_attachments_on_course_second_category_id (course_second_category_id) +# index_attachments_on_created_on (created_on) +# index_attachments_on_is_public (is_public) +# index_attachments_on_quotes (quotes) +# + @@ -97,6 +98,11 @@ class Attachment < ApplicationRecord downloads end + def generate_uuid + self.uuid = uuid || SecureRandom.uuid + save! + end + def quotes_count quotes.nil? ? 0 : quotes end diff --git a/app/models/issue.rb b/app/models/issue.rb index 210f3a61f..504804f13 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -102,7 +102,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, :associate_attachment_container, :refresh_root_issue_count + after_save :change_versions_count, :send_update_message_to_notice_system, :associate_attachment_container, :refresh_root_issue_count, :generate_uuid after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic def incre_project_common @@ -186,6 +186,11 @@ class Issue < ApplicationRecord end end + def generate_uuid + return if pm_project_id.nil? + attachments.map(&:generate_uuid) + end + def is_collaborators? if self.assigned_to_id.present? && self.project.present? self.project.member?(self.assigned_to_id) diff --git a/db/migrate/20231121084405_add_uuid_to_attachments.rb b/db/migrate/20231121084405_add_uuid_to_attachments.rb new file mode 100644 index 000000000..5d0e2ba02 --- /dev/null +++ b/db/migrate/20231121084405_add_uuid_to_attachments.rb @@ -0,0 +1,5 @@ +class AddUuidToAttachments < ActiveRecord::Migration[5.2] + def change + add_column :attachments, :uuid, :string, index: true + end +end From 2ea41d0100c7d5c435e435d96e12bafb505fd4ad Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 22 Nov 2023 11:17:22 +0800 Subject: [PATCH 087/294] =?UTF-8?q?fixed=20=E8=A7=A3=E5=86=B3=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E9=97=AE=E9=A2=98=E8=AE=BF=E9=97=AE=E9=99=84=E4=BB=B6?= =?UTF-8?q?=EF=BC=8Cid=E6=94=B9=E4=B8=BAuuid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 4 +++- app/helpers/application_helper.rb | 2 +- app/models/issue.rb | 10 ++++++++++ app/models/journal.rb | 10 ++++++++++ app/views/attachments/create.json.jbuilder | 2 +- 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 915723b64..bf8c870a0 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -94,6 +94,7 @@ class AttachmentsController < ApplicationController @attachment.author_id = current_user.id @attachment.disk_directory = month_folder @attachment.cloud_url = remote_path + @attachment.uuid = SecureRandom.uuid @attachment.save! else logger.info "文件已存在,id = #{@attachment.id}, filename = #{@attachment.filename}" @@ -147,8 +148,9 @@ class AttachmentsController < ApplicationController if params[:type] == 'history' AttachmentHistory.find params[:id] else - Attachment.find params[:id] || Attachment.find_by(uuid: params[:id]) + Attachment.find_by(id: params[:id]) || Attachment.find_by(uuid: params[:id]) end + tip_exception(404, "您访问的页面不存在或已被删除") if @file.blank? end def delete_file(file_path) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 936452470..5d5582428 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -299,7 +299,7 @@ module ApplicationHelper end def download_url attachment,options={} - attachment_path(attachment,options) + attachment&.uuid.present? ? attachment_path(attachment.uuid,options) : attachment_path(attachment,options) end # 耗时:天、小时、分、秒 diff --git a/app/models/issue.rb b/app/models/issue.rb index 85094e748..0d55163b4 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -248,6 +248,7 @@ class Issue < ApplicationRecord # 关附件到功能 def associate_attachment_container + return if self.project_id == 0 att_ids = [] # 附件的格式为(/api/attachments/ + 附件id)的形式,提取出id进行附件属性关联,做附件访问权限控制 att_ids += self.description.to_s.scan(/\(\/api\/attachments\/.+\)/).map{|s|s.match(/\d+/)[0]} @@ -256,6 +257,15 @@ class Issue < ApplicationRecord if att_ids.present? 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 + + att_ids2 = [] + # uuid_regex= /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/ + # 附件的格式为(/api/attachments/ + uuid)的形式,提取出id进行附件属性关联,做附件访问权限控制 + att_ids2 += self.description.to_s.scan(/\(\/api\/attachments\/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\)/).map{|s|s.match(/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/)[0]} + att_ids2 += self.description.to_s.scan(/\/api\/attachments\/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/).map{|s|s.match(/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/)[0]} + if att_ids2.present? + Attachment.where(uuid: att_ids2).where("container_type IS NULL OR container_type = 'Issue'").update_all(container_id: self.project_id, container_type: 'Project') + end end def to_builder diff --git a/app/models/journal.rb b/app/models/journal.rb index e0553ad40..2798c107a 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -61,6 +61,7 @@ class Journal < ApplicationRecord # 关附件到功能 def associate_attachment_container + return if self.issue&.project_id.to_i == 0 att_ids = [] # 附件的格式为(/api/attachments/ + 附件id)的形式,提取出id进行附件属性关联,做附件访问权限控制 att_ids += self.notes.to_s.scan(/\(\/api\/attachments\/.+\)/).map{|s|s.match(/\d+/)[0]} @@ -69,6 +70,15 @@ class Journal < ApplicationRecord if att_ids.present? 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 + + att_ids2 = [] + # uuid_regex= /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/ + # 附件的格式为(/api/attachments/ + uuid)的形式,提取出id进行附件属性关联,做附件访问权限控制 + att_ids2 += self.description.to_s.scan(/\(\/api\/attachments\/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\)/).map{|s|s.match(/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/)[0]} + att_ids2 += self.description.to_s.scan(/\/api\/attachments\/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/).map{|s|s.match(/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/)[0]} + if att_ids2.present? + Attachment.where(uuid: att_ids).where("container_type IS NULL OR container_type = 'Journal'").update_all(container_id: self.issue.project_id, container_type: "Project") + end end def operate_content diff --git a/app/views/attachments/create.json.jbuilder b/app/views/attachments/create.json.jbuilder index 6ddc5ced2..3b12193c9 100644 --- a/app/views/attachments/create.json.jbuilder +++ b/app/views/attachments/create.json.jbuilder @@ -1,4 +1,4 @@ -json.id @attachment.id +json.id @attachment.uuid json.title @attachment.title json.filesize number_to_human_size(@attachment.filesize) json.is_pdf @attachment.is_pdf? From d26dcb5b9a5bbfd9ef419fcdf68487c69ddb451e Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 22 Nov 2023 11:20:03 +0800 Subject: [PATCH 088/294] =?UTF-8?q?fixed=20=E8=A7=A3=E5=86=B3=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E9=97=AE=E9=A2=98=E8=AE=BF=E9=97=AE=E9=99=84=E4=BB=B6?= =?UTF-8?q?=EF=BC=8Cid=E6=94=B9=E4=B8=BAuuid=EF=BC=8C=E8=AF=84=E8=AE=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/journal.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/journal.rb b/app/models/journal.rb index 2798c107a..dad60cd71 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -74,8 +74,8 @@ class Journal < ApplicationRecord att_ids2 = [] # uuid_regex= /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/ # 附件的格式为(/api/attachments/ + uuid)的形式,提取出id进行附件属性关联,做附件访问权限控制 - att_ids2 += self.description.to_s.scan(/\(\/api\/attachments\/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\)/).map{|s|s.match(/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/)[0]} - att_ids2 += self.description.to_s.scan(/\/api\/attachments\/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/).map{|s|s.match(/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/)[0]} + att_ids2 += self.notes.to_s.scan(/\(\/api\/attachments\/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\)/).map{|s|s.match(/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/)[0]} + att_ids2 += self.notes.to_s.scan(/\/api\/attachments\/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/).map{|s|s.match(/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/)[0]} if att_ids2.present? Attachment.where(uuid: att_ids).where("container_type IS NULL OR container_type = 'Journal'").update_all(container_id: self.issue.project_id, container_type: "Project") end From 9526d1b896597127b4f763341e92377abc9910dc Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 22 Nov 2023 11:28:35 +0800 Subject: [PATCH 089/294] =?UTF-8?q?fixed=20=E8=A7=A3=E5=86=B3=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E9=97=AE=E9=A2=98=E8=AE=BF=E9=97=AE=E9=99=84=E4=BB=B6?= =?UTF-8?q?=EF=BC=8Cid=E6=94=B9=E4=B8=BAuuid=EF=BC=8C=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E9=99=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/issues/concerns/checkable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/api/v1/issues/concerns/checkable.rb b/app/services/api/v1/issues/concerns/checkable.rb index d3cc4741d..287fae2f6 100644 --- a/app/services/api/v1/issues/concerns/checkable.rb +++ b/app/services/api/v1/issues/concerns/checkable.rb @@ -31,7 +31,7 @@ module Api::V1::Issues::Concerns::Checkable 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) + raise ApplicationService::Error, "请输入正确的附件ID!" unless Attachment.exists?(id: aid) || Attachment.exists?(uuid: aid) end end From 168f5bf7d1379197fc57222e8849376e01af2439 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 22 Nov 2023 11:34:48 +0800 Subject: [PATCH 090/294] =?UTF-8?q?fixed=20=E8=A7=A3=E5=86=B3=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E9=97=AE=E9=A2=98=E8=AE=BF=E9=97=AE=E9=99=84=E4=BB=B6?= =?UTF-8?q?=EF=BC=8Cid=E6=94=B9=E4=B8=BAuuid=EF=BC=8Cissue=E5=85=B3?= =?UTF-8?q?=E8=81=94=E9=99=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/issues/concerns/loadable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/api/v1/issues/concerns/loadable.rb b/app/services/api/v1/issues/concerns/loadable.rb index df30042e0..ffd5ff4a7 100644 --- a/app/services/api/v1/issues/concerns/loadable.rb +++ b/app/services/api/v1/issues/concerns/loadable.rb @@ -9,7 +9,7 @@ module Api::V1::Issues::Concerns::Loadable end def load_attachments(attachment_ids) - @attachments = Attachment.where(id: attachment_ids) + @attachments = Attachment.where(id: attachment_ids).or(Attachment.where(uuid: attachment_ids)) end def load_atme_receivers(receivers_login) From 778f9563f396db98d453024b7d7e66fcdeeab17e Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 22 Nov 2023 11:38:34 +0800 Subject: [PATCH 091/294] =?UTF-8?q?fixed=20=E8=A7=A3=E5=86=B3=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E9=97=AE=E9=A2=98=E8=AE=BF=E9=97=AE=E9=99=84=E4=BB=B6?= =?UTF-8?q?id=E6=94=B9=E4=B8=BAuuid=EF=BC=8C=E7=BB=9F=E4=B8=80=E5=A4=84?= =?UTF-8?q?=E7=90=86=EF=BC=8Cissue=E4=B8=8D=E5=8D=95=E7=8B=AC=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/issue.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 0d55163b4..ffda5a189 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -188,8 +188,8 @@ class Issue < ApplicationRecord end def generate_uuid - return if pm_project_id.nil? - attachments.map(&:generate_uuid) + # return if pm_project_id.nil? + # attachments.map(&:generate_uuid) end def is_collaborators? From c09c167bdd90995184fdd04973dcd8fafc46e1c8 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 22 Nov 2023 14:47:04 +0800 Subject: [PATCH 092/294] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E6=95=B0=E6=8D=AE=E5=92=8C=E4=B8=B0=E5=AF=8C=E9=A2=9C?= =?UTF-8?q?=E8=89=B2=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 2 +- app/models/issue_priority.rb | 2 +- .../api/v1/issues/_simple_detail.json.jbuilder | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index e562a52e8..991265db3 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -90,7 +90,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController end def statues - @statues = IssueStatus.order("position asc") + @statues = IssueStatus.where.not(name: "反馈").order("position asc") @statues = @statues.ransack(name_cont: params[:keyword]).result if params[:keyword].present? @statues = kaminary_select_paginate(@statues) render "api/v1/issues/statues/index" diff --git a/app/models/issue_priority.rb b/app/models/issue_priority.rb index 9a3d69392..3c08c8098 100644 --- a/app/models/issue_priority.rb +++ b/app/models/issue_priority.rb @@ -52,7 +52,7 @@ class IssuePriority < ApplicationRecord when '立刻' '#f5222d' else - '13b33e' + '#13b33e' end end end diff --git a/app/views/api/v1/issues/_simple_detail.json.jbuilder b/app/views/api/v1/issues/_simple_detail.json.jbuilder index 3460c8c65..15259baa5 100644 --- a/app/views/api/v1/issues/_simple_detail.json.jbuilder +++ b/app/views/api/v1/issues/_simple_detail.json.jbuilder @@ -7,8 +7,22 @@ json.tags issue.show_issue_tags.each do |tag| end json.status_name issue.issue_status&.name json.status_id issue.status_id +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_name issue.priority&.name json.priority_id issue.priority_id +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_name issue.version&.name json.milestone_id issue.fixed_version_id json.root_id issue.root_id From f8a6dcb3eb2047321538359ac8fc066f5d19c1dd Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 22 Nov 2023 15:36:05 +0800 Subject: [PATCH 093/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E9=A1=B9=E7=BB=9F=E8=AE=A1=E7=B1=BB=E5=88=AB=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/sprint_issues_controller.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/pm/sprint_issues_controller.rb b/app/controllers/api/pm/sprint_issues_controller.rb index 49e2398e7..6abecfb13 100644 --- a/app/controllers/api/pm/sprint_issues_controller.rb +++ b/app/controllers/api/pm/sprint_issues_controller.rb @@ -13,8 +13,10 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController return tip_exception '参数错误' if pm_sprint_ids.blank? @issues = Issue.where(pm_sprint_id: pm_sprint_ids) data = {} + # requirement 1 task 2 bug 3 @issues_count = @issues.group(:pm_sprint_id).count @issues_type_count = @issues.group(:pm_sprint_id, :status_id).count + @issues_pm_type_count = @issues.group(:pm_sprint_id, :pm_issue_type).count @issues_hour_count = @issues.group(:pm_sprint_id).sum(:time_scale) @issues_hour_type_count = @issues.group(:pm_sprint_id, :status_id).sum(:time_scale) pm_sprint_ids.map(&:to_i).map do |sprint_id| @@ -22,7 +24,10 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController count_total: @issues_count[sprint_id] || 0, count_closed: @issues_type_count[[sprint_id, 5]] || 0, hour_total: @issues_hour_count[sprint_id] || 0, - hour_closed: @issues_hour_type_count[[sprint_id, 5]] || 0 + hour_closed: @issues_hour_type_count[[sprint_id, 5]] || 0, + requirement: @issues_pm_type_count[[sprint_id, 1]] || 0, + task: @issues_pm_type_count[[sprint_id, 2]] || 0, + bug: @issues_pm_type_count[[sprint_id, 3]] || 0 } end render_ok(data: data) From 1a067d0607696bc9d987f2a167c0f5ed7545cdff Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 23 Nov 2023 08:53:02 +0800 Subject: [PATCH 094/294] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Achild=5Fcoun?= =?UTF-8?q?t=E4=BD=BF=E7=94=A8count=5Fcache?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/issue.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index ffda5a189..b91dbb26a 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -67,6 +67,7 @@ class Issue < ApplicationRecord belongs_to :version, foreign_key: :fixed_version_id,optional: true, counter_cache: true belongs_to :user,optional: true, foreign_key: :author_id belongs_to :issue_status, foreign_key: :status_id,optional: true + belongs_to :parent_issue, class_name: 'Issue', optional: true, foreign_key: :root_id, counter_cache: :child_count has_many :commit_issues has_many :attachments, as: :container, dependent: :destroy # has_many :memos @@ -103,7 +104,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, :associate_attachment_container, :refresh_root_issue_count, :generate_uuid + after_save :change_versions_count, :send_update_message_to_notice_system, :associate_attachment_container, :generate_uuid after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic def incre_project_common @@ -128,6 +129,7 @@ class Issue < ApplicationRecord root_count = Issue.where(root_id: root_id).count root_issue.update(child_count: root_count) end + def incre_platform_statistic CacheAsyncSetJob.perform_later('platform_statistic_service', {issue_count: 1}) end From 9c4bc3f37c24bec65c3c9815972b3f7c51e80474 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 24 Nov 2023 09:42:25 +0800 Subject: [PATCH 095/294] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E6=9C=AA?= =?UTF-8?q?=E5=85=B3=E8=81=94=E5=B7=A5=E4=BD=9C=E9=A1=B9=E9=9C=80=E5=8C=85?= =?UTF-8?q?=E5=90=AB=E5=A4=96=E9=94=AE=E4=B8=BA0=E7=9A=84=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/pm/sprint_issues/list_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/api/pm/sprint_issues/list_service.rb b/app/services/api/pm/sprint_issues/list_service.rb index 884506af0..bc87df84c 100644 --- a/app/services/api/pm/sprint_issues/list_service.rb +++ b/app/services/api/pm/sprint_issues/list_service.rb @@ -33,7 +33,7 @@ class Api::Pm::SprintIssues::ListService < ApplicationService private def issue_query_data - issues = @category == "unlink" ? Issue.where(pm_project_id: @pm_project_id, pm_sprint_id: nil) : Issue.where(pm_project_id: @pm_project_id).where.not(pm_sprint_id: nil) + issues = @category == "unlink" ? Issue.where(pm_project_id: @pm_project_id, pm_sprint_id: [nil, 0]) : Issue.where(pm_project_id: @pm_project_id).where.not(pm_sprint_id: [nil, 0]) issues = issues.where(pm_issue_type: @pm_issue_type) if @pm_issue_type.present? From fe4f56dd3666aeb961061e0080451f024f1d7fea Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 29 Nov 2023 14:28:31 +0800 Subject: [PATCH 096/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E6=9B=B4=E6=96=B0=E8=BF=AD=E4=BB=A3=E4=B8=AD=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/pm/sprint_issues_controller.rb | 28 +++++++++++++++++++ config/routes/api.rb | 1 + 2 files changed, 29 insertions(+) diff --git a/app/controllers/api/pm/sprint_issues_controller.rb b/app/controllers/api/pm/sprint_issues_controller.rb index 6abecfb13..72e0d367d 100644 --- a/app/controllers/api/pm/sprint_issues_controller.rb +++ b/app/controllers/api/pm/sprint_issues_controller.rb @@ -32,6 +32,34 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController end render_ok(data: data) end + + before_action :load_uncomplete_issues, only: [:complete] + + def complete + begin + case complete_params[:complete_type].to_i + when 1 + @issues.update_all(status_id: 5) + when 2 + @issues.update_all(pm_sprint_id: 0) + when 3 + @issues.update_all(pm_sprint_id: complete_params[:target_pm_project_sprint_id]) + end + render_ok + rescue => e + render_error(e.message) + end + end + + private + + def load_uncomplete_issues + @issues = Issue.where(pm_sprint_id: complete_params[:pm_project_sprint_id]).where.not(status_id: 5) + end + + def complete_params + params.permit(:pm_project_sprint_id, :complete_type, :target_pm_project_sprint_id) + end def query_params params.permit( diff --git a/config/routes/api.rb b/config/routes/api.rb index e04218143..bf38eceaf 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -24,6 +24,7 @@ defaults format: :json do resources :sprint_issues, only: [:index] do collection do get :statistics + post :complete end end resources :projects do From 93514e8a73c80f6e413027f01e8f5660b8e11e28 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 1 Dec 2023 09:19:08 +0800 Subject: [PATCH 097/294] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E5=B7=A5=E4=BD=9C=E9=A1=B9=E5=AE=B9=E9=87=8F=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E9=A2=84=E4=BC=B0=E5=B7=A5=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 1 + app/controllers/api/pm/sprint_issues_controller.rb | 10 +++++++--- app/services/api/v1/issues/list_service.rb | 11 +++++++++-- app/views/api/v1/issues/index.json.jbuilder | 1 + 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 991265db3..2fad5bc18 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -10,6 +10,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController @total_issues_count = @object_result[:total_issues_count] @opened_issues_count = @object_result[:opened_issues_count] @closed_issues_count = @object_result[:closed_issues_count] + @complete_issues_count = @object_result[:complete_issues_count] if params[:only_name].present? @issues = kaminary_select_paginate( @object_result[:data].select(:id, :subject, :project_issues_index, :updated_on, :created_on)) diff --git a/app/controllers/api/pm/sprint_issues_controller.rb b/app/controllers/api/pm/sprint_issues_controller.rb index 72e0d367d..6aff44379 100644 --- a/app/controllers/api/pm/sprint_issues_controller.rb +++ b/app/controllers/api/pm/sprint_issues_controller.rb @@ -20,11 +20,15 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController @issues_hour_count = @issues.group(:pm_sprint_id).sum(:time_scale) @issues_hour_type_count = @issues.group(:pm_sprint_id, :status_id).sum(:time_scale) pm_sprint_ids.map(&:to_i).map do |sprint_id| + # count_closed 工作项已完成/已关闭数量,需排除已修复的缺陷数量 + count_closed = @issues_type_count[[sprint_id, 5]].to_i + @issues_type_count[[sprint_id, 3]].to_i - @issues.where(pm_issue_type: 3, status_id: 3).size + # hour_closed 已完成/已关闭 预估工时之和,需排除已修复的缺陷预估工时 + hour_closed = @issues_hour_type_count[[sprint_id, 5]].to_f + @issues_hour_type_count[[sprint_id, 3]].to_f - @issues.where(pm_issue_type: 3, status_id: 3).sum(:time_scale).to_f data[sprint_id] = { count_total: @issues_count[sprint_id] || 0, - count_closed: @issues_type_count[[sprint_id, 5]] || 0, - hour_total: @issues_hour_count[sprint_id] || 0, - hour_closed: @issues_hour_type_count[[sprint_id, 5]] || 0, + count_closed: count_closed || 0, + hour_total: @issues_hour_count[sprint_id].to_f || 0, + hour_closed: hour_closed || 0, requirement: @issues_pm_type_count[[sprint_id, 1]] || 0, task: @issues_pm_type_count[[sprint_id, 2]] || 0, bug: @issues_pm_type_count[[sprint_id, 3]] || 0 diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index 17db797a6..5183fbdb9 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -5,7 +5,7 @@ class Api::V1::Issues::ListService < ApplicationService attr_reader :begin_date, :end_date attr_reader :milestone_id, :assigner_id, :status_id, :sort_by, :sort_direction, :current_user attr_reader :pm_project_id, :pm_sprint_id, :root_id, :pm_issue_type, :status_ids - attr_accessor :queried_issues, :total_issues_count, :closed_issues_count, :opened_issues_count + attr_accessor :queried_issues, :total_issues_count, :closed_issues_count, :opened_issues_count, :complete_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'} @@ -41,7 +41,13 @@ class Api::V1::Issues::ListService < ApplicationService # begin issue_query_data - {data: queried_issues, total_issues_count: @total_issues_count, closed_issues_count: @closed_issues_count, opened_issues_count: @opened_issues_count} + { + data: queried_issues, + total_issues_count: @total_issues_count, + closed_issues_count: @closed_issues_count, + opened_issues_count: @opened_issues_count, + complete_issues_count: @complete_issues_count + } # rescue # raise Error, "服务器错误,请联系系统管理员!" # end @@ -108,6 +114,7 @@ class Api::V1::Issues::ListService < ApplicationService @total_issues_count = issues.distinct.size @closed_issues_count = issues.closed.distinct.size @opened_issues_count = issues.opened.distinct.size + @complete_issues_count = issues.closed.distinct.size + issues.where(status_id: 3).distinct.size - issues.where(pm_issue_type: 3, status_id: 3).size case category when 'closed' diff --git a/app/views/api/v1/issues/index.json.jbuilder b/app/views/api/v1/issues/index.json.jbuilder index c6a5f526c..30e26d2ca 100644 --- a/app/views/api/v1/issues/index.json.jbuilder +++ b/app/views/api/v1/issues/index.json.jbuilder @@ -1,6 +1,7 @@ json.total_issues_count @total_issues_count json.opened_count @opened_issues_count json.closed_count @closed_issues_count +json.complete_count @complete_issues_count json.total_count @issues.total_count json.has_created_issues @project.present? ? @project.issues.size > 0 : 0 json.issues @issues.each do |issue| From d2402c410337880c854c348caa9bad1e1bad0982 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 1 Dec 2023 10:21:40 +0800 Subject: [PATCH 098/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/sprint_issues_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/pm/sprint_issues_controller.rb b/app/controllers/api/pm/sprint_issues_controller.rb index 6aff44379..fa819513b 100644 --- a/app/controllers/api/pm/sprint_issues_controller.rb +++ b/app/controllers/api/pm/sprint_issues_controller.rb @@ -21,9 +21,9 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController @issues_hour_type_count = @issues.group(:pm_sprint_id, :status_id).sum(:time_scale) pm_sprint_ids.map(&:to_i).map do |sprint_id| # count_closed 工作项已完成/已关闭数量,需排除已修复的缺陷数量 - count_closed = @issues_type_count[[sprint_id, 5]].to_i + @issues_type_count[[sprint_id, 3]].to_i - @issues.where(pm_issue_type: 3, status_id: 3).size + count_closed = @issues_type_count[[sprint_id, 5]].to_i + @issues_type_count[[sprint_id, 3]].to_i - @issues.where(pm_sprint_id: sprint_id, pm_issue_type: 3, status_id: 3).size # hour_closed 已完成/已关闭 预估工时之和,需排除已修复的缺陷预估工时 - hour_closed = @issues_hour_type_count[[sprint_id, 5]].to_f + @issues_hour_type_count[[sprint_id, 3]].to_f - @issues.where(pm_issue_type: 3, status_id: 3).sum(:time_scale).to_f + hour_closed = @issues_hour_type_count[[sprint_id, 5]].to_f + @issues_hour_type_count[[sprint_id, 3]].to_f - @issues.where(pm_sprint_id: sprint_id, pm_issue_type: 3, status_id: 3).sum(:time_scale).to_f data[sprint_id] = { count_total: @issues_count[sprint_id] || 0, count_closed: count_closed || 0, From 65590bd33ed48d24cfe762e11bfc96e6d43ce001 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 1 Dec 2023 10:42:16 +0800 Subject: [PATCH 099/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20issues=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E4=BD=BF=E7=94=A8distinct=E5=8E=BB=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/issues/list_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index be1ca33fe..847be25cb 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -114,7 +114,7 @@ class Api::V1::Issues::ListService < ApplicationService @total_issues_count = issues.distinct.size @closed_issues_count = issues.closed.distinct.size @opened_issues_count = issues.opened.distinct.size - @complete_issues_count = issues.closed.distinct.size + issues.where(status_id: 3).distinct.size - issues.where(pm_issue_type: 3, status_id: 3).size + @complete_issues_count = issues.closed.distinct.size + issues.where(status_id: 3).distinct.size - issues.where(pm_issue_type: 3, status_id: 3).distinct.size case category when 'closed' From fea7c522279c70ae24449a582d9ee5885fdedb29 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 4 Dec 2023 09:49:59 +0800 Subject: [PATCH 100/294] =?UTF-8?q?issue=E6=8C=89id=E9=9B=86=E5=90=88?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=EF=BC=8C=E9=80=89=E6=8B=A9=E5=85=B3=E8=81=94?= =?UTF-8?q?issue=E6=97=B6=E6=8E=92=E9=99=A4=E5=B7=B2=E9=80=89id=E9=9B=86?= =?UTF-8?q?=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 4 +++- app/services/api/v1/issues/list_service.rb | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 2fad5bc18..8ad0760fc 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -29,6 +29,8 @@ class Api::Pm::IssuesController < Api::Pm::BaseController @issue.pm_links.pluck(:be_linkable_id) end + not_join_id = params[:exclude_ids].to_s.split(",") if params[:exclude_ids].present? + not_join_id << @issue.id object_issues = Issue.where( pm_project_id: params[:pm_project_id], @@ -145,7 +147,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController :begin_date, :end_date, :sort_by, :sort_direction, :root_id, :issue_tag_ids, :pm_project_id, :pm_sprint_id, :pm_issue_type, - :status_ids + :status_ids, :ids ) end diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index 847be25cb..bc098bfbe 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -76,6 +76,9 @@ class Api::V1::Issues::ListService < ApplicationService # milestone_id issues = issues.where(fixed_version_id: milestone_id) if milestone_id.present? + # ids + issues = issues.where(id: params[:ids].to_s.split(",")) if params[:ids].present? + #pm相关 # root_id# -1 查一级目录 issues = if root_id.to_i == -1 From 1bdb6dad9831b988cb367c361caada3e40ef9108 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 4 Dec 2023 09:59:25 +0800 Subject: [PATCH 101/294] =?UTF-8?q?issue=E6=8C=89id=E9=9B=86=E5=90=88?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=EF=BC=8C=E9=80=89=E6=8B=A9=E5=85=B3=E8=81=94?= =?UTF-8?q?issue=E6=97=B6=E6=8E=92=E9=99=A4=E5=B7=B2=E9=80=89id=E9=9B=86?= =?UTF-8?q?=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 2 -- app/services/api/v1/issues/list_service.rb | 11 +++++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 8ad0760fc..3055dfabe 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -29,8 +29,6 @@ class Api::Pm::IssuesController < Api::Pm::BaseController @issue.pm_links.pluck(:be_linkable_id) end - not_join_id = params[:exclude_ids].to_s.split(",") if params[:exclude_ids].present? - not_join_id << @issue.id object_issues = Issue.where( pm_project_id: params[:pm_project_id], diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index bc098bfbe..13f9e9842 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -76,9 +76,6 @@ class Api::V1::Issues::ListService < ApplicationService # milestone_id issues = issues.where(fixed_version_id: milestone_id) if milestone_id.present? - # ids - issues = issues.where(id: params[:ids].to_s.split(",")) if params[:ids].present? - #pm相关 # root_id# -1 查一级目录 issues = if root_id.to_i == -1 @@ -105,7 +102,13 @@ class Api::V1::Issues::ListService < ApplicationService issues = issues.where(status_id: status_id) if status_id.present? && category != 'closed' # status_ids - issues = issues.where(status_id: status_ids) unless status_ids.blank? + issues = issues.where(status_id: status_ids) unless status_ids.blank? + + # ids + issues = issues.where(id: params[:ids].to_s.split(",")) if params[:ids].present? + + # exclude_ids + issues = issues.where.not(id: params[:exclude_ids].to_s.split(",")) if params[:exclude_ids].present? if begin_date&.present? || end_date&.present? issues = issues.where('issues.created_on between ? and ?', begin_date&.present? ? begin_date.to_time : Time.now.beginning_of_day, end_date&.present? ? end_date.to_time.end_of_day : Time.now.end_of_day) From b13f1a681e80e088927a061a44fccff6a2cedad0 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 4 Dec 2023 10:41:19 +0800 Subject: [PATCH 102/294] =?UTF-8?q?issue=E6=8C=89id=E9=9B=86=E5=90=88?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=EF=BC=8C=E9=80=89=E6=8B=A9=E5=85=B3=E8=81=94?= =?UTF-8?q?issue=E6=97=B6=E6=8E=92=E9=99=A4=E5=B7=B2=E9=80=89id=E9=9B=86?= =?UTF-8?q?=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 2 +- app/services/api/v1/issues/list_service.rb | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 3055dfabe..1b3563a80 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -145,7 +145,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController :begin_date, :end_date, :sort_by, :sort_direction, :root_id, :issue_tag_ids, :pm_project_id, :pm_sprint_id, :pm_issue_type, - :status_ids, :ids + :status_ids, :ids, :exclude_ids ) end diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index 13f9e9842..6411f99e6 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -4,7 +4,7 @@ class Api::V1::Issues::ListService < ApplicationService attr_reader :project, :only_name, :category, :participant_category, :keyword, :author_id, :issue_tag_ids attr_reader :begin_date, :end_date attr_reader :milestone_id, :assigner_id, :status_id, :sort_by, :sort_direction, :current_user - attr_reader :pm_project_id, :pm_sprint_id, :root_id, :pm_issue_type, :status_ids + attr_reader :pm_project_id, :pm_sprint_id, :root_id, :pm_issue_type, :status_ids, :ids, :exclude_ids attr_accessor :queried_issues, :total_issues_count, :closed_issues_count, :opened_issues_count, :complete_issues_count validates :category, inclusion: { in: %w[all opened closed], message: '请输入正确的Category'} @@ -31,6 +31,8 @@ class Api::V1::Issues::ListService < ApplicationService @pm_sprint_id = params[:pm_sprint_id] @root_id = params[:root_id] @pm_issue_type = params[:pm_issue_type] + @ids = params[:ids] + @exclude_ids = params[:exclude_ids] @status_ids = params[:status_ids].present? ? params[:status_ids].split(',') : [] @sort_direction = (params[:sort_direction].present? ? params[:sort_direction] : 'desc').downcase @current_user = current_user @@ -105,10 +107,10 @@ class Api::V1::Issues::ListService < ApplicationService issues = issues.where(status_id: status_ids) unless status_ids.blank? # ids - issues = issues.where(id: params[:ids].to_s.split(",")) if params[:ids].present? + issues = issues.where(id: ids.to_s.split(",")) if ids.present? # exclude_ids - issues = issues.where.not(id: params[:exclude_ids].to_s.split(",")) if params[:exclude_ids].present? + issues = issues.where.not(id: exclude_ids.to_s.split(",")) if exclude_ids.present? if begin_date&.present? || end_date&.present? issues = issues.where('issues.created_on between ? and ?', begin_date&.present? ? begin_date.to_time : Time.now.beginning_of_day, end_date&.present? ? end_date.to_time.end_of_day : Time.now.end_of_day) From 63638d4b2edc28fb228a2b26e0ab101f9b3655a2 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 4 Dec 2023 15:46:34 +0800 Subject: [PATCH 103/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Aissue?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=96=B0=E5=A2=9E=E4=BC=98=E5=85=88=E7=BA=A7?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 2 +- app/services/api/v1/issues/list_service.rb | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 1b3563a80..ef9d02b50 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -141,7 +141,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController :participant_category, :keyword, :author_id, :milestone_id, :assigner_id, - :status_id, + :status_id, :priority_id, :begin_date, :end_date, :sort_by, :sort_direction, :root_id, :issue_tag_ids, :pm_project_id, :pm_sprint_id, :pm_issue_type, diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index 6411f99e6..c9e66d576 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -3,7 +3,7 @@ class Api::V1::Issues::ListService < ApplicationService attr_reader :project, :only_name, :category, :participant_category, :keyword, :author_id, :issue_tag_ids attr_reader :begin_date, :end_date - attr_reader :milestone_id, :assigner_id, :status_id, :sort_by, :sort_direction, :current_user + attr_reader :milestone_id, :assigner_id, :status_id, :priority_id, :sort_by, :sort_direction, :current_user attr_reader :pm_project_id, :pm_sprint_id, :root_id, :pm_issue_type, :status_ids, :ids, :exclude_ids attr_accessor :queried_issues, :total_issues_count, :closed_issues_count, :opened_issues_count, :complete_issues_count @@ -23,6 +23,7 @@ class Api::V1::Issues::ListService < ApplicationService @issue_tag_ids = params[:issue_tag_ids].present? ? params[:issue_tag_ids].split(',') : [] @milestone_id = params[:milestone_id] @assigner_id = params[:assigner_id] + @priority_id = params[:priority_id] @status_id = params[:status_id] @begin_date = params[:begin_date] @end_date = params[:end_date] @@ -103,6 +104,9 @@ class Api::V1::Issues::ListService < ApplicationService # status_id issues = issues.where(status_id: status_id) if status_id.present? && category != 'closed' + # priority_id + issues = issues.where(priority_id: priority_id) if priority_id.present? + # status_ids issues = issues.where(status_id: status_ids) unless status_ids.blank? From 50986035e267679c84bcf00014b0200926fd1a2b Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 5 Dec 2023 14:46:59 +0800 Subject: [PATCH 104/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=20issue?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E7=9A=84pm=5Fissue=5Ftypes=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/issues/list_service.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index c9e66d576..3fe5826e6 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -4,7 +4,7 @@ class Api::V1::Issues::ListService < ApplicationService attr_reader :project, :only_name, :category, :participant_category, :keyword, :author_id, :issue_tag_ids attr_reader :begin_date, :end_date attr_reader :milestone_id, :assigner_id, :status_id, :priority_id, :sort_by, :sort_direction, :current_user - attr_reader :pm_project_id, :pm_sprint_id, :root_id, :pm_issue_type, :status_ids, :ids, :exclude_ids + attr_reader :pm_project_id, :pm_sprint_id, :root_id, :pm_issue_type, :status_ids, :ids, :exclude_ids, :pm_issue_types attr_accessor :queried_issues, :total_issues_count, :closed_issues_count, :opened_issues_count, :complete_issues_count validates :category, inclusion: { in: %w[all opened closed], message: '请输入正确的Category'} @@ -35,6 +35,7 @@ class Api::V1::Issues::ListService < ApplicationService @ids = params[:ids] @exclude_ids = params[:exclude_ids] @status_ids = params[:status_ids].present? ? params[:status_ids].split(',') : [] + @pm_issue_types = params[:pm_issue_types].present? ? params[:pm_issue_types].split(',') : [] @sort_direction = (params[:sort_direction].present? ? params[:sort_direction] : 'desc').downcase @current_user = current_user end @@ -110,6 +111,9 @@ class Api::V1::Issues::ListService < ApplicationService # status_ids issues = issues.where(status_id: status_ids) unless status_ids.blank? + # pm_issue_types + issues = issues.where(pm_issue_type: pm_issue_types) unless pm_issue_types.blank? + # ids issues = issues.where(id: ids.to_s.split(",")) if ids.present? From 67ce9af3825d65795f5fbd26b5b3bc8eb51a3a2d Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 5 Dec 2023 14:49:21 +0800 Subject: [PATCH 105/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=20issue?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E7=9A=84pm=5Fissue=5Ftypes=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index ef9d02b50..addc80709 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -145,7 +145,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController :begin_date, :end_date, :sort_by, :sort_direction, :root_id, :issue_tag_ids, :pm_project_id, :pm_sprint_id, :pm_issue_type, - :status_ids, :ids, :exclude_ids + :status_ids, :ids, :exclude_ids, :pm_issue_types ) end From b15bddea49c7034902975a2fa196a0117f5f74ff Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 6 Dec 2023 09:30:49 +0800 Subject: [PATCH 106/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=8E=92?= =?UTF-8?q?=E5=BA=8F=E5=AD=97=E6=AE=B5=E5=A4=B1=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/pm/sprint_issues/list_service.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/services/api/pm/sprint_issues/list_service.rb b/app/services/api/pm/sprint_issues/list_service.rb index bc87df84c..b77d074b7 100644 --- a/app/services/api/pm/sprint_issues/list_service.rb +++ b/app/services/api/pm/sprint_issues/list_service.rb @@ -20,6 +20,8 @@ class Api::Pm::SprintIssues::ListService < ApplicationService @priority_id = params[:priority_id] @status_id = params[:status_id] @keyword = params[:keyword] + @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 From 5fec6b3942f19c89989ccbcd9bd803071f985176 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 6 Dec 2023 13:50:20 +0800 Subject: [PATCH 107/294] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=8E=BB?= =?UTF-8?q?=E6=8E=89=E5=A4=9A=E4=BD=99=E6=95=B0=E6=8D=AE=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 2 +- app/models/issue_priority.rb | 4 ++-- app/models/issue_status.rb | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index addc80709..5ae8ed9b1 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -91,7 +91,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController end def statues - @statues = IssueStatus.where.not(name: "反馈").order("position asc") + @statues = IssueStatus.where.order("position asc") @statues = @statues.ransack(name_cont: params[:keyword]).result if params[:keyword].present? @statues = kaminary_select_paginate(@statues) render "api/v1/issues/statues/index" diff --git a/app/models/issue_priority.rb b/app/models/issue_priority.rb index 3c08c8098..5904af649 100644 --- a/app/models/issue_priority.rb +++ b/app/models/issue_priority.rb @@ -49,8 +49,8 @@ class IssuePriority < ApplicationRecord '#ff6f00' when '紧急' '#d20f0f' - when '立刻' - '#f5222d' + # when '立刻' + # '#f5222d' else '#13b33e' end diff --git a/app/models/issue_status.rb b/app/models/issue_status.rb index cf1bc9f9b..63c15bd89 100644 --- a/app/models/issue_status.rb +++ b/app/models/issue_status.rb @@ -61,8 +61,8 @@ class IssueStatus < ApplicationRecord '#13b33e' when '关闭' '#b1aaa5' - when '反馈' - '#13c2c2' + # when '反馈' + # '#13c2c2' when '拒绝' '#ff0000' else From 6bd2bb702447e5911432295882363df911a313bf Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 6 Dec 2023 13:59:28 +0800 Subject: [PATCH 108/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 5ae8ed9b1..0263a115a 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -91,7 +91,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController end def statues - @statues = IssueStatus.where.order("position asc") + @statues = IssueStatus.order("position asc") @statues = @statues.ransack(name_cont: params[:keyword]).result if params[:keyword].present? @statues = kaminary_select_paginate(@statues) render "api/v1/issues/statues/index" From 09942caa3be3b669906870e802747d88c3f8b73c Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 7 Dec 2023 13:58:41 +0800 Subject: [PATCH 109/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Aprint=20issu?= =?UTF-8?q?es=20pm=5Fissue=5Ftypes=E5=AD=97=E6=AE=B5=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/pm/sprint_issues/list_service.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/services/api/pm/sprint_issues/list_service.rb b/app/services/api/pm/sprint_issues/list_service.rb index b77d074b7..231a84237 100644 --- a/app/services/api/pm/sprint_issues/list_service.rb +++ b/app/services/api/pm/sprint_issues/list_service.rb @@ -3,6 +3,7 @@ class Api::Pm::SprintIssues::ListService < ApplicationService include ActiveModel::Model attr_reader :category, :pm_project_id, :pm_issue_type, :assigner_id, :priority_id, :status_id, :keyword, :current_user + attr_reader :pm_issue_types attr_reader :sort_by, :sort_direction attr_accessor :queried_issues @@ -20,6 +21,7 @@ class Api::Pm::SprintIssues::ListService < ApplicationService @priority_id = params[:priority_id] @status_id = params[:status_id] @keyword = params[:keyword] + @pm_issue_types = params[:pm_issue_types].present? ? params[:pm_issue_types].split(',') : [] @sort_by = params[:sort_by].present? ? params[:sort_by] : 'issues.updated_on' @sort_direction = (params[:sort_direction].present? ? params[:sort_direction] : 'desc').downcase @current_user = current_user @@ -45,6 +47,9 @@ class Api::Pm::SprintIssues::ListService < ApplicationService issues = issues.where(status_id: @status_id) if @status_id.present? + # pm_issue_types + issues = issues.where(pm_issue_type: @pm_issue_types) unless @pm_issue_types.blank? + issues = issues.ransack(subject_cont: @keyword).result if @keyword.present? scope = issues.includes(:priority, :issue_status, :user, :show_assigners, :show_issue_tags, :version, :comment_journals) From 648d4189a2315ae7f26bde7f6b2fc0b6c5cacfe6 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 7 Dec 2023 14:05:33 +0800 Subject: [PATCH 110/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Apermit=20que?= =?UTF-8?q?ry=20parms?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/sprint_issues_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/pm/sprint_issues_controller.rb b/app/controllers/api/pm/sprint_issues_controller.rb index fa819513b..1a5f555fa 100644 --- a/app/controllers/api/pm/sprint_issues_controller.rb +++ b/app/controllers/api/pm/sprint_issues_controller.rb @@ -73,7 +73,7 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController :assigner_id, :priority_id, :status_id, - :keyword, + :keyword, :pm_issue_types, :sort_by, :sort_direction ) end From f9753c948eec543d2dba7152baa2c6558d5fdf96 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 7 Dec 2023 14:45:31 +0800 Subject: [PATCH 111/294] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E9=99=84?= =?UTF-8?q?=E4=BB=B6=E8=BF=94=E5=9B=9E=E7=BB=9D=E5=AF=B9=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/api/v1/attachments/_simple_detail.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/api/v1/attachments/_simple_detail.json.jbuilder b/app/views/api/v1/attachments/_simple_detail.json.jbuilder index 3d56eb82f..f2dba0f8c 100644 --- a/app/views/api/v1/attachments/_simple_detail.json.jbuilder +++ b/app/views/api/v1/attachments/_simple_detail.json.jbuilder @@ -2,6 +2,6 @@ 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.url Rails.application.config_for(:configuration)['platform_url'] + (attachment.is_pdf? ? download_url(attachment,disposition:"inline") : download_url(attachment)).to_s json.created_on attachment.created_on.strftime("%Y-%m-%d %H:%M") json.content_type attachment.content_type From 48a446662f9ddf6c0d93e43676354a1a8dd2f317 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 7 Dec 2023 15:37:02 +0800 Subject: [PATCH 112/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Aprint=20issu?= =?UTF-8?q?es=20status=5Fids=20=E5=AD=97=E6=AE=B5=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/sprint_issues_controller.rb | 2 +- app/services/api/pm/sprint_issues/list_service.rb | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/pm/sprint_issues_controller.rb b/app/controllers/api/pm/sprint_issues_controller.rb index 1a5f555fa..0ae86ca9b 100644 --- a/app/controllers/api/pm/sprint_issues_controller.rb +++ b/app/controllers/api/pm/sprint_issues_controller.rb @@ -73,7 +73,7 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController :assigner_id, :priority_id, :status_id, - :keyword, :pm_issue_types, + :keyword, :status_ids, :pm_issue_types, :sort_by, :sort_direction ) end diff --git a/app/services/api/pm/sprint_issues/list_service.rb b/app/services/api/pm/sprint_issues/list_service.rb index 231a84237..3f92963a3 100644 --- a/app/services/api/pm/sprint_issues/list_service.rb +++ b/app/services/api/pm/sprint_issues/list_service.rb @@ -3,7 +3,7 @@ class Api::Pm::SprintIssues::ListService < ApplicationService include ActiveModel::Model attr_reader :category, :pm_project_id, :pm_issue_type, :assigner_id, :priority_id, :status_id, :keyword, :current_user - attr_reader :pm_issue_types + attr_reader :status_ids, :pm_issue_types attr_reader :sort_by, :sort_direction attr_accessor :queried_issues @@ -21,6 +21,7 @@ class Api::Pm::SprintIssues::ListService < ApplicationService @priority_id = params[:priority_id] @status_id = params[:status_id] @keyword = params[:keyword] + @status_ids = params[:status_ids].present? ? params[:status_ids].split(',') : [] @pm_issue_types = params[:pm_issue_types].present? ? params[:pm_issue_types].split(',') : [] @sort_by = params[:sort_by].present? ? params[:sort_by] : 'issues.updated_on' @sort_direction = (params[:sort_direction].present? ? params[:sort_direction] : 'desc').downcase @@ -47,6 +48,9 @@ class Api::Pm::SprintIssues::ListService < ApplicationService issues = issues.where(status_id: @status_id) if @status_id.present? + # status_ids + issues = issues.where(status_id: @status_ids) unless @status_ids.blank? + # pm_issue_types issues = issues.where(pm_issue_type: @pm_issue_types) unless @pm_issue_types.blank? From 947117ac5f452e9e8b243637a8831694498e8f92 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 12 Dec 2023 09:47:54 +0800 Subject: [PATCH 113/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E7=88=B6?= =?UTF-8?q?=E5=AD=90=E5=85=B3=E7=B3=BB=E5=88=A4=E6=96=AD=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?=E5=8F=AF=E8=AE=BE=E7=BD=AE=E4=B8=BA=E7=88=B6=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E9=A1=B9=E7=9A=84=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 15 ++++++++++++++- app/models/issue.rb | 8 ++++++++ app/services/api/v1/issues/concerns/checkable.rb | 4 ++++ app/services/api/v1/issues/update_service.rb | 2 ++ .../api/pm/issues/parent_issues.json.jbuilder | 8 ++++++++ config/routes/api.rb | 1 + 6 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 app/views/api/pm/issues/parent_issues.json.jbuilder diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 0263a115a..162ce7bcf 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -1,7 +1,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController before_action :require_login, except: [:index] before_action :load_project - before_action :load_issue, only: %i[show update destroy link_index link_issues] + before_action :load_issue, only: %i[show update destroy link_index link_issues parent_issues] before_action :load_issues, only: %i[batch_update batch_destroy] before_action :check_issue_operate_permission, only: %i[update destroy] @@ -40,6 +40,19 @@ class Api::Pm::IssuesController < Api::Pm::BaseController render 'api/v1/issues/index' end + def parent_issues + @issues = Issue.where(pm_project_id: params[:pm_project_id]) + .where.not(id: @issue.id) + .where.not(id: Issue.full_children_issues(@issue).map{|i|i.id}) + if params[:only_name].present? + @issues = kaminary_select_paginate( + @issues.select(:id, :subject, :project_issues_index, :updated_on, :created_on)) + else + @issues = @issues.includes(:priority, :issue_status, :user, :show_assigners, :show_issue_tags, :version, :comment_journals) + @issues = kaminari_paginate(@issues) + end + end + def show @issue.associate_attachment_container render 'api/v1/issues/show' diff --git a/app/models/issue.rb b/app/models/issue.rb index b91dbb26a..b40efefa1 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -296,4 +296,12 @@ class Issue < ApplicationRecord end end + def self.full_children_issues(issue, issues = []) + issue.children_issues.each do |i| + issues << i + full_children_issues(i, issues) + end + issues + end + end diff --git a/app/services/api/v1/issues/concerns/checkable.rb b/app/services/api/v1/issues/concerns/checkable.rb index 287fae2f6..8067262e2 100644 --- a/app/services/api/v1/issues/concerns/checkable.rb +++ b/app/services/api/v1/issues/concerns/checkable.rb @@ -12,6 +12,10 @@ module Api::V1::Issues::Concerns::Checkable raise ApplicationService::Error, "Milestone不存在!" unless Version.find_by_id(milestone_id).present? end + def check_root_issue(issue, root_id) + raise ApplicationService::Error, "父工作项与当前工作项已存在父子关系!" if Issue.full_children_issues(issue).map{|i| i.id}.include?(root_id) + end + def check_issue_tags(issue_tag_ids) raise ApplicationService::Error, "请输入正确的标记ID数组!" unless issue_tag_ids.is_a?(Array) raise ApplicationService::Error, "最多可选择3个标记" if issue_tag_ids.size > 3 diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 6938bc946..7134197ab 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -5,6 +5,7 @@ class Api::V1::Issues::UpdateService < ApplicationService attr_reader :project, :issue, :current_user attr_reader :status_id, :priority_id, :milestone_id, :branch_name, :start_date, :due_date, :subject, :description, :blockchain_token_num + attr_reader :target_pm_project_id, :pm_sprint_id, :pm_issue_type, :root_id, :time_scale attr_reader :issue_tag_ids, :assigner_ids, :attachment_ids, :receivers_login, :before_issue_tag_ids, :before_assigner_ids, :project_id attr_accessor :add_assigner_ids, :previous_issue_changes, :updated_issue, :atme_receivers @@ -46,6 +47,7 @@ class Api::V1::Issues::UpdateService < ApplicationService check_issue_status(status_id) if status_id.present? check_issue_priority(priority_id) if priority_id.present? check_milestone(milestone_id) if milestone_id.present? + check_root_issue(issue, root_id) if root_id.present? check_issue_tags(issue_tag_ids) unless issue_tag_ids.nil? check_assigners(assigner_ids) unless assigner_ids.nil? check_attachments(attachment_ids) unless attachment_ids.nil? diff --git a/app/views/api/pm/issues/parent_issues.json.jbuilder b/app/views/api/pm/issues/parent_issues.json.jbuilder new file mode 100644 index 000000000..a9a930d6a --- /dev/null +++ b/app/views/api/pm/issues/parent_issues.json.jbuilder @@ -0,0 +1,8 @@ +json.total_count @issues.total_count +json.issues @issues.each do |issue| + if params[:only_name].present? + json.(issue, :id, :subject, :project_issues_index) + else + json.partial! "api/v1/issues/simple_detail", locals: {issue: issue} + end +end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index bf38eceaf..ee89921b6 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -11,6 +11,7 @@ defaults format: :json do end member do get :link_index + get :parent_issues end resources :issue_links From 008d9dda3e96e563093f406454dc8abcabe88a4a Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 12 Dec 2023 11:23:38 +0800 Subject: [PATCH 114/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E7=88=B6?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E9=A1=B9=E5=88=97=E8=A1=A8=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 162ce7bcf..02b8c46cf 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -44,6 +44,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController @issues = Issue.where(pm_project_id: params[:pm_project_id]) .where.not(id: @issue.id) .where.not(id: Issue.full_children_issues(@issue).map{|i|i.id}) + @issues = @issues.where(pm_issue_type: params[:pm_issue_type]) if params[:pm_issue_type].present? if params[:only_name].present? @issues = kaminary_select_paginate( @issues.select(:id, :subject, :project_issues_index, :updated_on, :created_on)) From 39aa02ff576dc27ae8c79ee8df5490115791e644 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 13 Dec 2023 11:05:16 +0800 Subject: [PATCH 115/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=85=B3?= =?UTF-8?q?=E9=94=AE=E8=AF=8D=E6=90=9C=E7=B4=A2=E4=BB=A5=E5=8F=8A=E6=8E=92?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 02b8c46cf..81f6a7af6 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -45,6 +45,8 @@ class Api::Pm::IssuesController < Api::Pm::BaseController .where.not(id: @issue.id) .where.not(id: Issue.full_children_issues(@issue).map{|i|i.id}) @issues = @issues.where(pm_issue_type: params[:pm_issue_type]) if params[:pm_issue_type].present? + @issues = @issues.ransack(id_or_project_issues_index_eq: params[:keyword]).result.or(@issues.ransack(subject_or_description_cont: params[:keyword]).result) if params[:keyword].present? + @issues = @issues.reorder("#{issue_sort_by} #{issue_sort_direction}") if params[:only_name].present? @issues = kaminary_select_paginate( @issues.select(:id, :subject, :project_issues_index, :updated_on, :created_on)) @@ -185,6 +187,18 @@ class Api::Pm::IssuesController < Api::Pm::BaseController :assigner_ids => [] ) end + def issue_sort_by + sort_by = params.fetch(:sort_by, "updated_on") + sort_by = Issue.column_names.include?(sort_by) ? sort_by : "updated_on" + sort_by + end + + def issue_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 tag_sort_by sort_by = params.fetch(:sort_by, "created_at") sort_by = IssueTag.column_names.include?(sort_by) ? sort_by : "created_at" From 5fafd8195c6eeda07a30e3e25841f3d06271986a Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 4 Jan 2024 14:25:40 +0800 Subject: [PATCH 116/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=A0=87=E8=AE=B0=E5=85=B3=E8=81=94=E7=BB=84=E7=BB=87?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/pm/issue_tags_controller.rb | 67 +++++++++++++++++++ app/models/issue_tag.rb | 5 ++ config/routes/api.rb | 2 +- ...53819_add_organization_id_to_issue_tags.rb | 5 ++ 4 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 app/controllers/api/pm/issue_tags_controller.rb create mode 100644 db/migrate/20240104053819_add_organization_id_to_issue_tags.rb diff --git a/app/controllers/api/pm/issue_tags_controller.rb b/app/controllers/api/pm/issue_tags_controller.rb new file mode 100644 index 000000000..3962b76d4 --- /dev/null +++ b/app/controllers/api/pm/issue_tags_controller.rb @@ -0,0 +1,67 @@ +class Api::Pm::IssueTagsController < Api::Pm::BaseController + + def index + @issue_tags = IssueTag.pm_able + @issue_tags = @issue_tags.where(organization_id: params[:organization_id]) if params[:organization_id].present? + @issue_tags = @issue_tags.where(pm_project_id: params[:pm_project_id]) if params[:pm_project_id].present? + @issue_tags = @issue_tags.ransack(name_cont: params[:keyword]).result if params[:keyword].present? + @issue_tags = @issue_tags.reorder("#{tag_sort_by} #{tag_sort_direction}") + @issue_tags = kaminari_paginate(@issue_tags) + render "api/v1/issues/issue_tags/index" + end + + def create + return render_error("请输入正确的OrganizationID") unless Organization.exists?(id: issue_tag_create_params[:organization_id]) + @issue_tag = IssueTag.new(issue_tag_create_params.merge!(project_id: 0)) + 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_update_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 tag_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 tag_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_create_params + params.permit(:name, :description, :color, :pm_project_id, :organization_id) + end + + def issue_tag_update_params + params.permit(:name, :description, :color) + end + + def load_issue_tag + @issue_tag = IssueTag.pm_able.find_by_id(params[:id]) + end +end \ No newline at end of file diff --git a/app/models/issue_tag.rb b/app/models/issue_tag.rb index e8ffa4c0a..3c88c4ef1 100644 --- a/app/models/issue_tag.rb +++ b/app/models/issue_tag.rb @@ -15,9 +15,11 @@ # gitea_url :string(255) # pull_requests_count :integer default("0") # pm_project_id :integer +# organization_id :integer # # Indexes # +# index_issue_tags_on_organization_id (organization_id) # index_issue_tags_on_user_id_and_name_and_project_id (user_id,name,project_id) # @@ -29,6 +31,9 @@ class IssueTag < ApplicationRecord 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 + belongs_to :organization, optional: true + + scope :pm_able, -> {where(project_id: 0)} validates :name, uniqueness: {scope: :project_id, message: "已存在" }, if: :pm_project? diff --git a/config/routes/api.rb b/config/routes/api.rb index 77abee455..50c6a9538 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -13,7 +13,6 @@ defaults format: :json do get :link_index get :parent_issues end - resources :issue_links resources :journals do @@ -22,6 +21,7 @@ defaults format: :json do end end end + resources :issue_tags resources :sprint_issues, only: [:index] do collection do get :statistics diff --git a/db/migrate/20240104053819_add_organization_id_to_issue_tags.rb b/db/migrate/20240104053819_add_organization_id_to_issue_tags.rb new file mode 100644 index 000000000..04cc02d0e --- /dev/null +++ b/db/migrate/20240104053819_add_organization_id_to_issue_tags.rb @@ -0,0 +1,5 @@ +class AddOrganizationIdToIssueTags < ActiveRecord::Migration[5.2] + def change + add_reference :issue_tags, :organization + end +end From 05aeecf67a0fb460b720930273fb4f270196cc53 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 10 Jan 2024 14:03:08 +0800 Subject: [PATCH 117/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=A0=87=E8=AE=B0=E5=85=B3=E8=81=94=E7=BB=84=E7=BB=87?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issue_tags_controller.rb | 9 ++++++--- app/controllers/api/pm/issues_controller.rb | 2 +- app/models/issue_tag.rb | 9 +++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/pm/issue_tags_controller.rb b/app/controllers/api/pm/issue_tags_controller.rb index 3962b76d4..f0f3543ca 100644 --- a/app/controllers/api/pm/issue_tags_controller.rb +++ b/app/controllers/api/pm/issue_tags_controller.rb @@ -2,7 +2,10 @@ class Api::Pm::IssueTagsController < Api::Pm::BaseController def index @issue_tags = IssueTag.pm_able - @issue_tags = @issue_tags.where(organization_id: params[:organization_id]) if params[:organization_id].present? + if params[:organization_id].present? + IssueTag.pm_org_init_data(params[:organization_id]) unless $redis_cache.hget("pm_org_init_issue_tags", params[:organization_id]) + @issue_tags = @issue_tags.where(organization_id: params[:organization_id]) + end @issue_tags = @issue_tags.where(pm_project_id: params[:pm_project_id]) if params[:pm_project_id].present? @issue_tags = @issue_tags.ransack(name_cont: params[:keyword]).result if params[:keyword].present? @issue_tags = @issue_tags.reorder("#{tag_sort_by} #{tag_sort_direction}") @@ -19,7 +22,7 @@ class Api::Pm::IssueTagsController < Api::Pm::BaseController render_error("创建标记失败!") end end - + before_action :load_issue_tag, only: [:update, :destroy] def update @@ -48,7 +51,7 @@ class Api::Pm::IssueTagsController < Api::Pm::BaseController end def tag_sort_direction - sort_direction = params.fetch(:sort_direction, "desc").downcase + sort_direction = params.fetch(:sort_direction, "desc")&.downcase sort_direction = %w(desc asc).include?(sort_direction) ? sort_direction : "desc" sort_direction end diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 81f6a7af6..6cd37ce18 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -98,7 +98,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController end def tags - IssueTag.pm_init_data(params[:pm_project_id]) unless $redis_cache.hget("pm_project_init_issue_tags", params[:pm_project_id]) + # IssueTag.pm_init_data(params[:pm_project_id]) unless $redis_cache.hget("pm_project_init_issue_tags", params[:pm_project_id]) @issue_tags = IssueTag.where(pm_project_id: params[:pm_project_id]).reorder("#{tag_sort_by} #{tag_sort_direction}") @issue_tags = @issue_tags.ransack(name_cont: params[:keyword]).result if params[:keyword].present? params[:only_name] = true #强制渲染 不走project diff --git a/app/models/issue_tag.rb b/app/models/issue_tag.rb index 3c88c4ef1..496cc907e 100644 --- a/app/models/issue_tag.rb +++ b/app/models/issue_tag.rb @@ -59,6 +59,15 @@ class IssueTag < ApplicationRecord $redis_cache.hset("pm_project_init_issue_tags", pm_project_id, 1) end + def self.pm_org_init_data(organization_id) + data = init_issue_tag_data + data.each do |item| + next if IssueTag.exists?(organization_id: organization_id, project_id: 0, name: item[0]) + IssueTag.create!(organization_id: organization_id, project_id: 0, name: item[0], description: item[1], color: item[2]) + end + $redis_cache.hset("pm_org_init_issue_tags", organization_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) From f9ce2a8b26de5bdcc98f0f079f9b9f1eeee891e1 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 12 Jan 2024 16:39:35 +0800 Subject: [PATCH 118/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=A0=87=E8=AE=B0=E5=88=9B=E5=BB=BA=E6=97=B6=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E4=B8=BA=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issue_tags_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/api/pm/issue_tags_controller.rb b/app/controllers/api/pm/issue_tags_controller.rb index f0f3543ca..58feb6e8d 100644 --- a/app/controllers/api/pm/issue_tags_controller.rb +++ b/app/controllers/api/pm/issue_tags_controller.rb @@ -15,6 +15,7 @@ class Api::Pm::IssueTagsController < Api::Pm::BaseController def create return render_error("请输入正确的OrganizationID") unless Organization.exists?(id: issue_tag_create_params[:organization_id]) + return render_error("项目标记名称不能为空!") unless issue_tag_create_params[:name].present? @issue_tag = IssueTag.new(issue_tag_create_params.merge!(project_id: 0)) if @issue_tag.save! render_ok From 8edc1508005b8fc8b07f933a49b6ec8e774842dc Mon Sep 17 00:00:00 2001 From: yystopf Date: Sat, 13 Jan 2024 08:26:15 +0800 Subject: [PATCH 119/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E4=BF=A1=E6=81=AF=E8=BF=94=E5=9B=9Ename?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/projects_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index 4b2ede03b..b66878367 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -4,7 +4,8 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController def convert data = { owner: @project.owner.try(:login), - identifier: @project.identifier + identifier: @project.identifier, + name: @project.name } render_ok(data: data) end From ebdfbbf4201a9e742a310f5755cb566c1b22acb5 Mon Sep 17 00:00:00 2001 From: yystopf Date: Sat, 13 Jan 2024 14:31:35 +0800 Subject: [PATCH 120/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E7=A6=85=E9=81=93=E6=95=B0=E6=8D=AE=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/import_issues_from_chandao.rake | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 lib/tasks/import_issues_from_chandao.rake diff --git a/lib/tasks/import_issues_from_chandao.rake b/lib/tasks/import_issues_from_chandao.rake new file mode 100644 index 000000000..1923f977a --- /dev/null +++ b/lib/tasks/import_issues_from_chandao.rake @@ -0,0 +1,29 @@ + +desc "导入禅道数据" +namespace :import_from_chandao do + desc "bug数据" + # 执行示例 bundle exec rake "import_from_chandao:bugs[企业内部工时管理系统-yystopf.csv, 1]" + # RAILS_ENV=production bundle exec rake "import_from_chandao:bugs[企业内部工时管理系统-yystopf.csv, 1]" + task :bugs, [:name, :pm_project_id] => :environment do |t, args| + name = args.name + CSV.foreach("#{Rails.root}/#{args.name}", headers: true) do | row | + randd_field_hash = row.to_hash + issue = Issue.new + author = User.like(randd_field_hash['由谁创建']).take + issue.author_id = author&.id + assigner = User.like(randd_field_hash['指派给']).take + issue.assigners << assigner + issue.status_id = IssueStatus.first.id + issue.tracker_id = Tracker.first.id + issue.priority_id = randd_field_hash['优先级'].to_i + issue.subject = randd_field_hash['Bug标题'] + issue.description = randd_field_hash['重现步骤'] + issue.created_on = randd_field_hash['创建日期'].to_time + issue.due_date = randd_field_hash['截止日期'] + issue.project_id = 0 + issue.pm_project_id = args.pm_project_id + issue.pm_issue_type = 3 + issue.save! + end + end +end \ No newline at end of file From f893ce41d00578239cdc639ffb59d28e99cfa34c Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 15 Jan 2024 10:52:30 +0800 Subject: [PATCH 121/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=8E=92?= =?UTF-8?q?=E9=99=A4=E7=BB=84=E7=BB=87=E9=A1=B9=E7=9B=AEID=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/organizations/projects_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/organizations/projects_controller.rb b/app/controllers/organizations/projects_controller.rb index 753fee5ea..c9740040b 100644 --- a/app/controllers/organizations/projects_controller.rb +++ b/app/controllers/organizations/projects_controller.rb @@ -11,6 +11,7 @@ class Organizations::ProjectsController < Organizations::BaseController # 表情处理 keywords = params[:search].to_s.each_char.select { |c| c.bytes.first < 240 }.join('') @projects = @projects.where(id: params[:pm_project_repository_ids].split(',')) if params[:pm_project_repository_ids].present? + @projects = @projects.where.not(id: params[:exclude_ids]) if params[:exclude_ids].present? @projects = @projects.ransack(name_or_identifier_cont: keywords).result if params[:search].present? @projects = @projects.includes(:owner).order("projects.#{sort} #{sort_direction}") @projects = paginate(@projects) From d55ff07296a04d54e79ab4ec044c7cb8a70e15d5 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 15 Jan 2024 10:59:01 +0800 Subject: [PATCH 122/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=8E=92?= =?UTF-8?q?=E9=99=A4=E7=BB=84=E7=BB=87=E9=A1=B9=E7=9B=AEID=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/organizations/projects_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/organizations/projects_controller.rb b/app/controllers/organizations/projects_controller.rb index c9740040b..1180a1a51 100644 --- a/app/controllers/organizations/projects_controller.rb +++ b/app/controllers/organizations/projects_controller.rb @@ -11,7 +11,7 @@ class Organizations::ProjectsController < Organizations::BaseController # 表情处理 keywords = params[:search].to_s.each_char.select { |c| c.bytes.first < 240 }.join('') @projects = @projects.where(id: params[:pm_project_repository_ids].split(',')) if params[:pm_project_repository_ids].present? - @projects = @projects.where.not(id: params[:exclude_ids]) if params[:exclude_ids].present? + @projects = @projects.where.not(id: params[:exclude_ids].to_s.split(",")) if params[:exclude_ids].present? @projects = @projects.ransack(name_or_identifier_cont: keywords).result if params[:search].present? @projects = @projects.includes(:owner).order("projects.#{sort} #{sort_direction}") @projects = paginate(@projects) From ccdacb641f6644a687da747b86b24618de5f9b54 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 15 Jan 2024 14:53:29 +0800 Subject: [PATCH 123/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E7=A6=85=E9=81=93=E9=9C=80=E6=B1=82=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/import_issues_from_chandao.rake | 29 +++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/tasks/import_issues_from_chandao.rake b/lib/tasks/import_issues_from_chandao.rake index 1923f977a..15b038ce6 100644 --- a/lib/tasks/import_issues_from_chandao.rake +++ b/lib/tasks/import_issues_from_chandao.rake @@ -2,8 +2,8 @@ desc "导入禅道数据" namespace :import_from_chandao do desc "bug数据" - # 执行示例 bundle exec rake "import_from_chandao:bugs[企业内部工时管理系统-yystopf.csv, 1]" - # RAILS_ENV=production bundle exec rake "import_from_chandao:bugs[企业内部工时管理系统-yystopf.csv, 1]" + # 执行示例 bundle exec rake "import_from_chandao:bugs[企业内部工时管理系统.csv, 3]" + # RAILS_ENV=production bundle exec rake "import_from_chandao:bugs[企业内部工时管理系统.csv, 3]" task :bugs, [:name, :pm_project_id] => :environment do |t, args| name = args.name CSV.foreach("#{Rails.root}/#{args.name}", headers: true) do | row | @@ -26,4 +26,29 @@ namespace :import_from_chandao do issue.save! end end + + # 执行示例 bundle exec rake "import_from_chandao:requirements[企业网站第二期.csv, 3]" + # RAILS_ENV=production bundle exec rake "import_from_chandao:requirements[企业网站第二期.csv, 3]" + task :requirements, [:name, :pm_project_id] => :environment do |t, args| + name = args.name + CSV.foreach("#{Rails.root}/#{args.name}", headers: true) do | row | + randd_field_hash = row.to_hash + issue = Issue.new + author = User.like(randd_field_hash['由谁创建']).take + issue.author_id = author&.id + assigner = User.like(randd_field_hash['指派给']).take + issue.assigners << assigner + issue.status_id = IssueStatus.first.id + issue.tracker_id = Tracker.first.id + issue.priority_id = randd_field_hash['优先级'].to_i + issue.subject = randd_field_hash['需求名称'] + issue.description = randd_field_hash['需求描述'] + issue.created_on = randd_field_hash['创建日期'].to_time + issue.time_scale = randd_field_hash['预计工时'].to_i + issue.project_id = 0 + issue.pm_project_id = args.pm_project_id + issue.pm_issue_type = 1 + issue.save! + end + end end \ No newline at end of file From ea6295c888b0f1d0500ae1c57d4f0a4bbe8d8494 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 23 Jan 2024 11:19:00 +0800 Subject: [PATCH 124/294] update pm statistics hour --- app/controllers/api/pm/sprint_issues_controller.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/pm/sprint_issues_controller.rb b/app/controllers/api/pm/sprint_issues_controller.rb index 0ae86ca9b..e443fcc0c 100644 --- a/app/controllers/api/pm/sprint_issues_controller.rb +++ b/app/controllers/api/pm/sprint_issues_controller.rb @@ -19,6 +19,7 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController @issues_pm_type_count = @issues.group(:pm_sprint_id, :pm_issue_type).count @issues_hour_count = @issues.group(:pm_sprint_id).sum(:time_scale) @issues_hour_type_count = @issues.group(:pm_sprint_id, :status_id).sum(:time_scale) + @issues_hour_pm_type_count = @issues.group(:pm_sprint_id, :pm_issue_type).sum(:time_scale) pm_sprint_ids.map(&:to_i).map do |sprint_id| # count_closed 工作项已完成/已关闭数量,需排除已修复的缺陷数量 count_closed = @issues_type_count[[sprint_id, 5]].to_i + @issues_type_count[[sprint_id, 3]].to_i - @issues.where(pm_sprint_id: sprint_id, pm_issue_type: 3, status_id: 3).size @@ -31,7 +32,11 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController hour_closed: hour_closed || 0, requirement: @issues_pm_type_count[[sprint_id, 1]] || 0, task: @issues_pm_type_count[[sprint_id, 2]] || 0, - bug: @issues_pm_type_count[[sprint_id, 3]] || 0 + bug: @issues_pm_type_count[[sprint_id, 3]] || 0, + requirement_hour: @issues_hour_pm_type_count[[sprint_id, 1]] || 0, + task_hour: @issues_hour_pm_type_count[[sprint_id, 2]] || 0, + bug_hour: @issues_hour_pm_type_count[[sprint_id, 3]] || 0 + } end render_ok(data: data) From 191153a39e666104ea1ddc2b23312919b3240a8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 23 Jan 2024 17:08:06 +0800 Subject: [PATCH 125/294] add burndown_charts --- .../api/pm/sprint_issues_controller.rb | 20 +++++ app/models/attachment.rb | 84 ++++++++++--------- app/models/journal.rb | 1 + config/routes/api.rb | 1 + 4 files changed, 65 insertions(+), 41 deletions(-) diff --git a/app/controllers/api/pm/sprint_issues_controller.rb b/app/controllers/api/pm/sprint_issues_controller.rb index e443fcc0c..9ee62d62c 100644 --- a/app/controllers/api/pm/sprint_issues_controller.rb +++ b/app/controllers/api/pm/sprint_issues_controller.rb @@ -8,6 +8,26 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController render 'api/v1/issues/index' end + def burndown_charts + return tip_exception '参数错误' if params[:pm_sprint_id].blank? || params[:start_time].blank? || params[:end_time].blank? + @issues = Issue.where(pm_sprint_id: params[:pm_sprint_id]) + start_time = Date.parse params[:start_time] + end_time = Date.parse params[:end_time] + x = (end_time - start_time).to_i + 1 #计算间隔时间 加上最后一天 + data = {} + curren_issues = @issues.group(:status_id,:due_date).count + x.times do |time| + e_time = start_time + time + undone = curren_issues[[1,nil]].to_i + curren_issues[[1,e_time]].to_i + curren_issues[[2,e_time]].to_i + curren_issues[[3,e_time]].to_i + completed = curren_issues[[4,e_time]].to_i + curren_issues[[5,e_time]].to_i + data[e_time] = { + undone: undone, + completed:completed + } + end + render_ok(data: data) + end + def statistics pm_sprint_ids = params[:pm_sprint_ids].split(",") rescue [] return tip_exception '参数错误' if pm_sprint_ids.blank? diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 810474609..70e1cd03a 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -1,44 +1,46 @@ -# == Schema Information -# -# Table name: attachments -# -# id :integer not null, primary key -# container_id :integer -# container_type :string(30) -# filename :string(255) default(""), not null -# disk_filename :string(255) default(""), not null -# filesize :integer default("0"), not null -# content_type :string(255) default("") -# digest :string(60) default(""), not null -# downloads :integer default("0"), not null -# author_id :integer default("0"), not null -# created_on :datetime -# description :text(65535) -# disk_directory :string(255) -# attachtype :integer default("1") -# is_public :integer default("1") -# copy_from :integer -# quotes :integer default("0") -# is_publish :integer default("1") -# publish_time :datetime -# resource_bank_id :integer -# unified_setting :boolean default("1") -# cloud_url :string(255) default("") -# course_second_category_id :integer default("0") -# delay_publish :boolean default("0") -# memo_image :boolean default("0") -# extra_type :integer default("0") -# uuid :string(255) -# -# Indexes -# -# index_attachments_on_author_id (author_id) -# index_attachments_on_container_id_and_container_type (container_id,container_type) -# index_attachments_on_course_second_category_id (course_second_category_id) -# index_attachments_on_created_on (created_on) -# index_attachments_on_is_public (is_public) -# index_attachments_on_quotes (quotes) -# +# == Schema Information +# +# Table name: attachments +# +# id :integer not null, primary key +# container_id :integer +# container_type :string(30) +# filename :string(255) default(""), not null +# disk_filename :string(255) default(""), not null +# filesize :integer default("0"), not null +# content_type :string(255) default("") +# digest :string(60) default(""), not null +# downloads :integer default("0"), not null +# author_id :integer default("0"), not null +# created_on :datetime +# description :text(65535) +# disk_directory :string(255) +# attachtype :integer default("1") +# is_public :integer default("1") +# copy_from :integer +# quotes :integer default("0") +# is_publish :integer default("1") +# publish_time :datetime +# resource_bank_id :integer +# unified_setting :boolean default("1") +# cloud_url :string(255) default("") +# course_second_category_id :integer default("0") +# delay_publish :boolean default("0") +# memo_image :boolean default("0") +# extra_type :integer default("0") +# uuid :string(255) +# +# Indexes +# +# index_attachments_on_author_id (author_id) +# index_attachments_on_container_id_and_container_type (container_id,container_type) +# index_attachments_on_course_second_category_id (course_second_category_id) +# index_attachments_on_created_on (created_on) +# index_attachments_on_is_public (is_public) +# index_attachments_on_quotes (quotes) +# index_attachments_on_uuid (uuid) +# + diff --git a/app/models/journal.rb b/app/models/journal.rb index 2e754c51a..0fdca0f9d 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -27,6 +27,7 @@ # # index_journals_on_created_on (created_on) # index_journals_on_journalized_id (journalized_id) +# index_journals_on_parent_id (parent_id) # index_journals_on_review_id (review_id) # index_journals_on_user_id (user_id) # journals_journalized_id (journalized_id,journalized_type) diff --git a/config/routes/api.rb b/config/routes/api.rb index 50c6a9538..9ee877c2c 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -25,6 +25,7 @@ defaults format: :json do resources :sprint_issues, only: [:index] do collection do get :statistics + get :burndown_charts post :complete end end From f85f9fe4f4da6f7443a647f0fdf0124c22e5ae73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 23 Jan 2024 17:22:58 +0800 Subject: [PATCH 126/294] update burndown_charts response --- app/controllers/api/pm/sprint_issues_controller.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/pm/sprint_issues_controller.rb b/app/controllers/api/pm/sprint_issues_controller.rb index 9ee62d62c..0a6f7e48f 100644 --- a/app/controllers/api/pm/sprint_issues_controller.rb +++ b/app/controllers/api/pm/sprint_issues_controller.rb @@ -14,16 +14,13 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController start_time = Date.parse params[:start_time] end_time = Date.parse params[:end_time] x = (end_time - start_time).to_i + 1 #计算间隔时间 加上最后一天 - data = {} + data = [] curren_issues = @issues.group(:status_id,:due_date).count x.times do |time| e_time = start_time + time undone = curren_issues[[1,nil]].to_i + curren_issues[[1,e_time]].to_i + curren_issues[[2,e_time]].to_i + curren_issues[[3,e_time]].to_i completed = curren_issues[[4,e_time]].to_i + curren_issues[[5,e_time]].to_i - data[e_time] = { - undone: undone, - completed:completed - } + data << {time: e_time, undone: undone, completed:completed} end render_ok(data: data) end From dbdebc6232492ce45d8b3e61ae36c25ca07b2c09 Mon Sep 17 00:00:00 2001 From: kingchan Date: Wed, 24 Jan 2024 16:55:10 +0800 Subject: [PATCH 127/294] update --- app/controllers/api/pm/sprint_issues_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/pm/sprint_issues_controller.rb b/app/controllers/api/pm/sprint_issues_controller.rb index 0a6f7e48f..14e26c76a 100644 --- a/app/controllers/api/pm/sprint_issues_controller.rb +++ b/app/controllers/api/pm/sprint_issues_controller.rb @@ -14,13 +14,14 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController start_time = Date.parse params[:start_time] end_time = Date.parse params[:end_time] x = (end_time - start_time).to_i + 1 #计算间隔时间 加上最后一天 + base_number = (@issues.count / x).to_f data = [] curren_issues = @issues.group(:status_id,:due_date).count x.times do |time| e_time = start_time + time undone = curren_issues[[1,nil]].to_i + curren_issues[[1,e_time]].to_i + curren_issues[[2,e_time]].to_i + curren_issues[[3,e_time]].to_i completed = curren_issues[[4,e_time]].to_i + curren_issues[[5,e_time]].to_i - data << {time: e_time, undone: undone, completed:completed} + data << {time: e_time, undone: undone, completed:completed, base_number: (base_number * (x - time))} end render_ok(data: data) end From 27b81a5479091d64b1dc97d5129a151895003481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 25 Jan 2024 09:01:35 +0800 Subject: [PATCH 128/294] update burndown_charts --- .../api/pm/sprint_issues_controller.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/pm/sprint_issues_controller.rb b/app/controllers/api/pm/sprint_issues_controller.rb index 14e26c76a..dc3ce1d5b 100644 --- a/app/controllers/api/pm/sprint_issues_controller.rb +++ b/app/controllers/api/pm/sprint_issues_controller.rb @@ -13,15 +13,16 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController @issues = Issue.where(pm_sprint_id: params[:pm_sprint_id]) start_time = Date.parse params[:start_time] end_time = Date.parse params[:end_time] - x = (end_time - start_time).to_i + 1 #计算间隔时间 加上最后一天 - base_number = (@issues.count / x).to_f + time_count = (end_time - start_time).to_i + 1 #计算间隔时间 加上最后一天 data = [] curren_issues = @issues.group(:status_id,:due_date).count - x.times do |time| - e_time = start_time + time - undone = curren_issues[[1,nil]].to_i + curren_issues[[1,e_time]].to_i + curren_issues[[2,e_time]].to_i + curren_issues[[3,e_time]].to_i - completed = curren_issues[[4,e_time]].to_i + curren_issues[[5,e_time]].to_i - data << {time: e_time, undone: undone, completed:completed, base_number: (base_number * (x - time))} + total_count = @issues.count + cardinality = (total_count / time_count).to_f + time_count.times do |x| + e_time = start_time + x + completed = curren_issues[[5,e_time]].to_i + curren_issues[[3, e_time]].to_i - @issues.where(pm_issue_type: 3, status_id: 3).size + total_count = total_count - completed + data << {time: e_time, undone: total_count, completed:completed, base_number: (cardinality * (time_count - x))} end render_ok(data: data) end From 406da81ccf908ae8766f217200a36223faef216a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 25 Jan 2024 14:04:36 +0800 Subject: [PATCH 129/294] add project statistics and project polyline --- .../api/pm/sprint_issues_controller.rb | 54 +++++++++++++++++++ config/routes/api.rb | 2 + 2 files changed, 56 insertions(+) diff --git a/app/controllers/api/pm/sprint_issues_controller.rb b/app/controllers/api/pm/sprint_issues_controller.rb index dc3ce1d5b..7e6de65b8 100644 --- a/app/controllers/api/pm/sprint_issues_controller.rb +++ b/app/controllers/api/pm/sprint_issues_controller.rb @@ -8,6 +8,60 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController render 'api/v1/issues/index' end + + def project_statistics + return tip_exception '参数错误' if params[:pm_project_id].blank? + @issues = Issue.where(pm_project_id: params[:pm_project_id]) + type_count_data = @issues.group(:pm_issue_type).count + type_status = @issues.group(:pm_issue_type,:status_id).count + type_status_data = {} + IssueStatus.all.map do |e| + type_count_data.keys.map{ |type| + type_status_data[type] = {} if type_status_data[type].nil? + if type_status[[type,e.id]].nil? + type_status_data[type][e.id] = 0 + else + type_status_data[type][e.id] = type_status[[type,e.id]] + end + } + end + data = { + pie_chart: type_count_data, + bar_chart: type_status_data + } + render_ok(data: data) + end + + def project_polyline + return tip_exception '参数错误' if params[:pm_project_id].blank? + time_line = (Time.current.beginning_of_day - 6.day) .. Time.current + # @create_issues = Issue.where(pm_project_id: params[:pm_project_id],created_on: time_line) + # @due_issues = Issue.where(pm_project_id: params[:pm_project_id],due_date: time_line) + @create_issues = Issue.where(pm_project_id: 135,created_on: time_line) + @due_issues = Issue.where(pm_project_id: 135,due_date: time_line) + @create_issues_count = @create_issues.group(:pm_issue_type,"DATE(created_on)").count + @due_issues_count = @due_issues.group(:pm_issue_type,"DATE(due_date)").count + data = { + create_issues: {}, + due_issues: {} + } + 7.times do |time| + current_time = Date.current - time.day + data[:create_issues][current_time] = { + "1": @create_issues_count[[1,current_time]] || 0, + "2": @create_issues_count[[2,current_time]] || 0, + "3": @create_issues_count[[3,current_time]] || 0 + } + + data[:due_issues][current_time] = { + "1": @due_issues_count[[1,current_time]] || 0, + "2": @due_issues_count[[2,current_time]] || 0, + "3": @due_issues_count[[3,current_time]] || 0 + } + end + render_ok(data: data) + end + def burndown_charts return tip_exception '参数错误' if params[:pm_sprint_id].blank? || params[:start_time].blank? || params[:end_time].blank? @issues = Issue.where(pm_sprint_id: params[:pm_sprint_id]) diff --git a/config/routes/api.rb b/config/routes/api.rb index 9ee877c2c..dae30ce26 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -25,6 +25,8 @@ defaults format: :json do resources :sprint_issues, only: [:index] do collection do get :statistics + get :project_statistics + get :project_polyline get :burndown_charts post :complete end From 0d250e0d4e6b13ba4fa07a1d77996896c5bb91b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 25 Jan 2024 14:28:00 +0800 Subject: [PATCH 130/294] update routes --- app/controllers/api/pm/projects_controller.rb | 54 +++++++++++++++++++ .../api/pm/sprint_issues_controller.rb | 52 ------------------ config/routes/api.rb | 5 +- 3 files changed, 57 insertions(+), 54 deletions(-) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index b66878367..83e2ecdb4 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -28,6 +28,60 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController render_ok(data: data) end + + def statistics + return tip_exception '参数错误' if params[:pm_project_id].blank? + @issues = Issue.where(pm_project_id: params[:pm_project_id]) + type_count_data = @issues.group(:pm_issue_type).count + type_status = @issues.group(:pm_issue_type,:status_id).count + type_status_data = {} + IssueStatus.all.map do |e| + type_count_data.keys.map{ |type| + type_status_data[type] = {} if type_status_data[type].nil? + if type_status[[type,e.id]].nil? + type_status_data[type][e.id] = 0 + else + type_status_data[type][e.id] = type_status[[type,e.id]] + end + } + end + data = { + pie_chart: type_count_data, + bar_chart: type_status_data + } + render_ok(data: data) + end + + def polyline + return tip_exception '参数错误' if params[:pm_project_id].blank? + time_line = (Time.current.beginning_of_day - 6.day) .. Time.current + # @create_issues = Issue.where(pm_project_id: params[:pm_project_id],created_on: time_line) + # @due_issues = Issue.where(pm_project_id: params[:pm_project_id],due_date: time_line) + @create_issues = Issue.where(pm_project_id: 135,created_on: time_line) + @due_issues = Issue.where(pm_project_id: 135,due_date: time_line) + @create_issues_count = @create_issues.group(:pm_issue_type,"DATE(created_on)").count + @due_issues_count = @due_issues.group(:pm_issue_type,"DATE(due_date)").count + data = { + create_issues: {}, + due_issues: {} + } + 7.times do |time| + current_time = Date.current - time.day + data[:create_issues][current_time] = { + "1": @create_issues_count[[1,current_time]] || 0, + "2": @create_issues_count[[2,current_time]] || 0, + "3": @create_issues_count[[3,current_time]] || 0 + } + + data[:due_issues][current_time] = { + "1": @due_issues_count[[1,current_time]] || 0, + "2": @due_issues_count[[2,current_time]] || 0, + "3": @due_issues_count[[3,current_time]] || 0 + } + end + render_ok(data: data) + end + def bind_project return render_forbidden('您没有操作权限!') unless @project.member?(current_user) || current_user.admin? Issue.where(pm_project_id: params[:pm_project_id], user_id: current_user).update_all(project_id: params[:project_id]) diff --git a/app/controllers/api/pm/sprint_issues_controller.rb b/app/controllers/api/pm/sprint_issues_controller.rb index 7e6de65b8..9ef5f911e 100644 --- a/app/controllers/api/pm/sprint_issues_controller.rb +++ b/app/controllers/api/pm/sprint_issues_controller.rb @@ -9,58 +9,6 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController end - def project_statistics - return tip_exception '参数错误' if params[:pm_project_id].blank? - @issues = Issue.where(pm_project_id: params[:pm_project_id]) - type_count_data = @issues.group(:pm_issue_type).count - type_status = @issues.group(:pm_issue_type,:status_id).count - type_status_data = {} - IssueStatus.all.map do |e| - type_count_data.keys.map{ |type| - type_status_data[type] = {} if type_status_data[type].nil? - if type_status[[type,e.id]].nil? - type_status_data[type][e.id] = 0 - else - type_status_data[type][e.id] = type_status[[type,e.id]] - end - } - end - data = { - pie_chart: type_count_data, - bar_chart: type_status_data - } - render_ok(data: data) - end - - def project_polyline - return tip_exception '参数错误' if params[:pm_project_id].blank? - time_line = (Time.current.beginning_of_day - 6.day) .. Time.current - # @create_issues = Issue.where(pm_project_id: params[:pm_project_id],created_on: time_line) - # @due_issues = Issue.where(pm_project_id: params[:pm_project_id],due_date: time_line) - @create_issues = Issue.where(pm_project_id: 135,created_on: time_line) - @due_issues = Issue.where(pm_project_id: 135,due_date: time_line) - @create_issues_count = @create_issues.group(:pm_issue_type,"DATE(created_on)").count - @due_issues_count = @due_issues.group(:pm_issue_type,"DATE(due_date)").count - data = { - create_issues: {}, - due_issues: {} - } - 7.times do |time| - current_time = Date.current - time.day - data[:create_issues][current_time] = { - "1": @create_issues_count[[1,current_time]] || 0, - "2": @create_issues_count[[2,current_time]] || 0, - "3": @create_issues_count[[3,current_time]] || 0 - } - - data[:due_issues][current_time] = { - "1": @due_issues_count[[1,current_time]] || 0, - "2": @due_issues_count[[2,current_time]] || 0, - "3": @due_issues_count[[3,current_time]] || 0 - } - end - render_ok(data: data) - end def burndown_charts return tip_exception '参数错误' if params[:pm_sprint_id].blank? || params[:start_time].blank? || params[:end_time].blank? diff --git a/config/routes/api.rb b/config/routes/api.rb index dae30ce26..c5d8e8c8c 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -25,8 +25,7 @@ defaults format: :json do resources :sprint_issues, only: [:index] do collection do get :statistics - get :project_statistics - get :project_polyline + get :burndown_charts post :complete end @@ -35,6 +34,8 @@ defaults format: :json do collection do get :convert get :issues_count + get :statistics + get :polyline end end end From 3986b86852d1d3d4191d7de801376529dddfb3a1 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 25 Jan 2024 15:44:55 +0800 Subject: [PATCH 131/294] =?UTF-8?q?pm=E4=B8=AD=E5=A4=9A=E9=A1=B9=E7=9B=AEi?= =?UTF-8?q?d=E6=9F=A5=E8=AF=A2issue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/issues/list_service.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index cfe9a3ce7..0878fb908 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -4,7 +4,7 @@ class Api::V1::Issues::ListService < ApplicationService attr_reader :project, :only_name, :category, :participant_category, :keyword, :author_id, :issue_tag_ids attr_reader :begin_date, :end_date attr_reader :milestone_id, :assigner_id, :status_id, :priority_id, :sort_by, :sort_direction, :current_user - attr_reader :pm_project_id, :pm_sprint_id, :root_id, :pm_issue_type, :status_ids, :ids, :exclude_ids, :pm_issue_types + attr_reader :pm_project_id, :pm_project_ids, :pm_sprint_id, :root_id, :pm_issue_type, :status_ids, :ids, :exclude_ids, :pm_issue_types attr_accessor :queried_issues, :total_issues_count, :closed_issues_count, :opened_issues_count, :complete_issues_count validates :category, inclusion: { in: %w[all opened closed], message: '请输入正确的Category'} @@ -29,6 +29,7 @@ class Api::V1::Issues::ListService < ApplicationService @end_date = params[:end_date] @sort_by = params[:sort_by].present? ? params[:sort_by] : 'issues.updated_on' @pm_project_id = params[:pm_project_id] + @pm_project_ids = params[:pm_project_ids] @pm_sprint_id = params[:pm_sprint_id] @root_id = params[:root_id] @pm_issue_type = params[:pm_issue_type] @@ -95,6 +96,7 @@ class Api::V1::Issues::ListService < ApplicationService # pm_project_id issues = issues.where(pm_project_id: pm_project_id) if pm_project_id.present? + issues = issues.where(pm_project_id: pm_project_ids.to_s.split(",")) if pm_project_ids.present? # pm_sprint_id issues = issues.where(pm_sprint_id: pm_sprint_id) if pm_sprint_id.present? From 088bb3d1ac137eee99d116350a30a0abf6612bfc Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 25 Jan 2024 15:49:03 +0800 Subject: [PATCH 132/294] =?UTF-8?q?pm=E4=B8=AD=E5=A4=9A=E9=A1=B9=E7=9B=AEi?= =?UTF-8?q?d=E6=9F=A5=E8=AF=A2issue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 6cd37ce18..307897d05 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -160,7 +160,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController :status_id, :priority_id, :begin_date, :end_date, :sort_by, :sort_direction, :root_id, - :issue_tag_ids, :pm_project_id, :pm_sprint_id, :pm_issue_type, + :issue_tag_ids, :pm_project_id, :pm_sprint_id, :pm_issue_type, :pm_project_ids, :status_ids, :ids, :exclude_ids, :pm_issue_types ) end From 45e8b4d83295df8ab0d005b95f44fe5a3810f0fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 25 Jan 2024 17:10:43 +0800 Subject: [PATCH 133/294] update burndown_charts base_number --- app/controllers/api/pm/sprint_issues_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/pm/sprint_issues_controller.rb b/app/controllers/api/pm/sprint_issues_controller.rb index 9ef5f911e..0e5180327 100644 --- a/app/controllers/api/pm/sprint_issues_controller.rb +++ b/app/controllers/api/pm/sprint_issues_controller.rb @@ -19,12 +19,12 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController data = [] curren_issues = @issues.group(:status_id,:due_date).count total_count = @issues.count - cardinality = (total_count / time_count).to_f + cardinality = BigDecimal.new(total_count) / BigDecimal.new(time_count) time_count.times do |x| e_time = start_time + x completed = curren_issues[[5,e_time]].to_i + curren_issues[[3, e_time]].to_i - @issues.where(pm_issue_type: 3, status_id: 3).size total_count = total_count - completed - data << {time: e_time, undone: total_count, completed:completed, base_number: (cardinality * (time_count - x))} + data << {time: e_time, undone: total_count, completed:completed, base_number: (cardinality * (time_count - x)).to_f.round(2)} end render_ok(data: data) end From efef195c27787c1d5d1e9aab24d43ac4ee143a12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 25 Jan 2024 17:13:57 +0800 Subject: [PATCH 134/294] update burndown_charts base_number -1 --- app/controllers/api/pm/sprint_issues_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/pm/sprint_issues_controller.rb b/app/controllers/api/pm/sprint_issues_controller.rb index 0e5180327..e0d4c50e6 100644 --- a/app/controllers/api/pm/sprint_issues_controller.rb +++ b/app/controllers/api/pm/sprint_issues_controller.rb @@ -24,7 +24,7 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController e_time = start_time + x completed = curren_issues[[5,e_time]].to_i + curren_issues[[3, e_time]].to_i - @issues.where(pm_issue_type: 3, status_id: 3).size total_count = total_count - completed - data << {time: e_time, undone: total_count, completed:completed, base_number: (cardinality * (time_count - x)).to_f.round(2)} + data << {time: e_time, undone: total_count, completed:completed, base_number: (cardinality * (time_count - x - 1)).to_f.round(2)} end render_ok(data: data) end From 28de064841ad1dc09994a63dc863655655c13e0c Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 26 Jan 2024 15:38:32 +0800 Subject: [PATCH 135/294] =?UTF-8?q?issues=5Fcount=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=88=91=E8=B4=9F=E8=B4=A3=E7=9A=84=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/projects_controller.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index 83e2ecdb4..1ce72b584 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -13,6 +13,16 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController def issues_count return tip_exception '参数错误' unless params[:pm_project_id].present? @issues = Issue.where(pm_project_id: params[:pm_project_id]) + case params[:participant_category].to_s + 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 data = {} @issues_count = @issues.group(:pm_project_id).count # requirement 1 task 2 bug 3 From 3505d29410f54b6423cb68c51030f956cd9ea0fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 30 Jan 2024 10:56:46 +0800 Subject: [PATCH 136/294] fix --- app/controllers/api/pm/projects_controller.rb | 31 ++++++++-------- .../api/pm/sprint_issues_controller.rb | 37 ++++++++++--------- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index 83e2ecdb4..e80d3a692 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -55,10 +55,8 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController def polyline return tip_exception '参数错误' if params[:pm_project_id].blank? time_line = (Time.current.beginning_of_day - 6.day) .. Time.current - # @create_issues = Issue.where(pm_project_id: params[:pm_project_id],created_on: time_line) - # @due_issues = Issue.where(pm_project_id: params[:pm_project_id],due_date: time_line) - @create_issues = Issue.where(pm_project_id: 135,created_on: time_line) - @due_issues = Issue.where(pm_project_id: 135,due_date: time_line) + @create_issues = Issue.where(pm_project_id: params[:pm_project_id],created_on: time_line) + @due_issues = Issue.where(pm_project_id: params[:pm_project_id],due_date: time_line) @create_issues_count = @create_issues.group(:pm_issue_type,"DATE(created_on)").count @due_issues_count = @due_issues.group(:pm_issue_type,"DATE(due_date)").count data = { @@ -67,17 +65,20 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController } 7.times do |time| current_time = Date.current - time.day - data[:create_issues][current_time] = { - "1": @create_issues_count[[1,current_time]] || 0, - "2": @create_issues_count[[2,current_time]] || 0, - "3": @create_issues_count[[3,current_time]] || 0 - } - - data[:due_issues][current_time] = { - "1": @due_issues_count[[1,current_time]] || 0, - "2": @due_issues_count[[2,current_time]] || 0, - "3": @due_issues_count[[3,current_time]] || 0 - } + if @create_issues_count.present? + data[:create_issues][current_time] = { + "1": @create_issues_count[[1,current_time]] || 0, + "2": @create_issues_count[[2,current_time]] || 0, + "3": @create_issues_count[[3,current_time]] || 0 + } + end + if @due_issues_count.present? + data[:due_issues][current_time] = { + "1": @due_issues_count[[1,current_time]] || 0, + "2": @due_issues_count[[2,current_time]] || 0, + "3": @due_issues_count[[3,current_time]] || 0 + } + end end render_ok(data: data) end diff --git a/app/controllers/api/pm/sprint_issues_controller.rb b/app/controllers/api/pm/sprint_issues_controller.rb index e0d4c50e6..fa66d53de 100644 --- a/app/controllers/api/pm/sprint_issues_controller.rb +++ b/app/controllers/api/pm/sprint_issues_controller.rb @@ -2,29 +2,27 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController before_action :require_login, except: [:index] - def index + def index @issues = Api::Pm::SprintIssues::ListService.call(query_params, current_user) @issues = kaminari_paginate(@issues) render 'api/v1/issues/index' end - - def burndown_charts - return tip_exception '参数错误' if params[:pm_sprint_id].blank? || params[:start_time].blank? || params[:end_time].blank? + return tip_exception '参数错误' if params[:pm_sprint_id].blank? || params[:start_time].blank? || params[:end_time].blank? @issues = Issue.where(pm_sprint_id: params[:pm_sprint_id]) start_time = Date.parse params[:start_time] end_time = Date.parse params[:end_time] - time_count = (end_time - start_time).to_i + 1 #计算间隔时间 加上最后一天 + time_count = (end_time - start_time).to_i + 1 # 计算间隔时间 加上最后一天 data = [] - curren_issues = @issues.group(:status_id,:due_date).count + curren_issues = @issues.group(:status_id, :due_date).count total_count = @issues.count cardinality = BigDecimal.new(total_count) / BigDecimal.new(time_count) time_count.times do |x| e_time = start_time + x - completed = curren_issues[[5,e_time]].to_i + curren_issues[[3, e_time]].to_i - @issues.where(pm_issue_type: 3, status_id: 3).size + completed = curren_issues[[5, e_time]].to_i + curren_issues[[3, e_time]].to_i - @issues.where(pm_issue_type: 3, status_id: 3).size total_count = total_count - completed - data << {time: e_time, undone: total_count, completed:completed, base_number: (cardinality * (time_count - x - 1)).to_f.round(2)} + data << { time: e_time, undone: total_count, completed: completed, base_number: (cardinality * (time_count - x - 1)).to_f.round(2) } end render_ok(data: data) end @@ -41,11 +39,12 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController @issues_hour_count = @issues.group(:pm_sprint_id).sum(:time_scale) @issues_hour_type_count = @issues.group(:pm_sprint_id, :status_id).sum(:time_scale) @issues_hour_pm_type_count = @issues.group(:pm_sprint_id, :pm_issue_type).sum(:time_scale) + @issues_status_pm_type_count = @issues.group(:pm_sprint_id, :pm_issue_type, :status_id).sum(:time_scale) pm_sprint_ids.map(&:to_i).map do |sprint_id| # count_closed 工作项已完成/已关闭数量,需排除已修复的缺陷数量 count_closed = @issues_type_count[[sprint_id, 5]].to_i + @issues_type_count[[sprint_id, 3]].to_i - @issues.where(pm_sprint_id: sprint_id, pm_issue_type: 3, status_id: 3).size # hour_closed 已完成/已关闭 预估工时之和,需排除已修复的缺陷预估工时 - hour_closed = @issues_hour_type_count[[sprint_id, 5]].to_f + @issues_hour_type_count[[sprint_id, 3]].to_f - @issues.where(pm_sprint_id: sprint_id, pm_issue_type: 3, status_id: 3).sum(:time_scale).to_f + hour_closed = @issues_hour_type_count[[sprint_id, 5]].to_f + @issues_hour_type_count[[sprint_id, 3]].to_f - @issues.where(pm_sprint_id: sprint_id, pm_issue_type: 3, status_id: 3).sum(:time_scale).to_f data[sprint_id] = { count_total: @issues_count[sprint_id] || 0, count_closed: count_closed || 0, @@ -56,8 +55,10 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController bug: @issues_pm_type_count[[sprint_id, 3]] || 0, requirement_hour: @issues_hour_pm_type_count[[sprint_id, 1]] || 0, task_hour: @issues_hour_pm_type_count[[sprint_id, 2]] || 0, - bug_hour: @issues_hour_pm_type_count[[sprint_id, 3]] || 0 - + bug_hour: @issues_hour_pm_type_count[[sprint_id, 3]] || 0, + requirement_open: (@issues_status_pm_type_count[[sprint_id, 1, 1]] + @issues_status_pm_type_count[[sprint_id, 1, 2]]) || 0, + task_open: @issues_status_pm_type_count[[sprint_id, 2, 1]] + @issues_status_pm_type_count[[sprint_id, 2, 2]] || 0, + bug_open: @issues_status_pm_type_count[[sprint_id, 3, 1]] + @issues_status_pm_type_count[[sprint_id, 3, 2]] || 0 } end render_ok(data: data) @@ -65,10 +66,10 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController before_action :load_uncomplete_issues, only: [:complete] - def complete + def complete begin - case complete_params[:complete_type].to_i - when 1 + case complete_params[:complete_type].to_i + when 1 @issues.update_all(status_id: 5) when 2 @issues.update_all(pm_sprint_id: 0) @@ -87,16 +88,16 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController @issues = Issue.where(pm_sprint_id: complete_params[:pm_project_sprint_id]).where.not(status_id: 5) end - def complete_params + def complete_params params.permit(:pm_project_sprint_id, :complete_type, :target_pm_project_sprint_id) end - + def query_params params.permit( :category, :pm_project_id, - :pm_issue_type, #需求1 任务2 缺陷3 - :assigner_id, + :pm_issue_type, # 需求1 任务2 缺陷3 + :assigner_id, :priority_id, :status_id, :keyword, :status_ids, :pm_issue_types, From 3094c81d2cec0ea13618d5a56cf2a60848dcc793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 30 Jan 2024 11:07:01 +0800 Subject: [PATCH 137/294] fix bug --- app/controllers/api/pm/sprint_issues_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/pm/sprint_issues_controller.rb b/app/controllers/api/pm/sprint_issues_controller.rb index fa66d53de..436327c80 100644 --- a/app/controllers/api/pm/sprint_issues_controller.rb +++ b/app/controllers/api/pm/sprint_issues_controller.rb @@ -56,9 +56,9 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController requirement_hour: @issues_hour_pm_type_count[[sprint_id, 1]] || 0, task_hour: @issues_hour_pm_type_count[[sprint_id, 2]] || 0, bug_hour: @issues_hour_pm_type_count[[sprint_id, 3]] || 0, - requirement_open: (@issues_status_pm_type_count[[sprint_id, 1, 1]] + @issues_status_pm_type_count[[sprint_id, 1, 2]]) || 0, - task_open: @issues_status_pm_type_count[[sprint_id, 2, 1]] + @issues_status_pm_type_count[[sprint_id, 2, 2]] || 0, - bug_open: @issues_status_pm_type_count[[sprint_id, 3, 1]] + @issues_status_pm_type_count[[sprint_id, 3, 2]] || 0 + requirement_open: (@issues_status_pm_type_count[[sprint_id, 1, 1]].to_i + @issues_status_pm_type_count[[sprint_id, 1, 2]].to_i) || 0, + task_open: @issues_status_pm_type_count[[sprint_id, 2, 1]].to_i + @issues_status_pm_type_count[[sprint_id, 2, 2]].to_i || 0, + bug_open: @issues_status_pm_type_count[[sprint_id, 3, 1]].to_i + @issues_status_pm_type_count[[sprint_id, 3, 2]].to_i || 0 } end render_ok(data: data) From f39b83692bfb6ec20cc8b0b65f1b4c30d490a781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 30 Jan 2024 11:16:06 +0800 Subject: [PATCH 138/294] update --- app/controllers/api/pm/sprint_issues_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/pm/sprint_issues_controller.rb b/app/controllers/api/pm/sprint_issues_controller.rb index 436327c80..0d3c7f31b 100644 --- a/app/controllers/api/pm/sprint_issues_controller.rb +++ b/app/controllers/api/pm/sprint_issues_controller.rb @@ -39,7 +39,7 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController @issues_hour_count = @issues.group(:pm_sprint_id).sum(:time_scale) @issues_hour_type_count = @issues.group(:pm_sprint_id, :status_id).sum(:time_scale) @issues_hour_pm_type_count = @issues.group(:pm_sprint_id, :pm_issue_type).sum(:time_scale) - @issues_status_pm_type_count = @issues.group(:pm_sprint_id, :pm_issue_type, :status_id).sum(:time_scale) + @issues_status_pm_type_count = @issues.group(:pm_sprint_id, :pm_issue_type, :status_id).count pm_sprint_ids.map(&:to_i).map do |sprint_id| # count_closed 工作项已完成/已关闭数量,需排除已修复的缺陷数量 count_closed = @issues_type_count[[sprint_id, 5]].to_i + @issues_type_count[[sprint_id, 3]].to_i - @issues.where(pm_sprint_id: sprint_id, pm_issue_type: 3, status_id: 3).size From 53083d30305f92dd1d737024832f0f7a8e1eb836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 30 Jan 2024 11:40:56 +0800 Subject: [PATCH 139/294] add open data for pm project statistics --- app/controllers/api/pm/projects_controller.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index e80d3a692..d71a945ea 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -45,9 +45,15 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController end } end + open_data = { + "1": type_status_data[1][1] + type_status_data[1][2], + "2": type_status_data[2][1] + type_status_data[2][2], + "3": type_status_data[3][1] + type_status_data[3][2], + } data = { pie_chart: type_count_data, - bar_chart: type_status_data + bar_chart: type_status_data, + open_data: open_data } render_ok(data: data) end From 7d8e0d018e05e417debbde973f6dfd9f2970fd86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 30 Jan 2024 14:03:34 +0800 Subject: [PATCH 140/294] add default for project polyline --- app/controllers/api/pm/projects_controller.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index d71a945ea..89732e79e 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -77,6 +77,12 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController "2": @create_issues_count[[2,current_time]] || 0, "3": @create_issues_count[[3,current_time]] || 0 } + else + data[:create_issues][current_time] = { + "1": 0, + "2": 0, + "3": 0 + } end if @due_issues_count.present? data[:due_issues][current_time] = { @@ -84,6 +90,12 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController "2": @due_issues_count[[2,current_time]] || 0, "3": @due_issues_count[[3,current_time]] || 0 } + else + data[:due_issues][current_time] = { + "1": 0, + "2": 0, + "3": 0 + } end end render_ok(data: data) From 95387671678cebc94fd82c13350eac0eb6427215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 30 Jan 2024 14:20:16 +0800 Subject: [PATCH 141/294] update pm project statistics --- app/controllers/api/pm/projects_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index 89732e79e..f2e31bbbe 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -46,9 +46,9 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController } end open_data = { - "1": type_status_data[1][1] + type_status_data[1][2], - "2": type_status_data[2][1] + type_status_data[2][2], - "3": type_status_data[3][1] + type_status_data[3][2], + "1": type_status_data[1][1].to_i + type_status_data[1][2].to_i, + "2": type_status_data[2][1].to_i + type_status_data[2][2].to_i, + "3": type_status_data[3][1].to_i + type_status_data[3][2].to_i, } data = { pie_chart: type_count_data, From a5a22f6889b04f4c3680a39ea45525775e04b178 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 30 Jan 2024 14:29:37 +0800 Subject: [PATCH 142/294] add default pm project statistics --- app/controllers/api/pm/projects_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index f2e31bbbe..d1dd3ac8f 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -36,7 +36,7 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController type_status = @issues.group(:pm_issue_type,:status_id).count type_status_data = {} IssueStatus.all.map do |e| - type_count_data.keys.map{ |type| + [1,2,3].map{ |type| type_status_data[type] = {} if type_status_data[type].nil? if type_status[[type,e.id]].nil? type_status_data[type][e.id] = 0 From b456bf99ca1c6e3032f8bba5835f5b751e1d06fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 30 Jan 2024 17:10:32 +0800 Subject: [PATCH 143/294] update plyline --- app/controllers/api/pm/projects_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index d1dd3ac8f..3dfd2e9c0 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -62,7 +62,8 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController return tip_exception '参数错误' if params[:pm_project_id].blank? time_line = (Time.current.beginning_of_day - 6.day) .. Time.current @create_issues = Issue.where(pm_project_id: params[:pm_project_id],created_on: time_line) - @due_issues = Issue.where(pm_project_id: params[:pm_project_id],due_date: time_line) + @create_issues = Issue.where(pm_project_id: 179,created_on: time_line) + @due_issues = Issue.where(pm_project_id: params[:pm_project_id],status_id:[3,5],due_date: time_line) @create_issues_count = @create_issues.group(:pm_issue_type,"DATE(created_on)").count @due_issues_count = @due_issues.group(:pm_issue_type,"DATE(due_date)").count data = { From 9b9374c99bb1ba1cc0ac8dce83a975e7ccb4fbb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 31 Jan 2024 08:43:10 +0800 Subject: [PATCH 144/294] add due_date to pm issue batch params --- app/controllers/api/pm/issues_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 6cd37ce18..06ada1e9a 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -182,7 +182,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController def batch_issue_params params.permit( - :status_id, :priority_id, :milestone_id, :pm_sprint_id, :pm_issue_type, :root_id, :target_pm_project_id, :project_id, + :status_id, :priority_id, :milestone_id, :pm_sprint_id, :due_date, :pm_issue_type, :root_id, :target_pm_project_id, :project_id, :issue_tag_ids => [], :assigner_ids => [] ) end From 65d23879313dc9311c9826d34258d1b204cd33e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 31 Jan 2024 09:08:38 +0800 Subject: [PATCH 145/294] update --- app/models/issue.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/models/issue.rb b/app/models/issue.rb index b40efefa1..2c1a22d92 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -104,9 +104,16 @@ 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 + before_save :check_pm_and_update_due_date after_save :change_versions_count, :send_update_message_to_notice_system, :associate_attachment_container, :generate_uuid after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic + def check_pm_and_update_due_date + if pm_project_id.present? && status_id.changed? && status_id == 5 + self.due_date = self.due_date || Time.current + end + end + def incre_project_common CacheAsyncSetJob.perform_later('project_common_service', {issues: 1}, self.project_id) end From 9e90b2cef381827c86eb8e30602051e6b1b42910 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 31 Jan 2024 09:19:20 +0800 Subject: [PATCH 146/294] update check_pm_and_update_due_date for issue --- app/models/issue.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 2c1a22d92..ad1090d8e 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -109,8 +109,20 @@ class Issue < ApplicationRecord after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic def check_pm_and_update_due_date - if pm_project_id.present? && status_id.changed? && status_id == 5 - self.due_date = self.due_date || Time.current + if pm_project_id.present? && pm_issue_type.present? && status_id_chenged? + status_ids = case pm_issue_type + when 1 + [3,5] + when 2 + [3,5] + when 3 + [5] + else + [] + end + if status_ids.include? self.status_id + self.due_date = self.due_date || Time.current + end end end From f3dd40515aaf6eb3d155060b50e838f8cdceb91c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 31 Jan 2024 10:21:31 +0800 Subject: [PATCH 147/294] fix bug check_pm_and_update_due_date --- app/models/issue.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index ad1090d8e..028ceb930 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -109,7 +109,7 @@ class Issue < ApplicationRecord after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic def check_pm_and_update_due_date - if pm_project_id.present? && pm_issue_type.present? && status_id_chenged? + if pm_project_id.present? && pm_issue_type.present? && status_id_changed? status_ids = case pm_issue_type when 1 [3,5] From d477d2cabb2cad2737e109918d6aa9ba93161922 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 31 Jan 2024 15:12:55 +0800 Subject: [PATCH 148/294] =?UTF-8?q?fixed=20issues=5Fcount=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E5=A2=9E=E5=8A=A0=E5=B7=B2=E5=88=86=E9=85=8D=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/projects_controller.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index 1ce72b584..95947dcef 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -13,15 +13,10 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController def issues_count return tip_exception '参数错误' unless params[:pm_project_id].present? @issues = Issue.where(pm_project_id: params[:pm_project_id]) - case params[:participant_category].to_s - when 'aboutme' # 关于我的 + @participant_category_count = {} + if params[:participant_category].present? @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}) + @participant_category_count = @issues.group(:pm_project_id, "issue_participants.participant_type").count end data = {} @issues_count = @issues.group(:pm_project_id).count @@ -32,7 +27,10 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController total: @issues_count[project_id] || 0, requirement: @issues_type_count[[project_id, 1]] || 0, task: @issues_type_count[[project_id, 2]] || 0, - bug: @issues_type_count[[project_id, 3]] || 0 + bug: @issues_type_count[[project_id, 3]] || 0, + authoredme: @participant_category_count[[project_id, 0]] || 0, + assignedme: @participant_category_count[[project_id, 1]] || 0, + atme: @participant_category_count[[project_id, 4]] || 0, } end render_ok(data: data) From 94b7129257b9204ee7c582f93edf5a962d94d927 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 31 Jan 2024 15:37:09 +0800 Subject: [PATCH 149/294] =?UTF-8?q?fixed=20issues=5Fcount=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E5=A2=9E=E5=8A=A0=E5=B7=B2=E5=88=86=E9=85=8D=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B,=E5=8D=95=E7=8B=AC=E6=B1=87=E6=80=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/projects_controller.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index 7fce94d94..536995a72 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -14,9 +14,19 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController return tip_exception '参数错误' unless params[:pm_project_id].present? @issues = Issue.where(pm_project_id: params[:pm_project_id]) @participant_category_count = {} - if params[:participant_category].present? + if params[:participant_category].to_s == "authoredme" or params[:participant_category].to_s == "assignedme" + issues_category = @issues.joins(:issue_participants).where(issue_participants: {participant_type: %w[authored assigned atme], participant_id: current_user&.id}) + @participant_category_count = issues_category.group(:pm_project_id, "issue_participants.participant_type").count + end + case params[:participant_category].to_s + when 'aboutme' # 关于我的 @issues = @issues.joins(:issue_participants).where(issue_participants: {participant_type: %w[authored assigned atme], participant_id: current_user&.id}) - @participant_category_count = @issues.group(:pm_project_id, "issue_participants.participant_type").count + 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 data = {} @issues_count = @issues.group(:pm_project_id).count From 0d815db283fe634310269041fdba1ed9e11368ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Thu, 1 Feb 2024 11:48:50 +0800 Subject: [PATCH 150/294] update --- app/controllers/api/pm/sprint_issues_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/pm/sprint_issues_controller.rb b/app/controllers/api/pm/sprint_issues_controller.rb index 0d3c7f31b..b004d93d2 100644 --- a/app/controllers/api/pm/sprint_issues_controller.rb +++ b/app/controllers/api/pm/sprint_issues_controller.rb @@ -53,9 +53,9 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController requirement: @issues_pm_type_count[[sprint_id, 1]] || 0, task: @issues_pm_type_count[[sprint_id, 2]] || 0, bug: @issues_pm_type_count[[sprint_id, 3]] || 0, - requirement_hour: @issues_hour_pm_type_count[[sprint_id, 1]] || 0, - task_hour: @issues_hour_pm_type_count[[sprint_id, 2]] || 0, - bug_hour: @issues_hour_pm_type_count[[sprint_id, 3]] || 0, + requirement_hour: @issues_hour_pm_type_count[[sprint_id, 1]].to_i || 0, + task_hour: @issues_hour_pm_type_count[[sprint_id, 2]].to_i || 0, + bug_hour: @issues_hour_pm_type_count[[sprint_id, 3]].to_i || 0, requirement_open: (@issues_status_pm_type_count[[sprint_id, 1, 1]].to_i + @issues_status_pm_type_count[[sprint_id, 1, 2]].to_i) || 0, task_open: @issues_status_pm_type_count[[sprint_id, 2, 1]].to_i + @issues_status_pm_type_count[[sprint_id, 2, 2]].to_i || 0, bug_open: @issues_status_pm_type_count[[sprint_id, 3, 1]].to_i + @issues_status_pm_type_count[[sprint_id, 3, 2]].to_i || 0 From 08e17454d5b33bb32ffa2ddba60b36d664ad699f Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 2 Feb 2024 11:20:33 +0800 Subject: [PATCH 151/294] =?UTF-8?q?fixed=20issues=5Fcount=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E5=A2=9E=E5=8A=A0=E5=B7=B2=E5=88=86=E9=85=8D=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B,=E5=8D=95=E7=8B=AC=E6=B1=87=E6=80=BB,=E5=8C=BA?= =?UTF-8?q?=E5=88=86=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/projects_controller.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index 536995a72..99bdcbd96 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -13,6 +13,12 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController def issues_count return tip_exception '参数错误' unless params[:pm_project_id].present? @issues = Issue.where(pm_project_id: params[:pm_project_id]) + case params[:category].to_s + when 'closed' + @issues = @issues.closed + when 'opened' + @issues = @issues.opened + end @participant_category_count = {} if params[:participant_category].to_s == "authoredme" or params[:participant_category].to_s == "assignedme" issues_category = @issues.joins(:issue_participants).where(issue_participants: {participant_type: %w[authored assigned atme], participant_id: current_user&.id}) From 9b5fdb5134e1e0624ac3c2b548790c9241b58b8e Mon Sep 17 00:00:00 2001 From: kingchan Date: Fri, 2 Feb 2024 11:40:53 +0800 Subject: [PATCH 152/294] fix bug for pm project --- app/controllers/api/pm/projects_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index 3dfd2e9c0..64c40d136 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -62,7 +62,6 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController return tip_exception '参数错误' if params[:pm_project_id].blank? time_line = (Time.current.beginning_of_day - 6.day) .. Time.current @create_issues = Issue.where(pm_project_id: params[:pm_project_id],created_on: time_line) - @create_issues = Issue.where(pm_project_id: 179,created_on: time_line) @due_issues = Issue.where(pm_project_id: params[:pm_project_id],status_id:[3,5],due_date: time_line) @create_issues_count = @create_issues.group(:pm_issue_type,"DATE(created_on)").count @due_issues_count = @due_issues.group(:pm_issue_type,"DATE(due_date)").count From 7f6c6383bcd84461e10e91f0fedffbb8b93dc3f3 Mon Sep 17 00:00:00 2001 From: yystopf Date: Sat, 3 Feb 2024 14:47:59 +0800 Subject: [PATCH 153/294] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E7=A6=85?= =?UTF-8?q?=E9=81=93=E8=84=9A=E6=9C=AC=E4=B8=AD=E6=95=B0=E6=8D=AE=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/import_issues_from_chandao.rake | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/tasks/import_issues_from_chandao.rake b/lib/tasks/import_issues_from_chandao.rake index 15b038ce6..325b90934 100644 --- a/lib/tasks/import_issues_from_chandao.rake +++ b/lib/tasks/import_issues_from_chandao.rake @@ -12,7 +12,9 @@ namespace :import_from_chandao do author = User.like(randd_field_hash['由谁创建']).take issue.author_id = author&.id assigner = User.like(randd_field_hash['指派给']).take - issue.assigners << assigner + if assigner.present? + issue.assigners << assigner + end issue.status_id = IssueStatus.first.id issue.tracker_id = Tracker.first.id issue.priority_id = randd_field_hash['优先级'].to_i @@ -37,7 +39,9 @@ namespace :import_from_chandao do author = User.like(randd_field_hash['由谁创建']).take issue.author_id = author&.id assigner = User.like(randd_field_hash['指派给']).take - issue.assigners << assigner + if assigner.present? + issue.assigners << assigner + end issue.status_id = IssueStatus.first.id issue.tracker_id = Tracker.first.id issue.priority_id = randd_field_hash['优先级'].to_i From 6694ed625fd5069de33c7e72558b749c169e0915 Mon Sep 17 00:00:00 2001 From: kingchan Date: Sat, 3 Feb 2024 14:59:43 +0800 Subject: [PATCH 154/294] update pie char default --- app/controllers/api/pm/projects_controller.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index 64c40d136..a6fc883f6 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -50,6 +50,12 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController "2": type_status_data[2][1].to_i + type_status_data[2][2].to_i, "3": type_status_data[3][1].to_i + type_status_data[3][2].to_i, } + if type_count_data.keys.size < 3 + nedd_add = [1,2,3] - type_count_data.keys + nedd_add.map{ |e| + type_count_data[e] = 0 + } + end data = { pie_chart: type_count_data, bar_chart: type_status_data, From 4ca1e2e85a7be861ae18a2bb2d918dc5eadd9d21 Mon Sep 17 00:00:00 2001 From: yystopf Date: Sat, 3 Feb 2024 17:12:33 +0800 Subject: [PATCH 155/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E7=A6=85?= =?UTF-8?q?=E9=81=93=E6=95=B0=E6=8D=AE=E5=AF=BC=E5=85=A5=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/import_issues_from_chandao.rake | 65 ++++++++++++++++++++--- 1 file changed, 57 insertions(+), 8 deletions(-) diff --git a/lib/tasks/import_issues_from_chandao.rake b/lib/tasks/import_issues_from_chandao.rake index 325b90934..142db7874 100644 --- a/lib/tasks/import_issues_from_chandao.rake +++ b/lib/tasks/import_issues_from_chandao.rake @@ -11,7 +11,7 @@ namespace :import_from_chandao do issue = Issue.new author = User.like(randd_field_hash['由谁创建']).take issue.author_id = author&.id - assigner = User.like(randd_field_hash['指派给']).take + assigner = randd_field_hash['指派给'].present? ? User.like(randd_field_hash['指派给']).take : nil if assigner.present? issue.assigners << assigner end @@ -29,28 +29,77 @@ namespace :import_from_chandao do end end - # 执行示例 bundle exec rake "import_from_chandao:requirements[企业网站第二期.csv, 3]" - # RAILS_ENV=production bundle exec rake "import_from_chandao:requirements[企业网站第二期.csv, 3]" - task :requirements, [:name, :pm_project_id] => :environment do |t, args| + # 执行示例 bundle exec rake "import_from_chandao:tasks[复杂智能软件项目-所有任务.csv, 365]" + # RAILS_ENV=production bundle exec rake "import_from_chandao:tasks[复杂智能软件项目-所有任务.csv, 365]" + task :tasks, [:name, :pm_project_id] => :environment do |t, args| + def trans_status(str) + h={ + "未开始" => 1, + "进行中" => 2, + "已完成" => 3, + "已关闭" => 4 + } + h[str] + end + name = args.name - CSV.foreach("#{Rails.root}/#{args.name}", headers: true) do | row | + pm_project_id = args.pm_project_id + CSV.foreach("#{Rails.root}/#{name}", headers: true) do | row | randd_field_hash = row.to_hash issue = Issue.new author = User.like(randd_field_hash['由谁创建']).take issue.author_id = author&.id - assigner = User.like(randd_field_hash['指派给']).take + assigner = randd_field_hash['指派给'].present? ? User.like(randd_field_hash['指派给']).take : nil if assigner.present? issue.assigners << assigner end + issue.status_id = trans_status(randd_field_hash['任务状态']) + issue.tracker_id = Tracker.first.id + issue.priority_id = randd_field_hash['优先级'].to_i + issue.subject = randd_field_hash['任务名称'] + issue.description = randd_field_hash['任务描述'] + issue.created_on = randd_field_hash['创建日期'].to_time + issue.updated_on = randd_field_hash['最后修改日期'].to_time rescue randd_field_hash['创建日期'].to_time + issue.time_scale = randd_field_hash['最初预计'].to_i + issue.start_date = randd_field_hash['预计开始'].to_time rescue nil + issue.due_date = randd_field_hash['截止日期'].to_time rescue nil + issue.project_id = 0 + issue.pm_project_id = pm_project_id + issue.pm_issue_type = 2 + issue.save! + requirement_issue = Issue.find_by(project_issues_index: randd_field_hash['相关需求'].split('(#')[1].split(')')[0], pm_project_id: pm_project_id, pm_issue_type: 1) rescue nil + if requirement_issue.present? + requirement_issue.pm_links.find_or_create_by(be_linkable_type: 'Issue', be_linkable_id: issue.id) + end + end + end +end + + # 执行示例 bundle exec rake "import_from_chandao:requirements[企业网站第二期.csv, 3]" + # RAILS_ENV=production bundle exec rake "import_from_chandao:requirements[企业网站第二期.csv, 3]" + task :requirements, [:name, :pm_project_id] => :environment do |t, args| + name = args.name + pm_project_id = args.pm_project_id + CSV.foreach("#{Rails.root}/#{name}", headers: true) do | row | + randd_field_hash = row.to_hash + issue = Issue.new + author = User.like(randd_field_hash['由谁创建']).take + issue.author_id = author&.id + assigner = randd_field_hash['指派给'].present? ? User.like(randd_field_hash['指派给']).take : nil + if assigner.present? + issue.assigners << assigner + end + issue.project_issues_index = randd_field_hash['编号'].to_i issue.status_id = IssueStatus.first.id issue.tracker_id = Tracker.first.id issue.priority_id = randd_field_hash['优先级'].to_i issue.subject = randd_field_hash['需求名称'] issue.description = randd_field_hash['需求描述'] - issue.created_on = randd_field_hash['创建日期'].to_time + issue.created_on = randd_field_hash['创建日期'].to_time + issue.updated_on = randd_field_hash['最后修改日期'].to_time rescue randd_field_hash['创建日期'].to_time issue.time_scale = randd_field_hash['预计工时'].to_i issue.project_id = 0 - issue.pm_project_id = args.pm_project_id + issue.pm_project_id = pm_project_id issue.pm_issue_type = 1 issue.save! end From 4e05be3176a8e962de8a29a4018c452729a0006e Mon Sep 17 00:00:00 2001 From: yystopf Date: Sat, 3 Feb 2024 17:14:51 +0800 Subject: [PATCH 156/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/import_issues_from_chandao.rake | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/tasks/import_issues_from_chandao.rake b/lib/tasks/import_issues_from_chandao.rake index 142db7874..ae8e308f6 100644 --- a/lib/tasks/import_issues_from_chandao.rake +++ b/lib/tasks/import_issues_from_chandao.rake @@ -73,7 +73,6 @@ namespace :import_from_chandao do end end end -end # 执行示例 bundle exec rake "import_from_chandao:requirements[企业网站第二期.csv, 3]" # RAILS_ENV=production bundle exec rake "import_from_chandao:requirements[企业网站第二期.csv, 3]" From a247ac0d3a5831b788cbe797addb27372f96364f Mon Sep 17 00:00:00 2001 From: yystopf Date: Sat, 3 Feb 2024 17:18:01 +0800 Subject: [PATCH 157/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/import_issues_from_chandao.rake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tasks/import_issues_from_chandao.rake b/lib/tasks/import_issues_from_chandao.rake index ae8e308f6..042e9fee6 100644 --- a/lib/tasks/import_issues_from_chandao.rake +++ b/lib/tasks/import_issues_from_chandao.rake @@ -58,8 +58,8 @@ namespace :import_from_chandao do issue.priority_id = randd_field_hash['优先级'].to_i issue.subject = randd_field_hash['任务名称'] issue.description = randd_field_hash['任务描述'] - issue.created_on = randd_field_hash['创建日期'].to_time - issue.updated_on = randd_field_hash['最后修改日期'].to_time rescue randd_field_hash['创建日期'].to_time + issue.created_on = randd_field_hash['创建日期'].to_time rescue nil + issue.updated_on = randd_field_hash['最后修改日期'].to_time rescue issue.created_on issue.time_scale = randd_field_hash['最初预计'].to_i issue.start_date = randd_field_hash['预计开始'].to_time rescue nil issue.due_date = randd_field_hash['截止日期'].to_time rescue nil From 13e58392dc73d6c9ae89805dfa2fa268b5b64593 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 19 Feb 2024 11:14:07 +0800 Subject: [PATCH 158/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E4=B8=ADstatus=E6=89=BE=E4=B8=8D=E5=88=B0=E7=9A=84?= =?UTF-8?q?=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/import_issues_from_chandao.rake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tasks/import_issues_from_chandao.rake b/lib/tasks/import_issues_from_chandao.rake index 042e9fee6..472013bda 100644 --- a/lib/tasks/import_issues_from_chandao.rake +++ b/lib/tasks/import_issues_from_chandao.rake @@ -37,7 +37,7 @@ namespace :import_from_chandao do "未开始" => 1, "进行中" => 2, "已完成" => 3, - "已关闭" => 4 + "已关闭" => 5 } h[str] end @@ -53,7 +53,7 @@ namespace :import_from_chandao do if assigner.present? issue.assigners << assigner end - issue.status_id = trans_status(randd_field_hash['任务状态']) + issue.status_id = trans_status(randd_field_hash['任务状态']) || IssueStatus.first.id issue.tracker_id = Tracker.first.id issue.priority_id = randd_field_hash['优先级'].to_i issue.subject = randd_field_hash['任务名称'] From d20a7b65c2839e86bf9dd9ad8922e8de2219428a Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 6 Mar 2024 09:02:25 +0800 Subject: [PATCH 159/294] fix --- app/models/issue.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 622aa4ae0..d764651e7 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -171,7 +171,6 @@ class Issue < ApplicationRecord def decre_platform_statistic CacheAsyncSetJob.perform_later('platform_statistic_service', {issue_count: -1}) if is_issuely_issue? end - end def get_assign_user User&.find_by_id(self.assigned_to_id) if self.assigned_to_id.present? From 1ed41b93d88c840ebf81b303b183de4331ad0ae0 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 6 Mar 2024 15:30:23 +0800 Subject: [PATCH 160/294] =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=BC=80=E5=90=AF?= =?UTF-8?q?=E7=99=BE=E5=BA=A6=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admins/dashboards_controller.rb | 34 +++++++++---------- app/views/admins/dashboards/index.html.erb | 2 ++ 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/app/controllers/admins/dashboards_controller.rb b/app/controllers/admins/dashboards_controller.rb index 6940ed1cf..37b69dc0d 100644 --- a/app/controllers/admins/dashboards_controller.rb +++ b/app/controllers/admins/dashboards_controller.rb @@ -69,26 +69,26 @@ class Admins::DashboardsController < Admins::BaseController @subject_icon = ["fa-user","fa-git", "fa-sitemap", "fa-warning", "fa-comments", "fa-share-alt", "fa-upload"] @subject_data = [@user_count, @project_count, @organization_count, @issue_count, @comment_count, @pr_count, @commit_count] - - tongji_service = Baidu::TongjiService.new - @access_token = tongji_service.access_token - Rails.logger.info "baidu_tongji_auth access_token ===== #{@access_token}" - # @overview_data = tongji_service.api_overview - last_date = DailyPlatformStatistic.order(:date).last - start_date = last_date.date - end_date = Time.now - if @access_token.present? - @overview_data = Rails.cache.fetch("dashboardscontroller:baidu_tongji:overview_data", expires_in: 10.minutes) do - tongji_service.source_from_batch_add(start_date, end_date) - @overview_data = tongji_service.overview_batch_add(start_date, end_date) - @overview_data + if EduSetting.get("open_baidu_tongji").to_s == "true" + tongji_service = Baidu::TongjiService.new + @access_token = tongji_service.access_token + Rails.logger.info "baidu_tongji_auth access_token ===== #{@access_token}" + # @overview_data = tongji_service.api_overview + last_date = DailyPlatformStatistic.order(:date).last || Time.now + start_date = last_date.date + end_date = Time.now + if @access_token.present? + @overview_data = Rails.cache.fetch("dashboardscontroller:baidu_tongji:overview_data", expires_in: 10.minutes) do + tongji_service.source_from_batch_add(start_date, end_date) + @overview_data = tongji_service.overview_batch_add(start_date, end_date) + @overview_data + end end + + @current_week_statistic = DailyPlatformStatistic.where(date: current_week) + @pre_week_statistic = DailyPlatformStatistic.where(date: pre_week) end - @current_week_statistic = DailyPlatformStatistic.where(date: current_week) - @pre_week_statistic = DailyPlatformStatistic.where(date: pre_week) - - end diff --git a/app/views/admins/dashboards/index.html.erb b/app/views/admins/dashboards/index.html.erb index 5441a1802..a55ef55e4 100644 --- a/app/views/admins/dashboards/index.html.erb +++ b/app/views/admins/dashboards/index.html.erb @@ -85,7 +85,9 @@ + <% if EduSetting.get("open_baidu_tongji").to_s == "true" %> <%= render partial: 'admins/dashboards/baidu_tongji' %> + <% end %>
\ No newline at end of file From d96a33fca4ab67f684dc4071e5fd43f002535c6a Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 11 Mar 2024 09:39:18 +0800 Subject: [PATCH 161/294] =?UTF-8?q?=E9=87=8D=E6=96=B0=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E7=BB=84=E7=BB=87=E6=88=90=E5=91=98=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/template_message_settings/_detail.json.jbuilder | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/template_message_settings/_detail.json.jbuilder b/app/views/template_message_settings/_detail.json.jbuilder index d85a4c4ea..5f6a0bf62 100644 --- a/app/views/template_message_settings/_detail.json.jbuilder +++ b/app/views/template_message_settings/_detail.json.jbuilder @@ -3,6 +3,7 @@ json.type_name type.constantize.type_name json.total_settings_count count json.settings do json.array! type.constantize.openning.limit(100).each do |setting| - json.(setting, :name, :key, :notification_disabled, :email_disabled) + json.(setting, :name, :key, :email_disabled) + json.notification_disabled false end end \ No newline at end of file From 9fbd0a470efe56fb931c8bf6baf0528d2d156c1b Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 26 Mar 2024 17:31:47 +0800 Subject: [PATCH 162/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Aissue?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=97=B6=E9=97=B4=E7=AD=9B=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 1 + app/services/api/v1/issues/list_service.rb | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 9b22068be..1f9270fe4 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -159,6 +159,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController :milestone_id, :assigner_id, :status_id, :priority_id, :begin_date, :end_date, + :update_begin_date, :update_end_date, :sort_by, :sort_direction, :root_id, :issue_tag_ids, :pm_project_id, :pm_sprint_id, :pm_issue_type, :pm_project_ids, :status_ids, :ids, :exclude_ids, :pm_issue_types diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index 2ceb5bae3..6432317ad 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -2,7 +2,7 @@ class Api::V1::Issues::ListService < ApplicationService include ActiveModel::Model attr_reader :project, :only_name, :category, :participant_category, :keyword, :author_id, :issue_tag_ids - attr_reader :begin_date, :end_date + attr_reader :begin_date, :end_date, :update_begin_date, :update_end_date attr_reader :milestone_id, :assigner_id, :status_id, :priority_id, :sort_by, :sort_direction, :current_user attr_reader :pm_project_id, :pm_project_ids, :pm_sprint_id, :root_id, :pm_issue_type, :status_ids, :ids, :exclude_ids, :pm_issue_types attr_accessor :queried_issues, :total_issues_count, :closed_issues_count, :opened_issues_count, :complete_issues_count @@ -27,6 +27,8 @@ class Api::V1::Issues::ListService < ApplicationService @status_id = params[:status_id] @begin_date = params[:begin_date] @end_date = params[:end_date] + @update_begin_date = params[:update_begin_date] + @update_end_date = params[:update_end_date] @sort_by = params[:sort_by].present? ? params[:sort_by] : 'issues.updated_on' @pm_project_id = params[:pm_project_id] @pm_project_ids = params[:pm_project_ids] @@ -144,6 +146,10 @@ class Api::V1::Issues::ListService < ApplicationService issues = issues.where('issues.created_on between ? and ?', begin_date&.present? ? begin_date.to_time : Time.now.beginning_of_day, end_date&.present? ? end_date.to_time.end_of_day : Time.now.end_of_day) end + if update_begin_date&.present? || update_end_date&.present? + issues = issues.where('issues.updated_on between ? and ?', update_begin_date&.present? ? update_begin_date.to_time : Time.now.beginning_of_day, update_end_date&.present? ? update_end_date.to_time.end_of_day : Time.now.end_of_day) + end + # keyword issues = issues.ransack(id_or_project_issues_index_eq: keyword).result.or(issues.ransack(subject_or_description_cont: keyword).result) if keyword.present? From a1ba0b596a58130d1ea407da1082b6aad3726dbb Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 27 Mar 2024 16:04:02 +0800 Subject: [PATCH 163/294] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Aissue?= =?UTF-8?q?=E4=B8=8E=E6=88=91=E7=9B=B8=E5=85=B3=E5=8F=AF=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 2 +- app/services/api/v1/issues/list_service.rb | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 1f9270fe4..d5bf01ad1 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -162,7 +162,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController :update_begin_date, :update_end_date, :sort_by, :sort_direction, :root_id, :issue_tag_ids, :pm_project_id, :pm_sprint_id, :pm_issue_type, :pm_project_ids, - :status_ids, :ids, :exclude_ids, :pm_issue_types + :status_ids, :ids, :exclude_ids, :pm_issue_types, :participantor_id ) end diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index 6432317ad..01100fa07 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -5,7 +5,7 @@ class Api::V1::Issues::ListService < ApplicationService attr_reader :begin_date, :end_date, :update_begin_date, :update_end_date attr_reader :milestone_id, :assigner_id, :status_id, :priority_id, :sort_by, :sort_direction, :current_user attr_reader :pm_project_id, :pm_project_ids, :pm_sprint_id, :root_id, :pm_issue_type, :status_ids, :ids, :exclude_ids, :pm_issue_types - attr_accessor :queried_issues, :total_issues_count, :closed_issues_count, :opened_issues_count, :complete_issues_count + attr_accessor :queried_issues, :total_issues_count, :closed_issues_count, :opened_issues_count, :complete_issues_count, :participantor validates :category, inclusion: { in: %w[all opened closed], message: '请输入正确的Category'} validates :participant_category, inclusion: { in: %w[all aboutme authoredme assignedme atme], message: '请输入正确的ParticipantCategory'} @@ -40,6 +40,7 @@ class Api::V1::Issues::ListService < ApplicationService @status_ids = params[:status_ids].present? ? params[:status_ids].split(',') : [] @pm_issue_types = params[:pm_issue_types].present? ? params[:pm_issue_types].split(',') : [] @sort_direction = (params[:sort_direction].present? ? params[:sort_direction] : 'desc').downcase + @participantor = params[:participantor_id].present? ? User.find_by_id(params[:participantor_id]) : current_user @current_user = current_user end @@ -66,13 +67,13 @@ class Api::V1::Issues::ListService < ApplicationService case participant_category when 'aboutme' # 关于我的 - issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: %w[authored assigned atme], participant_id: current_user&.id}) + issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: %w[authored assigned atme], participant_id: participantor&.id}) when 'authoredme' # 我创建的 - issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: 'authored', participant_id: current_user&.id}) + issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: 'authored', participant_id: participantor&.id}) when 'assignedme' # 我负责的 - issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: 'assigned', participant_id: current_user&.id}) + issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: 'assigned', participant_id: participantor&.id}) when 'atme' # @我的 - issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: 'atme', participant_id: current_user&.id}) + issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: 'atme', participant_id: participantor&.id}) end # author_id issues = issues.where(author_id: author_id) if author_id.present? From d3b552337e6331c67c5a6821f5f9cad2781f3cb4 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 27 Mar 2024 16:18:31 +0800 Subject: [PATCH 164/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 2 +- app/services/api/v1/issues/list_service.rb | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index d5bf01ad1..912305ca2 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -162,7 +162,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController :update_begin_date, :update_end_date, :sort_by, :sort_direction, :root_id, :issue_tag_ids, :pm_project_id, :pm_sprint_id, :pm_issue_type, :pm_project_ids, - :status_ids, :ids, :exclude_ids, :pm_issue_types, :participantor_id + :status_ids, :ids, :exclude_ids, :pm_issue_types, :participator_id ) end diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index 01100fa07..b499a5ea5 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -5,7 +5,7 @@ class Api::V1::Issues::ListService < ApplicationService attr_reader :begin_date, :end_date, :update_begin_date, :update_end_date attr_reader :milestone_id, :assigner_id, :status_id, :priority_id, :sort_by, :sort_direction, :current_user attr_reader :pm_project_id, :pm_project_ids, :pm_sprint_id, :root_id, :pm_issue_type, :status_ids, :ids, :exclude_ids, :pm_issue_types - attr_accessor :queried_issues, :total_issues_count, :closed_issues_count, :opened_issues_count, :complete_issues_count, :participantor + attr_accessor :queried_issues, :total_issues_count, :closed_issues_count, :opened_issues_count, :complete_issues_count, :participator validates :category, inclusion: { in: %w[all opened closed], message: '请输入正确的Category'} validates :participant_category, inclusion: { in: %w[all aboutme authoredme assignedme atme], message: '请输入正确的ParticipantCategory'} @@ -40,7 +40,7 @@ class Api::V1::Issues::ListService < ApplicationService @status_ids = params[:status_ids].present? ? params[:status_ids].split(',') : [] @pm_issue_types = params[:pm_issue_types].present? ? params[:pm_issue_types].split(',') : [] @sort_direction = (params[:sort_direction].present? ? params[:sort_direction] : 'desc').downcase - @participantor = params[:participantor_id].present? ? User.find_by_id(params[:participantor_id]) : current_user + @participator = params[:participator_id].present? ? User.find_by_id(params[:participator_id]) : current_user @current_user = current_user end @@ -67,13 +67,13 @@ class Api::V1::Issues::ListService < ApplicationService case participant_category when 'aboutme' # 关于我的 - issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: %w[authored assigned atme], participant_id: participantor&.id}) + issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: %w[authored assigned atme], participant_id: participator&.id}) when 'authoredme' # 我创建的 - issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: 'authored', participant_id: participantor&.id}) + issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: 'authored', participant_id: participator&.id}) when 'assignedme' # 我负责的 - issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: 'assigned', participant_id: participantor&.id}) + issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: 'assigned', participant_id: participator&.id}) when 'atme' # @我的 - issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: 'atme', participant_id: participantor&.id}) + issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: 'atme', participant_id: participator&.id}) end # author_id issues = issues.where(author_id: author_id) if author_id.present? From 7880ec177939195474bec771c98df63654d6e85f Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 28 Mar 2024 09:40:15 +0800 Subject: [PATCH 165/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E7=A6=85=E9=81=93=E6=95=B0=E6=8D=AE=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/import_issues_from_chandao.rake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/tasks/import_issues_from_chandao.rake b/lib/tasks/import_issues_from_chandao.rake index 472013bda..41bbc3356 100644 --- a/lib/tasks/import_issues_from_chandao.rake +++ b/lib/tasks/import_issues_from_chandao.rake @@ -8,7 +8,7 @@ namespace :import_from_chandao do name = args.name CSV.foreach("#{Rails.root}/#{args.name}", headers: true) do | row | randd_field_hash = row.to_hash - issue = Issue.new + issue = Issue.new(issue_classify: "issue") author = User.like(randd_field_hash['由谁创建']).take issue.author_id = author&.id assigner = randd_field_hash['指派给'].present? ? User.like(randd_field_hash['指派给']).take : nil @@ -46,7 +46,7 @@ namespace :import_from_chandao do pm_project_id = args.pm_project_id CSV.foreach("#{Rails.root}/#{name}", headers: true) do | row | randd_field_hash = row.to_hash - issue = Issue.new + issue = Issue.new(issue_classify: "issue") author = User.like(randd_field_hash['由谁创建']).take issue.author_id = author&.id assigner = randd_field_hash['指派给'].present? ? User.like(randd_field_hash['指派给']).take : nil @@ -81,7 +81,7 @@ namespace :import_from_chandao do pm_project_id = args.pm_project_id CSV.foreach("#{Rails.root}/#{name}", headers: true) do | row | randd_field_hash = row.to_hash - issue = Issue.new + issue = Issue.new(issue_classify: "issue") author = User.like(randd_field_hash['由谁创建']).take issue.author_id = author&.id assigner = randd_field_hash['指派给'].present? ? User.like(randd_field_hash['指派给']).take : nil From 5519c9c51ae0d5ee4636e74e0c102ea5eb74f2cb Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 28 Mar 2024 09:45:10 +0800 Subject: [PATCH 166/294] =?UTF-8?q?=E5=85=8B=E9=9A=86=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E4=B8=8D=E9=9C=80=E8=A6=81=E9=99=90=E5=88=B6ip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/libs/custom_regexp.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/libs/custom_regexp.rb b/app/libs/custom_regexp.rb index b735a631b..0a59d8748 100644 --- a/app/libs/custom_regexp.rb +++ b/app/libs/custom_regexp.rb @@ -9,7 +9,7 @@ module CustomRegexp URL = /\Ahttps?:\/\/[-A-Za-z0-9+&@#\/%?=~_|!:,.;]+[-A-Za-z0-9+&@#\/%=~_|]\z/ IP = /^((\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3}(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])$/ - URL_REGEX = /\A(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?\z/i + URL_REGEX = /\A(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?\z/i # REPOSITORY_NAME_REGEX = /^[a-zA-Z0-9][a-zA-Z0-9\-\_\.]+[a-zA-Z0-9]$/ #只含有数字、字母、下划线不能以下划线开头和结尾 REPOSITORY_NAME_REGEX = /^[a-zA-Z0-9\-\_\.]+[a-zA-Z0-9]$/ #只含有数字、字母、下划线不能以下划线开头和结尾 MD_REGEX = /^.+(\.[m|M][d|D])$/ From 9b0581831f3918a5e5a6aeb1570c09db1b065165 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 1 Apr 2024 14:01:17 +0800 Subject: [PATCH 167/294] =?UTF-8?q?=E5=85=81=E8=AE=B8=E8=B7=A8=E5=9F=9F?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E7=99=BD=E5=90=8D=E5=8D=95IP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/application.rb b/config/application.rb index c36279e38..4cbefed14 100644 --- a/config/application.rb +++ b/config/application.rb @@ -41,7 +41,7 @@ module Gitlink config.middleware.insert_before 0, Rack::Cors do allow do # origins '*' - origins /http:\/\/localhost(:\d+)?\z/, /^(http|https):\/\/(.*(gitlink.org.cn))$/, /^(http|https):\/\/(.*(trustie.net))$/ + origins /http:\/\/localhost(:\d+)?\z/, /http:\/\/172.20.32.201(:\d+)?\z/, /http:\/\/172.20.32.202(:\d+)?\z/, /^(http|https):\/\/(.*(gitlink.org.cn))$/, /^(http|https):\/\/(.*(trustie.net))$/ # location of your api resource '/*', :headers => :any, :methods => [:get, :post, :delete, :options, :put, :patch], credentials: true end From cb0ecc4194a1b36ef2620ef983d3eaeb417fe2c8 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 30 Apr 2024 15:35:35 +0800 Subject: [PATCH 168/294] =?UTF-8?q?fixed=20=E5=A4=9A=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E5=99=A8=E9=80=80=E5=87=BA=E8=B4=A6=E5=8F=B7=E6=97=B6=EF=BC=8C?= =?UTF-8?q?token=E4=B8=8D=E5=AD=98=E5=9C=A8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 41 +++++++++++------------ app/models/token.rb | 40 +++++++++++----------- 2 files changed, 40 insertions(+), 41 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0c134a3bd..bf2fb85c1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -318,19 +318,19 @@ class ApplicationController < ActionController::Base User.current = find_current_user uid_logger("user_setup: " + (User.current.logged? ? "#{User.current.try(:login)} (id=#{User.current.try(:id)})" : "anonymous")) - # 开放课程通过链接访问的用户 - if !User.current.logged? && !params[:chinaoocTimestamp].blank? && !params[:websiteName].blank? && !params[:chinaoocKey].blank? - content = "#{OPENKEY}#{params[:websiteName]}#{params[:chinaoocTimestamp]}" - - if Digest::MD5.hexdigest(content) == params[:chinaoocKey] - user = open_class_user - if user - start_user_session(user) - set_autologin_cookie(user) - end - User.current = user - end - end + # # 开放课程通过链接访问的用户 + # if !User.current.logged? && !params[:chinaoocTimestamp].blank? && !params[:websiteName].blank? && !params[:chinaoocKey].blank? + # content = "#{OPENKEY}#{params[:websiteName]}#{params[:chinaoocTimestamp]}" + # + # if Digest::MD5.hexdigest(content) == params[:chinaoocKey] + # user = open_class_user + # if user + # start_user_session(user) + # set_autologin_cookie(user) + # end + # User.current = user + # end + # end if !User.current.logged? && Rails.env.development? user = User.find 1 @@ -363,15 +363,14 @@ class ApplicationController < ActionController::Base uid_logger("user setup start: session[:user_id] is #{session[:user_id]}") uid_logger("0000000000000user setup start: default_yun_session is #{default_yun_session}, session[:current_user_id] is #{session[:"#{default_yun_session}"]}") current_domain_session = session[:"#{default_yun_session}"] - if current_domain_session - # existing session - User.current = (User.active.find(current_domain_session) rescue nil) - elsif autologin_user = try_to_autologin - autologin_user - elsif params[:format] == 'atom' && params[:key] && request.get? && accept_rss_auth? - # RSS key authentication does not start a session - User.find_by_rss_key(params[:key]) + autologin_user = try_to_autologin + uid_logger("user setup start: autologin_user is #{autologin_user}") + # 多浏览器退出账号时,token不存在处理 + if current_domain_session && autologin_user.nil? + autologin_user = (User.active.find(current_domain_session) rescue nil) + set_autologin_cookie(autologin_user) end + autologin_user end def try_to_autologin diff --git a/app/models/token.rb b/app/models/token.rb index fac516eb8..7d65f32a3 100644 --- a/app/models/token.rb +++ b/app/models/token.rb @@ -1,19 +1,19 @@ -# == Schema Information -# -# Table name: tokens -# -# id :integer not null, primary key -# user_id :integer default("0"), not null -# action :string(30) default(""), not null -# value :string(40) default(""), not null -# created_on :datetime not null -# -# Indexes -# -# index_tokens_on_user_id (user_id) -# tokens_value (value) UNIQUE -# - +# == Schema Information +# +# Table name: tokens +# +# id :integer not null, primary key +# user_id :integer default("0"), not null +# action :string(30) default(""), not null +# value :string(40) default(""), not null +# created_on :datetime not null +# +# Indexes +# +# index_tokens_on_user_id (user_id) +# tokens_value (value) UNIQUE +# + # # This program is free software; you can redistribute it and/or @@ -44,7 +44,7 @@ class Token < ActiveRecord::Base def self.get_or_create_permanent_login_token(user, type) token = Token.get_token_from_user(user, type) - Rails.logger.info "###### Token.get_token_from_user result: #{token&.value}" + Rails.logger.info "###### Token.get_token_from_user time:#{Time.new.to_i}, result: #{token&.value}" unless token token = Token.create(:user => user, :action => type) Rails.logger.info "###### Token.get_token_from_user is nul and agine create token: #{token&.value}" @@ -117,8 +117,8 @@ class Token < ActiveRecord::Base # Removes obsolete tokens (same user and action) def delete_previous_tokens - if user - Token.where(['user_id = ? AND action = ?', user.id, action]).delete_all - end + # if user + # Token.where(['user_id = ? AND action = ?', user.id, action]).delete_all + # end end end From ddaa6f7aec3b47b9b7cf46f77d2bc2f048fbe200 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 May 2024 09:42:48 +0800 Subject: [PATCH 169/294] =?UTF-8?q?fixed=20=E5=9B=BE=E5=BD=A2=E5=8C=96?= =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E6=9E=84=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/pipelines_controller.rb | 542 ++++++++++++++++++ app/models/action/node.rb | 53 +- app/models/action/pipeline.rb | 37 ++ .../v1/projects/pipelines/build_node.yaml.erb | 9 + .../pipelines/build_pipeline.yaml.erb | 55 ++ .../v1/projects/pipelines/index.json.jbuilder | 8 + .../v1/projects/pipelines/show.json.jbuilder | 5 + .../api/v1/projects/pipelines/test.yaml.erb | 89 +++ config/routes/api.rb | 3 +- ...0240408010227_create_action_node_inputs.rb | 2 +- .../20240408010233_create_action_templates.rb | 2 +- .../20240514121788_create_action_pipelines.rb | 23 + 12 files changed, 795 insertions(+), 33 deletions(-) create mode 100644 app/controllers/api/v1/projects/pipelines_controller.rb create mode 100644 app/models/action/pipeline.rb create mode 100644 app/views/api/v1/projects/pipelines/build_node.yaml.erb create mode 100644 app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb create mode 100644 app/views/api/v1/projects/pipelines/index.json.jbuilder create mode 100644 app/views/api/v1/projects/pipelines/show.json.jbuilder create mode 100644 app/views/api/v1/projects/pipelines/test.yaml.erb create mode 100644 db/migrate/20240514121788_create_action_pipelines.rb diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb new file mode 100644 index 000000000..ba1bafc4e --- /dev/null +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -0,0 +1,542 @@ +class Api::V1::Projects::PipelinesController < Api::V1::BaseController + before_action :require_manager_above + + def index + @pipelines = Action::Pipeline.where(project_id: @project.id).order(updated_at: :desc) + @pipelines = paginate @pipelines + end + + def create + size = Action::Pipeline.where(pipeline_name: params[:pipeline_name], project_id: @project.id).size + tip_exception("已经存在#{params[:pipeline_name]}流水线!") if size > 0 + @pipeline = Action::Pipeline.new(pipeline_name: params[:pipeline_name], project_id: @project.id) + @pipeline.file_name = ".gitea/workflows/#{@pipeline.pipeline_name}.yaml" + @pipeline.json = demo.to_json + # @pipeline.json = params[:json] if params[:json] + @pipeline.yaml = build_pipeline_yaml(@pipeline) + @pipeline.save! + sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch) + tip_exception("#{@pipeline.file_name}已存在") if sha + interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params) + tip_exception(interactor.error) unless interactor.success? + render_ok({ id: @pipeline.id }) + end + + def update + @pipeline = Action::Pipeline.find(params[:id]) + @pipeline.update!(pipeline_name: params[:pipeline_name]) + interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params) + tip_exception(interactor.error) unless interactor.success? + render_ok + end + + def destroy + @pipeline = Action::Pipeline.find(params[:id]) + if pipeline + interactor = Gitea::DeleteFileInteractor.call(current_user.gitea_token, @owner.login, content_params) + tip_exception(interactor.error) unless interactor.success? + @pipeline.destroy! + end + render_ok + end + + def show + @pipeline = Action::Pipeline.find_by(id: params[:id]) + @pipeline = Action::Pipeline.new(id: 0, pipeline_name: "test-ss", yaml: build_yaml) if @pipeline.blank? + end + + def build_pipeline_yaml(pipeline) + if pipeline.json.present? + @name = pipeline.pipeline_name + params_nodes = JSON.parse(pipeline.json)["nodes"].select { |node| !["on-push", "on-schedule"].include?(node["component_name"]) } + on_nodes = JSON.parse(pipeline.json)["nodes"].select { |node| ["on-push", "on-schedule"].include?(node["component_name"]) } + @on_nodes = build_nodes(on_nodes) + @steps_nodes = build_nodes(params_nodes) + yaml = ERB.new(File.read(File.join(Rails.root, "app/views/api/v1/projects/pipelines", "build_pipeline.yaml.erb"))).result(binding) + # 删除空行内容 + @pipeline_yaml = yaml.gsub(/^\s*\n/, "") + else + @pipeline_yaml = params[:yaml] + end + @pipeline_yaml + end + + def build_yaml + @name = "love me" + params_nodes = JSON.parse(demo.to_json)["nodes"].select { |node| !["on-push", "on-schedule"].include?(node["component_name"]) } + on_nodes = JSON.parse(demo.to_json)["nodes"].select { |node| ["on-push", "on-schedule"].include?(node["component_name"]) } + @on_nodes = build_nodes(on_nodes) + @steps_nodes = [] + params_nodes.each do |input_node| + # Rails.logger.info "input_node=====0===#{input_node["component_name"]}======#{input_node["in_parameters"]}" + node = Action::Node.find_by(name: input_node["component_name"]) + node.cust_name = input_node["component_label"] if input_node["component_label"].present? + input_values = {} + if input_node["in_parameters"].present? + # Rails.logger.info "@in_parameters=====11===#{input_node["component_name"]}======#{input_node["in_parameters"]}" + input_node["in_parameters"].each_key do |input_key| + # Rails.logger.info "@in_parameters.input_key===#{input_key}" + # Rails.logger.info "@in_parameters.input_value===#{input_node["in_parameters"][input_key]["value"]}" + input_values = input_values.merge({ "#{input_key.gsub("--", "")}": "#{input_node["in_parameters"][input_key]["value"]}" }) + end + node.input_values = input_values + # Rails.logger.info "@input_values node===#{node.input_values.to_json}" + end + @steps_nodes.push(node) + end + Rails.logger.info "@@on_nodes===#{@on_nodes.to_json}" + Rails.logger.info "@steps_nodes===#{@steps_nodes.to_json}" + yaml = ERB.new(File.read(File.join(Rails.root, "app/views/api/v1/projects/pipelines", "build_pipeline.yaml.erb"))).result(binding) + @pipeline_yaml = yaml.gsub(/^\s*\n/, "") + Rails.logger.info "=========================" + Rails.logger.info @pipeline_yaml + @pipeline_yaml + end + + private + + def get_pipeline_file_sha(file_name, branch) + file_path_uri = URI.parse(file_name) + interactor = Repositories::EntriesInteractor.call(@project.owner, @project.identifier, file_path_uri, ref: branch || 'master') + if interactor.success? + file = interactor.result + file['sha'] + end + end + + def content_params + { + filepath: ".gitea/workflows/#{@pipeline.pipeline_name}.yaml", + branch: @pipeline.branch, + new_branch: @pipeline.branch, + content: build_pipeline_yaml(@pipeline), + message: 'create pipeline', + committer: { + email: current_user.mail, + name: current_user.login + }, + identifier: @project.identifier + } + end + + def build_nodes(params_nodes) + steps_nodes = [] + params_nodes.each do |input_node| + node = Action::Node.find_by(name: input_node["component_name"]) + node.cust_name = input_node["component_label"] if input_node["component_label"].present? + input_values = {} + if input_node["in_parameters"].present? + # Rails.logger.info "@in_parameters=====11===#{input_node["component_name"]}======#{input_node["in_parameters"]}" + input_node["in_parameters"].each_key do |input_key| + # Rails.logger.info "@in_parameters.input_key===#{input_key}" + # Rails.logger.info "@in_parameters.input_value===#{input_node["in_parameters"][input_key]["value"]}" + input_values = input_values.merge({ "#{input_key.gsub("--", "")}": "#{input_node["in_parameters"][input_key]["value"]}" }) + end + # Rails.logger.info "@input_values node1===#{input_values}" + node.input_values = input_values + # Rails.logger.info "@input_values node===#{node.input_values.to_json}" + end + steps_nodes.push(node) + end + steps_nodes + end + + def demo + { + "nodes": [ + { + "id": "git-clone-245734ab", + "category_id": 1, + "component_name": "on-schedule", + "component_label": "触发器", + "working_directory": "", + "command": "", + "in_parameters": { + "--cro": { + "type": "str", + "item_type": "", + "label": "push代码", + "require": 1, + "choice": [], + "default": "", + "placeholder": "私有仓库填写ssh地址,公有仓库填写https git地址", + "describe": "代码仓库地址", + "editable": 1, + "condition": "", + "value": "15 4,5 * * *" + }, + "--paths-ignore": { + "type": "str", + "item_type": "", + "label": "push代码", + "require": 1, + "choice": [], + "default": "", + "placeholder": "私有仓库填写ssh地址,公有仓库填写https git地址", + "describe": "代码仓库地址", + "editable": 1, + "condition": "", + "value": "**.md" + } + }, + "out_parameters": { + "--code_output": { + "type": "str", + "label": "代码输出路径", + "path": "/code", + "require": 1, + "value": "/code" + } + }, + "description": "代码拉取组件", + "icon_path": "component-icon-1", + "create_by": "admin", + "create_time": "2024-03-02T05:41:25.000+00:00", + "update_by": "admin", + "update_time": "2024-03-02T05:41:25.000+00:00", + "state": 1, + "image": "172.20.32.187/pipeline-component/built-in/git:202312071000", + "env_variables": "", + "x": 532, + "y": 202, + "label": "代码拉取", + "img": "/assets/images/component-icon-1.png", + "isCluster": false, + "type": "rect-node", + "size": [110, 36], + "--code_path": "https://openi.pcl.ac.cn/somunslotus/somun202304241505581.git", + "--branch": "train_ci_test", + "--depth": "1", + "--code_output": "/code" + }, + { + "id": "git-clone-245734ab", + "category_id": 1, + "component_name": "git-clone", + "component_label": "代码拉取", + "working_directory": "", + "command": "", + "in_parameters": { + + }, + "out_parameters": { + "--code_output": { + "type": "str", + "label": "代码输出路径", + "path": "/code", + "require": 1, + "value": "/code" + } + }, + "description": "代码拉取组件", + "icon_path": "component-icon-1", + "create_by": "admin", + "create_time": "2024-03-02T05:41:25.000+00:00", + "update_by": "admin", + "update_time": "2024-03-02T05:41:25.000+00:00", + "state": 1, + "image": "172.20.32.187/pipeline-component/built-in/git:202312071000", + "env_variables": "", + "x": 532, + "y": 202, + "label": "代码拉取", + "img": "/assets/images/component-icon-1.png", + "isCluster": false, + "type": "rect-node", + "size": [110, 36], + "--code_path": "https://openi.pcl.ac.cn/somunslotus/somun202304241505581.git", + "--branch": "train_ci_test", + "--depth": "1", + "--code_output": "/code" + }, + { + "id": "git-clone-245734ab", + "category_id": 1, + "component_name": "setup-java", + "component_label": "安装java环境", + "working_directory": "", + "command": "", + "in_parameters": { + "--distribution": { + "type": "str", + "item_type": "", + "label": "代码仓库地址", + "require": 1, + "choice": [], + "default": "", + "placeholder": "私有仓库填写ssh地址,公有仓库填写https git地址", + "describe": "代码仓库地址", + "editable": 1, + "condition": "", + "value": "jdkfile" + }, + "--java-version": { + "type": "str", + "item_type": "", + "label": "代码分支/tag", + "require": 1, + "choice": [], + "default": "master", + "placeholder": "", + "describe": "代码分支或者tag", + "editable": 1, + "condition": "", + "value": "11.0.0" + }, + "--architecture": { + "type": "str", + "item_type": "", + "label": "克隆深度", + "require": 0, + "choice": [], + "default": "1", + "placeholder": "", + "describe": "代码克隆深度", + "editable": 1, + "condition": "", + "value": "x64" + }, + "--mvn-toolchain-vendor": { + "type": "str", + "item_type": "", + "label": "ssh私钥", + "require": 0, + "choice": [], + "default": "1", + "placeholder": "", + "describe": "ssh私钥,确保ssh公钥已经托管到代码平台,否则可能拉取失败", + "editable": 1, + "value": "Oracle" + } + }, + "out_parameters": { + "--code_output": { + "type": "str", + "label": "代码输出路径", + "path": "/code", + "require": 1, + "value": "/code" + } + }, + "description": "代码拉取组件", + "icon_path": "component-icon-1", + "create_by": "admin", + "create_time": "2024-03-02T05:41:25.000+00:00", + "update_by": "admin", + "update_time": "2024-03-02T05:41:25.000+00:00", + "state": 1, + "image": "172.20.32.187/pipeline-component/built-in/git:202312071000", + "env_variables": "", + "x": 532, + "y": 202, + "label": "代码拉取", + "img": "/assets/images/component-icon-1.png", + "isCluster": false, + "type": "rect-node", + "size": [110, 36], + "--code_path": "https://openi.pcl.ac.cn/somunslotus/somun202304241505581.git", + "--branch": "train_ci_test", + "--depth": "1", + "--code_output": "/code" + }, + { + "id": "git-clone-245734ab", + "category_id": 1, + "component_name": "shell", + "component_label": "执行shell命令", + "working_directory": "", + "command": "", + "in_parameters": { + "--run": { + "type": "str", + "item_type": "", + "label": "代码仓库地址", + "require": 1, + "choice": [], + "default": "", + "placeholder": "私有仓库填写ssh地址,公有仓库填写https git地址", + "describe": "代码仓库地址", + "editable": 1, + "condition": "", + "value": "service nginx restart" + } + } + }, + { + "id": "git-clone-245734ab", + "category_id": 1, + "component_name": "scp", + "component_label": "scp", + "working_directory": "", + "command": "", + "in_parameters": { + "--run": { + "type": "str", + "item_type": "", + "label": "代码仓库地址", + "require": 1, + "choice": [], + "default": "", + "placeholder": "私有仓库填写ssh地址,公有仓库填写https git地址", + "describe": "代码仓库地址", + "editable": 1, + "condition": "", + "value": "service nginx restart" + } + } + } + + ], + # "edges": [ + # { + # "source": "git-clone-245734ab", + # "target": "model-train-09b1491", + # "style": { + # "active": { + # "stroke": "rgb(95, 149, 255)", + # "lineWidth": 1 + # }, + # "selected": { + # "stroke": "rgb(95, 149, 255)", + # "lineWidth": 2, + # "shadowColor": "rgb(95, 149, 255)", + # "shadowBlur": 10, + # "text-shape": { + # "fontWeight": 500 + # } + # }, + # "highlight": { + # "stroke": "rgb(95, 149, 255)", + # "lineWidth": 2, + # "text-shape": { + # "fontWeight": 500 + # } + # }, + # "inactive": { + # "stroke": "rgb(234, 234, 234)", + # "lineWidth": 1 + # }, + # "disable": { + # "stroke": "rgb(245, 245, 245)", + # "lineWidth": 1 + # }, + # "endArrow": { + # "path": "M 6,0 L 9,-1.5 L 9,1.5 Z", + # "d": 4.5, + # "fill": "#CDD0DC" + # }, + # "cursor": "pointer", + # "lineWidth": 1, + # "opacity": 1, + # "stroke": "#CDD0DC", + # "radius": 1 + # }, + # "nodeStateStyle": { + # "hover": { + # "opacity": 1, + # "stroke": "#8fe8ff" + # } + # }, + # "labelCfg": { + # "autoRotate": true, + # "style": { + # "fontSize": 10, + # "fill": "#FFF" + # } + # }, + # "id": "edge-0.11773197923997381714446043619", + # "startPoint": { + # "x": 532, + # "y": 220.25, + # "anchorIndex": 1 + # }, + # "endPoint": { + # "x": 530, + # "y": 304.75, + # "anchorIndex": 0 + # }, + # "targetAnchor": 0, + # "type": "cubic-vertical", + # "curveOffset": [0, 0], + # "curvePosition": [0.5, 0.5], + # "minCurveOffset": [0, 0], + # "depth": 0 + # }, + # { + # "source": "model-train-09b1491", + # "target": "model-evaluate-b401ff0", + # "style": { + # "active": { + # "stroke": "rgb(95, 149, 255)", + # "lineWidth": 1 + # }, + # "selected": { + # "stroke": "rgb(95, 149, 255)", + # "lineWidth": 2, + # "shadowColor": "rgb(95, 149, 255)", + # "shadowBlur": 10, + # "text-shape": { + # "fontWeight": 500 + # } + # }, + # "highlight": { + # "stroke": "rgb(95, 149, 255)", + # "lineWidth": 2, + # "text-shape": { + # "fontWeight": 500 + # } + # }, + # "inactive": { + # "stroke": "rgb(234, 234, 234)", + # "lineWidth": 1 + # }, + # "disable": { + # "stroke": "rgb(245, 245, 245)", + # "lineWidth": 1 + # }, + # "endArrow": { + # "path": "M 6,0 L 9,-1.5 L 9,1.5 Z", + # "d": 4.5, + # "fill": "#CDD0DC" + # }, + # "cursor": "pointer", + # "lineWidth": 1, + # "opacity": 1, + # "stroke": "#CDD0DC", + # "radius": 1 + # }, + # "nodeStateStyle": { + # "hover": { + # "opacity": 1, + # "stroke": "#8fe8ff" + # } + # }, + # "labelCfg": { + # "autoRotate": true, + # "style": { + # "fontSize": 10, + # "fill": "#FFF" + # } + # }, + # "id": "edge-0.28238605806531771714446047075", + # "startPoint": { + # "x": 530, + # "y": 341.25, + # "anchorIndex": 1 + # }, + # "endPoint": { + # "x": 520, + # "y": 431.75, + # "anchorIndex": 0 + # }, + # "targetAnchor": 0, + # "type": "cubic-vertical", + # "curveOffset": [0, 0], + # "curvePosition": [0.5, 0.5], + # "minCurveOffset": [0, 0], + # "depth": 0 + # } + # ] + } + end +end diff --git a/app/models/action/node.rb b/app/models/action/node.rb index 69e45b3a8..601749047 100644 --- a/app/models/action/node.rb +++ b/app/models/action/node.rb @@ -19,6 +19,7 @@ # # Indexes # +# by_name (name) # index_action_nodes_on_action_types_id (action_node_types_id) # index_action_nodes_on_user_id (user_id) # @@ -33,39 +34,31 @@ class Action::Node < ApplicationRecord belongs_to :user, optional: true + attr_accessor :cust_name, :input_values - # def content_yaml - # "foo".to_yaml - # <<~YAML - # - name: Set up JDK ${{ matrix.java }} - # uses: actions/setup-java@v3 - # with: - # distribution: 'temurin' - # java-version: ${{ matrix.java }} - # YAML - # end - def yaml_hash + def content_yaml + "foo".to_yaml <<~YAML - name: Check dist - - on: - push: - branches: - - main - paths-ignore: - - '**.md' - pull_request: - paths-ignore: - - '**.md' - workflow_dispatch: - - jobs: - call-check-dist: - name: Check dist/ - uses: actions/reusable-workflows/.github/workflows/check-dist.yml@main - with: - node-version: '20.x' + - name: Set up JDK ${{ matrix.java }} + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: ${{ matrix.java }} YAML end + + def node + self + end + + def build_yaml + yaml = ERB.new(File.read(File.join(Rails.root, "app/views/api/v1/projects/pipelines", "build_node.yaml.erb"))).result(binding) + # 删除空行内容 + yaml = yaml.gsub(/^\s*\n/, "") + # Rails.logger.info "=========================" + # Rails.logger.info yaml + yaml + end + end diff --git a/app/models/action/pipeline.rb b/app/models/action/pipeline.rb new file mode 100644 index 000000000..1dfbd0f24 --- /dev/null +++ b/app/models/action/pipeline.rb @@ -0,0 +1,37 @@ +# == Schema Information +# +# Table name: action_pipelines +# +# id :integer not null, primary key +# project_id :integer +# user_id :integer +# pipeline_name :string(255) +# pipeline_status :string(255) +# description :string(255) +# file_name :string(255) +# is_graphic_design :boolean default("0") +# repo_name :string(255) +# repo_identifier :string(255) +# repo_owner :string(255) +# branch :string(255) +# event :string(255) +# sha :string(255) +# json :text(65535) +# yaml :text(65535) +# disable :boolean default("0") +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_action_pipelines_on_project_id (project_id) +# index_action_pipelines_on_user_id (user_id) +# + +class Action::Pipeline < ApplicationRecord + self.table_name = 'action_pipelines' + belongs_to :user, optional: true + belongs_to :project + + +end diff --git a/app/views/api/v1/projects/pipelines/build_node.yaml.erb b/app/views/api/v1/projects/pipelines/build_node.yaml.erb new file mode 100644 index 000000000..ded111099 --- /dev/null +++ b/app/views/api/v1/projects/pipelines/build_node.yaml.erb @@ -0,0 +1,9 @@ +steps: + - name: <%=self.node.name %> + uses: <%=self.full_name %> + <%if self.action_node_inputs.present? %> + with: + <% self.action_node_inputs.each do |input| %> + <%=input.name %>: '' + <%end %> + <%end %> \ No newline at end of file diff --git a/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb b/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb new file mode 100644 index 000000000..be8a7106e --- /dev/null +++ b/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb @@ -0,0 +1,55 @@ +# action name +name: <%=@name %> + +# 什么时候触发这个workflow +on: + <%@on_nodes.each do |node| %> + <%if node.name.to_s.include?("on-push") %> + push: + <% node.input_values.each_key do |key| %> + <%=key %>: + <% if node.input_values[key].blank? %> + - * + <% else %> + <% node.input_values[key].to_s.split(",").each do |val| %> + - <%=val %> + <% end %> + <% end %> + <% end %> + <% end %> + <%if node.name.to_s.include?("on-pull_request") %> + pull_request: + <% node.input_values.each_key do |key| %> + <%=key %>: + <% if node.input_values[key].blank? %> + - * + <% else %> + <% node.input_values[key].to_s.split(",").each do |val| %> + - <%=val %> + <% end %> + <% end %> + <% end %> + <% end %> + <%if node.name.to_s.include?("on-schedule") %> + schedule: + <% node.input_values.each_key do |key| %> + - <%=key %>: "<%=node.input_values[key] %>" + <% end %> + <% end %> + <% end %> + +jobs: + job1: + # 运行环境 + runs-on: 'ubuntu-latest' + steps: + <%@steps_nodes.each do |node| %> + - name: <%=node.cust_name || node.name %> + uses: <%=node.full_name %> + <%if node.input_values.present? %> + with: + <% node.input_values.each_key do |key| %> + <%=key %>: <%=node.input_values[key] %> + <%end %> + <%end %> + <% end %> diff --git a/app/views/api/v1/projects/pipelines/index.json.jbuilder b/app/views/api/v1/projects/pipelines/index.json.jbuilder new file mode 100644 index 000000000..7c3f2a405 --- /dev/null +++ b/app/views/api/v1/projects/pipelines/index.json.jbuilder @@ -0,0 +1,8 @@ +json.status 0 +json.message "success" + +json.pipelines @pipelines.each do |pip| + json.extract! pip, :id, :pipeline_name, :pipeline_status, :description, :file_name, :is_graphic_design, + :repo_name, :repo_identifier, :branch, :event, :sha, :disable, :json, :yaml, :created_at, :updated_at + # json.project +end diff --git a/app/views/api/v1/projects/pipelines/show.json.jbuilder b/app/views/api/v1/projects/pipelines/show.json.jbuilder new file mode 100644 index 000000000..d82015ade --- /dev/null +++ b/app/views/api/v1/projects/pipelines/show.json.jbuilder @@ -0,0 +1,5 @@ +json.status 0 +json.message "success" +json.extract! @pipeline, :id, :pipeline_name, :pipeline_status, :description, :file_name, :is_graphic_design, + :repo_name, :repo_identifier, :branch, :event, :sha, :disable, :json, :yaml, :created_at, :updated_at +# json.project \ No newline at end of file diff --git a/app/views/api/v1/projects/pipelines/test.yaml.erb b/app/views/api/v1/projects/pipelines/test.yaml.erb new file mode 100644 index 000000000..3ec890230 --- /dev/null +++ b/app/views/api/v1/projects/pipelines/test.yaml.erb @@ -0,0 +1,89 @@ +name: Check dist<%= @name %> + +# action name +name: Test with Junit + +# 什么时候触发这个workflow +on: + # push 到master分之的时候 这里可以指定多个 + #push: + # branches: + # - master +# paths-ignore: +# - '**.md' + # pull request 到master分之的时候, 这里可以指定多个 + #pull_request: + # branches: + # - master +# paths-ignore: +# - '**.md' + # 定时调度执行 + schedule: + - cron: '26 10,11 * * *' +env: + https_proxy: http://172.20.32.253:3128 + http_proxy: http://172.20.32.253:3128 + +# 一个workflow可以由多个job组成,多个job可以并行运行 +jobs: + junit: + strategy: + matrix: + # 指定jdk 版本。可以指定多个版本 比如[8,11,17] + java: [11] + # 指定运行 os 版本 也是多个 + os: [ 'ubuntu-latest' ] + # 运行环境,这里就是上面定义的多个 os + runs-on: 'ubuntu-latest' + + steps: + # 将job的工作目录指向$GITHUB_WORSPACES checkout@v2比较旧不推荐使用 + - name: Checkout codes + uses: actions/checkout@v3 + #- name: Install Java and Maven + # uses: actions/setup-java@v3 + # with: + # java-version: '11' + # distribution: 'temurin' + # 设置jdk环境 + - name: download latest temurin JDK + id: download_latest_jdk + env: + HTTPS_PROXY: http://172.20.32.253:3128 + HTTP_PROXY: http://172.20.32.253:3128 + #run: curl -o https://testgitea2.trustie.net/xxq250/licensee-identify-api-sss/raw/branch/master/openlogic-openjdk-11.0.22+7-linux-x64.tar.gz + run: wget -O $RUNNER_TEMP/java_package.tar.gz "http://172.20.32.202:10082/xxq250/licensee-identify-api-sss/raw/branch/master/OpenJDK11U-jdk_x64_linux_hotspot_11.0.22_7.tar.gz" + - uses: actions/setup-java@v4 + with: + distribution: 'jdkfile' + jdkFile: ${{ runner.temp }}/java_package.tar.gz + java-version: '11.0.0' + architecture: x64 + mvn-toolchain-vendor: 'Oracle' + # 设置maven 仓库缓存 避免每次构建时都重新下载依赖 + - name: Cache local Maven repository + uses: actions/cache@v3 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + - name: Test java version + run: java -version + - name: Set up Maven + uses: stCarolas/setup-maven@v5 + with: + maven-version: 3.8.2 + - name: Setup Maven mirrors + uses: s4u/maven-settings-action@v3.0.0 + with: + mirrors: '[{"id": "alimaven", "name": "aliyun maven", "mirrorOf": "central", "url": "http://172.20.32.181:30005/repository/aliyun-maven/"}]' + - name: env show + run: env + - name: cat maven-settings.xml + run: cat /root/.m2/settings.xml + - name: Test with Maven + run: mvn clean test -B -U + env: + https_proxy: http://172.20.32.253:3128 + http_proxy: http://172.20.32.253:3128 diff --git a/config/routes/api.rb b/config/routes/api.rb index a111bcdb2..4db29cf06 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -129,7 +129,8 @@ defaults format: :json do end end end - resources :pulls, module: 'pulls' do + resources :pipelines + resources :pulls, module: 'pulls' do resources :versions, only: [:index] do member do get :diff diff --git a/db/migrate/20240408010227_create_action_node_inputs.rb b/db/migrate/20240408010227_create_action_node_inputs.rb index 501844e28..a710271cd 100644 --- a/db/migrate/20240408010227_create_action_node_inputs.rb +++ b/db/migrate/20240408010227_create_action_node_inputs.rb @@ -6,7 +6,7 @@ class CreateActionNodeInputs < ActiveRecord::Migration[5.2] t.string :input_type t.string :description t.boolean :is_required, default: false - t.string :sort_no, default: 0 + t.integer :sort_no, default: 0 t.references :user t.timestamps end diff --git a/db/migrate/20240408010233_create_action_templates.rb b/db/migrate/20240408010233_create_action_templates.rb index 47d335094..1b4c985d2 100644 --- a/db/migrate/20240408010233_create_action_templates.rb +++ b/db/migrate/20240408010233_create_action_templates.rb @@ -4,7 +4,7 @@ class CreateActionTemplates < ActiveRecord::Migration[5.2] t.string :name t.string :description t.string :img - t.string :sort_no, default: 0 + t.integer :sort_no, default: 0 t.text :json t.text :yaml t.timestamps diff --git a/db/migrate/20240514121788_create_action_pipelines.rb b/db/migrate/20240514121788_create_action_pipelines.rb new file mode 100644 index 000000000..b453c3943 --- /dev/null +++ b/db/migrate/20240514121788_create_action_pipelines.rb @@ -0,0 +1,23 @@ +class CreateActionPipelines < ActiveRecord::Migration[5.2] + def change + create_table :action_pipelines do |t| + t.references :project + t.references :user + t.string :pipeline_name + t.string :pipeline_status + t.string :description + t.string :file_name + t.boolean :is_graphic_design, default: false + t.string :repo_name + t.string :repo_identifier + t.string :repo_owner + t.string :branch + t.string :event + t.string :sha + t.text :json + t.text :yaml + t.boolean :disable, default: false + t.timestamps + end + end +end From 785869d48ace77ea630425f613bae21f07988997 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 17 May 2024 15:26:58 +0800 Subject: [PATCH 170/294] =?UTF-8?q?fixed=20=E5=9B=BE=E5=BD=A2=E5=8C=96?= =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E6=9E=84=E5=BB=BA=E7=BB=86=E8=8A=82?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/pipelines_controller.rb | 69 ++++++++++++++++--- app/models/action/node.rb | 2 +- .../pipelines/build_pipeline.yaml.erb | 9 ++- config/routes/api.rb | 4 +- 4 files changed, 73 insertions(+), 11 deletions(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index ba1bafc4e..39f20a009 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -22,6 +22,23 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController render_ok({ id: @pipeline.id }) end + def build_yaml + # pipeline = params[:pipeline] + # @name = params[:name] + # params_nodes = JSON.parse(pipeline)["nodes"].select { |node| !["on-push", "on-schedule"].include?(node["component_name"]) } + # on_nodes = JSON.parse(pipeline)["nodes"].select { |node| ["on-push", "on-schedule"].include?(node["component_name"]) } + # @on_nodes = build_nodes(on_nodes) + # @steps_nodes = build_nodes(params_nodes) + # yaml = ERB.new(File.read(File.join(Rails.root, "app/views/api/v1/projects/pipelines", "build_pipeline.yaml.erb"))).result(binding) + # # 删除空行内容 + # @pipeline_yaml = yaml.gsub(/^\s*\n/, "") + @pipeline_yaml = build_test_yaml + render plain: @pipeline_yaml + # respond_to do |format| + # format.text { render yaml: @pipeline_yaml } + # end + end + def update @pipeline = Action::Pipeline.find(params[:id]) @pipeline.update!(pipeline_name: params[:pipeline_name]) @@ -42,7 +59,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController def show @pipeline = Action::Pipeline.find_by(id: params[:id]) - @pipeline = Action::Pipeline.new(id: 0, pipeline_name: "test-ss", yaml: build_yaml) if @pipeline.blank? + @pipeline = Action::Pipeline.new(id: 0, pipeline_name: "test-ss", yaml: build_test_yaml) if @pipeline.blank? end def build_pipeline_yaml(pipeline) @@ -61,7 +78,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController @pipeline_yaml end - def build_yaml + def build_test_yaml @name = "love me" params_nodes = JSON.parse(demo.to_json)["nodes"].select { |node| !["on-push", "on-schedule"].include?(node["component_name"]) } on_nodes = JSON.parse(demo.to_json)["nodes"].select { |node| ["on-push", "on-schedule"].include?(node["component_name"]) } @@ -71,16 +88,23 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController # Rails.logger.info "input_node=====0===#{input_node["component_name"]}======#{input_node["in_parameters"]}" node = Action::Node.find_by(name: input_node["component_name"]) node.cust_name = input_node["component_label"] if input_node["component_label"].present? + run_values = {} input_values = {} if input_node["in_parameters"].present? # Rails.logger.info "@in_parameters=====11===#{input_node["component_name"]}======#{input_node["in_parameters"]}" input_node["in_parameters"].each_key do |input_key| # Rails.logger.info "@in_parameters.input_key===#{input_key}" # Rails.logger.info "@in_parameters.input_value===#{input_node["in_parameters"][input_key]["value"]}" - input_values = input_values.merge({ "#{input_key.gsub("--", "")}": "#{input_node["in_parameters"][input_key]["value"]}" }) + if input_key.to_s.gsub("--", "") == "run" + run_values = run_values.merge({ "#{input_key.gsub("--", "")}": "#{input_node["in_parameters"][input_key]["value"]}" }) + else + input_values = input_values.merge({ "#{input_key.gsub("--", "")}": "#{input_node["in_parameters"][input_key]["value"]}" }) + end end + node.run_values = run_values node.input_values = input_values - # Rails.logger.info "@input_values node===#{node.input_values.to_json}" + # Rails.logger.info "@input_values run_values===#{node.run_values.to_json}" + # Rails.logger.info "@input_values input_values===#{node.input_values.to_json}" end @steps_nodes.push(node) end @@ -124,14 +148,20 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController params_nodes.each do |input_node| node = Action::Node.find_by(name: input_node["component_name"]) node.cust_name = input_node["component_label"] if input_node["component_label"].present? + run_values = {} input_values = {} if input_node["in_parameters"].present? # Rails.logger.info "@in_parameters=====11===#{input_node["component_name"]}======#{input_node["in_parameters"]}" input_node["in_parameters"].each_key do |input_key| # Rails.logger.info "@in_parameters.input_key===#{input_key}" # Rails.logger.info "@in_parameters.input_value===#{input_node["in_parameters"][input_key]["value"]}" - input_values = input_values.merge({ "#{input_key.gsub("--", "")}": "#{input_node["in_parameters"][input_key]["value"]}" }) + if input_key.to_s.gsub("--", "") == "run" + run_values = run_values.merge({ "#{input_key.gsub("--", "")}": "#{input_node["in_parameters"][input_key]["value"]}" }) + else + input_values = input_values.merge({ "#{input_key.gsub("--", "")}": "#{input_node["in_parameters"][input_key]["value"]}" }) + end end + node.run_values = run_values # Rails.logger.info "@input_values node1===#{input_values}" node.input_values = input_values # Rails.logger.info "@input_values node===#{node.input_values.to_json}" @@ -365,8 +395,8 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController { "id": "git-clone-245734ab", "category_id": 1, - "component_name": "scp", - "component_label": "scp", + "component_name": "shell", + "component_label": "执行shell命令", "working_directory": "", "command": "", "in_parameters": { @@ -381,7 +411,30 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController "describe": "代码仓库地址", "editable": 1, "condition": "", - "value": "service nginx restart" + "value": "echo env" + } + } + }, + { + "id": "git-clone-245734ab", + "category_id": 1, + "component_name": "scp", + "component_label": "scp", + "working_directory": "", + "command": "", + "in_parameters": { + "--host": { + "type": "str", + "item_type": "", + "label": "代码仓库地址", + "require": 1, + "choice": [], + "default": "", + "placeholder": "私有仓库填写ssh地址,公有仓库填写https git地址", + "describe": "代码仓库地址", + "editable": 1, + "condition": "", + "value": "192.168.1.114" } } } diff --git a/app/models/action/node.rb b/app/models/action/node.rb index 601749047..07d3be134 100644 --- a/app/models/action/node.rb +++ b/app/models/action/node.rb @@ -34,7 +34,7 @@ class Action::Node < ApplicationRecord belongs_to :user, optional: true - attr_accessor :cust_name, :input_values + attr_accessor :cust_name, :run_values, :input_values def content_yaml diff --git a/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb b/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb index be8a7106e..f443a8f6f 100644 --- a/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb +++ b/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb @@ -45,11 +45,18 @@ jobs: steps: <%@steps_nodes.each do |node| %> - name: <%=node.cust_name || node.name %> + <% if node.name !="shell" %> uses: <%=node.full_name %> + <% end %> <%if node.input_values.present? %> with: <% node.input_values.each_key do |key| %> - <%=key %>: <%=node.input_values[key] %> + <%=key %>: '<%=node.input_values[key] %>' + <%end %> + <%end %> + <%if node.run_values.present? %> + <% node.run_values.each_key do |key| %> + <%=key %>: '<%=node.run_values[key] %>' <%end %> <%end %> <% end %> diff --git a/config/routes/api.rb b/config/routes/api.rb index 4db29cf06..bb093a23e 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -129,7 +129,9 @@ defaults format: :json do end end end - resources :pipelines + resources :pipelines do + get :build_yaml, on: :collection + end resources :pulls, module: 'pulls' do resources :versions, only: [:index] do member do From 6f25498c292be88c8a82d4384e5338f871791206 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 20 May 2024 08:46:33 +0800 Subject: [PATCH 171/294] =?UTF-8?q?fixed=20issues=5Fcount=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E4=B8=8D=E5=8C=85=E5=90=AB=E5=91=A8=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/projects_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index 4bc90bc77..2c343cf3a 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -21,7 +21,7 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController end @participant_category_count = {} if params[:participant_category].to_s == "authoredme" or params[:participant_category].to_s == "assignedme" - issues_category = @issues.joins(:issue_participants).where(issue_participants: {participant_type: %w[authored assigned atme], participant_id: current_user&.id}) + issues_category = @issues.joins(:issue_participants).where(pm_issue_type: [1, 2, 3]).where(issue_participants: {participant_type: %w[authored assigned atme], participant_id: current_user&.id}) @participant_category_count = issues_category.group(:pm_project_id, "issue_participants.participant_type").count end case params[:participant_category].to_s From eb5c2a6b8bacdc6d9e7532ef568dd1c44704b8e8 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 22 May 2024 14:35:22 +0800 Subject: [PATCH 172/294] =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/pipelines_controller.rb | 26 +++++++++---------- config/routes/api.rb | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 39f20a009..bfa08ab5e 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -23,20 +23,20 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController end def build_yaml - # pipeline = params[:pipeline] - # @name = params[:name] - # params_nodes = JSON.parse(pipeline)["nodes"].select { |node| !["on-push", "on-schedule"].include?(node["component_name"]) } - # on_nodes = JSON.parse(pipeline)["nodes"].select { |node| ["on-push", "on-schedule"].include?(node["component_name"]) } - # @on_nodes = build_nodes(on_nodes) - # @steps_nodes = build_nodes(params_nodes) - # yaml = ERB.new(File.read(File.join(Rails.root, "app/views/api/v1/projects/pipelines", "build_pipeline.yaml.erb"))).result(binding) - # # 删除空行内容 - # @pipeline_yaml = yaml.gsub(/^\s*\n/, "") - @pipeline_yaml = build_test_yaml + if params[:pipeline].present? + pipeline = params[:pipeline] + @name = params[:name] + params_nodes = JSON.parse(pipeline)["nodes"].select { |node| !["on-push", "on-schedule"].include?(node["component_name"]) } + on_nodes = JSON.parse(pipeline)["nodes"].select { |node| ["on-push", "on-schedule"].include?(node["component_name"]) } + @on_nodes = build_nodes(on_nodes) + @steps_nodes = build_nodes(params_nodes) + yaml = ERB.new(File.read(File.join(Rails.root, "app/views/api/v1/projects/pipelines", "build_pipeline.yaml.erb"))).result(binding) + # # 删除空行内容 + @pipeline_yaml = yaml.gsub(/^\s*\n/, "") + else + @pipeline_yaml = build_test_yaml + end render plain: @pipeline_yaml - # respond_to do |format| - # format.text { render yaml: @pipeline_yaml } - # end end def update diff --git a/config/routes/api.rb b/config/routes/api.rb index bb093a23e..826468776 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -130,7 +130,7 @@ defaults format: :json do end end resources :pipelines do - get :build_yaml, on: :collection + post :build_yaml, on: :collection end resources :pulls, module: 'pulls' do resources :versions, only: [:index] do From 656c44647157da1505e06b1237ac129b5797235d Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 22 May 2024 14:45:53 +0800 Subject: [PATCH 173/294] =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BF,=E9=A1=B9=E7=9B=AE=E5=BC=80=E5=8F=91=E8=80=85?= =?UTF-8?q?=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index bfa08ab5e..3114f4f8a 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -1,5 +1,5 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController - before_action :require_manager_above + before_action :require_operate_above def index @pipelines = Action::Pipeline.where(project_id: @project.id).order(updated_at: :desc) From b0785014602f2e677cb9c079b1edbfedc265d3e3 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 22 May 2024 15:10:35 +0800 Subject: [PATCH 174/294] =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BF=E8=8A=82=E7=82=B9icon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/action/nodes/index.json.jbuilder | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/action/nodes/index.json.jbuilder b/app/views/action/nodes/index.json.jbuilder index 3909639ce..b81879e20 100644 --- a/app/views/action/nodes/index.json.jbuilder +++ b/app/views/action/nodes/index.json.jbuilder @@ -2,7 +2,7 @@ json.types @node_types.each do |node_type| if node_type.name.to_s == "未分类" json.extract! node_type, :id, :name json.nodes @no_type_nodes do |node| - json.extract! node, :id, :name, :full_name, :description, :action_node_types_id, :yaml, :sort_no, :use_count + json.extract! node, :id, :name, :full_name, :description, :icon, :action_node_types_id, :yaml, :sort_no, :use_count json.inputs node.action_node_inputs do |node_input| json.partial! "node_input", locals: { node_input: node_input, node: node } end @@ -10,7 +10,7 @@ json.types @node_types.each do |node_type| else json.extract! node_type, :id, :name json.nodes node_type.action_nodes do |node| - json.extract! node, :id, :name, :full_name, :description, :action_node_types_id, :yaml, :sort_no, :use_count + json.extract! node, :id, :name, :full_name, :description, :icon, :action_node_types_id, :yaml, :sort_no, :use_count json.inputs node.action_node_inputs do |node_input| json.partial! "node_input", locals: { node_input: node_input, node: node } end From 47c4d30cf7957788b8aa67992e39bf2100e0912b Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 22 May 2024 15:47:44 +0800 Subject: [PATCH 175/294] =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BF=E8=8A=82=E7=82=B9icon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 3114f4f8a..4807ba2e6 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -23,6 +23,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController end def build_yaml + Rails.logger.info("pipeline===========#{params[:pipeline].present?}") if params[:pipeline].present? pipeline = params[:pipeline] @name = params[:name] From 4ad6b265c717e1ec96c18b4ae244f5cb54b0a876 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 22 May 2024 16:11:21 +0800 Subject: [PATCH 176/294] =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BFjson=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 4807ba2e6..296166e52 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -23,9 +23,9 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController end def build_yaml - Rails.logger.info("pipeline===========#{params[:pipeline].present?}") - if params[:pipeline].present? - pipeline = params[:pipeline] + Rails.logger.info("pipeline===========#{params[:pipeline_json].present?}") + if params[:pipeline_json].present? + pipeline = params[:pipeline_json] @name = params[:name] params_nodes = JSON.parse(pipeline)["nodes"].select { |node| !["on-push", "on-schedule"].include?(node["component_name"]) } on_nodes = JSON.parse(pipeline)["nodes"].select { |node| ["on-push", "on-schedule"].include?(node["component_name"]) } From 6ba2394c1602291dc5bea46120850780ffac8fbd Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 22 May 2024 16:17:01 +0800 Subject: [PATCH 177/294] =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BFjson=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 296166e52..d49e6b5be 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -23,7 +23,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController end def build_yaml - Rails.logger.info("pipeline===========#{params[:pipeline_json].present?}") + Rails.logger.info("pipeline===========#{params[:pipeline_json]}") if params[:pipeline_json].present? pipeline = params[:pipeline_json] @name = params[:name] From 329511ac4b953ffa6fc438b4ff65fac7c527b20d Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 22 May 2024 16:19:56 +0800 Subject: [PATCH 178/294] =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BFjson=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index d49e6b5be..9bb74dc7e 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -27,8 +27,8 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController if params[:pipeline_json].present? pipeline = params[:pipeline_json] @name = params[:name] - params_nodes = JSON.parse(pipeline)["nodes"].select { |node| !["on-push", "on-schedule"].include?(node["component_name"]) } - on_nodes = JSON.parse(pipeline)["nodes"].select { |node| ["on-push", "on-schedule"].include?(node["component_name"]) } + params_nodes = JSON.parse(pipeline.to_json)["nodes"].select { |node| !["on-push", "on-schedule"].include?(node["component_name"]) } + on_nodes = JSON.parse(pipeline.to_json)["nodes"].select { |node| ["on-push", "on-schedule"].include?(node["component_name"]) } @on_nodes = build_nodes(on_nodes) @steps_nodes = build_nodes(params_nodes) yaml = ERB.new(File.read(File.join(Rails.root, "app/views/api/v1/projects/pipelines", "build_pipeline.yaml.erb"))).result(binding) From 87604a1dea82d0df8bac9a6e6d249fb4cc1ac666 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 22 May 2024 16:22:43 +0800 Subject: [PATCH 179/294] =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BFjson=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 9bb74dc7e..4966254f4 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -88,6 +88,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController params_nodes.each do |input_node| # Rails.logger.info "input_node=====0===#{input_node["component_name"]}======#{input_node["in_parameters"]}" node = Action::Node.find_by(name: input_node["component_name"]) + next if node.blank? node.cust_name = input_node["component_label"] if input_node["component_label"].present? run_values = {} input_values = {} @@ -148,6 +149,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController steps_nodes = [] params_nodes.each do |input_node| node = Action::Node.find_by(name: input_node["component_name"]) + next if node.blank? node.cust_name = input_node["component_label"] if input_node["component_label"].present? run_values = {} input_values = {} From 801dbd3f2f4c3e56d76162f67f5f52ef10be87ea Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 22 May 2024 17:24:15 +0800 Subject: [PATCH 180/294] =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BFyaml=EF=BC=8C=E4=BF=9D=E5=AD=98=E5=92=8C=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/pipelines_controller.rb | 55 ++++++++++--------- .../pipelines/build_pipeline.yaml.erb | 2 +- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 4966254f4..19ed03237 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -11,29 +11,34 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController tip_exception("已经存在#{params[:pipeline_name]}流水线!") if size > 0 @pipeline = Action::Pipeline.new(pipeline_name: params[:pipeline_name], project_id: @project.id) @pipeline.file_name = ".gitea/workflows/#{@pipeline.pipeline_name}.yaml" - @pipeline.json = demo.to_json - # @pipeline.json = params[:json] if params[:json] - @pipeline.yaml = build_pipeline_yaml(@pipeline) + @pipeline.json = params[:pipeline_json].to_json + pipeline_yaml = build_pipeline_yaml(params[:pipeline_name], params[:pipeline_json]) + tip_exception("流水线yaml内空不能为空") if pipeline_yaml.blank? + @pipeline.yaml = pipeline_yaml @pipeline.save! sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch) tip_exception("#{@pipeline.file_name}已存在") if sha - interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params) + interactor = Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params) tip_exception(interactor.error) unless interactor.success? render_ok({ id: @pipeline.id }) end + def save_yaml + @pipeline = Action::Pipeline.new(pipeline_name: params[:pipeline_name], project_id: @project.id) + @pipeline.file_name = ".gitea/workflows/#{@pipeline.pipeline_name}.yaml" + @pipeline.json = params[:pipeline_json].to_json + pipeline_yaml = build_pipeline_yaml(params[:pipeline_name], params[:pipeline_json]) + tip_exception("流水线yaml内空不能为空") if pipeline_yaml.blank? + @pipeline.yaml = pipeline_yaml + sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch) + interactor = sha.present? ? Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params) : Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params) + tip_exception(interactor.error) unless interactor.success? + render_ok + end + def build_yaml - Rails.logger.info("pipeline===========#{params[:pipeline_json]}") if params[:pipeline_json].present? - pipeline = params[:pipeline_json] - @name = params[:name] - params_nodes = JSON.parse(pipeline.to_json)["nodes"].select { |node| !["on-push", "on-schedule"].include?(node["component_name"]) } - on_nodes = JSON.parse(pipeline.to_json)["nodes"].select { |node| ["on-push", "on-schedule"].include?(node["component_name"]) } - @on_nodes = build_nodes(on_nodes) - @steps_nodes = build_nodes(params_nodes) - yaml = ERB.new(File.read(File.join(Rails.root, "app/views/api/v1/projects/pipelines", "build_pipeline.yaml.erb"))).result(binding) - # # 删除空行内容 - @pipeline_yaml = yaml.gsub(/^\s*\n/, "") + @pipeline_yaml = build_pipeline_yaml(params[:pipeline_name], params[:pipeline_json]) else @pipeline_yaml = build_test_yaml end @@ -63,24 +68,24 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController @pipeline = Action::Pipeline.new(id: 0, pipeline_name: "test-ss", yaml: build_test_yaml) if @pipeline.blank? end - def build_pipeline_yaml(pipeline) - if pipeline.json.present? - @name = pipeline.pipeline_name - params_nodes = JSON.parse(pipeline.json)["nodes"].select { |node| !["on-push", "on-schedule"].include?(node["component_name"]) } - on_nodes = JSON.parse(pipeline.json)["nodes"].select { |node| ["on-push", "on-schedule"].include?(node["component_name"]) } + def build_pipeline_yaml(pipeline_name, pipeline_json) + if pipeline_json.present? + @pipeline_name = pipeline_name + params_nodes = pipeline_json["nodes"].select { |node| !["on-push", "on-schedule"].include?(node["component_name"]) } + on_nodes = pipeline_json["nodes"].select { |node| ["on-push", "on-schedule"].include?(node["component_name"]) } @on_nodes = build_nodes(on_nodes) @steps_nodes = build_nodes(params_nodes) yaml = ERB.new(File.read(File.join(Rails.root, "app/views/api/v1/projects/pipelines", "build_pipeline.yaml.erb"))).result(binding) # 删除空行内容 @pipeline_yaml = yaml.gsub(/^\s*\n/, "") else - @pipeline_yaml = params[:yaml] + @pipeline_yaml = params[:pipeline_yaml] end @pipeline_yaml end def build_test_yaml - @name = "love me" + @pipeline_name = "I like it" params_nodes = JSON.parse(demo.to_json)["nodes"].select { |node| !["on-push", "on-schedule"].include?(node["component_name"]) } on_nodes = JSON.parse(demo.to_json)["nodes"].select { |node| ["on-push", "on-schedule"].include?(node["component_name"]) } @on_nodes = build_nodes(on_nodes) @@ -135,7 +140,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController filepath: ".gitea/workflows/#{@pipeline.pipeline_name}.yaml", branch: @pipeline.branch, new_branch: @pipeline.branch, - content: build_pipeline_yaml(@pipeline), + content: @pipeline.yaml, message: 'create pipeline', committer: { email: current_user.mail, @@ -154,8 +159,8 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController run_values = {} input_values = {} if input_node["in_parameters"].present? - # Rails.logger.info "@in_parameters=====11===#{input_node["component_name"]}======#{input_node["in_parameters"]}" - input_node["in_parameters"].each_key do |input_key| + Rails.logger.info "@in_parameters=====11===#{input_node["component_name"]}======#{input_node["in_parameters"].keys}" + input_node["in_parameters"].keys.each do |input_key| # Rails.logger.info "@in_parameters.input_key===#{input_key}" # Rails.logger.info "@in_parameters.input_value===#{input_node["in_parameters"][input_key]["value"]}" if input_key.to_s.gsub("--", "") == "run" @@ -185,7 +190,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController "working_directory": "", "command": "", "in_parameters": { - "--cro": { + "--cron": { "type": "str", "item_type": "", "label": "push代码", diff --git a/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb b/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb index f443a8f6f..149d7a6be 100644 --- a/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb +++ b/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb @@ -1,5 +1,5 @@ # action name -name: <%=@name %> +name: <%=@pipeline_name %> # 什么时候触发这个workflow on: From 08fe69ca375aad78a7ed6d65b73e5423cbdc4751 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 22 May 2024 17:29:02 +0800 Subject: [PATCH 181/294] =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BFyaml=EF=BC=8C=E4=BF=9D=E5=AD=98=E5=92=8C=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/routes/api.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/routes/api.rb b/config/routes/api.rb index 826468776..6df7dc8a3 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -131,6 +131,7 @@ defaults format: :json do end resources :pipelines do post :build_yaml, on: :collection + post :save_yaml, on: :collection end resources :pulls, module: 'pulls' do resources :versions, only: [:index] do From 4c956e48aee745be494c4836cbf04d3b05831e6d Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 22 May 2024 17:34:18 +0800 Subject: [PATCH 182/294] =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BFyaml=EF=BC=8C=E4=BF=9D=E5=AD=98=E5=92=8C=E6=9B=B4?= =?UTF-8?q?=E6=96=B0,=E5=88=86=E6=94=AF=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 19ed03237..97a671d52 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -11,6 +11,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController tip_exception("已经存在#{params[:pipeline_name]}流水线!") if size > 0 @pipeline = Action::Pipeline.new(pipeline_name: params[:pipeline_name], project_id: @project.id) @pipeline.file_name = ".gitea/workflows/#{@pipeline.pipeline_name}.yaml" + @pipeline.branch = params[:branch] || @project.default_branch @pipeline.json = params[:pipeline_json].to_json pipeline_yaml = build_pipeline_yaml(params[:pipeline_name], params[:pipeline_json]) tip_exception("流水线yaml内空不能为空") if pipeline_yaml.blank? @@ -26,6 +27,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController def save_yaml @pipeline = Action::Pipeline.new(pipeline_name: params[:pipeline_name], project_id: @project.id) @pipeline.file_name = ".gitea/workflows/#{@pipeline.pipeline_name}.yaml" + @pipeline.branch = params[:branch] || @project.default_branch @pipeline.json = params[:pipeline_json].to_json pipeline_yaml = build_pipeline_yaml(params[:pipeline_name], params[:pipeline_json]) tip_exception("流水线yaml内空不能为空") if pipeline_yaml.blank? @@ -128,7 +130,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController def get_pipeline_file_sha(file_name, branch) file_path_uri = URI.parse(file_name) - interactor = Repositories::EntriesInteractor.call(@project.owner, @project.identifier, file_path_uri, ref: branch || 'master') + interactor = Repositories::EntriesInteractor.call(@project.owner, @project.identifier, file_path_uri, ref: branch || @project.default_branch) if interactor.success? file = interactor.result file['sha'] From f55d69d5cf522e04a7c2d644366b51255619e8fc Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 23 May 2024 09:20:48 +0800 Subject: [PATCH 183/294] =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BFyaml=EF=BC=8C=E4=BF=9D=E5=AD=98=E5=92=8C=E6=9B=B4?= =?UTF-8?q?=E6=96=B0,=E5=88=86=E6=94=AF=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 97a671d52..4f2895843 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -134,12 +134,14 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController if interactor.success? file = interactor.result file['sha'] + else + nil end end def content_params { - filepath: ".gitea/workflows/#{@pipeline.pipeline_name}.yaml", + filepath: ".gitea/workflows/#{URI.parse(@pipeline.pipeline_name)}.yaml", branch: @pipeline.branch, new_branch: @pipeline.branch, content: @pipeline.yaml, From 2b7414c2fc1a7833a2cf131a523b266f9695f5e4 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 23 May 2024 09:23:21 +0800 Subject: [PATCH 184/294] =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BFyaml=EF=BC=8C=E4=BF=9D=E5=AD=98=E5=92=8C=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=20log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 4f2895843..24a288dd1 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -18,6 +18,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController @pipeline.yaml = pipeline_yaml @pipeline.save! sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch) + Rails.logger.info "sha==========#{sha}" tip_exception("#{@pipeline.file_name}已存在") if sha interactor = Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params) tip_exception(interactor.error) unless interactor.success? From 15513718f9cacf7969e201921760213f5c0ebdbf Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 23 May 2024 09:51:04 +0800 Subject: [PATCH 185/294] =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BFyaml=EF=BC=8C=E4=BF=9D=E5=AD=98=E5=92=8C=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=20log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 24a288dd1..c1edcbbd2 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -34,6 +34,8 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController tip_exception("流水线yaml内空不能为空") if pipeline_yaml.blank? @pipeline.yaml = pipeline_yaml sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch) + Rails.logger.info "sha==========#{sha}" + Rails.logger.info "sha==========#{sha.present?}" interactor = sha.present? ? Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params) : Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params) tip_exception(interactor.error) unless interactor.success? render_ok From 8760e46c4b3e3ad8d12ba10209b565b8b72c60dd Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 23 May 2024 10:44:48 +0800 Subject: [PATCH 186/294] =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BFyaml=20base64?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index c1edcbbd2..6cd4bff67 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -18,7 +18,6 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController @pipeline.yaml = pipeline_yaml @pipeline.save! sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch) - Rails.logger.info "sha==========#{sha}" tip_exception("#{@pipeline.file_name}已存在") if sha interactor = Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params) tip_exception(interactor.error) unless interactor.success? @@ -34,8 +33,6 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController tip_exception("流水线yaml内空不能为空") if pipeline_yaml.blank? @pipeline.yaml = pipeline_yaml sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch) - Rails.logger.info "sha==========#{sha}" - Rails.logger.info "sha==========#{sha.present?}" interactor = sha.present? ? Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params) : Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params) tip_exception(interactor.error) unless interactor.success? render_ok @@ -147,7 +144,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController filepath: ".gitea/workflows/#{URI.parse(@pipeline.pipeline_name)}.yaml", branch: @pipeline.branch, new_branch: @pipeline.branch, - content: @pipeline.yaml, + content: Base64.encode64(@pipeline.yaml), message: 'create pipeline', committer: { email: current_user.mail, From da831ec6e75762a319c4235c538cbc3e0f5327f9 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 23 May 2024 10:56:35 +0800 Subject: [PATCH 187/294] =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BFyaml=20=E6=9B=B4=E6=96=B0=E6=96=87=E4=BB=B6=E9=9C=80?= =?UTF-8?q?=E8=A6=81sha?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/pipelines_controller.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 6cd4bff67..fb5eee64d 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -33,7 +33,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController tip_exception("流水线yaml内空不能为空") if pipeline_yaml.blank? @pipeline.yaml = pipeline_yaml sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch) - interactor = sha.present? ? Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params) : Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params) + interactor = sha.present? ? Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params.merge(sha: sha)) : Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params) tip_exception(interactor.error) unless interactor.success? render_ok end @@ -49,8 +49,16 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController def update @pipeline = Action::Pipeline.find(params[:id]) - @pipeline.update!(pipeline_name: params[:pipeline_name]) - interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params) + @pipeline.pipeline_name = params[:pipeline_name] + @pipeline.file_name = ".gitea/workflows/#{@pipeline.pipeline_name}.yaml" + @pipeline.branch = params[:branch] || @project.default_branch + @pipeline.json = params[:pipeline_json].to_json + pipeline_yaml = build_pipeline_yaml(params[:pipeline_name], params[:pipeline_json]) + tip_exception("流水线yaml内空不能为空") if pipeline_yaml.blank? + @pipeline.yaml = pipeline_yaml + @pipeline.save + sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch) + interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params.merge(sha: sha)) tip_exception(interactor.error) unless interactor.success? render_ok end From 790a7eeb8c9ee5f7d0628bc1b5c6cb9827afa24a Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 23 May 2024 11:26:59 +0800 Subject: [PATCH 188/294] =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BFyaml,=20=E4=B8=AD=E6=96=87=E6=96=87=E4=BB=B6=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/pipelines_controller.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index fb5eee64d..cc90f8a10 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -19,7 +19,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController @pipeline.save! sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch) tip_exception("#{@pipeline.file_name}已存在") if sha - interactor = Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params) + interactor = Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("create")) tip_exception(interactor.error) unless interactor.success? render_ok({ id: @pipeline.id }) end @@ -33,7 +33,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController tip_exception("流水线yaml内空不能为空") if pipeline_yaml.blank? @pipeline.yaml = pipeline_yaml sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch) - interactor = sha.present? ? Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params.merge(sha: sha)) : Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params) + interactor = sha.present? ? Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("update").merge(sha: sha)) : Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("create")) tip_exception(interactor.error) unless interactor.success? render_ok end @@ -58,7 +58,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController @pipeline.yaml = pipeline_yaml @pipeline.save sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch) - interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params.merge(sha: sha)) + interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("create").merge(sha: sha)) tip_exception(interactor.error) unless interactor.success? render_ok end @@ -66,7 +66,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController def destroy @pipeline = Action::Pipeline.find(params[:id]) if pipeline - interactor = Gitea::DeleteFileInteractor.call(current_user.gitea_token, @owner.login, content_params) + interactor = Gitea::DeleteFileInteractor.call(current_user.gitea_token, @owner.login, content_params("update")) tip_exception(interactor.error) unless interactor.success? @pipeline.destroy! end @@ -147,13 +147,13 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController end end - def content_params + def content_params(opt) { - filepath: ".gitea/workflows/#{URI.parse(@pipeline.pipeline_name)}.yaml", + filepath: ".gitea/workflows/#{@pipeline.pipeline_name}.yaml", branch: @pipeline.branch, new_branch: @pipeline.branch, content: Base64.encode64(@pipeline.yaml), - message: 'create pipeline', + message: "#{opt} pipeline", committer: { email: current_user.mail, name: current_user.login From 8c077ef9a804020e7709948e5cd04402e886f048 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 23 May 2024 16:25:20 +0800 Subject: [PATCH 189/294] =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BFyaml,=20=E8=BF=94=E5=9B=9Ejson?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/pipelines_controller.rb | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index cc90f8a10..185120501 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -10,7 +10,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController size = Action::Pipeline.where(pipeline_name: params[:pipeline_name], project_id: @project.id).size tip_exception("已经存在#{params[:pipeline_name]}流水线!") if size > 0 @pipeline = Action::Pipeline.new(pipeline_name: params[:pipeline_name], project_id: @project.id) - @pipeline.file_name = ".gitea/workflows/#{@pipeline.pipeline_name}.yaml" + @pipeline.file_name = ".gitea/workflows/#{@pipeline.pipeline_name}.yml" @pipeline.branch = params[:branch] || @project.default_branch @pipeline.json = params[:pipeline_json].to_json pipeline_yaml = build_pipeline_yaml(params[:pipeline_name], params[:pipeline_json]) @@ -26,7 +26,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController def save_yaml @pipeline = Action::Pipeline.new(pipeline_name: params[:pipeline_name], project_id: @project.id) - @pipeline.file_name = ".gitea/workflows/#{@pipeline.pipeline_name}.yaml" + @pipeline.file_name = ".gitea/workflows/#{@pipeline.pipeline_name}.yml" @pipeline.branch = params[:branch] || @project.default_branch @pipeline.json = params[:pipeline_json].to_json pipeline_yaml = build_pipeline_yaml(params[:pipeline_name], params[:pipeline_json]) @@ -35,22 +35,23 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch) interactor = sha.present? ? Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("update").merge(sha: sha)) : Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("create")) tip_exception(interactor.error) unless interactor.success? - render_ok + render_ok({ pipeline_yaml: pipeline_yaml }) end def build_yaml if params[:pipeline_json].present? - @pipeline_yaml = build_pipeline_yaml(params[:pipeline_name], params[:pipeline_json]) + pipeline_yaml = build_pipeline_yaml(params[:pipeline_name], params[:pipeline_json]) else - @pipeline_yaml = build_test_yaml + pipeline_yaml = build_test_yaml end - render plain: @pipeline_yaml + # render plain: pipeline_yaml + render_ok({ pipeline_yaml: pipeline_yaml }) end def update @pipeline = Action::Pipeline.find(params[:id]) @pipeline.pipeline_name = params[:pipeline_name] - @pipeline.file_name = ".gitea/workflows/#{@pipeline.pipeline_name}.yaml" + @pipeline.file_name = ".gitea/workflows/#{@pipeline.pipeline_name}.yml" @pipeline.branch = params[:branch] || @project.default_branch @pipeline.json = params[:pipeline_json].to_json pipeline_yaml = build_pipeline_yaml(params[:pipeline_name], params[:pipeline_json]) @@ -87,11 +88,11 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController @steps_nodes = build_nodes(params_nodes) yaml = ERB.new(File.read(File.join(Rails.root, "app/views/api/v1/projects/pipelines", "build_pipeline.yaml.erb"))).result(binding) # 删除空行内容 - @pipeline_yaml = yaml.gsub(/^\s*\n/, "") + pipeline_yaml = yaml.gsub(/^\s*\n/, "") else - @pipeline_yaml = params[:pipeline_yaml] + pipeline_yaml = params[:pipeline_yaml] end - @pipeline_yaml + pipeline_yaml end def build_test_yaml @@ -128,10 +129,10 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController Rails.logger.info "@@on_nodes===#{@on_nodes.to_json}" Rails.logger.info "@steps_nodes===#{@steps_nodes.to_json}" yaml = ERB.new(File.read(File.join(Rails.root, "app/views/api/v1/projects/pipelines", "build_pipeline.yaml.erb"))).result(binding) - @pipeline_yaml = yaml.gsub(/^\s*\n/, "") + pipeline_yaml = yaml.gsub(/^\s*\n/, "") Rails.logger.info "=========================" - Rails.logger.info @pipeline_yaml - @pipeline_yaml + Rails.logger.info pipeline_yaml + pipeline_yaml end private @@ -149,7 +150,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController def content_params(opt) { - filepath: ".gitea/workflows/#{@pipeline.pipeline_name}.yaml", + filepath: ".gitea/workflows/#{@pipeline.pipeline_name}.yml", branch: @pipeline.branch, new_branch: @pipeline.branch, content: Base64.encode64(@pipeline.yaml), From d2c44ed163f8e4a7ac956324c17b75311fba7789 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 23 May 2024 16:26:09 +0800 Subject: [PATCH 190/294] =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BFyaml,=20=E8=BF=94=E5=9B=9Ejson?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 185120501..6f7bbb618 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -138,7 +138,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController private def get_pipeline_file_sha(file_name, branch) - file_path_uri = URI.parse(file_name) + file_path_uri = URI.parse(URI.encode(file_name)) interactor = Repositories::EntriesInteractor.call(@project.owner, @project.identifier, file_path_uri, ref: branch || @project.default_branch) if interactor.success? file = interactor.result From a6343d54428b82e166472ee1922c3207706a3e02 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 23 May 2024 16:40:43 +0800 Subject: [PATCH 191/294] =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BFyaml,=20=E8=BF=94=E5=9B=9Ejson?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 6f7bbb618..14b56350f 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -153,7 +153,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController filepath: ".gitea/workflows/#{@pipeline.pipeline_name}.yml", branch: @pipeline.branch, new_branch: @pipeline.branch, - content: Base64.encode64(@pipeline.yaml), + content: @pipeline.yaml, message: "#{opt} pipeline", committer: { email: current_user.mail, From 0d0f25777a741819152b01cd7e8c63cacb82bed8 Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Thu, 23 May 2024 17:20:30 +0800 Subject: [PATCH 192/294] =?UTF-8?q?=E6=96=B0=E5=A2=9Eissue=20=E5=85=B3?= =?UTF-8?q?=E8=81=94=20=E4=BF=AE=E5=A4=8Dpm=E5=B7=A5=E4=BD=9C=E9=A1=B9?= =?UTF-8?q?=E8=A2=AB=E5=88=A0=E9=99=A4=E5=90=8E=20=E5=85=B3=E8=81=94?= =?UTF-8?q?=E9=A1=B9=E4=BE=9D=E7=84=B6=E8=BF=98=E5=AD=98=E5=9C=A8=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/issue.rb | 1 + app/models/pm_link.rb | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 028ceb930..764708546 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -94,6 +94,7 @@ class Issue < ApplicationRecord has_many :attach_pull_requests, through: :pull_attached_issues, source: :pull_request # PM 关联工作项目 has_many :pm_links, as: :linkable, dependent: :destroy + has_many :be_pm_links,as: :be_linkable, dependent: :destroy belongs_to :changer, class_name: 'User', foreign_key: :changer_id, optional: true scope :issue_includes, ->{includes(:user)} diff --git a/app/models/pm_link.rb b/app/models/pm_link.rb index 91962bf7b..0e7d56b59 100644 --- a/app/models/pm_link.rb +++ b/app/models/pm_link.rb @@ -18,8 +18,9 @@ class PmLink < ApplicationRecord belongs_to :linkable, polymorphic: true + belongs_to :be_linkable, polymorphic: true - def be_linkable - be_linkable_type.constantize.find be_linkable_id - end + # def be_linkable + # be_linkable_type.constantize.find be_linkable_id + # end end From 907098619b9e547fde8976173230ca9db4cce04e Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Thu, 23 May 2024 17:39:42 +0800 Subject: [PATCH 193/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dissue=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/issue.rb | 8 ++++++-- app/models/pm_link.rb | 7 +++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 764708546..e7e15f4a7 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -94,7 +94,7 @@ class Issue < ApplicationRecord has_many :attach_pull_requests, through: :pull_attached_issues, source: :pull_request # PM 关联工作项目 has_many :pm_links, as: :linkable, dependent: :destroy - has_many :be_pm_links,as: :be_linkable, dependent: :destroy + belongs_to :changer, class_name: 'User', foreign_key: :changer_id, optional: true scope :issue_includes, ->{includes(:user)} @@ -107,7 +107,11 @@ class Issue < ApplicationRecord after_create :incre_project_common, :incre_user_statistic, :incre_platform_statistic before_save :check_pm_and_update_due_date after_save :change_versions_count, :send_update_message_to_notice_system, :associate_attachment_container, :generate_uuid - after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic + after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic, :destroy_be_pm_links + + def destroy_be_pm_links + PmLink.where(be_linkable_type:"Issue",be_linkable_id:self.id).map(&:destroy) + end def check_pm_and_update_due_date if pm_project_id.present? && pm_issue_type.present? && status_id_changed? diff --git a/app/models/pm_link.rb b/app/models/pm_link.rb index 0e7d56b59..91962bf7b 100644 --- a/app/models/pm_link.rb +++ b/app/models/pm_link.rb @@ -18,9 +18,8 @@ class PmLink < ApplicationRecord belongs_to :linkable, polymorphic: true - belongs_to :be_linkable, polymorphic: true - # def be_linkable - # be_linkable_type.constantize.find be_linkable_id - # end + def be_linkable + be_linkable_type.constantize.find be_linkable_id + end end From 52aeb9ec0704c875d41b12e3f9488b220f5d77ed Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Thu, 23 May 2024 17:39:42 +0800 Subject: [PATCH 194/294] =?UTF-8?q?merge=20=E4=BF=AE=E5=A4=8Dissue?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/issue.rb | 9 +++++++-- app/models/pm_link.rb | 7 +++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index e0f4a385e..4f160755f 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -94,7 +94,7 @@ class Issue < ApplicationRecord has_many :attach_pull_requests, through: :pull_attached_issues, source: :pull_request # PM 关联工作项目 has_many :pm_links, as: :linkable, dependent: :destroy - has_many :be_pm_links,as: :be_linkable, dependent: :destroy + belongs_to :changer, class_name: 'User', foreign_key: :changer_id, optional: true scope :issue_includes, ->{includes(:user)} @@ -106,8 +106,13 @@ class Issue < ApplicationRecord scope :opened, ->{where.not(status_id: 5)} after_create :incre_project_common, :incre_user_statistic, :incre_platform_statistic before_save :check_pm_and_update_due_date + after_save :incre_or_decre_closed_issues_count, :change_versions_count, :send_update_message_to_notice_system, :associate_attachment_container, :generate_uuid - after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic + after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic, :destroy_be_pm_links + + def destroy_be_pm_links + PmLink.where(be_linkable_type:"Issue",be_linkable_id:self.id).map(&:destroy) + end def check_pm_and_update_due_date if pm_project_id.present? && pm_issue_type.present? && status_id_changed? diff --git a/app/models/pm_link.rb b/app/models/pm_link.rb index 0e7d56b59..91962bf7b 100644 --- a/app/models/pm_link.rb +++ b/app/models/pm_link.rb @@ -18,9 +18,8 @@ class PmLink < ApplicationRecord belongs_to :linkable, polymorphic: true - belongs_to :be_linkable, polymorphic: true - # def be_linkable - # be_linkable_type.constantize.find be_linkable_id - # end + def be_linkable + be_linkable_type.constantize.find be_linkable_id + end end From 3b389480f4ca819fb91794dcc581b99457a472b6 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 24 May 2024 13:52:41 +0800 Subject: [PATCH 195/294] =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BFyaml,=20base64?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 14b56350f..ddeb5f146 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -153,7 +153,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController filepath: ".gitea/workflows/#{@pipeline.pipeline_name}.yml", branch: @pipeline.branch, new_branch: @pipeline.branch, - content: @pipeline.yaml, + content: Base64.encode64(@pipeline.yaml).gsub(/\n/, ''), message: "#{opt} pipeline", committer: { email: current_user.mail, From 8325fa73670a249d605ffe4376f98f8816d1f7fa Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 24 May 2024 15:31:29 +0800 Subject: [PATCH 196/294] =?UTF-8?q?=E8=81=94=E8=B0=83=E5=9B=BE=E5=BD=A2?= =?UTF-8?q?=E8=AE=BE=E8=AE=A1=E5=8C=96-=E6=9E=84=E5=BB=BA=E6=B5=81?= =?UTF-8?q?=E6=B0=B4=E7=BA=BFyaml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/pipelines_controller.rb | 730 +++++++----------- 1 file changed, 286 insertions(+), 444 deletions(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index ddeb5f146..c2efc36ae 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -82,8 +82,8 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController def build_pipeline_yaml(pipeline_name, pipeline_json) if pipeline_json.present? @pipeline_name = pipeline_name - params_nodes = pipeline_json["nodes"].select { |node| !["on-push", "on-schedule"].include?(node["component_name"]) } - on_nodes = pipeline_json["nodes"].select { |node| ["on-push", "on-schedule"].include?(node["component_name"]) } + params_nodes = pipeline_json["nodes"].select { |node| !["on-push", "on-schedule"].include?(node["name"]) } + on_nodes = pipeline_json["nodes"].select { |node| ["on-push", "on-schedule"].include?(node["name"]) } @on_nodes = build_nodes(on_nodes) @steps_nodes = build_nodes(params_nodes) yaml = ERB.new(File.read(File.join(Rails.root, "app/views/api/v1/projects/pipelines", "build_pipeline.yaml.erb"))).result(binding) @@ -97,26 +97,26 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController def build_test_yaml @pipeline_name = "I like it" - params_nodes = JSON.parse(demo.to_json)["nodes"].select { |node| !["on-push", "on-schedule"].include?(node["component_name"]) } - on_nodes = JSON.parse(demo.to_json)["nodes"].select { |node| ["on-push", "on-schedule"].include?(node["component_name"]) } + params_nodes = JSON.parse(demo.to_json)["nodes"].select { |node| !["on-push", "on-schedule"].include?(node["name"]) } + on_nodes = JSON.parse(demo.to_json)["nodes"].select { |node| ["on-push", "on-schedule"].include?(node["name"]) } @on_nodes = build_nodes(on_nodes) @steps_nodes = [] params_nodes.each do |input_node| - # Rails.logger.info "input_node=====0===#{input_node["component_name"]}======#{input_node["in_parameters"]}" - node = Action::Node.find_by(name: input_node["component_name"]) + # Rails.logger.info "input_node=====0===#{input_node["name"]}======#{input_node["inputs"]}" + node = Action::Node.find_by(name: input_node["name"]) next if node.blank? - node.cust_name = input_node["component_label"] if input_node["component_label"].present? + node.cust_name = input_node["label"] if input_node["label"].present? run_values = {} input_values = {} - if input_node["in_parameters"].present? - # Rails.logger.info "@in_parameters=====11===#{input_node["component_name"]}======#{input_node["in_parameters"]}" - input_node["in_parameters"].each_key do |input_key| - # Rails.logger.info "@in_parameters.input_key===#{input_key}" - # Rails.logger.info "@in_parameters.input_value===#{input_node["in_parameters"][input_key]["value"]}" - if input_key.to_s.gsub("--", "") == "run" - run_values = run_values.merge({ "#{input_key.gsub("--", "")}": "#{input_node["in_parameters"][input_key]["value"]}" }) + if input_node["inputs"].present? + Rails.logger.info "@inputs=====11===#{input_node["name"]}======#{input_node["inputs"]}" + input_node["inputs"].each do |input| + # Rails.logger.info "@inputs.input_name===#{input[:name]}" + # Rails.logger.info "@inputs.input_value===#{input["value"]}" + if input[:name].to_s.gsub("--", "") == "run" + run_values = run_values.merge({ "#{input[:name].gsub("--", "")}": "#{input["value"]}" }) else - input_values = input_values.merge({ "#{input_key.gsub("--", "")}": "#{input_node["in_parameters"][input_key]["value"]}" }) + input_values = input_values.merge({ "#{input[:name].gsub("--", "")}": "#{input["value"]}" }) end end node.run_values = run_values @@ -166,26 +166,24 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController def build_nodes(params_nodes) steps_nodes = [] params_nodes.each do |input_node| - node = Action::Node.find_by(name: input_node["component_name"]) + node = Action::Node.find_by(name: input_node["name"]) next if node.blank? - node.cust_name = input_node["component_label"] if input_node["component_label"].present? + node.cust_name = input_node["labelf"] if input_node["label"].present? run_values = {} input_values = {} - if input_node["in_parameters"].present? - Rails.logger.info "@in_parameters=====11===#{input_node["component_name"]}======#{input_node["in_parameters"].keys}" - input_node["in_parameters"].keys.each do |input_key| - # Rails.logger.info "@in_parameters.input_key===#{input_key}" - # Rails.logger.info "@in_parameters.input_value===#{input_node["in_parameters"][input_key]["value"]}" - if input_key.to_s.gsub("--", "") == "run" - run_values = run_values.merge({ "#{input_key.gsub("--", "")}": "#{input_node["in_parameters"][input_key]["value"]}" }) + if input_node["inputs"].present? + Rails.logger.info "@inputs=====11===#{input_node["name"]}======#{input_node["inputs"]}" + input_node["inputs"].each do |input| + # Rails.logger.info "@inputs.input_name===#{input[:name]}" + # Rails.logger.info "@inputs.input_value===#{input["value"]}" + if input[:name].to_s.gsub("--", "") == "run" + run_values = run_values.merge({ "#{input[:name].gsub("--", "")}": "#{input["value"]}" }) else - input_values = input_values.merge({ "#{input_key.gsub("--", "")}": "#{input_node["in_parameters"][input_key]["value"]}" }) + input_values = input_values.merge({ "#{input[:name].gsub("--", "")}": "#{input["value"]}" }) end end node.run_values = run_values - # Rails.logger.info "@input_values node1===#{input_values}" node.input_values = input_values - # Rails.logger.info "@input_values node===#{node.input_values.to_json}" end steps_nodes.push(node) end @@ -194,423 +192,267 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController def demo { - "nodes": [ - { - "id": "git-clone-245734ab", - "category_id": 1, - "component_name": "on-schedule", - "component_label": "触发器", - "working_directory": "", - "command": "", - "in_parameters": { - "--cron": { - "type": "str", - "item_type": "", - "label": "push代码", - "require": 1, - "choice": [], - "default": "", - "placeholder": "私有仓库填写ssh地址,公有仓库填写https git地址", - "describe": "代码仓库地址", - "editable": 1, - "condition": "", - "value": "15 4,5 * * *" - }, - "--paths-ignore": { - "type": "str", - "item_type": "", - "label": "push代码", - "require": 1, - "choice": [], - "default": "", - "placeholder": "私有仓库填写ssh地址,公有仓库填写https git地址", - "describe": "代码仓库地址", - "editable": 1, - "condition": "", - "value": "**.md" - } - }, - "out_parameters": { - "--code_output": { - "type": "str", - "label": "代码输出路径", - "path": "/code", - "require": 1, - "value": "/code" - } - }, - "description": "代码拉取组件", - "icon_path": "component-icon-1", - "create_by": "admin", - "create_time": "2024-03-02T05:41:25.000+00:00", - "update_by": "admin", - "update_time": "2024-03-02T05:41:25.000+00:00", - "state": 1, - "image": "172.20.32.187/pipeline-component/built-in/git:202312071000", - "env_variables": "", - "x": 532, - "y": 202, - "label": "代码拉取", - "img": "/assets/images/component-icon-1.png", - "isCluster": false, - "type": "rect-node", - "size": [110, 36], - "--code_path": "https://openi.pcl.ac.cn/somunslotus/somun202304241505581.git", - "--branch": "train_ci_test", - "--depth": "1", - "--code_output": "/code" - }, - { - "id": "git-clone-245734ab", - "category_id": 1, - "component_name": "git-clone", - "component_label": "代码拉取", - "working_directory": "", - "command": "", - "in_parameters": { - - }, - "out_parameters": { - "--code_output": { - "type": "str", - "label": "代码输出路径", - "path": "/code", - "require": 1, - "value": "/code" - } - }, - "description": "代码拉取组件", - "icon_path": "component-icon-1", - "create_by": "admin", - "create_time": "2024-03-02T05:41:25.000+00:00", - "update_by": "admin", - "update_time": "2024-03-02T05:41:25.000+00:00", - "state": 1, - "image": "172.20.32.187/pipeline-component/built-in/git:202312071000", - "env_variables": "", - "x": 532, - "y": 202, - "label": "代码拉取", - "img": "/assets/images/component-icon-1.png", - "isCluster": false, - "type": "rect-node", - "size": [110, 36], - "--code_path": "https://openi.pcl.ac.cn/somunslotus/somun202304241505581.git", - "--branch": "train_ci_test", - "--depth": "1", - "--code_output": "/code" - }, - { - "id": "git-clone-245734ab", - "category_id": 1, - "component_name": "setup-java", - "component_label": "安装java环境", - "working_directory": "", - "command": "", - "in_parameters": { - "--distribution": { - "type": "str", - "item_type": "", - "label": "代码仓库地址", - "require": 1, - "choice": [], - "default": "", - "placeholder": "私有仓库填写ssh地址,公有仓库填写https git地址", - "describe": "代码仓库地址", - "editable": 1, - "condition": "", - "value": "jdkfile" - }, - "--java-version": { - "type": "str", - "item_type": "", - "label": "代码分支/tag", - "require": 1, - "choice": [], - "default": "master", - "placeholder": "", - "describe": "代码分支或者tag", - "editable": 1, - "condition": "", - "value": "11.0.0" - }, - "--architecture": { - "type": "str", - "item_type": "", - "label": "克隆深度", - "require": 0, - "choice": [], - "default": "1", - "placeholder": "", - "describe": "代码克隆深度", - "editable": 1, - "condition": "", - "value": "x64" - }, - "--mvn-toolchain-vendor": { - "type": "str", - "item_type": "", - "label": "ssh私钥", - "require": 0, - "choice": [], - "default": "1", - "placeholder": "", - "describe": "ssh私钥,确保ssh公钥已经托管到代码平台,否则可能拉取失败", - "editable": 1, - "value": "Oracle" - } - }, - "out_parameters": { - "--code_output": { - "type": "str", - "label": "代码输出路径", - "path": "/code", - "require": 1, - "value": "/code" - } - }, - "description": "代码拉取组件", - "icon_path": "component-icon-1", - "create_by": "admin", - "create_time": "2024-03-02T05:41:25.000+00:00", - "update_by": "admin", - "update_time": "2024-03-02T05:41:25.000+00:00", - "state": 1, - "image": "172.20.32.187/pipeline-component/built-in/git:202312071000", - "env_variables": "", - "x": 532, - "y": 202, - "label": "代码拉取", - "img": "/assets/images/component-icon-1.png", - "isCluster": false, - "type": "rect-node", - "size": [110, 36], - "--code_path": "https://openi.pcl.ac.cn/somunslotus/somun202304241505581.git", - "--branch": "train_ci_test", - "--depth": "1", - "--code_output": "/code" - }, - { - "id": "git-clone-245734ab", - "category_id": 1, - "component_name": "shell", - "component_label": "执行shell命令", - "working_directory": "", - "command": "", - "in_parameters": { - "--run": { - "type": "str", - "item_type": "", - "label": "代码仓库地址", - "require": 1, - "choice": [], - "default": "", - "placeholder": "私有仓库填写ssh地址,公有仓库填写https git地址", - "describe": "代码仓库地址", - "editable": 1, - "condition": "", - "value": "service nginx restart" - } - } - }, - { - "id": "git-clone-245734ab", - "category_id": 1, - "component_name": "shell", - "component_label": "执行shell命令", - "working_directory": "", - "command": "", - "in_parameters": { - "--run": { - "type": "str", - "item_type": "", - "label": "代码仓库地址", - "require": 1, - "choice": [], - "default": "", - "placeholder": "私有仓库填写ssh地址,公有仓库填写https git地址", - "describe": "代码仓库地址", - "editable": 1, - "condition": "", - "value": "echo env" - } - } - }, - { - "id": "git-clone-245734ab", - "category_id": 1, - "component_name": "scp", - "component_label": "scp", - "working_directory": "", - "command": "", - "in_parameters": { - "--host": { - "type": "str", - "item_type": "", - "label": "代码仓库地址", - "require": 1, - "choice": [], - "default": "", - "placeholder": "私有仓库填写ssh地址,公有仓库填写https git地址", - "describe": "代码仓库地址", - "editable": 1, - "condition": "", - "value": "192.168.1.114" - } - } - } - - ], - # "edges": [ - # { - # "source": "git-clone-245734ab", - # "target": "model-train-09b1491", - # "style": { - # "active": { - # "stroke": "rgb(95, 149, 255)", - # "lineWidth": 1 - # }, - # "selected": { - # "stroke": "rgb(95, 149, 255)", - # "lineWidth": 2, - # "shadowColor": "rgb(95, 149, 255)", - # "shadowBlur": 10, - # "text-shape": { - # "fontWeight": 500 - # } - # }, - # "highlight": { - # "stroke": "rgb(95, 149, 255)", - # "lineWidth": 2, - # "text-shape": { - # "fontWeight": 500 - # } - # }, - # "inactive": { - # "stroke": "rgb(234, 234, 234)", - # "lineWidth": 1 - # }, - # "disable": { - # "stroke": "rgb(245, 245, 245)", - # "lineWidth": 1 - # }, - # "endArrow": { - # "path": "M 6,0 L 9,-1.5 L 9,1.5 Z", - # "d": 4.5, - # "fill": "#CDD0DC" - # }, - # "cursor": "pointer", - # "lineWidth": 1, - # "opacity": 1, - # "stroke": "#CDD0DC", - # "radius": 1 - # }, - # "nodeStateStyle": { - # "hover": { - # "opacity": 1, - # "stroke": "#8fe8ff" - # } - # }, - # "labelCfg": { - # "autoRotate": true, - # "style": { - # "fontSize": 10, - # "fill": "#FFF" - # } - # }, - # "id": "edge-0.11773197923997381714446043619", - # "startPoint": { - # "x": 532, - # "y": 220.25, - # "anchorIndex": 1 - # }, - # "endPoint": { - # "x": 530, - # "y": 304.75, - # "anchorIndex": 0 - # }, - # "targetAnchor": 0, - # "type": "cubic-vertical", - # "curveOffset": [0, 0], - # "curvePosition": [0.5, 0.5], - # "minCurveOffset": [0, 0], - # "depth": 0 - # }, - # { - # "source": "model-train-09b1491", - # "target": "model-evaluate-b401ff0", - # "style": { - # "active": { - # "stroke": "rgb(95, 149, 255)", - # "lineWidth": 1 - # }, - # "selected": { - # "stroke": "rgb(95, 149, 255)", - # "lineWidth": 2, - # "shadowColor": "rgb(95, 149, 255)", - # "shadowBlur": 10, - # "text-shape": { - # "fontWeight": 500 - # } - # }, - # "highlight": { - # "stroke": "rgb(95, 149, 255)", - # "lineWidth": 2, - # "text-shape": { - # "fontWeight": 500 - # } - # }, - # "inactive": { - # "stroke": "rgb(234, 234, 234)", - # "lineWidth": 1 - # }, - # "disable": { - # "stroke": "rgb(245, 245, 245)", - # "lineWidth": 1 - # }, - # "endArrow": { - # "path": "M 6,0 L 9,-1.5 L 9,1.5 Z", - # "d": 4.5, - # "fill": "#CDD0DC" - # }, - # "cursor": "pointer", - # "lineWidth": 1, - # "opacity": 1, - # "stroke": "#CDD0DC", - # "radius": 1 - # }, - # "nodeStateStyle": { - # "hover": { - # "opacity": 1, - # "stroke": "#8fe8ff" - # } - # }, - # "labelCfg": { - # "autoRotate": true, - # "style": { - # "fontSize": 10, - # "fill": "#FFF" - # } - # }, - # "id": "edge-0.28238605806531771714446047075", - # "startPoint": { - # "x": 530, - # "y": 341.25, - # "anchorIndex": 1 - # }, - # "endPoint": { - # "x": 520, - # "y": 431.75, - # "anchorIndex": 0 - # }, - # "targetAnchor": 0, - # "type": "cubic-vertical", - # "curveOffset": [0, 0], - # "curvePosition": [0.5, 0.5], - # "minCurveOffset": [0, 0], - # "depth": 0 - # } - # ] + "nodes": [{ + "id": "on-schedule-2fcf505", + "name": "on-schedule", + "full_name": "on-schedule", + "description": " 定时器计划器", + "icon": "https://testforgeplus.trustie.net/api/attachments/0445403c-5d9e-4495-8414-339f87981ca1", + "action_node_types_id": 3, + "yaml": "", + "sort_no": 0, + "use_count": 0, + "inputs": [{ + "id": 8, + "name": "cron", + "input_type": "input", + "description": "示例:\r\n- cron: '20 8 * * *'", + "is_required": true, + "value": "- corn: '0 10 * * *'" + }], + "x": 586, + "y": 165.328125, + "label": "on-schedule", + "img": "https://testforgeplus.trustie.net/api/attachments/0445403c-5d9e-4495-8414-339f87981ca1", + "isCluster": false, + "type": "rect-node", + "size": [110, 36], + "labelCfg": { + "style": { + "fill": "transparent", + "fontSize": 0, + "boxShadow": "0px 0px 12px rgba(75, 84, 137, 0.05)", + "overflow": "hidden", + "x": -20, + "y": 0, + "textAlign": "left", + "textBaseline": "middle" + } + }, + "style": { + "active": { + "fill": "rgb(247, 250, 255)", + "stroke": "rgb(95, 149, 255)", + "lineWidth": 2, + "shadowColor": "rgb(95, 149, 255)", + "shadowBlur": 10 + }, + "selected": { + "fill": "rgb(255, 255, 255)", + "stroke": "rgb(95, 149, 255)", + "lineWidth": 4, + "shadowColor": "rgb(95, 149, 255)", + "shadowBlur": 10, + "text-shape": { + "fontWeight": 500 + } + }, + "highlight": { + "fill": "rgb(223, 234, 255)", + "stroke": "#4572d9", + "lineWidth": 2, + "text-shape": { + "fontWeight": 500 + } + }, + "inactive": { + "fill": "rgb(247, 250, 255)", + "stroke": "rgb(191, 213, 255)", + "lineWidth": 1 + }, + "disable": { + "fill": "rgb(250, 250, 250)", + "stroke": "rgb(224, 224, 224)", + "lineWidth": 1 + }, + "nodeSelected": { + "fill": "red", + "shadowColor": "red", + "stroke": "red", + "text-shape": { + "fill": "red", + "stroke": "red" + } + }, + "fill": "#fff", + "stroke": "transparent", + "cursor": "pointer", + "radius": 10, + "overflow": "hidden", + "lineWidth": 0.5, + "shadowColor": "rgba(75,84,137,0.05)", + "shadowBlur": 12 + }, + "cron": "- corn: '0 10 * * *'", + "depth": 0 + }, { + "id": "actions/setup-node@v3-257f29d", + "name": "node", + "full_name": "actions/setup-node@v3", + "description": "", + "icon": "https://testforgeplus.trustie.net/api/attachments/c4774fc1-ecd9-47fd-9878-1847bdaf98f6", + "action_node_types_id": 1, + "yaml": "", + "sort_no": 0, + "use_count": 0, + "inputs": [{ + "id": 2, + "name": "node-version", + "input_type": "select", + "is_required": false, + "value": 55 + }], + "x": 608, + "y": 357.328125, + "label": "node", + "img": "https://testforgeplus.trustie.net/api/attachments/c4774fc1-ecd9-47fd-9878-1847bdaf98f6", + "isCluster": false, + "type": "rect-node", + "size": [110, 36], + "labelCfg": { + "style": { + "fill": "transparent", + "fontSize": 0, + "boxShadow": "0px 0px 12px rgba(75, 84, 137, 0.05)", + "overflow": "hidden", + "x": -20, + "y": 0, + "textAlign": "left", + "textBaseline": "middle" + } + }, + "style": { + "active": { + "fill": "rgb(247, 250, 255)", + "stroke": "rgb(95, 149, 255)", + "lineWidth": 2, + "shadowColor": "rgb(95, 149, 255)", + "shadowBlur": 10 + }, + "selected": { + "fill": "rgb(255, 255, 255)", + "stroke": "rgb(95, 149, 255)", + "lineWidth": 4, + "shadowColor": "rgb(95, 149, 255)", + "shadowBlur": 10, + "text-shape": { + "fontWeight": 500 + } + }, + "highlight": { + "fill": "rgb(223, 234, 255)", + "stroke": "#4572d9", + "lineWidth": 2, + "text-shape": { + "fontWeight": 500 + } + }, + "inactive": { + "fill": "rgb(247, 250, 255)", + "stroke": "rgb(191, 213, 255)", + "lineWidth": 1 + }, + "disable": { + "fill": "rgb(250, 250, 250)", + "stroke": "rgb(224, 224, 224)", + "lineWidth": 1 + }, + "nodeSelected": { + "fill": "red", + "shadowColor": "red", + "stroke": "red", + "text-shape": { + "fill": "red", + "stroke": "red" + } + }, + "fill": "#fff", + "stroke": "transparent", + "cursor": "pointer", + "radius": 10, + "overflow": "hidden", + "lineWidth": 0.5, + "shadowColor": "rgba(75,84,137,0.05)", + "shadowBlur": 12 + }, + "depth": 0, + "node-version": 55 + }], + "edges": [{ + "source": "on-schedule-2fcf505", + "target": "actions/setup-node@v3-257f29d", + "style": { + "active": { + "stroke": "rgb(95, 149, 255)", + "lineWidth": 1 + }, + "selected": { + "stroke": "rgb(95, 149, 255)", + "lineWidth": 2, + "shadowColor": "rgb(95, 149, 255)", + "shadowBlur": 10, + "text-shape": { + "fontWeight": 500 + } + }, + "highlight": { + "stroke": "rgb(95, 149, 255)", + "lineWidth": 2, + "text-shape": { + "fontWeight": 500 + } + }, + "inactive": { + "stroke": "rgb(234, 234, 234)", + "lineWidth": 1 + }, + "disable": { + "stroke": "rgb(245, 245, 245)", + "lineWidth": 1 + }, + "endArrow": { + "path": "M 6,0 L 9,-1.5 L 9,1.5 Z", + "d": 4.5, + "fill": "#CDD0DC" + }, + "cursor": "pointer", + "lineWidth": 1, + "opacity": 1, + "stroke": "#CDD0DC", + "radius": 1 + }, + "nodeStateStyle": { + "hover": { + "opacity": 1, + "stroke": "#8fe8ff" + } + }, + "labelCfg": { + "autoRotate": true, + "style": { + "fontSize": 10, + "fill": "#FFF" + } + }, + "id": "edge-0.96904321945951241716516719464", + "startPoint": { + "x": 586, + "y": 183.578125, + "anchorIndex": 1 + }, + "endPoint": { + "x": 608, + "y": 339.078125, + "anchorIndex": 0 + }, + "sourceAnchor": 1, + "targetAnchor": 0, + "type": "cubic-vertical", + "curveOffset": [0, 0], + "curvePosition": [0.5, 0.5], + "minCurveOffset": [0, 0] + }], + "combos": [] } end end From 4d3e33a4e8312e724e4903af49ed75bbd1e6ed18 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 27 May 2024 11:51:51 +0800 Subject: [PATCH 197/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Aroot=5Fsubje?= =?UTF-8?q?ct=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 2 +- app/services/api/v1/issues/create_service.rb | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 912305ca2..b74cf29f0 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -172,7 +172,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController params.permit( :status_id, :priority_id, :milestone_id, :branch_name, :start_date, :due_date, :time_scale, - :subject, :description, :blockchain_token_num, + :subject, :description, :blockchain_token_num, :root_subject, :pm_project_id, :pm_sprint_id, :pm_issue_type, :root_id, :link_able_id, :project_id, issue_tag_ids: [], assigner_ids: [], diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index 0806a2397..6c456a2bd 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -4,7 +4,7 @@ class Api::V1::Issues::CreateService < ApplicationService include Api::V1::Issues::Concerns::Loadable attr_reader :project, :current_user - attr_reader :status_id, :priority_id, :milestone_id, :branch_name, :start_date, :due_date, :subject, :description, :blockchain_token_num + attr_reader :status_id, :priority_id, :milestone_id, :branch_name, :start_date, :due_date, :subject, :description, :blockchain_token_num, :root_subject attr_reader :issue_tag_ids, :assigner_ids, :attachment_ids, :receivers_login attr_accessor :created_issue @@ -35,6 +35,7 @@ class Api::V1::Issues::CreateService < ApplicationService @root_id = params[:root_id] @time_scale = params[:time_scale] @linkable_id = params[:link_able_id] + @root_subject = params[:root_subject] end def call @@ -65,7 +66,15 @@ class Api::V1::Issues::CreateService < ApplicationService @created_issue.pm_project_id = @pm_project_id @created_issue.pm_sprint_id = @pm_sprint_id @created_issue.pm_issue_type = @pm_issue_type - @created_issue.root_id = @root_id + if @root_subject.present? && @pm_issue_type.to_i == 4 + @root_issue = Issue.find_by(subject: @root_subject, pm_issue_type: 4, pm_project_id: @pm_project_id) + unless @root_issue.present? + @root_issue.create(subject: @root_subject, pm_issue_type: 4, pm_project_id: @pm_project_id, status_id: 1, priority_id: 1, tracker_id: Tracker.first.id, project_id: @project.id, author_id: current_user.id) + end + @created_issue.root_id = @root_issue.id + else + @created_issue.root_id = @root_id + end @created_issue.time_scale = @time_scale @created_issue.issue_tags_value = @issue_tags.order('id asc').pluck(:id).join(',') unless issue_tag_ids.blank? @created_issue.changer_id = @current_user.id From c88479a8eca9bed0cfdc397ff9c137424a961083 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 27 May 2024 11:56:30 +0800 Subject: [PATCH 198/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/issues/create_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index 6c456a2bd..fdbdc71ed 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -69,7 +69,7 @@ class Api::V1::Issues::CreateService < ApplicationService if @root_subject.present? && @pm_issue_type.to_i == 4 @root_issue = Issue.find_by(subject: @root_subject, pm_issue_type: 4, pm_project_id: @pm_project_id) unless @root_issue.present? - @root_issue.create(subject: @root_subject, pm_issue_type: 4, pm_project_id: @pm_project_id, status_id: 1, priority_id: 1, tracker_id: Tracker.first.id, project_id: @project.id, author_id: current_user.id) + @root_issue = Issue.create(subject: @root_subject, pm_issue_type: 4, pm_project_id: @pm_project_id, status_id: 1, priority_id: 1, tracker_id: Tracker.first.id, project_id: @project.id, author_id: current_user.id) end @created_issue.root_id = @root_issue.id else From 541815fb03d904010287547e7d91f2e3f71d0f78 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 28 May 2024 17:31:07 +0800 Subject: [PATCH 199/294] =?UTF-8?q?=E8=81=94=E8=B0=83=E5=9B=BE=E5=BD=A2?= =?UTF-8?q?=E8=AE=BE=E8=AE=A1=E5=8C=96-=E8=BF=94=E5=9B=9E=E6=96=87?= =?UTF-8?q?=E4=BB=B6sha?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index c2efc36ae..e8a7a1c3b 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -35,7 +35,8 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch) interactor = sha.present? ? Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("update").merge(sha: sha)) : Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("create")) tip_exception(interactor.error) unless interactor.success? - render_ok({ pipeline_yaml: pipeline_yaml }) + file = interactor.result + render_ok({ pipeline_yaml: pipeline_yaml, pipeline_name: params[:pipeline_name], file_name: @pipeline.file_name, sha: file['content']['sha'] }) end def build_yaml @@ -61,7 +62,8 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch) interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("create").merge(sha: sha)) tip_exception(interactor.error) unless interactor.success? - render_ok + file = interactor.result + render_ok({ pipeline_yaml: pipeline_yaml, pipeline_name: params[:pipeline_name], file_name: @pipeline.file_name, sha: file['content']['sha'] }) end def destroy From c87da2947f312a985a3e51879ce48395a35972fb Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 28 May 2024 18:04:53 +0800 Subject: [PATCH 200/294] =?UTF-8?q?=E8=81=94=E8=B0=83=E5=9B=BE=E5=BD=A2?= =?UTF-8?q?=E8=AE=BE=E8=AE=A1=E5=8C=96-=E8=BF=94=E5=9B=9E=E6=96=87?= =?UTF-8?q?=E4=BB=B6sha?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index e8a7a1c3b..c1bcc8299 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -36,7 +36,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController interactor = sha.present? ? Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("update").merge(sha: sha)) : Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("create")) tip_exception(interactor.error) unless interactor.success? file = interactor.result - render_ok({ pipeline_yaml: pipeline_yaml, pipeline_name: params[:pipeline_name], file_name: @pipeline.file_name, sha: file['content']['sha'] }) + render_ok({ pipeline_yaml: pipeline_yaml, pipeline_name: params[:pipeline_name], file_name: @pipeline.file_name, sha: sha.present? ? sha : file['content']['sha'] }) end def build_yaml @@ -82,7 +82,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController end def build_pipeline_yaml(pipeline_name, pipeline_json) - if pipeline_json.present? + if pipeline_json.present? && pipeline_json.present? @pipeline_name = pipeline_name params_nodes = pipeline_json["nodes"].select { |node| !["on-push", "on-schedule"].include?(node["name"]) } on_nodes = pipeline_json["nodes"].select { |node| ["on-push", "on-schedule"].include?(node["name"]) } From 61ca57e4e0e86242330fb117f1d909461ddb3fab Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Wed, 29 May 2024 11:11:48 +0800 Subject: [PATCH 201/294] update pm issue total_issues_count --- app/services/api/v1/issues/list_service.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index b499a5ea5..c27dcd29f 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -64,7 +64,7 @@ class Api::V1::Issues::ListService < ApplicationService private def issue_query_data issues = @project&.id.zero? ? Issue.issue_issue : @project.issues.issue_issue - + @total_issues_count = issues.distinct.size case participant_category when 'aboutme' # 关于我的 issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: %w[authored assigned atme], participant_id: participator&.id}) @@ -154,7 +154,7 @@ class Api::V1::Issues::ListService < ApplicationService # keyword issues = issues.ransack(id_or_project_issues_index_eq: keyword).result.or(issues.ransack(subject_or_description_cont: keyword).result) if keyword.present? - @total_issues_count = issues.distinct.size + @closed_issues_count = issues.closed.distinct.size @opened_issues_count = issues.opened.distinct.size @complete_issues_count = issues.closed.distinct.size + issues.where(status_id: 3).distinct.size - issues.where(pm_issue_type: 3, status_id: 3).distinct.size From ad085fcddc2cb363707553c279c253373cb05ae7 Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Wed, 29 May 2024 16:06:56 +0800 Subject: [PATCH 202/294] add sonarqube --- Gemfile | 3 +- Gemfile.lock | 34 +++++++++++++------ .../javascripts/api/v1/sonarqube/issues.js | 2 ++ .../stylesheets/api/v1/sonarqube/issues.scss | 3 ++ .../api/v1/sonarqubes/issues_controller.rb | 6 ++++ app/helpers/api/v1/sonarqube/issues_helper.rb | 2 ++ config/initializers/sonarqube.rb | 6 ++++ config/routes/api.rb | 6 ++++ .../v1/sonarqube/issues_controller_spec.rb | 5 +++ .../api/v1/sonarqube/issues_helper_spec.rb | 15 ++++++++ 10 files changed, 69 insertions(+), 13 deletions(-) create mode 100644 app/assets/javascripts/api/v1/sonarqube/issues.js create mode 100644 app/assets/stylesheets/api/v1/sonarqube/issues.scss create mode 100644 app/controllers/api/v1/sonarqubes/issues_controller.rb create mode 100644 app/helpers/api/v1/sonarqube/issues_helper.rb create mode 100644 config/initializers/sonarqube.rb create mode 100644 spec/controllers/api/v1/sonarqube/issues_controller_spec.rb create mode 100644 spec/helpers/api/v1/sonarqube/issues_helper_spec.rb diff --git a/Gemfile b/Gemfile index edaae8a75..206b0057d 100644 --- a/Gemfile +++ b/Gemfile @@ -26,7 +26,7 @@ gem 'roo-xls' gem 'simple_xlsx_reader', '~>1.0.4' gem 'rubyzip' - +gem 'sonarqube', :git => 'https://gitlink.org.cn/KingChan/sonarqube.git' gem 'spreadsheet' gem 'ruby-ole' # 导出为xlsx @@ -114,7 +114,6 @@ gem 'aasm' gem 'enumerize' gem 'diffy' - gem 'deep_cloneable', '~> 3.0.0' # oauth2 diff --git a/Gemfile.lock b/Gemfile.lock index b7f060b2a..4dff7c2ba 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,11 @@ +GIT + remote: https://gitlink.org.cn/KingChan/sonarqube.git + revision: 80f07d427322ef02c0714c77a382e87aed0bef81 + specs: + sonarqube (1.3.0) + httparty (~> 0.14, >= 0.14.0) + terminal-table (~> 1.5, >= 1.5.1) + GEM remote: https://mirrors.cloud.tencent.com/rubygems/ specs: @@ -135,7 +143,7 @@ GEM fugit (1.4.1) et-orbi (~> 1.1, >= 1.1.8) raabro (~> 1.4) - gitea-client (1.4.2) + gitea-client (1.4.6) rest-client (~> 2.1.0) globalid (0.4.2) activesupport (>= 4.2.0) @@ -150,6 +158,9 @@ GEM http-accept (1.7.0) http-cookie (1.0.5) domain_name (~> 0.5) + httparty (0.21.0) + mini_mime (>= 1.0.0) + multi_xml (>= 0.5.2) i18n (1.8.2) concurrent-ruby (~> 1.0) io-like (0.3.1) @@ -187,9 +198,9 @@ GEM mimemagic (~> 0.3.2) maruku (0.7.3) method_source (0.9.2) - mime-types (3.4.1) + mime-types (3.5.2) mime-types-data (~> 3.2015) - mime-types-data (3.2023.0218.1) + mime-types-data (3.2024.0507) mimemagic (0.3.10) nokogiri (~> 1) rake @@ -245,13 +256,12 @@ GEM powerpack (0.1.2) prettier (0.18.2) public_suffix (4.0.3) - puma (3.12.2) + puma (5.6.8) + nio4r (~> 2.0) raabro (1.4.0) rack (2.0.9) rack-cors (1.1.1) rack (>= 2.0.0) - rack-mini-profiler (2.0.1) - rack (>= 1.2.0) rack-protection (2.0.8.1) rack rack-test (1.1.0) @@ -438,6 +448,8 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) + terminal-table (1.8.0) + unicode-display_width (~> 1.1, >= 1.1.1) thor (1.0.1) thread_safe (0.3.6) tilt (2.0.10) @@ -450,7 +462,7 @@ GEM execjs (>= 0.3.0, < 3) unf (0.1.4) unf_ext - unf_ext (0.0.8.2) + unf_ext (0.0.9.1) unicode-display_width (1.6.1) web-console (3.7.0) actionview (>= 5.0) @@ -492,7 +504,7 @@ DEPENDENCIES enumerize faraday (~> 0.15.4) font-awesome-sass (= 4.7.0) - gitea-client (~> 1.4.2) + gitea-client (~> 1.4.3) grape-entity (~> 0.7.1) groupdate (~> 4.1.0) harmonious_dictionary (~> 0.0.1) @@ -514,9 +526,8 @@ DEPENDENCIES parallel (~> 1.19, >= 1.19.1) pdfkit prettier - puma (~> 3.11) + puma (~> 5.6.5) rack-cors - rack-mini-profiler rails (~> 5.2.0) rails-i18n (~> 5.1) ransack @@ -538,9 +549,10 @@ DEPENDENCIES sidekiq-cron (= 1.2.0) sidekiq-failures simple_form - simple_xlsx_reader + simple_xlsx_reader (~> 1.0.4) sinatra solargraph (~> 0.38.0) + sonarqube! spreadsheet spring spring-watcher-listen (~> 2.0.0) diff --git a/app/assets/javascripts/api/v1/sonarqube/issues.js b/app/assets/javascripts/api/v1/sonarqube/issues.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/api/v1/sonarqube/issues.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/api/v1/sonarqube/issues.scss b/app/assets/stylesheets/api/v1/sonarqube/issues.scss new file mode 100644 index 000000000..a74cba738 --- /dev/null +++ b/app/assets/stylesheets/api/v1/sonarqube/issues.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the api/v1/sonarqube/issues controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/api/v1/sonarqubes/issues_controller.rb b/app/controllers/api/v1/sonarqubes/issues_controller.rb new file mode 100644 index 000000000..0a0188875 --- /dev/null +++ b/app/controllers/api/v1/sonarqubes/issues_controller.rb @@ -0,0 +1,6 @@ +class Api::V1::Sonarqubes::IssuesController < ApplicationController + def index + data = Sonarqube.client.get("/api/issues/search",params) + render_ok data + end +end diff --git a/app/helpers/api/v1/sonarqube/issues_helper.rb b/app/helpers/api/v1/sonarqube/issues_helper.rb new file mode 100644 index 000000000..7dbee46e4 --- /dev/null +++ b/app/helpers/api/v1/sonarqube/issues_helper.rb @@ -0,0 +1,2 @@ +module Api::V1::Sonarqube::IssuesHelper +end diff --git a/config/initializers/sonarqube.rb b/config/initializers/sonarqube.rb new file mode 100644 index 000000000..99c88c82a --- /dev/null +++ b/config/initializers/sonarqube.rb @@ -0,0 +1,6 @@ +Sonarqube.configure do |config| + config.endpoint = 'http://172.20.32.202:9999' # API endpoint URL, default: ENV['SONARQUBE_API_ENDPOINT'] + config.private_token = 'squ_fb81f52a7b2c2db00c71c29f71c9595f48c2ff3f' # user's private token, default: ENV['SONARQUBE_API_PRIVATE_TOKEN'] + # Optional + # config.user_agent = 'Custom User Agent' # user agent, default: 'Sonarqube Ruby Gem [version]' +end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index 6df7dc8a3..66018a51c 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -48,6 +48,12 @@ defaults format: :json do end end + resources :sonarqubes ,only: [:index] do + collection do + resource :issues + end + end + scope ':owner' do resource :users, path: '/', only: [:update, :edit, :destroy] do collection do diff --git a/spec/controllers/api/v1/sonarqube/issues_controller_spec.rb b/spec/controllers/api/v1/sonarqube/issues_controller_spec.rb new file mode 100644 index 000000000..194d01c09 --- /dev/null +++ b/spec/controllers/api/v1/sonarqube/issues_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Api::V1::Sonarqube::IssuesController, type: :controller do + +end diff --git a/spec/helpers/api/v1/sonarqube/issues_helper_spec.rb b/spec/helpers/api/v1/sonarqube/issues_helper_spec.rb new file mode 100644 index 000000000..7288e088d --- /dev/null +++ b/spec/helpers/api/v1/sonarqube/issues_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Api::V1::Sonarqube::IssuesHelper. For example: +# +# describe Api::V1::Sonarqube::IssuesHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe Api::V1::Sonarqube::IssuesHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end From 97d1e9466b3b7c254cfd90beadd9b23f80d0cfa4 Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Thu, 30 May 2024 11:50:08 +0800 Subject: [PATCH 203/294] add sonarqube for projects --- Gemfile | 2 +- Gemfile.lock | 34 +++++++++++++------ app/controllers/api/v1/projects_controller.rb | 7 +++- config/initializers/sonarqube.rb | 6 ++++ config/routes/api.rb | 3 +- 5 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 config/initializers/sonarqube.rb diff --git a/Gemfile b/Gemfile index 811fabc41..41e5d2123 100644 --- a/Gemfile +++ b/Gemfile @@ -26,7 +26,7 @@ gem 'roo-xls' gem 'simple_xlsx_reader', '~>1.0.4' gem 'rubyzip' - +gem 'sonarqube', :git => 'https://gitlink.org.cn/KingChan/sonarqube.git' gem 'spreadsheet' gem 'ruby-ole' # 导出为xlsx diff --git a/Gemfile.lock b/Gemfile.lock index b7f060b2a..0e18d1f29 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,11 @@ +GIT + remote: https://gitlink.org.cn/KingChan/sonarqube.git + revision: 80f07d427322ef02c0714c77a382e87aed0bef81 + specs: + sonarqube (1.3.0) + httparty (~> 0.14, >= 0.14.0) + terminal-table (~> 1.5, >= 1.5.1) + GEM remote: https://mirrors.cloud.tencent.com/rubygems/ specs: @@ -135,7 +143,7 @@ GEM fugit (1.4.1) et-orbi (~> 1.1, >= 1.1.8) raabro (~> 1.4) - gitea-client (1.4.2) + gitea-client (1.5.7) rest-client (~> 2.1.0) globalid (0.4.2) activesupport (>= 4.2.0) @@ -150,6 +158,9 @@ GEM http-accept (1.7.0) http-cookie (1.0.5) domain_name (~> 0.5) + httparty (0.21.0) + mini_mime (>= 1.0.0) + multi_xml (>= 0.5.2) i18n (1.8.2) concurrent-ruby (~> 1.0) io-like (0.3.1) @@ -187,9 +198,9 @@ GEM mimemagic (~> 0.3.2) maruku (0.7.3) method_source (0.9.2) - mime-types (3.4.1) + mime-types (3.5.2) mime-types-data (~> 3.2015) - mime-types-data (3.2023.0218.1) + mime-types-data (3.2024.0507) mimemagic (0.3.10) nokogiri (~> 1) rake @@ -245,13 +256,12 @@ GEM powerpack (0.1.2) prettier (0.18.2) public_suffix (4.0.3) - puma (3.12.2) + puma (5.6.8) + nio4r (~> 2.0) raabro (1.4.0) rack (2.0.9) rack-cors (1.1.1) rack (>= 2.0.0) - rack-mini-profiler (2.0.1) - rack (>= 1.2.0) rack-protection (2.0.8.1) rack rack-test (1.1.0) @@ -438,6 +448,8 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) + terminal-table (1.8.0) + unicode-display_width (~> 1.1, >= 1.1.1) thor (1.0.1) thread_safe (0.3.6) tilt (2.0.10) @@ -450,7 +462,7 @@ GEM execjs (>= 0.3.0, < 3) unf (0.1.4) unf_ext - unf_ext (0.0.8.2) + unf_ext (0.0.9.1) unicode-display_width (1.6.1) web-console (3.7.0) actionview (>= 5.0) @@ -492,7 +504,7 @@ DEPENDENCIES enumerize faraday (~> 0.15.4) font-awesome-sass (= 4.7.0) - gitea-client (~> 1.4.2) + gitea-client (~> 1.5.7) grape-entity (~> 0.7.1) groupdate (~> 4.1.0) harmonious_dictionary (~> 0.0.1) @@ -514,9 +526,8 @@ DEPENDENCIES parallel (~> 1.19, >= 1.19.1) pdfkit prettier - puma (~> 3.11) + puma (~> 5.6.5) rack-cors - rack-mini-profiler rails (~> 5.2.0) rails-i18n (~> 5.1) ransack @@ -538,9 +549,10 @@ DEPENDENCIES sidekiq-cron (= 1.2.0) sidekiq-failures simple_form - simple_xlsx_reader + simple_xlsx_reader (~> 1.0.4) sinatra solargraph (~> 0.38.0) + sonarqube! spreadsheet spring spring-watcher-listen (~> 2.0.0) diff --git a/app/controllers/api/v1/projects_controller.rb b/app/controllers/api/v1/projects_controller.rb index 810c40171..33f664b31 100644 --- a/app/controllers/api/v1/projects_controller.rb +++ b/app/controllers/api/v1/projects_controller.rb @@ -1,5 +1,5 @@ class Api::V1::ProjectsController < Api::V1::BaseController - before_action :require_public_and_member_above, only: [:show, :compare, :blame] + before_action :require_public_and_member_above, only: [:show, :compare, :blame, :sonar_search] def index render_ok @@ -9,6 +9,11 @@ class Api::V1::ProjectsController < Api::V1::BaseController @result_object = Api::V1::Projects::GetService.call(@project, current_user.gitea_token) end + def sonar_search + data = Sonarqube.client.get("/api/issues/search", { components:"#{@project.owner.login}-#{@project.identifier}" }) + render_ok data + end + def compare @result_object = Api::V1::Projects::CompareService.call(@project, params[:from], params[:to], current_user&.gitea_token) end diff --git a/config/initializers/sonarqube.rb b/config/initializers/sonarqube.rb new file mode 100644 index 000000000..99c88c82a --- /dev/null +++ b/config/initializers/sonarqube.rb @@ -0,0 +1,6 @@ +Sonarqube.configure do |config| + config.endpoint = 'http://172.20.32.202:9999' # API endpoint URL, default: ENV['SONARQUBE_API_ENDPOINT'] + config.private_token = 'squ_fb81f52a7b2c2db00c71c29f71c9595f48c2ff3f' # user's private token, default: ENV['SONARQUBE_API_PRIVATE_TOKEN'] + # Optional + # config.user_agent = 'Custom User Agent' # user agent, default: 'Sonarqube Ruby Gem [version]' +end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index c74b38836..9eede3e4f 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -48,7 +48,7 @@ defaults format: :json do end end - scope ':owner' do + scope ':owner' do resource :users, path: '/', only: [:update, :edit, :destroy] do collection do get :send_email_vefify_code @@ -76,6 +76,7 @@ defaults format: :json do collection do get :compare get :blame + get :sonar_search end end From c590c29f2939da078f82f5548d169a303d3a9eaf Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Thu, 30 May 2024 12:22:04 +0800 Subject: [PATCH 204/294] =?UTF-8?q?=E8=B0=83=E6=95=B4pm=20issue=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=97=B6=E7=9A=84=E9=80=BB=E8=BE=91=20=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=80=BB=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/issues/list_service.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index b499a5ea5..c27dcd29f 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -64,7 +64,7 @@ class Api::V1::Issues::ListService < ApplicationService private def issue_query_data issues = @project&.id.zero? ? Issue.issue_issue : @project.issues.issue_issue - + @total_issues_count = issues.distinct.size case participant_category when 'aboutme' # 关于我的 issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: %w[authored assigned atme], participant_id: participator&.id}) @@ -154,7 +154,7 @@ class Api::V1::Issues::ListService < ApplicationService # keyword issues = issues.ransack(id_or_project_issues_index_eq: keyword).result.or(issues.ransack(subject_or_description_cont: keyword).result) if keyword.present? - @total_issues_count = issues.distinct.size + @closed_issues_count = issues.closed.distinct.size @opened_issues_count = issues.opened.distinct.size @complete_issues_count = issues.closed.distinct.size + issues.where(status_id: 3).distinct.size - issues.where(pm_issue_type: 3, status_id: 3).distinct.size From 983edca9a3f055c30ae0cb13f6d09d7ef64c07a0 Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Thu, 30 May 2024 11:50:08 +0800 Subject: [PATCH 205/294] add sonarqube for projects --- Gemfile | 2 +- Gemfile.lock | 34 +++++++++++++------ app/controllers/api/v1/projects_controller.rb | 7 +++- config/initializers/sonarqube.rb | 6 ++++ config/routes/api.rb | 3 +- 5 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 config/initializers/sonarqube.rb diff --git a/Gemfile b/Gemfile index 811fabc41..41e5d2123 100644 --- a/Gemfile +++ b/Gemfile @@ -26,7 +26,7 @@ gem 'roo-xls' gem 'simple_xlsx_reader', '~>1.0.4' gem 'rubyzip' - +gem 'sonarqube', :git => 'https://gitlink.org.cn/KingChan/sonarqube.git' gem 'spreadsheet' gem 'ruby-ole' # 导出为xlsx diff --git a/Gemfile.lock b/Gemfile.lock index b7f060b2a..0e18d1f29 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,11 @@ +GIT + remote: https://gitlink.org.cn/KingChan/sonarqube.git + revision: 80f07d427322ef02c0714c77a382e87aed0bef81 + specs: + sonarqube (1.3.0) + httparty (~> 0.14, >= 0.14.0) + terminal-table (~> 1.5, >= 1.5.1) + GEM remote: https://mirrors.cloud.tencent.com/rubygems/ specs: @@ -135,7 +143,7 @@ GEM fugit (1.4.1) et-orbi (~> 1.1, >= 1.1.8) raabro (~> 1.4) - gitea-client (1.4.2) + gitea-client (1.5.7) rest-client (~> 2.1.0) globalid (0.4.2) activesupport (>= 4.2.0) @@ -150,6 +158,9 @@ GEM http-accept (1.7.0) http-cookie (1.0.5) domain_name (~> 0.5) + httparty (0.21.0) + mini_mime (>= 1.0.0) + multi_xml (>= 0.5.2) i18n (1.8.2) concurrent-ruby (~> 1.0) io-like (0.3.1) @@ -187,9 +198,9 @@ GEM mimemagic (~> 0.3.2) maruku (0.7.3) method_source (0.9.2) - mime-types (3.4.1) + mime-types (3.5.2) mime-types-data (~> 3.2015) - mime-types-data (3.2023.0218.1) + mime-types-data (3.2024.0507) mimemagic (0.3.10) nokogiri (~> 1) rake @@ -245,13 +256,12 @@ GEM powerpack (0.1.2) prettier (0.18.2) public_suffix (4.0.3) - puma (3.12.2) + puma (5.6.8) + nio4r (~> 2.0) raabro (1.4.0) rack (2.0.9) rack-cors (1.1.1) rack (>= 2.0.0) - rack-mini-profiler (2.0.1) - rack (>= 1.2.0) rack-protection (2.0.8.1) rack rack-test (1.1.0) @@ -438,6 +448,8 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) + terminal-table (1.8.0) + unicode-display_width (~> 1.1, >= 1.1.1) thor (1.0.1) thread_safe (0.3.6) tilt (2.0.10) @@ -450,7 +462,7 @@ GEM execjs (>= 0.3.0, < 3) unf (0.1.4) unf_ext - unf_ext (0.0.8.2) + unf_ext (0.0.9.1) unicode-display_width (1.6.1) web-console (3.7.0) actionview (>= 5.0) @@ -492,7 +504,7 @@ DEPENDENCIES enumerize faraday (~> 0.15.4) font-awesome-sass (= 4.7.0) - gitea-client (~> 1.4.2) + gitea-client (~> 1.5.7) grape-entity (~> 0.7.1) groupdate (~> 4.1.0) harmonious_dictionary (~> 0.0.1) @@ -514,9 +526,8 @@ DEPENDENCIES parallel (~> 1.19, >= 1.19.1) pdfkit prettier - puma (~> 3.11) + puma (~> 5.6.5) rack-cors - rack-mini-profiler rails (~> 5.2.0) rails-i18n (~> 5.1) ransack @@ -538,9 +549,10 @@ DEPENDENCIES sidekiq-cron (= 1.2.0) sidekiq-failures simple_form - simple_xlsx_reader + simple_xlsx_reader (~> 1.0.4) sinatra solargraph (~> 0.38.0) + sonarqube! spreadsheet spring spring-watcher-listen (~> 2.0.0) diff --git a/app/controllers/api/v1/projects_controller.rb b/app/controllers/api/v1/projects_controller.rb index 810c40171..33f664b31 100644 --- a/app/controllers/api/v1/projects_controller.rb +++ b/app/controllers/api/v1/projects_controller.rb @@ -1,5 +1,5 @@ class Api::V1::ProjectsController < Api::V1::BaseController - before_action :require_public_and_member_above, only: [:show, :compare, :blame] + before_action :require_public_and_member_above, only: [:show, :compare, :blame, :sonar_search] def index render_ok @@ -9,6 +9,11 @@ class Api::V1::ProjectsController < Api::V1::BaseController @result_object = Api::V1::Projects::GetService.call(@project, current_user.gitea_token) end + def sonar_search + data = Sonarqube.client.get("/api/issues/search", { components:"#{@project.owner.login}-#{@project.identifier}" }) + render_ok data + end + def compare @result_object = Api::V1::Projects::CompareService.call(@project, params[:from], params[:to], current_user&.gitea_token) end diff --git a/config/initializers/sonarqube.rb b/config/initializers/sonarqube.rb new file mode 100644 index 000000000..99c88c82a --- /dev/null +++ b/config/initializers/sonarqube.rb @@ -0,0 +1,6 @@ +Sonarqube.configure do |config| + config.endpoint = 'http://172.20.32.202:9999' # API endpoint URL, default: ENV['SONARQUBE_API_ENDPOINT'] + config.private_token = 'squ_fb81f52a7b2c2db00c71c29f71c9595f48c2ff3f' # user's private token, default: ENV['SONARQUBE_API_PRIVATE_TOKEN'] + # Optional + # config.user_agent = 'Custom User Agent' # user agent, default: 'Sonarqube Ruby Gem [version]' +end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index c74b38836..9eede3e4f 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -48,7 +48,7 @@ defaults format: :json do end end - scope ':owner' do + scope ':owner' do resource :users, path: '/', only: [:update, :edit, :destroy] do collection do get :send_email_vefify_code @@ -76,6 +76,7 @@ defaults format: :json do collection do get :compare get :blame + get :sonar_search end end From e393b13ac15f56fda46b702740e868a554ed0371 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 30 May 2024 17:31:47 +0800 Subject: [PATCH 206/294] =?UTF-8?q?=E8=81=94=E8=B0=83=E5=9B=BE=E5=BD=A2?= =?UTF-8?q?=E8=AE=BE=E8=AE=A1=E5=8C=96-=E8=BF=94=E5=9B=9Elog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index c1bcc8299..e5a3de5b1 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -94,6 +94,8 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController else pipeline_yaml = params[:pipeline_yaml] end + Rails.logger.info "pipeline_yaml=========================" + Rails.logger.info pipeline_yaml pipeline_yaml end From 9c84856f99d7708208b70a0259a8019802de810b Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Thu, 30 May 2024 17:33:09 +0800 Subject: [PATCH 207/294] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=20=E6=97=A0=E9=9C=80=E9=87=8D=E5=90=AFrails?= =?UTF-8?q?=20s=20=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/environments/development.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/environments/development.rb b/config/environments/development.rb index 1adbdde7c..199481259 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -62,8 +62,8 @@ Rails.application.configure do # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. - config.file_watcher = ActiveSupport::EventedFileUpdateChecker - + config.file_watcher = ActiveSupport::FileUpdateChecker + config.reload_classes_only_on_change = false config.action_controller.perform_caching = true config.action_mailer.delivery_method = :smtp From cf5b4c1e2df2a088edb072d9ed97ec630b0c1ed1 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 31 May 2024 08:55:36 +0800 Subject: [PATCH 208/294] =?UTF-8?q?=E8=81=94=E8=B0=83=E5=9B=BE=E5=BD=A2?= =?UTF-8?q?=E8=AE=BE=E8=AE=A1=E5=8C=96-=E8=BF=94=E5=9B=9Elog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index e5a3de5b1..ba8634629 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -32,6 +32,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController pipeline_yaml = build_pipeline_yaml(params[:pipeline_name], params[:pipeline_json]) tip_exception("流水线yaml内空不能为空") if pipeline_yaml.blank? @pipeline.yaml = pipeline_yaml + Rails.logger.info "pipeline_yaml base64=========================#{Base64.encode64(@pipeline.yaml).gsub(/\n/, '')}" sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch) interactor = sha.present? ? Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("update").merge(sha: sha)) : Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("create")) tip_exception(interactor.error) unless interactor.success? From 62de4a0ac873cee0d350153a3f225bb51d70dff1 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 31 May 2024 09:24:39 +0800 Subject: [PATCH 209/294] =?UTF-8?q?=E8=81=94=E8=B0=83=E5=9B=BE=E5=BD=A2?= =?UTF-8?q?=E8=AE=BE=E8=AE=A1=E5=8C=96-=E6=9B=B4=E6=96=B0=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8D=E8=BD=ACbase64?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 2 +- app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index ba8634629..ce662f24d 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -158,7 +158,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController filepath: ".gitea/workflows/#{@pipeline.pipeline_name}.yml", branch: @pipeline.branch, new_branch: @pipeline.branch, - content: Base64.encode64(@pipeline.yaml).gsub(/\n/, ''), + content: opt == "create" ? Base64.encode64(@pipeline.yaml).gsub(/\n/, '') : @pipeline.yaml, message: "#{opt} pipeline", committer: { email: current_user.mail, diff --git a/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb b/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb index 149d7a6be..d25705687 100644 --- a/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb +++ b/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb @@ -9,10 +9,10 @@ on: <% node.input_values.each_key do |key| %> <%=key %>: <% if node.input_values[key].blank? %> - - * + - * <% else %> <% node.input_values[key].to_s.split(",").each do |val| %> - - <%=val %> + - <%=val %> <% end %> <% end %> <% end %> From b96d52a84dbb089a4e6fe07d4fc28e8f3e9778ef Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 31 May 2024 10:56:46 +0800 Subject: [PATCH 210/294] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BF=E8=8A=82=E7=82=B9=E5=90=8D=E7=A7=B0=EF=BC=8C=E5=92=8C?= =?UTF-8?q?=E6=A0=87=E8=AF=86=E5=8C=BA=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/action/nodes_controller.rb | 4 ++-- app/models/action/node.rb | 5 +++++ app/models/action/node_input.rb | 3 +++ app/models/action/node_select.rb | 3 +++ app/models/action/node_type.rb | 3 +++ app/models/action/pipeline.rb | 4 +++- app/models/action/template.rb | 3 +++ app/views/action/node_inputs/edit.html.erb | 2 +- app/views/action/node_inputs/index.json.jbuilder | 4 ++-- app/views/action/nodes/_form.html.erb | 6 +++++- app/views/action/nodes/index.html.erb | 2 ++ app/views/action/nodes/index.json.jbuilder | 4 ++-- db/migrate/20240408010103_add_action_nodes_label.rb | 5 +++++ 13 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 db/migrate/20240408010103_add_action_nodes_label.rb diff --git a/app/controllers/action/nodes_controller.rb b/app/controllers/action/nodes_controller.rb index e1e7799f4..d85a6094a 100644 --- a/app/controllers/action/nodes_controller.rb +++ b/app/controllers/action/nodes_controller.rb @@ -61,9 +61,9 @@ class Action::NodesController < ApplicationController def node_params if params.require(:action_node) - params.require(:action_node).permit(:name, :full_name, :description, :icon, :action_node_types_id, :is_local, :local_url, :yaml, :sort_no) + params.require(:action_node).permit(:name, :label, :full_name, :description, :icon, :action_node_types_id, :is_local, :local_url, :yaml, :sort_no) else - params.permit(:name, :full_name, :description, :icon, :action_node_types_id, :is_local, :local_url, :yaml, :sort_no) + params.permit(:name, :label, :full_name, :description, :icon, :action_node_types_id, :is_local, :local_url, :yaml, :sort_no) end end end diff --git a/app/models/action/node.rb b/app/models/action/node.rb index 07d3be134..a761a0216 100644 --- a/app/models/action/node.rb +++ b/app/models/action/node.rb @@ -36,6 +36,11 @@ class Action::Node < ApplicationRecord attr_accessor :cust_name, :run_values, :input_values + validates :name, presence: { message: "不能为空" } + validates :full_name, length: { maximum: 200, too_long: "不能超过200个字符" } + validates :label, length: { maximum: 200, too_long: "不能超过200个字符" } + validates :description, length: { maximum: 65535, too_long: "不能超过65535个字符"} + def content_yaml "foo".to_yaml diff --git a/app/models/action/node_input.rb b/app/models/action/node_input.rb index 4f3825170..7dc475a2e 100644 --- a/app/models/action/node_input.rb +++ b/app/models/action/node_input.rb @@ -24,4 +24,7 @@ class Action::NodeInput < ApplicationRecord default_scope { order(sort_no: :asc) } belongs_to :action_node, :class_name => 'Action::Node', foreign_key: "action_nodes_id" + + validates :name, presence: { message: "不能为空" } + validates :description, length: { maximum: 65535, too_long: "不能超过65535个字符"} end diff --git a/app/models/action/node_select.rb b/app/models/action/node_select.rb index 25be51f99..23cd87bb8 100644 --- a/app/models/action/node_select.rb +++ b/app/models/action/node_select.rb @@ -29,6 +29,9 @@ class Action::NodeSelect < ApplicationRecord belongs_to :action_node, :class_name => 'Action::Node', foreign_key: "action_nodes_id" belongs_to :user, optional: true + validates :name, presence: { message: "不能为空" } + validates :description, length: { maximum: 65535, too_long: "不能超过65535个字符"} + def value if self.val_ext.blank? self.val diff --git a/app/models/action/node_type.rb b/app/models/action/node_type.rb index 7ce78b0fb..59f4ab9de 100644 --- a/app/models/action/node_type.rb +++ b/app/models/action/node_type.rb @@ -15,4 +15,7 @@ class Action::NodeType < ApplicationRecord default_scope { order(sort_no: :asc) } has_many :action_nodes, :class_name => 'Action::Node', foreign_key: "action_node_types_id" + + validates :name, presence: { message: "不能为空" } + validates :description, length: { maximum: 65535, too_long: "不能超过65535个字符"} end diff --git a/app/models/action/pipeline.rb b/app/models/action/pipeline.rb index 1dfbd0f24..227fa4aa8 100644 --- a/app/models/action/pipeline.rb +++ b/app/models/action/pipeline.rb @@ -33,5 +33,7 @@ class Action::Pipeline < ApplicationRecord belongs_to :user, optional: true belongs_to :project - + validates :name, presence: { message: "不能为空" } + validates :json, length: { maximum: 65535, too_long: "不能超过65535个字符"} + validates :yaml, length: { maximum: 65535, too_long: "不能超过65535个字符"} end diff --git a/app/models/action/template.rb b/app/models/action/template.rb index 34b669f66..d854e8854 100644 --- a/app/models/action/template.rb +++ b/app/models/action/template.rb @@ -17,4 +17,7 @@ class Action::Template < ApplicationRecord self.table_name = 'action_templates' default_scope { order(sort_no: :asc) } + validates :name, presence: { message: "不能为空" } + validates :description, length: { maximum: 65535, too_long: "不能超过65535个字符"} + end diff --git a/app/views/action/node_inputs/edit.html.erb b/app/views/action/node_inputs/edit.html.erb index 6ae9f8a78..6139eb73f 100644 --- a/app/views/action/node_inputs/edit.html.erb +++ b/app/views/action/node_inputs/edit.html.erb @@ -39,7 +39,7 @@
- <%= form.submit("保存赛事") %> + <%= form.submit("保存") %>
<% end %> diff --git a/app/views/action/node_inputs/index.json.jbuilder b/app/views/action/node_inputs/index.json.jbuilder index 3909639ce..059a647e4 100644 --- a/app/views/action/node_inputs/index.json.jbuilder +++ b/app/views/action/node_inputs/index.json.jbuilder @@ -2,7 +2,7 @@ json.types @node_types.each do |node_type| if node_type.name.to_s == "未分类" json.extract! node_type, :id, :name json.nodes @no_type_nodes do |node| - json.extract! node, :id, :name, :full_name, :description, :action_node_types_id, :yaml, :sort_no, :use_count + json.extract! node, :id, :label, :name, :full_name, :description, :action_node_types_id, :yaml, :sort_no, :use_count json.inputs node.action_node_inputs do |node_input| json.partial! "node_input", locals: { node_input: node_input, node: node } end @@ -10,7 +10,7 @@ json.types @node_types.each do |node_type| else json.extract! node_type, :id, :name json.nodes node_type.action_nodes do |node| - json.extract! node, :id, :name, :full_name, :description, :action_node_types_id, :yaml, :sort_no, :use_count + json.extract! node, :id, :label, :name, :full_name, :description, :action_node_types_id, :yaml, :sort_no, :use_count json.inputs node.action_node_inputs do |node_input| json.partial! "node_input", locals: { node_input: node_input, node: node } end diff --git a/app/views/action/nodes/_form.html.erb b/app/views/action/nodes/_form.html.erb index 4e40f0ff0..f80395809 100644 --- a/app/views/action/nodes/_form.html.erb +++ b/app/views/action/nodes/_form.html.erb @@ -20,7 +20,11 @@ <%= form.text_field :name %>
- <%= form.label :full_name, "节点全称" %> + <%= form.label :label, "节点标识" %> + <%= form.text_field :label %> +
+
+ <%= form.label :full_name, "节点全名" %> <%= form.text_field :full_name %>
diff --git a/app/views/action/nodes/index.html.erb b/app/views/action/nodes/index.html.erb index 763a8e467..ce603590b 100644 --- a/app/views/action/nodes/index.html.erb +++ b/app/views/action/nodes/index.html.erb @@ -10,6 +10,7 @@ ID 节点名称 + 节点标识 节点全称 节点描述 分类 @@ -27,6 +28,7 @@ <% @nodes.each do |info| %> <%= info.id %> + <%= info.label %> <%= info.name %> <%= info.full_name %> <%= info.description %> diff --git a/app/views/action/nodes/index.json.jbuilder b/app/views/action/nodes/index.json.jbuilder index b81879e20..fc8a38505 100644 --- a/app/views/action/nodes/index.json.jbuilder +++ b/app/views/action/nodes/index.json.jbuilder @@ -2,7 +2,7 @@ json.types @node_types.each do |node_type| if node_type.name.to_s == "未分类" json.extract! node_type, :id, :name json.nodes @no_type_nodes do |node| - json.extract! node, :id, :name, :full_name, :description, :icon, :action_node_types_id, :yaml, :sort_no, :use_count + json.extract! node, :id, :label, :name, :full_name, :description, :icon, :action_node_types_id, :yaml, :sort_no, :use_count json.inputs node.action_node_inputs do |node_input| json.partial! "node_input", locals: { node_input: node_input, node: node } end @@ -10,7 +10,7 @@ json.types @node_types.each do |node_type| else json.extract! node_type, :id, :name json.nodes node_type.action_nodes do |node| - json.extract! node, :id, :name, :full_name, :description, :icon, :action_node_types_id, :yaml, :sort_no, :use_count + json.extract! node, :id, :label, :name, :full_name, :description, :icon, :action_node_types_id, :yaml, :sort_no, :use_count json.inputs node.action_node_inputs do |node_input| json.partial! "node_input", locals: { node_input: node_input, node: node } end diff --git a/db/migrate/20240408010103_add_action_nodes_label.rb b/db/migrate/20240408010103_add_action_nodes_label.rb new file mode 100644 index 000000000..fe88fb4fc --- /dev/null +++ b/db/migrate/20240408010103_add_action_nodes_label.rb @@ -0,0 +1,5 @@ +class AddActionNodesLabel < ActiveRecord::Migration[5.2] + def change + add_column :action_nodes, :label, :string + end +end From 1573abdde12641f06030f5c511a6661746e70468 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 31 May 2024 10:59:38 +0800 Subject: [PATCH 211/294] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BF=E8=8A=82=E7=82=B9=E5=90=8D=E7=A7=B0=EF=BC=8C=E5=92=8C?= =?UTF-8?q?=E6=A0=87=E8=AF=86=E5=8C=BA=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/action/nodes/_form.html.erb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/views/action/nodes/_form.html.erb b/app/views/action/nodes/_form.html.erb index f80395809..0ecee56ed 100644 --- a/app/views/action/nodes/_form.html.erb +++ b/app/views/action/nodes/_form.html.erb @@ -14,14 +14,13 @@ <%= form.select :action_node_types_id, options_for_select(Action::NodeType.all.map { |key| [key.name, key.id]}, node.action_node_types_id), {}, class: "form-control" %> -
- <%= form.label :name, "节点名称" %> - <%= form.text_field :name %> + <%= form.label :label, "节点名称" %> + <%= form.text_field :label %>
- <%= form.label :label, "节点标识" %> - <%= form.text_field :label %> + <%= form.label :name, "节点标识" %> + <%= form.text_field :name %>
<%= form.label :full_name, "节点全名" %> From e0fc9590370ba4c9d4d864edd2eb7a882f1067b7 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 31 May 2024 11:04:30 +0800 Subject: [PATCH 212/294] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BF=E8=8A=82=E7=82=B9=E5=90=8D=E7=A7=B0=EF=BC=8C=E5=92=8C?= =?UTF-8?q?=E6=A0=87=E8=AF=86=E5=8C=BA=E5=88=86label?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 4 ++-- app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index ce662f24d..888e68960 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -110,7 +110,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController # Rails.logger.info "input_node=====0===#{input_node["name"]}======#{input_node["inputs"]}" node = Action::Node.find_by(name: input_node["name"]) next if node.blank? - node.cust_name = input_node["label"] if input_node["label"].present? + node.label = input_node["label"] if input_node["label"].present? run_values = {} input_values = {} if input_node["inputs"].present? @@ -173,7 +173,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController params_nodes.each do |input_node| node = Action::Node.find_by(name: input_node["name"]) next if node.blank? - node.cust_name = input_node["labelf"] if input_node["label"].present? + node.label = input_node["label"] if input_node["label"].present? run_values = {} input_values = {} if input_node["inputs"].present? diff --git a/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb b/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb index d25705687..cbe7a8333 100644 --- a/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb +++ b/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb @@ -44,7 +44,7 @@ jobs: runs-on: 'ubuntu-latest' steps: <%@steps_nodes.each do |node| %> - - name: <%=node.cust_name || node.name %> + - name: <%=node.label || node.name %> <% if node.name !="shell" %> uses: <%=node.full_name %> <% end %> From c98c7d5ac57294ca79f56232fdcd0a3859bbd6e5 Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Tue, 4 Jun 2024 17:25:08 +0800 Subject: [PATCH 213/294] =?UTF-8?q?sonar=20=E8=BD=AC=E5=8F=91=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 1 + Gemfile.lock | 7 ++++ app/assets/javascripts/api/v1/sonarqubes.js | 2 + app/assets/stylesheets/api/v1/sonarqubes.scss | 3 ++ app/controllers/api/v1/projects_controller.rb | 4 -- .../api/v1/sonarqubes_controller.rb | 40 +++++++++++++++++++ app/helpers/api/v1/sonarqubes_helper.rb | 2 + config/routes/api.rb | 7 +++- .../api/v1/sonarqubes_controller_spec.rb | 5 +++ spec/helpers/api/v1/sonarqubes_helper_spec.rb | 15 +++++++ 10 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 app/assets/javascripts/api/v1/sonarqubes.js create mode 100644 app/assets/stylesheets/api/v1/sonarqubes.scss create mode 100644 app/controllers/api/v1/sonarqubes_controller.rb create mode 100644 app/helpers/api/v1/sonarqubes_helper.rb create mode 100644 spec/controllers/api/v1/sonarqubes_controller_spec.rb create mode 100644 spec/helpers/api/v1/sonarqubes_helper_spec.rb diff --git a/Gemfile b/Gemfile index 41e5d2123..07fb6b68b 100644 --- a/Gemfile +++ b/Gemfile @@ -70,6 +70,7 @@ group :development do gem 'web-console', '>= 3.3.0' gem 'listen', '>= 3.0.5', '< 3.2' gem 'spring' + gem 'pry-rails' gem 'spring-watcher-listen', '~> 2.0.0' gem "annotate", "~> 2.6.0" end diff --git a/Gemfile.lock b/Gemfile.lock index 0e18d1f29..fd4d95fa4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -107,6 +107,7 @@ GEM archive-zip (~> 0.10) nokogiri (~> 1.8) chunky_png (1.3.11) + coderay (1.1.3) concurrent-ruby (1.1.6) connection_pool (2.2.2) crass (1.0.6) @@ -255,6 +256,11 @@ GEM popper_js (1.16.0) powerpack (0.1.2) prettier (0.18.2) + pry (0.12.2) + coderay (~> 1.1.0) + method_source (~> 0.9.0) + pry-rails (0.3.9) + pry (>= 0.10.4) public_suffix (4.0.3) puma (5.6.8) nio4r (~> 2.0) @@ -526,6 +532,7 @@ DEPENDENCIES parallel (~> 1.19, >= 1.19.1) pdfkit prettier + pry-rails puma (~> 5.6.5) rack-cors rails (~> 5.2.0) diff --git a/app/assets/javascripts/api/v1/sonarqubes.js b/app/assets/javascripts/api/v1/sonarqubes.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/api/v1/sonarqubes.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/api/v1/sonarqubes.scss b/app/assets/stylesheets/api/v1/sonarqubes.scss new file mode 100644 index 000000000..8b651fe3a --- /dev/null +++ b/app/assets/stylesheets/api/v1/sonarqubes.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the api/v1/sonarqubes controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/api/v1/projects_controller.rb b/app/controllers/api/v1/projects_controller.rb index 33f664b31..d6a90e14a 100644 --- a/app/controllers/api/v1/projects_controller.rb +++ b/app/controllers/api/v1/projects_controller.rb @@ -9,10 +9,6 @@ class Api::V1::ProjectsController < Api::V1::BaseController @result_object = Api::V1::Projects::GetService.call(@project, current_user.gitea_token) end - def sonar_search - data = Sonarqube.client.get("/api/issues/search", { components:"#{@project.owner.login}-#{@project.identifier}" }) - render_ok data - end def compare @result_object = Api::V1::Projects::CompareService.call(@project, params[:from], params[:to], current_user&.gitea_token) diff --git a/app/controllers/api/v1/sonarqubes_controller.rb b/app/controllers/api/v1/sonarqubes_controller.rb new file mode 100644 index 000000000..6db7e2102 --- /dev/null +++ b/app/controllers/api/v1/sonarqubes_controller.rb @@ -0,0 +1,40 @@ +class Api::V1::SonarqubesController < Api::V1::BaseController + def issues_search + params_data = { + components: 'kingchanx-fluid-cloudnative_fluid', + s: 'FILE_LINE', + impactSoftwareQualities: 'SECURITY', + issueStatuses: 'CONFIRMED%2COPEN', + ps: 100, + facets: 'cleanCodeAttributeCategories%2CimpactSoftwareQualities%2CcodeVariants&', + additionalFields: '_all', + timeZone: 'Asia%2FShanghai' + } + data = Sonarqube.client.get('/api/issues/search', params_data) + render_ok data + end + + def ce_component + params_data = { + components: 'kingchanx-fluid-cloudnative_fluid', + } + data = Sonarqube.client.get('/api/ce/component', params_data) + render_ok data + end + + def sources_issue_snippet + params_data = { + issueKey: '93f87856-d71e-44f6-93b6-f9a6d54ff488' + } + data = Sonarqube.client.get('/api/sources/issue_snippets', params_data) + render_ok data + end + + def rules_show + params_data = { + key: 'kubernetes%3AS6865' + } + data = Sonarqube.client.get('/api/rules/show', params_data) + render_ok data + end +end diff --git a/app/helpers/api/v1/sonarqubes_helper.rb b/app/helpers/api/v1/sonarqubes_helper.rb new file mode 100644 index 000000000..94205dc10 --- /dev/null +++ b/app/helpers/api/v1/sonarqubes_helper.rb @@ -0,0 +1,2 @@ +module Api::V1::SonarqubesHelper +end diff --git a/config/routes/api.rb b/config/routes/api.rb index 9eede3e4f..7adc55323 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -76,7 +76,12 @@ defaults format: :json do collection do get :compare get :blame - get :sonar_search + + end + end + resource :sonarqubes, only: [:index] do + collection do + get :search end end diff --git a/spec/controllers/api/v1/sonarqubes_controller_spec.rb b/spec/controllers/api/v1/sonarqubes_controller_spec.rb new file mode 100644 index 000000000..ce71590c4 --- /dev/null +++ b/spec/controllers/api/v1/sonarqubes_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Api::V1::SonarqubesController, type: :controller do + +end diff --git a/spec/helpers/api/v1/sonarqubes_helper_spec.rb b/spec/helpers/api/v1/sonarqubes_helper_spec.rb new file mode 100644 index 000000000..9021add1e --- /dev/null +++ b/spec/helpers/api/v1/sonarqubes_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Api::V1::SonarqubesHelper. For example: +# +# describe Api::V1::SonarqubesHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe Api::V1::SonarqubesHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end From fc8c31ec660535a16eab815ee1f5be3923beac75 Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Wed, 5 Jun 2024 14:09:28 +0800 Subject: [PATCH 214/294] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/sonarqubes_controller.rb | 32 ++++++++++++------- config/routes/api.rb | 9 +++++- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/app/controllers/api/v1/sonarqubes_controller.rb b/app/controllers/api/v1/sonarqubes_controller.rb index 6db7e2102..448b527dc 100644 --- a/app/controllers/api/v1/sonarqubes_controller.rb +++ b/app/controllers/api/v1/sonarqubes_controller.rb @@ -1,14 +1,24 @@ class Api::V1::SonarqubesController < Api::V1::BaseController + def sonar_initialize + + end + + def execute_sonar_sanner + + end + + def issues_search params_data = { - components: 'kingchanx-fluid-cloudnative_fluid', - s: 'FILE_LINE', - impactSoftwareQualities: 'SECURITY', - issueStatuses: 'CONFIRMED%2COPEN', - ps: 100, - facets: 'cleanCodeAttributeCategories%2CimpactSoftwareQualities%2CcodeVariants&', - additionalFields: '_all', - timeZone: 'Asia%2FShanghai' + components: params[:components], + s: params[:s], + impactSoftwareQualities: params[:impactSoftwareQualities], + issueStatuses: params[:issueStatuses], + ps: params[:ps], + p: params[:s], + facets: params[:facets], + additionalFields: params[:additionalFields], + timeZone: params[:timeZone] } data = Sonarqube.client.get('/api/issues/search', params_data) render_ok data @@ -16,7 +26,7 @@ class Api::V1::SonarqubesController < Api::V1::BaseController def ce_component params_data = { - components: 'kingchanx-fluid-cloudnative_fluid', + components: params[:components] } data = Sonarqube.client.get('/api/ce/component', params_data) render_ok data @@ -24,7 +34,7 @@ class Api::V1::SonarqubesController < Api::V1::BaseController def sources_issue_snippet params_data = { - issueKey: '93f87856-d71e-44f6-93b6-f9a6d54ff488' + issueKey: params[:issueKey] } data = Sonarqube.client.get('/api/sources/issue_snippets', params_data) render_ok data @@ -32,7 +42,7 @@ class Api::V1::SonarqubesController < Api::V1::BaseController def rules_show params_data = { - key: 'kubernetes%3AS6865' + key: params[:key] } data = Sonarqube.client.get('/api/rules/show', params_data) render_ok data diff --git a/config/routes/api.rb b/config/routes/api.rb index 7adc55323..95810bee2 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -81,7 +81,14 @@ defaults format: :json do end resource :sonarqubes, only: [:index] do collection do - get :search + get :issues_search + get :ce_component + get :sources_issue_snippet + get :rules_show + + post :sonar_initialize + post :execute_sonar_sanner + end end From 1449064b6487ed7673d41cd50d4a16bb91c8ed2a Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Wed, 5 Jun 2024 16:22:44 +0800 Subject: [PATCH 215/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/sonarqubes_controller.rb | 15 ++++++++++++++- config/routes/api.rb | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/sonarqubes_controller.rb b/app/controllers/api/v1/sonarqubes_controller.rb index 448b527dc..012327a4c 100644 --- a/app/controllers/api/v1/sonarqubes_controller.rb +++ b/app/controllers/api/v1/sonarqubes_controller.rb @@ -1,6 +1,8 @@ class Api::V1::SonarqubesController < Api::V1::BaseController + before_action :load_repository def sonar_initialize - + gitea_params = { has_actions: true } + Gitea::Repository::UpdateService.call(@owner, @project.identifier, gitea_params) end def execute_sonar_sanner @@ -47,4 +49,15 @@ class Api::V1::SonarqubesController < Api::V1::BaseController data = Sonarqube.client.get('/api/rules/show', params_data) render_ok data end + + def measures_search_history + params_data = { + from: params[:form], + component: params[:component], + metrics: params[:metrics], + ps: params[:ps] + } + data = Sonarqube.client.get('/api/measures/search_history', params_data) + render_ok data + end end diff --git a/config/routes/api.rb b/config/routes/api.rb index 95810bee2..31f0bc64a 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -85,6 +85,7 @@ defaults format: :json do get :ce_component get :sources_issue_snippet get :rules_show + get :measures_search_history post :sonar_initialize post :execute_sonar_sanner From 4438b11c518aad635e7ff5a256438d06a937053a Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Wed, 5 Jun 2024 16:54:57 +0800 Subject: [PATCH 216/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8E=A5=E5=8F=A3=20?= =?UTF-8?q?measures=5Fcomponent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/sonarqubes_controller.rb | 10 ++++++++++ config/routes/api.rb | 1 + 2 files changed, 11 insertions(+) diff --git a/app/controllers/api/v1/sonarqubes_controller.rb b/app/controllers/api/v1/sonarqubes_controller.rb index 012327a4c..ae8d7e5b8 100644 --- a/app/controllers/api/v1/sonarqubes_controller.rb +++ b/app/controllers/api/v1/sonarqubes_controller.rb @@ -60,4 +60,14 @@ class Api::V1::SonarqubesController < Api::V1::BaseController data = Sonarqube.client.get('/api/measures/search_history', params_data) render_ok data end + + def measures_component + params_data = { + component: params[:component], + additionalFields: params[:additionalFields], + metricKeys: params[:metricKeys], + } + data = Sonarqube.client.get('/api/measures/component', params_data) + render_ok data + end end diff --git a/config/routes/api.rb b/config/routes/api.rb index 31f0bc64a..13660a404 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -86,6 +86,7 @@ defaults format: :json do get :sources_issue_snippet get :rules_show get :measures_search_history + get :measures_component post :sonar_initialize post :execute_sonar_sanner From 69568cf62639063db2f1fcb86ba1c213bdb8f3a3 Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Thu, 6 Jun 2024 14:31:28 +0800 Subject: [PATCH 217/294] =?UTF-8?q?=E6=96=B0=E5=A2=9Esonar=20action?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/sonarqubes_controller.rb | 55 +++++++++++++++++-- .../repository/action_secrets_service.rb | 33 +++++++++++ config/initializers/sonarqube.rb | 6 +- config/routes/api.rb | 2 +- 4 files changed, 89 insertions(+), 7 deletions(-) create mode 100644 app/services/gitea/repository/action_secrets_service.rb diff --git a/app/controllers/api/v1/sonarqubes_controller.rb b/app/controllers/api/v1/sonarqubes_controller.rb index ae8d7e5b8..bde3913e4 100644 --- a/app/controllers/api/v1/sonarqubes_controller.rb +++ b/app/controllers/api/v1/sonarqubes_controller.rb @@ -1,15 +1,62 @@ class Api::V1::SonarqubesController < Api::V1::BaseController before_action :load_repository def sonar_initialize - gitea_params = { has_actions: true } - Gitea::Repository::UpdateService.call(@owner, @project.identifier, gitea_params) + gitea_params = { has_actions: params[:has_actions] == 'true' ? true :false } + gitea_setting = Gitea::Repository::UpdateService.call(@owner, @project.identifier, gitea_params) + if gitea_setting['has_actions'] == true + Gitea::Repository::ActionSecretsService.new(@owner, @project.identifier, 'SONAR_HOST_URL', Rails.application.config_for(:configuration)['sonarqube']['url'] ).call + Gitea::Repository::ActionSecretsService.new(@owner, @project.identifier, 'SONAR_TOKEN', Rails.application.config_for(:configuration)['sonarqube']['secret'] ).call + else + Gitea::Repository::ActionSecretsService.new(@owner, @project.identifier, 'SONAR_HOST_URL', Rails.application.config_for(:configuration)['sonarqube']['url'] ).destroy + Gitea::Repository::ActionSecretsService.new(@owner, @project.identifier, 'SONAR_TOKEN', Rails.application.config_for(:configuration)['sonarqube']['secret'] ).destroy + end + render_ok end - def execute_sonar_sanner + def insert_file + sonar_scanner_content = { + filepath: '.gitea/workflows/SonarScanner.yaml', + branch: params[:branch], + new_branch: nil, + content: 'b246CiAgIyBUcmlnZ2VyIGFuYWx5c2lzIHdoZW4gcHVzaGluZyB0byB5b3VyIG1haW4gYnJhbmNoZXMsIGFuZCB3aGVuIGNyZWF0aW5nIGEgcHVsbCByZXF1ZXN0LgogIHB1c2g6CiAgICBicmFuY2hlczoKICAgICAgLSBtYWluCiAgICAgIC0gbWFzdGVyCiAgICAgIC0gZGV2ZWxvcAogICAgICAtICdyZWxlYXNlcy8qKicKICBwdWxsX3JlcXVlc3Q6CiAgICAgIHR5cGVzOiBbb3BlbmVkLCBzeW5jaHJvbml6ZSwgcmVvcGVuZWRdCgpuYW1lOiBNYWluIFdvcmtmbG93CmpvYnM6CiAgc29uYXJxdWJlOgogICAgcnVucy1vbjogdWJ1bnR1LWxhdGVzdAogICAgc3RlcHM6CiAgICAtIHVzZXM6IGFjdGlvbnMvY2hlY2tvdXRAdjQKICAgICAgd2l0aDoKICAgICAgICAjIERpc2FibGluZyBzaGFsbG93IGNsb25lcyBpcyByZWNvbW1lbmRlZCBmb3IgaW1wcm92aW5nIHRoZSByZWxldmFuY3kgb2YgcmVwb3J0aW5nCiAgICAgICAgZmV0Y2gtZGVwdGg6IDAKICAgIC0gbmFtZTogU29uYXJRdWJlIFNjYW4KICAgICAgdXNlczogc29uYXJzb3VyY2Uvc29uYXJxdWJlLXNjYW4tYWN0aW9uQG1hc3RlcgogICAgICBlbnY6CiAgICAgICAgU09OQVJfVE9LRU46ICR7eyBzZWNyZXRzLlNPTkFSX1RPS0VOIH19CiAgICAgICAgU09OQVJfSE9TVF9VUkw6ICAke3sgc2VjcmV0cy5TT05BUl9IT1NUX1VSTCB9fQ==', + message: 'Add .gitea/workflows/SonarScanner.yaml', + committer: { + email: @owner.mail, + name: @owner.login + }, + identifier: @project.identifier + } + @path = GiteaService.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{params[:branch]}/" + sonar_scanner_exit = Repositories::EntriesInteractor.call(@owner, @project.identifier, '.gitea/workflows/SonarScanner.yaml', ref: params[:branch]) + if sonar_scanner_exit.success? + sonar_scanner_content[:content] = Base64.decode64(sonar_scanner_content[:content]) + Gitea::UpdateFileInteractor.call(@owner.gitea_token, @owner.login, sonar_scanner_content.merge(sha:sonar_scanner_exit.result['sha'])) + else + Gitea::CreateFileInteractor.call(@owner.gitea_token, @owner.login, sonar_scanner_content) + end + sonar_project_content = { + filepath: 'sonar-project.properties', + branch: params[:branch], + new_branch: nil, + "content": "sonar.projectKey=#{params[:owner]}-#{params[:repo]}\nsonar.sources=.", + "message": 'Add sonar-project.properties', + committer: { + email: @owner.mail, + name: @owner.login + }, + identifier: @project.identifier + } + sonar_project_exit = Repositories::EntriesInteractor.call(@owner, @project.identifier, 'sonar-project.properties', ref: params[:branch]) + if sonar_project_exit.success? + Gitea::UpdateFileInteractor.call(@owner.gitea_token, @owner.login, sonar_project_content.merge(sha:sonar_project_exit.result['sha'])) + else + sonar_project_content[:content] = Base64.strict_encode64(sonar_project_content[:content]) + Gitea::CreateFileInteractor.call(@owner.gitea_token, @owner.login, sonar_project_content) + end + render_ok end - def issues_search params_data = { components: params[:components], diff --git a/app/services/gitea/repository/action_secrets_service.rb b/app/services/gitea/repository/action_secrets_service.rb new file mode 100644 index 000000000..d5e782073 --- /dev/null +++ b/app/services/gitea/repository/action_secrets_service.rb @@ -0,0 +1,33 @@ +class Gitea::Repository::ActionSecretsService < Gitea::ClientService + attr_reader :owner, :repo, :secret_name, :secret + + def initialize(owner, repo, secret_name, secret) + @owner = owner + @repo = repo + @secret_name = secret_name + @secret = secret + end + + def call + response = put(url, request_params) + render_201_response(response) + end + + def destroy + response = delete(url, request_params) + render_201_response(response) + end + + + private + + def request_params + Hash.new.merge(token: owner.gitea_token, data: { data: secret } ) + end + + + + def url + "/repos/#{owner.login}/#{repo}/actions/secrets/#{secret_name}".freeze + end +end diff --git a/config/initializers/sonarqube.rb b/config/initializers/sonarqube.rb index 99c88c82a..30754885c 100644 --- a/config/initializers/sonarqube.rb +++ b/config/initializers/sonarqube.rb @@ -1,6 +1,8 @@ +sonarqube_config = Rails.application.config_for(:configuration)['sonarqube'] + Sonarqube.configure do |config| - config.endpoint = 'http://172.20.32.202:9999' # API endpoint URL, default: ENV['SONARQUBE_API_ENDPOINT'] - config.private_token = 'squ_fb81f52a7b2c2db00c71c29f71c9595f48c2ff3f' # user's private token, default: ENV['SONARQUBE_API_PRIVATE_TOKEN'] + config.endpoint = sonarqube_config["url"] # API endpoint URL, default: ENV['SONARQUBE_API_ENDPOINT'] + config.private_token = sonarqube_config["secret"] # user's private token, default: ENV['SONARQUBE_API_PRIVATE_TOKEN'] # Optional # config.user_agent = 'Custom User Agent' # user agent, default: 'Sonarqube Ruby Gem [version]' end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index 13660a404..998d699bd 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -89,7 +89,7 @@ defaults format: :json do get :measures_component post :sonar_initialize - post :execute_sonar_sanner + post :insert_file end end From 619dce03ca47af0c202bcc9977f954f85b45addc Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Tue, 11 Jun 2024 10:19:40 +0800 Subject: [PATCH 218/294] update project details --- app/views/repositories/detail.json.jbuilder | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/repositories/detail.json.jbuilder b/app/views/repositories/detail.json.jbuilder index 0e5d850a5..4f04e9701 100644 --- a/app/views/repositories/detail.json.jbuilder +++ b/app/views/repositories/detail.json.jbuilder @@ -20,6 +20,7 @@ json.version_releasesed_count @project.releases_size(@user.try(:id), "released") json.permission render_permission(@user, @project) json.mirror_url @project&.repository.remote_mirror_url json.mirror @project&.repository.mirror_url.present? +json.has_actions @project.try(:has_actions) json.web_site @project.page.try(:identifier) json.type @project.numerical_for_project_type json.open_devops @project.open_devops? From ee7916de01661229322f1d6f77543e7c87ea61f0 Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Tue, 11 Jun 2024 10:48:49 +0800 Subject: [PATCH 219/294] update total issue count rule --- app/services/api/v1/issues/list_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index c27dcd29f..1f0781347 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -64,7 +64,7 @@ class Api::V1::Issues::ListService < ApplicationService private def issue_query_data issues = @project&.id.zero? ? Issue.issue_issue : @project.issues.issue_issue - @total_issues_count = issues.distinct.size + @total_issues_count = issues.where(pm_issue_type:[1, 2, 3]).distinct.size case participant_category when 'aboutme' # 关于我的 issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: %w[authored assigned atme], participant_id: participator&.id}) From f6f8a1ca87c8269f20e842a974b383031a359c65 Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Tue, 11 Jun 2024 10:58:13 +0800 Subject: [PATCH 220/294] update project pm statistics --- app/controllers/api/pm/projects_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index 2c343cf3a..b70bd7240 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -55,7 +55,7 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController def statistics return tip_exception '参数错误' if params[:pm_project_id].blank? - @issues = Issue.where(pm_project_id: params[:pm_project_id]) + @issues = Issue.where(pm_project_id: params[:pm_project_id], pm_issue_type:[1, 2, 3]) type_count_data = @issues.group(:pm_issue_type).count type_status = @issues.group(:pm_issue_type,:status_id).count type_status_data = {} From 1450aec0f565ec9a610a92d2416b794fd2fb7f9a Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Tue, 11 Jun 2024 11:47:41 +0800 Subject: [PATCH 221/294] update change pm_issue_type rule --- app/services/api/v1/issues/update_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 895c98c5c..c03a868b1 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -79,7 +79,7 @@ class Api::V1::Issues::UpdateService < ApplicationService #Pm相关 @updated_issue.pm_project_id = @target_pm_project_id unless @target_pm_project_id.nil? @updated_issue.pm_sprint_id = @pm_sprint_id unless @pm_sprint_id.nil? - @updated_issue.pm_issue_type = @pm_issue_type unless @pm_issue_type.nil? + @updated_issue.pm_issue_type = @pm_issue_type unless @pm_issue_type.nil? && @pm_issue_type.children_issues.count > 0 && @pm_issue_type.parent_id.present? @updated_issue.root_id = @root_id unless @root_id.nil? #不为 nil的时候更新 @updated_issue.root_id = nil if @root_id.try(:zero?) #为 0 的时候设置为 nil @updated_issue.time_scale = @time_scale unless @time_scale.nil? From 069f165fc5e8af8a92ac94ed89f5e1596d9b46d2 Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Tue, 11 Jun 2024 16:03:22 +0800 Subject: [PATCH 222/294] fix sonar quest --- .../api/v1/sonarqubes_controller.rb | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/app/controllers/api/v1/sonarqubes_controller.rb b/app/controllers/api/v1/sonarqubes_controller.rb index bde3913e4..5e3c14f70 100644 --- a/app/controllers/api/v1/sonarqubes_controller.rb +++ b/app/controllers/api/v1/sonarqubes_controller.rb @@ -1,5 +1,5 @@ class Api::V1::SonarqubesController < Api::V1::BaseController - before_action :load_repository + #before_action :load_repository def sonar_initialize gitea_params = { has_actions: params[:has_actions] == 'true' ? true :false } gitea_setting = Gitea::Repository::UpdateService.call(@owner, @project.identifier, gitea_params) @@ -59,7 +59,7 @@ class Api::V1::SonarqubesController < Api::V1::BaseController def issues_search params_data = { - components: params[:components], + components: "#{params[:owner]}-#{params[:repo]}", s: params[:s], impactSoftwareQualities: params[:impactSoftwareQualities], issueStatuses: params[:issueStatuses], @@ -69,15 +69,15 @@ class Api::V1::SonarqubesController < Api::V1::BaseController additionalFields: params[:additionalFields], timeZone: params[:timeZone] } - data = Sonarqube.client.get('/api/issues/search', params_data) + data = Sonarqube.client.get('/api/issues/search', query: params_data) render_ok data end def ce_component params_data = { - components: params[:components] + components: "#{params[:owner]}-#{params[:repo]}", } - data = Sonarqube.client.get('/api/ce/component', params_data) + data = Sonarqube.client.get('/api/ce/component', query: params_data) render_ok data end @@ -85,7 +85,7 @@ class Api::V1::SonarqubesController < Api::V1::BaseController params_data = { issueKey: params[:issueKey] } - data = Sonarqube.client.get('/api/sources/issue_snippets', params_data) + data = Sonarqube.client.get('/api/sources/issue_snippets', query: params_data) render_ok data end @@ -93,28 +93,29 @@ class Api::V1::SonarqubesController < Api::V1::BaseController params_data = { key: params[:key] } - data = Sonarqube.client.get('/api/rules/show', params_data) + data = Sonarqube.client.get('/api/rules/show', query: params_data) render_ok data end def measures_search_history params_data = { from: params[:form], - component: params[:component], + component: "#{params[:owner]}-#{params[:repo]}", metrics: params[:metrics], ps: params[:ps] } - data = Sonarqube.client.get('/api/measures/search_history', params_data) + data = Sonarqube.client.get('/api/measures/search_history', query: params_data) render_ok data end def measures_component params_data = { - component: params[:component], + component: "#{params[:owner]}-#{params[:repo]}", additionalFields: params[:additionalFields], - metricKeys: params[:metricKeys], + metricKeys: params[:metricKeys] } - data = Sonarqube.client.get('/api/measures/component', params_data) + data = Sonarqube.client.get('/api/measures/component', query: params_data) + Sonarqube.project_create('new_project') render_ok data end end From b6746d5c494c14ac2c9dedcb684ec49eadb47db8 Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Tue, 11 Jun 2024 16:12:51 +0800 Subject: [PATCH 223/294] fix sonar quest error --- app/controllers/api/v1/sonarqubes_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/api/v1/sonarqubes_controller.rb b/app/controllers/api/v1/sonarqubes_controller.rb index 5e3c14f70..9a736314f 100644 --- a/app/controllers/api/v1/sonarqubes_controller.rb +++ b/app/controllers/api/v1/sonarqubes_controller.rb @@ -115,7 +115,6 @@ class Api::V1::SonarqubesController < Api::V1::BaseController metricKeys: params[:metricKeys] } data = Sonarqube.client.get('/api/measures/component', query: params_data) - Sonarqube.project_create('new_project') render_ok data end end From 3b60fee922285cc5fff6be7560ef5ddc0f273916 Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Tue, 11 Jun 2024 16:17:18 +0800 Subject: [PATCH 224/294] load repo --- app/controllers/api/v1/sonarqubes_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/sonarqubes_controller.rb b/app/controllers/api/v1/sonarqubes_controller.rb index 9a736314f..49614486c 100644 --- a/app/controllers/api/v1/sonarqubes_controller.rb +++ b/app/controllers/api/v1/sonarqubes_controller.rb @@ -1,5 +1,5 @@ class Api::V1::SonarqubesController < Api::V1::BaseController - #before_action :load_repository + before_action :load_repository def sonar_initialize gitea_params = { has_actions: params[:has_actions] == 'true' ? true :false } gitea_setting = Gitea::Repository::UpdateService.call(@owner, @project.identifier, gitea_params) @@ -116,5 +116,5 @@ class Api::V1::SonarqubesController < Api::V1::BaseController } data = Sonarqube.client.get('/api/measures/component', query: params_data) render_ok data - end + end end From 73b2173a2d051061cbbcd56e70e8ac073a0f6709 Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Tue, 11 Jun 2024 16:23:54 +0800 Subject: [PATCH 225/294] fix issues_search --- app/controllers/api/v1/sonarqubes_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/v1/sonarqubes_controller.rb b/app/controllers/api/v1/sonarqubes_controller.rb index 49614486c..f6bc80638 100644 --- a/app/controllers/api/v1/sonarqubes_controller.rb +++ b/app/controllers/api/v1/sonarqubes_controller.rb @@ -64,7 +64,7 @@ class Api::V1::SonarqubesController < Api::V1::BaseController impactSoftwareQualities: params[:impactSoftwareQualities], issueStatuses: params[:issueStatuses], ps: params[:ps], - p: params[:s], + p: params[:p], facets: params[:facets], additionalFields: params[:additionalFields], timeZone: params[:timeZone] From 1a53054e58ea3f978bf77c1f66465507e224e4b0 Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Tue, 11 Jun 2024 16:37:29 +0800 Subject: [PATCH 226/294] add params --- app/controllers/api/v1/sonarqubes_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/sonarqubes_controller.rb b/app/controllers/api/v1/sonarqubes_controller.rb index f6bc80638..d924d011d 100644 --- a/app/controllers/api/v1/sonarqubes_controller.rb +++ b/app/controllers/api/v1/sonarqubes_controller.rb @@ -67,7 +67,10 @@ class Api::V1::SonarqubesController < Api::V1::BaseController p: params[:p], facets: params[:facets], additionalFields: params[:additionalFields], - timeZone: params[:timeZone] + timeZone: params[:timeZone], + types: params[:types], + impactSeverities: params[:impactSeverities], + tags: params[:tags] } data = Sonarqube.client.get('/api/issues/search', query: params_data) render_ok data From 486156ff92c55279abaf62bb6bc7173494b20eca Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Wed, 12 Jun 2024 11:22:20 +0800 Subject: [PATCH 227/294] =?UTF-8?q?=E5=8F=8C=E5=90=91=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issue_links_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/pm/issue_links_controller.rb b/app/controllers/api/pm/issue_links_controller.rb index 844c01597..b6fa91774 100644 --- a/app/controllers/api/pm/issue_links_controller.rb +++ b/app/controllers/api/pm/issue_links_controller.rb @@ -2,7 +2,7 @@ class Api::Pm::IssueLinksController < Api::Pm::BaseController before_action :load_project before_action :load_issue def index - @links = @issue.pm_links.where(be_linkable_type: 'Issue') + @links = PmLink.where(be_linkable_id: @issue.id,be_linkable_type: 'Issue').or(PmLink.where(linkable_id: @issue.id,linkable_type: 'Issue')) end def create From 49b4224a69635affa1111c499ad9034eda6f7567 Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Wed, 12 Jun 2024 15:12:20 +0800 Subject: [PATCH 228/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=91=A8=E6=8A=A5=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/issues/update_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index c03a868b1..c55115ded 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -79,7 +79,7 @@ class Api::V1::Issues::UpdateService < ApplicationService #Pm相关 @updated_issue.pm_project_id = @target_pm_project_id unless @target_pm_project_id.nil? @updated_issue.pm_sprint_id = @pm_sprint_id unless @pm_sprint_id.nil? - @updated_issue.pm_issue_type = @pm_issue_type unless @pm_issue_type.nil? && @pm_issue_type.children_issues.count > 0 && @pm_issue_type.parent_id.present? + @updated_issue.pm_issue_type = @pm_issue_type unless @pm_issue_type.nil? && @updated_issue.children_issues.count > 0 && @updated_issue.parent_id.present? @updated_issue.root_id = @root_id unless @root_id.nil? #不为 nil的时候更新 @updated_issue.root_id = nil if @root_id.try(:zero?) #为 0 的时候设置为 nil @updated_issue.time_scale = @time_scale unless @time_scale.nil? From 105f4401c2d01dafac5e0505bb082e3e484ea87d Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Wed, 12 Jun 2024 16:14:25 +0800 Subject: [PATCH 229/294] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=88=A4=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/issues/update_service.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index c55115ded..5f040b25f 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -79,7 +79,9 @@ class Api::V1::Issues::UpdateService < ApplicationService #Pm相关 @updated_issue.pm_project_id = @target_pm_project_id unless @target_pm_project_id.nil? @updated_issue.pm_sprint_id = @pm_sprint_id unless @pm_sprint_id.nil? - @updated_issue.pm_issue_type = @pm_issue_type unless @pm_issue_type.nil? && @updated_issue.children_issues.count > 0 && @updated_issue.parent_id.present? + if @updated_issue.children_issues.count == 0 && @updated_issue.parent_id.nil? + @updated_issue.pm_issue_type = @pm_issue_type unless @pm_issue_type.nil? + end @updated_issue.root_id = @root_id unless @root_id.nil? #不为 nil的时候更新 @updated_issue.root_id = nil if @root_id.try(:zero?) #为 0 的时候设置为 nil @updated_issue.time_scale = @time_scale unless @time_scale.nil? From 89d6a3f48da06c0c8cb95bcc156a72b57ba1fd48 Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Thu, 13 Jun 2024 09:17:59 +0800 Subject: [PATCH 230/294] =?UTF-8?q?=E8=B0=83=E6=95=B4gitea=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/sonarqubes_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/v1/sonarqubes_controller.rb b/app/controllers/api/v1/sonarqubes_controller.rb index d924d011d..8c363a8d5 100644 --- a/app/controllers/api/v1/sonarqubes_controller.rb +++ b/app/controllers/api/v1/sonarqubes_controller.rb @@ -18,7 +18,7 @@ class Api::V1::SonarqubesController < Api::V1::BaseController filepath: '.gitea/workflows/SonarScanner.yaml', branch: params[:branch], new_branch: nil, - content: 'b246CiAgIyBUcmlnZ2VyIGFuYWx5c2lzIHdoZW4gcHVzaGluZyB0byB5b3VyIG1haW4gYnJhbmNoZXMsIGFuZCB3aGVuIGNyZWF0aW5nIGEgcHVsbCByZXF1ZXN0LgogIHB1c2g6CiAgICBicmFuY2hlczoKICAgICAgLSBtYWluCiAgICAgIC0gbWFzdGVyCiAgICAgIC0gZGV2ZWxvcAogICAgICAtICdyZWxlYXNlcy8qKicKICBwdWxsX3JlcXVlc3Q6CiAgICAgIHR5cGVzOiBbb3BlbmVkLCBzeW5jaHJvbml6ZSwgcmVvcGVuZWRdCgpuYW1lOiBNYWluIFdvcmtmbG93CmpvYnM6CiAgc29uYXJxdWJlOgogICAgcnVucy1vbjogdWJ1bnR1LWxhdGVzdAogICAgc3RlcHM6CiAgICAtIHVzZXM6IGFjdGlvbnMvY2hlY2tvdXRAdjQKICAgICAgd2l0aDoKICAgICAgICAjIERpc2FibGluZyBzaGFsbG93IGNsb25lcyBpcyByZWNvbW1lbmRlZCBmb3IgaW1wcm92aW5nIHRoZSByZWxldmFuY3kgb2YgcmVwb3J0aW5nCiAgICAgICAgZmV0Y2gtZGVwdGg6IDAKICAgIC0gbmFtZTogU29uYXJRdWJlIFNjYW4KICAgICAgdXNlczogc29uYXJzb3VyY2Uvc29uYXJxdWJlLXNjYW4tYWN0aW9uQG1hc3RlcgogICAgICBlbnY6CiAgICAgICAgU09OQVJfVE9LRU46ICR7eyBzZWNyZXRzLlNPTkFSX1RPS0VOIH19CiAgICAgICAgU09OQVJfSE9TVF9VUkw6ICAke3sgc2VjcmV0cy5TT05BUl9IT1NUX1VSTCB9fQ==', + content: 'b246CiAgIyBUcmlnZ2VyIGFuYWx5c2lzIHdoZW4gcHVzaGluZyB0byB5b3VyIG1haW4gYnJhbmNoZXMsIGFuZCB3aGVuIGNyZWF0aW5nIGEgcHVsbCByZXF1ZXN0LgogIHB1c2g6CiAgICBicmFuY2hlczoKICAgICAgLSBtYWluCiAgICAgIC0gbWFzdGVyCiAgICAgIC0gZGV2ZWxvcAogICAgICAtICdyZWxlYXNlcy8qKicKICBwdWxsX3JlcXVlc3Q6CiAgICAgIHR5cGVzOiBbb3BlbmVkLCBzeW5jaHJvbml6ZSwgcmVvcGVuZWRdCgpuYW1lOiBNYWluIFdvcmtmbG93CmpvYnM6CiAgc29uYXJxdWJlOgogICAgcnVucy1vbjogdWJ1bnR1LWxhdGVzdAogICAgc3RlcHM6CiAgICAtIHVzZXM6IGh0dHBzOi8vZ2l0bGluay5vcmcuY24vS2luZ0NoYW4vY2hlY2tvdXRAdjQKICAgICAgd2l0aDoKICAgICAgICAjIERpc2FibGluZyBzaGFsbG93IGNsb25lcyBpcyByZWNvbW1lbmRlZCBmb3IgaW1wcm92aW5nIHRoZSByZWxldmFuY3kgb2YgcmVwb3J0aW5nCiAgICAgICAgZmV0Y2gtZGVwdGg6IDAKICAgIC0gbmFtZTogU29uYXJRdWJlIFNjYW4KICAgICAgdXNlczogaHR0cHM6Ly9naXRsaW5rLm9yZy5jbi9LaW5nQ2hhbi9zb25hcnF1YmUtc2Nhbi1hY3Rpb25AbWFzdGVyCiAgICAgIGVudjoKICAgICAgICBTT05BUl9UT0tFTjogJHt7IHNlY3JldHMuU09OQVJfVE9LRU4gfX0KICAgICAgICBTT05BUl9IT1NUX1VSTDogICR7eyBzZWNyZXRzLlNPTkFSX0hPU1RfVVJMIH19==', message: 'Add .gitea/workflows/SonarScanner.yaml', committer: { email: @owner.mail, From 502884810dcc43b8bd852aa914cd04b1eb8f77ed Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Thu, 13 Jun 2024 09:23:24 +0800 Subject: [PATCH 231/294] =?UTF-8?q?=E8=B0=83=E6=95=B4gitea=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/sonarqubes_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/v1/sonarqubes_controller.rb b/app/controllers/api/v1/sonarqubes_controller.rb index 8c363a8d5..5fe88ab91 100644 --- a/app/controllers/api/v1/sonarqubes_controller.rb +++ b/app/controllers/api/v1/sonarqubes_controller.rb @@ -18,7 +18,7 @@ class Api::V1::SonarqubesController < Api::V1::BaseController filepath: '.gitea/workflows/SonarScanner.yaml', branch: params[:branch], new_branch: nil, - content: 'b246CiAgIyBUcmlnZ2VyIGFuYWx5c2lzIHdoZW4gcHVzaGluZyB0byB5b3VyIG1haW4gYnJhbmNoZXMsIGFuZCB3aGVuIGNyZWF0aW5nIGEgcHVsbCByZXF1ZXN0LgogIHB1c2g6CiAgICBicmFuY2hlczoKICAgICAgLSBtYWluCiAgICAgIC0gbWFzdGVyCiAgICAgIC0gZGV2ZWxvcAogICAgICAtICdyZWxlYXNlcy8qKicKICBwdWxsX3JlcXVlc3Q6CiAgICAgIHR5cGVzOiBbb3BlbmVkLCBzeW5jaHJvbml6ZSwgcmVvcGVuZWRdCgpuYW1lOiBNYWluIFdvcmtmbG93CmpvYnM6CiAgc29uYXJxdWJlOgogICAgcnVucy1vbjogdWJ1bnR1LWxhdGVzdAogICAgc3RlcHM6CiAgICAtIHVzZXM6IGh0dHBzOi8vZ2l0bGluay5vcmcuY24vS2luZ0NoYW4vY2hlY2tvdXRAdjQKICAgICAgd2l0aDoKICAgICAgICAjIERpc2FibGluZyBzaGFsbG93IGNsb25lcyBpcyByZWNvbW1lbmRlZCBmb3IgaW1wcm92aW5nIHRoZSByZWxldmFuY3kgb2YgcmVwb3J0aW5nCiAgICAgICAgZmV0Y2gtZGVwdGg6IDAKICAgIC0gbmFtZTogU29uYXJRdWJlIFNjYW4KICAgICAgdXNlczogaHR0cHM6Ly9naXRsaW5rLm9yZy5jbi9LaW5nQ2hhbi9zb25hcnF1YmUtc2Nhbi1hY3Rpb25AbWFzdGVyCiAgICAgIGVudjoKICAgICAgICBTT05BUl9UT0tFTjogJHt7IHNlY3JldHMuU09OQVJfVE9LRU4gfX0KICAgICAgICBTT05BUl9IT1NUX1VSTDogICR7eyBzZWNyZXRzLlNPTkFSX0hPU1RfVVJMIH19==', + content: 'b246CiAgIyBUcmlnZ2VyIGFuYWx5c2lzIHdoZW4gcHVzaGluZyB0byB5b3VyIG1haW4gYnJhbmNoZXMsIGFuZCB3aGVuIGNyZWF0aW5nIGEgcHVsbCByZXF1ZXN0LgogIHB1c2g6CiAgICBicmFuY2hlczoKICAgICAgLSBtYWluCiAgICAgIC0gbWFzdGVyCiAgICAgIC0gZGV2ZWxvcAogICAgICAtICdyZWxlYXNlcy8qKicKICBwdWxsX3JlcXVlc3Q6CiAgICAgIHR5cGVzOiBbb3BlbmVkLCBzeW5jaHJvbml6ZSwgcmVvcGVuZWRdCgpuYW1lOiBNYWluIFdvcmtmbG93CmpvYnM6CiAgc29uYXJxdWJlOgogICAgcnVucy1vbjogdWJ1bnR1LWxhdGVzdAogICAgc3RlcHM6CiAgICAtIHVzZXM6IGh0dHBzOi8vZ2l0bGluay5vcmcuY24vS2luZ0NoYW4vY2hlY2tvdXRAdjQKICAgICAgd2l0aDoKICAgICAgICAjIERpc2FibGluZyBzaGFsbG93IGNsb25lcyBpcyByZWNvbW1lbmRlZCBmb3IgaW1wcm92aW5nIHRoZSByZWxldmFuY3kgb2YgcmVwb3J0aW5nCiAgICAgICAgZmV0Y2gtZGVwdGg6IDAKICAgIC0gbmFtZTogU29uYXJRdWJlIFNjYW4KICAgICAgdXNlczogaHR0cHM6Ly9naXRsaW5rLm9yZy5jbi9LaW5nQ2hhbi9zb25hcnF1YmUtc2Nhbi1hY3Rpb25AbWFzdGVyCiAgICAgIGVudjoKICAgICAgICBTT05BUl9UT0tFTjogJHt7IHNlY3JldHMuU09OQVJfVE9LRU4gfX0KICAgICAgICBTT05BUl9IT1NUX1VSTDogICR7eyBzZWNyZXRzLlNPTkFSX0hPU1RfVVJMIH19', message: 'Add .gitea/workflows/SonarScanner.yaml', committer: { email: @owner.mail, From 0c509c58ed629bac3483dc00b7b5ea69d69e923d Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Thu, 13 Jun 2024 11:21:51 +0800 Subject: [PATCH 232/294] =?UTF-8?q?=E8=B0=83=E6=95=B4pm=20issue=20link?= =?UTF-8?q?=E6=B8=B2=E6=9F=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/api/pm/issue_links/index.json.jbuilder | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/views/api/pm/issue_links/index.json.jbuilder b/app/views/api/pm/issue_links/index.json.jbuilder index 5a563feba..46a5f0cc2 100644 --- a/app/views/api/pm/issue_links/index.json.jbuilder +++ b/app/views/api/pm/issue_links/index.json.jbuilder @@ -1,4 +1,8 @@ json.issues @links.each do |link| - json.partial! "api/v1/issues/simple_detail", locals: { issue: link.be_linkable } + if @issue.id == link.be_linkable_id + json.partial! "api/v1/issues/simple_detail", locals: { issue: link.linkable } + else + json.partial! "api/v1/issues/simple_detail", locals: { issue: link.be_linkable } + end end \ No newline at end of file From 3dfb616213f81e3cf682422deca98480ad7c4cf6 Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Thu, 13 Jun 2024 16:47:15 +0800 Subject: [PATCH 233/294] =?UTF-8?q?=E5=8F=8C=E5=90=91=E5=85=B3=E8=81=94?= =?UTF-8?q?=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/issues/delete_service.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/services/api/v1/issues/delete_service.rb b/app/services/api/v1/issues/delete_service.rb index 02b2b533c..4d7ff7cfc 100644 --- a/app/services/api/v1/issues/delete_service.rb +++ b/app/services/api/v1/issues/delete_service.rb @@ -16,6 +16,8 @@ class Api::V1::Issues::DeleteService < ApplicationService try_lock("Api::V1::Issues::DeleteService:#{project.id}") # 开始写数据,加锁 delete_issue + #删除双向关联 + PmLink.where(be_linkable_id: @issue.id, be_linkable_type: 'Issue').or(PmLink.where(linkable_id: @issue.id, linkable_type: 'Issue')).map(&:destroy) project.incre_project_issue_cache_delete_count From 68bb149dabb98247bd2bc6744f618e9ed817ad25 Mon Sep 17 00:00:00 2001 From: KingChan <281221230@qq.com> Date: Fri, 14 Jun 2024 09:43:48 +0800 Subject: [PATCH 234/294] Update list_service.rb --- app/services/api/pm/sprint_issues/list_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/api/pm/sprint_issues/list_service.rb b/app/services/api/pm/sprint_issues/list_service.rb index 3f92963a3..5a539b195 100644 --- a/app/services/api/pm/sprint_issues/list_service.rb +++ b/app/services/api/pm/sprint_issues/list_service.rb @@ -8,7 +8,7 @@ class Api::Pm::SprintIssues::ListService < ApplicationService attr_accessor :queried_issues validates :category, inclusion: { in: %w[linked unlink], message: '请输入正确的Category'} - validates :sort_by, inclusion: { in: %w[issues.created_on issues.updated_on issue_priorities.position] , message: '请输入正确的SortBy'}, allow_blank: true + validates :sort_by, inclusion: { in: %w[issues.status_id issues.created_on issues.updated_on issue_priorities.position] , message: '请输入正确的SortBy'}, allow_blank: true validates :sort_direction, inclusion: { in: %w[asc desc], message: '请输入正确的SortDirection'}, allow_blank: true validates :pm_project_id, :current_user, presence: true From 55fac3d6e29d1563d3d9b0bbdcfc0a71eafc7850 Mon Sep 17 00:00:00 2001 From: KingChan <281221230@qq.com> Date: Fri, 14 Jun 2024 11:08:48 +0800 Subject: [PATCH 235/294] Update list_service.rb --- app/services/api/v1/issues/list_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index 1f0781347..40dc2669e 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -9,7 +9,7 @@ class Api::V1::Issues::ListService < ApplicationService validates :category, inclusion: { in: %w[all opened closed], message: '请输入正确的Category'} validates :participant_category, inclusion: { in: %w[all aboutme authoredme assignedme atme], message: '请输入正确的ParticipantCategory'} - validates :sort_by, inclusion: { in: %w[issues.created_on issues.updated_on issues.blockchain_token_num issue_priorities.position issues.start_date issues.due_date] , message: '请输入正确的SortBy'}, allow_blank: true + validates :sort_by, inclusion: { in: %w[issues.created_on issues.updated_on issues.blockchain_token_num issue_priorities.position issues.start_date issues.due_date issues.status_id] , message: '请输入正确的SortBy'}, allow_blank: true validates :sort_direction, inclusion: { in: %w[asc desc], message: '请输入正确的SortDirection'}, allow_blank: true validates :current_user, presence: true From 33801448fe216de615bae57b06f46e70e54631c4 Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Thu, 20 Jun 2024 10:17:33 +0800 Subject: [PATCH 236/294] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99con?= =?UTF-8?q?troller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/sonarqubes/issues_controller.rb | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 app/controllers/api/v1/sonarqubes/issues_controller.rb diff --git a/app/controllers/api/v1/sonarqubes/issues_controller.rb b/app/controllers/api/v1/sonarqubes/issues_controller.rb deleted file mode 100644 index 0a0188875..000000000 --- a/app/controllers/api/v1/sonarqubes/issues_controller.rb +++ /dev/null @@ -1,6 +0,0 @@ -class Api::V1::Sonarqubes::IssuesController < ApplicationController - def index - data = Sonarqube.client.get("/api/issues/search",params) - render_ok data - end -end From 939cce2cd372edfdfd7cf56402aa97e767907cb2 Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Thu, 20 Jun 2024 10:24:28 +0800 Subject: [PATCH 237/294] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=88=86=E6=9E=90?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/sonarqubes_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/v1/sonarqubes_controller.rb b/app/controllers/api/v1/sonarqubes_controller.rb index 5fe88ab91..0c64ba7ba 100644 --- a/app/controllers/api/v1/sonarqubes_controller.rb +++ b/app/controllers/api/v1/sonarqubes_controller.rb @@ -39,7 +39,7 @@ class Api::V1::SonarqubesController < Api::V1::BaseController filepath: 'sonar-project.properties', branch: params[:branch], new_branch: nil, - "content": "sonar.projectKey=#{params[:owner]}-#{params[:repo]}\nsonar.sources=.", + "content": "sonar.projectKey=#{params[:owner]}-#{params[:repo]}\nsonar.sources=.\nsonar.java.binaries=.", "message": 'Add sonar-project.properties', committer: { email: @owner.mail, From 32b40487f67c652e15d64a175ed1355f0cdaf146 Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Thu, 20 Jun 2024 10:36:24 +0800 Subject: [PATCH 238/294] =?UTF-8?q?=E8=B0=83=E6=95=B4soanr=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/initializers/sonarqube.rb | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/config/initializers/sonarqube.rb b/config/initializers/sonarqube.rb index 30754885c..30e8b7d08 100644 --- a/config/initializers/sonarqube.rb +++ b/config/initializers/sonarqube.rb @@ -1,8 +1,17 @@ -sonarqube_config = Rails.application.config_for(:configuration)['sonarqube'] +oauth_config = {} +begin + config = Rails.application.config_for(:configuration) + sonarqube_config = config.dig('sonarqube') + raise 'sonar config missing' if sonarqube_config.blank? +rescue => ex + raise ex if Rails.env.production? -Sonarqube.configure do |config| - config.endpoint = sonarqube_config["url"] # API endpoint URL, default: ENV['SONARQUBE_API_ENDPOINT'] - config.private_token = sonarqube_config["secret"] # user's private token, default: ENV['SONARQUBE_API_PRIVATE_TOKEN'] - # Optional - # config.user_agent = 'Custom User Agent' # user agent, default: 'Sonarqube Ruby Gem [version]' -end \ No newline at end of file + puts %Q{\033[33m [warning] soanrqube config or configuration.yml missing, + please add it or execute 'cp config/configuration.yml.example config/configuration.yml' \033[0m} +end +if sonarqube_config.present? + Sonarqube.configure do |config| + config.endpoint = sonarqube_config["url"] # API endpoint URL, default: ENV['SONARQUBE_API_ENDPOINT'] + config.private_token = sonarqube_config["secret"] # user's private token, default: ENV['SONARQUBE_API_PRIVATE_TOKEN'] + end +end From ec0155281894eafd8680c3d1a187d220660bc4b2 Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Thu, 20 Jun 2024 14:10:51 +0800 Subject: [PATCH 239/294] add has_actions to projects --- .../api/v1/sonarqubes_controller.rb | 1 + app/models/action/node.rb | 6 +- app/models/action/node_input.rb | 2 +- app/models/action/node_type.rb | 2 +- app/models/action/template.rb | 2 +- app/models/attachment.rb | 83 +++++++++---------- app/models/gitlink_competition_apply.rb | 20 +++++ app/models/license.rb | 1 - app/models/member.rb | 1 - app/models/organization_user.rb | 1 - app/models/project.rb | 1 + app/models/project_category.rb | 1 - app/models/project_language.rb | 4 - app/models/repository.rb | 1 - app/models/sync_repositories/gitee.rb | 2 + app/models/sync_repositories/github.rb | 2 + app/models/token.rb | 31 +++---- app/models/user_extension.rb | 4 +- config/configuration.yml.example | 4 +- ...40620060536_add_has_actions_to_projects.rb | 5 ++ 20 files changed, 99 insertions(+), 75 deletions(-) create mode 100644 db/migrate/20240620060536_add_has_actions_to_projects.rb diff --git a/app/controllers/api/v1/sonarqubes_controller.rb b/app/controllers/api/v1/sonarqubes_controller.rb index 0c64ba7ba..d42593a33 100644 --- a/app/controllers/api/v1/sonarqubes_controller.rb +++ b/app/controllers/api/v1/sonarqubes_controller.rb @@ -10,6 +10,7 @@ class Api::V1::SonarqubesController < Api::V1::BaseController Gitea::Repository::ActionSecretsService.new(@owner, @project.identifier, 'SONAR_HOST_URL', Rails.application.config_for(:configuration)['sonarqube']['url'] ).destroy Gitea::Repository::ActionSecretsService.new(@owner, @project.identifier, 'SONAR_TOKEN', Rails.application.config_for(:configuration)['sonarqube']['secret'] ).destroy end + @project.update(gitea_params) render_ok end diff --git a/app/models/action/node.rb b/app/models/action/node.rb index a761a0216..79c54293d 100644 --- a/app/models/action/node.rb +++ b/app/models/action/node.rb @@ -16,12 +16,12 @@ # user_id :integer # created_at :datetime not null # updated_at :datetime not null +# label :string(255) # # Indexes # -# by_name (name) -# index_action_nodes_on_action_types_id (action_node_types_id) -# index_action_nodes_on_user_id (user_id) +# index_action_nodes_on_action_node_types_id (action_node_types_id) +# index_action_nodes_on_user_id (user_id) # class Action::Node < ApplicationRecord diff --git a/app/models/action/node_input.rb b/app/models/action/node_input.rb index 7dc475a2e..3710e1633 100644 --- a/app/models/action/node_input.rb +++ b/app/models/action/node_input.rb @@ -8,7 +8,7 @@ # input_type :string(255) # description :string(255) # is_required :boolean default("0") -# sort_no :string(255) default("0") +# sort_no :integer default("0") # user_id :integer # created_at :datetime not null # updated_at :datetime not null diff --git a/app/models/action/node_type.rb b/app/models/action/node_type.rb index 59f4ab9de..64d9eabce 100644 --- a/app/models/action/node_type.rb +++ b/app/models/action/node_type.rb @@ -5,7 +5,7 @@ # id :integer not null, primary key # name :string(255) # description :string(255) -# sort_no :integer +# sort_no :integer default("0") # created_at :datetime not null # updated_at :datetime not null # diff --git a/app/models/action/template.rb b/app/models/action/template.rb index d854e8854..d256c7f67 100644 --- a/app/models/action/template.rb +++ b/app/models/action/template.rb @@ -6,7 +6,7 @@ # name :string(255) # description :string(255) # img :string(255) -# sort_no :string(255) default("0") +# sort_no :integer default("0") # json :text(65535) # yaml :text(65535) # created_at :datetime not null diff --git a/app/models/attachment.rb b/app/models/attachment.rb index be715921b..a201faa30 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -1,45 +1,44 @@ -# == Schema Information -# -# Table name: attachments -# -# id :integer not null, primary key -# container_id :integer -# container_type :string(30) -# filename :string(255) default(""), not null -# disk_filename :string(255) default(""), not null -# filesize :integer default("0"), not null -# content_type :string(255) default("") -# digest :string(60) default(""), not null -# downloads :integer default("0"), not null -# author_id :integer default("0"), not null -# created_on :datetime -# description :text(65535) -# disk_directory :string(255) -# attachtype :integer default("1") -# is_public :integer default("1") -# copy_from :integer -# quotes :integer default("0") -# is_publish :integer default("1") -# publish_time :datetime -# resource_bank_id :integer -# unified_setting :boolean default("1") -# cloud_url :string(255) default("") -# course_second_category_id :integer default("0") -# delay_publish :boolean default("0") -# memo_image :boolean default("0") -# extra_type :integer default("0") -# uuid :string(255) -# -# Indexes -# -# index_attachments_on_author_id (author_id) -# index_attachments_on_container_id_and_container_type (container_id,container_type) -# index_attachments_on_course_second_category_id (course_second_category_id) -# index_attachments_on_created_on (created_on) -# index_attachments_on_is_public (is_public) -# index_attachments_on_quotes (quotes) -# index_attachments_on_uuid (uuid) -# +# == Schema Information +# +# Table name: attachments +# +# id :integer not null, primary key +# container_id :integer +# container_type :string(30) +# filename :string(255) default(""), not null +# disk_filename :string(255) default(""), not null +# filesize :integer default("0"), not null +# content_type :string(255) default("") +# digest :string(60) default(""), not null +# downloads :integer default("0"), not null +# author_id :integer default("0"), not null +# created_on :datetime +# description :text(65535) +# disk_directory :string(255) +# attachtype :integer default("1") +# is_public :integer default("1") +# copy_from :integer +# quotes :integer default("0") +# is_publish :integer default("1") +# publish_time :datetime +# resource_bank_id :integer +# unified_setting :boolean default("1") +# cloud_url :string(255) default("") +# course_second_category_id :integer default("0") +# delay_publish :boolean default("0") +# uuid :string(255) +# +# Indexes +# +# index_attachments_on_author_id (author_id) +# index_attachments_on_container_id_and_container_type (container_id,container_type) +# index_attachments_on_course_second_category_id (course_second_category_id) +# index_attachments_on_created_on (created_on) +# index_attachments_on_is_public (is_public) +# index_attachments_on_quotes (quotes) +# index_attachments_on_uuid (uuid) +# + diff --git a/app/models/gitlink_competition_apply.rb b/app/models/gitlink_competition_apply.rb index f3b7d4ce1..cc942bd45 100644 --- a/app/models/gitlink_competition_apply.rb +++ b/app/models/gitlink_competition_apply.rb @@ -1,3 +1,23 @@ +# == Schema Information +# +# Table name: gitlink_competition_applies +# +# id :integer not null, primary key +# competition_id :integer +# competition_identifier :string(255) +# team_id :integer +# team_name :string(255) +# school_name :string(255) +# educoder_login :string(255) +# nickname :string(255) +# phone :string(255) +# email :string(255) +# identity :string(255) +# role :string(255) +# created_at :datetime not null +# updated_at :datetime not null +# + # == Schema Information # # Table name: gitlink_competition_applies diff --git a/app/models/license.rb b/app/models/license.rb index f84e63573..d14a9db14 100644 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -7,7 +7,6 @@ # content :text(65535) # created_at :datetime not null # updated_at :datetime not null -# is_secret :boolean default("0") # class License < ApplicationRecord diff --git a/app/models/member.rb b/app/models/member.rb index aaaf34efc..521f939c5 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -11,7 +11,6 @@ # course_group_id :integer default("0") # is_collect :integer default("1") # graduation_group_id :integer default("0") -# is_apply_signature :boolean default("0") # team_user_id :integer # # Indexes diff --git a/app/models/organization_user.rb b/app/models/organization_user.rb index 900710a9a..4ff6946b7 100644 --- a/app/models/organization_user.rb +++ b/app/models/organization_user.rb @@ -5,7 +5,6 @@ # id :integer not null, primary key # user_id :integer # organization_id :integer -# is_creator :boolean default("0") # created_at :datetime not null # updated_at :datetime not null # diff --git a/app/models/project.rb b/app/models/project.rb index 245537408..5bfe52c4c 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -59,6 +59,7 @@ # is_pinned :boolean default("0") # recommend_index :integer default("0") # pr_view_admin :boolean default("0") +# has_actions :boolean default("0") # # Indexes # diff --git a/app/models/project_category.rb b/app/models/project_category.rb index bc6f8427d..97a304259 100644 --- a/app/models/project_category.rb +++ b/app/models/project_category.rb @@ -15,7 +15,6 @@ # Indexes # # index_project_categories_on_ancestry (ancestry) -# index_project_categories_on_id (id) # class ProjectCategory < ApplicationRecord diff --git a/app/models/project_language.rb b/app/models/project_language.rb index 22a4a81ff..0770a1efa 100644 --- a/app/models/project_language.rb +++ b/app/models/project_language.rb @@ -9,10 +9,6 @@ # created_at :datetime not null # updated_at :datetime not null # -# Indexes -# -# index_project_languages_on_id (id) -# class ProjectLanguage < ApplicationRecord include Projectable diff --git a/app/models/repository.rb b/app/models/repository.rb index 7d3f207ea..f2815dde7 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -27,7 +27,6 @@ # # Indexes # -# index_name (project_id) # index_repositories_on_identifier (identifier) # index_repositories_on_project_id (project_id) # index_repositories_on_user_id (user_id) diff --git a/app/models/sync_repositories/gitee.rb b/app/models/sync_repositories/gitee.rb index 0a51b21c8..29309c99b 100644 --- a/app/models/sync_repositories/gitee.rb +++ b/app/models/sync_repositories/gitee.rb @@ -11,6 +11,8 @@ # sync_direction :integer # created_at :datetime not null # updated_at :datetime not null +# external_token :string(255) +# webhook_gid :integer # # Indexes # diff --git a/app/models/sync_repositories/github.rb b/app/models/sync_repositories/github.rb index 1ef413a54..10845dea7 100644 --- a/app/models/sync_repositories/github.rb +++ b/app/models/sync_repositories/github.rb @@ -11,6 +11,8 @@ # sync_direction :integer # created_at :datetime not null # updated_at :datetime not null +# external_token :string(255) +# webhook_gid :integer # # Indexes # diff --git a/app/models/token.rb b/app/models/token.rb index 7d65f32a3..9b9ea5895 100644 --- a/app/models/token.rb +++ b/app/models/token.rb @@ -1,18 +1,19 @@ -# == Schema Information -# -# Table name: tokens -# -# id :integer not null, primary key -# user_id :integer default("0"), not null -# action :string(30) default(""), not null -# value :string(40) default(""), not null -# created_on :datetime not null -# -# Indexes -# -# index_tokens_on_user_id (user_id) -# tokens_value (value) UNIQUE -# +# == Schema Information +# +# Table name: tokens +# +# id :integer not null, primary key +# user_id :integer default("0"), not null +# action :string(30) default(""), not null +# value :string(40) default(""), not null +# created_on :datetime not null +# +# Indexes +# +# index_tokens_on_user_id (user_id) +# tokens_value (value) UNIQUE +# + # diff --git a/app/models/user_extension.rb b/app/models/user_extension.rb index aeb9a9d83..ef4af5fd3 100644 --- a/app/models/user_extension.rb +++ b/app/models/user_extension.rb @@ -22,9 +22,9 @@ # school_id :integer # description :string(255) # department_id :integer -# province :text(65535) -# custom_department :string(255) +# province :string(255) # city :string(255) +# custom_department :string(255) # show_email :boolean default("0") # show_location :boolean default("0") # show_department :boolean default("0") diff --git a/config/configuration.yml.example b/config/configuration.yml.example index f5f17f59c..c18cf544c 100644 --- a/config/configuration.yml.example +++ b/config/configuration.yml.example @@ -53,7 +53,9 @@ default: &default # 区块链相关配置 blockchain: api_url: 'blockchain service url' - + sonarqube: + url: '' + secret: '' production: <<: *default diff --git a/db/migrate/20240620060536_add_has_actions_to_projects.rb b/db/migrate/20240620060536_add_has_actions_to_projects.rb new file mode 100644 index 000000000..f4b4fc164 --- /dev/null +++ b/db/migrate/20240620060536_add_has_actions_to_projects.rb @@ -0,0 +1,5 @@ +class AddHasActionsToProjects < ActiveRecord::Migration[5.2] + def change + add_column :projects , :has_actions, :boolean, default: false + end +end From 013a1d6cba2b1916f3a4baece92b42fe8ca93c0f Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Thu, 27 Jun 2024 14:04:50 +0800 Subject: [PATCH 240/294] update sonar insert_file --- .../api/v1/sonarqubes_controller.rb | 33 +++++++++++++++++-- config/configuration.yml.example | 2 ++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/sonarqubes_controller.rb b/app/controllers/api/v1/sonarqubes_controller.rb index d42593a33..e81e2a4b4 100644 --- a/app/controllers/api/v1/sonarqubes_controller.rb +++ b/app/controllers/api/v1/sonarqubes_controller.rb @@ -15,11 +15,40 @@ class Api::V1::SonarqubesController < Api::V1::BaseController end def insert_file + config = Rails.application.config_for(:configuration) + sonarqube_config = config.dig('sonarqube') + sonar_scanner_content = { filepath: '.gitea/workflows/SonarScanner.yaml', branch: params[:branch], new_branch: nil, - content: 'b246CiAgIyBUcmlnZ2VyIGFuYWx5c2lzIHdoZW4gcHVzaGluZyB0byB5b3VyIG1haW4gYnJhbmNoZXMsIGFuZCB3aGVuIGNyZWF0aW5nIGEgcHVsbCByZXF1ZXN0LgogIHB1c2g6CiAgICBicmFuY2hlczoKICAgICAgLSBtYWluCiAgICAgIC0gbWFzdGVyCiAgICAgIC0gZGV2ZWxvcAogICAgICAtICdyZWxlYXNlcy8qKicKICBwdWxsX3JlcXVlc3Q6CiAgICAgIHR5cGVzOiBbb3BlbmVkLCBzeW5jaHJvbml6ZSwgcmVvcGVuZWRdCgpuYW1lOiBNYWluIFdvcmtmbG93CmpvYnM6CiAgc29uYXJxdWJlOgogICAgcnVucy1vbjogdWJ1bnR1LWxhdGVzdAogICAgc3RlcHM6CiAgICAtIHVzZXM6IGh0dHBzOi8vZ2l0bGluay5vcmcuY24vS2luZ0NoYW4vY2hlY2tvdXRAdjQKICAgICAgd2l0aDoKICAgICAgICAjIERpc2FibGluZyBzaGFsbG93IGNsb25lcyBpcyByZWNvbW1lbmRlZCBmb3IgaW1wcm92aW5nIHRoZSByZWxldmFuY3kgb2YgcmVwb3J0aW5nCiAgICAgICAgZmV0Y2gtZGVwdGg6IDAKICAgIC0gbmFtZTogU29uYXJRdWJlIFNjYW4KICAgICAgdXNlczogaHR0cHM6Ly9naXRsaW5rLm9yZy5jbi9LaW5nQ2hhbi9zb25hcnF1YmUtc2Nhbi1hY3Rpb25AbWFzdGVyCiAgICAgIGVudjoKICAgICAgICBTT05BUl9UT0tFTjogJHt7IHNlY3JldHMuU09OQVJfVE9LRU4gfX0KICAgICAgICBTT05BUl9IT1NUX1VSTDogICR7eyBzZWNyZXRzLlNPTkFSX0hPU1RfVVJMIH19', + content: " + on: + # Trigger analysis when pushing to your main branches, and when creating a pull request. + push: + branches: + - main + - master + - develop + - 'releases/**' + pull_request: + types: [opened, synchronize, reopened] + + name: Main Workflow + jobs: + sonarqube: + runs-on: ubuntu-latest + steps: + - uses: #{sonarqube_config['checkout']} + with: + # Disabling shallow clones is recommended for improving the relevancy of reporting + fetch-depth: 0 + - name: SonarQube Scan + uses: #{sonarqube_config['scanner']} + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + ", message: 'Add .gitea/workflows/SonarScanner.yaml', committer: { email: @owner.mail, @@ -30,9 +59,9 @@ class Api::V1::SonarqubesController < Api::V1::BaseController @path = GiteaService.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{params[:branch]}/" sonar_scanner_exit = Repositories::EntriesInteractor.call(@owner, @project.identifier, '.gitea/workflows/SonarScanner.yaml', ref: params[:branch]) if sonar_scanner_exit.success? - sonar_scanner_content[:content] = Base64.decode64(sonar_scanner_content[:content]) Gitea::UpdateFileInteractor.call(@owner.gitea_token, @owner.login, sonar_scanner_content.merge(sha:sonar_scanner_exit.result['sha'])) else + sonar_scanner_content[:content] = Base64.strict_encode64(sonar_scanner_content[:content]) Gitea::CreateFileInteractor.call(@owner.gitea_token, @owner.login, sonar_scanner_content) end diff --git a/config/configuration.yml.example b/config/configuration.yml.example index c18cf544c..9d5294a76 100644 --- a/config/configuration.yml.example +++ b/config/configuration.yml.example @@ -56,6 +56,8 @@ default: &default sonarqube: url: '' secret: '' + checkout: '' + scanner: '' production: <<: *default From dfe2f8a7a2d7a74b7d71725101259d3bdfb70bd5 Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Thu, 27 Jun 2024 14:06:59 +0800 Subject: [PATCH 241/294] sonar insert_file try cache --- app/controllers/api/v1/sonarqubes_controller.rb | 12 ++++++++++-- config/initializers/sonarqube.rb | 1 - 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/v1/sonarqubes_controller.rb b/app/controllers/api/v1/sonarqubes_controller.rb index e81e2a4b4..f7ec2a39c 100644 --- a/app/controllers/api/v1/sonarqubes_controller.rb +++ b/app/controllers/api/v1/sonarqubes_controller.rb @@ -15,8 +15,16 @@ class Api::V1::SonarqubesController < Api::V1::BaseController end def insert_file - config = Rails.application.config_for(:configuration) - sonarqube_config = config.dig('sonarqube') + begin + config = Rails.application.config_for(:configuration) + sonarqube_config = config.dig('sonarqube') + raise 'sonar config missing' if sonarqube_config.blank? + rescue => ex + raise ex if Rails.env.production? + + puts %Q{\033[33m [warning] soanrqube config or configuration.yml missing, + please add it or execute 'cp config/configuration.yml.example config/configuration.yml' \033[0m} + end sonar_scanner_content = { filepath: '.gitea/workflows/SonarScanner.yaml', diff --git a/config/initializers/sonarqube.rb b/config/initializers/sonarqube.rb index 30e8b7d08..8103e7641 100644 --- a/config/initializers/sonarqube.rb +++ b/config/initializers/sonarqube.rb @@ -1,4 +1,3 @@ -oauth_config = {} begin config = Rails.application.config_for(:configuration) sonarqube_config = config.dig('sonarqube') From a384e129c6e7fd39367b154bbca4981eb3bef67f Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Thu, 27 Jun 2024 14:26:42 +0800 Subject: [PATCH 242/294] update sonar insert_file --- app/controllers/api/v1/sonarqubes_controller.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/sonarqubes_controller.rb b/app/controllers/api/v1/sonarqubes_controller.rb index f7ec2a39c..29cfdd152 100644 --- a/app/controllers/api/v1/sonarqubes_controller.rb +++ b/app/controllers/api/v1/sonarqubes_controller.rb @@ -15,9 +15,19 @@ class Api::V1::SonarqubesController < Api::V1::BaseController end def insert_file + checkout_url = 'https://gitlink.org.cn/KingChan/checkout@v4' + scanner_url = 'https://gitlink.org.cn/KingChan/sonarqube-scan-action@master' begin config = Rails.application.config_for(:configuration) sonarqube_config = config.dig('sonarqube') + + if sonarqube_config.present? && sonarqube_config['checkout'].present? + checkout_url = sonarqube_config['checkout'] + end + if sonarqube_config.present? && sonarqube_config['scanner'].present? + scanner_url = sonarqube_config['scanner'] + end + raise 'sonar config missing' if sonarqube_config.blank? rescue => ex raise ex if Rails.env.production? @@ -47,12 +57,12 @@ class Api::V1::SonarqubesController < Api::V1::BaseController sonarqube: runs-on: ubuntu-latest steps: - - uses: #{sonarqube_config['checkout']} + - uses: #{checkout_url} with: # Disabling shallow clones is recommended for improving the relevancy of reporting fetch-depth: 0 - name: SonarQube Scan - uses: #{sonarqube_config['scanner']} + uses: #{scanner_url} env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} From 499473c2966cf8dbdb81bc7d75095df3d7ed5dd3 Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Thu, 27 Jun 2024 14:43:13 +0800 Subject: [PATCH 243/294] add TransferService update actions --- app/services/projects/transfer_service.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/services/projects/transfer_service.rb b/app/services/projects/transfer_service.rb index 07eab8981..87d17e970 100644 --- a/app/services/projects/transfer_service.rb +++ b/app/services/projects/transfer_service.rb @@ -10,6 +10,7 @@ class Projects::TransferService < ApplicationService def call Rails.logger.info("###### Project transfer_service begin ######") ActiveRecord::Base.transaction do + update_actions gitea_update_owner update_owner update_repo_url @@ -31,6 +32,16 @@ class Projects::TransferService < ApplicationService project.set_owner_permission(new_owner) end + def update_actions + begin + action_params = { has_actions: false } + Gitea::Repository::UpdateService.call(owner&.login, project.identifier, action_params) + project.update action_params + rescue Exception => e + Rails.logger.info("##### Project transfer_service, gitea transfer error #{e}") + end + end + def update_repo_url project.repository.update!(user_id: new_owner.id, url: @gitea_repo["clone_url"]) end From 290f5cc161180b5685843898fc51e4e3f3f6059b Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Thu, 27 Jun 2024 15:01:48 +0800 Subject: [PATCH 244/294] update TransferService update actions --- app/services/projects/transfer_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/projects/transfer_service.rb b/app/services/projects/transfer_service.rb index 87d17e970..2060feeea 100644 --- a/app/services/projects/transfer_service.rb +++ b/app/services/projects/transfer_service.rb @@ -35,7 +35,7 @@ class Projects::TransferService < ApplicationService def update_actions begin action_params = { has_actions: false } - Gitea::Repository::UpdateService.call(owner&.login, project.identifier, action_params) + Gitea::Repository::UpdateService.call(owner, project.identifier, action_params) project.update action_params rescue Exception => e Rails.logger.info("##### Project transfer_service, gitea transfer error #{e}") From fe924527ecbc3824d406e9f277ad362cf08919e5 Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Thu, 27 Jun 2024 15:42:38 +0800 Subject: [PATCH 245/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BF=9B=E5=85=A5?= =?UTF-8?q?=E5=85=B3=E8=81=94=E5=AD=90=E9=A1=B9=E5=90=8E=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=85=B3=E8=81=94=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issue_links_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/pm/issue_links_controller.rb b/app/controllers/api/pm/issue_links_controller.rb index b6fa91774..99ceb4428 100644 --- a/app/controllers/api/pm/issue_links_controller.rb +++ b/app/controllers/api/pm/issue_links_controller.rb @@ -11,7 +11,9 @@ class Api::Pm::IssueLinksController < Api::Pm::BaseController end def destroy - @link = @issue.pm_links.find_by(be_linkable_type: 'Issue', be_linkable_id: params[:id]) + params ={"pm_project_id":"17", "issue_id":"4279", "id":3117} + @links = PmLink.where(be_linkable_id: @issue.id, be_linkable_type: 'Issue', linkable_id: params[:id], linkable_type: 'Issue').or(PmLink.where(linkable_id: @issue.id, linkable_type: 'Issue', be_linkable_id: params[:id], be_linkable_type: 'Issue')) + @link =@links.last if @link.try(:destroy) render_ok else From e22b2c8c290c196b4d152b1a7e6334ff14d1dc26 Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Thu, 27 Jun 2024 15:43:38 +0800 Subject: [PATCH 246/294] update --- app/controllers/api/pm/issue_links_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/api/pm/issue_links_controller.rb b/app/controllers/api/pm/issue_links_controller.rb index 99ceb4428..fe2c93c82 100644 --- a/app/controllers/api/pm/issue_links_controller.rb +++ b/app/controllers/api/pm/issue_links_controller.rb @@ -11,9 +11,8 @@ class Api::Pm::IssueLinksController < Api::Pm::BaseController end def destroy - params ={"pm_project_id":"17", "issue_id":"4279", "id":3117} @links = PmLink.where(be_linkable_id: @issue.id, be_linkable_type: 'Issue', linkable_id: params[:id], linkable_type: 'Issue').or(PmLink.where(linkable_id: @issue.id, linkable_type: 'Issue', be_linkable_id: params[:id], be_linkable_type: 'Issue')) - @link =@links.last + @link = @links.last if @link.try(:destroy) render_ok else From 40423aabf70a59dd24c5c66300b9435b86ef2b4c Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Thu, 27 Jun 2024 15:47:53 +0800 Subject: [PATCH 247/294] update login to id --- app/controllers/api/v1/sonarqubes_controller.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/v1/sonarqubes_controller.rb b/app/controllers/api/v1/sonarqubes_controller.rb index 29cfdd152..ab22787db 100644 --- a/app/controllers/api/v1/sonarqubes_controller.rb +++ b/app/controllers/api/v1/sonarqubes_controller.rb @@ -87,7 +87,7 @@ class Api::V1::SonarqubesController < Api::V1::BaseController filepath: 'sonar-project.properties', branch: params[:branch], new_branch: nil, - "content": "sonar.projectKey=#{params[:owner]}-#{params[:repo]}\nsonar.sources=.\nsonar.java.binaries=.", + "content": "sonar.projectKey=#{params[:owner]}-#{@project.id}\nsonar.sources=.\nsonar.java.binaries=.", "message": 'Add sonar-project.properties', committer: { email: @owner.mail, @@ -107,7 +107,7 @@ class Api::V1::SonarqubesController < Api::V1::BaseController def issues_search params_data = { - components: "#{params[:owner]}-#{params[:repo]}", + components: "#{params[:owner]}-#{@project.id]}", s: params[:s], impactSoftwareQualities: params[:impactSoftwareQualities], issueStatuses: params[:issueStatuses], @@ -126,7 +126,7 @@ class Api::V1::SonarqubesController < Api::V1::BaseController def ce_component params_data = { - components: "#{params[:owner]}-#{params[:repo]}", + components: "#{params[:owner]}-#{@project.id]}", } data = Sonarqube.client.get('/api/ce/component', query: params_data) render_ok data @@ -151,7 +151,7 @@ class Api::V1::SonarqubesController < Api::V1::BaseController def measures_search_history params_data = { from: params[:form], - component: "#{params[:owner]}-#{params[:repo]}", + component: "#{params[:owner]}-#{@project.id]}", metrics: params[:metrics], ps: params[:ps] } @@ -161,7 +161,7 @@ class Api::V1::SonarqubesController < Api::V1::BaseController def measures_component params_data = { - component: "#{params[:owner]}-#{params[:repo]}", + component: "#{params[:owner]}-#{@project.id]}", additionalFields: params[:additionalFields], metricKeys: params[:metricKeys] } From 07bc3b4eab85b19cd1b697eeb8b9dee79a7e7222 Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Thu, 27 Jun 2024 16:04:03 +0800 Subject: [PATCH 248/294] fix bug --- app/controllers/api/v1/sonarqubes_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/v1/sonarqubes_controller.rb b/app/controllers/api/v1/sonarqubes_controller.rb index ab22787db..c6f718de0 100644 --- a/app/controllers/api/v1/sonarqubes_controller.rb +++ b/app/controllers/api/v1/sonarqubes_controller.rb @@ -107,7 +107,7 @@ class Api::V1::SonarqubesController < Api::V1::BaseController def issues_search params_data = { - components: "#{params[:owner]}-#{@project.id]}", + components: "#{params[:owner]}-#{@project.id}", s: params[:s], impactSoftwareQualities: params[:impactSoftwareQualities], issueStatuses: params[:issueStatuses], @@ -126,7 +126,7 @@ class Api::V1::SonarqubesController < Api::V1::BaseController def ce_component params_data = { - components: "#{params[:owner]}-#{@project.id]}", + components: "#{params[:owner]}-#{@project.id}", } data = Sonarqube.client.get('/api/ce/component', query: params_data) render_ok data @@ -151,7 +151,7 @@ class Api::V1::SonarqubesController < Api::V1::BaseController def measures_search_history params_data = { from: params[:form], - component: "#{params[:owner]}-#{@project.id]}", + component: "#{params[:owner]}-#{@project.id}", metrics: params[:metrics], ps: params[:ps] } @@ -161,7 +161,7 @@ class Api::V1::SonarqubesController < Api::V1::BaseController def measures_component params_data = { - component: "#{params[:owner]}-#{@project.id]}", + component: "#{params[:owner]}-#{@project.id}", additionalFields: params[:additionalFields], metricKeys: params[:metricKeys] } From 6f0afffb3bca51b94369f629b37cb27f670f6d3c Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 7 Aug 2024 11:01:24 +0800 Subject: [PATCH 249/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E5=AF=BC=E5=87=BA=E5=B7=A5=E4=BD=9C=E9=A1=B9=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 62 +++++++++++++++++++++ config/routes/api.rb | 2 + 2 files changed, 64 insertions(+) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index b74cf29f0..3506dfdea 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -124,6 +124,68 @@ class Api::Pm::IssuesController < Api::Pm::BaseController end end + def export + return render_error('请输入正确的项目ID.') if params[:pm_project_id].blank? + Axlsx::Package.new do |p| + [['requirement', 1], ['task', 2], ['bug', 3]].each do |type| + p.workbook.add_worksheet(:name => type[0]) do |sheet| + @issues = Issue.where(pm_project_id: params[:pm_project_id], pm_issue_type: type[1]) + sheet.add_row ["标题", "正文", "创建者", "创建时间", "修改者", "更新时间", "状态", "负责人", "优先级", "标记", "开始时间","结束时间", "预估工时"] + @issues.each do |issue| + sheet.add_row [issue.subject, issue.description, issue.user.try(:login), issue.created_on.strftime("%Y-%m-%d %H:%M:%S"), issue.changer.try(:login), issue.updated_on.strftime("%Y-%m-%d %H:%M:%S"), issue.status_id, issue.assigners.pluck(:login).join(","), issue.priority_id, issue.issue_tags.pluck(:name, :color).join(","), issue.start_date.present? ? issue.start_date.strftime("%Y-%m-%d") : "", issue.due_date.present? ? issue.due_date.strftime("%Y-%m-%d") : "", issue.time_scale] + end + end + end + p.serialize('public/导出工作项.xlsx') + end + + send_file('public/导出工作项.xlsx') + end + + def import + return render_error('请上传正确的文件') if params[:file].blank? || !params[:file].is_a?(ActionDispatch::Http::UploadedFile) + return render_error('请输入正确的项目ID.') if params[:pm_project_id].blank? + return render_error('请输入正确的组织ID.') if params[:organization_id].blank? + types = {requirement: 1, task: 2, bug: 3} + doc = SimpleXlsxReader.parse(params[:file].to_io) + doc.sheets.each do |sheet| + type = types["#{sheet.name}".to_sym] + sheet.rows.each.with_index do |row, index| + next if index == 0 + issue = Issue.new(issue_classify: "issue", project_id: 0, pm_project_id: params[:pm_project_id], pm_issue_type: type, tracker_id: Tracker.first.id) + issue.subject = row[0] + issue.description = row[1] + author = User.find_by(login: row[2]) || User.first + issue.user = author + issue.created_on = row[3] + changer = User.find_by(login: row[4]) || User.first + issue.changer = changer + issue.updated_on = row[5] + issue.status_id = row[6].to_i + row[7].split(',').each do |a| + u = User.find_by(login: a) + next unless u.present? + issue.assigners << u + end + issue.priority_id = row[8] + row[9].split(',').each_slice(2).to_a.each do |t| + tag = IssueTag.find_by(project_id: 0, organization_id: params[:organization_id], name: t[0]) + if tag.present? + issue.issue_tags << tag + else + tag = IssueTag.create(project_id: 0,organization_id: params[:organization_id], name: t[0], color: t[1]) + issue.issue_tags << tag + end + end + issue.start_date = row[10] + issue.due_date = row[11] + issue.time_scale = row[12] + issue.save + end + + end + end + private def check_issue_operate_permission return if params[:project_id].to_i.zero? diff --git a/config/routes/api.rb b/config/routes/api.rb index 6d5aded88..1aea612b7 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -8,6 +8,8 @@ defaults format: :json do get :priorities get :tags get :statues + get :export + get :import end member do get :link_index From 97685bf68cf6441818d79bd3cd4b73ee72f02324 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 7 Aug 2024 11:23:11 +0800 Subject: [PATCH 250/294] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E6=96=87=E4=BB=B6=E5=BD=A2=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 3506dfdea..a85c5b310 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -147,7 +147,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController return render_error('请输入正确的项目ID.') if params[:pm_project_id].blank? return render_error('请输入正确的组织ID.') if params[:organization_id].blank? types = {requirement: 1, task: 2, bug: 3} - doc = SimpleXlsxReader.parse(params[:file].to_io) + doc = SimpleXlsxReader.open(params[:file].tempfile) doc.sheets.each do |sheet| type = types["#{sheet.name}".to_sym] sheet.rows.each.with_index do |row, index| From f1a79d926c9457c7bb5d833f494f7b2e4d2c8094 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 7 Aug 2024 11:27:14 +0800 Subject: [PATCH 251/294] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Anil=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 26 ++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index a85c5b310..e56ef5e53 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -162,19 +162,23 @@ class Api::Pm::IssuesController < Api::Pm::BaseController issue.changer = changer issue.updated_on = row[5] issue.status_id = row[6].to_i - row[7].split(',').each do |a| - u = User.find_by(login: a) - next unless u.present? - issue.assigners << u + if row[7].present? + row[7].split(',').each do |a| + u = User.find_by(login: a) + next unless u.present? + issue.assigners << u + end end issue.priority_id = row[8] - row[9].split(',').each_slice(2).to_a.each do |t| - tag = IssueTag.find_by(project_id: 0, organization_id: params[:organization_id], name: t[0]) - if tag.present? - issue.issue_tags << tag - else - tag = IssueTag.create(project_id: 0,organization_id: params[:organization_id], name: t[0], color: t[1]) - issue.issue_tags << tag + if row[9].present? + row[9].split(',').each_slice(2).to_a.each do |t| + tag = IssueTag.find_by(project_id: 0, organization_id: params[:organization_id], name: t[0]) + if tag.present? + issue.issue_tags << tag + else + tag = IssueTag.create(project_id: 0,organization_id: params[:organization_id], name: t[0], color: t[1]) + issue.issue_tags << tag + end end end issue.start_date = row[10] From b7aa1e51b3c8cc6a12c449f6b9d30fcfada64c04 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 20 Aug 2024 15:56:40 +0800 Subject: [PATCH 252/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E6=97=A5=E5=BF=97=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 10 +- app/controllers/api/pm/journals_controller.rb | 2 +- app/models/journal.rb | 365 ++++++++++++++++++ .../api/pm/issues/batch_delete_service.rb | 38 ++ .../api/pm/issues/batch_update_service.rb | 33 ++ app/services/api/pm/issues/create_service.rb | 168 ++++++++ app/services/api/pm/issues/delete_service.rb | 42 ++ app/services/api/pm/issues/update_service.rb | 283 ++++++++++++++ .../pm/issues/journals/_detail.json.jbuilder | 25 ++ .../pm/issues/journals/index.json.jbuilder | 8 + 10 files changed, 968 insertions(+), 6 deletions(-) create mode 100644 app/services/api/pm/issues/batch_delete_service.rb create mode 100644 app/services/api/pm/issues/batch_update_service.rb create mode 100644 app/services/api/pm/issues/create_service.rb create mode 100644 app/services/api/pm/issues/delete_service.rb create mode 100644 app/services/api/pm/issues/update_service.rb create mode 100644 app/views/api/pm/issues/journals/_detail.json.jbuilder create mode 100644 app/views/api/pm/issues/journals/index.json.jbuilder diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index e56ef5e53..cdf5f1d7d 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -62,17 +62,17 @@ class Api::Pm::IssuesController < Api::Pm::BaseController end def create - @object_result = Api::V1::Issues::CreateService.call(@project, issue_params, current_user) + @object_result = Api::Pm::Issues::CreateService.call(@project, issue_params, current_user) render 'api/v1/issues/create' end def update - @object_result = Api::V1::Issues::UpdateService.call(@project, @issue, issue_params, current_user) + @object_result = Api::Pm::Issues::UpdateService.call(@project, @issue, issue_params, current_user) render 'api/v1/issues/update' end def batch_update - @object_result = Api::V1::Issues::BatchUpdateService.call(@project, @issues, batch_issue_params, current_user) + @object_result = Api::Pm::Issues::BatchUpdateService.call(@project, @issues, batch_issue_params, current_user) if @object_result render_ok else @@ -82,7 +82,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController def batch_destroy return render_ok if params[:ids].is_a?(Array) && params[:ids].blank? - @object_result = Api::V1::Issues::BatchDeleteService.call(@project, @issues, current_user) + @object_result = Api::Pm::Issues::BatchDeleteService.call(@project, @issues, current_user) if @object_result render_ok else @@ -116,7 +116,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController def destroy - @object_result = Api::V1::Issues::DeleteService.call(@project, @issue, current_user) + @object_result = Api::Pm::Issues::DeleteService.call(@project, @issue, current_user) if @object_result render_ok else diff --git a/app/controllers/api/pm/journals_controller.rb b/app/controllers/api/pm/journals_controller.rb index 14f386860..b10cb4829 100644 --- a/app/controllers/api/pm/journals_controller.rb +++ b/app/controllers/api/pm/journals_controller.rb @@ -10,7 +10,7 @@ class Api::Pm::JournalsController < Api::Pm::BaseController @total_operate_journals_count = @object_result[:total_operate_journals_count] @total_comment_journals_count = @object_result[:total_comment_journals_count] @journals = kaminary_select_paginate(@object_result[:data]) - render 'api/v1/issues/journals/index' + render 'api/pm/issues/journals/index' end def create diff --git a/app/models/journal.rb b/app/models/journal.rb index 0fdca0f9d..ea50646b6 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -82,6 +82,371 @@ class Journal < ApplicationRecord end end + def pm_operate_content + content = "" + detail = self.journal_details.take + case detail.property + when 'requirement' + case detail.prop_key + when 'status_id' + old_value = IssueStatus.find_by_id(detail.old_value)&.name + new_value = IssueStatus.find_by_id(detail.value)&.name + content += "将状态" + if old_value.nil? || old_value.blank? + content += "设置为#{new_value}" + else + new_value = "未设置" if new_value.blank? + content += "由#{old_value}更改为#{new_value}" + end + content.gsub!('新增', '待评审') + content.gsub!('正在解决', '进行中') + content.gsub!('已解决', '已完成') + content.gsub!('关闭', '已关闭') + content.gsub!('拒绝', '已拒绝') + return content + when 'root_id' + old_value = Issue.find_by_id(detail.old_value)&.subject + new_value = Issue.find_by_id(detail.value)&.subject + if old_value.nil? || old_value.blank? + content += "关联了父需求<#{new_value}>" + else + if new_value.nil? || new_value.blank? + content += "取消了关联的父需求<#{old_value}>" + else + content += "将关联的父需求由<#{old_value}>更改为<#{new_value}>" + end + end + return content + when 'leaf_issue' + old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + if old_value.nil? || old_value.blank? + content += "新建了子需求#{new_value}" + else + if new_value.nil? || new_value.blank? + content += "删除了关联的子需求#{old_value}" + else + content += "新建了子需求#{new_value}" + end + end + return content + when 'tag_leaf_issue' + old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + if old_value.nil? || old_value.blank? + content += "关联了子需求#{new_value}" + else + if new_value.nil? || new_value.blank? + content += "取消了关联的子需求#{old_value}" + else + content += "关联了子需求#{new_value}" + end + end + return content + else + return "创建了需求" + end + when 'task' + case detail.prop_key + when 'status_id' + old_value = IssueStatus.find_by_id(detail.old_value)&.name + new_value = IssueStatus.find_by_id(detail.value)&.name + content += "将状态" + if old_value.nil? || old_value.blank? + content += "设置为#{new_value}" + else + new_value = "未设置" if new_value.blank? + content += "由#{old_value}更改为#{new_value}" + end + content.gsub!('新增', '待处理') + content.gsub!('正在解决', '进行中') + content.gsub!('已解决', '已完成') + content.gsub!('关闭', '已关闭') + content.gsub!('拒绝', '已拒绝') + return content + when 'root_id' + old_value = Issue.find_by_id(detail.old_value)&.subject + new_value = Issue.find_by_id(detail.value)&.subject + if old_value.nil? || old_value.blank? + content += "关联了父任务<#{new_value}>" + else + if new_value.nil? || new_value.blank? + content += "取消了关联的父任务<#{old_value}>" + else + content += "将关联的父任务由<#{old_value}>更改为<#{new_value}>" + end + end + return content + when 'leaf_issue' + old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + if old_value.nil? || old_value.blank? + content += "新建了子任务#{new_value}" + else + if new_value.nil? || new_value.blank? + content += "删除了关联的子任务#{old_value}" + else + content += "新建了子任务#{new_value}" + end + end + return content + when 'tag_leaf_issue' + old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + if old_value.nil? || old_value.blank? + content += "关联了子任务#{new_value}" + else + if new_value.nil? || new_value.blank? + content += "取消了关联的子任务#{old_value}" + else + content += "关联了子任务#{new_value}" + end + end + return content + else + return "创建了任务" + end + when 'bug' + case detail.prop_key + when 'status_id' + old_value = IssueStatus.find_by_id(detail.old_value)&.name + new_value = IssueStatus.find_by_id(detail.value)&.name + content += "将状态" + if old_value.nil? || old_value.blank? + content += "设置为#{new_value}" + else + new_value = "未设置" if new_value.blank? + content += "由#{old_value}更改为#{new_value}" + end + content.gsub!('新增', '待修复') + content.gsub!('正在解决', '修复中') + content.gsub!('已解决', '已修复') + content.gsub!('关闭', '已关闭') + content.gsub!('拒绝', '已拒绝') + return content + when 'root_id' + old_value = Issue.find_by_id(detail.old_value)&.subject + new_value = Issue.find_by_id(detail.value)&.subject + if old_value.nil? || old_value.blank? + content += "关联了父缺陷<#{new_value}>" + else + if new_value.nil? || new_value.blank? + content += "取消了关联的父缺陷<#{old_value}>" + else + content += "将关联的父缺陷由<#{old_value}>更改为<#{new_value}>" + end + end + return content + when 'leaf_issue' + old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + if old_value.nil? || old_value.blank? + content += "新建了子缺陷#{new_value}" + else + if new_value.nil? || new_value.blank? + content += "删除了关联的子缺陷#{old_value}" + else + content += "新建了子缺陷#{new_value}" + end + end + return content + when 'tag_leaf_issue' + old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + if old_value.nil? || old_value.blank? + content += "关联了子缺陷#{new_value}" + else + if new_value.nil? || new_value.blank? + content += "取消了关联的子缺陷#{old_value}" + else + content += "关联了子缺陷#{new_value}" + end + end + return content + else + return "创建了缺陷" + end + when 'attr' + case detail.prop_key + when 'subject' + return "修改了标题" + when 'description' + return "修改了正文" + when 'priority_id' + old_value = IssuePriority.find_by_id(detail.old_value)&.name + new_value = IssuePriority.find_by_id(detail.value)&.name + if old_value.nil? || old_value.blank? + content += "将优先级设置为#{new_value}" + else + new_value = "未设置" if new_value.blank? + content += "将优先级由#{old_value}更改为#{new_value}" + end + return content + when 'pm_issue_type' + old_value = detail.old_value + new_value = detail.value + if old_value.nil? || old_value.blank? + content += "将工作项类型设置为#{new_value}" + else + new_value = "未设置" if new_value.blank? + content += "将工作项类型由#{old_value}更改为#{new_value}" + end + content.gsub!('1', '需求') + content.gsub!('2', '任务') + content.gsub!('3', '缺陷') + return content + when 'pm_sprint_id' + old_value = detail.old_value + new_value = detail.value + if old_value.nil? || old_value.blank? + content += "添加了关联迭代" + else + if new_value.nil? || new_value.blank? + content += "将关联迭代更改为未设置" + else + content += "变更了关联迭代" + end + end + return content + when 'project_id' + old_value = Project.find_by_id(detail.old_value)&.name + new_value = Project.find_by_id(detail.value)&.name + if old_value.nil? || old_value.blank? + content += "添加关联代码库#{new_value}" + else + if new_value.nil? || new_value.blank? + content += "将关联代码库更改为未设置" + else + content += "将关联代码库由#{old_value}改为#{new_value}" + end + end + return content + when 'branch_name' + old_value = detail.old_value + new_value = detail.value + if old_value.nil? || old_value.blank? + content += "添加关联分支#{new_value}" + else + if new_value.nil? || new_value.blank? + content += "将关联分支更改为未设置" + else + content += "将关联分支由#{old_value}改为#{new_value}" + end + end + return content + + when 'start_date' + old_value = detail.old_value + new_value = detail.value + if old_value.nil? || old_value.blank? + content += "添加开始时间#{new_value}" + else + if new_value.nil? || new_value.blank? + content += "将开始时间更改为未设置" + else + content += "将开始时间由#{old_value}改为#{new_value}" + end + end + return content + + when 'due_date' + old_value = detail.old_value + new_value = detail.value + if old_value.nil? || old_value.blank? + content += "添加结束时间#{new_value}" + else + if new_value.nil? || new_value.blank? + content += "将结束时间更改为未设置" + else + content += "将结束时间由#{old_value}改为#{new_value}" + end + end + return content + when 'time_scale' + old_value = detail.old_value + new_value = detail.value + if old_value.nil? || old_value.blank? + content += "添加预估工时#{new_value}" + else + if new_value.nil? || new_value.blank? + content += "将预估工时更改为未设置" + else + content += "将预估工时由#{old_value}改为#{new_value}" + end + end + return content + end + when 'attachment' + old_value = detail.old_value.to_s + new_value = detail.value.to_s + if old_value.nil? || old_value.blank? + content += "上传了附件" + else + if new_value.nil? || new_value.blank? + content += "删除了附件" + else + content += "上传了附件" + end + end + return content + when 'assigner' + old_value = User.where(id: detail.old_value.split(",")).map{|u| u.real_name}.join("、") + new_value = User.where(id: detail.value.split(",")).map{|u| u.real_name}.join("、") + if old_value.nil? || old_value.blank? + content += "添加负责人#{new_value}" + else + if new_value.nil? || new_value.blank? + content += "将负责人更改为未设置" + else + content += "将负责人由#{old_value}更改为#{new_value}" + end + end + return content + when 'issue_tag' + old_value = IssueTag.where(id: detail.old_value.split(",")).pluck(:name).join("、") + new_value = IssueTag.where(id: detail.value.split(",")).pluck(:name).join("、") + if old_value.nil? || old_value.blank? + content += "添加标记#{new_value}" + else + if new_value.nil? || new_value.blank? + content += "将标记更改为未设置" + else + content += "将标记由#{old_value}更改为#{new_value}" + end + end + return content + when 'link_issue' + old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") + if old_value.nil? || old_value.blank? + content += "关联了工作项#{new_value}" + else + if new_value.nil? || new_value.blank? + content += "取消了关联的工作项#{old_value}" + else + content += "关联了工作项#{new_value}" + end + end + content.gsub!('1', "需求") + content.gsub!('2', "任务") + content.gsub!('3', "缺陷") + return content + when 'tag_link_issue' + old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") + if old_value.nil? || old_value.blank? + content += "新建了关联的工作项#{new_value}" + else + if new_value.nil? || new_value.blank? + content += "删除了关联的工作项#{old_value}" + else + content += "新建了关联的工作项#{new_value}" + end + end + return content + end + end + def operate_content content = "" detail = self.journal_details.take diff --git a/app/services/api/pm/issues/batch_delete_service.rb b/app/services/api/pm/issues/batch_delete_service.rb new file mode 100644 index 000000000..9afdfdb81 --- /dev/null +++ b/app/services/api/pm/issues/batch_delete_service.rb @@ -0,0 +1,38 @@ +class Api::Pm::Issues::BatchDeleteService < ApplicationService + include ActiveModel::Model + + attr_reader :project, :issues, :current_user + + validates :project, :issues, :current_user, presence: true + + def initialize(project, issues, current_user = nil) + @project = project + @issues = issues.includes(:assigners) + @current_user = current_user + end + + def call + raise Error, errors.full_messages.join(", ") unless valid? + try_lock("Api::V1::Issues::DeleteService:#{project.id}") # 开始写数据,加锁 + + delete_issues + + project.incre_project_issue_cache_delete_count(@issues.size) + + if Site.has_notice_menu? && !project.id.zero? + @issues.each do |issue| + SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, @issue&.subject, @issue.assigners.pluck(:id), @issue.author_id) + end + end + + unlock("Api::V1::Issues::DeleteService:#{project.id}") + + return true + end + + private + + def delete_issues + raise Error, "批量删除疑修失败!" unless @issues.destroy_all + end +end \ No newline at end of file diff --git a/app/services/api/pm/issues/batch_update_service.rb b/app/services/api/pm/issues/batch_update_service.rb new file mode 100644 index 000000000..b7eabf2cb --- /dev/null +++ b/app/services/api/pm/issues/batch_update_service.rb @@ -0,0 +1,33 @@ +class Api::Pm::Issues::BatchUpdateService < ApplicationService + include ActiveModel::Model + include Api::V1::Issues::Concerns::Checkable + include Api::V1::Issues::Concerns::Loadable + + attr_reader :project, :issues, :params, :current_user + attr_reader :status_id, :priority_id, :milestone_id, :project_id + attr_reader :issue_tag_ids, :assigner_ids + + validates :project, :issues, :current_user, presence: true + + def initialize(project, issues, params, current_user = nil) + @project = project + @issues = issues + @params = params + @current_user = current_user + end + + def call + raise Error, errors.full_messages.join(", ") unless valid? + ActiveRecord::Base.transaction do + @issues.each do |issue| + if issue.issue_classify == "issue" + Api::Pm::Issues::UpdateService.call(project, issue, params, current_user) + end + end + + return true + end + end + + +end \ No newline at end of file diff --git a/app/services/api/pm/issues/create_service.rb b/app/services/api/pm/issues/create_service.rb new file mode 100644 index 000000000..796faf1e5 --- /dev/null +++ b/app/services/api/pm/issues/create_service.rb @@ -0,0 +1,168 @@ +class Api::Pm::Issues::CreateService < ApplicationService + include ActiveModel::Model + include Api::V1::Issues::Concerns::Checkable + include Api::V1::Issues::Concerns::Loadable + + attr_reader :project, :current_user + attr_reader :status_id, :priority_id, :milestone_id, :branch_name, :start_date, :due_date, :subject, :description, :blockchain_token_num, :root_subject + attr_reader :issue_tag_ids, :assigner_ids, :attachment_ids, :receivers_login + attr_accessor :created_issue + + validates :subject, presence: true + validates :status_id, :priority_id, presence: true + validates :project, :current_user, presence: true + validates :blockchain_token_num, numericality: {greater_than: 0}, allow_blank: true + + def initialize(project, params, current_user = nil) + @project = project + @current_user = current_user + @status_id = params[:status_id] + @priority_id = params[:priority_id] + @milestone_id = params[:milestone_id] + @branch_name = params[:branch_name] + @start_date = params[:start_date] + @due_date = params[:due_date] + @subject = params[:subject] + @description = params[:description] + @blockchain_token_num = params[:blockchain_token_num] + @issue_tag_ids = params[:issue_tag_ids] + @assigner_ids = params[:assigner_ids] + @attachment_ids = params[:attachment_ids] + @receivers_login = params[:receivers_login] + @pm_project_id = params[:pm_project_id] + @pm_sprint_id = params[:pm_sprint_id] + @pm_issue_type = params[:pm_issue_type] + @root_id = params[:root_id] + @time_scale = params[:time_scale] + @linkable_id = params[:link_able_id] + @root_subject = params[:root_subject] + end + + def call + raise Error, errors.full_messages.join(', ') unless valid? + ActiveRecord::Base.transaction do + check_issue_status(status_id) + check_issue_priority(priority_id) + check_milestone(milestone_id) if milestone_id.present? + check_issue_tags(issue_tag_ids) unless issue_tag_ids.blank? + check_assigners(assigner_ids) unless assigner_ids.blank? + check_attachments(attachment_ids) unless attachment_ids.blank? + check_atme_receivers(receivers_login) unless receivers_login.blank? + check_blockchain_token_num(current_user.id, project.id, blockchain_token_num) if blockchain_token_num.present? + load_assigners(assigner_ids) unless assigner_ids.blank? + load_attachments(attachment_ids) unless attachment_ids.blank? + load_issue_tags(issue_tag_ids) unless issue_tag_ids.blank? + load_atme_receivers(receivers_login) unless receivers_login.blank? + try_lock("Api::Pm::Issues::CreateService:#{project.id}") # 开始写数据,加锁 + @created_issue = Issue.new(issue_attributes) + build_author_participants + build_assigner_participants unless assigner_ids.blank? + build_atme_participants if @atme_receivers.present? + build_issue_journal_details + build_issue_project_trends + @created_issue.assigners = @assigners unless assigner_ids.blank? + @created_issue.attachments = @attachments unless attachment_ids.blank? + @created_issue.issue_tags = @issue_tags unless issue_tag_ids.blank? + @created_issue.pm_project_id = @pm_project_id + @created_issue.pm_sprint_id = @pm_sprint_id + @created_issue.pm_issue_type = @pm_issue_type + if @root_subject.present? && @pm_issue_type.to_i == 4 + @root_issue = Issue.find_by(subject: @root_subject, pm_issue_type: 4, pm_project_id: @pm_project_id) + unless @root_issue.present? + @root_issue = Issue.create(subject: @root_subject, pm_issue_type: 4, pm_project_id: @pm_project_id, status_id: 1, priority_id: 1, tracker_id: Tracker.first.id, project_id: @project.id, author_id: current_user.id) + end + @created_issue.root_id = @root_issue.id + else + @created_issue.root_id = @root_id + end + @created_issue.time_scale = @time_scale + @created_issue.issue_tags_value = @issue_tags.order('id asc').pluck(:id).join(',') unless issue_tag_ids.blank? + @created_issue.changer_id = @current_user.id + @created_issue.save! + + PmLink.create(be_linkable_type: 'Issue', be_linkable_id: @created_issue.id, linkable_type: 'Issue', linkable_id: @linkable_id) if @linkable_id.present? + if Site.has_blockchain? && @project.use_blockchain + if @created_issue.blockchain_token_num.present? && @created_issue.blockchain_token_num > 0 + Blockchain::CreateIssue.call({user_id: current_user.id, project_id: @created_issue.project_id, token_num: @created_issue.blockchain_token_num}) + end + + push_activity_2_blockchain('issue_create', @created_issue) + end + + project.del_project_issue_cache_delete_count # 把缓存里存储项目删除issue的个数清除掉 + unless @project.id.zero? + # 新增时向grimoirelab推送事件 + IssueWebhookJob.set(wait: 5.seconds).perform_later(@created_issue.id) + + # @信息发送 + AtmeService.call(current_user, @atme_receivers, @created_issue) unless receivers_login.blank? + + # 发消息 + if Site.has_notice_menu? + SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @created_issue&.id, assigner_ids) unless assigner_ids.blank? + SendTemplateMessageJob.perform_later('ProjectIssue', current_user.id, @created_issue&.id) + end + + # 触发webhook + TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueCreate', @created_issue&.id, current_user.id) + TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueLabel', @created_issue&.id, current_user.id, {issue_tag_ids: [[], issue_tag_ids]}) unless issue_tag_ids.blank? + TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueAssign', @created_issue&.id, current_user.id, {assigner_ids: [[], assigner_ids]}) unless assigner_ids.blank? + end + unlock("Api::Pm::Issues::CreateService:#{project.id}") # 结束写数据,解锁 + end + + return @created_issue + end + + private + + def issue_attributes + issue_attributes = { + subject: subject, + project_id: project.id, + author_id: current_user.id, + tracker_id: Tracker.first.id, + status_id: status_id, + priority_id: priority_id, + project_issues_index: (project.get_last_project_issues_index + 1), + issue_type: '1', + issue_classify: 'issue' + } + + issue_attributes.merge!({description: description}) if description.present? + issue_attributes.merge!({fixed_version_id: milestone_id}) if milestone_id.present? + issue_attributes.merge!({start_date: start_date}) if start_date.present? + issue_attributes.merge!({due_date: due_date}) if due_date.present? + issue_attributes.merge!({branch_name: branch_name}) if branch_name.present? + issue_attributes.merge!({blockchain_token_num: blockchain_token_num}) if blockchain_token_num.present? + + issue_attributes + end + + def build_author_participants + @created_issue.issue_participants.new({participant_type: 'authored', participant_id: current_user.id}) + end + + def build_assigner_participants + assigner_ids.each do |aid| + @created_issue.issue_participants.new({participant_type: 'assigned', participant_id: aid}) + end + end + + def build_atme_participants + @atme_receivers.each do |receiver| + @created_issue.issue_participants.new({participant_type: 'atme', participant_id: receiver.id}) + end + end + + def build_issue_project_trends + return if @project.id == 0 + @created_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: 'create'}) + @created_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE}) if status_id.to_i == 5 + end + + def build_issue_journal_details + journal = @created_issue.journals.new({user_id: current_user.id}) + journal.journal_details.new({property: 'issue', prop_key: 1, old_value: '', value: ''}) + end +end \ No newline at end of file diff --git a/app/services/api/pm/issues/delete_service.rb b/app/services/api/pm/issues/delete_service.rb new file mode 100644 index 000000000..2d5df500e --- /dev/null +++ b/app/services/api/pm/issues/delete_service.rb @@ -0,0 +1,42 @@ +class Api::Pm::Issues::DeleteService < ApplicationService + include ActiveModel::Model + + attr_reader :project, :issue, :current_user + + validates :project, :issue, :current_user, presence: true + + def initialize(project, issue, current_user = nil) + @project = project + @issue = issue + @current_user = current_user + end + + def call + raise Error, errors.full_messages.join(", ") unless valid? + try_lock("Api::V1::Issues::DeleteService:#{project.id}") # 开始写数据,加锁 + + delete_issue + #删除双向关联 + PmLink.where(be_linkable_id: @issue.id, be_linkable_type: 'Issue').or(PmLink.where(linkable_id: @issue.id, linkable_type: 'Issue')).map(&:destroy) + + project.incre_project_issue_cache_delete_count + + if Site.has_blockchain? && @project.use_blockchain && !project.id.zero? + unlock_balance_on_blockchain(@issue.author_id.to_s, @project.id.to_s, @issue.blockchain_token_num.to_i) if @issue.blockchain_token_num.present? + end + + if Site.has_notice_menu? && !project.id.zero? + SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, @issue&.subject, @issue.assigners.pluck(:id), @issue.author_id) + end + + unlock("Api::V1::Issues::DeleteService:#{project.id}") + + return true + end + + private + + def delete_issue + raise Error, "删除疑修失败!" unless issue.destroy! + end +end \ No newline at end of file diff --git a/app/services/api/pm/issues/update_service.rb b/app/services/api/pm/issues/update_service.rb new file mode 100644 index 000000000..99896e884 --- /dev/null +++ b/app/services/api/pm/issues/update_service.rb @@ -0,0 +1,283 @@ +class Api::Pm::Issues::UpdateService < ApplicationService + include ActiveModel::Model + include Api::V1::Issues::Concerns::Checkable + include Api::V1::Issues::Concerns::Loadable + + attr_reader :project, :issue, :current_user + attr_reader :status_id, :priority_id, :milestone_id, :branch_name, :start_date, :due_date, :subject, :description, :blockchain_token_num + attr_reader :target_pm_project_id, :pm_sprint_id, :pm_issue_type, :root_id, :time_scale + attr_reader :issue_tag_ids, :assigner_ids, :attachment_ids, :receivers_login, :before_issue_tag_ids, :before_assigner_ids, :project_id + attr_accessor :add_assigner_ids, :previous_issue_changes, :updated_issue, :atme_receivers + + validates :project, :issue, :current_user, presence: true + validates :blockchain_token_num, numericality: {greater_than: 0}, allow_blank: true + + def initialize(project, issue, params, current_user = nil) + @project = project + @issue = issue + @current_user = current_user + @status_id = params[:status_id] + @priority_id = params[:priority_id] + @milestone_id = params[:milestone_id] + @branch_name = params[:branch_name] + @start_date = params[:start_date] + @due_date = params[:due_date] + @subject = params[:subject] + @description = params[:description] + @blockchain_token_num = params[:blockchain_token_num] + @issue_tag_ids = params[:issue_tag_ids] + @assigner_ids = params[:assigner_ids] + @before_issue_tag_ids = issue.issue_tags.pluck(:id) + @before_assigner_ids = issue.assigners.pluck(:id) + @attachment_ids = params[:attachment_ids] + @receivers_login = params[:receivers_login] + @target_pm_project_id = params[:target_pm_project_id] + @pm_sprint_id = params[:pm_sprint_id] + @pm_issue_type = params[:pm_issue_type] + @root_id = params[:root_id] + @time_scale = params[:time_scale] + @project_id = params[:project_id] + @add_assigner_ids = [] + @previous_issue_changes = {} + end + + def call + raise Error, errors.full_messages.join(", ") unless valid? + ActiveRecord::Base.transaction do + check_issue_status(status_id) if status_id.present? + check_issue_priority(priority_id) if priority_id.present? + check_milestone(milestone_id) if milestone_id.present? + check_root_issue(issue, root_id) if root_id.present? + check_issue_tags(issue_tag_ids) unless issue_tag_ids.nil? + check_assigners(assigner_ids) unless assigner_ids.nil? + check_attachments(attachment_ids) unless attachment_ids.nil? + check_atme_receivers(receivers_login) unless receivers_login.nil? + check_blockchain_token_num(issue.author_id, project.id, blockchain_token_num, (@issue.blockchain_token_num || 0)) if blockchain_token_num.present? && current_user.id == @issue.author_id && !PullAttachedIssue.exists?(issue_id: @issue, fixed: true) + load_assigners(assigner_ids) + load_attachments(attachment_ids) + load_issue_tags(issue_tag_ids) + load_atme_receivers(receivers_login) unless receivers_login.nil? + + try_lock("Api::Pm::Issues::UpdateService:#{project.id}:#{issue.id}") + @updated_issue = @issue + issue_load_attributes + build_assigner_issue_journal_details unless assigner_ids.nil?# 操作记录 + build_attachment_issue_journal_details unless attachment_ids.nil? + build_issue_tag_issue_journal_details unless issue_tag_ids.nil? + build_issue_project_trends if status_id.present? # 开关时间记录 + build_assigner_participants unless assigner_ids.nil? # 负责人 + build_edit_participants + build_atme_participants if @atme_receivers.present? + unless assigner_ids.nil? + @previous_issue_changes.merge!(assigned_to_id: [@updated_issue.assigners.pluck(:id), @assigners.pluck(:id)]) + @updated_issue.assigners = @assigners || User.none + end + @updated_issue.attachments = @attachments || Attachment.none unless attachment_ids.nil? + @updated_issue.issue_tags_relates.destroy_all & @updated_issue.issue_tags = @issue_tags || IssueTag.none unless issue_tag_ids.nil? + @updated_issue.issue_tags_value = @issue_tags.order("id asc").pluck(:id).join(",") unless issue_tag_ids.nil? + + #Pm相关 + @updated_issue.pm_project_id = @target_pm_project_id unless @target_pm_project_id.nil? + @updated_issue.pm_sprint_id = @pm_sprint_id unless @pm_sprint_id.nil? + if @updated_issue.children_issues.count == 0 && @updated_issue.parent_id.nil? + @updated_issue.pm_issue_type = @pm_issue_type unless @pm_issue_type.nil? + end + @updated_issue.root_id = @root_id unless @root_id.nil? #不为 nil的时候更新 + @updated_issue.root_id = nil if @root_id.try(:zero?) #为 0 的时候设置为 nil + @updated_issue.time_scale = @time_scale unless @time_scale.nil? + @updated_issue.project_id = @project_id unless @project_id.nil? + @updated_issue.updated_on = Time.now + @updated_issue.changer_id = @current_user.id + @updated_issue.save! + + build_after_issue_journal_details if @updated_issue.previous_changes.present? # 操作记录 + build_previous_issue_changes + build_cirle_blockchain_token if blockchain_token_num.present? + unless @project.id.zero? + # @信息发送 + AtmeService.call(current_user, @atme_receivers, @issue) unless receivers_login.blank? + # 消息发送 + if Site.has_notice_menu? + SendTemplateMessageJob.perform_later('IssueChanged', current_user.id, @issue&.id, previous_issue_changes) unless previous_issue_changes.blank? + SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id, add_assigner_ids) unless add_assigner_ids.blank? + end + # 触发webhook + Rails.logger.info "################### 触发webhook" + TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueUpdate', @updated_issue&.id, current_user.id, previous_issue_changes.except(:issue_tags_value, :assigned_to_id)) + TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueLabel', @issue&.id, current_user.id, {issue_tag_ids: [before_issue_tag_ids, issue_tag_ids]}) unless issue_tag_ids.nil? + TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueAssign', @issue&.id, current_user.id, {assigner_ids: [before_assigner_ids, assigner_ids]}) unless assigner_ids.nil? + end + + unlock("Api::Pm::Issues::UpdateService:#{project.id}:#{issue.id}") + return @updated_issue + end + end + + private + + def issue_load_attributes + if current_user.id == @updated_issue.author_id && !PullAttachedIssue.exists?(issue_id: @updated_issue, fixed: true) + @updated_issue.blockchain_token_num = blockchain_token_num unless blockchain_token_num.nil? + end + @updated_issue.status_id = status_id if status_id.present? + @updated_issue.priority_id = priority_id if priority_id.present? + @updated_issue.fixed_version_id = milestone_id unless milestone_id.nil? + @updated_issue.branch_name = branch_name unless branch_name.nil? + @updated_issue.start_date = start_date unless start_date.nil? + @updated_issue.due_date = due_date unless due_date.nil? + @updated_issue.subject = subject if subject.present? + @updated_issue.description = description unless description.nil? + end + + def build_assigner_participants + if assigner_ids.blank? + @updated_issue.issue_participants.where(participant_type: "assigned").each(&:destroy!) + else + @updated_issue.issue_participants.where(participant_type: "assigned").where.not(participant_id: assigner_ids).each(&:destroy!) + assigner_ids.each do |aid| + next if @updated_issue.issue_participants.exists?(participant_type: "assigned", participant_id: aid) + @updated_issue.issue_participants.new({participant_type: "assigned", participant_id: aid}) + @add_assigner_ids << aid + end + end + end + + def build_edit_participants + @updated_issue.issue_participants.new({participant_type: "edited", participant_id: current_user.id}) unless @updated_issue.issue_participants.exists?(participant_type: "edited", participant_id: current_user.id) + end + + def build_atme_participants + @atme_receivers.each do |receiver| + next if @updated_issue.issue_participants.exists?(participant_type: "atme", participant_id: receiver.id) + @updated_issue.issue_participants.new({participant_type: "atme", participant_id: receiver.id}) + end + end + + def build_previous_issue_changes + @previous_issue_changes.merge!(@updated_issue.previous_changes.slice("status_id", "priority_id", "fixed_version_id", "issue_tags_value", "branch_name", "subject").symbolize_keys) + if @updated_issue.previous_changes[:start_date].present? + @previous_issue_changes.merge!(start_date: [@updated_issue.previous_changes[:start_date][0].to_s, @updated_issue.previous_changes[:start_date][1].to_s]) + end + if @updated_issue.previous_changes[:due_date].present? + @previous_issue_changes.merge!(due_date: [@updated_issue.previous_changes[:due_date][0].to_s, @updated_issue.previous_changes[:due_date][1].to_s]) + end + end + + def build_cirle_blockchain_token + if @updated_issue.previous_changes["blockchain_token_num"].present? + unlock_balance_on_blockchain(@updated_issue&.author_id.to_s, @updated_issue.project_id.to_s, @updated_issue.previous_changes["blockchain_token_num"][0].to_i) if @updated_issue.previous_changes["blockchain_token_num"][0].present? + lock_balance_on_blockchain(@updated_issue&.author_id.to_s, @updated_issue.project_id.to_s, @updated_issue.previous_changes["blockchain_token_num"][1].to_i) if @updated_issue.previous_changes["blockchain_token_num"][1].present? + end + end + + def build_issue_project_trends + if @updated_issue.previous_changes["status_id"].present? && @updated_issue.previous_changes["status_id"][1] == 5 + @updated_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE}) + end + if @updated_issue.previous_changes["status_id"].present? && @updated_issue.previous_changes["status_id"][0] == 5 + @updated_issue.project_trends.where(action_type: ProjectTrend::CLOSE).each(&:destroy!) + end + end + + def build_after_issue_journal_details + begin + # 更改标题 + if @updated_issue.previous_changes["subject"].present? + journal = @updated_issue.journals.create!({user_id: current_user.id}) + journal.journal_details.create!({property: "attr", prop_key: "subject", old_value: @updated_issue.previous_changes["subject"][0], value: @updated_issue.previous_changes["subject"][1]}) + end + + # 更改描述 + if @updated_issue.previous_changes["description"].present? + journal = @updated_issue.journals.create!({user_id: current_user.id}) + journal.journal_details.create!({property: "attr", prop_key: "description", old_value: @updated_issue.previous_changes["description"][0], value: @updated_issue.previous_changes["description"][1]}) + end + + # 修改状态 + if @updated_issue.previous_changes["status_id"].present? + journal = @updated_issue.journals.create!({user_id: current_user.id}) + journal.journal_details.create!({property: "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 \ No newline at end of file diff --git a/app/views/api/pm/issues/journals/_detail.json.jbuilder b/app/views/api/pm/issues/journals/_detail.json.jbuilder new file mode 100644 index 000000000..58a7ed8fd --- /dev/null +++ b/app/views/api/pm/issues/journals/_detail.json.jbuilder @@ -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.pm_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! "api/v1/issues/journals/children_detail", journal: journal + end + json.attachments journal.attachments do |attachment| + json.partial! "api/v1/attachments/simple_detail", locals: {attachment: attachment} + end +end diff --git a/app/views/api/pm/issues/journals/index.json.jbuilder b/app/views/api/pm/issues/journals/index.json.jbuilder new file mode 100644 index 000000000..0ca2a50e6 --- /dev/null +++ b/app/views/api/pm/issues/journals/index.json.jbuilder @@ -0,0 +1,8 @@ +json.total_journals_count @total_journals_count +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! "api/pm/issues/journals/detail", journal: journal +end \ No newline at end of file From 854df00ffb51ad90d7750674f5af9b7c4d927683 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 20 Aug 2024 16:32:19 +0800 Subject: [PATCH 253/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E6=97=A5=E5=BF=97=E6=97=A7=E6=95=B0=E6=8D=AE=E9=80=82?= =?UTF-8?q?=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/journal.rb | 48 +++++++++++++++++++ .../pm/issues/journals/_detail.json.jbuilder | 2 +- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/app/models/journal.rb b/app/models/journal.rb index ea50646b6..30924437b 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -82,6 +82,14 @@ class Journal < ApplicationRecord end end + def pm_operate_category + if (detail.property == "requirement" || detail.property == "task" || detail.property == "bug") && detail.prop_key.to_s == "1" + return "issue" + else + return detail.property == "attr" ? detail.prop_key : detail.property + end + end + def pm_operate_content content = "" detail = self.journal_details.take @@ -282,6 +290,36 @@ class Journal < ApplicationRecord content += "将优先级由#{old_value}更改为#{new_value}" end return content + when 'status_id' + old_value = IssueStatus.find_by_id(detail.old_value)&.name + new_value = IssueStatus.find_by_id(detail.value)&.name + if old_value.nil? || old_value.blank? + content += "将状态设置为#{new_value}" + else + new_value = "未设置" if new_value.blank? + content += "将状态由#{old_value}更改为#{new_value}" + end + case self.issue.pm_issue_type + when 'requirement' + content.gsub!('新增', '待评审') + content.gsub!('正在解决', '进行中') + content.gsub!('已解决', '已完成') + content.gsub!('关闭', '已关闭') + content.gsub!('拒绝', '已拒绝') + when 'task' + content.gsub!('新增', '待处理') + content.gsub!('正在解决', '进行中') + content.gsub!('已解决', '已完成') + content.gsub!('关闭', '已关闭') + content.gsub!('拒绝', '已拒绝') + when 'bug' + content.gsub!('新增', '待修复') + content.gsub!('正在解决', '修复中') + content.gsub!('已解决', '已修复') + content.gsub!('关闭', '已关闭') + content.gsub!('拒绝', '已拒绝') + end + return content when 'pm_issue_type' old_value = detail.old_value new_value = detail.value @@ -444,6 +482,16 @@ class Journal < ApplicationRecord end end return content + when 'issue' + issue = self.issue + case issue.pm_issue_type + when 1 + return "创建了需求" + when 2 + return "创建了任务" + when 3 + return "创建了缺陷" + end end end diff --git a/app/views/api/pm/issues/journals/_detail.json.jbuilder b/app/views/api/pm/issues/journals/_detail.json.jbuilder index 58a7ed8fd..fdf4bc716 100644 --- a/app/views/api/pm/issues/journals/_detail.json.jbuilder +++ b/app/views/api/pm/issues/journals/_detail.json.jbuilder @@ -11,7 +11,7 @@ json.user do end if journal.is_journal_detail? detail = journal.journal_details.take - json.operate_category detail.property == "attr" ? detail.prop_key : detail.property + json.operate_category journal.pm_operate_category json.operate_content journal.is_journal_detail? ? journal.pm_operate_content : nil else json.notes journal.notes From a8b0435c94beaf2c02625b0c1de5dbf765188fd4 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 20 Aug 2024 16:34:28 +0800 Subject: [PATCH 254/294] fix --- app/models/journal.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/journal.rb b/app/models/journal.rb index 30924437b..9a0624cf0 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -83,6 +83,7 @@ class Journal < ApplicationRecord end def pm_operate_category + detail = self.journal_details.take if (detail.property == "requirement" || detail.property == "task" || detail.property == "bug") && detail.prop_key.to_s == "1" return "issue" else From 69b5cae870013bfb38ec6c92dc868f6480469fb9 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 20 Aug 2024 16:43:31 +0800 Subject: [PATCH 255/294] fix --- app/models/journal.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/journal.rb b/app/models/journal.rb index 9a0624cf0..1c37d2f1b 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -300,20 +300,20 @@ class Journal < ApplicationRecord new_value = "未设置" if new_value.blank? content += "将状态由#{old_value}更改为#{new_value}" end - case self.issue.pm_issue_type - when 'requirement' + case self.issue.pm_issue_type.to_i + when 1 content.gsub!('新增', '待评审') content.gsub!('正在解决', '进行中') content.gsub!('已解决', '已完成') content.gsub!('关闭', '已关闭') content.gsub!('拒绝', '已拒绝') - when 'task' + when 2 content.gsub!('新增', '待处理') content.gsub!('正在解决', '进行中') content.gsub!('已解决', '已完成') content.gsub!('关闭', '已关闭') content.gsub!('拒绝', '已拒绝') - when 'bug' + when 3 content.gsub!('新增', '待修复') content.gsub!('正在解决', '修复中') content.gsub!('已解决', '已修复') From 91399808c4498f7e212044ee6dd16c6c85f914d1 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 21 Aug 2024 16:05:45 +0800 Subject: [PATCH 256/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E6=93=8D=E4=BD=9C=E8=AE=B0=E5=BD=95=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/pm/issue_links_controller.rb | 36 +++++- app/models/issue.rb | 14 +++ app/models/journal.rb | 111 +++++++++--------- app/services/api/pm/issues/create_service.rb | 39 ++++-- app/services/api/pm/issues/delete_service.rb | 28 +++-- app/services/api/pm/issues/update_service.rb | 45 ++++++- 6 files changed, 188 insertions(+), 85 deletions(-) diff --git a/app/controllers/api/pm/issue_links_controller.rb b/app/controllers/api/pm/issue_links_controller.rb index fe2c93c82..370e61d13 100644 --- a/app/controllers/api/pm/issue_links_controller.rb +++ b/app/controllers/api/pm/issue_links_controller.rb @@ -6,16 +6,40 @@ class Api::Pm::IssueLinksController < Api::Pm::BaseController end def create - params[:link_ids].map { |e| @issue.pm_links.find_or_create_by(be_linkable_type: 'Issue', be_linkable_id: e) } - render_ok + begin + ActiveRecord::Base.transaction do + params[:link_ids].each do |e| + @issue.pm_links.find_or_create_by!(be_linkable_type: 'Issue', be_linkable_id: e) + tag_issue = Issue.find_by_id(e) + next unless tag_issue.present? + journal = tag_issue.journals.create!({user_id: current_id.id}) + journal.journal_details.create!({property: "tag_link_issue", prop_key: "1", value: @issue.id.to_s}) + end + journal = @issue.journals.create!({user_id: current_user.id}) + journal.journal_details.create!({property: "tag_link_issue", prop_key: "#{params[:link_ids].size}", value: params[:link_ids].join(",")}) + end + render_ok + rescue + render_error('创建失败!') + end end def destroy - @links = PmLink.where(be_linkable_id: @issue.id, be_linkable_type: 'Issue', linkable_id: params[:id], linkable_type: 'Issue').or(PmLink.where(linkable_id: @issue.id, linkable_type: 'Issue', be_linkable_id: params[:id], be_linkable_type: 'Issue')) - @link = @links.last - if @link.try(:destroy) + begin + ActiveRecord::Base.transaction do + @links = PmLink.where(be_linkable_id: @issue.id, be_linkable_type: 'Issue', linkable_id: params[:id], linkable_type: 'Issue').or(PmLink.where(linkable_id: @issue.id, linkable_type: 'Issue', be_linkable_id: params[:id], be_linkable_type: 'Issue')) + journal = @issue.journals.create!({user_id: current_user.id}) + journal.journal_details.create!({property: "tag_link_issue", prop_key: "1", old_value: params[:id].to_s}) + another_issue = Issue.find_by_id(params[:id]) + if another_issue.present? + journal = another_issue.journals.create!({user_id: current_user.id}) + journal.journal_details.create!({property: "tag_link_issue", prop_key: "1", old_value: @issue.id.to_s}) + end + @link = @links.last + @link.destroy! + end render_ok - else + rescue render_error('删除失败!') end end diff --git a/app/models/issue.rb b/app/models/issue.rb index cb8b98cce..955f903e9 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -109,6 +109,20 @@ class Issue < ApplicationRecord after_save :incre_or_decre_closed_issues_count, :change_versions_count, :send_update_message_to_notice_system, :associate_attachment_container, :generate_uuid after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic, :destroy_be_pm_links + + def pm_issue_type_string + case pm_issue_type + when 1 + "requirement" + when 2 + "task" + when 3 + "bug" + else + "issue" + end + end + def destroy_be_pm_links PmLink.where(be_linkable_type:"Issue",be_linkable_id:self.id).map(&:destroy) end diff --git a/app/models/journal.rb b/app/models/journal.rb index 1c37d2f1b..d387366aa 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -114,8 +114,8 @@ class Journal < ApplicationRecord content.gsub!('拒绝', '已拒绝') return content when 'root_id' - old_value = Issue.find_by_id(detail.old_value)&.subject - new_value = Issue.find_by_id(detail.value)&.subject + old_value = "#{Issue.find_by_id(detail.old_value)&.subject}" + new_value = "#{Issue.find_by_id(detail.value)&.subject}" if old_value.nil? || old_value.blank? content += "关联了父需求<#{new_value}>" else @@ -127,28 +127,28 @@ class Journal < ApplicationRecord end return content when 'leaf_issue' - old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") if old_value.nil? || old_value.blank? - content += "新建了子需求#{new_value}" + content += "新建了子需求#{new_value}" else if new_value.nil? || new_value.blank? - content += "删除了关联的子需求#{old_value}" + content += "删除了关联的子需求#{old_value}" else - content += "新建了子需求#{new_value}" + content += "新建了子需求#{new_value}" end end return content when 'tag_leaf_issue' - old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") if old_value.nil? || old_value.blank? - content += "关联了子需求#{new_value}" + content += "关联了子需求#{new_value}" else if new_value.nil? || new_value.blank? - content += "取消了关联的子需求#{old_value}" + content += "取消了关联的子需求#{old_value}" else - content += "关联了子需求#{new_value}" + content += "关联了子需求#{new_value}" end end return content @@ -174,8 +174,8 @@ class Journal < ApplicationRecord content.gsub!('拒绝', '已拒绝') return content when 'root_id' - old_value = Issue.find_by_id(detail.old_value)&.subject - new_value = Issue.find_by_id(detail.value)&.subject + old_value = "#{Issue.find_by_id(detail.old_value)&.subject}" + new_value = "#{Issue.find_by_id(detail.value)&.subject}" if old_value.nil? || old_value.blank? content += "关联了父任务<#{new_value}>" else @@ -187,28 +187,28 @@ class Journal < ApplicationRecord end return content when 'leaf_issue' - old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") if old_value.nil? || old_value.blank? - content += "新建了子任务#{new_value}" + content += "新建了子任务#{new_value}" else if new_value.nil? || new_value.blank? - content += "删除了关联的子任务#{old_value}" + content += "删除了关联的子任务#{old_value}" else - content += "新建了子任务#{new_value}" + content += "新建了子任务#{new_value}" end end return content when 'tag_leaf_issue' - old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") if old_value.nil? || old_value.blank? - content += "关联了子任务#{new_value}" + content += "关联了子任务#{new_value}" else if new_value.nil? || new_value.blank? - content += "取消了关联的子任务#{old_value}" + content += "取消了关联的子任务#{old_value}" else - content += "关联了子任务#{new_value}" + content += "关联了子任务#{new_value}" end end return content @@ -234,8 +234,8 @@ class Journal < ApplicationRecord content.gsub!('拒绝', '已拒绝') return content when 'root_id' - old_value = Issue.find_by_id(detail.old_value)&.subject - new_value = Issue.find_by_id(detail.value)&.subject + old_value = "#{Issue.find_by_id(detail.old_value)&.subject}" + new_value = "#{Issue.find_by_id(detail.value)&.subject}" if old_value.nil? || old_value.blank? content += "关联了父缺陷<#{new_value}>" else @@ -247,28 +247,28 @@ class Journal < ApplicationRecord end return content when 'leaf_issue' - old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") if old_value.nil? || old_value.blank? - content += "新建了子缺陷#{new_value}" + content += "新建了子缺陷#{new_value}" else if new_value.nil? || new_value.blank? - content += "删除了关联的子缺陷#{old_value}" + content += "删除了关联的子缺陷#{old_value}" else - content += "新建了子缺陷#{new_value}" + content += "新建了子缺陷#{new_value}" end end return content when 'tag_leaf_issue' - old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") if old_value.nil? || old_value.blank? - content += "关联了子缺陷#{new_value}" + content += "关联了子缺陷#{new_value}" else if new_value.nil? || new_value.blank? - content += "取消了关联的子缺陷#{old_value}" + content += "取消了关联的子缺陷#{old_value}" else - content += "关联了子缺陷#{new_value}" + content += "关联了子缺陷#{new_value}" end end return content @@ -429,41 +429,41 @@ class Journal < ApplicationRecord end return content when 'assigner' - old_value = User.where(id: detail.old_value.split(",")).map{|u| u.real_name}.join("、") - new_value = User.where(id: detail.value.split(",")).map{|u| u.real_name}.join("、") + old_value = User.where(id: detail.old_value.split(",")).map{|u| "#{u.real_name}"}.join("、") + new_value = User.where(id: detail.value.split(",")).map{|u| "#{u.real_name}"}.join("、") if old_value.nil? || old_value.blank? - content += "添加负责人#{new_value}" + content += "添加负责人#{new_value}" else if new_value.nil? || new_value.blank? content += "将负责人更改为未设置" else - content += "将负责人由#{old_value}更改为#{new_value}" + content += "将负责人由#{old_value}更改为#{new_value}" end end return content when 'issue_tag' - old_value = IssueTag.where(id: detail.old_value.split(",")).pluck(:name).join("、") - new_value = IssueTag.where(id: detail.value.split(",")).pluck(:name).join("、") + old_value = IssueTag.where(id: detail.old_value.split(",")).map{|t| "#{t.name}"}.join("、") + new_value = IssueTag.where(id: detail.value.split(",")).map{|t| "#{t.name}"}.join("、") if old_value.nil? || old_value.blank? - content += "添加标记#{new_value}" + content += "添加标记#{new_value}" else if new_value.nil? || new_value.blank? content += "将标记更改为未设置" else - content += "将标记由#{old_value}更改为#{new_value}" + content += "将标记由#{old_value}更改为#{new_value}" end end return content when 'link_issue' - old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") - new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") + old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") if old_value.nil? || old_value.blank? - content += "关联了工作项#{new_value}" + content += "新建了关联的工作项#{new_value}" else if new_value.nil? || new_value.blank? - content += "取消了关联的工作项#{old_value}" + content += "删除了关联的工作项#{old_value}" else - content += "关联了工作项#{new_value}" + content += "新建了关联的工作项#{new_value}" end end content.gsub!('1', "需求") @@ -471,17 +471,20 @@ class Journal < ApplicationRecord content.gsub!('3', "缺陷") return content when 'tag_link_issue' - old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") - new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") + old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") if old_value.nil? || old_value.blank? - content += "新建了关联的工作项#{new_value}" + content += "关联了工作项#{new_value}" else if new_value.nil? || new_value.blank? - content += "删除了关联的工作项#{old_value}" + content += "取消了关联的工作项#{old_value}" else - content += "新建了关联的工作项#{new_value}" + content += "关联了工作项#{new_value}" end end + content.gsub!('1', "需求") + content.gsub!('2', "任务") + content.gsub!('3', "缺陷") return content when 'issue' issue = self.issue diff --git a/app/services/api/pm/issues/create_service.rb b/app/services/api/pm/issues/create_service.rb index 796faf1e5..5412fe17d 100644 --- a/app/services/api/pm/issues/create_service.rb +++ b/app/services/api/pm/issues/create_service.rb @@ -55,16 +55,6 @@ class Api::Pm::Issues::CreateService < ApplicationService load_atme_receivers(receivers_login) unless receivers_login.blank? try_lock("Api::Pm::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.pm_project_id = @pm_project_id - @created_issue.pm_sprint_id = @pm_sprint_id @created_issue.pm_issue_type = @pm_issue_type if @root_subject.present? && @pm_issue_type.to_i == 4 @root_issue = Issue.find_by(subject: @root_subject, pm_issue_type: 4, pm_project_id: @pm_project_id) @@ -75,12 +65,35 @@ class Api::Pm::Issues::CreateService < ApplicationService else @created_issue.root_id = @root_id end + build_author_participants + build_assigner_participants unless assigner_ids.blank? + build_atme_participants if @atme_receivers.present? + build_issue_journal_details + build_issue_project_trends + @created_issue.assigners = @assigners unless assigner_ids.blank? + @created_issue.attachments = @attachments unless attachment_ids.blank? + @created_issue.issue_tags = @issue_tags unless issue_tag_ids.blank? + @created_issue.pm_project_id = @pm_project_id + @created_issue.pm_sprint_id = @pm_sprint_id @created_issue.time_scale = @time_scale @created_issue.issue_tags_value = @issue_tags.order('id asc').pluck(:id).join(',') unless issue_tag_ids.blank? @created_issue.changer_id = @current_user.id @created_issue.save! - - PmLink.create(be_linkable_type: 'Issue', be_linkable_id: @created_issue.id, linkable_type: 'Issue', linkable_id: @linkable_id) if @linkable_id.present? + if @created_issue.parent_issue.present? + parent_issue = @created_issue.parent_issue + if @created_issue.root_id.present? && parent_issue.present? + journal = parent_issue.journals.create!({user_id: current_user.id}) + journal.journal_details.create!({property: @created_issue.pm_issue_type_string, prop_key: 'leaf_issue', value: @created_issue.id.to_s}) + end + end + if @linkable_id.present? + PmLink.create(be_linkable_type: 'Issue', be_linkable_id: @created_issue.id, linkable_type: 'Issue', linkable_id: @linkable_id) + another_issue = Issue.find_by_id(@linkable_id) + if another_issue.present? + journal = another_issue.journals.create!({user_id: @current_user.id}) + journal.journal_details.create!({property: 'link_issue', prop_key: "1", value: @created_issue.id.to_s}) + end + end if Site.has_blockchain? && @project.use_blockchain if @created_issue.blockchain_token_num.present? && @created_issue.blockchain_token_num > 0 Blockchain::CreateIssue.call({user_id: current_user.id, project_id: @created_issue.project_id, token_num: @created_issue.blockchain_token_num}) @@ -163,6 +176,6 @@ class Api::Pm::Issues::CreateService < ApplicationService def build_issue_journal_details journal = @created_issue.journals.new({user_id: current_user.id}) - journal.journal_details.new({property: 'issue', prop_key: 1, old_value: '', value: ''}) + journal.journal_details.new({property: @created_issue.pm_issue_type_string, prop_key: 1, old_value: '', value: ''}) end end \ No newline at end of file diff --git a/app/services/api/pm/issues/delete_service.rb b/app/services/api/pm/issues/delete_service.rb index 2d5df500e..0a04094c3 100644 --- a/app/services/api/pm/issues/delete_service.rb +++ b/app/services/api/pm/issues/delete_service.rb @@ -14,21 +14,27 @@ class Api::Pm::Issues::DeleteService < ApplicationService def call raise Error, errors.full_messages.join(", ") unless valid? try_lock("Api::V1::Issues::DeleteService:#{project.id}") # 开始写数据,加锁 + ActiveRecord::Base.transaction do + parent_issue = @issue.parent_issue + if @issue.root_id.present? && parent_issue.present? + journal = parent_issue.journals.create!({user_id: current_user.id}) + journal.journal_details.create!({property: @issue.pm_issue_type_string, prop_key: 'leaf_issue', old_value: @issue.id.to_s}) + end - delete_issue - #删除双向关联 - PmLink.where(be_linkable_id: @issue.id, be_linkable_type: 'Issue').or(PmLink.where(linkable_id: @issue.id, linkable_type: 'Issue')).map(&:destroy) + delete_issue + #删除双向关联 + PmLink.where(be_linkable_id: @issue.id, be_linkable_type: 'Issue').or(PmLink.where(linkable_id: @issue.id, linkable_type: 'Issue')).map(&:destroy) - project.incre_project_issue_cache_delete_count + project.incre_project_issue_cache_delete_count - if Site.has_blockchain? && @project.use_blockchain && !project.id.zero? - unlock_balance_on_blockchain(@issue.author_id.to_s, @project.id.to_s, @issue.blockchain_token_num.to_i) if @issue.blockchain_token_num.present? + if Site.has_blockchain? && @project.use_blockchain && !project.id.zero? + unlock_balance_on_blockchain(@issue.author_id.to_s, @project.id.to_s, @issue.blockchain_token_num.to_i) if @issue.blockchain_token_num.present? + end + + if Site.has_notice_menu? && !project.id.zero? + SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, @issue&.subject, @issue.assigners.pluck(:id), @issue.author_id) + end end - - if Site.has_notice_menu? && !project.id.zero? - SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, @issue&.subject, @issue.assigners.pluck(:id), @issue.author_id) - end - unlock("Api::V1::Issues::DeleteService:#{project.id}") return true diff --git a/app/services/api/pm/issues/update_service.rb b/app/services/api/pm/issues/update_service.rb index 99896e884..7196a497e 100644 --- a/app/services/api/pm/issues/update_service.rb +++ b/app/services/api/pm/issues/update_service.rb @@ -196,7 +196,7 @@ class Api::Pm::Issues::UpdateService < ApplicationService # 修改状态 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]}) + journal.journal_details.create!({property: @updated_issue.pm_issue_type_string, prop_key: "status_id", old_value: @updated_issue.previous_changes["status_id"][0], value: @updated_issue.previous_changes["status_id"][1]}) end # 修改优先级 @@ -205,6 +205,24 @@ class Api::Pm::Issues::UpdateService < ApplicationService journal.journal_details.create!({property: "attr", prop_key: "priority_id", old_value: @updated_issue.previous_changes["priority_id"][0], value: @updated_issue.previous_changes["priority_id"][1]}) end + # 修改工作项类型 + if @updated_issue.previous_changes["pm_issue_type"].present? + journal = @updated_issue.journals.create!({user_id: current_user.id}) + journal.journal_details.create!({property: "attr", prop_key: "pm_issue_type", old_value: @updated_issue.previous_changes["pm_issue_type"][0], value: @updated_issue.previous_changes["pm_issue_type"][1]}) + end + + # 修改迭代 + if @updated_issue.previous_changes["pm_sprint_id"].present? + journal = @updated_issue.journals.create!({user_id: current_user.id}) + journal.journal_details.create!({property: "attr", prop_key: "pm_sprint_id", old_value: @updated_issue.previous_changes["pm_sprint_id"][0], value: @updated_issue.previous_changes["pm_sprint_id"][1]}) + end + + # 修改代码库 + if @updated_issue.previous_changes["project_id"].present? + journal = @updated_issue.journals.create!({user_id: current_user.id}) + journal.journal_details.create!({property: "attr", prop_key: "project_id", old_value: @updated_issue.previous_changes["project_id"][0], value: @updated_issue.previous_changes["project_id"][1]}) + end + # 修改里程碑 if @updated_issue.previous_changes["fixed_version_id"].present? journal = @updated_issue.journals.create!({user_id: current_user.id}) @@ -228,6 +246,31 @@ class Api::Pm::Issues::UpdateService < ApplicationService journal = @updated_issue.journals.create!({user_id: current_user.id}) journal.journal_details.create!({property: "attr", prop_key: "due_date", old_value: @updated_issue.previous_changes["due_date"][0], value: @updated_issue.previous_changes["due_date"][1]}) end + + # 更改预估工时 + if @updated_issue.previous_changes["time_scale"].present? + journal = @updated_issue.journals.create!({user_id: current_user.id}) + journal.journal_details.create!({property: "attr", prop_key: "time_scale", old_value: @updated_issue.previous_changes["time_scale"][0], value: @updated_issue.previous_changes["time_scale"][1]}) + end + + # 更改父工作项 + if @updated_issue.previous_changes["root_id"].present? + journal = @updated_issue.journals.create!({user_id: current_user.id}) + journal.journal_details.create!({property: @updated_issue.pm_issue_type_string, prop_key: "root_id", old_value: @updated_issue.previous_changes["root_id"][0], value: @updated_issue.previous_changes["root_id"][1]}) + + # 更改子工作项 + before_parent_issue = Issue.find_by_id(@updated_issue.previous_changes["root_id"][0]) + if before_parent_issue.present? + journal = before_parent_issue.journals.create!({user_id: current_user.id}) + journal.journal_details.create!({property: @updated_issue.pm_issue_type_string, prop_key: "tag_leaf_issue", old_value: @updated_issue.previous_changes["root_id"][0]}) + end + + after_parent_issue = Issue.find_by_id(@updated_issue.previous_changes["root_id"][1]) + if after_parent_issue.present? + journal = after_parent_issue.journals.create!({user_id: current_user.id}) + journal.journal_details.create!({property: @updated_issue.pm_issue_type_string, prop_key: "tag_leaf_issue", value: @updated_issue.previous_changes["root_id"][1]}) + end + end rescue raise Error, "创建操作记录失败!" end From 1a374468eaa1c4fa6c0558fc175bc929bbd625a5 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 21 Aug 2024 17:23:13 +0800 Subject: [PATCH 257/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/pm/issue_links_controller.rb | 2 +- app/models/journal.rb | 108 +++++++++--------- app/services/api/pm/issues/update_service.rb | 10 +- 3 files changed, 60 insertions(+), 60 deletions(-) diff --git a/app/controllers/api/pm/issue_links_controller.rb b/app/controllers/api/pm/issue_links_controller.rb index 370e61d13..867dcaf41 100644 --- a/app/controllers/api/pm/issue_links_controller.rb +++ b/app/controllers/api/pm/issue_links_controller.rb @@ -12,7 +12,7 @@ class Api::Pm::IssueLinksController < Api::Pm::BaseController @issue.pm_links.find_or_create_by!(be_linkable_type: 'Issue', be_linkable_id: e) tag_issue = Issue.find_by_id(e) next unless tag_issue.present? - journal = tag_issue.journals.create!({user_id: current_id.id}) + journal = tag_issue.journals.create!({user_id: current_user.id}) journal.journal_details.create!({property: "tag_link_issue", prop_key: "1", value: @issue.id.to_s}) end journal = @issue.journals.create!({user_id: current_user.id}) diff --git a/app/models/journal.rb b/app/models/journal.rb index d387366aa..4a78ed301 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -84,10 +84,10 @@ class Journal < ApplicationRecord def pm_operate_category detail = self.journal_details.take - if (detail.property == "requirement" || detail.property == "task" || detail.property == "bug") && detail.prop_key.to_s == "1" + if %w(requirement task bug).include?(detail.property) && detail.prop_key.to_s == "1" return "issue" else - return detail.property == "attr" ? detail.prop_key : detail.property + return %w(requirement task bug attr).include?(detail.property) ? detail.prop_key : detail.property end end @@ -101,10 +101,10 @@ class Journal < ApplicationRecord old_value = IssueStatus.find_by_id(detail.old_value)&.name new_value = IssueStatus.find_by_id(detail.value)&.name content += "将状态" - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "设置为#{new_value}" else - new_value = "未设置" if new_value.blank? + new_value = "未设置" if detail.value.blank? content += "由#{old_value}更改为#{new_value}" end content.gsub!('新增', '待评审') @@ -116,10 +116,10 @@ class Journal < ApplicationRecord when 'root_id' old_value = "#{Issue.find_by_id(detail.old_value)&.subject}" new_value = "#{Issue.find_by_id(detail.value)&.subject}" - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "关联了父需求<#{new_value}>" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "取消了关联的父需求<#{old_value}>" else content += "将关联的父需求由<#{old_value}>更改为<#{new_value}>" @@ -129,10 +129,10 @@ class Journal < ApplicationRecord when 'leaf_issue' old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "新建了子需求#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "删除了关联的子需求#{old_value}" else content += "新建了子需求#{new_value}" @@ -142,10 +142,10 @@ class Journal < ApplicationRecord when 'tag_leaf_issue' old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "关联了子需求#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "取消了关联的子需求#{old_value}" else content += "关联了子需求#{new_value}" @@ -161,10 +161,10 @@ class Journal < ApplicationRecord old_value = IssueStatus.find_by_id(detail.old_value)&.name new_value = IssueStatus.find_by_id(detail.value)&.name content += "将状态" - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "设置为#{new_value}" else - new_value = "未设置" if new_value.blank? + new_value = "未设置" if detail.value.blank? content += "由#{old_value}更改为#{new_value}" end content.gsub!('新增', '待处理') @@ -176,10 +176,10 @@ class Journal < ApplicationRecord when 'root_id' old_value = "#{Issue.find_by_id(detail.old_value)&.subject}" new_value = "#{Issue.find_by_id(detail.value)&.subject}" - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "关联了父任务<#{new_value}>" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "取消了关联的父任务<#{old_value}>" else content += "将关联的父任务由<#{old_value}>更改为<#{new_value}>" @@ -189,10 +189,10 @@ class Journal < ApplicationRecord when 'leaf_issue' old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "新建了子任务#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "删除了关联的子任务#{old_value}" else content += "新建了子任务#{new_value}" @@ -202,10 +202,10 @@ class Journal < ApplicationRecord when 'tag_leaf_issue' old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "关联了子任务#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "取消了关联的子任务#{old_value}" else content += "关联了子任务#{new_value}" @@ -221,10 +221,10 @@ class Journal < ApplicationRecord old_value = IssueStatus.find_by_id(detail.old_value)&.name new_value = IssueStatus.find_by_id(detail.value)&.name content += "将状态" - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "设置为#{new_value}" else - new_value = "未设置" if new_value.blank? + new_value = "未设置" if detail.value.blank? content += "由#{old_value}更改为#{new_value}" end content.gsub!('新增', '待修复') @@ -236,10 +236,10 @@ class Journal < ApplicationRecord when 'root_id' old_value = "#{Issue.find_by_id(detail.old_value)&.subject}" new_value = "#{Issue.find_by_id(detail.value)&.subject}" - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "关联了父缺陷<#{new_value}>" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "取消了关联的父缺陷<#{old_value}>" else content += "将关联的父缺陷由<#{old_value}>更改为<#{new_value}>" @@ -249,10 +249,10 @@ class Journal < ApplicationRecord when 'leaf_issue' old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "新建了子缺陷#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "删除了关联的子缺陷#{old_value}" else content += "新建了子缺陷#{new_value}" @@ -262,10 +262,10 @@ class Journal < ApplicationRecord when 'tag_leaf_issue' old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "关联了子缺陷#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "取消了关联的子缺陷#{old_value}" else content += "关联了子缺陷#{new_value}" @@ -284,20 +284,20 @@ class Journal < ApplicationRecord when 'priority_id' old_value = IssuePriority.find_by_id(detail.old_value)&.name new_value = IssuePriority.find_by_id(detail.value)&.name - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "将优先级设置为#{new_value}" else - new_value = "未设置" if new_value.blank? + new_value = "未设置" if detail.value.blank? content += "将优先级由#{old_value}更改为#{new_value}" end return content when 'status_id' old_value = IssueStatus.find_by_id(detail.old_value)&.name new_value = IssueStatus.find_by_id(detail.value)&.name - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "将状态设置为#{new_value}" else - new_value = "未设置" if new_value.blank? + new_value = "未设置" if detail.value.blank? content += "将状态由#{old_value}更改为#{new_value}" end case self.issue.pm_issue_type.to_i @@ -324,10 +324,10 @@ class Journal < ApplicationRecord when 'pm_issue_type' old_value = detail.old_value new_value = detail.value - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "将工作项类型设置为#{new_value}" else - new_value = "未设置" if new_value.blank? + new_value = "未设置" if detail.value.blank? content += "将工作项类型由#{old_value}更改为#{new_value}" end content.gsub!('1', '需求') @@ -337,10 +337,10 @@ class Journal < ApplicationRecord when 'pm_sprint_id' old_value = detail.old_value new_value = detail.value - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "添加了关联迭代" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "将关联迭代更改为未设置" else content += "变更了关联迭代" @@ -350,10 +350,10 @@ class Journal < ApplicationRecord when 'project_id' old_value = Project.find_by_id(detail.old_value)&.name new_value = Project.find_by_id(detail.value)&.name - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "添加关联代码库#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "将关联代码库更改为未设置" else content += "将关联代码库由#{old_value}改为#{new_value}" @@ -363,10 +363,10 @@ class Journal < ApplicationRecord when 'branch_name' old_value = detail.old_value new_value = detail.value - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "添加关联分支#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "将关联分支更改为未设置" else content += "将关联分支由#{old_value}改为#{new_value}" @@ -377,10 +377,10 @@ class Journal < ApplicationRecord when 'start_date' old_value = detail.old_value new_value = detail.value - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "添加开始时间#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "将开始时间更改为未设置" else content += "将开始时间由#{old_value}改为#{new_value}" @@ -391,10 +391,10 @@ class Journal < ApplicationRecord when 'due_date' old_value = detail.old_value new_value = detail.value - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "添加结束时间#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "将结束时间更改为未设置" else content += "将结束时间由#{old_value}改为#{new_value}" @@ -404,10 +404,10 @@ class Journal < ApplicationRecord when 'time_scale' old_value = detail.old_value new_value = detail.value - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "添加预估工时#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "将预估工时更改为未设置" else content += "将预估工时由#{old_value}改为#{new_value}" @@ -418,10 +418,10 @@ class Journal < ApplicationRecord when 'attachment' old_value = detail.old_value.to_s new_value = detail.value.to_s - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "上传了附件" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "删除了附件" else content += "上传了附件" @@ -431,10 +431,10 @@ class Journal < ApplicationRecord when 'assigner' old_value = User.where(id: detail.old_value.split(",")).map{|u| "#{u.real_name}"}.join("、") new_value = User.where(id: detail.value.split(",")).map{|u| "#{u.real_name}"}.join("、") - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "添加负责人#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "将负责人更改为未设置" else content += "将负责人由#{old_value}更改为#{new_value}" @@ -444,10 +444,10 @@ class Journal < ApplicationRecord when 'issue_tag' old_value = IssueTag.where(id: detail.old_value.split(",")).map{|t| "#{t.name}"}.join("、") new_value = IssueTag.where(id: detail.value.split(",")).map{|t| "#{t.name}"}.join("、") - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "添加标记#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "将标记更改为未设置" else content += "将标记由#{old_value}更改为#{new_value}" @@ -457,10 +457,10 @@ class Journal < ApplicationRecord when 'link_issue' old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "新建了关联的工作项#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "删除了关联的工作项#{old_value}" else content += "新建了关联的工作项#{new_value}" @@ -473,10 +473,10 @@ class Journal < ApplicationRecord when 'tag_link_issue' old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "关联了工作项#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "取消了关联的工作项#{old_value}" else content += "关联了工作项#{new_value}" diff --git a/app/services/api/pm/issues/update_service.rb b/app/services/api/pm/issues/update_service.rb index 7196a497e..78d62fb2b 100644 --- a/app/services/api/pm/issues/update_service.rb +++ b/app/services/api/pm/issues/update_service.rb @@ -262,13 +262,13 @@ class Api::Pm::Issues::UpdateService < ApplicationService before_parent_issue = Issue.find_by_id(@updated_issue.previous_changes["root_id"][0]) if before_parent_issue.present? journal = before_parent_issue.journals.create!({user_id: current_user.id}) - journal.journal_details.create!({property: @updated_issue.pm_issue_type_string, prop_key: "tag_leaf_issue", old_value: @updated_issue.previous_changes["root_id"][0]}) + journal.journal_details.create!({property: @updated_issue.pm_issue_type_string, prop_key: "tag_leaf_issue", old_value: @updated_issue.id.to_s}) end after_parent_issue = Issue.find_by_id(@updated_issue.previous_changes["root_id"][1]) if after_parent_issue.present? journal = after_parent_issue.journals.create!({user_id: current_user.id}) - journal.journal_details.create!({property: @updated_issue.pm_issue_type_string, prop_key: "tag_leaf_issue", value: @updated_issue.previous_changes["root_id"][1]}) + journal.journal_details.create!({property: @updated_issue.pm_issue_type_string, prop_key: "tag_leaf_issue", value: @updated_issue.id.to_s}) end end rescue @@ -282,7 +282,7 @@ class Api::Pm::Issues::UpdateService < ApplicationService 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?) + if !(now_assigner_ids.sort == new_assigner_ids.sort) journal = @updated_issue.journals.create!({user_id: current_user.id}) journal.journal_details.create!({property: "assigner", prop_key: "#{new_assigner_ids.size}", old_value: now_assigner_ids.join(","), value: new_assigner_ids.join(",")}) end @@ -298,7 +298,7 @@ class Api::Pm::Issues::UpdateService < ApplicationService 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?) + if !(now_issue_tag_ids.sort == new_issue_tag_ids.sort) journal = @updated_issue.journals.create!({user_id: current_user.id}) journal.journal_details.create!({property: "issue_tag", prop_key: "#{new_issue_tag_ids.size}", old_value: now_issue_tag_ids.join(","), value: new_issue_tag_ids.join(",")}) end @@ -314,7 +314,7 @@ class Api::Pm::Issues::UpdateService < ApplicationService 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?) + if !(now_attachment_ids.sort == new_attachment_ids.sort) journal = @updated_issue.journals.create!({user_id: current_user.id}) journal.journal_details.create!({property: "attachment", prop_key: "#{new_attachment_ids.size}", old_value: now_attachment_ids.join(","), value: new_attachment_ids.join(",")}) end From 0643d24486d3ebfee67f1c7e2fd740c8e96e9cad Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 21 Aug 2024 17:30:14 +0800 Subject: [PATCH 258/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/journal.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/models/journal.rb b/app/models/journal.rb index 4a78ed301..d2410a2b7 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -117,12 +117,12 @@ class Journal < ApplicationRecord old_value = "#{Issue.find_by_id(detail.old_value)&.subject}" new_value = "#{Issue.find_by_id(detail.value)&.subject}" if detail.old_value.nil? || detail.old_value.blank? - content += "关联了父需求<#{new_value}>" + content += "关联了父需求<#{new_value}>" else if detail.value.nil? || detail.value.blank? - content += "取消了关联的父需求<#{old_value}>" + content += "取消了关联的父需求<#{old_value}>" else - content += "将关联的父需求由<#{old_value}>更改为<#{new_value}>" + content += "将关联的父需求由<#{old_value}>更改为<#{new_value}>" end end return content @@ -177,12 +177,12 @@ class Journal < ApplicationRecord old_value = "#{Issue.find_by_id(detail.old_value)&.subject}" new_value = "#{Issue.find_by_id(detail.value)&.subject}" if detail.old_value.nil? || detail.old_value.blank? - content += "关联了父任务<#{new_value}>" + content += "关联了父任务<#{new_value}>" else if detail.value.nil? || detail.value.blank? - content += "取消了关联的父任务<#{old_value}>" + content += "取消了关联的父任务<#{old_value}>" else - content += "将关联的父任务由<#{old_value}>更改为<#{new_value}>" + content += "将关联的父任务由<#{old_value}>更改为<#{new_value}>" end end return content @@ -237,12 +237,12 @@ class Journal < ApplicationRecord old_value = "#{Issue.find_by_id(detail.old_value)&.subject}" new_value = "#{Issue.find_by_id(detail.value)&.subject}" if detail.old_value.nil? || detail.old_value.blank? - content += "关联了父缺陷<#{new_value}>" + content += "关联了父缺陷<#{new_value}>" else if detail.value.nil? || detail.value.blank? - content += "取消了关联的父缺陷<#{old_value}>" + content += "取消了关联的父缺陷<#{old_value}>" else - content += "将关联的父缺陷由<#{old_value}>更改为<#{new_value}>" + content += "将关联的父缺陷由<#{old_value}>更改为<#{new_value}>" end end return content From 63753c3963f479840f8ce85851dd9f5ac72ad350 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 21 Aug 2024 17:36:03 +0800 Subject: [PATCH 259/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=8E=A8?= =?UTF-8?q?=E9=80=81=E4=BB=A3=E7=A0=81=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/journal.rb | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/app/models/journal.rb b/app/models/journal.rb index d2410a2b7..ab15de9d9 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -114,15 +114,15 @@ class Journal < ApplicationRecord content.gsub!('拒绝', '已拒绝') return content when 'root_id' - old_value = "#{Issue.find_by_id(detail.old_value)&.subject}" - new_value = "#{Issue.find_by_id(detail.value)&.subject}" + old_value = "<#{Issue.find_by_id(detail.old_value)&.subject}>" + new_value = "<#{Issue.find_by_id(detail.value)&.subject}>" if detail.old_value.nil? || detail.old_value.blank? - content += "关联了父需求<#{new_value}>" + content += "关联了父需求#{new_value}" else if detail.value.nil? || detail.value.blank? - content += "取消了关联的父需求<#{old_value}>" + content += "取消了关联的父需求#{old_value}" else - content += "将关联的父需求由<#{old_value}>更改为<#{new_value}>" + content += "将关联的父需求由#{old_value}更改为#{new_value}" end end return content @@ -174,15 +174,15 @@ class Journal < ApplicationRecord content.gsub!('拒绝', '已拒绝') return content when 'root_id' - old_value = "#{Issue.find_by_id(detail.old_value)&.subject}" - new_value = "#{Issue.find_by_id(detail.value)&.subject}" + old_value = "<#{Issue.find_by_id(detail.old_value)&.subject}>" + new_value = "<#{Issue.find_by_id(detail.value)&.subject}>" if detail.old_value.nil? || detail.old_value.blank? - content += "关联了父任务<#{new_value}>" + content += "关联了父任务#{new_value}" else if detail.value.nil? || detail.value.blank? - content += "取消了关联的父任务<#{old_value}>" + content += "取消了关联的父任务#{old_value}" else - content += "将关联的父任务由<#{old_value}>更改为<#{new_value}>" + content += "将关联的父任务由#{old_value}>更改为#{new_value}" end end return content @@ -234,15 +234,15 @@ class Journal < ApplicationRecord content.gsub!('拒绝', '已拒绝') return content when 'root_id' - old_value = "#{Issue.find_by_id(detail.old_value)&.subject}" - new_value = "#{Issue.find_by_id(detail.value)&.subject}" + old_value = "<#{Issue.find_by_id(detail.old_value)&.subject}>" + new_value = "<#{Issue.find_by_id(detail.value)&.subject}>" if detail.old_value.nil? || detail.old_value.blank? - content += "关联了父缺陷<#{new_value}>" + content += "关联了父缺陷#{new_value}" else if detail.value.nil? || detail.value.blank? - content += "取消了关联的父缺陷<#{old_value}>" + content += "取消了关联的父缺陷#{old_value}" else - content += "将关联的父缺陷由<#{old_value}>更改为<#{new_value}>" + content += "将关联的父缺陷由#{old_value}更改为#{new_value}" end end return content From d69438454d947bfc744d614a1870efda38b58b0c Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 22 Aug 2024 14:20:19 +0800 Subject: [PATCH 260/294] =?UTF-8?q?fixed=20=E9=99=84=E4=BB=B6uuid=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E7=B2=BE=E5=87=86=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/journal.rb | 4 ++-- app/services/api/v1/issues/concerns/loadable.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/journal.rb b/app/models/journal.rb index 0fdca0f9d..57eca7035 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -89,8 +89,8 @@ class Journal < ApplicationRecord when 'issue' return "创建了疑修" when 'attachment' - old_value = Attachment.where("id in (?) or uuid in (?)", detail.old_value.to_s.split(","), detail.old_value.to_s.split(",")).pluck(:filename).join("、") - new_value = Attachment.where("id in (?) or uuid in (?)", detail.value.to_s.split(","), detail.value.to_s.split(",")).pluck(:filename).join("、") + old_value = Attachment.where("BINARY id in (?) or uuid in (?)", detail.old_value.to_s.split(","), detail.old_value.to_s.split(",")).pluck(:filename).join("、") + new_value = Attachment.where("BINARY id in (?) or uuid in (?)", detail.value.to_s.split(","), detail.value.to_s.split(",")).pluck(:filename).join("、") if old_value.nil? || old_value.blank? content += "添加了#{new_value}附件" else diff --git a/app/services/api/v1/issues/concerns/loadable.rb b/app/services/api/v1/issues/concerns/loadable.rb index 547ff50d7..c8f67f256 100644 --- a/app/services/api/v1/issues/concerns/loadable.rb +++ b/app/services/api/v1/issues/concerns/loadable.rb @@ -9,7 +9,7 @@ module Api::V1::Issues::Concerns::Loadable end def load_attachments(attachment_ids) - @attachments = Attachment.where("id in (?) or uuid in (?)", attachment_ids, attachment_ids) + @attachments = Attachment.where("BINARY id in (?) or uuid in (?)", attachment_ids, attachment_ids) end def load_atme_receivers(receivers_login) From 118edbf61f3bd4e43d6d340bbe0b44bec4bf4d03 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 22 Aug 2024 14:53:00 +0800 Subject: [PATCH 261/294] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E7=A6=85?= =?UTF-8?q?=E9=81=93=E5=AF=BC=E5=85=A5=E6=95=B0=E6=8D=AE=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/import_issues_from_chandao.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/import_issues_from_chandao.rake b/lib/tasks/import_issues_from_chandao.rake index 41bbc3356..fd4c74ca1 100644 --- a/lib/tasks/import_issues_from_chandao.rake +++ b/lib/tasks/import_issues_from_chandao.rake @@ -9,7 +9,7 @@ namespace :import_from_chandao do CSV.foreach("#{Rails.root}/#{args.name}", headers: true) do | row | randd_field_hash = row.to_hash issue = Issue.new(issue_classify: "issue") - author = User.like(randd_field_hash['由谁创建']).take + author = User.like(randd_field_hash['由谁创建']).take || User.where(admin: first).first issue.author_id = author&.id assigner = randd_field_hash['指派给'].present? ? User.like(randd_field_hash['指派给']).take : nil if assigner.present? From 958631ce36158d91c1c40ce8baad4a93010cf742 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 22 Aug 2024 14:54:06 +0800 Subject: [PATCH 262/294] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E7=A6=85?= =?UTF-8?q?=E9=81=93=E5=AF=BC=E5=85=A5=E6=95=B0=E6=8D=AE=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/import_issues_from_chandao.rake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/tasks/import_issues_from_chandao.rake b/lib/tasks/import_issues_from_chandao.rake index fd4c74ca1..245e6df14 100644 --- a/lib/tasks/import_issues_from_chandao.rake +++ b/lib/tasks/import_issues_from_chandao.rake @@ -9,7 +9,7 @@ namespace :import_from_chandao do CSV.foreach("#{Rails.root}/#{args.name}", headers: true) do | row | randd_field_hash = row.to_hash issue = Issue.new(issue_classify: "issue") - author = User.like(randd_field_hash['由谁创建']).take || User.where(admin: first).first + author = User.like(randd_field_hash['由谁创建']).take || User.where(admin: true).first issue.author_id = author&.id assigner = randd_field_hash['指派给'].present? ? User.like(randd_field_hash['指派给']).take : nil if assigner.present? @@ -47,7 +47,7 @@ namespace :import_from_chandao do CSV.foreach("#{Rails.root}/#{name}", headers: true) do | row | randd_field_hash = row.to_hash issue = Issue.new(issue_classify: "issue") - author = User.like(randd_field_hash['由谁创建']).take + author = User.like(randd_field_hash['由谁创建']).take || User.where(admin: true).first issue.author_id = author&.id assigner = randd_field_hash['指派给'].present? ? User.like(randd_field_hash['指派给']).take : nil if assigner.present? @@ -82,7 +82,7 @@ namespace :import_from_chandao do CSV.foreach("#{Rails.root}/#{name}", headers: true) do | row | randd_field_hash = row.to_hash issue = Issue.new(issue_classify: "issue") - author = User.like(randd_field_hash['由谁创建']).take + author = User.like(randd_field_hash['由谁创建']).take || User.where(admin: true).first issue.author_id = author&.id assigner = randd_field_hash['指派给'].present? ? User.like(randd_field_hash['指派给']).take : nil if assigner.present? From 4516558e6f96f49368c48819717dd7c9e67dcccb Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 22 Aug 2024 14:58:02 +0800 Subject: [PATCH 263/294] =?UTF-8?q?fixed=20=E9=99=84=E4=BB=B6=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=8F=82=E6=95=B0=E8=BF=87=E8=99=91=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/organizations/projects_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/organizations/projects_controller.rb b/app/controllers/organizations/projects_controller.rb index 1180a1a51..e0525eaff 100644 --- a/app/controllers/organizations/projects_controller.rb +++ b/app/controllers/organizations/projects_controller.rb @@ -12,6 +12,7 @@ class Organizations::ProjectsController < Organizations::BaseController keywords = params[:search].to_s.each_char.select { |c| c.bytes.first < 240 }.join('') @projects = @projects.where(id: params[:pm_project_repository_ids].split(',')) if params[:pm_project_repository_ids].present? @projects = @projects.where.not(id: params[:exclude_ids].to_s.split(",")) if params[:exclude_ids].present? + @projects = @projects.where("gpid is not null") if params[:actived].present? @projects = @projects.ransack(name_or_identifier_cont: keywords).result if params[:search].present? @projects = @projects.includes(:owner).order("projects.#{sort} #{sort_direction}") @projects = paginate(@projects) From fb572af48fe85efc4aef3c6607295853e7e7793f Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 27 Aug 2024 13:42:02 +0800 Subject: [PATCH 264/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E5=B7=A5=E4=BD=9C=E9=A1=B9=E5=85=B3=E8=81=94=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E9=A1=B9=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 126 ++++++++++++------ app/models/pm_link.rb | 3 + .../20240826084717_add_fake_id_to_issues.rb | 5 + 3 files changed, 92 insertions(+), 42 deletions(-) create mode 100644 db/migrate/20240826084717_add_fake_id_to_issues.rb diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index cdf5f1d7d..472921dc8 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -130,12 +130,26 @@ class Api::Pm::IssuesController < Api::Pm::BaseController [['requirement', 1], ['task', 2], ['bug', 3]].each do |type| p.workbook.add_worksheet(:name => type[0]) do |sheet| @issues = Issue.where(pm_project_id: params[:pm_project_id], pm_issue_type: type[1]) - sheet.add_row ["标题", "正文", "创建者", "创建时间", "修改者", "更新时间", "状态", "负责人", "优先级", "标记", "开始时间","结束时间", "预估工时"] + sheet.add_row ["ID", "标题", "正文", "创建者", "创建时间", "修改者", "更新时间", "状态", "负责人", "优先级", "标记", "开始时间","结束时间", "预估工时"] @issues.each do |issue| - sheet.add_row [issue.subject, issue.description, issue.user.try(:login), issue.created_on.strftime("%Y-%m-%d %H:%M:%S"), issue.changer.try(:login), issue.updated_on.strftime("%Y-%m-%d %H:%M:%S"), issue.status_id, issue.assigners.pluck(:login).join(","), issue.priority_id, issue.issue_tags.pluck(:name, :color).join(","), issue.start_date.present? ? issue.start_date.strftime("%Y-%m-%d") : "", issue.due_date.present? ? issue.due_date.strftime("%Y-%m-%d") : "", issue.time_scale] + sheet.add_row [issue.id, issue.subject, issue.description, issue.user.try(:login), issue.created_on.strftime("%Y-%m-%d %H:%M:%S"), issue.changer.try(:login), issue.updated_on.strftime("%Y-%m-%d %H:%M:%S"), issue.status_id, issue.assigners.pluck(:login).join(","), issue.priority_id, issue.issue_tags.pluck(:name, :color).join(","), issue.start_date.present? ? issue.start_date.strftime("%Y-%m-%d") : "", issue.due_date.present? ? issue.due_date.strftime("%Y-%m-%d") : "", issue.time_scale] end end end + p.workbook.add_worksheet(:name => 'leaf_relations') do |sheet| + leaf_issues = Issue.where(pm_project_id: params[:pm_project_id]).where.not(root_id: nil) + sheet.add_row ["ID", "父工作项ID"] + leaf_issues.each do |issue| + sheet.add_row [issue.id, issue.root_id] + end + end + p.workbook.add_worksheet(:name => 'link_relations') do |sheet| + links = PmLink.joins(:linkable_issue).where(issues: {pm_project_id: params[:pm_project_id]}) + sheet.add_row ["ID", "被关联工作项ID"] + links.each do |link| + sheet.add_row [link.linkable_id, link.be_linkable_id] + end + end p.serialize('public/导出工作项.xlsx') end @@ -143,50 +157,78 @@ class Api::Pm::IssuesController < Api::Pm::BaseController end def import - return render_error('请上传正确的文件') if params[:file].blank? || !params[:file].is_a?(ActionDispatch::Http::UploadedFile) - return render_error('请输入正确的项目ID.') if params[:pm_project_id].blank? - return render_error('请输入正确的组织ID.') if params[:organization_id].blank? - types = {requirement: 1, task: 2, bug: 3} - doc = SimpleXlsxReader.open(params[:file].tempfile) - doc.sheets.each do |sheet| - type = types["#{sheet.name}".to_sym] - sheet.rows.each.with_index do |row, index| - next if index == 0 - issue = Issue.new(issue_classify: "issue", project_id: 0, pm_project_id: params[:pm_project_id], pm_issue_type: type, tracker_id: Tracker.first.id) - issue.subject = row[0] - issue.description = row[1] - author = User.find_by(login: row[2]) || User.first - issue.user = author - issue.created_on = row[3] - changer = User.find_by(login: row[4]) || User.first - issue.changer = changer - issue.updated_on = row[5] - issue.status_id = row[6].to_i - if row[7].present? - row[7].split(',').each do |a| - u = User.find_by(login: a) - next unless u.present? - issue.assigners << u - end - end - issue.priority_id = row[8] - if row[9].present? - row[9].split(',').each_slice(2).to_a.each do |t| - tag = IssueTag.find_by(project_id: 0, organization_id: params[:organization_id], name: t[0]) - if tag.present? - issue.issue_tags << tag - else - tag = IssueTag.create(project_id: 0,organization_id: params[:organization_id], name: t[0], color: t[1]) - issue.issue_tags << tag + begin + return render_error('请上传正确的文件') if params[:file].blank? || !params[:file].is_a?(ActionDispatch::Http::UploadedFile) + return render_error('请输入正确的项目ID.') if params[:pm_project_id].blank? + return render_error('请输入正确的组织ID.') if params[:organization_id].blank? + ActiveRecord::Base.transaction do + types = {requirement: 1, task: 2, bug: 3} + doc = SimpleXlsxReader.open(params[:file].tempfile) + doc.sheets.each do |sheet| + case sheet.name + when 'requirement', 'task', 'bug' + + type = types["#{sheet.name}".to_sym] + + sheet.rows.each.with_index do |row, index| + next if index == 0 + issue = Issue.new(issue_classify: "issue", project_id: 0, pm_project_id: params[:pm_project_id], pm_issue_type: type, tracker_id: Tracker.first.id) + issue.fake_id = row[0] + issue.subject = row[1] + issue.description = row[2] + author = User.find_by(login: row[3]) || User.where(admin: true).first + issue.user = author + issue.created_on = row[4] + changer = User.find_by(login: row[5]) || User.where(admin: true).first + issue.changer = changer + issue.updated_on = row[6] + issue.status_id = row[7].to_i + if row[8].present? + row[8].split(',').each do |a| + u = User.find_by(login: a) + next unless u.present? + issue.assigners << u + end + end + issue.priority_id = row[9] + if row[10].present? + row[10].split(',').each_slice(2).to_a.each do |t| + tag = IssueTag.find_by(project_id: 0, organization_id: params[:organization_id], name: t[0]) + if tag.present? + issue.issue_tags << tag + else + tag = IssueTag.create(project_id: 0,organization_id: params[:organization_id], name: t[0], color: t[1]) + issue.issue_tags << tag + end + end + end + issue.start_date = row[11] + issue.due_date = row[12] + issue.time_scale = row[13] + issue.save! + end + when 'leaf_relations' + sheet.rows.each.with_index do |row, index| + next if index == 0 + children_issue = Issue.where(fake_id: row[0]).last + parent_issue = Issue.where(fake_id: row[1]).last + next if children_issue.blank? || parent_issue.blank? + children_issue.update_column(:root_id, parent_issue.id) + end + when 'link_relations' + sheet.rows.each.with_index do |row, index| + next if index == 0 + link_issue = Issue.where(fake_id: row[0]).last + be_link_issue = Issue.where(fake_id: row[1]).last + next if link_issue.blank? || be_link_issue.blank? + PmLink.create!(linkable_type: 'Issue', linkable_id: link_issue.id, be_linkable_type: 'Issue', be_linkable_id: be_link_issue.id) end end + end - issue.start_date = row[10] - issue.due_date = row[11] - issue.time_scale = row[12] - issue.save end - + rescue + return render_error('导入失败,请上传正确格式的excel文件') end end diff --git a/app/models/pm_link.rb b/app/models/pm_link.rb index 91962bf7b..e45578158 100644 --- a/app/models/pm_link.rb +++ b/app/models/pm_link.rb @@ -18,6 +18,9 @@ class PmLink < ApplicationRecord belongs_to :linkable, polymorphic: true + belongs_to :be_linkable, polymorphic: true + belongs_to :linkable_issue, -> {where(pm_links: {linkable_type: 'Issue'})}, foreign_key: 'linkable_id', class_name: 'Issue' + belongs_to :be_linkable_issue, -> {where(pm_links: {be_linkable_type: 'Issue'})}, foreign_key: 'be_linkable_id', class_name: 'Issue' def be_linkable be_linkable_type.constantize.find be_linkable_id diff --git a/db/migrate/20240826084717_add_fake_id_to_issues.rb b/db/migrate/20240826084717_add_fake_id_to_issues.rb new file mode 100644 index 000000000..de9e30152 --- /dev/null +++ b/db/migrate/20240826084717_add_fake_id_to_issues.rb @@ -0,0 +1,5 @@ +class AddFakeIdToIssues < ActiveRecord::Migration[5.2] + def change + add_column :issues, :fake_id, :integer + end +end From 9e6ea77bf90a40a8d31173d5943faeb96343a92f Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 27 Aug 2024 13:58:35 +0800 Subject: [PATCH 265/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 472921dc8..23d9e8c54 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -227,6 +227,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController end end + render_ok rescue return render_error('导入失败,请上传正确格式的excel文件') end From 75011f66c302f2eaaa33e39f9af7d3ed60b6eb68 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 27 Aug 2024 14:20:35 +0800 Subject: [PATCH 266/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Achild=5Fcoun?= =?UTF-8?q?t=E7=9A=84=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 23d9e8c54..d93d196cc 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -213,7 +213,8 @@ class Api::Pm::IssuesController < Api::Pm::BaseController children_issue = Issue.where(fake_id: row[0]).last parent_issue = Issue.where(fake_id: row[1]).last next if children_issue.blank? || parent_issue.blank? - children_issue.update_column(:root_id, parent_issue.id) + children_issue.root_id = parent_issue.id + children_issue.save(touch: false) end when 'link_relations' sheet.rows.each.with_index do |row, index| From eff2b1fe361819470712356cdf34f5a7ac43c99e Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 28 Aug 2024 10:37:37 +0800 Subject: [PATCH 267/294] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E5=B7=A5=E4=BD=9C=E9=A1=B9=E4=B8=BApost=E6=96=B9?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/routes/api.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes/api.rb b/config/routes/api.rb index 1aea612b7..a9b472745 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -9,7 +9,7 @@ defaults format: :json do get :tags get :statues get :export - get :import + post :import end member do get :link_index From 0852a704175196ed4f0c92bd4e1fc087c1d96a60 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 28 Aug 2024 11:55:35 +0800 Subject: [PATCH 268/294] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E8=BF=94=E5=9B=9Etype?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index d93d196cc..770be6a9c 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -153,7 +153,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController p.serialize('public/导出工作项.xlsx') end - send_file('public/导出工作项.xlsx') + send_file('public/导出工作项.xlsx', :type => 'application/octet-stream;charset=utf-8') end def import From b153a486f3f1c34f3e4d8dfc82e397e554239359 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 29 Aug 2024 14:31:58 +0800 Subject: [PATCH 269/294] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E7=A6=85=E9=81=93=E6=95=B0=E6=8D=AE=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/import_issues_from_chandao.rake | 35 ++++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/lib/tasks/import_issues_from_chandao.rake b/lib/tasks/import_issues_from_chandao.rake index 245e6df14..96a47b901 100644 --- a/lib/tasks/import_issues_from_chandao.rake +++ b/lib/tasks/import_issues_from_chandao.rake @@ -5,6 +5,14 @@ namespace :import_from_chandao do # 执行示例 bundle exec rake "import_from_chandao:bugs[企业内部工时管理系统.csv, 3]" # RAILS_ENV=production bundle exec rake "import_from_chandao:bugs[企业内部工时管理系统.csv, 3]" task :bugs, [:name, :pm_project_id] => :environment do |t, args| + def trans_status(str) + h={ + "激活" => 1, + "已解决" => 3, + "已关闭" => 5 + } + h[str] + end name = args.name CSV.foreach("#{Rails.root}/#{args.name}", headers: true) do | row | randd_field_hash = row.to_hash @@ -15,17 +23,27 @@ namespace :import_from_chandao do if assigner.present? issue.assigners << assigner end - issue.status_id = IssueStatus.first.id + issue.project_issues_index = randd_field_hash['编号'].to_i + issue.status_id = trans_status(randd_field_hash['Bug状态']) || IssueStatus.first.id issue.tracker_id = Tracker.first.id issue.priority_id = randd_field_hash['优先级'].to_i issue.subject = randd_field_hash['Bug标题'] issue.description = randd_field_hash['重现步骤'] - issue.created_on = randd_field_hash['创建日期'].to_time - issue.due_date = randd_field_hash['截止日期'] + issue.created_on = randd_field_hash['创建日期'].to_time rescue nil + issue.updated_on = randd_field_hash['修改日期'].to_time rescue issue.created_on + issue.due_date = randd_field_hash['截止日期'].to_time rescue nil issue.project_id = 0 issue.pm_project_id = args.pm_project_id issue.pm_issue_type = 3 issue.save! + requirement_issue = Issue.find_by(project_issues_index: randd_field_hash['相关需求'].split('(#')[1].split(')')[0], pm_project_id: pm_project_id, pm_issue_type: 1) rescue nil + if requirement_issue.present? + requirement_issue.pm_links.find_or_create_by(be_linkable_type: 'Issue', be_linkable_id: issue.id) + end + task_issue = Issue.find_by(project_issues_index: randd_field_hash['相关任务'].split('(')[1].split(')')[0], pm_project_id: pm_project_id, pm_issue_type: 2) rescue nil + if task_issue.present? + task_issue.pm_links.find_or_create_by(be_linkable_type: 'Issue', be_linkable_id: issue.id) + end end end @@ -53,6 +71,7 @@ namespace :import_from_chandao do if assigner.present? issue.assigners << assigner end + issue.project_issues_index = randd_field_hash['编号'].to_i issue.status_id = trans_status(randd_field_hash['任务状态']) || IssueStatus.first.id issue.tracker_id = Tracker.first.id issue.priority_id = randd_field_hash['优先级'].to_i @@ -77,6 +96,14 @@ namespace :import_from_chandao do # 执行示例 bundle exec rake "import_from_chandao:requirements[企业网站第二期.csv, 3]" # RAILS_ENV=production bundle exec rake "import_from_chandao:requirements[企业网站第二期.csv, 3]" task :requirements, [:name, :pm_project_id] => :environment do |t, args| + def trans_status(str) + h={ + "草稿" => 1, + "激活" => 1, + "已关闭" => 5 + } + h[str] + end name = args.name pm_project_id = args.pm_project_id CSV.foreach("#{Rails.root}/#{name}", headers: true) do | row | @@ -89,7 +116,7 @@ namespace :import_from_chandao do issue.assigners << assigner end issue.project_issues_index = randd_field_hash['编号'].to_i - issue.status_id = IssueStatus.first.id + issue.status_id = trans_status(randd_field_hash['当前状态']) || IssueStatus.first.id issue.tracker_id = Tracker.first.id issue.priority_id = randd_field_hash['优先级'].to_i issue.subject = randd_field_hash['需求名称'] From 12ae3b94d971a894f3f573957536aa4bb953faf4 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 29 Aug 2024 16:00:44 +0800 Subject: [PATCH 270/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/import_issues_from_chandao.rake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/tasks/import_issues_from_chandao.rake b/lib/tasks/import_issues_from_chandao.rake index 96a47b901..de890b717 100644 --- a/lib/tasks/import_issues_from_chandao.rake +++ b/lib/tasks/import_issues_from_chandao.rake @@ -23,7 +23,7 @@ namespace :import_from_chandao do if assigner.present? issue.assigners << assigner end - issue.project_issues_index = randd_field_hash['编号'].to_i + issue.project_issues_index = randd_field_hash['Bug编号'].to_i issue.status_id = trans_status(randd_field_hash['Bug状态']) || IssueStatus.first.id issue.tracker_id = Tracker.first.id issue.priority_id = randd_field_hash['优先级'].to_i @@ -36,11 +36,11 @@ namespace :import_from_chandao do issue.pm_project_id = args.pm_project_id issue.pm_issue_type = 3 issue.save! - requirement_issue = Issue.find_by(project_issues_index: randd_field_hash['相关需求'].split('(#')[1].split(')')[0], pm_project_id: pm_project_id, pm_issue_type: 1) rescue nil + requirement_issue = Issue.find_by(project_issues_index: randd_field_hash['相关需求'].split('(#')[1].split(')')[0], pm_project_id: args.pm_project_id, pm_issue_type: 1) rescue nil if requirement_issue.present? requirement_issue.pm_links.find_or_create_by(be_linkable_type: 'Issue', be_linkable_id: issue.id) end - task_issue = Issue.find_by(project_issues_index: randd_field_hash['相关任务'].split('(')[1].split(')')[0], pm_project_id: pm_project_id, pm_issue_type: 2) rescue nil + task_issue = Issue.find_by(project_issues_index: randd_field_hash['相关任务'].split('(')[1].split(')')[0], pm_project_id: args.pm_project_id, pm_issue_type: 2) rescue nil if task_issue.present? task_issue.pm_links.find_or_create_by(be_linkable_type: 'Issue', be_linkable_id: issue.id) end From cd71532dd7f76648de4e7eb83783f22d9d169acf Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 3 Sep 2024 10:13:38 +0800 Subject: [PATCH 271/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E7=A6=85=E9=81=93=E8=84=9A=E6=9C=AC=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E8=BF=AD=E4=BB=A3=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/import_issues_from_chandao.rake | 265 +++++++++++++--------- 1 file changed, 154 insertions(+), 111 deletions(-) diff --git a/lib/tasks/import_issues_from_chandao.rake b/lib/tasks/import_issues_from_chandao.rake index de890b717..c4a787a57 100644 --- a/lib/tasks/import_issues_from_chandao.rake +++ b/lib/tasks/import_issues_from_chandao.rake @@ -1,133 +1,176 @@ desc "导入禅道数据" namespace :import_from_chandao do + + def get_sprint_data(name, pm_project_id, org) + assigner = org.team_users.joins(:team).where(teams: {authorize: "owner"}).take&.user + url = URI("#{EduSetting.get("pms_server_url")}/api/pms/#{org.login}/pmsProjectSprint/findOrCreate") + + http = Net::HTTP.new(url.host, url.port); + request = Net::HTTP::Post.new(url) + request["Cookie"] = "autologin_trustie=#{Token.get_or_create_permanent_login_token(assigner, 'autologin')}" + request["Content-Type"] = "application/json" + request.body = JSON.dump({ + "pmsProjectId": pm_project_id, + "sprintAssigneeId": assigner.id, + "sprintName": name + }) + + response = http.request(request) + puts response.read_body + return JSON.parse(response.read_body)['data'] + rescue + return nil + end + desc "bug数据" # 执行示例 bundle exec rake "import_from_chandao:bugs[企业内部工时管理系统.csv, 3]" # RAILS_ENV=production bundle exec rake "import_from_chandao:bugs[企业内部工时管理系统.csv, 3]" - task :bugs, [:name, :pm_project_id] => :environment do |t, args| - def trans_status(str) - h={ - "激活" => 1, - "已解决" => 3, - "已关闭" => 5 - } - h[str] - end - name = args.name - CSV.foreach("#{Rails.root}/#{args.name}", headers: true) do | row | - randd_field_hash = row.to_hash - issue = Issue.new(issue_classify: "issue") - author = User.like(randd_field_hash['由谁创建']).take || User.where(admin: true).first - issue.author_id = author&.id - assigner = randd_field_hash['指派给'].present? ? User.like(randd_field_hash['指派给']).take : nil - if assigner.present? - issue.assigners << assigner - end - issue.project_issues_index = randd_field_hash['Bug编号'].to_i - issue.status_id = trans_status(randd_field_hash['Bug状态']) || IssueStatus.first.id - issue.tracker_id = Tracker.first.id - issue.priority_id = randd_field_hash['优先级'].to_i - issue.subject = randd_field_hash['Bug标题'] - issue.description = randd_field_hash['重现步骤'] - issue.created_on = randd_field_hash['创建日期'].to_time rescue nil - issue.updated_on = randd_field_hash['修改日期'].to_time rescue issue.created_on - issue.due_date = randd_field_hash['截止日期'].to_time rescue nil - issue.project_id = 0 - issue.pm_project_id = args.pm_project_id - issue.pm_issue_type = 3 - issue.save! - requirement_issue = Issue.find_by(project_issues_index: randd_field_hash['相关需求'].split('(#')[1].split(')')[0], pm_project_id: args.pm_project_id, pm_issue_type: 1) rescue nil - if requirement_issue.present? - requirement_issue.pm_links.find_or_create_by(be_linkable_type: 'Issue', be_linkable_id: issue.id) - end - task_issue = Issue.find_by(project_issues_index: randd_field_hash['相关任务'].split('(')[1].split(')')[0], pm_project_id: args.pm_project_id, pm_issue_type: 2) rescue nil - if task_issue.present? - task_issue.pm_links.find_or_create_by(be_linkable_type: 'Issue', be_linkable_id: issue.id) + task :bugs, [:name, :pm_project_id, :org_login] => :environment do |t, args| + org = Organization.find_by(login: args.org_login) + if org.present? + def trans_status(str) + h={ + "激活" => 1, + "已解决" => 3, + "已关闭" => 5 + } + h[str] + end + name = args.name + CSV.foreach("#{Rails.root}/#{args.name}", headers: true) do | row | + randd_field_hash = row.to_hash + issue = Issue.new(issue_classify: "issue") + author = User.like(randd_field_hash['由谁创建']).take || User.where(admin: true).first + issue.author_id = author&.id + assigner = randd_field_hash['指派给'].present? ? User.like(randd_field_hash['指派给']).take : nil + if assigner.present? + issue.assigners << assigner + end + issue.project_issues_index = randd_field_hash['Bug编号'].to_i + issue.status_id = trans_status(randd_field_hash['Bug状态']) || IssueStatus.first.id + issue.tracker_id = Tracker.first.id + issue.priority_id = randd_field_hash['优先级'].to_i + issue.subject = randd_field_hash['Bug标题'] + issue.description = randd_field_hash['重现步骤'] + issue.created_on = randd_field_hash['创建日期'].to_time rescue nil + issue.updated_on = randd_field_hash['修改日期'].to_time rescue issue.created_on + issue.due_date = randd_field_hash['截止日期'].to_time rescue nil + issue.project_id = 0 + issue.pm_project_id = args.pm_project_id + issue.pm_issue_type = 3 + sprint_name = randd_field_hash['所属迭代'].split('(#')[0] + sprint = get_sprint_data(sprint_name, args.pm_project_id, org) + issue.pm_sprint_id = sprint['id'] if sprint.present? + issue.save! + requirement_issue = Issue.find_by(project_issues_index: randd_field_hash['相关需求'].split('(#')[1].split(')')[0], pm_project_id: args.pm_project_id, pm_issue_type: 1) rescue nil + if requirement_issue.present? + requirement_issue.pm_links.find_or_create_by(be_linkable_type: 'Issue', be_linkable_id: issue.id) + end + task_issue = Issue.find_by(project_issues_index: randd_field_hash['相关任务'].split('(')[1].split(')')[0], pm_project_id: args.pm_project_id, pm_issue_type: 2) rescue nil + if task_issue.present? + task_issue.pm_links.find_or_create_by(be_linkable_type: 'Issue', be_linkable_id: issue.id) + end end + else + puts "组织不存在" end end # 执行示例 bundle exec rake "import_from_chandao:tasks[复杂智能软件项目-所有任务.csv, 365]" # RAILS_ENV=production bundle exec rake "import_from_chandao:tasks[复杂智能软件项目-所有任务.csv, 365]" - task :tasks, [:name, :pm_project_id] => :environment do |t, args| - def trans_status(str) - h={ - "未开始" => 1, - "进行中" => 2, - "已完成" => 3, - "已关闭" => 5 - } - h[str] - end - - name = args.name - pm_project_id = args.pm_project_id - CSV.foreach("#{Rails.root}/#{name}", headers: true) do | row | - randd_field_hash = row.to_hash - issue = Issue.new(issue_classify: "issue") - author = User.like(randd_field_hash['由谁创建']).take || User.where(admin: true).first - issue.author_id = author&.id - assigner = randd_field_hash['指派给'].present? ? User.like(randd_field_hash['指派给']).take : nil - if assigner.present? - issue.assigners << assigner - end - issue.project_issues_index = randd_field_hash['编号'].to_i - issue.status_id = trans_status(randd_field_hash['任务状态']) || IssueStatus.first.id - issue.tracker_id = Tracker.first.id - issue.priority_id = randd_field_hash['优先级'].to_i - issue.subject = randd_field_hash['任务名称'] - issue.description = randd_field_hash['任务描述'] - issue.created_on = randd_field_hash['创建日期'].to_time rescue nil - issue.updated_on = randd_field_hash['最后修改日期'].to_time rescue issue.created_on - issue.time_scale = randd_field_hash['最初预计'].to_i - issue.start_date = randd_field_hash['预计开始'].to_time rescue nil - issue.due_date = randd_field_hash['截止日期'].to_time rescue nil - issue.project_id = 0 - issue.pm_project_id = pm_project_id - issue.pm_issue_type = 2 - issue.save! - requirement_issue = Issue.find_by(project_issues_index: randd_field_hash['相关需求'].split('(#')[1].split(')')[0], pm_project_id: pm_project_id, pm_issue_type: 1) rescue nil - if requirement_issue.present? - requirement_issue.pm_links.find_or_create_by(be_linkable_type: 'Issue', be_linkable_id: issue.id) + task :tasks, [:name, :pm_project_id, :org_login] => :environment do |t, args| + org = Organization.find_by(login: args.org_login) + if org.present? + def trans_status(str) + h={ + "未开始" => 1, + "进行中" => 2, + "已完成" => 3, + "已关闭" => 5 + } + h[str] + end + + name = args.name + pm_project_id = args.pm_project_id + CSV.foreach("#{Rails.root}/#{name}", headers: true) do | row | + randd_field_hash = row.to_hash + issue = Issue.new(issue_classify: "issue") + author = User.like(randd_field_hash['由谁创建']).take || User.where(admin: true).first + issue.author_id = author&.id + assigner = randd_field_hash['指派给'].present? ? User.like(randd_field_hash['指派给']).take : nil + if assigner.present? + issue.assigners << assigner + end + issue.project_issues_index = randd_field_hash['编号'].to_i + issue.status_id = trans_status(randd_field_hash['任务状态']) || IssueStatus.first.id + issue.tracker_id = Tracker.first.id + issue.priority_id = randd_field_hash['优先级'].to_i + issue.subject = randd_field_hash['任务名称'] + issue.description = randd_field_hash['任务描述'] + issue.created_on = randd_field_hash['创建日期'].to_time rescue nil + issue.updated_on = randd_field_hash['最后修改日期'].to_time rescue issue.created_on + issue.time_scale = randd_field_hash['最初预计'].to_i + issue.start_date = randd_field_hash['预计开始'].to_time rescue nil + issue.due_date = randd_field_hash['截止日期'].to_time rescue nil + issue.project_id = 0 + issue.pm_project_id = pm_project_id + issue.pm_issue_type = 2 + sprint_name = randd_field_hash['所属迭代'].split('(#')[0] + sprint = get_sprint_data(sprint_name, args.pm_project_id, org) + issue.pm_sprint_id = sprint['id'] if sprint.present? + issue.save! + requirement_issue = Issue.find_by(project_issues_index: randd_field_hash['相关需求'].split('(#')[1].split(')')[0], pm_project_id: pm_project_id, pm_issue_type: 1) rescue nil + if requirement_issue.present? + requirement_issue.pm_links.find_or_create_by(be_linkable_type: 'Issue', be_linkable_id: issue.id) + end end + else + puts '组织不存在' end end # 执行示例 bundle exec rake "import_from_chandao:requirements[企业网站第二期.csv, 3]" # RAILS_ENV=production bundle exec rake "import_from_chandao:requirements[企业网站第二期.csv, 3]" - task :requirements, [:name, :pm_project_id] => :environment do |t, args| - def trans_status(str) - h={ - "草稿" => 1, - "激活" => 1, - "已关闭" => 5 - } - h[str] - end - name = args.name - pm_project_id = args.pm_project_id - CSV.foreach("#{Rails.root}/#{name}", headers: true) do | row | - randd_field_hash = row.to_hash - issue = Issue.new(issue_classify: "issue") - author = User.like(randd_field_hash['由谁创建']).take || User.where(admin: true).first - issue.author_id = author&.id - assigner = randd_field_hash['指派给'].present? ? User.like(randd_field_hash['指派给']).take : nil - if assigner.present? - issue.assigners << assigner + task :requirements, [:name, :pm_project_id, :org_login] => :environment do |t, args| + org = Organization.find_by(login: args.org_login) + if org.present? + def trans_status(str) + h={ + "草稿" => 1, + "激活" => 1, + "已关闭" => 5 + } + h[str] + end + name = args.name + pm_project_id = args.pm_project_id + CSV.foreach("#{Rails.root}/#{name}", headers: true) do | row | + randd_field_hash = row.to_hash + issue = Issue.new(issue_classify: "issue") + author = User.like(randd_field_hash['由谁创建']).take || User.where(admin: true).first + issue.author_id = author&.id + assigner = randd_field_hash['指派给'].present? ? User.like(randd_field_hash['指派给']).take : nil + if assigner.present? + issue.assigners << assigner + end + issue.project_issues_index = randd_field_hash['编号'].to_i + issue.status_id = trans_status(randd_field_hash['当前状态']) || IssueStatus.first.id + issue.tracker_id = Tracker.first.id + issue.priority_id = randd_field_hash['优先级'].to_i + issue.subject = randd_field_hash['需求名称'] + issue.description = randd_field_hash['需求描述'] + issue.created_on = randd_field_hash['创建日期'].to_time + issue.updated_on = randd_field_hash['最后修改日期'].to_time rescue randd_field_hash['创建日期'].to_time + issue.time_scale = randd_field_hash['预计工时'].to_i + issue.project_id = 0 + issue.pm_project_id = pm_project_id + issue.pm_issue_type = 1 + issue.save! end - issue.project_issues_index = randd_field_hash['编号'].to_i - issue.status_id = trans_status(randd_field_hash['当前状态']) || IssueStatus.first.id - issue.tracker_id = Tracker.first.id - issue.priority_id = randd_field_hash['优先级'].to_i - issue.subject = randd_field_hash['需求名称'] - issue.description = randd_field_hash['需求描述'] - issue.created_on = randd_field_hash['创建日期'].to_time - issue.updated_on = randd_field_hash['最后修改日期'].to_time rescue randd_field_hash['创建日期'].to_time - issue.time_scale = randd_field_hash['预计工时'].to_i - issue.project_id = 0 - issue.pm_project_id = pm_project_id - issue.pm_issue_type = 1 - issue.save! + else + puts '组织不存在' end end end \ No newline at end of file From 9ec3f4655e85215cedc655830be31f2b60065926 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 3 Sep 2024 10:40:27 +0800 Subject: [PATCH 272/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/import_issues_from_chandao.rake | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/tasks/import_issues_from_chandao.rake b/lib/tasks/import_issues_from_chandao.rake index c4a787a57..d8cc4b89d 100644 --- a/lib/tasks/import_issues_from_chandao.rake +++ b/lib/tasks/import_issues_from_chandao.rake @@ -24,8 +24,8 @@ namespace :import_from_chandao do end desc "bug数据" - # 执行示例 bundle exec rake "import_from_chandao:bugs[企业内部工时管理系统.csv, 3]" - # RAILS_ENV=production bundle exec rake "import_from_chandao:bugs[企业内部工时管理系统.csv, 3]" + # 执行示例 bundle exec rake "import_from_chandao:bugs[企业内部工时管理系统.csv, 3, ceshi_org]" + # RAILS_ENV=production bundle exec rake "import_from_chandao:bugs[企业内部工时管理系统.csv, 3, ceshi_org]" task :bugs, [:name, :pm_project_id, :org_login] => :environment do |t, args| org = Organization.find_by(login: args.org_login) if org.present? @@ -59,8 +59,7 @@ namespace :import_from_chandao do issue.project_id = 0 issue.pm_project_id = args.pm_project_id issue.pm_issue_type = 3 - sprint_name = randd_field_hash['所属迭代'].split('(#')[0] - sprint = get_sprint_data(sprint_name, args.pm_project_id, org) + sprint = get_sprint_data(randd_field_hash['所属迭代'].split('(#')[0], args.pm_project_id, org) rescue nil issue.pm_sprint_id = sprint['id'] if sprint.present? issue.save! requirement_issue = Issue.find_by(project_issues_index: randd_field_hash['相关需求'].split('(#')[1].split(')')[0], pm_project_id: args.pm_project_id, pm_issue_type: 1) rescue nil @@ -77,8 +76,8 @@ namespace :import_from_chandao do end end - # 执行示例 bundle exec rake "import_from_chandao:tasks[复杂智能软件项目-所有任务.csv, 365]" - # RAILS_ENV=production bundle exec rake "import_from_chandao:tasks[复杂智能软件项目-所有任务.csv, 365]" + # 执行示例 bundle exec rake "import_from_chandao:tasks[复杂智能软件项目-所有任务.csv, 365, ceshi_org]" + # RAILS_ENV=production bundle exec rake "import_from_chandao:tasks[复杂智能软件项目-所有任务.csv, 365, ceshi_org]" task :tasks, [:name, :pm_project_id, :org_login] => :environment do |t, args| org = Organization.find_by(login: args.org_login) if org.present? @@ -117,8 +116,7 @@ namespace :import_from_chandao do issue.project_id = 0 issue.pm_project_id = pm_project_id issue.pm_issue_type = 2 - sprint_name = randd_field_hash['所属迭代'].split('(#')[0] - sprint = get_sprint_data(sprint_name, args.pm_project_id, org) + sprint = get_sprint_data(randd_field_hash['所属迭代'].split('(#')[0], args.pm_project_id, org) rescue nil issue.pm_sprint_id = sprint['id'] if sprint.present? issue.save! requirement_issue = Issue.find_by(project_issues_index: randd_field_hash['相关需求'].split('(#')[1].split(')')[0], pm_project_id: pm_project_id, pm_issue_type: 1) rescue nil @@ -131,8 +129,8 @@ namespace :import_from_chandao do end end - # 执行示例 bundle exec rake "import_from_chandao:requirements[企业网站第二期.csv, 3]" - # RAILS_ENV=production bundle exec rake "import_from_chandao:requirements[企业网站第二期.csv, 3]" + # 执行示例 bundle exec rake "import_from_chandao:requirements[企业网站第二期.csv, 3, ceshi_org]" + # RAILS_ENV=production bundle exec rake "import_from_chandao:requirements[企业网站第二期.csv, 3, ceshi_org]" task :requirements, [:name, :pm_project_id, :org_login] => :environment do |t, args| org = Organization.find_by(login: args.org_login) if org.present? From 46124f7f15672844c5c59c85d5e5ce7cae7ab8eb Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 3 Sep 2024 10:49:09 +0800 Subject: [PATCH 273/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/import_issues_from_chandao.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/import_issues_from_chandao.rake b/lib/tasks/import_issues_from_chandao.rake index d8cc4b89d..b4b799fc0 100644 --- a/lib/tasks/import_issues_from_chandao.rake +++ b/lib/tasks/import_issues_from_chandao.rake @@ -8,7 +8,7 @@ namespace :import_from_chandao do http = Net::HTTP.new(url.host, url.port); request = Net::HTTP::Post.new(url) - request["Cookie"] = "autologin_trustie=#{Token.get_or_create_permanent_login_token(assigner, 'autologin')}" + request["Cookie"] = "autologin_trustie=#{Token.get_or_create_permanent_login_token(assigner, 'autologin')&.value}" request["Content-Type"] = "application/json" request.body = JSON.dump({ "pmsProjectId": pm_project_id, From 8588c486e30e8034f9bb928885ea63bee68c3fe4 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 4 Sep 2024 09:46:39 +0800 Subject: [PATCH 274/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 770be6a9c..a3875b6c0 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -176,10 +176,10 @@ class Api::Pm::IssuesController < Api::Pm::BaseController issue.fake_id = row[0] issue.subject = row[1] issue.description = row[2] - author = User.find_by(login: row[3]) || User.where(admin: true).first + author = User.find_by(login: row[3]) issue.user = author issue.created_on = row[4] - changer = User.find_by(login: row[5]) || User.where(admin: true).first + changer = User.find_by(login: row[5]) issue.changer = changer issue.updated_on = row[6] issue.status_id = row[7].to_i @@ -224,6 +224,8 @@ class Api::Pm::IssuesController < Api::Pm::BaseController next if link_issue.blank? || be_link_issue.blank? PmLink.create!(linkable_type: 'Issue', linkable_id: link_issue.id, be_linkable_type: 'Issue', be_linkable_id: be_link_issue.id) end + else + return render_error('导入失败,请上传正确格式的excel文件') end end From 844811bc48d4b00cae8c9801285927504a7fa93d Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 5 Sep 2024 10:29:11 +0800 Subject: [PATCH 275/294] =?UTF-8?q?'=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E5=B7=A5=E4=BD=9C=E9=A1=B9=E8=A1=A8=E5=A4=B4=E6=98=9F?= =?UTF-8?q?=E5=8F=B7=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index a3875b6c0..d7890e15a 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -130,7 +130,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController [['requirement', 1], ['task', 2], ['bug', 3]].each do |type| p.workbook.add_worksheet(:name => type[0]) do |sheet| @issues = Issue.where(pm_project_id: params[:pm_project_id], pm_issue_type: type[1]) - sheet.add_row ["ID", "标题", "正文", "创建者", "创建时间", "修改者", "更新时间", "状态", "负责人", "优先级", "标记", "开始时间","结束时间", "预估工时"] + sheet.add_row ["ID", "标题*", "正文", "创建者*", "创建时间", "修改者", "更新时间", "状态", "负责人", "优先级", "标记", "开始时间","结束时间", "预估工时"] @issues.each do |issue| sheet.add_row [issue.id, issue.subject, issue.description, issue.user.try(:login), issue.created_on.strftime("%Y-%m-%d %H:%M:%S"), issue.changer.try(:login), issue.updated_on.strftime("%Y-%m-%d %H:%M:%S"), issue.status_id, issue.assigners.pluck(:login).join(","), issue.priority_id, issue.issue_tags.pluck(:name, :color).join(","), issue.start_date.present? ? issue.start_date.strftime("%Y-%m-%d") : "", issue.due_date.present? ? issue.due_date.strftime("%Y-%m-%d") : "", issue.time_scale] end From 3760eab73d154aabf9071fdaef43daa7d08545c4 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 5 Sep 2024 09:18:07 +0800 Subject: [PATCH 276/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9AThe=20target?= =?UTF-8?q?=20couldn't=20be=20found?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 92ad84b2f..2db6af016 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -300,8 +300,8 @@ class ProjectsController < ApplicationController def simple if !@project.common? && @project&.repository&.mirror&.waiting? - gitea_result = $gitea_client.get_repos_by_owner_repo(@project&.owner&.login, @project&.identifier) - if !gitea_result["empty"] + gitea_result = $gitea_client.get_repos_by_owner_repo(@project&.owner&.login, @project&.identifier) rescue nil + if gitea_result.present? && !gitea_result["empty"] @project&.update_columns(gpid: gitea_result["id"]) @project&.repository&.mirror&.succeeded! project_id = @project&.id From 192e555315b94f00ffa22d5a4f8775d4ed1241ae Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 10 Sep 2024 14:05:15 +0800 Subject: [PATCH 277/294] =?UTF-8?q?fixed=20is=5Flocal=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/settings/show.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/settings/show.json.jbuilder b/app/views/settings/show.json.jbuilder index db39d1dff..2b622f678 100644 --- a/app/views/settings/show.json.jbuilder +++ b/app/views/settings/show.json.jbuilder @@ -47,7 +47,7 @@ json.setting do json.main_site current_laboratory.main_site? json.new_course default_course_links - + json.is_local EduSetting.get("is_local") == "true" json.add do json.array! @add From 2033b2cbf063ccda0bda0e61831ef506259166e8 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 11 Sep 2024 11:30:00 +0800 Subject: [PATCH 278/294] add: debug user --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 52387cbbd..f6ee02bd6 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -356,7 +356,7 @@ class ApplicationController < ActionController::Base User.current = User.find 8686 elsif params[:debug] == 'admin' logger.info "@@@@@@@@@@@@@@@@@@@@@@ debug mode....." - user = User.find 36480 + user = User.find 1 User.current = user cookies.signed[:user_id] = user.id end From 444ce3764b686ff3b34792e81eac38440fc97801 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 11 Sep 2024 16:30:48 +0800 Subject: [PATCH 279/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E7=A6=85=E9=81=93=E6=8F=8F=E8=BF=B0=E9=87=8C=E7=9A=84?= =?UTF-8?q?=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/import_issues_from_chandao.rake | 45 +++++++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/lib/tasks/import_issues_from_chandao.rake b/lib/tasks/import_issues_from_chandao.rake index b4b799fc0..d53c10baf 100644 --- a/lib/tasks/import_issues_from_chandao.rake +++ b/lib/tasks/import_issues_from_chandao.rake @@ -23,6 +23,45 @@ namespace :import_from_chandao do return nil end + def trans_content_img(content, user) + respace_content_arr = content.to_s.scan(/]*?src=[“.*?“][^>]*?\/?>/).map{|s|[s,s.match(/(\d+\.\w+)/)[0].split(".")[0],s.match(/(\d+\.\w+)/)[0].split(".")[1]]} + respace_content_arr.each do |img| + remote_image_url = "#{EduSetting.get("chandao_server_url")}/file-read-#{img[1]}.json" + tmp_local_image_path = "#{Rails.root}/#{img[1..2].join(".")}" + uri = URI(remote_image_url) + size = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http| + response = http.get(uri.path) + File.open(tmp_local_image_path, 'wb') do |file| + file.write(response.body) + end + end + digest = "#{Digest::MD5.file(tmp_local_image_path).hexdigest}_#{(Time.now.to_f * 1000).to_i}.#{img[2]}" + month_folder = "#{Time.now.year}/#{Time.now.month.to_s.rjust(2, '0')}" + save_path = "#{Rails.root}#{EduSetting.get("attachment_folder")}#{month_folder}" + unless Dir.exists?(save_path) + FileUtils.mkdir_p(save_path) ##不成功这里会抛异常 + end + + local_image_path = File.join(save_path, digest) + FileUtils.mv(tmp_local_image_path, local_image_path) + attachment = Attachment.new + attachment.filename = img[1..2].join(".") + attachment.disk_filename = local_image_path[save_path.size+1, local_image_path.size] + attachment.filesize = size + attachment.content_type = img[2] + attachment.digest = digest + attachment.author_id = user.id + attachment.disk_directory = month_folder + attachment.cloud_url = remote_image_url + attachment.uuid = SecureRandom.uuid + attachment.save + + att_url = "#{Rails.application.config_for(:configuration)['platform_url']}/api/attachments/#{attachment.uuid}" + content.gsub!(img[0], "![](#{att_url})") + end + return content + end + desc "bug数据" # 执行示例 bundle exec rake "import_from_chandao:bugs[企业内部工时管理系统.csv, 3, ceshi_org]" # RAILS_ENV=production bundle exec rake "import_from_chandao:bugs[企业内部工时管理系统.csv, 3, ceshi_org]" @@ -52,7 +91,7 @@ namespace :import_from_chandao do issue.tracker_id = Tracker.first.id issue.priority_id = randd_field_hash['优先级'].to_i issue.subject = randd_field_hash['Bug标题'] - issue.description = randd_field_hash['重现步骤'] + issue.description = trans_content_img(randd_field_hash['重现步骤'].to_s, author) issue.created_on = randd_field_hash['创建日期'].to_time rescue nil issue.updated_on = randd_field_hash['修改日期'].to_time rescue issue.created_on issue.due_date = randd_field_hash['截止日期'].to_time rescue nil @@ -107,7 +146,7 @@ namespace :import_from_chandao do issue.tracker_id = Tracker.first.id issue.priority_id = randd_field_hash['优先级'].to_i issue.subject = randd_field_hash['任务名称'] - issue.description = randd_field_hash['任务描述'] + issue.description = trans_content_img(randd_field_hash['任务描述'].to_s, author) issue.created_on = randd_field_hash['创建日期'].to_time rescue nil issue.updated_on = randd_field_hash['最后修改日期'].to_time rescue issue.created_on issue.time_scale = randd_field_hash['最初预计'].to_i @@ -158,7 +197,7 @@ namespace :import_from_chandao do issue.tracker_id = Tracker.first.id issue.priority_id = randd_field_hash['优先级'].to_i issue.subject = randd_field_hash['需求名称'] - issue.description = randd_field_hash['需求描述'] + issue.description = trans_content_img(randd_field_hash['需求描述'].to_s, author) issue.created_on = randd_field_hash['创建日期'].to_time issue.updated_on = randd_field_hash['最后修改日期'].to_time rescue randd_field_hash['创建日期'].to_time issue.time_scale = randd_field_hash['预计工时'].to_i From f81bd6bffbdc84fb752542b67d4c4f0138feae81 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 12 Sep 2024 09:12:24 +0800 Subject: [PATCH 280/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=9F=90?= =?UTF-8?q?=E4=B8=AA=E7=89=88=E6=9C=AC=E6=97=A0=E6=B3=95=E8=AF=86=E5=88=AB?= =?UTF-8?q?=E5=A4=9A=E6=80=81=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 3 ++- app/models/pm_link.rb | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index d7890e15a..f6dfd39b3 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -144,7 +144,8 @@ class Api::Pm::IssuesController < Api::Pm::BaseController end end p.workbook.add_worksheet(:name => 'link_relations') do |sheet| - links = PmLink.joins(:linkable_issue).where(issues: {pm_project_id: params[:pm_project_id]}) + # links = PmLink.joins(:linkable_issue).where(issues: {pm_project_id: params[:pm_project_id]}) + links = PmLink.find_by_sql("SELECT `pm_links`.* FROM `pm_links` INNER JOIN `issues` ON `issues`.`id` = `pm_links`.`linkable_id` AND `pm_links`.`linkable_type` = 'Issue' WHERE `issues`.`pm_project_id` = #{params[pm_project_id]}") sheet.add_row ["ID", "被关联工作项ID"] links.each do |link| sheet.add_row [link.linkable_id, link.be_linkable_id] diff --git a/app/models/pm_link.rb b/app/models/pm_link.rb index e45578158..d9d9a7893 100644 --- a/app/models/pm_link.rb +++ b/app/models/pm_link.rb @@ -19,8 +19,8 @@ class PmLink < ApplicationRecord belongs_to :linkable, polymorphic: true belongs_to :be_linkable, polymorphic: true - belongs_to :linkable_issue, -> {where(pm_links: {linkable_type: 'Issue'})}, foreign_key: 'linkable_id', class_name: 'Issue' - belongs_to :be_linkable_issue, -> {where(pm_links: {be_linkable_type: 'Issue'})}, foreign_key: 'be_linkable_id', class_name: 'Issue' + # belongs_to :linkable_issue, -> {where(pm_links: {linkable_type: 'Issue'})}, foreign_key: 'linkable_id', class_name: 'Issue' + # belongs_to :be_linkable_issue, -> {where(pm_links: {be_linkable_type: 'Issue'})}, foreign_key: 'be_linkable_id', class_name: 'Issue' def be_linkable be_linkable_type.constantize.find be_linkable_id From 421fba24c247eebb12331df0de81a8900e8d9c8c Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 12 Sep 2024 10:07:46 +0800 Subject: [PATCH 281/294] =?UTF-8?q?=E7=BB=84=E7=BB=87=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=8F=AF=E5=BC=80=E5=90=AFpms?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/organizations/organizations/_detail.json.jbuilder | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/organizations/organizations/_detail.json.jbuilder b/app/views/organizations/organizations/_detail.json.jbuilder index 1968e78c8..8d5cde0bb 100644 --- a/app/views/organizations/organizations/_detail.json.jbuilder +++ b/app/views/organizations/organizations/_detail.json.jbuilder @@ -17,4 +17,5 @@ json.news_content organization.news_content json.memo organization.memo json.news_title organization.news_title json.news_url organization.news_url -json.enabling_cla organization.enabling_cla \ No newline at end of file +json.enabling_cla organization.enabling_cla +json.pms_enable EduSetting.get("pms_enable_organizations").to_s.split(",").include?(organization.login.to_s.downcase) \ No newline at end of file From f6a2883c0007902c93daacb53b955db493c91d94 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 12 Sep 2024 10:10:22 +0800 Subject: [PATCH 282/294] =?UTF-8?q?=E7=BB=84=E7=BB=87=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=8F=AF=E5=BC=80=E5=90=AFpms?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/organizations/organizations/_detail.json.jbuilder | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/organizations/organizations/_detail.json.jbuilder b/app/views/organizations/organizations/_detail.json.jbuilder index 1968e78c8..8d5cde0bb 100644 --- a/app/views/organizations/organizations/_detail.json.jbuilder +++ b/app/views/organizations/organizations/_detail.json.jbuilder @@ -17,4 +17,5 @@ json.news_content organization.news_content json.memo organization.memo json.news_title organization.news_title json.news_url organization.news_url -json.enabling_cla organization.enabling_cla \ No newline at end of file +json.enabling_cla organization.enabling_cla +json.pms_enable EduSetting.get("pms_enable_organizations").to_s.split(",").include?(organization.login.to_s.downcase) \ No newline at end of file From fbbfab7a31f8ee675caab75b4028e7bcdb481c59 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 12 Sep 2024 12:01:11 +0800 Subject: [PATCH 283/294] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E9=A1=B9=E5=88=86=E5=B8=83=E7=A7=BB=E9=99=A4=E5=B7=B2?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E7=9A=84=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/projects_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index b70bd7240..506df0c10 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -60,6 +60,7 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController type_status = @issues.group(:pm_issue_type,:status_id).count type_status_data = {} IssueStatus.all.map do |e| + next if e.id == 5 [1,2,3].map{ |type| type_status_data[type] = {} if type_status_data[type].nil? if type_status[[type,e.id]].nil? From 98f2898395b4984a45d76ff2fc2b6444e430bdff Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 12 Sep 2024 13:39:32 +0800 Subject: [PATCH 284/294] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E4=B8=8A=E6=AC=A1=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/projects_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index 506df0c10..8d808bf99 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -60,7 +60,7 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController type_status = @issues.group(:pm_issue_type,:status_id).count type_status_data = {} IssueStatus.all.map do |e| - next if e.id == 5 + # next if e.id == 5 [1,2,3].map{ |type| type_status_data[type] = {} if type_status_data[type].nil? if type_status[[type,e.id]].nil? From a18bc247bb5951f49762074e26037544f5712993 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 11 Jul 2024 16:53:48 +0800 Subject: [PATCH 285/294] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=BB=84=E7=BB=87?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E4=B8=8D=E5=AD=98=E5=9C=A8=E6=97=B6=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/organizations/organizations/_detail.json.jbuilder | 2 +- app/views/projects/banner_recommend.json.jbuilder | 2 +- app/views/projects/index.json.jbuilder | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/organizations/organizations/_detail.json.jbuilder b/app/views/organizations/organizations/_detail.json.jbuilder index 8d5cde0bb..0effd51f4 100644 --- a/app/views/organizations/organizations/_detail.json.jbuilder +++ b/app/views/organizations/organizations/_detail.json.jbuilder @@ -10,7 +10,7 @@ json.max_repo_creation organization.max_repo_creation json.num_projects organization.num_projects json.num_users organization.num_users json.num_teams organization.num_teams -json.avatar_url url_to_avatar(organization) +json.avatar_url url_to_avatar(organization).blank?? User::Avatar.get_letter_avatar_url(organization.login) : url_to_avatar(organization) json.created_at organization.created_on.strftime("%Y-%m-%d") json.news_banner_id organization.news_banner_id json.news_content organization.news_content diff --git a/app/views/projects/banner_recommend.json.jbuilder b/app/views/projects/banner_recommend.json.jbuilder index fe9861f85..312659913 100644 --- a/app/views/projects/banner_recommend.json.jbuilder +++ b/app/views/projects/banner_recommend.json.jbuilder @@ -11,7 +11,7 @@ json.projects do json.name owner.try(:show_real_name) json.type owner.type json.login owner.login - json.image_url url_to_avatar(owner) + json.image_url url_to_avatar(owner).blank?? User::Avatar.get_letter_avatar_url(owner.login) : url_to_avatar(owner) end json.category do diff --git a/app/views/projects/index.json.jbuilder b/app/views/projects/index.json.jbuilder index 7841f4564..eb100c180 100644 --- a/app/views/projects/index.json.jbuilder +++ b/app/views/projects/index.json.jbuilder @@ -30,7 +30,7 @@ json.projects @projects do |project| json.type user.type json.name user.try(:show_real_name) json.login user.login - json.image_url url_to_avatar(user) + json.image_url url_to_avatar(user).blank?? User::Avatar.get_letter_avatar_url(user.login) : url_to_avatar(user) end end From 6a87765f3d9bcf8af2d69d387b6d06c159e23359 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 12 Sep 2024 11:51:09 +0800 Subject: [PATCH 286/294] =?UTF-8?q?=E5=8C=BA=E5=9D=97=E7=A1=AE=E6=9D=83?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=9F=A5=E8=AF=A2token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/project.rb | 71 ++++++++++++++----------- app/queries/blockchain/balance_query.rb | 41 +++++++++----- 2 files changed, 69 insertions(+), 43 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index ba0cab97e..925ecec8e 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -125,20 +125,21 @@ class Project < ApplicationRecord has_many :praise_treads, as: :praise_tread_object, dependent: :destroy has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position" has_one :project_detail, dependent: :destroy + has_many :apply_signatures, dependent: :destroy has_many :project_units, dependent: :destroy has_one :applied_transfer_project,-> { order created_at: :desc }, dependent: :destroy has_many :pinned_projects, dependent: :destroy has_many :has_pinned_users, through: :pinned_projects, source: :owner has_many :webhooks, class_name: "Gitea::Webhook", primary_key: :gpid, foreign_key: :repo_id - has_many :user_trace_tasks, dependent: :destroy + #has_many :user_trace_tasks, dependent: :destroy + has_many :user_trace_tasks, dependent: :destroy has_many :project_invite_links, dependent: :destroy - has_many :project_topic_ralates, dependent: :destroy + has_many :project_topic_ralates, dependent: :destroy has_many :project_topics, through: :project_topic_ralates has_many :commit_logs, dependent: :destroy has_many :daily_project_statistics, dependent: :destroy has_one :project_dataset, dependent: :destroy has_many :sync_repositories, dependent: :destroy - has_many :home_top_settings, as: :top, dependent: :destroy after_create :incre_user_statistic, :incre_platform_statistic after_save :check_project_members before_save :set_invite_code, :reset_unmember_followed, :set_recommend_and_is_pinned, :reset_cache_data @@ -149,6 +150,12 @@ class Project < ApplicationRecord scope :recommend, -> { visible.project_statics_select.where(recommend: true) } scope :pinned, -> {where(is_pinned: true)} + scope :like, lambda { |keywords| + # 表情处理 + keywords = keywords.to_s.each_char.select { |c| c.bytes.first < 240 }.join('') + sql = "name LIKE :search OR identifier LIKE :search" + where(sql, :search => "%#{keywords.strip}%") unless keywords.blank? + } delegate :content, to: :project_detail, allow_nil: true delegate :name, to: :license, prefix: true, allow_nil: true @@ -245,11 +252,11 @@ class Project < ApplicationRecord def set_recommend_and_is_pinned self.recommend = self.recommend_index.zero? ? false : true # 私有项目不允许设置精选和推荐 - unless self.is_public - self.recommend = false - self.recommend_index = 0 - self.is_pinned = false - end + # unless self.is_public + # self.recommend = false + # self.recommend_index = 0 + # self.is_pinned = false + # end end def self.search_project(search) @@ -393,11 +400,13 @@ class Project < ApplicationRecord user = Owner.find_by_login namespace_path user = User.new(login: namespace_path) if user.nil? + project = user&.projects&.find_by(identifier: identifier) || Project.find_by(identifier: "#{namespace_path}/#{identifier}") + user = User.new(login: namespace_path) if user.nil? if identifier.end_with?('.json') project = user&.projects&.find_by(identifier: identifier) || Project.find_by(identifier: "#{namespace_path}/#{identifier}") identifier = identifier.sub(/.*\K.json/, '') project = user&.projects&.find_by(identifier: identifier) || Project.find_by(identifier: "#{namespace_path}/#{identifier}") - else + else project = user&.projects&.find_by(identifier: identifier) || Project.find_by(identifier: "#{namespace_path}/#{identifier}") end return nil if project.blank? @@ -444,36 +453,33 @@ class Project < ApplicationRecord end def get_last_project_issues_index - last_issue = self.issues.issue_issue.last + 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) + $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) + $redis_cache.hdel("issue_cache_delete_count", self.id) end - def open_portrait - EduSetting.get("open_portrait_projects").present? ? EduSetting.get("open_portrait_projects").split(",").include?(self.id.to_s) : false + def actionable + return false if EduSetting.get("project_user_actionable").nil? + return EduSetting.get("project_user_actionable").split(",").include?(self.owner&.login) end - def has_pull_request(branch_name) - return true if self.pull_requests.opening.where(head: branch_name).present? || self.pull_requests.opening.where(base: branch_name).present? - if self.forked_from_project_id.present? - return true if self.fork_project.pull_requests.opening.where(head: branch_name).present? || self.fork_project.pull_requests.opening.where(base: branch_name).present? - end - - return false + def is_need_apply + return false if EduSetting.get("project_need_apply").nil? + return EduSetting.get("project_need_apply").split(",").include?(self.id.to_s) end - def self.mindspore_contributors + def self.mindspore_contributors cache_result = $redis_cache.get("ProjectMindsporeContributors") - if cache_result.nil? + if cache_result.nil? contributors = [] file = File.open('public/mindspore_authors', 'r') file.each_line do |l| @@ -481,12 +487,12 @@ class Project < ApplicationRecord email = itemArray[0] username = itemArray[1] commits = itemArray[2].to_i - user = User.find_by(login: username, mail: email) - user = User.find_by(login: username) if user.nil? + user = User.find_by(login: username, mail: email) + user = User.find_by(login: username) if user.nil? user = User.find_by(mail: email) if user.nil? # next if user.nil? search_contributor = contributors.select{|con| con["id"]==user.id}[0] - if search_contributor.present? + if search_contributor.present? search_contributor["contributions"] += commits else contributors << {contributions: commits, name: username, login: username, email: email, id: user&.id}.stringify_keys @@ -497,10 +503,15 @@ class Project < ApplicationRecord $redis_cache.set("ProjectMindsporeContributors", contributors.to_json) return contributors - else + else return JSON.parse(cache_result) end end + + def full_url + Rails.application.config_for(:configuration)['platform_url'].to_s + '/' + self.owner&.try(:login).to_s + '/' + self.identifier.to_s + end + def to_builder Jbuilder.new do |project| project.id self.id @@ -509,9 +520,9 @@ class Project < ApplicationRecord project.description Nokogiri::HTML(self.description).text project.visits self.visits project.praises_count self.praises_count.to_i - project.watchers_count self.watchers_count.to_i - project.issues_count self.issues_count.to_i - project.pull_requests_count self.pull_requests_count.to_i + project.watchers_count self.watchers_count.to_i + project.issues_count self.issues_count.to_i + project.pull_requests_count self.pull_requests_count.to_i project.forked_count self.forked_count.to_i project.is_public self.is_public project.mirror_url self.repository&.mirror_url diff --git a/app/queries/blockchain/balance_query.rb b/app/queries/blockchain/balance_query.rb index f2c39c003..045d2fe8a 100644 --- a/app/queries/blockchain/balance_query.rb +++ b/app/queries/blockchain/balance_query.rb @@ -9,24 +9,39 @@ class Blockchain::BalanceQuery < ApplicationQuery def call if is_current_admin_user - token_list, total_count = find_repo_with_token(params["user_id"], (params["page"] || 1), (params["limit"] || 10)) result_list = [] - token_list.each do |t| - project = Project.find_by(id: t['token_name'].to_i) - if project.nil? - result_list << {project: nil, balance: t['balance']} - next + if params[:project_id].present? or params[:keyword].present? + project_ids = params[:project_id].present? ? [params[:project_id]] : Project.where(user_id: params["user_id"]).like(params[:keyword]).ids + project_ids.each do |project_id| + project_balance = find_one_balance(params["user_id"], project_id) + project = Project.find_by(id: project_balance['token_name'].to_i) + if project.present? + owner = User.find_by(id: project.user_id) + if owner.present? + result_list << {project: project, balance: project_balance['balance']} + end + end end - owner = User.find_by(id: project.user_id) - if owner.nil? || project.nil? - else - balance = t['balance'] - result_list << {project: project, balance: balance} + {"status": 0, "projects": result_list, "total_count": result_list.size} + else + token_list, total_count = find_repo_with_token(params["user_id"], (params["page"] || 1), (params["limit"] || 10)) + token_list.each do |t| + project = Project.find_by(id: t['token_name'].to_i) + if project.nil? + result_list << {project: nil, balance: t['balance']} + next + end + owner = User.find_by(id: project.user_id) + if owner.nil? || project.nil? + else + balance = t['balance'] + result_list << {project: project, balance: balance} + end end + {"status": 0, "projects": result_list, "total_count": total_count} end - results = {"status": 0, "projects": result_list, "total_count": total_count} else - results = {"status": 1} # query failed + {"status": 1} # query failed end end end From 1d3bf34da6ae82e5d72a738742e48c36066b1253 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 12 Sep 2024 15:29:44 +0800 Subject: [PATCH 287/294] =?UTF-8?q?=E7=BB=84=E7=BB=87=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=8F=AF=E5=BC=80=E5=90=AFpms?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/organizations/organizations/_detail.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/organizations/organizations/_detail.json.jbuilder b/app/views/organizations/organizations/_detail.json.jbuilder index 0effd51f4..441eceeac 100644 --- a/app/views/organizations/organizations/_detail.json.jbuilder +++ b/app/views/organizations/organizations/_detail.json.jbuilder @@ -18,4 +18,4 @@ json.memo organization.memo json.news_title organization.news_title json.news_url organization.news_url json.enabling_cla organization.enabling_cla -json.pms_enable EduSetting.get("pms_enable_organizations").to_s.split(",").include?(organization.login.to_s.downcase) \ No newline at end of file +json.pms_enable EduSetting.get("pms_enable_organizations").to_s.downcase.split(",").include?(organization.login.to_s.downcase) \ No newline at end of file From a33a26a87e14b25f3a9fc92272d25c397009a9bf Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 12 Sep 2024 15:50:02 +0800 Subject: [PATCH 288/294] =?UTF-8?q?=E5=90=88=E5=B9=B6=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/project.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 925ecec8e..99f87fe30 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -131,7 +131,6 @@ class Project < ApplicationRecord has_many :pinned_projects, dependent: :destroy has_many :has_pinned_users, through: :pinned_projects, source: :owner has_many :webhooks, class_name: "Gitea::Webhook", primary_key: :gpid, foreign_key: :repo_id - #has_many :user_trace_tasks, dependent: :destroy has_many :user_trace_tasks, dependent: :destroy has_many :project_invite_links, dependent: :destroy has_many :project_topic_ralates, dependent: :destroy @@ -140,6 +139,7 @@ class Project < ApplicationRecord has_many :daily_project_statistics, dependent: :destroy has_one :project_dataset, dependent: :destroy has_many :sync_repositories, dependent: :destroy + has_many :home_top_settings, as: :top, dependent: :destroy after_create :incre_user_statistic, :incre_platform_statistic after_save :check_project_members before_save :set_invite_code, :reset_unmember_followed, :set_recommend_and_is_pinned, :reset_cache_data From 1a6d333c1a4aee5ce1782f417e6738598d9f9259 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 12 Sep 2024 16:45:19 +0800 Subject: [PATCH 289/294] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Agemfile=20?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=20loofah=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Gemfile b/Gemfile index c791291a1..442da5fab 100644 --- a/Gemfile +++ b/Gemfile @@ -142,3 +142,5 @@ gem 'doorkeeper' gem 'doorkeeper-jwt' gem 'gitea-client', '~> 1.5.8' + +gem 'loofah', '~> 2.20.0' \ No newline at end of file From 4fbbe88ca9c48fe995bfc0416d7d0d4ce4b8123d Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 12 Sep 2024 17:04:43 +0800 Subject: [PATCH 290/294] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Apms=5Fenable?= =?UTF-8?q?=20=E5=A4=A7=E5=B0=8F=E5=86=99=E6=A8=A1=E7=B3=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/organizations/organizations/_detail.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/organizations/organizations/_detail.json.jbuilder b/app/views/organizations/organizations/_detail.json.jbuilder index 8d5cde0bb..3e23e0ebb 100644 --- a/app/views/organizations/organizations/_detail.json.jbuilder +++ b/app/views/organizations/organizations/_detail.json.jbuilder @@ -18,4 +18,4 @@ json.memo organization.memo json.news_title organization.news_title json.news_url organization.news_url json.enabling_cla organization.enabling_cla -json.pms_enable EduSetting.get("pms_enable_organizations").to_s.split(",").include?(organization.login.to_s.downcase) \ No newline at end of file +json.pms_enable EduSetting.get("pms_enable_organizations").to_s.downcase.split(",").include?(organization.login.to_s.downcase) \ No newline at end of file From 0d1ca7bc49828baaaf04c152ad4ff44ffede8889 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 13 Sep 2024 13:48:26 +0800 Subject: [PATCH 291/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=A4=84?= =?UTF-8?q?=E7=90=86=E7=A6=85=E9=81=93=E5=9B=BE=E7=89=87=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/attachment.rb | 118 ++++++++++++++-------- lib/tasks/import_issues_from_chandao.rake | 45 +++------ 2 files changed, 92 insertions(+), 71 deletions(-) diff --git a/app/models/attachment.rb b/app/models/attachment.rb index a201faa30..330979e82 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -1,44 +1,44 @@ -# == Schema Information -# -# Table name: attachments -# -# id :integer not null, primary key -# container_id :integer -# container_type :string(30) -# filename :string(255) default(""), not null -# disk_filename :string(255) default(""), not null -# filesize :integer default("0"), not null -# content_type :string(255) default("") -# digest :string(60) default(""), not null -# downloads :integer default("0"), not null -# author_id :integer default("0"), not null -# created_on :datetime -# description :text(65535) -# disk_directory :string(255) -# attachtype :integer default("1") -# is_public :integer default("1") -# copy_from :integer -# quotes :integer default("0") -# is_publish :integer default("1") -# publish_time :datetime -# resource_bank_id :integer -# unified_setting :boolean default("1") -# cloud_url :string(255) default("") -# course_second_category_id :integer default("0") -# delay_publish :boolean default("0") -# uuid :string(255) -# -# Indexes -# -# index_attachments_on_author_id (author_id) -# index_attachments_on_container_id_and_container_type (container_id,container_type) -# index_attachments_on_course_second_category_id (course_second_category_id) -# index_attachments_on_created_on (created_on) -# index_attachments_on_is_public (is_public) -# index_attachments_on_quotes (quotes) -# index_attachments_on_uuid (uuid) -# - +# == Schema Information +# +# Table name: attachments +# +# id :integer not null, primary key +# container_id :integer +# container_type :string(30) +# filename :string(255) default(""), not null +# disk_filename :string(255) default(""), not null +# filesize :integer default("0"), not null +# content_type :string(255) default("") +# digest :string(60) default(""), not null +# downloads :integer default("0"), not null +# author_id :integer default("0"), not null +# created_on :datetime +# description :text(65535) +# disk_directory :string(255) +# attachtype :integer default("1") +# is_public :integer default("1") +# copy_from :integer +# quotes :integer default("0") +# is_publish :integer default("1") +# publish_time :datetime +# resource_bank_id :integer +# unified_setting :boolean default("1") +# cloud_url :string(255) default("") +# course_second_category_id :integer default("0") +# delay_publish :boolean default("0") +# uuid :string(255) +# +# Indexes +# +# index_attachments_on_author_id (author_id) +# index_attachments_on_container_id_and_container_type (container_id,container_type) +# index_attachments_on_course_second_category_id (course_second_category_id) +# index_attachments_on_created_on (created_on) +# index_attachments_on_is_public (is_public) +# index_attachments_on_quotes (quotes) +# index_attachments_on_uuid (uuid) +# + @@ -76,6 +76,42 @@ class Attachment < ApplicationRecord DCODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z) + def self.build_from_remote_url(user, name, url, container=nil) + ext = name.split('.')[-1] + tmp_path = "#{Rails.root}/#{name}" + uri = URI(url) + size = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http| + response = http.get(uri.path) + File.open(tmp_path, 'wb') do |file| + file.write(response.body) + end + end + digest = "#{Digest::MD5.file(tmp_path).hexdigest}_#{(Time.now.to_f * 1000).to_i}.#{ext}" + month_folder = "#{Time.now.year}/#{Time.now.month.to_s.rjust(2, '0')}" + save_path = "#{Rails.root}#{EduSetting.get("attachment_folder")}#{month_folder}" + unless Dir.exists?(save_path) + FileUtils.mkdir_p(save_path) ##不成功这里会抛异常 + end + path = File.join(save_path, digest) + FileUtils.mv(tmp_path, path) + attachment = Attachment.new + attachment.filename = name + attachment.disk_filename = path[save_path.size+1, path.size] + attachment.filesize = size + attachment.content_type = 'application/octet-stream' + attachment.digest = digest.split('.')[0] + attachment.author_id = user.id + attachment.disk_directory = month_folder + attachment.cloud_url = url + attachment.uuid = SecureRandom.uuid + attachment.container = container + attachment.save! + + return attachment + rescue + return nil + end + def diskfile File.join(File.join(Rails.root, "files"), disk_directory.to_s, disk_filename.to_s) end diff --git a/lib/tasks/import_issues_from_chandao.rake b/lib/tasks/import_issues_from_chandao.rake index d53c10baf..0a7c34888 100644 --- a/lib/tasks/import_issues_from_chandao.rake +++ b/lib/tasks/import_issues_from_chandao.rake @@ -23,39 +23,24 @@ namespace :import_from_chandao do return nil end + def get_chandao_json(api_url) + url = URI("#{EduSetting.get("chandao_server_url")}#{api_url}") + http = Net::HTTP.new(url.host, url.port); + request = Net::HTTP::Post.new(url) + request["Cookie"] = "zentaosid=#{EduSetting.get("chandao_sid")}" + response = http.request(request) + response.read_body + return JSON.parse(JSON.parse(response.read_body)['data']) + rescue + return {} + end + def trans_content_img(content, user) respace_content_arr = content.to_s.scan(/]*?src=[“.*?“][^>]*?\/?>/).map{|s|[s,s.match(/(\d+\.\w+)/)[0].split(".")[0],s.match(/(\d+\.\w+)/)[0].split(".")[1]]} respace_content_arr.each do |img| remote_image_url = "#{EduSetting.get("chandao_server_url")}/file-read-#{img[1]}.json" - tmp_local_image_path = "#{Rails.root}/#{img[1..2].join(".")}" - uri = URI(remote_image_url) - size = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http| - response = http.get(uri.path) - File.open(tmp_local_image_path, 'wb') do |file| - file.write(response.body) - end - end - digest = "#{Digest::MD5.file(tmp_local_image_path).hexdigest}_#{(Time.now.to_f * 1000).to_i}.#{img[2]}" - month_folder = "#{Time.now.year}/#{Time.now.month.to_s.rjust(2, '0')}" - save_path = "#{Rails.root}#{EduSetting.get("attachment_folder")}#{month_folder}" - unless Dir.exists?(save_path) - FileUtils.mkdir_p(save_path) ##不成功这里会抛异常 - end - - local_image_path = File.join(save_path, digest) - FileUtils.mv(tmp_local_image_path, local_image_path) - attachment = Attachment.new - attachment.filename = img[1..2].join(".") - attachment.disk_filename = local_image_path[save_path.size+1, local_image_path.size] - attachment.filesize = size - attachment.content_type = img[2] - attachment.digest = digest - attachment.author_id = user.id - attachment.disk_directory = month_folder - attachment.cloud_url = remote_image_url - attachment.uuid = SecureRandom.uuid - attachment.save - + attachment = Attachment.build_from_remote_url(user, img[1..2].join("."), remote_image_url) + att_url = "#{Rails.application.config_for(:configuration)['platform_url']}/api/attachments/#{attachment.uuid}" content.gsub!(img[0], "![](#{att_url})") end @@ -89,7 +74,7 @@ namespace :import_from_chandao do issue.project_issues_index = randd_field_hash['Bug编号'].to_i issue.status_id = trans_status(randd_field_hash['Bug状态']) || IssueStatus.first.id issue.tracker_id = Tracker.first.id - issue.priority_id = randd_field_hash['优先级'].to_i + issue.priority_id = randd_field_hash['优先级'].split('P')[-1].to_i rescue 1 issue.subject = randd_field_hash['Bug标题'] issue.description = trans_content_img(randd_field_hash['重现步骤'].to_s, author) issue.created_on = randd_field_hash['创建日期'].to_time rescue nil From cadafb6fe0e90f42faf73c2661a445642b74ad20 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 13 Sep 2024 14:03:58 +0800 Subject: [PATCH 292/294] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=8E=AF=E5=A2=83debug=E7=94=A8=E6=88=B7id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f6ee02bd6..52387cbbd 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -356,7 +356,7 @@ class ApplicationController < ActionController::Base User.current = User.find 8686 elsif params[:debug] == 'admin' logger.info "@@@@@@@@@@@@@@@@@@@@@@ debug mode....." - user = User.find 1 + user = User.find 36480 User.current = user cookies.signed[:user_id] = user.id end From b676462dd71e6033208287776bff9f756ce17119 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 13 Sep 2024 14:29:35 +0800 Subject: [PATCH 293/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Aopen=5Fportr?= =?UTF-8?q?ait=E5=87=BD=E6=95=B0=E4=B8=A2=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/project.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/project.rb b/app/models/project.rb index 093fb8b1a..ecaee3e80 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -468,6 +468,10 @@ class Project < ApplicationRecord $redis_cache.hdel("issue_cache_delete_count", self.id) end + def open_portrait + EduSetting.get("open_portrait_projects").present? ? EduSetting.get("open_portrait_projects").split(",").include?(self.id.to_s) : false + end + def actionable return false if EduSetting.get("project_user_actionable").nil? return EduSetting.get("project_user_actionable").split(",").include?(self.owner&.login) From e2c3de3601da7d6d186d37220b42d65c82ff5687 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 13 Sep 2024 15:00:12 +0800 Subject: [PATCH 294/294] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Ahas=5Fpull?= =?UTF-8?q?=5Frequest=E4=B8=A2=E5=A4=B1=E4=BB=A5=E5=8F=8A=E5=86=97?= =?UTF-8?q?=E4=BD=99=E5=85=B3=E7=B3=BBapply=5Fsignatures=E7=A7=BB=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/project.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index ecaee3e80..b0133eec7 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -126,7 +126,6 @@ class Project < ApplicationRecord has_many :praise_treads, as: :praise_tread_object, dependent: :destroy has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position" has_one :project_detail, dependent: :destroy - has_many :apply_signatures, dependent: :destroy has_many :project_units, dependent: :destroy has_one :applied_transfer_project,-> { order created_at: :desc }, dependent: :destroy has_many :pinned_projects, dependent: :destroy @@ -477,6 +476,15 @@ class Project < ApplicationRecord return EduSetting.get("project_user_actionable").split(",").include?(self.owner&.login) end + def has_pull_request(branch_name) + return true if self.pull_requests.opening.where(head: branch_name).present? || self.pull_requests.opening.where(base: branch_name).present? + if self.forked_from_project_id.present? + return true if self.fork_project.pull_requests.opening.where(head: branch_name).present? || self.fork_project.pull_requests.opening.where(base: branch_name).present? + end + + return false + end + def is_need_apply return false if EduSetting.get("project_need_apply").nil? return EduSetting.get("project_need_apply").split(",").include?(self.id.to_s)