From 18156ffd8d61324d67883fc5a6f96ed8efcb1cbb Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 2 Mar 2023 15:55:46 +0800 Subject: [PATCH 01/42] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E8=AF=B7=E6=B1=82=E5=85=B3=E8=81=94=E7=96=91=E4=BF=AE?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/pull_requests_controller.rb | 48 ++++++++----------- app/models/issue.rb | 2 + app/models/pull_attached_issue.rb | 22 +++++++++ app/models/pull_request.rb | 2 + app/services/pull_requests/create_service.rb | 15 ++++++ ...30302063013_create_pull_attached_issues.rb | 10 ++++ 6 files changed, 71 insertions(+), 28 deletions(-) create mode 100644 app/models/pull_attached_issue.rb create mode 100644 db/migrate/20230302063013_create_pull_attached_issues.rb diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 5a6742037..6f3ca4d34 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -127,6 +127,18 @@ class PullRequestsController < ApplicationController return normal_status(-1, "请输入正确的标记。") end end + if params[:attached_issue_ids].present? + if params[:attached_issue_ids].is_a?(Array) && params[:attached_issue_ids].size > 1 + return normal_status(-1, "最多只能关联一个疑修。") + elsif params[:attached_issue_ids].is_a?(Array) && params[:attached_issue_ids].size == 1 + @pull_request&.pull_attached_issues&.destroy_all + params[:attached_issue_ids].each do |issue| + PullAttachedIssue.create!(issue_id: issue, pull_request_id: @pull_request.id) + end + else + return normal_status(-1, "请输入正确的疑修。") + end + end if params[:status_id].to_i == 5 @issue.issue_times.update_all(end_time: Time.now) end @@ -214,35 +226,15 @@ class PullRequestsController < ApplicationController push_activity_2_blockchain("pull_request_merge", @pull_request) # 查看是否fix了相关issue,如果fix就转账 - if params["fix_issue_id"].nil? || params["fix_issue_id"] == "" - else - issue = Issue.find_by(id: params["fix_issue_id"]) - if issue.nil? - normal_status(-1, "关联issue失败") - raise ActiveRecord::Rollback - else - token_num = issue.blockchain_token_num - token_num = token_num.nil? ? 0 : token_num - owner = User.find_by(login: params["owner"]) - pr = PullRequest.find_by(id: params["pull_request"]["id"]) - if owner.nil? || pr.nil? - normal_status(-1, "关联issue失败") - raise ActiveRecord::Rollback - else - project = Project.find_by(user_id: owner.id, identifier: params["project_id"]) - if project.nil? - normal_status(-1, "关联issue失败") - raise ActiveRecord::Rollback - else - author_id = pr.user_id - if token_num > 0 - Blockchain::FixIssue.call({user_id: author_id.to_s, project_id: project.id.to_s, token_num: token_num}) - end - # update issue to state 5 - issue.update(status_id: 5) - end - end + @pull_request.attached_issues.each do |issue| + token_num = issue.blockchain_token_num + token_num = token_num.nil? ? 0 : token_num + author_id = @pull_request.user_id + if token_num > 0 + Blockchain::FixIssue.call({user_id: author_id.to_s, project_id: project.id.to_s, token_num: token_num}) end + # update issue to state 5 + issue.update(status_id: 5) end # 合并请求下issue处理为关闭 diff --git a/app/models/issue.rb b/app/models/issue.rb index 9c61f3ec3..0fb5291e0 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -79,6 +79,8 @@ class Issue < ApplicationRecord 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 scope :issue_includes, ->{includes(:user)} scope :issue_many_includes, ->{includes(journals: :user)} diff --git a/app/models/pull_attached_issue.rb b/app/models/pull_attached_issue.rb new file mode 100644 index 000000000..c93a95d65 --- /dev/null +++ b/app/models/pull_attached_issue.rb @@ -0,0 +1,22 @@ +# == Schema Information +# +# Table name: pull_attached_issues +# +# id :integer not null, primary key +# pull_request_id :integer +# issue_id :integer +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_pull_attached_issues_on_issue_id (issue_id) +# index_pull_attached_issues_on_pull_request_id (pull_request_id) +# + +class PullAttachedIssue < ApplicationRecord + + belongs_to :pull_request + belongs_to :issue + +end diff --git a/app/models/pull_request.rb b/app/models/pull_request.rb index 270e7dc76..648912f5a 100644 --- a/app/models/pull_request.rb +++ b/app/models/pull_request.rb @@ -44,6 +44,8 @@ class PullRequest < ApplicationRecord has_many :pull_requests_reviewers, dependent: :destroy has_many :reviewers, through: :pull_requests_reviewers has_many :mark_files, dependent: :destroy + has_many :pull_attached_issues, dependent: :destroy + has_many :attached_issues, through: :pull_attached_issues, source: :issue scope :merged_and_closed, ->{where.not(status: 0)} scope :opening, -> {where(status: 0)} diff --git a/app/services/pull_requests/create_service.rb b/app/services/pull_requests/create_service.rb index 258d0e31b..c2c6cfb22 100644 --- a/app/services/pull_requests/create_service.rb +++ b/app/services/pull_requests/create_service.rb @@ -20,6 +20,7 @@ class PullRequests::CreateService < ApplicationService save_tiding! save_project_trend! save_custom_journal_detail! + save_pull_attached_issues! end [pull_request, gitea_pull_request] @@ -111,6 +112,20 @@ class PullRequests::CreateService < ApplicationService end end + def save_pull_attached_issues! + if attached_issue_ids.size > 1 + raise "最多只能关联一个疑修。" + else + attached_issue_ids.each do |issue| + PullAttachedIssue.create!(issue_id: issue, pull_request_id: pull_request&.id) + end + end + end + + def issue_tag_ids + Array(@params[:attached_issue_ids]) + end + def gitea_pull_request @gitea_pull_request ||= create_gitea_pull_request! end diff --git a/db/migrate/20230302063013_create_pull_attached_issues.rb b/db/migrate/20230302063013_create_pull_attached_issues.rb new file mode 100644 index 000000000..c3b4f6528 --- /dev/null +++ b/db/migrate/20230302063013_create_pull_attached_issues.rb @@ -0,0 +1,10 @@ +class CreatePullAttachedIssues < ActiveRecord::Migration[5.2] + def change + create_table :pull_attached_issues do |t| + t.references :pull_request + t.references :issue + + t.timestamps + end + end +end From aba5de8bb883ea7d3c36c75b6c5b8ecffb0c8b1c Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 2 Mar 2023 16:20:35 +0800 Subject: [PATCH 02/42] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E7=96=91?= =?UTF-8?q?=E4=BF=AE=E6=96=B0=E5=A2=9E=E6=82=AC=E8=B5=8F=E9=87=91=E9=A2=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/issues_controller.rb | 2 +- app/services/api/v1/issues/create_service.rb | 5 ++++- app/services/api/v1/issues/list_service.rb | 4 ++-- app/services/api/v1/issues/update_service.rb | 5 ++++- app/views/api/v1/issues/_detail.json.jbuilder | 2 +- app/views/api/v1/issues/_simple_detail.json.jbuilder | 2 +- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/v1/issues_controller.rb b/app/controllers/api/v1/issues_controller.rb index 6f615e498..689d8e520 100644 --- a/app/controllers/api/v1/issues_controller.rb +++ b/app/controllers/api/v1/issues_controller.rb @@ -99,7 +99,7 @@ class Api::V1::IssuesController < Api::V1::BaseController params.permit( :status_id, :priority_id, :milestone_id, :branch_name, :start_date, :due_date, - :subject, :description, + :subject, :description, :blockchain_token_num, :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 30f4a11ef..ae9d45c95 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -4,13 +4,14 @@ 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 + 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 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} def initialize(project, params, current_user = nil) @project = project @@ -23,6 +24,7 @@ class Api::V1::Issues::CreateService < ApplicationService @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] @@ -94,6 +96,7 @@ class Api::V1::Issues::CreateService < ApplicationService 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 diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index fa27f4ee4..7019dc8e4 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -7,7 +7,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: ['issues.created_on', 'issues.updated_on', 'issue_priorities.position'], message: '请输入正确的SortBy'}, allow_blank: true + 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 :current_user, presence: true @@ -68,7 +68,7 @@ class Api::V1::Issues::ListService < ApplicationService issues = issues.where(status_id: status_id) if status_id.present? # keyword - issues = issues.ransack(subject_or_description_cont: keyword).result if keyword.present? + issues = issues.ransack(id_eq: params[: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 diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 9aa9d6bb1..4d3495022 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -4,11 +4,12 @@ class Api::V1::Issues::UpdateService < ApplicationService include Api::V1::Issues::Concerns::Loadable attr_reader :project, :issue, :current_user - attr_reader :status_id, :priority_id, :milestone_id, :branch_name, :start_date, :due_date, :subject, :description + attr_reader :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 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} def initialize(project, issue, params, current_user = nil) @project = project @@ -22,6 +23,7 @@ class Api::V1::Issues::UpdateService < ApplicationService @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] @@ -94,6 +96,7 @@ class Api::V1::Issues::UpdateService < ApplicationService @updated_issue.due_date = due_date unless due_date.nil? @updated_issue.subject = subject if subject.present? @updated_issue.description = description unless description.nil? + @updated_issue.blockchain_token_num = blockchain_token_num unless blockchain_token_num.nil? end def build_assigner_participants diff --git a/app/views/api/v1/issues/_detail.json.jbuilder b/app/views/api/v1/issues/_detail.json.jbuilder index 193357ce1..d1b6352c7 100644 --- a/app/views/api/v1/issues/_detail.json.jbuilder +++ b/app/views/api/v1/issues/_detail.json.jbuilder @@ -1,4 +1,4 @@ -json.(issue, :id, :subject, :project_issues_index, :description, :branch_name, :start_date, :due_date) +json.(issue, :id, :subject, :project_issues_index, :description, :branch_name, :start_date, :due_date, :blockchain_token_num) json.created_at issue.created_on.strftime("%Y-%m-%d %H:%M") json.updated_at issue.updated_on.strftime("%Y-%m-%d %H:%M") json.tags issue.show_issue_tags.each do |tag| diff --git a/app/views/api/v1/issues/_simple_detail.json.jbuilder b/app/views/api/v1/issues/_simple_detail.json.jbuilder index 7e0d6b11f..27424deff 100644 --- a/app/views/api/v1/issues/_simple_detail.json.jbuilder +++ b/app/views/api/v1/issues/_simple_detail.json.jbuilder @@ -1,4 +1,4 @@ -json.(issue, :id, :subject, :project_issues_index) +json.(issue, :id, :subject, :project_issues_index, :blockchain_token_num) json.created_at issue.created_on.strftime("%Y-%m-%d %H:%M") json.updated_at issue.updated_on.strftime("%Y-%m-%d %H:%M") json.tags issue.show_issue_tags.each do |tag| From c9c16aef8d23a4844497629e1cd802e36471dff3 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 2 Mar 2023 17:06:49 +0800 Subject: [PATCH 03/42] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=96=B0?= =?UTF-8?q?=E7=89=88=E7=96=91=E4=BF=AE=E4=B8=8A=E9=93=BE=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/issues_controller.rb | 16 +++++++++------- app/controllers/journals_controller.rb | 2 +- app/controllers/pull_requests_controller.rb | 8 ++++---- app/models/site.rb | 4 ++++ app/services/api/v1/issues/create_service.rb | 12 ++++++++++++ .../api/v1/issues/journals/create_service.rb | 2 ++ .../v1/projects/pulls/journals/create_service.rb | 2 ++ 7 files changed, 34 insertions(+), 12 deletions(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index dfc551e3c..0302bd5b8 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -160,14 +160,16 @@ class IssuesController < ApplicationController # 新增时向grimoirelab推送事件 IssueWebhookJob.set(wait: 5.seconds).perform_later(@issue.id) - # author: zxh - # 扣除发起人的token - if @issue.blockchain_token_num > 0 - Blockchain::CreateIssue.call(user_id: @issue.author_id, project_id: @issue.project_id, token_num: @issue.blockchain_token_num) - end + if Site.has_blockchain? + # author: zxh + # 扣除发起人的token + if @issue.blockchain_token_num > 0 + Blockchain::CreateIssue.call(user_id: @issue.author_id, project_id: @issue.project_id, token_num: @issue.blockchain_token_num) + end - # 调用上链API存证 - push_activity_2_blockchain("issue_create", @issue) + # 调用上链API存证 + push_activity_2_blockchain("issue_create", @issue) + end render json: {status: 0, message: "创建成功", id: @issue.id} else diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rb index ff5e28cc1..a8804a8c6 100644 --- a/app/controllers/journals_controller.rb +++ b/app/controllers/journals_controller.rb @@ -50,7 +50,7 @@ class JournalsController < ApplicationController # author: zxh # 调用上链API - push_activity_2_blockchain("issue_comment_create", journal) + push_activity_2_blockchain("issue_comment_create", journal) if Site.has_blockchain? render :json => { status: 0, message: "评论成功", id: journal.id} else diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 6f3ca4d34..55b8aedf5 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -77,7 +77,7 @@ class PullRequestsController < ApplicationController # author: zxh # 调用上链API - push_activity_2_blockchain("pull_request_create", @pull_request) + push_activity_2_blockchain("pull_request_create", @pull_request) if Site.has_blockchain? else render_error("create pull request error: #{@gitea_pull_request[:status]}") @@ -169,7 +169,7 @@ class PullRequestsController < ApplicationController colsed = PullRequests::CloseService.call(@owner, @repository, @pull_request, current_user) # author: zxh # 调用上链API - push_activity_2_blockchain("pull_request_refuse", @pull_request) + push_activity_2_blockchain("pull_request_refuse", @pull_request) if Site.has_blockchain? if colsed === true @pull_request.project_trends.create!(user: current_user, project: @project,action_type: ProjectTrend::CLOSE) @@ -223,7 +223,7 @@ class PullRequestsController < ApplicationController # author: zxh # 调用上链API - push_activity_2_blockchain("pull_request_merge", @pull_request) + push_activity_2_blockchain("pull_request_merge", @pull_request) if Site.has_blockchain? # 查看是否fix了相关issue,如果fix就转账 @pull_request.attached_issues.each do |issue| @@ -231,7 +231,7 @@ class PullRequestsController < ApplicationController token_num = token_num.nil? ? 0 : token_num author_id = @pull_request.user_id if token_num > 0 - Blockchain::FixIssue.call({user_id: author_id.to_s, project_id: project.id.to_s, token_num: token_num}) + Blockchain::FixIssue.call({user_id: author_id.to_s, project_id: project.id.to_s, token_num: token_num}) if Site.has_blockchain? end # update issue to state 5 issue.update(status_id: 5) diff --git a/app/models/site.rb b/app/models/site.rb index a8b725ef6..097306fb5 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -30,6 +30,10 @@ class Site < ApplicationRecord self.common.where(key: 'notice').present? end + def self.has_blockchain? + self.common.where(key: 'blockchain').present? + end + private def self.set_add_menu! adds= [ diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index ae9d45c95..4b2f658d0 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -59,8 +59,20 @@ class Api::V1::Issues::CreateService < ApplicationService @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? + if @created_issue.blockchain_token_num > 0 + Blockchain::CreateIssue.call(user_id: @created_issue.author_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) + # @信息发送 AtmeService.call(current_user, @atme_receivers, @created_issue) unless receivers_login.blank? diff --git a/app/services/api/v1/issues/journals/create_service.rb b/app/services/api/v1/issues/journals/create_service.rb index dce00349b..9f50311fa 100644 --- a/app/services/api/v1/issues/journals/create_service.rb +++ b/app/services/api/v1/issues/journals/create_service.rb @@ -39,6 +39,8 @@ class Api::V1::Issues::Journals::CreateService < ApplicationService @created_journal.save! @issue.save! + push_activity_2_blockchain("issue_comment_create", @created_journal) if Site.has_blockchain? + # @信息发送 AtmeService.call(current_user, @atme_receivers, @created_journal) unless receivers_login.blank? diff --git a/app/services/api/v1/projects/pulls/journals/create_service.rb b/app/services/api/v1/projects/pulls/journals/create_service.rb index df207771b..c9abca83c 100644 --- a/app/services/api/v1/projects/pulls/journals/create_service.rb +++ b/app/services/api/v1/projects/pulls/journals/create_service.rb @@ -30,6 +30,8 @@ class Api::V1::Projects::Pulls::Journals::CreateService < ApplicationService create_comment_journal end + push_activity_2_blockchain("issue_comment_create", @journal) if Site.has_blockchain? + journal end From 129d2651b2ab6e0c2789d149b1bdedd1c43c4194 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 6 Mar 2023 09:27:05 +0800 Subject: [PATCH 04/42] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E8=AF=B7=E6=B1=82=E8=AF=A6=E6=83=85=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=85=B3=E8=81=94=E7=96=91=E4=BF=AE=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/pull_requests/show.json.jbuilder | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/views/pull_requests/show.json.jbuilder b/app/views/pull_requests/show.json.jbuilder index 27c393de5..7aa0081e9 100644 --- a/app/views/pull_requests/show.json.jbuilder +++ b/app/views/pull_requests/show.json.jbuilder @@ -51,4 +51,8 @@ json.issue do json.issue_tags @issue.get_issue_tags end +json.attached_issues @pull_request.attached_issues.each do |issue| + json.(issue, :id,:subject) +end + json.conflict_files @pull_request.conflict_files From a2916415053dbe2ec9ee35356bdee5da50425a34 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 7 Mar 2023 10:46:17 +0800 Subject: [PATCH 05/42] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=82=AC?= =?UTF-8?q?=E8=B5=8F=E9=87=91=E9=A2=9D=E6=A0=B9=E6=8D=AE=E4=BB=93=E5=BA=93?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=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/_detail.json.jbuilder | 3 ++- app/views/api/v1/issues/_simple_detail.json.jbuilder | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/views/api/v1/issues/_detail.json.jbuilder b/app/views/api/v1/issues/_detail.json.jbuilder index d1b6352c7..83e83d981 100644 --- a/app/views/api/v1/issues/_detail.json.jbuilder +++ b/app/views/api/v1/issues/_detail.json.jbuilder @@ -1,4 +1,5 @@ -json.(issue, :id, :subject, :project_issues_index, :description, :branch_name, :start_date, :due_date, :blockchain_token_num) +json.(issue, :id, :subject, :project_issues_index, :description, :branch_name, :start_date, :due_date) +json.blockchain_token_num issue.project&.use_blockchain ? issue.blockchain_token_num : nil json.created_at issue.created_on.strftime("%Y-%m-%d %H:%M") json.updated_at issue.updated_on.strftime("%Y-%m-%d %H:%M") json.tags issue.show_issue_tags.each do |tag| diff --git a/app/views/api/v1/issues/_simple_detail.json.jbuilder b/app/views/api/v1/issues/_simple_detail.json.jbuilder index 27424deff..4f288ce20 100644 --- a/app/views/api/v1/issues/_simple_detail.json.jbuilder +++ b/app/views/api/v1/issues/_simple_detail.json.jbuilder @@ -1,4 +1,5 @@ -json.(issue, :id, :subject, :project_issues_index, :blockchain_token_num) +json.(issue, :id, :subject, :project_issues_index) +json.blockchain_token_num issue.project&.use_blockchain ? issue.blockchain_token_num : nil json.created_at issue.created_on.strftime("%Y-%m-%d %H:%M") json.updated_at issue.updated_on.strftime("%Y-%m-%d %H:%M") json.tags issue.show_issue_tags.each do |tag| From 3e0df7c1b9ce9d3d04a5bd7a7c6dc48c19335bf5 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 7 Mar 2023 15:38:54 +0800 Subject: [PATCH 06/42] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E4=B8=8A?= =?UTF-8?q?=E9=93=BE=E9=9C=80=E8=A6=81=E9=A1=B9=E7=9B=AE=E5=BC=80=E5=90=AF?= =?UTF-8?q?=E5=8C=BA=E5=9D=97=E9=93=BE=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/issues_controller.rb | 2 +- app/controllers/journals_controller.rb | 2 +- app/controllers/pull_requests_controller.rb | 8 ++++---- app/services/api/v1/issues/create_service.rb | 2 +- app/services/api/v1/issues/journals/create_service.rb | 2 +- .../api/v1/projects/pulls/journals/create_service.rb | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 0302bd5b8..c1f2ea1f0 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -160,7 +160,7 @@ class IssuesController < ApplicationController # 新增时向grimoirelab推送事件 IssueWebhookJob.set(wait: 5.seconds).perform_later(@issue.id) - if Site.has_blockchain? + if Site.has_blockchain? && @project.use_blockchain # author: zxh # 扣除发起人的token if @issue.blockchain_token_num > 0 diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rb index a8804a8c6..834cdbd4e 100644 --- a/app/controllers/journals_controller.rb +++ b/app/controllers/journals_controller.rb @@ -50,7 +50,7 @@ class JournalsController < ApplicationController # author: zxh # 调用上链API - push_activity_2_blockchain("issue_comment_create", journal) if Site.has_blockchain? + push_activity_2_blockchain("issue_comment_create", journal) if Site.has_blockchain? && @project.use_blockchain render :json => { status: 0, message: "评论成功", id: journal.id} else diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 55b8aedf5..d095a02fa 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -77,7 +77,7 @@ class PullRequestsController < ApplicationController # author: zxh # 调用上链API - push_activity_2_blockchain("pull_request_create", @pull_request) if Site.has_blockchain? + push_activity_2_blockchain("pull_request_create", @pull_request) if Site.has_blockchain? && @project.use_blockchain else render_error("create pull request error: #{@gitea_pull_request[:status]}") @@ -169,7 +169,7 @@ class PullRequestsController < ApplicationController colsed = PullRequests::CloseService.call(@owner, @repository, @pull_request, current_user) # author: zxh # 调用上链API - push_activity_2_blockchain("pull_request_refuse", @pull_request) if Site.has_blockchain? + push_activity_2_blockchain("pull_request_refuse", @pull_request) if Site.has_blockchain? && @project.use_blockchain if colsed === true @pull_request.project_trends.create!(user: current_user, project: @project,action_type: ProjectTrend::CLOSE) @@ -223,7 +223,7 @@ class PullRequestsController < ApplicationController # author: zxh # 调用上链API - push_activity_2_blockchain("pull_request_merge", @pull_request) if Site.has_blockchain? + push_activity_2_blockchain("pull_request_merge", @pull_request) if Site.has_blockchain? && @project.use_blockchain # 查看是否fix了相关issue,如果fix就转账 @pull_request.attached_issues.each do |issue| @@ -231,7 +231,7 @@ class PullRequestsController < ApplicationController token_num = token_num.nil? ? 0 : token_num author_id = @pull_request.user_id if token_num > 0 - Blockchain::FixIssue.call({user_id: author_id.to_s, project_id: project.id.to_s, token_num: token_num}) if Site.has_blockchain? + Blockchain::FixIssue.call({user_id: author_id.to_s, project_id: project.id.to_s, token_num: token_num}) if Site.has_blockchain? && @project.use_blockchain end # update issue to state 5 issue.update(status_id: 5) diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index 4b2f658d0..2069b8761 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -60,7 +60,7 @@ class Api::V1::Issues::CreateService < ApplicationService @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? + if Site.has_blockchain? && @project.use_blockchain if @created_issue.blockchain_token_num > 0 Blockchain::CreateIssue.call(user_id: @created_issue.author_id, project_id: @created_issue.project_id, token_num: @created_issue.blockchain_token_num) end diff --git a/app/services/api/v1/issues/journals/create_service.rb b/app/services/api/v1/issues/journals/create_service.rb index 9f50311fa..d3daff1df 100644 --- a/app/services/api/v1/issues/journals/create_service.rb +++ b/app/services/api/v1/issues/journals/create_service.rb @@ -39,7 +39,7 @@ class Api::V1::Issues::Journals::CreateService < ApplicationService @created_journal.save! @issue.save! - push_activity_2_blockchain("issue_comment_create", @created_journal) if Site.has_blockchain? + push_activity_2_blockchain("issue_comment_create", @created_journal) if Site.has_blockchain? && @project.use_blockchain # @信息发送 AtmeService.call(current_user, @atme_receivers, @created_journal) unless receivers_login.blank? diff --git a/app/services/api/v1/projects/pulls/journals/create_service.rb b/app/services/api/v1/projects/pulls/journals/create_service.rb index c9abca83c..051c6777c 100644 --- a/app/services/api/v1/projects/pulls/journals/create_service.rb +++ b/app/services/api/v1/projects/pulls/journals/create_service.rb @@ -30,7 +30,7 @@ class Api::V1::Projects::Pulls::Journals::CreateService < ApplicationService create_comment_journal end - push_activity_2_blockchain("issue_comment_create", @journal) if Site.has_blockchain? + push_activity_2_blockchain("issue_comment_create", @journal) if Site.has_blockchain? && @project.use_blockchain journal end From b44ab1e39e3f9d1dc128a592c37421871a513b6c Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 7 Mar 2023 17:22:00 +0800 Subject: [PATCH 07/42] fix --- config/routes.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/routes.rb b/config/routes.rb index 2a837190f..c544c9198 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -258,6 +258,7 @@ Rails.application.routes.draw do get :fan_users get :hovercard get :hovercard4proj # author: zxh, 获取用户对项目的贡献情况 + get :contribution_perc put :update_image get :get_image end From 75d74f80cacc4d7f6fca1361c65d14b6b0ef2d70 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 7 Mar 2023 17:43:10 +0800 Subject: [PATCH 08/42] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=82=AC?= =?UTF-8?q?=E8=B5=8F=E9=87=91=E9=A2=9D=E5=8F=AF=E4=BB=A5=E4=B8=BA=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/issues/create_service.rb | 2 +- app/services/api/v1/issues/update_service.rb | 2 +- 2 files 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 2069b8761..ddb3b7af5 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -11,7 +11,7 @@ class Api::V1::Issues::CreateService < ApplicationService 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} + validates :blockchain_token_num, numericality: {greater_than: 0}, allow_blank: true def initialize(project, params, current_user = nil) @project = project diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 4d3495022..ddbd67d82 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -9,7 +9,7 @@ class Api::V1::Issues::UpdateService < ApplicationService 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} + validates :blockchain_token_num, numericality: {greater_than: 0}, allow_blank: true def initialize(project, issue, params, current_user = nil) @project = project From 90773483b84937314f373deb4552215e7673036c Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 7 Mar 2023 20:49:08 +0800 Subject: [PATCH 09/42] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E7=BC=BA=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/libs/blockchain.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 app/libs/blockchain.rb diff --git a/app/libs/blockchain.rb b/app/libs/blockchain.rb new file mode 100644 index 000000000..e2c7804aa --- /dev/null +++ b/app/libs/blockchain.rb @@ -0,0 +1,20 @@ +class Blockchain + class << self + def blockchain_config + blockchain_config = {} + + begin + config = Rails.application.config_for(:configuration).symbolize_keys! + blockchain_config = config[:blockchain].symbolize_keys! + raise 'blockchain config missing' if blockchain_config.blank? + rescue => ex + raise ex if Rails.env.production? + + puts %Q{\033[33m [warning] blockchain config or configuration.yml missing, + please add it or execute 'cp config/configuration.yml.example config/configuration.yml' \033[0m} + blockchain_config = {} + end + blockchain_config + end + end +end \ No newline at end of file From 47a8f1707302e0a2fcf1643ba00a6180ce6792a0 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 8 Mar 2023 11:05:24 +0800 Subject: [PATCH 10/42] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E8=BD=AC?= =?UTF-8?q?=E8=B4=A6=E8=AE=B0=E5=BD=95=E4=BD=BF=E7=94=A8json=20builder?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E8=B4=A1=E7=8C=AE=E8=80=85=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E8=B4=A1=E7=8C=AE=E5=8D=A0=E6=AF=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 2 +- app/models/concerns/watchable.rb | 8 +++----- app/queries/blockchain/balance_query.rb | 2 +- app/views/repositories/_contributor.json.jbuilder | 1 + app/views/repositories/contributors.json.jbuilder | 2 +- app/views/users/blockchain_balance.json.jbuilder | 5 +++++ 6 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 app/views/users/blockchain_balance.json.jbuilder diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6aee4b584..1b51e3b12 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -423,7 +423,7 @@ class UsersController < ApplicationController @projects = [] end - render json: { status: results[:status], projects: @projects, total_count: @total_count } + # render json: { status: results[:status], projects: @projects, total_count: @total_count } end # query one balance diff --git a/app/models/concerns/watchable.rb b/app/models/concerns/watchable.rb index 9eb0172d7..dc2b67f67 100644 --- a/app/models/concerns/watchable.rb +++ b/app/models/concerns/watchable.rb @@ -31,11 +31,9 @@ module Watchable following.size end - def contribution_perc - project_identifier = params[:project_identifier] - user_login = params[:id] - @project = Project.find_by_identifier(project_identifier) - @user = User.find_by_login(user_login) + def contribution_perc(project) + @project = project + @user = self def cal_perc(count_user, count_all) (count_user * 1.0 / (count_all + 0.000000001)).round(5) diff --git a/app/queries/blockchain/balance_query.rb b/app/queries/blockchain/balance_query.rb index 669370a54..a1bb76eea 100644 --- a/app/queries/blockchain/balance_query.rb +++ b/app/queries/blockchain/balance_query.rb @@ -20,7 +20,7 @@ class Blockchain::BalanceQuery < ApplicationQuery if owner.nil? || project.nil? else balance = t['balance'] - result_list << [owner, project, balance] + result_list << {project: project, balance: balance} end end results = {"status": 0, "projects": result_list} diff --git a/app/views/repositories/_contributor.json.jbuilder b/app/views/repositories/_contributor.json.jbuilder index 56fa9ce86..2efaa0073 100644 --- a/app/views/repositories/_contributor.json.jbuilder +++ b/app/views/repositories/_contributor.json.jbuilder @@ -13,4 +13,5 @@ else json.type user["type"] json.name user["name"] json.image_url user["avatar_url"] + json.blockchain_perc user.contribution_perc(project) end diff --git a/app/views/repositories/contributors.json.jbuilder b/app/views/repositories/contributors.json.jbuilder index 2fb6abae8..4534de693 100644 --- a/app/views/repositories/contributors.json.jbuilder +++ b/app/views/repositories/contributors.json.jbuilder @@ -1,6 +1,6 @@ total_count = @contributors.size json.list @contributors.each do |contributor| - json.partial! 'contributor', locals: { contributor: contributor } + json.partial! 'contributor', locals: { contributor: contributor, project: @project } end json.total_count total_count diff --git a/app/views/users/blockchain_balance.json.jbuilder b/app/views/users/blockchain_balance.json.jbuilder new file mode 100644 index 000000000..83293cf09 --- /dev/null +++ b/app/views/users/blockchain_balance.json.jbuilder @@ -0,0 +1,5 @@ +json.total_count @total_count +json.projects @projects.each do |p| + json.partial! 'projects/detail', locals: { project: p[:project] } + json.balance p[:balance] +end \ No newline at end of file From b0e117b06569c7893efb8c22a1294e8f722a1258 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 8 Mar 2023 11:22:34 +0800 Subject: [PATCH 11/42] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E5=8D=A0=E6=AF=94=E9=9C=80=E5=A2=9E=E5=8A=A0=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=98=AF=E5=90=A6=E5=BC=80=E5=90=AF=E7=A1=AE=E6=9D=83?= =?UTF-8?q?=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/repositories/_contributor.json.jbuilder | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/views/repositories/_contributor.json.jbuilder b/app/views/repositories/_contributor.json.jbuilder index 2efaa0073..ed8a581a6 100644 --- a/app/views/repositories/_contributor.json.jbuilder +++ b/app/views/repositories/_contributor.json.jbuilder @@ -13,5 +13,8 @@ else json.type user["type"] json.name user["name"] json.image_url user["avatar_url"] - json.blockchain_perc user.contribution_perc(project) + if project.use_blockchain + db_user = User.find_by_id(user["id"]) + json.blockchain_perc db_user.contribution_perc(project) + end end From 70de1136e12204cef9c38681219fe1d9c9d28f2a Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 8 Mar 2023 17:45:54 +0800 Subject: [PATCH 12/42] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E8=BD=AC=E8=B4=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/issues/create_service.rb | 2 +- app/services/application_service.rb | 318 +++++++++++++++++++ 2 files changed, 319 insertions(+), 1 deletion(-) diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index ddb3b7af5..6a10df87c 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -62,7 +62,7 @@ class Api::V1::Issues::CreateService < ApplicationService if Site.has_blockchain? && @project.use_blockchain if @created_issue.blockchain_token_num > 0 - Blockchain::CreateIssue.call(user_id: @created_issue.author_id, project_id: @created_issue.project_id, token_num: @created_issue.blockchain_token_num) + Blockchain::CreateIssue.call({user_id: @created_issue.author_id, project_id: @created_issue.project_id, token_num: @created_issue.blockchain_token_num}) end push_activity_2_blockchain("issue_create", @created_issue) diff --git a/app/services/application_service.rb b/app/services/application_service.rb index df06f3960..259a720fc 100644 --- a/app/services/application_service.rb +++ b/app/services/application_service.rb @@ -102,6 +102,324 @@ class ApplicationService else end end + + def push_activity_2_blockchain(activity_type, model) + if activity_type == "issue_create" + + project_id = model['project_id'] + project = Project.find(project_id) + if project['use_blockchain'] == 0 || project['use_blockchain'] == false + # 无需执行上链操作 + return true + end + + id = model['id'] + + owner_id = project['user_id'] + owner = User.find(owner_id) + ownername = owner['login'] + identifier = project['identifier'] + + author_id = project['user_id'] + author = User.find(author_id) + username = author['login'] + + action = 'opened' + + title = model['subject'] + content = model['description'] + created_at = model['created_on'] + updated_at = model['updated_on'] + + # 调用区块链接口 + params = { + "request-type": "upload issue info", + "issue_id": "gitlink-" + id.to_s, + "repo_id": "gitlink-" + project_id.to_s, + "issue_number": 0, # 暂时不需要改字段 + "reponame": identifier, + "ownername": ownername, + "username": username, + "action": action, + "title": title, + "content": content, + "created_at": created_at, + "updated_at": updated_at + }.to_json + resp_body = Blockchain::InvokeBlockchainApi.call(params) + if resp_body['status'] == 10 + raise Error, resp_body['message'] + elsif resp_body['status'] != 0 + raise Error, "区块链接口请求失败." + end + + elsif activity_type == "issue_comment_create" + issue_comment_id = model['id'] + issue_id = model['journalized_id'] + parent_id = model['parent_id'].nil? ? "" : model['parent_id'] + + issue = Issue.find(issue_id) + issue_classify = issue['issue_classify'] # issue或pull_request + project_id = issue['project_id'] + project = Project.find(project_id) + + if project['use_blockchain'] == 0 || project['use_blockchain'] == false + # 无需执行上链操作 + return + end + + identifier = project['identifier'] + owner_id = project['user_id'] + owner = User.find(owner_id) + ownername = owner['login'] + + author_id = model['user_id'] + author = User.find(author_id) + username = author['login'] + + action = 'created' + + content = model['notes'] + created_at = model['created_on'] + + if issue_classify == "issue" + params = { + "request-type": "upload issue comment info", + "issue_comment_id": "gitlink-" + issue_comment_id.to_s, + "issue_comment_number": 0, # 暂时不需要 + "issue_number": 0, # 暂时不需要 + "issue_id": "gitlink-" + issue_id.to_s, + "repo_id": "gitlink-" + project.id.to_s, + "parent_id": parent_id.to_s, + "reponame": identifier, + "ownername": ownername, + "username": username, + "action": action, + "content": content, + "created_at": created_at, + }.to_json + elsif issue_classify == "pull_request" + params = { + "request-type": "upload pull request comment info", + "pull_request_comment_id": "gitlink-" + issue_comment_id.to_s, + "pull_request_comment_number": 0, # 不考虑该字段 + "pull_request_number": 0, # 不考虑该字段 + "pull_request_id": "gitlink-" + issue_id.to_s, + "parent_id": parent_id.to_s, + "repo_id": "gitlink-" + project.id.to_s, + "reponame": identifier, + "ownername": ownername, + "username": username, + "action": action, + "content": content, + "created_at": created_at, + }.to_json + end + + # 调用区块链接口 + resp_body = Blockchain::InvokeBlockchainApi.call(params) + if resp_body['status'] == 10 + raise Error, resp_body['message'] + elsif resp_body['status'] != 0 + raise Error, "区块链接口请求失败." + end + elsif activity_type == "pull_request_create" + # 调用区块链接口 + project_id = model['project_id'] + project = Project.find(project_id) + if project['use_blockchain'] == 0 || project['use_blockchain'] == false + # 无需执行上链操作 + return + end + + pull_request_id = model['id'] + identifier = project['identifier'] + owner_id = project['user_id'] + owner = User.find(owner_id) + ownername = owner['login'] + + action = 'opened' + + title = model['title'] + content = model['body'] + + source_branch = model['head'] + source_repo_id = model['fork_project_id'].nil? ? project_id : model['fork_project_id'] + + target_branch = model['base'] + target_repo_id = project_id + + author_id = model['user_id'] + author = User.find(author_id) + username = author['login'] + + created_at = model['created_at'] + updated_at = model['updated_at'] + + # 查询pull request对应的commit信息 + commits = Gitea::PullRequest::CommitsService.call(ownername, identifier, model['gitea_number']) + if commits.nil? + raise Error, "区块链接口请求失败" # 获取pr中变更的commit信息失败 + end + commit_shas = [] + commits.each do |c| + commit_shas << c["Sha"] + end + params = { + "request-type": "upload pull request info", + "pull_request_id": "gitlink-" + pull_request_id.to_s, + "pull_request_number": 0, # trustie没有该字段 + "repo_id": "gitlink-" + project_id.to_s, + "ownername": ownername, + "reponame": identifier, + "username": username, + "action": action, + "title": title, + "content": content, + "source_branch": source_branch, + "target_branch": target_branch, + "reviewers": [], # trustie没有该字段 + "commit_shas": commit_shas, + "merge_user": "", # trustie没有该字段 + "created_at": created_at, + "updated_at": updated_at + }.to_json + resp_body = Blockchain::InvokeBlockchainApi.call(params) + if resp_body['status'] == 9 + raise Error, resp_body['message'] + elsif resp_body['status'] != 0 + raise Error, "区块链接口请求失败." + end + elsif activity_type == "pull_request_merge" + # 调用区块链接口 + project_id = model['project_id'] + project = Project.find(project_id) + if project['use_blockchain'] == 0 || project['use_blockchain'] == false + # 无需执行上链操作 + return + end + + pull_request_id = model['id'] + identifier = project['identifier'] + owner_id = project['user_id'] + owner = User.find(owner_id) + ownername = owner['login'] + + action = 'merged' + + created_at = model['created_at'] + updated_at = model['updated_at'] + + # 查询pull request对应的commit信息 + commits = Gitea::PullRequest::CommitsService.call(ownername, identifier, model['gitea_number']) + if commits.nil? + raise Error, "区块链接口请求失败" # 获取pr中变更的commit信息失败 + end + commit_shas = [] + commits.each do |c| + commit_shas << c["Sha"] + end + + # 将pull request相关信息写入链上 + params = { + "request-type": "upload pull request info", + "pull_request_id": "gitlink-" + pull_request_id.to_s, + "pull_request_number": 0, # trustie没有该字段 + "repo_id": "gitlink-" + project_id.to_s, + "ownername": ownername, + "reponame": identifier, + "username": username, + "action": action, + "title": title, + "content": content, + "source_branch": source_branch, + "target_branch": target_branch, + "reviewers": [], # trustie没有该字段 + "commit_shas": commit_shas, + "merge_user": "", # trustie没有该字段 + "created_at": created_at, + "updated_at": updated_at + }.to_json + resp_body = Blockchain::InvokeBlockchainApi.call(params) + if resp_body['status'] == 9 + raise Error, resp_body['message'] + elsif resp_body['status'] != 0 + raise Error, "区块链接口请求失败." + end + + + # 将commit相关信息写入链上 + commit_shas.each do |commit_sha| + commit_diff = Gitea::Commit::DiffService.call(ownername, identifier, commit_sha, owner['gitea_token']) + commit = Gitea::Commit::InfoService.call(ownername, identifier, commit_sha, owner['gitea_token']) + params = { + "request-type": "upload commit info", + "commit_hash": commit_sha, + "repo_id": "gitlink-" + project_id.to_s, + "author": commit['commit']['author']['name'], + "author_email": commit['commit']['author']['email'], + "committer": commit['commit']['committer']['name'], + "committer_email": commit['commit']['committer']['email'], + "author_time": commit['commit']['author']['date'], + "committer_time": commit['commit']['committer']['date'], + "content": commit['commit']['message'], + "commit_diff": commit_diff['Files'].to_s + }.to_json + resp_body = Blockchain::InvokeBlockchainApi.call(params) + if resp_body['status'] == 7 + raise Error, resp_body['message'] + elsif resp_body['status'] != 0 + raise Error, "区块链接口请求失败." + end + end + + elsif activity_type == "pull_request_refuse" + + # 调用区块链接口 + project_id = model['project_id'] + project = Project.find(project_id) + if project['use_blockchain'] == 0 || project['use_blockchain'] == false + # 无需执行上链操作 + return true + end + + pull_request_id = model['id'] + identifier = project['identifier'] + owner_id = project['user_id'] + owner = User.find(owner_id) + ownername = owner['login'] + + action = 'refused' + + # 将pull request相关信息写入链上 + params = { + "request-type": "upload pull request info", + "pull_request_id": "gitlink-" + pull_request_id.to_s, + "pull_request_number": 0, # trustie没有该字段 + "repo_id": "gitlink-" + project_id.to_s, + "ownername": ownername, + "reponame": identifier, + "username": username, + "action": action, + "title": title, + "content": content, + "source_branch": source_branch, + "target_branch": target_branch, + "reviewers": [], # trustie没有该字段 + "commit_shas": commit_shas, + "merge_user": "", # trustie没有该字段 + "created_at": created_at, + "updated_at": updated_at + }.to_json + resp_body = Blockchain::InvokeBlockchainApi.call(params) + if resp_body['status'] == 9 + raise Error, resp_body['message'] + elsif resp_body['status'] != 0 + raise Error, "区块链接口请求失败." + end + end + end + def phone_mail_type value value =~ /^1\d{10}$/ ? 1 : 0 end From bd855ea4ed0e2606bead899bd775a16219065b7c Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 8 Mar 2023 17:59:36 +0800 Subject: [PATCH 13/42] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E8=AF=B7=E6=B1=82=E5=88=97=E8=A1=A8=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=85=B3=E8=81=94issue=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/pull_requests/index.json.jbuilder | 3 +++ app/views/pull_requests/show.json.jbuilder | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/views/pull_requests/index.json.jbuilder b/app/views/pull_requests/index.json.jbuilder index ace52945c..9df36fae7 100644 --- a/app/views/pull_requests/index.json.jbuilder +++ b/app/views/pull_requests/index.json.jbuilder @@ -38,6 +38,9 @@ json.issues do json.version issue.version.try(:name) json.journals_count issue.get_journals_size json.issue_tags issue.get_issue_tags + json.attached_issues pr.attached_issues.each do |issue| + json.(issue, :id, :subject, :project_issues_index) + end end end diff --git a/app/views/pull_requests/show.json.jbuilder b/app/views/pull_requests/show.json.jbuilder index 7aa0081e9..71f0641b6 100644 --- a/app/views/pull_requests/show.json.jbuilder +++ b/app/views/pull_requests/show.json.jbuilder @@ -52,7 +52,7 @@ json.issue do end json.attached_issues @pull_request.attached_issues.each do |issue| - json.(issue, :id,:subject) + json.(issue, :id, :subject, :project_issues_index) end json.conflict_files @pull_request.conflict_files From 9c85fdfeaf181220303b2ace8abff2ebdf8243bd Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 8 Mar 2023 18:11:26 +0800 Subject: [PATCH 14/42] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/projects_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index c904b1743..804e2aa46 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -66,6 +66,7 @@ module ProjectsHelper jianmu_devops: jianmu_devops_code(project, user), jianmu_devops_url: jianmu_devops_url, cloud_ide_saas_url: cloud_ide_saas_url(user), + open_blockchain: Site.has_blockchain? && project.use_blockchain, ignore_id: project.ignore_id }).compact From 43cbb9cf4ff04a7d88c5db5bb1f2e0946ed339bc Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 9 Mar 2023 09:23:49 +0800 Subject: [PATCH 15/42] =?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/v1/issues_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/v1/issues_controller.rb b/app/controllers/api/v1/issues_controller.rb index 689d8e520..9dc94caae 100644 --- a/app/controllers/api/v1/issues_controller.rb +++ b/app/controllers/api/v1/issues_controller.rb @@ -10,7 +10,7 @@ class Api::V1::IssuesController < Api::V1::BaseController @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].pluck(:id, :subject)) + @issues = kaminary_select_paginate(@object_result[:data].select(:id, :subject, :project_issues_index)) else @issues = kaminari_paginate(@object_result[:data]) end From edf60ca0a8b9d5072267de96c6aac349a756885c Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 9 Mar 2023 09:40:32 +0800 Subject: [PATCH 16/42] =?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/v1/issues_controller.rb | 3 ++- app/services/api/v1/issues/list_service.rb | 13 +++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/v1/issues_controller.rb b/app/controllers/api/v1/issues_controller.rb index 9dc94caae..d07807202 100644 --- a/app/controllers/api/v1/issues_controller.rb +++ b/app/controllers/api/v1/issues_controller.rb @@ -10,7 +10,7 @@ class Api::V1::IssuesController < Api::V1::BaseController @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)) + @issues = kaminary_select_paginate(@object_result[:data]) else @issues = kaminari_paginate(@object_result[:data]) end @@ -86,6 +86,7 @@ class Api::V1::IssuesController < Api::V1::BaseController def query_params params.permit( + :only_name, :category, :participant_category, :keyword, :author_id, diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index 7019dc8e4..67bc84c5e 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -1,7 +1,7 @@ class Api::V1::Issues::ListService < ApplicationService include ActiveModel::Model - attr_reader :project, :category, :participant_category, :keyword, :author_id, :issue_tag_ids + attr_reader :project, :only_name, :category, :participant_category, :keyword, :author_id, :issue_tag_ids attr_reader :milestone_id, :assigner_id, :status_id, :sort_by, :sort_direction, :current_user attr_accessor :queried_issues, :total_issues_count, :closed_issues_count, :opened_issues_count @@ -13,6 +13,7 @@ class Api::V1::Issues::ListService < ApplicationService 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] @@ -81,9 +82,13 @@ class Api::V1::Issues::ListService < ApplicationService issues = issues.opened end - scope = issues.includes(:priority, :issue_status, :user, :show_assigners, :show_issue_tags, :version, :comment_journals) - - scope = scope.reorder("#{sort_by} #{sort_direction}").distinct + if only_name.present? + scope = issues.select(:id, :subject, :project_issues_index) + scope = scope.reorder("project_issues_index asc").distinct + else + scope = issues.includes(:priority, :issue_status, :user, :show_assigners, :show_issue_tags, :version, :comment_journals) + scope = scope.reorder("#{sort_by} #{sort_direction}").distinct + end @queried_issues = scope end From 2d7a0ef2e1c9b67795824d56ea929498ac663a33 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 9 Mar 2023 09:54:24 +0800 Subject: [PATCH 17/42] =?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/journals/create_service.rb | 2 +- app/services/pull_requests/create_service.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/api/v1/issues/journals/create_service.rb b/app/services/api/v1/issues/journals/create_service.rb index d3daff1df..31ecc00cd 100644 --- a/app/services/api/v1/issues/journals/create_service.rb +++ b/app/services/api/v1/issues/journals/create_service.rb @@ -39,7 +39,7 @@ class Api::V1::Issues::Journals::CreateService < ApplicationService @created_journal.save! @issue.save! - push_activity_2_blockchain("issue_comment_create", @created_journal) if Site.has_blockchain? && @project.use_blockchain + push_activity_2_blockchain("issue_comment_create", @created_journal) if Site.has_blockchain? && @issue.project&.use_blockchain # @信息发送 AtmeService.call(current_user, @atme_receivers, @created_journal) unless receivers_login.blank? diff --git a/app/services/pull_requests/create_service.rb b/app/services/pull_requests/create_service.rb index c2c6cfb22..2b4767f31 100644 --- a/app/services/pull_requests/create_service.rb +++ b/app/services/pull_requests/create_service.rb @@ -122,7 +122,7 @@ class PullRequests::CreateService < ApplicationService end end - def issue_tag_ids + def attached_issue_ids Array(@params[:attached_issue_ids]) end From 7fc373e25967df5f57133f165aaf51f474f348c0 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 9 Mar 2023 10:35:07 +0800 Subject: [PATCH 18/42] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E8=AF=B7=E6=B1=82=E7=BC=96=E8=BE=91=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=85=B3=E8=81=94issue=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/pull_requests/edit.json.jbuilder | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/views/pull_requests/edit.json.jbuilder b/app/views/pull_requests/edit.json.jbuilder index 683b1961c..08cefcb91 100644 --- a/app/views/pull_requests/edit.json.jbuilder +++ b/app/views/pull_requests/edit.json.jbuilder @@ -12,4 +12,7 @@ json.issue_tag_ids @issue&.issue_tags_value&.split(",") json.commits_count @pull_request.commits_count json.files_count @pull_request.files_count json.comments_count @pull_request.comments_count -json.reviewers @pull_request.reviewers.pluck(:login) \ No newline at end of file +json.reviewers @pull_request.reviewers.pluck(:login) +json.attached_issues @pull_request.attached_issues.each do |issue| + json.(issue, :id, :subject, :project_issues_index) +end From 16df3c409c77e720c97431d5d93f1d60de524dc7 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 9 Mar 2023 11:41:54 +0800 Subject: [PATCH 19/42] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E5=8D=A0=E6=AF=94=E6=98=BE=E7=A4=BA=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E7=A7=BB=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/repositories/_contributor.json.jbuilder | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/views/repositories/_contributor.json.jbuilder b/app/views/repositories/_contributor.json.jbuilder index ed8a581a6..e18173a19 100644 --- a/app/views/repositories/_contributor.json.jbuilder +++ b/app/views/repositories/_contributor.json.jbuilder @@ -13,8 +13,6 @@ else json.type user["type"] json.name user["name"] json.image_url user["avatar_url"] - if project.use_blockchain - db_user = User.find_by_id(user["id"]) - json.blockchain_perc db_user.contribution_perc(project) - end + db_user = User.find_by_id(user["id"]) + json.blockchain_perc db_user.contribution_perc(project) end From c5ad8ff33f001ec1e860775dc7936511501e8b2d Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 9 Mar 2023 11:43:02 +0800 Subject: [PATCH 20/42] =?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/repositories/_contributor.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/repositories/_contributor.json.jbuilder b/app/views/repositories/_contributor.json.jbuilder index e18173a19..d2caa53cd 100644 --- a/app/views/repositories/_contributor.json.jbuilder +++ b/app/views/repositories/_contributor.json.jbuilder @@ -14,5 +14,5 @@ else json.name user["name"] json.image_url user["avatar_url"] db_user = User.find_by_id(user["id"]) - json.blockchain_perc db_user.contribution_perc(project) + json.contribution_perc db_user.contribution_perc(project) end From d7c1ce759583cf0cfc92eea1ef39198f4669b341 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 9 Mar 2023 14:58:32 +0800 Subject: [PATCH 21/42] =?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 | 4 ++-- app/services/api/v1/issues/list_service.rb | 2 +- 2 files 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 6a10df87c..4db9394f8 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -60,8 +60,8 @@ class Api::V1::Issues::CreateService < ApplicationService @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 @created_issue.blockchain_token_num > 0 + 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: @created_issue.author_id, project_id: @created_issue.project_id, token_num: @created_issue.blockchain_token_num}) end diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index 67bc84c5e..faf1c1c31 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -69,7 +69,7 @@ class Api::V1::Issues::ListService < ApplicationService issues = issues.where(status_id: status_id) if status_id.present? # keyword - issues = issues.ransack(id_eq: params[:keyword]).result.or(issues.ransack(subject_or_description_cont: keyword).result) if keyword.present? + issues = issues.ransack(id_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 From 00eda17c2c42144b73b2e4517196cfbb825de31a Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 9 Mar 2023 15:37:38 +0800 Subject: [PATCH 22/42] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E8=AF=B7?= =?UTF-8?q?=E6=B1=82gitea=E6=8E=A5=E5=8F=A3=E9=9C=80=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E7=94=A8=E6=88=B7token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 36 +++++++++++------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f98c3c456..31d56f9e3 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -880,9 +880,9 @@ class ApplicationController < ActionController::Base }.to_json resp_body = Blockchain::InvokeBlockchainApi.call(params) if resp_body['status'] == 10 - raise Error, resp_body['message'] + raise ApplicationService::Error, resp_body['message'] elsif resp_body['status'] != 0 - raise Error, "区块链接口请求失败." + raise ApplicationService::Error, "区块链接口请求失败." end elsif activity_type == "issue_comment_create" @@ -951,9 +951,9 @@ class ApplicationController < ActionController::Base # 调用区块链接口 resp_body = Blockchain::InvokeBlockchainApi.call(params) if resp_body['status'] == 10 - raise Error, resp_body['message'] + raise ApplicationService::Error, resp_body['message'] elsif resp_body['status'] != 0 - raise Error, "区块链接口请求失败." + raise ApplicationService::Error, "区块链接口请求失败." end elsif activity_type == "pull_request_create" # 调用区块链接口 @@ -989,9 +989,9 @@ class ApplicationController < ActionController::Base updated_at = model['updated_at'] # 查询pull request对应的commit信息 - commits = Gitea::PullRequest::CommitsService.call(ownername, identifier, model['gitea_number']) + commits = Gitea::PullRequest::CommitsService.call(ownername, identifier, model['gitea_number'], current_user&.gitea_token) if commits.nil? - raise Error, "区块链接口请求失败" # 获取pr中变更的commit信息失败 + raise ApplicationService::Error, "区块链接口请求失败" # 获取pr中变更的commit信息失败 end commit_shas = [] commits.each do |c| @@ -1018,9 +1018,9 @@ class ApplicationController < ActionController::Base }.to_json resp_body = Blockchain::InvokeBlockchainApi.call(params) if resp_body['status'] == 9 - raise Error, resp_body['message'] + raise ApplicationService::Error, resp_body['message'] elsif resp_body['status'] != 0 - raise Error, "区块链接口请求失败." + raise ApplicationService::Error, "区块链接口请求失败." end elsif activity_type == "pull_request_merge" # 调用区块链接口 @@ -1043,9 +1043,9 @@ class ApplicationController < ActionController::Base updated_at = model['updated_at'] # 查询pull request对应的commit信息 - commits = Gitea::PullRequest::CommitsService.call(ownername, identifier, model['gitea_number']) + commits = Gitea::PullRequest::CommitsService.call(ownername, identifier, model['gitea_number'], current_user&.gitea_token) if commits.nil? - raise Error, "区块链接口请求失败" # 获取pr中变更的commit信息失败 + raise ApplicationService::Error, "区块链接口请求失败" # 获取pr中变更的commit信息失败 end commit_shas = [] commits.each do |c| @@ -1074,16 +1074,16 @@ class ApplicationController < ActionController::Base }.to_json resp_body = Blockchain::InvokeBlockchainApi.call(params) if resp_body['status'] == 9 - raise Error, resp_body['message'] + raise ApplicationService::Error, resp_body['message'] elsif resp_body['status'] != 0 - raise Error, "区块链接口请求失败." + raise ApplicationService::Error, "区块链接口请求失败." end # 将commit相关信息写入链上 commit_shas.each do |commit_sha| - commit_diff = Gitea::Commit::DiffService.call(ownername, identifier, commit_sha, owner['gitea_token']) - commit = Gitea::Commit::InfoService.call(ownername, identifier, commit_sha, owner['gitea_token']) + commit_diff = Gitea::Commit::DiffService.call(ownername, identifier, commit_sha, owner['gitea_token'], current_user&.gitea_token) + commit = Gitea::Commit::InfoService.call(ownername, identifier, commit_sha, owner['gitea_token'], current_user&.gitea_token) params = { "request-type": "upload commit info", "commit_hash": commit_sha, @@ -1099,9 +1099,9 @@ class ApplicationController < ActionController::Base }.to_json resp_body = Blockchain::InvokeBlockchainApi.call(params) if resp_body['status'] == 7 - raise Error, resp_body['message'] + raise ApplicationService::Error, resp_body['message'] elsif resp_body['status'] != 0 - raise Error, "区块链接口请求失败." + raise ApplicationService::Error, "区块链接口请求失败." end end @@ -1145,9 +1145,9 @@ class ApplicationController < ActionController::Base }.to_json resp_body = Blockchain::InvokeBlockchainApi.call(params) if resp_body['status'] == 9 - raise Error, resp_body['message'] + raise ApplicationService::Error, resp_body['message'] elsif resp_body['status'] != 0 - raise Error, "区块链接口请求失败." + raise ApplicationService::Error, "区块链接口请求失败." end end end From 2600eacb348e573fcd8e8c9d52adaa7c86d6707d Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 9 Mar 2023 16:10:23 +0800 Subject: [PATCH 23/42] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=B7=B7?= =?UTF-8?q?=E5=90=88=E6=9F=A5=E8=AF=A2=E5=AD=97=E6=AE=B5=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E9=9B=86=E6=9B=B4=E6=94=B9=E4=BB=A5=E5=8F=8Agitea=20service?= =?UTF-8?q?=E7=BC=BA=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/gitea/commit/diff_service.rb | 40 +++++++++++++++++++ app/services/gitea/commit/info_service.rb | 39 ++++++++++++++++++ ...9080338_change_user_mixin_field_collate.rb | 6 +++ 3 files changed, 85 insertions(+) create mode 100644 app/services/gitea/commit/diff_service.rb create mode 100644 app/services/gitea/commit/info_service.rb create mode 100644 db/migrate/20230309080338_change_user_mixin_field_collate.rb diff --git a/app/services/gitea/commit/diff_service.rb b/app/services/gitea/commit/diff_service.rb new file mode 100644 index 000000000..712302505 --- /dev/null +++ b/app/services/gitea/commit/diff_service.rb @@ -0,0 +1,40 @@ +# get the diff info for the commit +class Gitea::Commit::DiffService < Gitea::ClientService + attr_reader :owner, :repo, :sha, :token + + # GET /repos/{owner}/{repo}/commits/{sha}/diff + # owner: 用户 + # repo: 仓库名称/标识 + # sha: commit唯一标识 + # eg: + # Gitea::Commit::DiffService.call('jasder', 'repo_identifier', 'sha value') + def initialize(owner, repo, sha, token=nil) + @owner = owner + @repo = repo + @sha = sha + @token = token + end + + def call + response = get(url, params) + render_result(response) + end + + private + def params + Hash.new.merge(token: token) + end + + def url + "/repos/#{owner}/#{repo}/commits/#{sha}/diff".freeze + end + + def render_result(response) + case response.status + when 200 + JSON.parse(response.body) + else + nil + end + end +end diff --git a/app/services/gitea/commit/info_service.rb b/app/services/gitea/commit/info_service.rb new file mode 100644 index 000000000..d337071e8 --- /dev/null +++ b/app/services/gitea/commit/info_service.rb @@ -0,0 +1,39 @@ +class Gitea::Commit::InfoService < Gitea::ClientService + attr_reader :owner, :repo, :sha, :token + + # GET /repos/{owner}/{repo}/commits/{sha}/diff + # owner: 用户 + # repo: 仓库名称/标识 + # sha: commit唯一标识 + # eg: + # Gitea::Commit::InfoService.call('jasder', 'repo_identifier', 'sha value', token='gitea token') + def initialize(owner, repo, sha, token=nil) + @owner = owner + @repo = repo + @sha = sha + @token = token + end + + def call + response = get(url, params) + render_result(response) + end + + private + def params + Hash.new.merge(token: token) + end + + def url + "/repos/#{owner}/#{repo}/git/commits/#{sha}".freeze + end + + def render_result(response) + case response.status + when 200 + JSON.parse(response.body) + else + nil + end + end +end \ No newline at end of file diff --git a/db/migrate/20230309080338_change_user_mixin_field_collate.rb b/db/migrate/20230309080338_change_user_mixin_field_collate.rb new file mode 100644 index 000000000..1899d43fe --- /dev/null +++ b/db/migrate/20230309080338_change_user_mixin_field_collate.rb @@ -0,0 +1,6 @@ +class ChangeUserMixinFieldCollate < ActiveRecord::Migration[5.2] + def change + execute("ALTER TABLE `users` MODIFY `login` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;") + execute("ALTER TABLE `users` MODIFY `mail` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;") + end +end From b869226f512f2ae5c4a01605b25f5c24d619ff58 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 9 Mar 2023 16:16:49 +0800 Subject: [PATCH 24/42] =?UTF-8?q?=E7=A7=BB=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20230309080338_change_user_mixin_field_collate.rb | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 db/migrate/20230309080338_change_user_mixin_field_collate.rb diff --git a/db/migrate/20230309080338_change_user_mixin_field_collate.rb b/db/migrate/20230309080338_change_user_mixin_field_collate.rb deleted file mode 100644 index 1899d43fe..000000000 --- a/db/migrate/20230309080338_change_user_mixin_field_collate.rb +++ /dev/null @@ -1,6 +0,0 @@ -class ChangeUserMixinFieldCollate < ActiveRecord::Migration[5.2] - def change - execute("ALTER TABLE `users` MODIFY `login` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;") - execute("ALTER TABLE `users` MODIFY `mail` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;") - end -end From a7e493b8213ac80773a6a3d1e407e25dbc06ea07 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 9 Mar 2023 16:18:56 +0800 Subject: [PATCH 25/42] =?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/application_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 31d56f9e3..ac99c30f5 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1082,8 +1082,8 @@ class ApplicationController < ActionController::Base # 将commit相关信息写入链上 commit_shas.each do |commit_sha| - commit_diff = Gitea::Commit::DiffService.call(ownername, identifier, commit_sha, owner['gitea_token'], current_user&.gitea_token) - commit = Gitea::Commit::InfoService.call(ownername, identifier, commit_sha, owner['gitea_token'], current_user&.gitea_token) + commit_diff = Gitea::Commit::DiffService.call(ownername, identifier, commit_sha, owner['gitea_token']) + commit = Gitea::Commit::InfoService.call(ownername, identifier, commit_sha, owner['gitea_token']) params = { "request-type": "upload commit info", "commit_hash": commit_sha, From d240797c2503bbc93d2415e590604be8fae79ece Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 9 Mar 2023 17:03:15 +0800 Subject: [PATCH 26/42] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E7=96=91?= =?UTF-8?q?=E4=BF=AE=E6=82=AC=E8=B5=8F=E9=87=91=E9=A2=9D=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/pull_requests_controller.rb | 2 +- app/services/api/v1/issues/concerns/checkable.rb | 5 +++++ app/services/api/v1/issues/create_service.rb | 1 + app/services/api/v1/issues/update_service.rb | 1 + 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index d095a02fa..e9db3a487 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -231,7 +231,7 @@ class PullRequestsController < ApplicationController token_num = token_num.nil? ? 0 : token_num author_id = @pull_request.user_id if token_num > 0 - Blockchain::FixIssue.call({user_id: author_id.to_s, project_id: project.id.to_s, token_num: token_num}) if Site.has_blockchain? && @project.use_blockchain + Blockchain::FixIssue.call({user_id: author_id.to_s, project_id: @project.id.to_s, token_num: token_num}) if Site.has_blockchain? && @project.use_blockchain end # update issue to state 5 issue.update(status_id: 5) diff --git a/app/services/api/v1/issues/concerns/checkable.rb b/app/services/api/v1/issues/concerns/checkable.rb index d013c3033..411b1b7ff 100644 --- a/app/services/api/v1/issues/concerns/checkable.rb +++ b/app/services/api/v1/issues/concerns/checkable.rb @@ -45,4 +45,9 @@ module Api::V1::Issues::Concerns::Checkable def check_parent_journal(parent_id) raise ApplicationService::Error, "ParentJournal不存在!" unless Journal.find_by_id(parent_id).present? end + + def check_blockchain_token_num(user_id, project_id, blockchain_token_num) + 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 > left_blockchain_token_num + end end diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index 4db9394f8..91007fbea 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -41,6 +41,7 @@ class Api::V1::Issues::CreateService < ApplicationService 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(project.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? diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index ddbd67d82..3c2600bf3 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -42,6 +42,7 @@ class Api::V1::Issues::UpdateService < ApplicationService 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(project.user_id, project.id, blockchain_token_num) if blockchain_token_num.present? load_assigners(assigner_ids) load_attachments(attachment_ids) load_issue_tags(issue_tag_ids) From 6c71994e3309406e58da0e9fcbfcb82001aedabd Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 9 Mar 2023 18:11:10 +0800 Subject: [PATCH 27/42] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E6=82=AC?= =?UTF-8?q?=E8=B5=8F=E9=87=91=E9=A2=9D=E5=8F=98=E6=9B=B4=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E8=87=B3=E9=93=BE=E4=B8=8A=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?=E5=85=B3=E8=81=94=E7=96=91=E4=BF=AE=E6=96=B0=E5=A2=9E=E6=A0=87?= =?UTF-8?q?=E8=AE=B0=E6=98=AF=E5=90=A6=E8=A7=A3=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/pull_requests_controller.rb | 2 ++ app/models/pull_attached_issue.rb | 1 + app/services/api/v1/issues/concerns/checkable.rb | 4 ++-- app/services/api/v1/issues/update_service.rb | 10 +++++++++- ...20230309095515_add_fixed_to_pull_attached_issues.rb | 5 +++++ 5 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20230309095515_add_fixed_to_pull_attached_issues.rb diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index e9db3a487..47e55af15 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -227,11 +227,13 @@ class PullRequestsController < ApplicationController # 查看是否fix了相关issue,如果fix就转账 @pull_request.attached_issues.each do |issue| + next if PullAttachedIssue.exist?(issue_id: issue.id, fixed: true) token_num = issue.blockchain_token_num token_num = token_num.nil? ? 0 : token_num author_id = @pull_request.user_id if token_num > 0 Blockchain::FixIssue.call({user_id: author_id.to_s, project_id: @project.id.to_s, token_num: token_num}) if Site.has_blockchain? && @project.use_blockchain + PullAttachedIssue.find_by(issue_id: issue.id, pull_request_id: @pull_request.id).update(fixed: true) end # update issue to state 5 issue.update(status_id: 5) diff --git a/app/models/pull_attached_issue.rb b/app/models/pull_attached_issue.rb index c93a95d65..abc6c3448 100644 --- a/app/models/pull_attached_issue.rb +++ b/app/models/pull_attached_issue.rb @@ -7,6 +7,7 @@ # issue_id :integer # created_at :datetime not null # updated_at :datetime not null +# fixed :boolean default("0") # # Indexes # diff --git a/app/services/api/v1/issues/concerns/checkable.rb b/app/services/api/v1/issues/concerns/checkable.rb index 411b1b7ff..cda01ba25 100644 --- a/app/services/api/v1/issues/concerns/checkable.rb +++ b/app/services/api/v1/issues/concerns/checkable.rb @@ -46,8 +46,8 @@ module Api::V1::Issues::Concerns::Checkable raise ApplicationService::Error, "ParentJournal不存在!" unless Journal.find_by_id(parent_id).present? end - def check_blockchain_token_num(user_id, project_id, blockchain_token_num) + def check_blockchain_token_num(user_id, project_id, blockchain_token_num, now_blockchain_token_num=0) 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 > left_blockchain_token_num + raise ApplicationService::Error, "项目Token不足。" if blockchain_token_num.to_i > (left_blockchain_token_num+now_blockchain_token_num).to_i end end diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 3c2600bf3..85190fe95 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -42,7 +42,7 @@ class Api::V1::Issues::UpdateService < ApplicationService 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(project.user_id, project.id, blockchain_token_num) if blockchain_token_num.present? + check_blockchain_token_num(project.user_id, project.id, blockchain_token_num, @issue.blockchain_token_num) if blockchain_token_num.present? load_assigners(assigner_ids) load_attachments(attachment_ids) load_issue_tags(issue_tag_ids) @@ -71,6 +71,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? # @信息发送 AtmeService.call(current_user, @atme_receivers, @issue) unless receivers_login.blank? @@ -134,6 +135,13 @@ class Api::V1::Issues::UpdateService < ApplicationService end end + def build_cirle_blockchain_token + if @updated_issue.previous_changes["blockchain_token_num"].present? + unlock_balance_on_blockchain(@updated_issue.project&.user_id, @updated_issue.project_id, @updated_issue.previous_changes["blockchain_token_num"][0]) + lock_balance_on_blockchain(@updated_issue.project&.user_id, @updated_issue.project_id, @updated_issue.previous_changes["blockchain_token_num"][1]) + 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}) diff --git a/db/migrate/20230309095515_add_fixed_to_pull_attached_issues.rb b/db/migrate/20230309095515_add_fixed_to_pull_attached_issues.rb new file mode 100644 index 000000000..9f9952121 --- /dev/null +++ b/db/migrate/20230309095515_add_fixed_to_pull_attached_issues.rb @@ -0,0 +1,5 @@ +class AddFixedToPullAttachedIssues < ActiveRecord::Migration[5.2] + def change + add_column :pull_attached_issues, :fixed, :boolean, default: false + end +end From 8f680fd7c3b066ae0fff24c0b7d89553b1a392a0 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 9 Mar 2023 18:37:08 +0800 Subject: [PATCH 28/42] =?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/pull_requests_controller.rb | 2 +- app/services/api/v1/issues/update_service.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 47e55af15..12e67ccc2 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -227,7 +227,7 @@ class PullRequestsController < ApplicationController # 查看是否fix了相关issue,如果fix就转账 @pull_request.attached_issues.each do |issue| - next if PullAttachedIssue.exist?(issue_id: issue.id, fixed: true) + next if PullAttachedIssue.exists?(issue_id: issue.id, fixed: true) token_num = issue.blockchain_token_num token_num = token_num.nil? ? 0 : token_num author_id = @pull_request.user_id diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 85190fe95..04db49177 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -42,7 +42,7 @@ class Api::V1::Issues::UpdateService < ApplicationService 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(project.user_id, project.id, blockchain_token_num, @issue.blockchain_token_num) if blockchain_token_num.present? + check_blockchain_token_num(project.user_id, project.id, blockchain_token_num, (@issue.blockchain_token_num || 0)) if blockchain_token_num.present? load_assigners(assigner_ids) load_attachments(attachment_ids) load_issue_tags(issue_tag_ids) @@ -137,8 +137,8 @@ class Api::V1::Issues::UpdateService < ApplicationService def build_cirle_blockchain_token if @updated_issue.previous_changes["blockchain_token_num"].present? - unlock_balance_on_blockchain(@updated_issue.project&.user_id, @updated_issue.project_id, @updated_issue.previous_changes["blockchain_token_num"][0]) - lock_balance_on_blockchain(@updated_issue.project&.user_id, @updated_issue.project_id, @updated_issue.previous_changes["blockchain_token_num"][1]) + unlock_balance_on_blockchain(@updated_issue.project&.user_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.project&.user_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 From 841126c0fc238d0becf4dd2f1eb73b6a164c0488 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 10 Mar 2023 09:22:13 +0800 Subject: [PATCH 29/42] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Atoken=E8=BD=AC?= =?UTF-8?q?=E8=B4=A6=E5=88=97=E8=A1=A8=E6=96=B0=E5=A2=9E=E5=88=86=E9=A1=B5?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 2 +- app/queries/application_query.rb | 10 ++++++---- app/queries/blockchain/balance_query.rb | 4 ++-- app/queries/projects/list_my_query.rb | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 1b51e3b12..35f44b4e2 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -416,7 +416,7 @@ class UsersController < ApplicationController is_current_admin_user = true results = Blockchain::BalanceQuery.call(params, is_current_admin_user) if results[:status] == 0 - @total_count = results[:projects].size + @total_count = results[:total_count] @projects = results[:projects] else @total_count = -1 diff --git a/app/queries/application_query.rb b/app/queries/application_query.rb index fdef1b71d..e2d7c446f 100644 --- a/app/queries/application_query.rb +++ b/app/queries/application_query.rb @@ -8,17 +8,19 @@ class ApplicationQuery end # find all the repos that a user has tokens - def find_repo_with_token(user_id) + def find_repo_with_token(user_id, page=1, limit=10) params = { - "request-type": "query user balance of all repos", - "username": user_id.to_s + "request-type": "query user balance of all repos by page", + "username": user_id.to_s, + "page": page.to_i, + "page_num": limit.to_i }.to_json resp_body = Blockchain::InvokeBlockchainApi.call(params) if resp_body['status'] != 0 raise "区块链接口请求失败." else token_list = resp_body['UserBalanceList'].nil? ? [] : resp_body['UserBalanceList'] - return token_list + return token_list, resp_body['total_count'] end end diff --git a/app/queries/blockchain/balance_query.rb b/app/queries/blockchain/balance_query.rb index a1bb76eea..52a2fa525 100644 --- a/app/queries/blockchain/balance_query.rb +++ b/app/queries/blockchain/balance_query.rb @@ -9,7 +9,7 @@ class Blockchain::BalanceQuery < ApplicationQuery def call if is_current_admin_user - token_list = find_repo_with_token(params["user_id"]) + token_list, total_count = find_repo_with_token(params["user_id"], (params["page"]), (params["limit"])) result_list = [] token_list.each do |t| project = Project.find_by(id: t['token_name'].to_i) @@ -23,7 +23,7 @@ class Blockchain::BalanceQuery < ApplicationQuery result_list << {project: project, balance: balance} end end - results = {"status": 0, "projects": result_list} + results = {"status": 0, "projects": result_list, "total_count": total_count} else results = {"status": 1} # query failed end diff --git a/app/queries/projects/list_my_query.rb b/app/queries/projects/list_my_query.rb index 734956b98..31c17846a 100644 --- a/app/queries/projects/list_my_query.rb +++ b/app/queries/projects/list_my_query.rb @@ -39,7 +39,7 @@ class Projects::ListMyQuery < ApplicationQuery # elsif params[:category].to_s == "private" # projects = projects.is_private.joins(:members).where(members: { user_id: user.id }) elsif params[:category].to_s == "blockchain_token" # 所有钱包中有token的项目有哪些 - token_list = find_repo_with_token(user.id) + token_list, total_count = find_repo_with_token(user.id) project_names = token_list.map { |x| x['token_name'] } projects = projects.where(name: project_names) tokens = token_list.map { |x| x['balance'] } From b8decd92a4aa2e1d4c48d711cc48d9356951b6bc Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 10 Mar 2023 09:34:22 +0800 Subject: [PATCH 30/42] =?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/queries/blockchain/balance_query.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/queries/blockchain/balance_query.rb b/app/queries/blockchain/balance_query.rb index 52a2fa525..65fe96224 100644 --- a/app/queries/blockchain/balance_query.rb +++ b/app/queries/blockchain/balance_query.rb @@ -9,7 +9,7 @@ class Blockchain::BalanceQuery < ApplicationQuery def call if is_current_admin_user - token_list, total_count = find_repo_with_token(params["user_id"], (params["page"]), (params["limit"])) + 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) From 2d0020003675f8a7c8e50a0cc968f828a81396ca Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 10 Mar 2023 10:01:35 +0800 Subject: [PATCH 31/42] =?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/queries/blockchain/balance_query.rb | 1 + app/views/users/blockchain_balance.json.jbuilder | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/queries/blockchain/balance_query.rb b/app/queries/blockchain/balance_query.rb index 65fe96224..f2c39c003 100644 --- a/app/queries/blockchain/balance_query.rb +++ b/app/queries/blockchain/balance_query.rb @@ -14,6 +14,7 @@ class Blockchain::BalanceQuery < ApplicationQuery 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) diff --git a/app/views/users/blockchain_balance.json.jbuilder b/app/views/users/blockchain_balance.json.jbuilder index 83293cf09..9216733c2 100644 --- a/app/views/users/blockchain_balance.json.jbuilder +++ b/app/views/users/blockchain_balance.json.jbuilder @@ -1,5 +1,7 @@ json.total_count @total_count json.projects @projects.each do |p| - json.partial! 'projects/detail', locals: { project: p[:project] } + if p[:project].present? + json.partial! 'projects/detail', locals: { project: p[:project] } + end json.balance p[:balance] end \ No newline at end of file From 633b0ff08042be6c170adc676383a189654c40c4 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 10 Mar 2023 11:15:16 +0800 Subject: [PATCH 32/42] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E7=96=91=E4=BF=AE=E9=9C=80=E8=A6=81=E4=B8=8A=E9=93=BE?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E7=94=A8=E6=88=B7=E5=88=9D=E5=A7=8Btoken?= =?UTF-8?q?=E4=B8=8D=E4=BD=BF=E7=94=A8=E7=99=BE=E5=88=86=E6=AF=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/issues/delete_service.rb | 4 ++++ app/services/application_service.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/services/api/v1/issues/delete_service.rb b/app/services/api/v1/issues/delete_service.rb index a34fdced6..4c4a4b828 100644 --- a/app/services/api/v1/issues/delete_service.rb +++ b/app/services/api/v1/issues/delete_service.rb @@ -19,6 +19,10 @@ class Api::V1::Issues::DeleteService < ApplicationService project.incre_project_issue_cache_delete_count + if Site.has_blockchain? && @project.use_blockchain + unlock_balance_on_blockchain(@project.user_id.to_s, @project.id.to_s, @issue.blockchain_token_num.to_i) + end + if Site.has_notice_menu? SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, @issue&.subject, @issue.assigners.pluck(:id), @issue.author_id) end diff --git a/app/services/application_service.rb b/app/services/application_service.rb index 259a720fc..de9842f9d 100644 --- a/app/services/application_service.rb +++ b/app/services/application_service.rb @@ -33,7 +33,7 @@ class ApplicationService username = params['user_id'].to_s token_name = project.id.to_s total_supply = params['blockchain_token_all'].to_i - token_balance = [[username, (total_supply * params['blockchain_init_token'].to_i / 100).to_i]] + token_balance = [[username, params['blockchain_init_token'].to_i]] params = { "request-type": "create repo", From d4dab409a70e11ecf325dca30cd883575ad1d0fe Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 10 Mar 2023 11:15:43 +0800 Subject: [PATCH 33/42] =?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/delete_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/api/v1/issues/delete_service.rb b/app/services/api/v1/issues/delete_service.rb index 4c4a4b828..56fbc3edb 100644 --- a/app/services/api/v1/issues/delete_service.rb +++ b/app/services/api/v1/issues/delete_service.rb @@ -20,7 +20,7 @@ class Api::V1::Issues::DeleteService < ApplicationService project.incre_project_issue_cache_delete_count if Site.has_blockchain? && @project.use_blockchain - unlock_balance_on_blockchain(@project.user_id.to_s, @project.id.to_s, @issue.blockchain_token_num.to_i) + unlock_balance_on_blockchain(@project.user_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? From 582f364b16b18beb1347fbdd0959db3440a55ef4 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 10 Mar 2023 11:40:33 +0800 Subject: [PATCH 34/42] =?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/forms/base_form.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/forms/base_form.rb b/app/forms/base_form.rb index db745e8d8..44b5109c3 100644 --- a/app/forms/base_form.rb +++ b/app/forms/base_form.rb @@ -35,7 +35,7 @@ class BaseForm end def check_blockchain_init_token(blockchain_init_token) - raise "请正确填写项目创始人token占比." if (Float(blockchain_init_token) rescue false) == false or blockchain_init_token.to_i < 0 or blockchain_init_token.to_i > 100 or Float(blockchain_init_token) != blockchain_init_token.to_i + raise "请正确填写项目创始人token占比." if (Float(blockchain_init_token) rescue false) == false or blockchain_init_token.to_i < 0 or Float(blockchain_init_token) != blockchain_init_token.to_i end def check_reversed_keyword(repository_name) From 92c4f87d5ba6b66a7b888f0e7b91f9ccf17d19ae Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 10 Mar 2023 11:50:47 +0800 Subject: [PATCH 35/42] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E5=85=B3=E8=81=94=E7=96=91=E4=BF=AE=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/pull_requests_controller.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 12e67ccc2..5401c96f0 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -236,6 +236,9 @@ class PullRequestsController < ApplicationController PullAttachedIssue.find_by(issue_id: issue.id, pull_request_id: @pull_request.id).update(fixed: true) end # update issue to state 5 + issue.issue_participants.create!({participant_type: "edited", participant_id: current_user.id}) unless issue.issue_participants.exists?(participant_type: "edited", participant_id: current_user.id) + journal = issue.journals.create!({user_id: current_user.id}) + journal.journal_details.create!({property: "attr", prop_key: "status_id", old_value: issue.status_id, value: 5}) issue.update(status_id: 5) end From dae37155948937d65a00b47c6ff1558a2085835a Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 10 Mar 2023 14:48:37 +0800 Subject: [PATCH 36/42] =?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 +- app/services/api/v1/issues/update_service.rb | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index 91007fbea..821ad2787 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -63,7 +63,7 @@ class Api::V1::Issues::CreateService < ApplicationService 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: @created_issue.author_id, project_id: @created_issue.project_id, token_num: @created_issue.blockchain_token_num}) + 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) diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 04db49177..2a377d4fb 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -90,6 +90,9 @@ class Api::V1::Issues::UpdateService < ApplicationService 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? @@ -98,7 +101,6 @@ class Api::V1::Issues::UpdateService < ApplicationService @updated_issue.due_date = due_date unless due_date.nil? @updated_issue.subject = subject if subject.present? @updated_issue.description = description unless description.nil? - @updated_issue.blockchain_token_num = blockchain_token_num unless blockchain_token_num.nil? end def build_assigner_participants @@ -137,8 +139,8 @@ class Api::V1::Issues::UpdateService < ApplicationService def build_cirle_blockchain_token if @updated_issue.previous_changes["blockchain_token_num"].present? - unlock_balance_on_blockchain(@updated_issue.project&.user_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.project&.user_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? + 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 From 9a8bbc2d03221c499ca8ac106e47031b6102a633 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 10 Mar 2023 14:58:16 +0800 Subject: [PATCH 37/42] fix --- app/services/api/v1/issues/create_service.rb | 2 +- app/services/api/v1/issues/update_service.rb | 2 +- app/views/api/v1/issues/_detail.json.jbuilder | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index 821ad2787..41b8ff64f 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -41,7 +41,7 @@ class Api::V1::Issues::CreateService < ApplicationService 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(project.user_id, project.id, blockchain_token_num) if blockchain_token_num.present? + 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? diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 2a377d4fb..8a89bcf4f 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -42,7 +42,7 @@ class Api::V1::Issues::UpdateService < ApplicationService 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(project.user_id, project.id, blockchain_token_num, (@issue.blockchain_token_num || 0)) if blockchain_token_num.present? + 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) diff --git a/app/views/api/v1/issues/_detail.json.jbuilder b/app/views/api/v1/issues/_detail.json.jbuilder index 83e83d981..265591ff1 100644 --- a/app/views/api/v1/issues/_detail.json.jbuilder +++ b/app/views/api/v1/issues/_detail.json.jbuilder @@ -43,4 +43,5 @@ json.comment_journals_count issue.comment_journals.size json.operate_journals_count issue.operate_journals.size json.attachments issue.attachments.each do |attachment| json.partial! "api/v1/attachments/simple_detail", locals: {attachment: attachment} -end \ No newline at end of file +end +json.pull_fixed issue.pull_attached_issues.fixed.present? \ No newline at end of file From 3858d9c482d2b26371d032c8a226c4e8e3051f07 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 10 Mar 2023 15:08:05 +0800 Subject: [PATCH 38/42] fix --- app/services/api/v1/issues/delete_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/api/v1/issues/delete_service.rb b/app/services/api/v1/issues/delete_service.rb index 56fbc3edb..b62733181 100644 --- a/app/services/api/v1/issues/delete_service.rb +++ b/app/services/api/v1/issues/delete_service.rb @@ -20,7 +20,7 @@ class Api::V1::Issues::DeleteService < ApplicationService project.incre_project_issue_cache_delete_count if Site.has_blockchain? && @project.use_blockchain - unlock_balance_on_blockchain(@project.user_id.to_s, @project.id.to_s, @issue.blockchain_token_num.to_i) if @issue.blockchain_token_num.present? + 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? From 01b80619e479b810a716032432913bb6c35a362d Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 10 Mar 2023 15:48:41 +0800 Subject: [PATCH 39/42] fix --- 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 cda01ba25..b19c245ed 100644 --- a/app/services/api/v1/issues/concerns/checkable.rb +++ b/app/services/api/v1/issues/concerns/checkable.rb @@ -48,6 +48,6 @@ module Api::V1::Issues::Concerns::Checkable def check_blockchain_token_num(user_id, project_id, blockchain_token_num, now_blockchain_token_num=0) 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 + raise ApplicationService::Error, "用户Token不足。" if blockchain_token_num.to_i > (left_blockchain_token_num+now_blockchain_token_num).to_i end end From e9e970ca20e1d40bc7a461f536b566bea5f00368 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 10 Mar 2023 16:02:54 +0800 Subject: [PATCH 40/42] fix --- 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 265591ff1..712e7a960 100644 --- a/app/views/api/v1/issues/_detail.json.jbuilder +++ b/app/views/api/v1/issues/_detail.json.jbuilder @@ -44,4 +44,4 @@ 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.fixed.present? \ No newline at end of file +json.pull_fixed issue.pull_attached_issues.where(fixed: true).present? \ No newline at end of file From 80b42f56d5a8671872d94e40f27ed4f55d0ef175 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 10 Mar 2023 18:01:53 +0800 Subject: [PATCH 41/42] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E8=80=85=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/repositories/_contributor.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/repositories/_contributor.json.jbuilder b/app/views/repositories/_contributor.json.jbuilder index d2caa53cd..bd1a037f7 100644 --- a/app/views/repositories/_contributor.json.jbuilder +++ b/app/views/repositories/_contributor.json.jbuilder @@ -14,5 +14,5 @@ else json.name user["name"] json.image_url user["avatar_url"] db_user = User.find_by_id(user["id"]) - json.contribution_perc db_user.contribution_perc(project) + json.contribution_perc db_user.contribution_perc(project) if db_user.present? end From 9c5d1e29007448c81ec2a6ed10de39a34ed94013 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 10 Mar 2023 18:09:17 +0800 Subject: [PATCH 42/42] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E6=97=A5=E5=BF=97=E5=85=BC=E5=AE=B9=E6=97=A7=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=B4=9F=E8=B4=A3=E4=BA=BA=E6=8C=87=E6=B4=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/journal.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/journal.rb b/app/models/journal.rb index a789f28cd..74b26b26e 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -121,6 +121,10 @@ class Journal < ApplicationRecord old_value = detail.old_value new_value = detail.value content += "结束日期" + when 'assigned_to_id' + old_value = User.find_by_id(detail.old_value)&.nickname + new_value = User.find_by_id(detail.value)&.nickname + content += "负责人" end if old_value.nil? || old_value.blank? content += "设置为#{new_value}"