From 587facfb3d98fc68dfeb9320f7b5200fe63d3834 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 7 Feb 2023 17:12:43 +0800 Subject: [PATCH 001/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E4=BA=BA=E5=92=8C=E7=8A=B6=E6=80=81=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/base_controller.rb | 9 +++++++++ app/controllers/api/v1/issues/authors_controller.rb | 9 +++++++++ app/controllers/api/v1/issues/statues_controller.rb | 10 ++++++++++ .../{projects => }/issues/_simple_detail.json.jbuilder | 0 app/views/api/v1/issues/authors/index.json.jbuilder | 4 ++++ app/views/api/v1/issues/statues/index.json.jbuilder | 4 ++++ config/routes/api.rb | 8 +++++++- 7 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 app/controllers/api/v1/issues/authors_controller.rb create mode 100644 app/controllers/api/v1/issues/statues_controller.rb rename app/views/api/v1/{projects => }/issues/_simple_detail.json.jbuilder (100%) create mode 100644 app/views/api/v1/issues/authors/index.json.jbuilder create mode 100644 app/views/api/v1/issues/statues/index.json.jbuilder diff --git a/app/controllers/api/v1/base_controller.rb b/app/controllers/api/v1/base_controller.rb index b937d798e..771adcc05 100644 --- a/app/controllers/api/v1/base_controller.rb +++ b/app/controllers/api/v1/base_controller.rb @@ -20,10 +20,19 @@ class Api::V1::BaseController < ApplicationController # User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token # end # end + + def kaminary_select_paginate(relation) + limit = params[:limit] || params[:per_page] + limit = (limit.to_i.zero? || limit.to_i > 100) ? 100 : limit.to_i + page = params[:page].to_i.zero? ? 1 : params[:page].to_i + + relation.page(page).per(limit) + end def limit params.fetch(:limit, 15) end + def page params.fetch(:page, 1) end diff --git a/app/controllers/api/v1/issues/authors_controller.rb b/app/controllers/api/v1/issues/authors_controller.rb new file mode 100644 index 000000000..8c7a4f7e6 --- /dev/null +++ b/app/controllers/api/v1/issues/authors_controller.rb @@ -0,0 +1,9 @@ +class Api::V1::Issues::AuthorsController < Api::V1::BaseController + before_action :require_public_and_member_above, only: [:index] + + # 发布人列表 + def index + @authors = User.joins(issues: :project).where(projects: {id: @project&.id}) + @authors = kaminary_select_paginate(@authors) + end +end \ No newline at end of file diff --git a/app/controllers/api/v1/issues/statues_controller.rb b/app/controllers/api/v1/issues/statues_controller.rb new file mode 100644 index 000000000..0e9eff43f --- /dev/null +++ b/app/controllers/api/v1/issues/statues_controller.rb @@ -0,0 +1,10 @@ +class Api::V1::Issues::StatuesController < Api::V1::BaseController + + before_action :require_public_and_member_above, only: [:index] + + # 状态列表 + def index + @statues = IssueStatus.order("position asc") + @statues = kaminary_select_paginate(@statues) + end +end \ No newline at end of file diff --git a/app/views/api/v1/projects/issues/_simple_detail.json.jbuilder b/app/views/api/v1/issues/_simple_detail.json.jbuilder similarity index 100% rename from app/views/api/v1/projects/issues/_simple_detail.json.jbuilder rename to app/views/api/v1/issues/_simple_detail.json.jbuilder diff --git a/app/views/api/v1/issues/authors/index.json.jbuilder b/app/views/api/v1/issues/authors/index.json.jbuilder new file mode 100644 index 000000000..dd1a4174a --- /dev/null +++ b/app/views/api/v1/issues/authors/index.json.jbuilder @@ -0,0 +1,4 @@ +json.total_count @authors.total_count +json.authors @authors.each do |author| + json.partial! 'api/v1/users/simple_user', locals: { user: author} +end \ No newline at end of file diff --git a/app/views/api/v1/issues/statues/index.json.jbuilder b/app/views/api/v1/issues/statues/index.json.jbuilder new file mode 100644 index 000000000..2cc91fb52 --- /dev/null +++ b/app/views/api/v1/issues/statues/index.json.jbuilder @@ -0,0 +1,4 @@ +json.total_count @statues.total_count +json.statues @statues.each do |status| + json.(status, :id, :name) +end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index 19531526e..fac227d73 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -28,6 +28,13 @@ defaults format: :json do # projects文件夹下的 scope module: :projects do resources :issues + scope module: :issues do + resources :milestones, except: [:new, :edit] + resources :issue_statues, only: [:index], controller: '/api/v1/issues/statues' + resources :issue_authors, only: [:index], controller: '/api/v1/issues/authors' + resources :issue_assigners, only: [:index], controller: '/api/v1/issues/assigners' + end + resources :pulls, module: 'pulls' do resources :versions, only: [:index] do member do @@ -38,7 +45,6 @@ defaults format: :json do resources :reviews, only: [:index, :create] end - resources :versions resources :release_versions resources :webhooks do member do From 241bbc06ca3a231224105245618e8274237c01d6 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 7 Feb 2023 17:47:28 +0800 Subject: [PATCH 002/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Aissue?= =?UTF-8?q?=E8=B4=9F=E8=B4=A3=E4=BA=BA=E5=8F=98=E6=9B=B4=E4=B8=BA=E4=B8=80?= =?UTF-8?q?=E5=AF=B9=E5=A4=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/issues/assigners_controller.rb | 10 ++++++++++ app/models/issue.rb | 3 +++ app/models/issue_assigner.rb | 20 +++++++++++++++++++ app/models/user.rb | 2 ++ .../v1/issues/assigners/index.json.jbuilder | 4 ++++ .../20230207091507_create_issue_assigners.rb | 10 ++++++++++ 6 files changed, 49 insertions(+) create mode 100644 app/controllers/api/v1/issues/assigners_controller.rb create mode 100644 app/models/issue_assigner.rb create mode 100644 app/views/api/v1/issues/assigners/index.json.jbuilder create mode 100644 db/migrate/20230207091507_create_issue_assigners.rb diff --git a/app/controllers/api/v1/issues/assigners_controller.rb b/app/controllers/api/v1/issues/assigners_controller.rb new file mode 100644 index 000000000..421ae2eda --- /dev/null +++ b/app/controllers/api/v1/issues/assigners_controller.rb @@ -0,0 +1,10 @@ +class Api::V1::Issues::AssignersController < Api::V1::BaseController + + before_action :require_public_and_member_above, only: [:index] + + # 负责人列表 + def index + @assigners = User.joins(assigned_issues: :project).where(projects: {id: @project&.id}) + @assigners = kaminary_select_paginate(@assigners) + end +end \ No newline at end of file diff --git a/app/models/issue.rb b/app/models/issue.rb index 2a3b95958..069fae40a 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -68,6 +68,9 @@ class Issue < ApplicationRecord has_many :issue_tags, through: :issue_tags_relates has_many :issue_times, dependent: :destroy has_many :issue_depends, dependent: :destroy + has_many :issue_assigners + has_many :assigners, through: :issue_assigners + scope :issue_includes, ->{includes(:user)} scope :issue_many_includes, ->{includes(journals: :user)} scope :issue_issue, ->{where(issue_classify: [nil,"issue"])} diff --git a/app/models/issue_assigner.rb b/app/models/issue_assigner.rb new file mode 100644 index 000000000..a0836f214 --- /dev/null +++ b/app/models/issue_assigner.rb @@ -0,0 +1,20 @@ +# == Schema Information +# +# Table name: issue_assigners +# +# id :integer not null, primary key +# issue_id :integer +# assigner_id :integer +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_issue_assigners_on_assigner_id (assigner_id) +# index_issue_assigners_on_issue_id (issue_id) +# + +class IssueAssigner < ApplicationRecord + belongs_to :issue + belongs_to :assigner, class_name: "User" +end diff --git a/app/models/user.rb b/app/models/user.rb index 4288c4d4c..9162702fc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -175,6 +175,8 @@ class User < Owner has_many :system_notifications, through: :system_notification_histories has_one :trace_user, dependent: :destroy has_many :feedbacks, dependent: :destroy + has_many :issue_assigners, foreign_key: :assigner_id + has_many :assigned_issues, through: :issue_assigners, source: :issue # Groups and active users scope :active, lambda { where(status: STATUS_ACTIVE) } scope :like, lambda { |keywords| diff --git a/app/views/api/v1/issues/assigners/index.json.jbuilder b/app/views/api/v1/issues/assigners/index.json.jbuilder new file mode 100644 index 000000000..fbcf469a6 --- /dev/null +++ b/app/views/api/v1/issues/assigners/index.json.jbuilder @@ -0,0 +1,4 @@ +json.total_count @assigners.total_count +json.assigners @assigners.each do |assigner| + json.partial! 'api/v1/users/simple_user', locals: { user: assigner} +end \ No newline at end of file diff --git a/db/migrate/20230207091507_create_issue_assigners.rb b/db/migrate/20230207091507_create_issue_assigners.rb new file mode 100644 index 000000000..1a25db213 --- /dev/null +++ b/db/migrate/20230207091507_create_issue_assigners.rb @@ -0,0 +1,10 @@ +class CreateIssueAssigners < ActiveRecord::Migration[5.2] + def change + create_table :issue_assigners do |t| + t.references :issue + t.references :assigner, references: :user + + t.timestamps + end + end +end From af67d984b4839aa7badbd2b50ce00420031ad49d Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 8 Feb 2023 09:49:02 +0800 Subject: [PATCH 003/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E9=87=8C?= =?UTF-8?q?=E7=A8=8B=E7=A2=91=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/issues/milestones_controller.rb | 31 +++++++++++++++++++ .../milestones/_simple_detail.json.jbuilder | 1 + .../v1/issues/milestones/index.json.jbuilder | 6 ++++ 3 files changed, 38 insertions(+) create mode 100644 app/controllers/api/v1/issues/milestones_controller.rb create mode 100644 app/views/api/v1/issues/milestones/_simple_detail.json.jbuilder create mode 100644 app/views/api/v1/issues/milestones/index.json.jbuilder diff --git a/app/controllers/api/v1/issues/milestones_controller.rb b/app/controllers/api/v1/issues/milestones_controller.rb new file mode 100644 index 000000000..f25ec498c --- /dev/null +++ b/app/controllers/api/v1/issues/milestones_controller.rb @@ -0,0 +1,31 @@ +class Api::V1::Issues::MilestonesController < Api::V1::BaseController + before_action :require_public_and_member_above, only: [:index] + + # 里程碑列表 + def index + if params[:only_name] + @milestones = @project.versions + else + @milestones = @project.versions.includes(:issues) + end + @milestones = kaminary_select_paginate(@milestones) + end + + # 里程碑详情 + def show + end + + def create + end + + def update + end + + def destroy + end + + + private + + +end \ No newline at end of file diff --git a/app/views/api/v1/issues/milestones/_simple_detail.json.jbuilder b/app/views/api/v1/issues/milestones/_simple_detail.json.jbuilder new file mode 100644 index 000000000..667f7b6a7 --- /dev/null +++ b/app/views/api/v1/issues/milestones/_simple_detail.json.jbuilder @@ -0,0 +1 @@ +json.(milestone, :id, :name) \ No newline at end of file diff --git a/app/views/api/v1/issues/milestones/index.json.jbuilder b/app/views/api/v1/issues/milestones/index.json.jbuilder new file mode 100644 index 000000000..012549bd3 --- /dev/null +++ b/app/views/api/v1/issues/milestones/index.json.jbuilder @@ -0,0 +1,6 @@ +json.total_count @milestones.total_count +json.milestones @milestones.each do |milestone| + if params[:only_name] + json.partial! "simple_detail", locals: {milestone: milestone} + end +end \ No newline at end of file From fe972f1141015845469bfd7feafb0c5fde588d22 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 8 Feb 2023 10:15:29 +0800 Subject: [PATCH 004/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=A0=87=E8=AE=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/issues/issue_tags_controller.rb | 27 +++++++++++++++++++ .../issue_tags/_simple_detail.json.jbuilder | 1 + .../v1/issues/issue_tags/index.json.jbuilder | 6 +++++ config/routes/api.rb | 1 + 4 files changed, 35 insertions(+) create mode 100644 app/controllers/api/v1/issues/issue_tags_controller.rb create mode 100644 app/views/api/v1/issues/issue_tags/_simple_detail.json.jbuilder create mode 100644 app/views/api/v1/issues/issue_tags/index.json.jbuilder diff --git a/app/controllers/api/v1/issues/issue_tags_controller.rb b/app/controllers/api/v1/issues/issue_tags_controller.rb new file mode 100644 index 000000000..2b03c94fe --- /dev/null +++ b/app/controllers/api/v1/issues/issue_tags_controller.rb @@ -0,0 +1,27 @@ +class Api::V1::Issues::IssueTagsController < Api::V1::BaseController + + before_action :require_public_and_member_above, only: [:index] + + def index + @issue_tags = @project.issue_tags.order("#{order_by} #{order_direction}") + if params[:only_name] + @issue_tags = kaminary_select_paginate(@issue_tags.select(:id, :name)) + else + @issue_tags = kaminari_paginate(@issue_tags) + end + end + + + private + def order_by + order_by = params.fetch(:order_by, "created_at") + order_by = IssueTag.column_names.include?(order_by) ? order_by : "created_at" + order_by + end + + def order_direction + order_direction = params.fetch(:order_direction, "desc").downcase + order_direction = %w(desc asc).include?(order_direction) ? order_direction : "desc" + order_direction + end +end \ No newline at end of file diff --git a/app/views/api/v1/issues/issue_tags/_simple_detail.json.jbuilder b/app/views/api/v1/issues/issue_tags/_simple_detail.json.jbuilder new file mode 100644 index 000000000..f0826fab7 --- /dev/null +++ b/app/views/api/v1/issues/issue_tags/_simple_detail.json.jbuilder @@ -0,0 +1 @@ +json.(tag, :id, :name) \ No newline at end of file diff --git a/app/views/api/v1/issues/issue_tags/index.json.jbuilder b/app/views/api/v1/issues/issue_tags/index.json.jbuilder new file mode 100644 index 000000000..548cd1b40 --- /dev/null +++ b/app/views/api/v1/issues/issue_tags/index.json.jbuilder @@ -0,0 +1,6 @@ +json.total_count @issue_tags.total_count +json.issue_tags @issue_tags.each do |tag| + if params[:only_name] + json.partial! "simple_detail", locals: {tag: tag} + end +end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index fac227d73..6c262ddd0 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -29,6 +29,7 @@ defaults format: :json do scope module: :projects do resources :issues scope module: :issues do + resources :issue_tags, only: [:index] resources :milestones, except: [:new, :edit] resources :issue_statues, only: [:index], controller: '/api/v1/issues/statues' resources :issue_authors, only: [:index], controller: '/api/v1/issues/authors' From ade03c5e2facf3e164c043630b2106fac881378a Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 8 Feb 2023 16:55:20 +0800 Subject: [PATCH 005/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Aissue?= =?UTF-8?q?=E5=8F=82=E4=B8=8E=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/issue.rb | 3 +++ app/models/issue_participant.rb | 9 +++++++++ app/models/user.rb | 2 ++ .../20230208023811_create_issue_participants.rb | 11 +++++++++++ 4 files changed, 25 insertions(+) create mode 100644 app/models/issue_participant.rb create mode 100644 db/migrate/20230208023811_create_issue_participants.rb diff --git a/app/models/issue.rb b/app/models/issue.rb index 069fae40a..11375f4b9 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -70,6 +70,8 @@ class Issue < ApplicationRecord has_many :issue_depends, dependent: :destroy has_many :issue_assigners has_many :assigners, through: :issue_assigners + has_many :issue_participants + has_many :participants, through: :issue_participants scope :issue_includes, ->{includes(:user)} scope :issue_many_includes, ->{includes(journals: :user)} @@ -77,6 +79,7 @@ class Issue < ApplicationRecord scope :issue_pull_request, ->{where(issue_classify: "pull_request")} scope :issue_index_includes, ->{includes(:tracker, :priority, :version, :issue_status, :journals,:issue_tags,user: :user_extension)} scope :closed, ->{where(status_id: 5)} + scope :opened, ->{where.not(status_id: 5)} after_create :incre_project_common, :incre_user_statistic, :incre_platform_statistic after_save :change_versions_count, :send_update_message_to_notice_system after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic diff --git a/app/models/issue_participant.rb b/app/models/issue_participant.rb new file mode 100644 index 000000000..fa7be6980 --- /dev/null +++ b/app/models/issue_participant.rb @@ -0,0 +1,9 @@ +class IssueParticipant < ApplicationRecord + + belongs_to :issue + belongs_to :participant, class_name: "User" + + enum participant_type: {"authored": 0, "assigned": 1, "commented": 2, "edited": 3, "atme": 4} + + +end diff --git a/app/models/user.rb b/app/models/user.rb index 9162702fc..cb39e42e7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -177,6 +177,8 @@ class User < Owner has_many :feedbacks, dependent: :destroy has_many :issue_assigners, foreign_key: :assigner_id has_many :assigned_issues, through: :issue_assigners, source: :issue + has_many :issue_participants, foreign_key: :participant_id + has_many :participant_issues, through: :issue_participants, source: :issue # Groups and active users scope :active, lambda { where(status: STATUS_ACTIVE) } scope :like, lambda { |keywords| diff --git a/db/migrate/20230208023811_create_issue_participants.rb b/db/migrate/20230208023811_create_issue_participants.rb new file mode 100644 index 000000000..834061053 --- /dev/null +++ b/db/migrate/20230208023811_create_issue_participants.rb @@ -0,0 +1,11 @@ +class CreateIssueParticipants < ActiveRecord::Migration[5.2] + def change + create_table :issue_participants do |t| + t.references :issue + t.references :participant, references: :user + t.integer :participant_type, default: 0 + + t.timestamps + end + end +end From 4085da7837870e96b1a377d58889d573be3063f8 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 8 Feb 2023 16:56:01 +0800 Subject: [PATCH 006/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Aissue?= =?UTF-8?q?=E5=92=8C=E9=87=8C=E7=A8=8B=E7=A2=91=E5=88=97=E8=A1=A8=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/issues_controller.rb | 23 +++++ app/services/api/v1/issues/list_service.rb | 87 +++++++++++++++++++ .../v1/issues/_simple_detail.json.jbuilder | 20 +++++ app/views/api/v1/issues/index.json.jbuilder | 4 + .../issue_tags/_simple_detail.json.jbuilder | 2 +- 5 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 app/controllers/api/v1/issues_controller.rb create mode 100644 app/services/api/v1/issues/list_service.rb create mode 100644 app/views/api/v1/issues/index.json.jbuilder diff --git a/app/controllers/api/v1/issues_controller.rb b/app/controllers/api/v1/issues_controller.rb new file mode 100644 index 000000000..1decf3421 --- /dev/null +++ b/app/controllers/api/v1/issues_controller.rb @@ -0,0 +1,23 @@ +class Api::V1::IssuesController < Api::V1::BaseController + + before_action :require_public_and_member_above, only: [:index] + + def index + @object_results = Api::V1::Issues::ListService.call(@project, query_params, current_user) + @issues = kaminari_paginate(@object_results) + end + + private + + def query_params + params.permit( + :category, + :participant_category, + :keyword, :author_id, + :milestone_id, :assigner_id, + :status_id, + :sort_by, :sort_direction, + :issue_tag_ids => []) + end + +end \ No newline at end of file diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb new file mode 100644 index 000000000..1a7378598 --- /dev/null +++ b/app/services/api/v1/issues/list_service.rb @@ -0,0 +1,87 @@ +class Api::V1::Issues::ListService < ApplicationService + include ActiveModel::Model + + attr_reader :project, :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 + + validates :category, inclusion: {in: %w(all opened closed), message: "请输入正确的Category"} + validates :sort_by, inclusion: {in: Issue.column_names, message: '请输入正确的SortBy'}, allow_blank: true + validates :sort_direction, inclusion: {in: %w(asc desc), message: '请输入正确的SortDirection'}, allow_blank: true + + def initialize(project, params, current_user=nil) + puts params + @project = project + @category = params[:category] || 'all' + @participant_category = params[:participant_category] + @keyword = params[:keyword] + @author_id = params[:author_id] + @issue_tag_ids = params[:issue_tag_ids] + @milestone_id = params[:milestone_id] + @assigner_id = params[:assigner_id] + @status_id = params[:status_id] + @sort_by = params[:sort_by].present? ? params[:sort_by] : 'updated_on' + @sort_direction = (params[:sort_direction].present? ? params[:sort_direction] : 'desc').downcase + @current_user = current_user + end + + def call + raise Error, errors.full_messages.join(", ") unless valid? + begin + issue_query_data + + queried_issues + rescue + raise Error, "服务器错误,请联系系统管理员!" + end + end + + private + def issue_query_data + issues = @project.issues.issue_issue.joins(:journals).where.not(journals: {notes: nil}) + + case category + when 'closed' + issues = issues.closed + when 'opened' + issues = issues.opened + end + + case participant_category + when 'aboutme' # 关于我的 + issues = issues.joins(:participants, :issue_participants).where(issue_participants: {participant_type: %(authored assigned atme)},users: {id: current_user&.id}) + when 'authoredme' # 我创建的 + issues = issues.joins(:participants, :issue_participants).where(issue_participants: {participant_type: %(authored)},users: {id: current_user&.id}) + when 'assignedme' # 我负责的 + issues = issues.joins(:participants, :issue_participants).where(issue_participants: {participant_type: %(assigned)},users: {id: current_user&.id}) + when 'atme' # @我的 + issues = issues.joins(:participants, :issue_participants).where(issue_participants: {participant_type: %(atme)},users: {id: current_user&.id}) + end + + # author_id + issues = issues.where(author_id: author_id) if author_id.present? + + # issue_tag_ids + issues = issues.joins(:issue_tags).where(issue_tags: {id: issue_tag_ids}) unless issue_tag_ids.blank? + + # milestone_id + issues = issues.where(fixed_version_id: milestone_id) if milestone_id.present? + + # assigner_id + issues = issues.joins(:assigners).where(users: {id: assigner_id}) if assigner_id.present? + + # status_id + issues = issues.where(status_id: status_id) if status_id.present? + + # keyword + q = issues.ransack(subject_or_description_cont: keyword) + + scope = q.result.includes(:priority, :issue_status, :user, :assigners, :version, :issue_tags, :journals) + + + scope = scope.reorder("issues.#{sort_by} #{sort_direction}") + + @queried_issues = scope + end + +end \ No newline at end of file diff --git a/app/views/api/v1/issues/_simple_detail.json.jbuilder b/app/views/api/v1/issues/_simple_detail.json.jbuilder index e69de29bb..395086d59 100644 --- a/app/views/api/v1/issues/_simple_detail.json.jbuilder +++ b/app/views/api/v1/issues/_simple_detail.json.jbuilder @@ -0,0 +1,20 @@ +json.(issue, :id, :subject, :project_issues_index) +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.issue_tags.each do |tag| + json.partial! "api/v1/issues/issue_tags/simple_detail", locals: {tag: tag} +end +json.status_name issue.issue_status&.name +json.priority_name issue.priority&.name +json.milestone_name issue.version&.name +json.author do + if issue.user.present? + json.partial! "api/v1/users/simple_user", locals: {user: issue.user} + else + json.nil! + end +end +json.assigners issue.assigners.each do |assigner| + json.partial! "api/v1/users/simple_user", locals: {user: assigner} +end +json.journals_count issue.journals.size \ No newline at end of file diff --git a/app/views/api/v1/issues/index.json.jbuilder b/app/views/api/v1/issues/index.json.jbuilder new file mode 100644 index 000000000..e0d6ae7bd --- /dev/null +++ b/app/views/api/v1/issues/index.json.jbuilder @@ -0,0 +1,4 @@ +# json.total_count @issues.total_count +json.issues @issues.each do |issue| + json.partial! "simple_detail", locals: {issue: issue} +end \ No newline at end of file diff --git a/app/views/api/v1/issues/issue_tags/_simple_detail.json.jbuilder b/app/views/api/v1/issues/issue_tags/_simple_detail.json.jbuilder index f0826fab7..8395a8e83 100644 --- a/app/views/api/v1/issues/issue_tags/_simple_detail.json.jbuilder +++ b/app/views/api/v1/issues/issue_tags/_simple_detail.json.jbuilder @@ -1 +1 @@ -json.(tag, :id, :name) \ No newline at end of file +json.(tag, :id, :name, :color) \ No newline at end of file From 1aeed8236da79476acfb6e2d6e575dde5b416384 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 9 Feb 2023 09:29:02 +0800 Subject: [PATCH 007/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E9=83=A8?= =?UTF-8?q?=E5=88=86=E6=8E=A5=E5=8F=A3=E4=BC=A0=E5=8F=82=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=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/assigners_controller.rb | 1 + app/controllers/api/v1/issues/authors_controller.rb | 1 + app/controllers/api/v1/issues/issue_tags_controller.rb | 2 +- app/services/users/register_service.rb | 2 +- config/routes/api.rb | 6 +++--- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/v1/issues/assigners_controller.rb b/app/controllers/api/v1/issues/assigners_controller.rb index 421ae2eda..b2b15a90a 100644 --- a/app/controllers/api/v1/issues/assigners_controller.rb +++ b/app/controllers/api/v1/issues/assigners_controller.rb @@ -5,6 +5,7 @@ class Api::V1::Issues::AssignersController < Api::V1::BaseController # 负责人列表 def index @assigners = User.joins(assigned_issues: :project).where(projects: {id: @project&.id}) + @assigners = @assigners.order("users.id=#{current_user.id} desc, issue_assigners.created_at desc").distinct @assigners = kaminary_select_paginate(@assigners) end end \ No newline at end of file diff --git a/app/controllers/api/v1/issues/authors_controller.rb b/app/controllers/api/v1/issues/authors_controller.rb index 8c7a4f7e6..8a5dbcdce 100644 --- a/app/controllers/api/v1/issues/authors_controller.rb +++ b/app/controllers/api/v1/issues/authors_controller.rb @@ -4,6 +4,7 @@ class Api::V1::Issues::AuthorsController < Api::V1::BaseController # 发布人列表 def index @authors = User.joins(issues: :project).where(projects: {id: @project&.id}) + @authors = @authors.order("users.id=#{current_user.id} desc").distinct @authors = kaminary_select_paginate(@authors) end end \ No newline at end of file diff --git a/app/controllers/api/v1/issues/issue_tags_controller.rb b/app/controllers/api/v1/issues/issue_tags_controller.rb index 2b03c94fe..3fa46a4da 100644 --- a/app/controllers/api/v1/issues/issue_tags_controller.rb +++ b/app/controllers/api/v1/issues/issue_tags_controller.rb @@ -5,7 +5,7 @@ class Api::V1::Issues::IssueTagsController < Api::V1::BaseController def index @issue_tags = @project.issue_tags.order("#{order_by} #{order_direction}") if params[:only_name] - @issue_tags = kaminary_select_paginate(@issue_tags.select(:id, :name)) + @issue_tags = kaminary_select_paginate(@issue_tags.select(:id, :name, :color)) else @issue_tags = kaminari_paginate(@issue_tags) end diff --git a/app/services/users/register_service.rb b/app/services/users/register_service.rb index bb3b3ada1..bb984477f 100644 --- a/app/services/users/register_service.rb +++ b/app/services/users/register_service.rb @@ -12,7 +12,7 @@ class Users::RegisterService < ApplicationService namespace = strip(@namespace) password = strip(@password) - Rails.logger.info "Users::RegisterService params: ##### #{params} " + # Rails.logger.info "Users::RegisterService params: ##### #{params} " email, phone = if register_type == 1 diff --git a/config/routes/api.rb b/config/routes/api.rb index 6c262ddd0..657ca52bd 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -25,9 +25,7 @@ defaults format: :json do end end - # projects文件夹下的 - scope module: :projects do - resources :issues + resources :issues scope module: :issues do resources :issue_tags, only: [:index] resources :milestones, except: [:new, :edit] @@ -36,6 +34,8 @@ defaults format: :json do resources :issue_assigners, only: [:index], controller: '/api/v1/issues/assigners' end + # projects文件夹下的 + scope module: :projects do resources :pulls, module: 'pulls' do resources :versions, only: [:index] do member do From c1d791741c4f9763a6303a9a1c3051540e2ba92d Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 9 Feb 2023 10:15:59 +0800 Subject: [PATCH 008/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=AD=A3=E5=B8=B8=E6=9F=A5=E8=AF=A2=E5=85=B3=E8=81=94?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/issue.rb | 1 + app/services/api/v1/issues/list_service.rb | 6 +++--- app/views/api/v1/issues/_simple_detail.json.jbuilder | 2 +- app/views/api/v1/issues/index.json.jbuilder | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 11375f4b9..03e33c666 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -72,6 +72,7 @@ class Issue < ApplicationRecord has_many :assigners, through: :issue_assigners has_many :issue_participants has_many :participants, through: :issue_participants + has_many :comment_journals, -> {where.not(notes: nil)}, class_name: "Journal", :as => :journalized scope :issue_includes, ->{includes(:user)} scope :issue_many_includes, ->{includes(journals: :user)} diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index 1a7378598..39ff2eca8 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -38,7 +38,7 @@ class Api::V1::Issues::ListService < ApplicationService private def issue_query_data - issues = @project.issues.issue_issue.joins(:journals).where.not(journals: {notes: nil}) + issues = @project.issues.issue_issue case category when 'closed' @@ -76,10 +76,10 @@ class Api::V1::Issues::ListService < ApplicationService # keyword q = issues.ransack(subject_or_description_cont: keyword) - scope = q.result.includes(:priority, :issue_status, :user, :assigners, :version, :issue_tags, :journals) + scope = q.result.includes(:priority, :issue_status, :user, :assigners, :version, :issue_tags, :comment_journals) - scope = scope.reorder("issues.#{sort_by} #{sort_direction}") + scope = scope.reorder("issues.#{sort_by} #{sort_direction}").distinct @queried_issues = scope end diff --git a/app/views/api/v1/issues/_simple_detail.json.jbuilder b/app/views/api/v1/issues/_simple_detail.json.jbuilder index 395086d59..da1bdfcb1 100644 --- a/app/views/api/v1/issues/_simple_detail.json.jbuilder +++ b/app/views/api/v1/issues/_simple_detail.json.jbuilder @@ -17,4 +17,4 @@ end json.assigners issue.assigners.each do |assigner| json.partial! "api/v1/users/simple_user", locals: {user: assigner} end -json.journals_count issue.journals.size \ No newline at end of file +json.journals_count issue.comment_journals.size \ No newline at end of file diff --git a/app/views/api/v1/issues/index.json.jbuilder b/app/views/api/v1/issues/index.json.jbuilder index e0d6ae7bd..920e7d68d 100644 --- a/app/views/api/v1/issues/index.json.jbuilder +++ b/app/views/api/v1/issues/index.json.jbuilder @@ -1,4 +1,4 @@ -# json.total_count @issues.total_count +json.total_count @issues.total_count json.issues @issues.each do |issue| json.partial! "simple_detail", locals: {issue: issue} end \ No newline at end of file From 934b42f1a15ec07a95ddcbbd6547d838bd680b8f Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 9 Feb 2023 16:20:16 +0800 Subject: [PATCH 009/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E4=BC=98?= =?UTF-8?q?=E5=85=88=E7=BA=A7=E5=92=8C=E6=89=80=E6=9C=89=E4=BB=93=E5=BA=93?= =?UTF-8?q?=E6=88=90=E5=91=98=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v1/issues/issue_priorities_controller.rb | 9 +++++++++ .../api/v1/projects/collaborators_controller.rb | 10 ++++++++++ .../api/v1/issues/_simple_detail.json.jbuilder | 2 +- .../issues/issue_priorities/index.json.jbuilder | 4 ++++ .../projects/collaborators/index.json.jbuilder | 4 ++++ config/routes/api.rb | 17 +++++++++-------- 6 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 app/controllers/api/v1/issues/issue_priorities_controller.rb create mode 100644 app/controllers/api/v1/projects/collaborators_controller.rb create mode 100644 app/views/api/v1/issues/issue_priorities/index.json.jbuilder create mode 100644 app/views/api/v1/projects/collaborators/index.json.jbuilder diff --git a/app/controllers/api/v1/issues/issue_priorities_controller.rb b/app/controllers/api/v1/issues/issue_priorities_controller.rb new file mode 100644 index 000000000..d26d8f3a8 --- /dev/null +++ b/app/controllers/api/v1/issues/issue_priorities_controller.rb @@ -0,0 +1,9 @@ +class Api::V1::Issues::IssuePrioritiesController < Api::V1::BaseController + + before_action :require_public_and_member_above, only: [:index] + + def index + @priorities = IssuePriority.order(position: :asc) + @priorities = kaminary_select_paginate(@priorities) + end +end \ No newline at end of file diff --git a/app/controllers/api/v1/projects/collaborators_controller.rb b/app/controllers/api/v1/projects/collaborators_controller.rb new file mode 100644 index 000000000..67a96378e --- /dev/null +++ b/app/controllers/api/v1/projects/collaborators_controller.rb @@ -0,0 +1,10 @@ +class Api::V1::Projects::CollaboratorsController < Api::V1::BaseController + + before_action :require_public_and_member_above, only: [:index] + + def index + @collaborators = @project.all_collaborators.ransack(name_or_login_cont: params[:keyword]).result + @collaborators = kaminary_select_paginate(@collaborators) + end + +end \ No newline at end of file diff --git a/app/views/api/v1/issues/_simple_detail.json.jbuilder b/app/views/api/v1/issues/_simple_detail.json.jbuilder index da1bdfcb1..a33cde4cf 100644 --- a/app/views/api/v1/issues/_simple_detail.json.jbuilder +++ b/app/views/api/v1/issues/_simple_detail.json.jbuilder @@ -17,4 +17,4 @@ end json.assigners issue.assigners.each do |assigner| json.partial! "api/v1/users/simple_user", locals: {user: assigner} end -json.journals_count issue.comment_journals.size \ No newline at end of file +json.comment_journals_count issue.comment_journals.size \ No newline at end of file diff --git a/app/views/api/v1/issues/issue_priorities/index.json.jbuilder b/app/views/api/v1/issues/issue_priorities/index.json.jbuilder new file mode 100644 index 000000000..41499d456 --- /dev/null +++ b/app/views/api/v1/issues/issue_priorities/index.json.jbuilder @@ -0,0 +1,4 @@ +json.total_count @priorities.total_count +json.priorities @priorities.each do |priority| + json.(priority, :id, :name) +end \ No newline at end of file diff --git a/app/views/api/v1/projects/collaborators/index.json.jbuilder b/app/views/api/v1/projects/collaborators/index.json.jbuilder new file mode 100644 index 000000000..c0c33c6ba --- /dev/null +++ b/app/views/api/v1/projects/collaborators/index.json.jbuilder @@ -0,0 +1,4 @@ +json.total_count @collaborators.total_count +json.collaborators @collaborators.each do |collaborator| + json.partial! "api/v1/users/simple_user", locals: {user: collaborator} +end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index 657ca52bd..e4994f529 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -26,13 +26,14 @@ defaults format: :json do end resources :issues - scope module: :issues do - resources :issue_tags, only: [:index] - resources :milestones, except: [:new, :edit] - resources :issue_statues, only: [:index], controller: '/api/v1/issues/statues' - resources :issue_authors, only: [:index], controller: '/api/v1/issues/authors' - resources :issue_assigners, only: [:index], controller: '/api/v1/issues/assigners' - end + scope module: :issues do + resources :issue_tags, only: [:index] + resources :milestones, except: [:new, :edit] + resources :issue_statues, only: [:index], controller: '/api/v1/issues/statues' + resources :issue_authors, only: [:index], controller: '/api/v1/issues/authors' + resources :issue_assigners, only: [:index], controller: '/api/v1/issues/assigners' + resources :issue_priorities, only: [:index] + end # projects文件夹下的 scope module: :projects do @@ -45,7 +46,7 @@ defaults format: :json do resources :journals, except: [:show, :edit] resources :reviews, only: [:index, :create] end - + resources :collaborators, only: [:index] resources :release_versions resources :webhooks do member do From 53c2ffffb3c2af8707e16a4a6923773deb33eea9 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 10 Feb 2023 11:38:51 +0800 Subject: [PATCH 010/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E7=96=91?= =?UTF-8?q?=E4=BF=AE=E5=88=9B=E5=BB=BA=E4=BB=A5=E5=8F=8A=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/issues_controller.rb | 34 +++++- app/controllers/issues_controller.rb | 3 + app/models/issue.rb | 1 + app/models/project.rb | 15 +++ app/services/api/v1/issues/create_service.rb | 107 ++++++++++++++++++ app/services/api/v1/issues/list_service.rb | 5 +- app/views/api/v1/issues/_detail.json.jbuilder | 42 +++++++ .../v1/issues/_simple_detail.json.jbuilder | 4 +- app/views/api/v1/issues/create.json.jbuilder | 1 + app/views/api/v1/issues/index.json.jbuilder | 2 + .../_simple_detail.json.jbuilder | 1 + .../issue_priorities/index.json.jbuilder | 2 +- app/views/api/v1/issues/show.json.jbuilder | 1 + .../statues/_simple_detail.json.jbuilder | 1 + .../api/v1/issues/statues/index.json.jbuilder | 2 +- lib/tasks/fix_issue_project_issues_index.rake | 22 ++++ 16 files changed, 236 insertions(+), 7 deletions(-) create mode 100644 app/services/api/v1/issues/create_service.rb create mode 100644 app/views/api/v1/issues/_detail.json.jbuilder create mode 100644 app/views/api/v1/issues/create.json.jbuilder create mode 100644 app/views/api/v1/issues/issue_priorities/_simple_detail.json.jbuilder create mode 100644 app/views/api/v1/issues/show.json.jbuilder create mode 100644 app/views/api/v1/issues/statues/_simple_detail.json.jbuilder create mode 100644 lib/tasks/fix_issue_project_issues_index.rake diff --git a/app/controllers/api/v1/issues_controller.rb b/app/controllers/api/v1/issues_controller.rb index 1decf3421..3f61259e5 100644 --- a/app/controllers/api/v1/issues_controller.rb +++ b/app/controllers/api/v1/issues_controller.rb @@ -1,12 +1,25 @@ class Api::V1::IssuesController < Api::V1::BaseController - before_action :require_public_and_member_above, only: [:index] + before_action :require_public_and_member_above, only: [:index, :show, :create, :update, :destroy] def index @object_results = Api::V1::Issues::ListService.call(@project, query_params, current_user) @issues = kaminari_paginate(@object_results) end + def create + @object_result = Api::V1::Issues::CreateService.call(@project, issue_params, current_user) + end + + before_action :load_issue, only: [:show, :update, :destroy] + + def show + end + + def update + @object_result = Api::V1::Issues::EditService.call(@project, issue_params, current_user) + end + private def query_params @@ -20,4 +33,23 @@ class Api::V1::IssuesController < Api::V1::BaseController :issue_tag_ids => []) end + def issue_params + params.permit( + :status_id, :priority_id, :milestone_id, + :branch_name, :start_date, :due_date, + :subject, :description, + :issue_tag_ids => [], + :assigner_ids => [], + :attachment_ids => []) + end + + def load_issue + @issue = @project.issues.where(project_issues_index: params[:id]).where.not(id: params[:id]).take || Issue.find_by_id(params[:id]) + if @issue.blank? + render_not_found("疑修不存在!") + elsif @issue.present? && @issue.is_lock &&!(@project.member?(current_user) || current_user.admin?) + render_forbidden("您没有权限操作!") + end + end + end \ No newline at end of file diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index ddb0facdf..2f779f418 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -111,7 +111,9 @@ class IssuesController < ApplicationController issue_params = issue_send_params(params) Issues::CreateForm.new({subject: issue_params[:subject], description: issue_params[:description].blank? ? issue_params[:description] : issue_params[:description].b}).validate! @issue = Issue.new(issue_params) + @issue.project_issues_index = @project.get_last_project_issues_index + 1 if @issue.save! + @project.del_project_issue_cache_delete_count SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id) if Site.has_notice_menu? SendTemplateMessageJob.perform_later('ProjectIssue', current_user.id, @issue&.id) if Site.has_notice_menu? if params[:attachment_ids].present? @@ -302,6 +304,7 @@ class IssuesController < ApplicationController login = @issue.user.try(:login) SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, @issue&.subject, @issue.assigned_to_id, @issue.author_id) if Site.has_notice_menu? if @issue.destroy + @project.incre_project_issue_cache_delete_count if issue_type == "2" && status_id != 5 post_to_chain("add", token, login) end diff --git a/app/models/issue.rb b/app/models/issue.rb index 03e33c666..be759d2b4 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -73,6 +73,7 @@ class Issue < ApplicationRecord has_many :issue_participants has_many :participants, through: :issue_participants 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 scope :issue_includes, ->{includes(:user)} scope :issue_many_includes, ->{includes(journals: :user)} diff --git a/app/models/project.rb b/app/models/project.rb index 840661ee7..310d3009e 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -424,4 +424,19 @@ class Project < ApplicationRecord raise("项目名称包含敏感词汇,请重新输入") if name && !HarmoniousDictionary.clean?(name) raise("项目描述包含敏感词汇,请重新输入") if description && !HarmoniousDictionary.clean?(description) end + + def get_last_project_issues_index + last_issue = self.issues.last + deleted_issue_count = ($redis_cache.hget("issue_cache_delete_count", self.id) || 0).to_i + + last_issue.project_issues_index.present? ? last_issue.project_issues_index + deleted_issue_count : 1 + end + + def incre_project_issue_cache_delete_count + $redis_cache.hincrby("issue_cache_delete_count", self.id, 1) + end + + def del_project_issue_cache_delete_count + $redis_cache.hdel("issue_cache_delete_count", self.id) + end end diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb new file mode 100644 index 000000000..6b3e9685a --- /dev/null +++ b/app/services/api/v1/issues/create_service.rb @@ -0,0 +1,107 @@ +class Api::V1::Issues::CreateService < ApplicationService + include ActiveModel::Model + + attr_reader :project, :created_issue, :current_user + attr_reader :status_id, :priority_id, :milestone_id, :branch_name, :start_date, :due_date, :subject, :description + attr_reader :issue_tag_ids, :assigner_ids, :attachment_ids + + validates :subject, presence: true + validates :status_id, :priority_id, presence: true + validates :current_user, presence: true + + def initialize(project, params, current_user = nil) + @project = project + @current_user = current_user + @status_id = params[:status_id] + @priority_id = params[:priority_id] + @milestone_id = params[:milestone_id] + @branch_name = params[:branch_name] + @start_date = params[:start_date] + @due_date = params[:due_date] + @subject = params[:subject] + @description = params[:description] + @issue_tag_ids = params[:issue_tag_ids] + @assigner_ids = params[:assigner_ids] + @attachment_ids = params[:attachment_ids] + end + + def call + raise Error, errors.full_messages.join(", ") unless valid? + begin + ActiveRecord::Base.transaction do + check_issue_status + check_issue_priority + check_milestone if milestone_id.present? + load_assigners unless assigner_ids.blank? + load_attachments unless attachment_ids.blank? + load_issue_tags unless issue_tag_ids.blank? + load_participants + + @created_issue = Issue.new(issue_attributes) + @created_issue.assigners = @assigners unless assigner_ids.blank? + @created_issue.attachments = @attachments unless attachment_ids.blank? + @created_issue.issue_tags = @issue_tags unless issue_tag_ids.blank? + @created_issue.participants = @participants + + @created_issue.save! + + project.del_project_issue_cache_delete_count # 把缓存里存储项目删除issue的个数清除掉 + end + + return @created_issue + rescue + raise Error, "服务器错误,请联系系统管理员!" + end + end + + private + def check_issue_status + raise Error, "IssueStatus不存在!" unless IssueStatus.find_by_id(status_id).present? + end + + def check_issue_priority + raise Error, "IssuePriority不存在!" unless IssuePriority.find_by_id(priority_id).present? + end + + def check_milestone + raise Error, "Milestone不存在!" unless Version.find_by_id(milestone_id).present? + end + + def load_assigners + @assigners = User.where(id: assigner_ids) + end + + def load_issue_tags + @issue_tags = IssueTag.where(id: issue_tag_ids) + end + + def load_attachments + @attachments = Attachment.where(id: attachment_ids) + end + + def load_participants + @participants = User.where(id: assigner_ids).or(User.where(id: current_user.id)) + end + + def issue_attributes + issue_attributes = { + subject: subject, + project_id: project.id, + author_id: current_user.id, + tracker_id: Tracker.first.id, + status_id: status_id, + priority_id: priority_id, + project_issues_index: (project.get_last_project_issues_index + 1), + issue_type: "1", + issue_classify: "Issue" + } + + issue_attributes.merge!({description: description}) if description.present? + issue_attributes.merge!({fixed_version_id: milestone_id}) if milestone_id.present? + issue_attributes.merge!({start_date: start_date}) if start_date.present? + issue_attributes.merge!({due_date: due_date}) if due_date.present? + issue_attributes.merge!({branch_name: branch_name}) if branch_name.present? + + issue_attributes + end +end \ No newline at end of file diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index 39ff2eca8..a5609bb62 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -6,14 +6,15 @@ class Api::V1::Issues::ListService < ApplicationService attr_accessor :queried_issues 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: Issue.column_names, message: '请输入正确的SortBy'}, allow_blank: true validates :sort_direction, inclusion: {in: %w(asc desc), message: '请输入正确的SortDirection'}, allow_blank: true + validates :current_user, presence: true def initialize(project, params, current_user=nil) - puts params @project = project @category = params[:category] || 'all' - @participant_category = params[:participant_category] + @participant_category = params[:participant_category] || 'all' @keyword = params[:keyword] @author_id = params[:author_id] @issue_tag_ids = params[:issue_tag_ids] diff --git a/app/views/api/v1/issues/_detail.json.jbuilder b/app/views/api/v1/issues/_detail.json.jbuilder new file mode 100644 index 000000000..e2e1bde8d --- /dev/null +++ b/app/views/api/v1/issues/_detail.json.jbuilder @@ -0,0 +1,42 @@ +json.(issue, :id, :subject, :project_issues_index, :description, :branch_name, :start_date, :due_date) +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.issue_tags.each do |tag| + json.partial! "api/v1/issues/issue_tags/simple_detail", locals: {tag: tag} +end +json.status do + if issue.issue_status.present? + json.partial! "api/v1/issues/statues/simple_detail", locals: {status: issue.issue_status} + else + json.nil! + end +end +json.priority do + if issue.priority.present? + json.partial! "api/v1/issues/issue_priorities/simple_detail", locals: {priority: issue.priority} + else + json.nil! + end +end +json.milestone do + if issue.version.present? + json.partial! "api/v1/issues/milestones/simple_detail", locals: {milestone: issue.version} + else + json.nil! + end +end +json.author do + if issue.user.present? + json.partial! "api/v1/users/simple_user", locals: {user: issue.user} + else + json.nil! + end +end +json.assigners issue.assigners.each do |assigner| + json.partial! "api/v1/users/simple_user", locals: {user: assigner} +end +json.participants issue.participants.each do |participant| + json.partial! "api/v1/users/simple_user", locals: {user: participant} +end +json.comment_journals_count issue.comment_journals.size +json.operate_journals_count issue.operate_journals.size \ No newline at end of file diff --git a/app/views/api/v1/issues/_simple_detail.json.jbuilder b/app/views/api/v1/issues/_simple_detail.json.jbuilder index a33cde4cf..bfc2693cf 100644 --- a/app/views/api/v1/issues/_simple_detail.json.jbuilder +++ b/app/views/api/v1/issues/_simple_detail.json.jbuilder @@ -1,6 +1,6 @@ json.(issue, :id, :subject, :project_issues_index) -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.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.issue_tags.each do |tag| json.partial! "api/v1/issues/issue_tags/simple_detail", locals: {tag: tag} end diff --git a/app/views/api/v1/issues/create.json.jbuilder b/app/views/api/v1/issues/create.json.jbuilder new file mode 100644 index 000000000..f45ef5b2f --- /dev/null +++ b/app/views/api/v1/issues/create.json.jbuilder @@ -0,0 +1 @@ +json.partial! "api/v1/issues/detail", locals: {issue: @object_result} diff --git a/app/views/api/v1/issues/index.json.jbuilder b/app/views/api/v1/issues/index.json.jbuilder index 920e7d68d..3e820f6f4 100644 --- a/app/views/api/v1/issues/index.json.jbuilder +++ b/app/views/api/v1/issues/index.json.jbuilder @@ -1,4 +1,6 @@ json.total_count @issues.total_count +json.opened_count @issues.opened.size +json.closed_count @issues.closed.size json.issues @issues.each do |issue| json.partial! "simple_detail", locals: {issue: issue} end \ No newline at end of file diff --git a/app/views/api/v1/issues/issue_priorities/_simple_detail.json.jbuilder b/app/views/api/v1/issues/issue_priorities/_simple_detail.json.jbuilder new file mode 100644 index 000000000..b7c37147a --- /dev/null +++ b/app/views/api/v1/issues/issue_priorities/_simple_detail.json.jbuilder @@ -0,0 +1 @@ +json.(priority, :id, :name) diff --git a/app/views/api/v1/issues/issue_priorities/index.json.jbuilder b/app/views/api/v1/issues/issue_priorities/index.json.jbuilder index 41499d456..c1b8ebb25 100644 --- a/app/views/api/v1/issues/issue_priorities/index.json.jbuilder +++ b/app/views/api/v1/issues/issue_priorities/index.json.jbuilder @@ -1,4 +1,4 @@ json.total_count @priorities.total_count json.priorities @priorities.each do |priority| - json.(priority, :id, :name) + json.partial! "simple_detail", locals: {priority: priority} end \ No newline at end of file diff --git a/app/views/api/v1/issues/show.json.jbuilder b/app/views/api/v1/issues/show.json.jbuilder new file mode 100644 index 000000000..8746417b5 --- /dev/null +++ b/app/views/api/v1/issues/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "api/v1/issues/detail", locals: {issue: @issue} diff --git a/app/views/api/v1/issues/statues/_simple_detail.json.jbuilder b/app/views/api/v1/issues/statues/_simple_detail.json.jbuilder new file mode 100644 index 000000000..f66b6c95a --- /dev/null +++ b/app/views/api/v1/issues/statues/_simple_detail.json.jbuilder @@ -0,0 +1 @@ +json.(status, :id, :name) diff --git a/app/views/api/v1/issues/statues/index.json.jbuilder b/app/views/api/v1/issues/statues/index.json.jbuilder index 2cc91fb52..9fb60acc2 100644 --- a/app/views/api/v1/issues/statues/index.json.jbuilder +++ b/app/views/api/v1/issues/statues/index.json.jbuilder @@ -1,4 +1,4 @@ json.total_count @statues.total_count json.statues @statues.each do |status| - json.(status, :id, :name) + json.partial! "simple_detail", locals: {status: status} end \ No newline at end of file diff --git a/lib/tasks/fix_issue_project_issues_index.rake b/lib/tasks/fix_issue_project_issues_index.rake new file mode 100644 index 000000000..010df5f4b --- /dev/null +++ b/lib/tasks/fix_issue_project_issues_index.rake @@ -0,0 +1,22 @@ +# 执行示例 bundle exec rake sync_version_issues:update_issues +# 线上环境执行示例 RAILS_ENV=production bundle exec rake sync_version_issues:update_issues + +namespace :fix_issue_project_issues_index do + desc "update issue project_issues_index" + + task update_issues: :environment do + puts "____________fix start________________" + + Issue.update_all(project_issues_index: nil) + + Issue.where(project_issues_index: nil).group(:project_id).count.each do |pid, count| + p = Project.find_by_id(pid) + issues = p.issues.order(created_on: :asc) + issues.find_each.with_index do |issue, index| + issue.update_column(:project_issues_index, index+1) + end + end + puts "____________fix end________________" + end + +end \ No newline at end of file From 4a8e3324af95634c2202494c3f7fd60c4aff1408 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 10 Feb 2023 15:39:09 +0800 Subject: [PATCH 011/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/project.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 310d3009e..d258fb0d8 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -429,7 +429,7 @@ class Project < ApplicationRecord last_issue = self.issues.last deleted_issue_count = ($redis_cache.hget("issue_cache_delete_count", self.id) || 0).to_i - last_issue.project_issues_index.present? ? last_issue.project_issues_index + deleted_issue_count : 1 + last_issue&.project_issues_index.present? ? last_issue.project_issues_index + deleted_issue_count : 1 end def incre_project_issue_cache_delete_count From db2d398d94d5e3a6b02864d8c9918a76e86dcc44 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 13 Feb 2023 09:43:26 +0800 Subject: [PATCH 012/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Aparticipants?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/issue.rb | 1 + app/models/project.rb | 2 +- app/services/api/v1/issues/create_service.rb | 46 +++++++++++++++++--- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index be759d2b4..a1438761e 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -72,6 +72,7 @@ class Issue < ApplicationRecord has_many :assigners, through: :issue_assigners has_many :issue_participants has_many :participants, through: :issue_participants + has_many :show_participants, -> {joins(:issue_participants).where.not(issue_participants: {participant_type: "atme"}).distinct}, through: :issue_participants, source: :participant has_many :comment_journals, -> {where.not(notes: nil)}, class_name: "Journal", :as => :journalized has_many :operate_journals, -> {where(notes: nil)}, class_name: "Journal", :as => :journalized diff --git a/app/models/project.rb b/app/models/project.rb index d258fb0d8..0792c9cb0 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -429,7 +429,7 @@ class Project < ApplicationRecord last_issue = self.issues.last deleted_issue_count = ($redis_cache.hget("issue_cache_delete_count", self.id) || 0).to_i - last_issue&.project_issues_index.present? ? last_issue.project_issues_index + deleted_issue_count : 1 + last_issue&.project_issues_index.present? ? last_issue.project_issues_index + deleted_issue_count : 0 end def incre_project_issue_cache_delete_count diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index 6b3e9685a..8a795f395 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -32,17 +32,20 @@ class Api::V1::Issues::CreateService < ApplicationService check_issue_status check_issue_priority check_milestone if milestone_id.present? + check_issue_tags unless issue_tag_ids.blank? + check_assigners unless assigner_ids.blank? + check_attachments unless attachment_ids.blank? load_assigners unless assigner_ids.blank? load_attachments unless attachment_ids.blank? load_issue_tags unless issue_tag_ids.blank? - load_participants @created_issue = Issue.new(issue_attributes) @created_issue.assigners = @assigners unless assigner_ids.blank? @created_issue.attachments = @attachments unless attachment_ids.blank? @created_issue.issue_tags = @issue_tags unless issue_tag_ids.blank? - @created_issue.participants = @participants - + build_author_participants + build_assinger_participants unless assigner_ids.blank? + @created_issue.save! project.del_project_issue_cache_delete_count # 把缓存里存储项目删除issue的个数清除掉 @@ -67,6 +70,29 @@ class Api::V1::Issues::CreateService < ApplicationService raise Error, "Milestone不存在!" unless Version.find_by_id(milestone_id).present? end + def check_issue_tags + raise Error, "请输入正确的标记ID数组!" unless issue_tag_ids.is_a?(Array) + raise Error, "最多可选择3个标记" if issue_tag_ids.size > 3 + issue_tag_ids.each do |tid| + raise Error, "请输入正确的标记ID!" unless IssueTag.exists?(id: tid) + end + end + + def check_assigners + raise Error, "请输入正确的负责人ID数组!" unless assigner_ids.is_a?(Array) + raise Error, "最多可选择5个负责人" if assigner_ids.size > 5 + assigner_ids.each do |aid| + raise Error, "请输入正确的负责人ID!" unless User.exists?(id: aid) + end + end + + def check_attachments + raise Error, "请输入正确的附件ID数组!" unless assigner_ids.is_a?(Array) + attachment_ids.each do |aid| + raise Error, "请输入正确的附件ID!" unless Attachment.exists?(id: aid) + end + end + def load_assigners @assigners = User.where(id: assigner_ids) end @@ -79,10 +105,6 @@ class Api::V1::Issues::CreateService < ApplicationService @attachments = Attachment.where(id: attachment_ids) end - def load_participants - @participants = User.where(id: assigner_ids).or(User.where(id: current_user.id)) - end - def issue_attributes issue_attributes = { subject: subject, @@ -104,4 +126,14 @@ class Api::V1::Issues::CreateService < ApplicationService issue_attributes end + + def build_author_participants + @created_issue.issue_participants.new({participant_type: "authored", participant_id: current_user.id}) + end + + def build_assinger_participants + assigner_ids.each do |aid| + @created_issue.issue_participants.new({participant_type: "assigned", participant_id: aid}) + end + end end \ No newline at end of file From 404a6a00e7b0bd30aa4e4150f2b12b9b50f59050 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 14 Feb 2023 23:19:17 +0800 Subject: [PATCH 013/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Aissue?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E5=88=A0=E9=99=A4=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/issues_controller.rb | 37 +++- app/jobs/send_template_message_job.rb | 14 +- app/models/issue.rb | 4 +- app/models/project.rb | 6 +- .../api/v1/issues/batch_delete_service.rb | 41 ++++ .../api/v1/issues/batch_update_service.rb | 29 +++ .../api/v1/issues/concerns/checkable.rb | 45 +++++ .../api/v1/issues/concerns/loadable.rb | 19 ++ app/services/api/v1/issues/create_service.rb | 137 ++++++------- app/services/api/v1/issues/delete_service.rb | 43 +++++ app/services/api/v1/issues/update_service.rb | 181 ++++++++++++++++++ config/routes/api.rb | 7 +- 12 files changed, 477 insertions(+), 86 deletions(-) create mode 100644 app/services/api/v1/issues/batch_delete_service.rb create mode 100644 app/services/api/v1/issues/batch_update_service.rb create mode 100644 app/services/api/v1/issues/concerns/checkable.rb create mode 100644 app/services/api/v1/issues/concerns/loadable.rb create mode 100644 app/services/api/v1/issues/delete_service.rb create mode 100644 app/services/api/v1/issues/update_service.rb diff --git a/app/controllers/api/v1/issues_controller.rb b/app/controllers/api/v1/issues_controller.rb index 3f61259e5..d1addcf31 100644 --- a/app/controllers/api/v1/issues_controller.rb +++ b/app/controllers/api/v1/issues_controller.rb @@ -17,7 +17,22 @@ class Api::V1::IssuesController < Api::V1::BaseController end def update - @object_result = Api::V1::Issues::EditService.call(@project, issue_params, current_user) + @object_result = Api::V1::Issues::UpdateService.call(@project, @issue, issue_params, current_user) + end + + def destroy + @object_result = Api::V1::Issues::DeleteService.call(@project, @issue, current_user) + end + + + before_action :load_issues, only: [:batch_update, :batch_destroy] + + def batch_update + @object_result = Api::V1::Issues::BatchUpdateService.call(@project, @issues, batch_issue_params, current_user) + end + + def batch_destroy + @object_result = Api::V1::Issues::BatchDeleteService.call(@project, @issues, current_user) end private @@ -43,6 +58,13 @@ class Api::V1::IssuesController < Api::V1::BaseController :attachment_ids => []) end + def batch_issue_params + params.permit( + :status_id, :priority_id, :milestone_id, + :issue_tag_ids => [], + :assigner_ids => []) + end + def load_issue @issue = @project.issues.where(project_issues_index: params[:id]).where.not(id: params[:id]).take || Issue.find_by_id(params[:id]) if @issue.blank? @@ -52,4 +74,17 @@ class Api::V1::IssuesController < Api::V1::BaseController end end + def load_issues + return render_error("请输入正确的ID数组!") unless params[:ids].is_a?(Array) + params[:ids].each do |id| + @issue = @project.issues.where(project_issues_index: id).where.not(id: id).take || Issue.find_by_id(id) + if @issue.blank? + return render_not_found("ID为#{id}的疑修不存在!") + elsif if @issue.present? && @issue.is_lock &&!(@project.member?(current_user) || current_user.admin?) + return render_forbidden("ID为#{id}的疑修您没有权限操作!") + end + end + @issues = @project.issues.where(project_issues_index: params[:ids]).where.not(id: params[:ids]) || Issue.where(id: params[:ids]) + end + end \ No newline at end of file diff --git a/app/jobs/send_template_message_job.rb b/app/jobs/send_template_message_job.rb index 557d4d0fa..594a7a7b5 100644 --- a/app/jobs/send_template_message_job.rb +++ b/app/jobs/send_template_message_job.rb @@ -34,8 +34,12 @@ class SendTemplateMessageJob < ApplicationJob operator_id, issue_id = args[0], args[1] operator = User.find_by_id(operator_id) issue = Issue.find_by_id(issue_id) - return unless operator.present? && issue.present? - receivers = User.where(id: issue&.assigned_to_id).where.not(id: operator&.id) + return unless operator.present? && issue.present? + if args[2].present? + receivers = User.where(id: args[2]).where.not(id: operator&.id) + else + receivers = User.where(id: issue&.assigned_to_id).where.not(id: operator&.id) + end receivers_string, content, notification_url = MessageTemplate::IssueAssigned.get_message_content(receivers, operator, issue) Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, issue_id: issue.id}) receivers.find_each do |receiver| @@ -78,7 +82,11 @@ class SendTemplateMessageJob < ApplicationJob operator_id, issue_title, issue_assigned_to_id, issue_author_id = args[0], args[1], args[2], args[3] operator = User.find_by_id(operator_id) return unless operator.present? - receivers = User.where(id: [issue_assigned_to_id, issue_author_id]).where.not(id: operator&.id) + if issue_assigned_to_id.is_a?(Array) + receivers = User.where(id: issue_assigned_to_id.append(issue_author_id)).where.not(id: operator&.id) + else + receivers = User.where(id: [issue_assigned_to_id, issue_author_id]).where.not(id: operator&.id) + end receivers_string, content, notification_url = MessageTemplate::IssueDeleted.get_message_content(receivers, operator, issue_title) Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, issue_title: issue_title}) receivers.find_each do |receiver| diff --git a/app/models/issue.rb b/app/models/issue.rb index a1438761e..78ffaead7 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -68,9 +68,9 @@ class Issue < ApplicationRecord has_many :issue_tags, through: :issue_tags_relates has_many :issue_times, dependent: :destroy has_many :issue_depends, dependent: :destroy - has_many :issue_assigners + has_many :issue_assigners, dependent: :destroy has_many :assigners, through: :issue_assigners - has_many :issue_participants + has_many :issue_participants, dependent: :destroy has_many :participants, through: :issue_participants has_many :show_participants, -> {joins(:issue_participants).where.not(issue_participants: {participant_type: "atme"}).distinct}, through: :issue_participants, source: :participant has_many :comment_journals, -> {where.not(notes: nil)}, class_name: "Journal", :as => :journalized diff --git a/app/models/project.rb b/app/models/project.rb index 0792c9cb0..4361118e4 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -432,11 +432,11 @@ class Project < ApplicationRecord last_issue&.project_issues_index.present? ? last_issue.project_issues_index + deleted_issue_count : 0 end - def incre_project_issue_cache_delete_count - $redis_cache.hincrby("issue_cache_delete_count", self.id, 1) + def incre_project_issue_cache_delete_count(count=1) + $redis_cache.hincrby("issue_cache_delete_count", self.id, count) end - def del_project_issue_cache_delete_count + def del_project_issue_cache_delete_count $redis_cache.hdel("issue_cache_delete_count", self.id) end end diff --git a/app/services/api/v1/issues/batch_delete_service.rb b/app/services/api/v1/issues/batch_delete_service.rb new file mode 100644 index 000000000..13da5d84a --- /dev/null +++ b/app/services/api/v1/issues/batch_delete_service.rb @@ -0,0 +1,41 @@ +class Api::V1::Issues::BatchDeleteService < ApplicationService + include ActiveModel::Model + + attr_reader :project, :issues, :current_user + + validates :project, :issues, :current_user, presence: true + + def initialize(project, issues, current_user = nil) + @project = project + @issues = issues.includes(:assigners) + @current_user = current_user + end + + def call + raise Error, errors.full_messages.join(", ") unless valid? + try_lock # 开始写数据,加锁 + + delete_issues + + project.incre_project_issue_cache_delete_count(@issues.size) + + if Site.has_notice_menu? + @issues.each do |issue| + SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, @issue&.subject, @issue.assigners.pluck(:id), @issue.author_id) + end + end + + unlock + end + + private + + def try_lock + raise Error, "请稍后再试!" unless $redis_cache.set("Api::V1::Issues::BatchDeleteService:#{project.id}", 1, nx: true, ex: 60.seconds) + end + + def unlock + $redis_cache.del("Api::V1::Issues::BatchDeleteService:#{project.id}") + end + +end \ No newline at end of file diff --git a/app/services/api/v1/issues/batch_update_service.rb b/app/services/api/v1/issues/batch_update_service.rb new file mode 100644 index 000000000..2e3e4fab7 --- /dev/null +++ b/app/services/api/v1/issues/batch_update_service.rb @@ -0,0 +1,29 @@ +class Api::V1::Issues::BatchUpdateService < ApplicationService + include ActiveModel::Model + include Api::V1::Issues::Concerns::Checkable + include Api::V1::Issues::Concerns::Loadable + + attr_reader :project, :issues, :params, :current_user + attr_reader :status_id, :priority_id, :milestone_id + attr_reader :issue_tag_ids, :assigner_ids + + validates :project, :issues, :current_user, presence: true + + def initialize(project, issues, params, current_user = nil) + @project = project + @issues = issues + @params = params + @current_user = current_user + end + + def call + raise Error, errors.full_messages.join(", ") unless valid? + ActiveRecord::Base.transaction do + @issues.each do |issue| + Api::V1::Issues::UpdateService.call(project, issue, params, current_user) + end + end + end + + +end \ No newline at end of file diff --git a/app/services/api/v1/issues/concerns/checkable.rb b/app/services/api/v1/issues/concerns/checkable.rb new file mode 100644 index 000000000..8ac03f053 --- /dev/null +++ b/app/services/api/v1/issues/concerns/checkable.rb @@ -0,0 +1,45 @@ +module Api::V1::Issues::Concerns::Checkable + + def check_issue_status(status_id) + raise ApplicationService::Error, "IssueStatus不存在!" unless IssueStatus.find_by_id(status_id).present? + end + + def check_issue_priority(priority_id) + raise ApplicationService::Error, "IssuePriority不存在!" unless IssuePriority.find_by_id(priority_id).present? + end + + def check_milestone(milestone_id) + raise ApplicationService::Error, "Milestone不存在!" unless Version.find_by_id(milestone_id).present? + end + + def check_issue_tags(issue_tag_ids) + raise ApplicationService::Error, "请输入正确的标记ID数组!" unless issue_tag_ids.is_a?(Array) + raise ApplicationService::Error, "最多可选择3个标记" if issue_tag_ids.size > 3 + issue_tag_ids.each do |tid| + raise ApplicationService::Error, "请输入正确的标记ID!" unless IssueTag.exists?(id: tid) + end + end + + def check_assigners(assigner_ids) + raise ApplicationService::Error, "请输入正确的负责人ID数组!" unless assigner_ids.is_a?(Array) + raise ApplicationService::Error, "最多可选择5个负责人" if assigner_ids.size > 5 + assigner_ids.each do |aid| + raise ApplicationService::Error, "请输入正确的负责人ID!" unless User.exists?(id: aid) + end + end + + def check_attachments (attachment_ids) + raise ApplicationService::Error, "请输入正确的附件ID数组!" unless attachment_ids.is_a?(Array) + attachment_ids.each do |aid| + raise ApplicationService::Error, "请输入正确的附件ID!" unless Attachment.exists?(id: aid) + end + end + + def check_atme_receivers(receivers_login) + raise ApplicationService::Error, "请输入正确的用户标识数组!" unless receivers_login.is_a?(Array) + receivers_login.each do |rlogin| + raise ApplicationService::Error, "请输入正确的用户标识!" unless User.exists?(login: rlogin) + end + end + +end diff --git a/app/services/api/v1/issues/concerns/loadable.rb b/app/services/api/v1/issues/concerns/loadable.rb new file mode 100644 index 000000000..df30042e0 --- /dev/null +++ b/app/services/api/v1/issues/concerns/loadable.rb @@ -0,0 +1,19 @@ +module Api::V1::Issues::Concerns::Loadable + + def load_assigners(assigner_ids) + @assigners = User.where(id: assigner_ids) + end + + def load_issue_tags(issue_tag_ids) + @issue_tags = IssueTag.where(id: issue_tag_ids) + end + + def load_attachments(attachment_ids) + @attachments = Attachment.where(id: attachment_ids) + end + + def load_atme_receivers(receivers_login) + @atme_receivers = User.where(login: receivers_login) + end + +end \ No newline at end of file diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index 8a795f395..bee688d6d 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -1,13 +1,16 @@ class Api::V1::Issues::CreateService < ApplicationService include ActiveModel::Model + include Api::V1::Issues::Concerns::Checkable + include Api::V1::Issues::Concerns::Loadable - attr_reader :project, :created_issue, :current_user - attr_reader :status_id, :priority_id, :milestone_id, :branch_name, :start_date, :due_date, :subject, :description - attr_reader :issue_tag_ids, :assigner_ids, :attachment_ids + attr_reader :project, :current_user + attr_reader :status_id, :priority_id, :milestone_id, :branch_name, :start_date, :due_date, :subject, :description + attr_reader :issue_tag_ids, :assigner_ids, :attachment_ids, :receivers_login + attr_accessor :created_issue validates :subject, presence: true validates :status_id, :priority_id, presence: true - validates :current_user, presence: true + validates :project, :current_user, presence: true def initialize(project, params, current_user = nil) @project = project @@ -23,87 +26,51 @@ class Api::V1::Issues::CreateService < ApplicationService @issue_tag_ids = params[:issue_tag_ids] @assigner_ids = params[:assigner_ids] @attachment_ids = params[:attachment_ids] + @receivers_login = params[:receivers_login] end def call raise Error, errors.full_messages.join(", ") unless valid? - begin - ActiveRecord::Base.transaction do - check_issue_status - check_issue_priority - check_milestone if milestone_id.present? - check_issue_tags unless issue_tag_ids.blank? - check_assigners unless assigner_ids.blank? - check_attachments unless attachment_ids.blank? - load_assigners unless assigner_ids.blank? - load_attachments unless attachment_ids.blank? - load_issue_tags unless issue_tag_ids.blank? - - @created_issue = Issue.new(issue_attributes) - @created_issue.assigners = @assigners unless assigner_ids.blank? - @created_issue.attachments = @attachments unless attachment_ids.blank? - @created_issue.issue_tags = @issue_tags unless issue_tag_ids.blank? - build_author_participants - build_assinger_participants unless assigner_ids.blank? - - @created_issue.save! - - project.del_project_issue_cache_delete_count # 把缓存里存储项目删除issue的个数清除掉 - end + ActiveRecord::Base.transaction do + check_issue_status(status_id) + check_issue_priority(priority_id) + check_milestone(milestone_id) if milestone_id.present? + check_issue_tags(issue_tag_ids) unless issue_tag_ids.blank? + check_assigners(assigner_ids) unless assigner_ids.blank? + check_attachments(attachment_ids) unless attachment_ids.blank? + check_atme_receivers(receivers_login) unless receivers_login.blank? + load_attachments(attachment_ids) unless attachment_ids.blank? + load_issue_tags(issue_tag_ids) unless issue_tag_ids.blank? + load_atme_receivers(receivers_login) unless receivers_login.blank? + + try_lock # 开始写数据,加锁 + @created_issue = Issue.new(issue_attributes) + build_author_participants + build_assigner_participants unless assigner_ids.blank? + build_issue_journal_details if @updated_issue.previous_changes.present? # 操作记录 + build_issue_project_trends if status_id.present? # 开关时间 + @created_issue.attachments = @attachments unless attachment_ids.blank? + @created_issue.issue_tags = @issue_tags unless issue_tag_ids.blank? - return @created_issue - rescue - raise Error, "服务器错误,请联系系统管理员!" - end - end - - private - def check_issue_status - raise Error, "IssueStatus不存在!" unless IssueStatus.find_by_id(status_id).present? - end - - def check_issue_priority - raise Error, "IssuePriority不存在!" unless IssuePriority.find_by_id(priority_id).present? - end + @created_issue.save! + project.del_project_issue_cache_delete_count # 把缓存里存储项目删除issue的个数清除掉 - def check_milestone - raise Error, "Milestone不存在!" unless Version.find_by_id(milestone_id).present? - end + # @信息发送 + AtmeService.call(current_user, @atme_receivers, @issue) unless receivers_login.blank? - def check_issue_tags - raise Error, "请输入正确的标记ID数组!" unless issue_tag_ids.is_a?(Array) - raise Error, "最多可选择3个标记" if issue_tag_ids.size > 3 - issue_tag_ids.each do |tid| - raise Error, "请输入正确的标记ID!" unless IssueTag.exists?(id: tid) + # 发消息 + if Site.has_notice_menu? + SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id, assigner_ids) unless assigner_ids.blank? + SendTemplateMessageJob.perform_later('ProjectIssue', current_user.id, @issue&.id) + end + + unlock # 结束写数据,解锁 end + + return @created_issue end - def check_assigners - raise Error, "请输入正确的负责人ID数组!" unless assigner_ids.is_a?(Array) - raise Error, "最多可选择5个负责人" if assigner_ids.size > 5 - assigner_ids.each do |aid| - raise Error, "请输入正确的负责人ID!" unless User.exists?(id: aid) - end - end - - def check_attachments - raise Error, "请输入正确的附件ID数组!" unless assigner_ids.is_a?(Array) - attachment_ids.each do |aid| - raise Error, "请输入正确的附件ID!" unless Attachment.exists?(id: aid) - end - end - - def load_assigners - @assigners = User.where(id: assigner_ids) - end - - def load_issue_tags - @issue_tags = IssueTag.where(id: issue_tag_ids) - end - - def load_attachments - @attachments = Attachment.where(id: attachment_ids) - end + private def issue_attributes issue_attributes = { @@ -131,9 +98,27 @@ class Api::V1::Issues::CreateService < ApplicationService @created_issue.issue_participants.new({participant_type: "authored", participant_id: current_user.id}) end - def build_assinger_participants + def build_assigner_participants assigner_ids.each do |aid| @created_issue.issue_participants.new({participant_type: "assigned", participant_id: aid}) end end + + def build_issue_project_trends + @created_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: "create"}) + @created_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE}) if status_id.to_i == 5 + end + + def build_issue_journal_details + journal = @updated_issue.journals.new({user_id: current_user.id}) + journal.journal_details.new({property: "issue", prop_key: 1, old_value: '', value: ''}) + end + + def try_lock + raise Error, "请稍后再试!" unless $redis_cache.set("Api::V1::Issues::CreateService:#{project.id}", 1, nx: true, ex: 60.seconds) + end + + def unlock + $redis_cache.del("Api::V1::Issues::CreateService:#{project.id}") + end end \ No newline at end of file diff --git a/app/services/api/v1/issues/delete_service.rb b/app/services/api/v1/issues/delete_service.rb new file mode 100644 index 000000000..02aaa441b --- /dev/null +++ b/app/services/api/v1/issues/delete_service.rb @@ -0,0 +1,43 @@ +class Api::V1::Issues::DeleteService < ApplicationService + include ActiveModel::Model + + attr_reader :project, :issue, :current_user + + validates :project, :issue, :current_user, presence: true + + def initialize(project, issue, current_user = nil) + @project = project + @issue = issue + @current_user = current_user + end + + def call + raise Error, errors.full_messages.join(", ") unless valid? + try_lock # 开始写数据,加锁 + + delete_issue + + project.incre_project_issue_cache_delete_count + + if Site.has_notice_menu? + SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, @issue&.subject, @issue.assigners.pluck(:id), @issue.author_id) + end + + unlock + end + + private + + def delete_issue + raise Error, "删除疑修失败!" unless issue.destroy! + end + + def try_lock + raise Error, "请稍后再试!" unless $redis_cache.set("Api::V1::Issues::DeleteService:#{project.id}", 1, nx: true, ex: 60.seconds) + end + + def unlock + $redis_cache.del("Api::V1::Issues::DeleteService:#{project.id}") + end + +end \ No newline at end of file diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb new file mode 100644 index 000000000..49410e81a --- /dev/null +++ b/app/services/api/v1/issues/update_service.rb @@ -0,0 +1,181 @@ +class Api::V1::Issues::UpdateService < ApplicationService + include ActiveModel::Model + include Api::V1::Issues::Concerns::Checkable + include Api::V1::Issues::Concerns::Loadable + + attr_reader :project, :issue, :current_user + attr_reader :status_id, :priority_id, :milestone_id, :branch_name, :start_date, :due_date, :subject, :description + attr_reader :issue_tag_ids, :assigner_ids, :attachment_ids, :receivers_login + attr_accessor :add_assigner_ids, :previous_issue_changes, :updated_issue + + validates :project, :issue, :current_user, presence: true + + def initialize(project, issue, params, current_user = nil) + @project = project + @issue = issue + @current_user = current_user + @status_id = params[:status_id] + @priority_id = params[:priority_id] + @milestone_id = params[:milestone_id] + @branch_name = params[:branch_name] + @start_date = params[:start_date] + @due_date = params[:due_date] + @subject = params[:subject] + @description = params[:description] + @issue_tag_ids = params[:issue_tag_ids] + @assigner_ids = params[:assigner_ids] + @attachment_ids = params[:attachment_ids] + @receivers_login = params[:receivers_login] + @add_assigner_ids = [] + @previous_issue_changes = {} + end + + def call + raise Error, errors.full_messages.join(", ") unless valid? + ActiveRecord::Base.transaction do + check_issue_status(status_id) if status_id.present? + check_issue_priority(priority_id) if priority_id.present? + check_milestone(milestone_id) if milestone_id.present? + check_issue_tags(issue_tag_ids) unless issue_tag_ids.blank? + check_assigners(assigner_ids) unless assigner_ids.blank? + check_attachments(attachment_ids) unless attachment_ids.blank? + check_atme_receivers(receivers_login) unless receivers_login.blank? + load_assigners(assigner_ids) unless assigner_ids.blank? + load_attachments(attachment_ids) unless attachment_ids.blank? + load_issue_tags(issue_tag_ids) unless issue_tag_ids.blank? + load_atme_receivers(receivers_login) unless receivers_login.blank? + + try_lock + @updated_issue = @issue + @updated_issue.load_attributes + build_issue_journal_details if @updated_issue.previous_changes.present? # 操作记录 + build_issue_project_trends if status_id.present? # 开关时间记录 + build_assigner_participants unless assigner_ids.blank? # 负责人 + @updated_issue.assigners = @assigners unless assigner_ids.blank? + @updated_issue.attachments = @attachments unless attachment_ids.blank? + @updated_issue.issue_tags = @issue_tags unless issue_tag_ids.blank? + + @updated_issue.save! + + build_previous_issue_changes + + # @信息发送 + AtmeService.call(current_user, @atme_receivers, @issue) unless receivers_login.blank? + # 消息发送 + if Site.has_notice_menu? + SendTemplateMessageJob.perform_later('IssueChanged', current_user.id, @issue&.id, previous_changes) unless previous_issue_changes.blank? + SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id, add_assigner_ids) unless add_assigner_ids.blank? + end + + unlock + end + end + + private + + def build_assigner_participants + @updated_issue.issue_participants.where.not(id: assigner_ids).each(&:destroy!) + assigner_ids.each do |aid| + next if @updated_issue.issue_participants.exists?(participant_id: aid) + @updated_issue.issue_participants.new({participant_type: "assigned", participant_id: aid}) + @add_assigner_ids << aid + end + end + + def build_previous_issue_changes + @previous_issue_changes = @updated_issue.previous_changes + if @updated_issue.previous_changes[:start_date].present? + @previous_issue_changes.merge!(start_date: [@updated_issue.previous_changes[:start_date][0].to_s, @updated_issue.previous_changes[:start_date][1].to_s]) + end + if @updated_issue.previous_changes[:due_date].present? + @previous_issue_changes.merge!(due_date: [@updated_issue.previous_changes[:due_date][0].to_s, @updated_issue.previous_changes[:due_date][1].to_s]) + end + end + + def build_issue_project_trends + if @updated_issue.previous_changes[:status_id].present? && @updated_issue.previous_changes[:status_id][1] == 5 + @updated_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE}) + end + if @updated_issue.previous_changes[:status_id].present? && @updated_issue.previous_changes[:status_id][0] == 5 + @updated_issue.project_trends.where(action_type: ProjectTrend::CLOSE).each(:&destroy!) + end + end + + def build_issue_journal_details + # 更改标题 + if @updated_issue.previous_changes[:subject].present? + journal = @updated_issue.journals.new({user_id: current_user.id}) + journal.journal_details.new({property: "attr", prop_key: "subject", old_value: @updated_issue.previous_changes[:subject][0], value: @updated_issue.previous_changes[:subject][1]}) + end + + # 更改描述 + if @updated_issue.previous_changes[:description].present? + journal = @updated_issue.journals.new({user_id: current_user.id}) + journal.journal_details.new({property: "attr", prop_key: "description", old_value: @updated_issue.previous_changes[:description][0], value: @updated_issue.previous_changes[:description][1]}) + end + + # 修改状态 + if @updated_issue.previous_changes[:status_id].present? + journal = @updated_issue.journals.new({user_id: current_user.id}) + journal.journal_details.new({property: "attr", prop_key: "status_id", old_value: @updated_issue.previous_changes[:status_id][0], value: @updated_issue.previous_changes[:status_id][1]}) + end + + # 修改优先级 + if @updated_issue.previous_changes[:priority_id].present? + journal = @updated_issue.journals.new({user_id: current_user.id}) + journal.journal_details.new({property: "attr", prop_key: "priority_id", old_value: @updated_issue.previous_changes[:priority_id][0], value: @updated_issue.previous_changes[:priority_id][1]}) + end + + # 修改里程碑 + if @updated_issue.previous_changes[:fixed_version_id].present? + journal = @updated_issue.journals.new({user_id: current_user.id}) + journal.journal_details.new({property: "attr", prop_key: "fixed_version_id", old_value: @updated_issue.previous_changes[:fixed_version_id][0], value: @updated_issue.previous_changes[:fixed_version_id][1]}) + end + + # 更改分支 + if @updated_issue.previous_changes[:branch_name].present? + journal = @updated_issue.journals.new({user_id: current_user.id}) + journal.journal_details.new({property: "attr", prop_key: "branch_name", old_value: @updated_issue.previous_changes[:branch_name][0], value: @updated_issue.previous_changes[:branch_name][1]}) + end + + # 更改开始时间 + if @updated_issue.previous_changes[:start_date].present? + journal = @updated_issue.journals.new({user_id: current_user.id}) + journal.journal_details.new({property: "attr", prop_key: "start_date", old_value: @updated_issue.previous_changes[:start_date][0], value: @updated_issue.previous_changes[:start_date][1]}) + end + + # 更改结束时间 + if @updated_issue.previous_changes[:due_date].present? + journal = @updated_issue.journals.new({user_id: current_user.id}) + journal.journal_details.new({property: "attr", prop_key: "due_date", old_value: @updated_issue.previous_changes[:due_date][0], value: @updated_issue.previous_changes[:due_date][1]}) + end + + # 更改负责人 + if !@updated_issue.assigners.pluck(:id).sort! == assigner_ids.sort! + journal = @updated_issue.journals.new({user_id: current_user.id}) + journal.journal_details.new({property: "assigner", prop_key: "#{assigner_ids.size}", old_value: @updated_issue.assigners.pluck(:nickname).join(","), value: @assigners.pluck(:nickname).join(",")}) + end + + # 更改标记 + if !@updated_issue.issue_tags.pluck(:id).sort! == issue_tag_ids.sort! + journal = @updated_issue.journals.new({user_id: current_user.id}) + journal.journal_details.new({property: "issue_tag", prop_key: "#{issue_tag_ids.size}", old_value: @updated_issue.issue_tags.pluck(:name).join(","), value: @issue_tags.pluck(:name).join(",")}) + end + + # 更改附件 + if !@updated_issue.attachments.pluck(:id).sort! == attachment_ids.sort! + journal = @updated_issue.journals.new({user_id: current_user.id}) + journal.journal_details.new({property: "attachment", prop_key: "#{attachment_ids.size}", old_value: @updated_issue.attachments.pluck(:filename).join(","), value: @attachments.pluck(:filename).join(",")}) + end + end + + def try_lock + raise Error, "请稍后再试!" unless $redis_cache.set("Api::V1::Issues::UpdateService:#{project.id}:#{issue.id}", 1, nx: true, ex: 60.seconds) + end + + def unlock + $redis_cache.del("Api::V1::Issues::UpdateService:#{project.id}:#{issue.id}") + end + + +end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index e4994f529..bf79cb16c 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -25,7 +25,12 @@ defaults format: :json do end end - resources :issues + resources :issues, except: [:new, :edit] do + collection do + patch :batch_update + delete :batch_destroy + end + end scope module: :issues do resources :issue_tags, only: [:index] resources :milestones, except: [:new, :edit] From 2899f3b18e1aebfefd79c85db06bc8e04a8e9780 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 15 Feb 2023 09:48:56 +0800 Subject: [PATCH 014/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E3=80=81=E6=9B=B4=E6=94=B9=E9=80=BB=E8=BE=91=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/issues_controller.rb | 27 ++++++++++++++----- .../api/v1/issues/batch_delete_service.rb | 6 +++++ .../api/v1/issues/batch_update_service.rb | 2 ++ app/services/api/v1/issues/create_service.rb | 6 ++--- app/services/api/v1/issues/delete_service.rb | 2 ++ app/services/api/v1/issues/update_service.rb | 25 ++++++++++++----- app/views/api/v1/issues/_detail.json.jbuilder | 2 +- app/views/api/v1/issues/update.json.jbuilder | 1 + 8 files changed, 55 insertions(+), 16 deletions(-) create mode 100644 app/views/api/v1/issues/update.json.jbuilder diff --git a/app/controllers/api/v1/issues_controller.rb b/app/controllers/api/v1/issues_controller.rb index d1addcf31..567ef6b3b 100644 --- a/app/controllers/api/v1/issues_controller.rb +++ b/app/controllers/api/v1/issues_controller.rb @@ -1,6 +1,6 @@ class Api::V1::IssuesController < Api::V1::BaseController - before_action :require_public_and_member_above, only: [:index, :show, :create, :update, :destroy] + before_action :require_public_and_member_above, only: [:index, :show, :create, :update, :destroy, :batch_update, :batch_destroy] def index @object_results = Api::V1::Issues::ListService.call(@project, query_params, current_user) @@ -22,17 +22,31 @@ class Api::V1::IssuesController < Api::V1::BaseController def destroy @object_result = Api::V1::Issues::DeleteService.call(@project, @issue, current_user) + if @object_result + render_ok + else + render_error("删除疑修失败!") + end end - before_action :load_issues, only: [:batch_update, :batch_destroy] def batch_update @object_result = Api::V1::Issues::BatchUpdateService.call(@project, @issues, batch_issue_params, current_user) + if @object_result + render_ok + else + render_error("批量更新疑修失败!") + end end def batch_destroy @object_result = Api::V1::Issues::BatchDeleteService.call(@project, @issues, current_user) + if @object_result + render_ok + else + render_error("批量删除疑修失败!") + end end private @@ -55,7 +69,8 @@ class Api::V1::IssuesController < Api::V1::BaseController :subject, :description, :issue_tag_ids => [], :assigner_ids => [], - :attachment_ids => []) + :attachment_ids => [], + :receivers_login => []) end def batch_issue_params @@ -77,14 +92,14 @@ class Api::V1::IssuesController < Api::V1::BaseController def load_issues return render_error("请输入正确的ID数组!") unless params[:ids].is_a?(Array) params[:ids].each do |id| - @issue = @project.issues.where(project_issues_index: id).where.not(id: id).take || Issue.find_by_id(id) + @issue = Issue.find_by_id(id) if @issue.blank? return render_not_found("ID为#{id}的疑修不存在!") - elsif if @issue.present? && @issue.is_lock &&!(@project.member?(current_user) || current_user.admin?) + elsif @issue.present? && @issue.is_lock &&!(@project.member?(current_user) || current_user.admin?) return render_forbidden("ID为#{id}的疑修您没有权限操作!") end end - @issues = @project.issues.where(project_issues_index: params[:ids]).where.not(id: params[:ids]) || Issue.where(id: params[:ids]) + @issues = Issue.where(id: params[:ids]) end end \ No newline at end of file diff --git a/app/services/api/v1/issues/batch_delete_service.rb b/app/services/api/v1/issues/batch_delete_service.rb index 13da5d84a..133f098cd 100644 --- a/app/services/api/v1/issues/batch_delete_service.rb +++ b/app/services/api/v1/issues/batch_delete_service.rb @@ -26,10 +26,16 @@ class Api::V1::Issues::BatchDeleteService < ApplicationService end unlock + + return true end private + def delete_issues + raise Error, "批量删除疑修失败!" unless @issues.destroy_all + end + def try_lock raise Error, "请稍后再试!" unless $redis_cache.set("Api::V1::Issues::BatchDeleteService:#{project.id}", 1, nx: true, ex: 60.seconds) end diff --git a/app/services/api/v1/issues/batch_update_service.rb b/app/services/api/v1/issues/batch_update_service.rb index 2e3e4fab7..ffa1ba7df 100644 --- a/app/services/api/v1/issues/batch_update_service.rb +++ b/app/services/api/v1/issues/batch_update_service.rb @@ -22,6 +22,8 @@ class Api::V1::Issues::BatchUpdateService < ApplicationService @issues.each do |issue| Api::V1::Issues::UpdateService.call(project, issue, params, current_user) end + + return true end end diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index bee688d6d..e87745950 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -47,8 +47,8 @@ class Api::V1::Issues::CreateService < ApplicationService @created_issue = Issue.new(issue_attributes) build_author_participants build_assigner_participants unless assigner_ids.blank? - build_issue_journal_details if @updated_issue.previous_changes.present? # 操作记录 - build_issue_project_trends if status_id.present? # 开关时间 + build_issue_journal_details + build_issue_project_trends @created_issue.attachments = @attachments unless attachment_ids.blank? @created_issue.issue_tags = @issue_tags unless issue_tag_ids.blank? @@ -110,7 +110,7 @@ class Api::V1::Issues::CreateService < ApplicationService end def build_issue_journal_details - journal = @updated_issue.journals.new({user_id: current_user.id}) + journal = @created_issue.journals.new({user_id: current_user.id}) journal.journal_details.new({property: "issue", prop_key: 1, old_value: '', value: ''}) end diff --git a/app/services/api/v1/issues/delete_service.rb b/app/services/api/v1/issues/delete_service.rb index 02aaa441b..e6429390e 100644 --- a/app/services/api/v1/issues/delete_service.rb +++ b/app/services/api/v1/issues/delete_service.rb @@ -24,6 +24,8 @@ class Api::V1::Issues::DeleteService < ApplicationService end unlock + + return true end private diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 49410e81a..3084e78a9 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -47,7 +47,7 @@ class Api::V1::Issues::UpdateService < ApplicationService try_lock @updated_issue = @issue - @updated_issue.load_attributes + issue_load_attributes build_issue_journal_details if @updated_issue.previous_changes.present? # 操作记录 build_issue_project_trends if status_id.present? # 开关时间记录 build_assigner_participants unless assigner_ids.blank? # 负责人 @@ -63,27 +63,40 @@ class Api::V1::Issues::UpdateService < ApplicationService AtmeService.call(current_user, @atme_receivers, @issue) unless receivers_login.blank? # 消息发送 if Site.has_notice_menu? - SendTemplateMessageJob.perform_later('IssueChanged', current_user.id, @issue&.id, previous_changes) unless previous_issue_changes.blank? + SendTemplateMessageJob.perform_later('IssueChanged', current_user.id, @issue&.id, previous_issue_changes) unless previous_issue_changes.blank? SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id, add_assigner_ids) unless add_assigner_ids.blank? end unlock + + return @updated_issue end end private + def issue_load_attributes + @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 if milestone_id.present? + @updated_issue.branch_name = branch_name if branch_name.present? + @updated_issue.start_date = start_date if start_date.present? + @updated_issue.due_date = due_date if due_date.present? + @updated_issue.subject = subject if subject.present? + @updated_issue.description = description if description.present? + end + def build_assigner_participants - @updated_issue.issue_participants.where.not(id: assigner_ids).each(&:destroy!) + @updated_issue.issue_participants.where(participant_type: "assigned").where.not(participant_id: assigner_ids).each(&:destroy!) assigner_ids.each do |aid| - next if @updated_issue.issue_participants.exists?(participant_id: aid) + next if @updated_issue.issue_participants.exists?(participant_type: "assigned", participant_id: aid) @updated_issue.issue_participants.new({participant_type: "assigned", participant_id: aid}) @add_assigner_ids << aid end end def build_previous_issue_changes - @previous_issue_changes = @updated_issue.previous_changes + @previous_issue_changes = @updated_issue.previous_changes.except("updated_on", "created_on") if @updated_issue.previous_changes[:start_date].present? @previous_issue_changes.merge!(start_date: [@updated_issue.previous_changes[:start_date][0].to_s, @updated_issue.previous_changes[:start_date][1].to_s]) end @@ -97,7 +110,7 @@ class Api::V1::Issues::UpdateService < ApplicationService @updated_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE}) end if @updated_issue.previous_changes[:status_id].present? && @updated_issue.previous_changes[:status_id][0] == 5 - @updated_issue.project_trends.where(action_type: ProjectTrend::CLOSE).each(:&destroy!) + @updated_issue.project_trends.where(action_type: ProjectTrend::CLOSE).each(&:destroy!) end end diff --git a/app/views/api/v1/issues/_detail.json.jbuilder b/app/views/api/v1/issues/_detail.json.jbuilder index e2e1bde8d..82fea8098 100644 --- a/app/views/api/v1/issues/_detail.json.jbuilder +++ b/app/views/api/v1/issues/_detail.json.jbuilder @@ -35,7 +35,7 @@ end json.assigners issue.assigners.each do |assigner| json.partial! "api/v1/users/simple_user", locals: {user: assigner} end -json.participants issue.participants.each do |participant| +json.participants issue.participants.distinct.each do |participant| json.partial! "api/v1/users/simple_user", locals: {user: participant} end json.comment_journals_count issue.comment_journals.size diff --git a/app/views/api/v1/issues/update.json.jbuilder b/app/views/api/v1/issues/update.json.jbuilder new file mode 100644 index 000000000..f45ef5b2f --- /dev/null +++ b/app/views/api/v1/issues/update.json.jbuilder @@ -0,0 +1 @@ +json.partial! "api/v1/issues/detail", locals: {issue: @object_result} From 2a8e0d2be8db84d1cb16049b5af81e038e63e5c6 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 15 Feb 2023 17:24:36 +0800 Subject: [PATCH 015/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=A0=87?= =?UTF-8?q?=E8=AE=B0=E7=AE=A1=E7=90=86=E6=8E=A5=E5=8F=A3=EF=BC=8C=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E5=88=97=E8=A1=A8=E4=B8=8B=E6=8B=89=E6=A1=86=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/issues/assigners_controller.rb | 3 +- .../api/v1/issues/authors_controller.rb | 1 + .../v1/issues/issue_priorities_controller.rb | 1 + .../api/v1/issues/issue_tags_controller.rb | 41 ++++++++++++++++++- .../api/v1/issues/milestones_controller.rb | 1 + .../api/v1/issues/statues_controller.rb | 1 + app/models/issue_tag.rb | 1 + app/services/users/register_service.rb | 2 +- .../issues/issue_tags/_detail.json.jbuilder | 17 ++++++++ .../v1/issues/issue_tags/index.json.jbuilder | 2 + config/routes/api.rb | 2 +- 11 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 app/views/api/v1/issues/issue_tags/_detail.json.jbuilder diff --git a/app/controllers/api/v1/issues/assigners_controller.rb b/app/controllers/api/v1/issues/assigners_controller.rb index b2b15a90a..84476138f 100644 --- a/app/controllers/api/v1/issues/assigners_controller.rb +++ b/app/controllers/api/v1/issues/assigners_controller.rb @@ -5,7 +5,8 @@ class Api::V1::Issues::AssignersController < Api::V1::BaseController # 负责人列表 def index @assigners = User.joins(assigned_issues: :project).where(projects: {id: @project&.id}) - @assigners = @assigners.order("users.id=#{current_user.id} desc, issue_assigners.created_at desc").distinct + @assigners = @assigners.order("users.id=#{current_user.id} desc").distinct + @assigners = @assigners.ransack(login_or_nickname_cont: params[:keyword]).result if params[:keyword].present? @assigners = kaminary_select_paginate(@assigners) end end \ No newline at end of file diff --git a/app/controllers/api/v1/issues/authors_controller.rb b/app/controllers/api/v1/issues/authors_controller.rb index 8a5dbcdce..d0242a517 100644 --- a/app/controllers/api/v1/issues/authors_controller.rb +++ b/app/controllers/api/v1/issues/authors_controller.rb @@ -5,6 +5,7 @@ class Api::V1::Issues::AuthorsController < Api::V1::BaseController def index @authors = User.joins(issues: :project).where(projects: {id: @project&.id}) @authors = @authors.order("users.id=#{current_user.id} desc").distinct + @authors = @authors.ransack(login_or_nickname_cont: params[:keyword]).result if params[:keyword].present? @authors = kaminary_select_paginate(@authors) end end \ No newline at end of file diff --git a/app/controllers/api/v1/issues/issue_priorities_controller.rb b/app/controllers/api/v1/issues/issue_priorities_controller.rb index d26d8f3a8..319994a28 100644 --- a/app/controllers/api/v1/issues/issue_priorities_controller.rb +++ b/app/controllers/api/v1/issues/issue_priorities_controller.rb @@ -4,6 +4,7 @@ class Api::V1::Issues::IssuePrioritiesController < Api::V1::BaseController def index @priorities = IssuePriority.order(position: :asc) + @priorities = @priorities.ransack(name_cont: params[:keyword]).result if params[:keyword] @priorities = kaminary_select_paginate(@priorities) end end \ No newline at end of file diff --git a/app/controllers/api/v1/issues/issue_tags_controller.rb b/app/controllers/api/v1/issues/issue_tags_controller.rb index 3fa46a4da..63d8fb605 100644 --- a/app/controllers/api/v1/issues/issue_tags_controller.rb +++ b/app/controllers/api/v1/issues/issue_tags_controller.rb @@ -1,13 +1,42 @@ class Api::V1::Issues::IssueTagsController < Api::V1::BaseController - before_action :require_public_and_member_above, only: [:index] + before_action :require_public_and_member_above, only: [:index, :create, :update, :destroy] def index @issue_tags = @project.issue_tags.order("#{order_by} #{order_direction}") + @issue_tags = @issue_tags.ransack(name_cont: params[:keyword]).result if params[:keyword].present? if params[:only_name] @issue_tags = kaminary_select_paginate(@issue_tags.select(:id, :name, :color)) else - @issue_tags = kaminari_paginate(@issue_tags) + @issue_tags = kaminari_paginate(@issue_tags.includes(:project, :user)) + end + end + + def create + @issue_tag = @project.issue_tags.new(issue_tag_params) + if @issue_tag.save! + render_ok + else + render_error("创建标记失败!") + end + end + + before_action :load_issue_tag, only: [:update, :destroy] + + def update + @issue_tag.attributes = issue_tag_params + if @issue_tag.save! + render_ok + else + render_error("更新标记失败!") + end + end + + def destroy + if @issue_tag.destroy! + render_ok + else + render_error("删除标记失败!") end end @@ -24,4 +53,12 @@ class Api::V1::Issues::IssueTagsController < Api::V1::BaseController order_direction = %w(desc asc).include?(order_direction) ? order_direction : "desc" order_direction end + + def issue_tag_params + params.permit(:name, :description, :color) + end + + def load_issue_tag + @issue_tag = @project.issue_tags.find_by_id(params[:id]) + end end \ No newline at end of file diff --git a/app/controllers/api/v1/issues/milestones_controller.rb b/app/controllers/api/v1/issues/milestones_controller.rb index f25ec498c..bb5033904 100644 --- a/app/controllers/api/v1/issues/milestones_controller.rb +++ b/app/controllers/api/v1/issues/milestones_controller.rb @@ -8,6 +8,7 @@ class Api::V1::Issues::MilestonesController < Api::V1::BaseController else @milestones = @project.versions.includes(:issues) end + @milestones = @milestones.ransack(name_or_description_cont: params[:keyword]).result if params[:keyword].present? @milestones = kaminary_select_paginate(@milestones) end diff --git a/app/controllers/api/v1/issues/statues_controller.rb b/app/controllers/api/v1/issues/statues_controller.rb index 0e9eff43f..5a7fbc338 100644 --- a/app/controllers/api/v1/issues/statues_controller.rb +++ b/app/controllers/api/v1/issues/statues_controller.rb @@ -5,6 +5,7 @@ class Api::V1::Issues::StatuesController < Api::V1::BaseController # 状态列表 def index @statues = IssueStatus.order("position asc") + @statues = @statues.ransack(name_cont: params[:keyword]).result if params[:keyword].present? @statues = kaminary_select_paginate(@statues) end end \ No newline at end of file diff --git a/app/models/issue_tag.rb b/app/models/issue_tag.rb index bf2368654..2c62117d0 100644 --- a/app/models/issue_tag.rb +++ b/app/models/issue_tag.rb @@ -24,5 +24,6 @@ class IssueTag < ApplicationRecord has_many :issue_tags_relates, dependent: :destroy has_many :issues, through: :issue_tags_relates belongs_to :project, optional: true, counter_cache: true + belongs_to :user, optional: true end diff --git a/app/services/users/register_service.rb b/app/services/users/register_service.rb index bb984477f..bb3b3ada1 100644 --- a/app/services/users/register_service.rb +++ b/app/services/users/register_service.rb @@ -12,7 +12,7 @@ class Users::RegisterService < ApplicationService namespace = strip(@namespace) password = strip(@password) - # Rails.logger.info "Users::RegisterService params: ##### #{params} " + Rails.logger.info "Users::RegisterService params: ##### #{params} " email, phone = if register_type == 1 diff --git a/app/views/api/v1/issues/issue_tags/_detail.json.jbuilder b/app/views/api/v1/issues/issue_tags/_detail.json.jbuilder new file mode 100644 index 000000000..644badf3e --- /dev/null +++ b/app/views/api/v1/issues/issue_tags/_detail.json.jbuilder @@ -0,0 +1,17 @@ +json.(tag, :name, :description, :color, :issues_count) +json.project do + if tag.project.present? + json.partial! "api/v1/projects/simple_detail", project: tag.project + else + json.nil! + end +end +json.user do + if tag.user.present? + json.partial! "api/v1/users/simple_user", user: tag.user + else + json.nil! + end +end +json.created_at tag.created_at.strftime("%Y-%m-%d %H:%M") +json.updated_at tag.updated_at.strftime("%Y-%m-%d %H:%M") \ No newline at end of file diff --git a/app/views/api/v1/issues/issue_tags/index.json.jbuilder b/app/views/api/v1/issues/issue_tags/index.json.jbuilder index 548cd1b40..0bd055b57 100644 --- a/app/views/api/v1/issues/issue_tags/index.json.jbuilder +++ b/app/views/api/v1/issues/issue_tags/index.json.jbuilder @@ -2,5 +2,7 @@ json.total_count @issue_tags.total_count json.issue_tags @issue_tags.each do |tag| if params[:only_name] json.partial! "simple_detail", locals: {tag: tag} + else + json.partial! "detail", locals: {tag: tag} end end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index bf79cb16c..15ebc44f1 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -32,7 +32,7 @@ defaults format: :json do end end scope module: :issues do - resources :issue_tags, only: [:index] + resources :issue_tags, except: [:new, :edit] resources :milestones, except: [:new, :edit] resources :issue_statues, only: [:index], controller: '/api/v1/issues/statues' resources :issue_authors, only: [:index], controller: '/api/v1/issues/authors' From b85913e4850b2e5fd5bf73444c8eca0de08f7361 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 17 Feb 2023 16:11:39 +0800 Subject: [PATCH 016/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E7=96=91?= =?UTF-8?q?=E4=BF=AE=E6=93=8D=E4=BD=9C=E8=AE=B0=E5=BD=95=E3=80=81=E8=AF=84?= =?UTF-8?q?=E8=AE=BA=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=96=91=E4=BF=AE=E6=97=A0=E6=B3=95=E4=BA=A7?= =?UTF-8?q?=E7=94=9F=E6=93=8D=E4=BD=9C=E8=AE=B0=E5=BD=95=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/issues/journals_controller.rb | 39 ++++ app/controllers/api/v1/issues_controller.rb | 51 +++-- app/models/journal.rb | 78 +++++++ .../api/v1/issues/batch_delete_service.rb | 13 +- app/services/api/v1/issues/create_service.rb | 19 +- app/services/api/v1/issues/delete_service.rb | 12 +- .../api/v1/issues/journals/create_service.rb | 48 ++++ .../api/v1/issues/journals/list_service.rb | 52 +++++ app/services/api/v1/issues/list_service.rb | 1 - app/services/api/v1/issues/update_service.rb | 209 +++++++++++------- app/services/application_service.rb | 9 + app/views/api/v1/issues/index.json.jbuilder | 4 +- .../journals/_children_detail.json.jbuilder | 17 ++ .../v1/issues/journals/_detail.json.jbuilder | 20 ++ .../v1/issues/journals/create.json.jbuilder | 1 + .../v1/issues/journals/index.json.jbuilder | 4 + config/routes/api.rb | 8 + 17 files changed, 446 insertions(+), 139 deletions(-) create mode 100644 app/controllers/api/v1/issues/journals_controller.rb create mode 100644 app/services/api/v1/issues/journals/create_service.rb create mode 100644 app/services/api/v1/issues/journals/list_service.rb create mode 100644 app/views/api/v1/issues/journals/_children_detail.json.jbuilder create mode 100644 app/views/api/v1/issues/journals/_detail.json.jbuilder create mode 100644 app/views/api/v1/issues/journals/create.json.jbuilder create mode 100644 app/views/api/v1/issues/journals/index.json.jbuilder diff --git a/app/controllers/api/v1/issues/journals_controller.rb b/app/controllers/api/v1/issues/journals_controller.rb new file mode 100644 index 000000000..c3185a755 --- /dev/null +++ b/app/controllers/api/v1/issues/journals_controller.rb @@ -0,0 +1,39 @@ +class Api::V1::Issues::JournalsController < Api::V1::IssuesController + + before_action :require_public_and_member_above, only: [:index, :create, :destroy] + before_action :load_issue, only: [:index, :create, :destroy] + before_action :load_journal, only: [:destroy] + + def index + @object_results = Api::V1::Issues::Journals::ListService.call(@issue, query_params, current_user) + @journals = kaminari_paginate(@object_results) + end + + def create + @object_result = Api::V1::Issues::Journals::CreateService.call(@issue, journal_params, current_user) + end + + def destroy + if @journal.destroy! + render_ok + else + render_error("删除评论失败!") + end + end + + private + + def query_params + params.permit(:category, :keyword, :sort_by, :sort_direction) + end + + def journal_params + params.permit(:notes, :parent_id, :attachment_ids => []) + end + + def load_journal + @journal = @issue.journals.find_by_id(params[:id]) + return render_not_found("评论不存在!") unless @journal.present? + end + +end \ No newline at end of file diff --git a/app/controllers/api/v1/issues_controller.rb b/app/controllers/api/v1/issues_controller.rb index 567ef6b3b..d1f8a83a1 100644 --- a/app/controllers/api/v1/issues_controller.rb +++ b/app/controllers/api/v1/issues_controller.rb @@ -4,6 +4,9 @@ class Api::V1::IssuesController < Api::V1::BaseController def index @object_results = Api::V1::Issues::ListService.call(@project, query_params, current_user) + @opened_issues_count = @object_results.opened.size + @closed_issues_count = @object_results.closed.size + @issues = kaminari_paginate(@object_results) end @@ -49,6 +52,31 @@ class Api::V1::IssuesController < Api::V1::BaseController end end + protected + + def load_issue + @issue = @project.issues.where(project_issues_index: params[:id]).where.not(id: params[:id]).take || Issue.find_by_id(params[:id]) + if @issue.blank? + render_not_found("疑修不存在!") + elsif @issue.present? && @issue.is_lock &&!(@project.member?(current_user) || current_user.admin?) + render_forbidden("您没有权限操作!") + end + end + + def load_issues + return render_error("请输入正确的ID数组!") unless params[:ids].is_a?(Array) + params[:ids].each do |id| + @issue = Issue.find_by_id(id) + if @issue.blank? + return render_not_found("ID为#{id}的疑修不存在!") + elsif @issue.present? && @issue.is_lock &&!(@project.member?(current_user) || current_user.admin?) + return render_forbidden("ID为#{id}的疑修您没有权限操作!") + end + end + @issues = Issue.where(id: params[:ids]) + end + + private def query_params @@ -79,27 +107,4 @@ class Api::V1::IssuesController < Api::V1::BaseController :issue_tag_ids => [], :assigner_ids => []) end - - def load_issue - @issue = @project.issues.where(project_issues_index: params[:id]).where.not(id: params[:id]).take || Issue.find_by_id(params[:id]) - if @issue.blank? - render_not_found("疑修不存在!") - elsif @issue.present? && @issue.is_lock &&!(@project.member?(current_user) || current_user.admin?) - render_forbidden("您没有权限操作!") - end - end - - def load_issues - return render_error("请输入正确的ID数组!") unless params[:ids].is_a?(Array) - params[:ids].each do |id| - @issue = Issue.find_by_id(id) - if @issue.blank? - return render_not_found("ID为#{id}的疑修不存在!") - elsif @issue.present? && @issue.is_lock &&!(@project.member?(current_user) || current_user.admin?) - return render_forbidden("ID为#{id}的疑修您没有权限操作!") - end - end - @issues = Issue.where(id: params[:ids]) - end - end \ No newline at end of file diff --git a/app/models/journal.rb b/app/models/journal.rb index 20297dd99..382ebd017 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -40,8 +40,11 @@ class Journal < ApplicationRecord belongs_to :journalized, polymorphic: true belongs_to :review, optional: true belongs_to :resolveer, class_name: 'User', foreign_key: :resolveer_id, optional: true + belongs_to :parent_journal, class_name: 'Journal', foreign_key: :parent_id, optional: true + belongs_to :reply_journal, class_name: 'Journal', foreign_key: :reply_id, optional: true has_many :journal_details, :dependent => :delete_all has_many :attachments, as: :container, dependent: :destroy + has_many :first_ten_children_journals, -> { order(created_on: :asc).limit(10)}, class_name: 'Journal', foreign_key: :parent_id has_many :children_journals, class_name: 'Journal', foreign_key: :parent_id scope :journal_includes, ->{includes(:user, :journal_details, :attachments)} @@ -54,6 +57,81 @@ class Journal < ApplicationRecord self.notes.blank? && self.journal_details.present? end + def operate_content + content = "" + detail = self.journal_details.take + case detail.property + when 'issue' + return "创建了疑修" + when 'attachment' + old_value = Attachment.where(id: detail.old_value.split(",")).pluck(:filename).join("、") + new_value = Attachment.where(id: detail.value.split(",")).pluck(:filename).join("、") + if old_value.nil? || old_value.blank? + content += "添加了#{new_value}附件" + else + new_value = "无" if new_value.blank? + content += "将附件由#{old_value}更改为#{new_value}" + end + when 'issue_tag' + old_value = IssueTag.where(id: detail.old_value.split(",")).pluck(:name, :color).map{|t| "#{t[0]}"}.join(" ") + new_value = IssueTag.where(id: detail.value.split(",")).pluck(:name, :color).map{|t| "#{t[0]}"}.join(" ") + if old_value.nil? || old_value.blank? + content += "添加了#{new_value}标记" + else + new_value = "无" if new_value.blank? + content += "将标记由#{old_value}更改为#{new_value}" + end + when 'assigner' + old_value = User.where(id: detail.old_value.split(",")).pluck(:nickname).join("、") + new_value = User.where(id: detail.value.split(",")).pluck(:nickname).join("、") + if old_value.nil? || old_value.blank? + content += "添加负责人#{new_value}" + else + new_value = "无" if new_value.blank? + content += "将负责人由#{old_value}更改为#{new_value}" + end + when 'attr' + content = "将" + case detail.prop_key + when 'subject' + return "修改了标题" + when 'description' + return "修改了描述" + when 'status_id' + old_value = IssueStatus.find_by_id(detail.old_value)&.name + new_value = IssueStatus.find_by_id(detail.value)&.name + content += "状态" + when 'priority_id' + old_value = IssuePriority.find_by_id(detail.old_value)&.name + new_value = IssuePriority.find_by_id(detail.value)&.name + content += "优先级" + when 'fixed_version_id' + old_value = Version.find_by_id(detail.old_value)&.name + new_value = Version.find_by_id(detail.value)&.name + content += "里程碑" + when 'branch_name' + old_value = detail.old_value + new_value = detail.value + content += "关联分支" + when 'start_date' + old_value = detail.old_value + new_value = detail.value + content += "开始日期" + when 'due_date' + old_value = detail.old_value + new_value = detail.value + content += "结束日期" + end + if old_value.nil? || old_value.blank? + content += "设置为#{new_value}" + else + new_value = "无" if new_value.blank? + content += "由#{old_value}更改为#{new_value}" + end + end + + end + def journal_content send_details = [] if self.is_journal_detail? diff --git a/app/services/api/v1/issues/batch_delete_service.rb b/app/services/api/v1/issues/batch_delete_service.rb index 133f098cd..45821b373 100644 --- a/app/services/api/v1/issues/batch_delete_service.rb +++ b/app/services/api/v1/issues/batch_delete_service.rb @@ -13,7 +13,7 @@ class Api::V1::Issues::BatchDeleteService < ApplicationService def call raise Error, errors.full_messages.join(", ") unless valid? - try_lock # 开始写数据,加锁 + try_lock("Api::V1::Issues::DeleteService:#{project.id}") # 开始写数据,加锁 delete_issues @@ -25,7 +25,7 @@ class Api::V1::Issues::BatchDeleteService < ApplicationService end end - unlock + unlock("Api::V1::Issues::DeleteService:#{project.id}") return true end @@ -35,13 +35,4 @@ class Api::V1::Issues::BatchDeleteService < ApplicationService def delete_issues raise Error, "批量删除疑修失败!" unless @issues.destroy_all end - - def try_lock - raise Error, "请稍后再试!" unless $redis_cache.set("Api::V1::Issues::BatchDeleteService:#{project.id}", 1, nx: true, ex: 60.seconds) - end - - def unlock - $redis_cache.del("Api::V1::Issues::BatchDeleteService:#{project.id}") - end - end \ No newline at end of file diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index e87745950..f5d9c7fa6 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -43,10 +43,11 @@ class Api::V1::Issues::CreateService < ApplicationService load_issue_tags(issue_tag_ids) unless issue_tag_ids.blank? load_atme_receivers(receivers_login) unless receivers_login.blank? - try_lock # 开始写数据,加锁 + try_lock("Api::V1::Issues::CreateService:#{project.id}") # 开始写数据,加锁 @created_issue = Issue.new(issue_attributes) build_author_participants build_assigner_participants unless assigner_ids.blank? + build_atme_participants if @atme_receivers.present? build_issue_journal_details build_issue_project_trends @created_issue.attachments = @attachments unless attachment_ids.blank? @@ -64,7 +65,7 @@ class Api::V1::Issues::CreateService < ApplicationService SendTemplateMessageJob.perform_later('ProjectIssue', current_user.id, @issue&.id) end - unlock # 结束写数据,解锁 + unlock("Api::V1::Issues::CreateService:#{project.id}") # 结束写数据,解锁 end return @created_issue @@ -104,6 +105,12 @@ class Api::V1::Issues::CreateService < ApplicationService end end + def build_atme_participants + atme_receivers.each do |receiver| + @created_issue.issue_participants.new({participant_type: "atme", participant_id: receiver.id}) + end + end + def build_issue_project_trends @created_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: "create"}) @created_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE}) if status_id.to_i == 5 @@ -113,12 +120,4 @@ class Api::V1::Issues::CreateService < ApplicationService journal = @created_issue.journals.new({user_id: current_user.id}) journal.journal_details.new({property: "issue", prop_key: 1, old_value: '', value: ''}) end - - def try_lock - raise Error, "请稍后再试!" unless $redis_cache.set("Api::V1::Issues::CreateService:#{project.id}", 1, nx: true, ex: 60.seconds) - end - - def unlock - $redis_cache.del("Api::V1::Issues::CreateService:#{project.id}") - end end \ No newline at end of file diff --git a/app/services/api/v1/issues/delete_service.rb b/app/services/api/v1/issues/delete_service.rb index e6429390e..a34fdced6 100644 --- a/app/services/api/v1/issues/delete_service.rb +++ b/app/services/api/v1/issues/delete_service.rb @@ -13,7 +13,7 @@ class Api::V1::Issues::DeleteService < ApplicationService def call raise Error, errors.full_messages.join(", ") unless valid? - try_lock # 开始写数据,加锁 + try_lock("Api::V1::Issues::DeleteService:#{project.id}") # 开始写数据,加锁 delete_issue @@ -23,7 +23,7 @@ class Api::V1::Issues::DeleteService < ApplicationService SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, @issue&.subject, @issue.assigners.pluck(:id), @issue.author_id) end - unlock + unlock("Api::V1::Issues::DeleteService:#{project.id}") return true end @@ -34,12 +34,4 @@ class Api::V1::Issues::DeleteService < ApplicationService raise Error, "删除疑修失败!" unless issue.destroy! end - def try_lock - raise Error, "请稍后再试!" unless $redis_cache.set("Api::V1::Issues::DeleteService:#{project.id}", 1, nx: true, ex: 60.seconds) - end - - def unlock - $redis_cache.del("Api::V1::Issues::DeleteService:#{project.id}") - end - end \ No newline at end of file diff --git a/app/services/api/v1/issues/journals/create_service.rb b/app/services/api/v1/issues/journals/create_service.rb new file mode 100644 index 000000000..6fe096426 --- /dev/null +++ b/app/services/api/v1/issues/journals/create_service.rb @@ -0,0 +1,48 @@ +class Api::V1::Issues::Journals::CreateService < ApplicationService + include ActiveModel::Model + + attr_reader :issue, :current_user, :notes, :parent_id, :attachment_ids + + validates :issue, :current_user, presence: true + + def initialize(issue, params, current_user=nil) + @issue = issue + @notes = params[:notes] + @parent_id = params[:parent_id] + @attachment_ids = params[:attachment_ids] + @current_user = current_user + end + + def call + raise Error, errors.full_messages.join(", ") unless valid? + ActiveRecord::Base.transaction do + check_attachments(attachment_ids) unless attachment_ids.blank? + load_attachments(attachment_ids) unless attachment_ids.blank? + + try_lock("Api::V1::Issues::Journals::CreateService:#{@issue.id}") + @created_journal = Journal.new(journal_attributes) + + build_comment_participants + @created_journal.attachments = @attachments + + @created_journal.save! + unlock("Api::V1::Issues::Journals::CreateService:#{@issue.id}") + end + end + + private + + def journal_attributes + journal_attributes = { + notes: notes + } + + journal_attributes.merge!({parent_id: parent_id}) if parent_id.present? + + journal_attributes + end + + def build_comment_participants + @issue.issue_participants.new({participant_type: "commented", participant_id: current_user.id}) unless @issue.issue_participants.exists?(participant_type: "commented", participant_id: current_user.id) + end +end \ No newline at end of file diff --git a/app/services/api/v1/issues/journals/list_service.rb b/app/services/api/v1/issues/journals/list_service.rb new file mode 100644 index 000000000..02f709e55 --- /dev/null +++ b/app/services/api/v1/issues/journals/list_service.rb @@ -0,0 +1,52 @@ +class Api::V1::Issues::Journals::ListService < ApplicationService + + include ActiveModel::Model + + attr_reader :issue, :category, :keyword, :sort_by, :sort_direction + attr_accessor :queried_journals + + validates :category, inclusion: {in: %w(all comment operate), message: "请输入正确的Category"} + validates :sort_by, inclusion: {in: Journal.column_names, message: '请输入正确的SortBy'}, allow_blank: true + validates :sort_direction, inclusion: {in: %w(asc desc), message: '请输入正确的SortDirection'}, allow_blank: true + + def initialize(issue, params, current_user=nil) + @issue = issue + @keyword = params[:keyword] + @category = params[:category] || 'all' + @sort_by = params[:sort_by].present? ? params[:sort_by] : 'created_on' + @sort_direction = (params[:sort_direction].present? ? params[:sort_direction] : 'asc').downcase + end + + def call + raise Error, errors.full_messages.join(", ") unless valid? + begin + journal_query_data + + @queried_journals + rescue + raise Error, "服务器错误,请联系系统管理员!" + end + end + + private + def journal_query_data + + @queried_journals = issue.journals + + case category + when 'comment' + @queried_journals = issue.comment_journals + when 'operate' + @queried_journals = issue.operate_journals + end + + @queried_journals = @queried_journals.parent_journals + + @queried_journals = @queried_journals.ransack(notes_cont: keyword).result if keyword.present? + + @queried_journals = @queried_journals.includes(:journal_details, :user, :attachments, first_ten_children_journals: [:parent_journal, :reply_journal]) + @queried_journals = @queried_journals.reorder("journals.#{sort_by} #{sort_direction}").distinct + + @queried_journals + end +end \ No newline at end of file diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index a5609bb62..6383a6e12 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -79,7 +79,6 @@ class Api::V1::Issues::ListService < ApplicationService scope = q.result.includes(:priority, :issue_status, :user, :assigners, :version, :issue_tags, :comment_journals) - scope = scope.reorder("issues.#{sort_by} #{sort_direction}").distinct @queried_issues = scope diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 3084e78a9..8abc6aae4 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -6,7 +6,7 @@ class Api::V1::Issues::UpdateService < ApplicationService attr_reader :project, :issue, :current_user attr_reader :status_id, :priority_id, :milestone_id, :branch_name, :start_date, :due_date, :subject, :description attr_reader :issue_tag_ids, :assigner_ids, :attachment_ids, :receivers_login - attr_accessor :add_assigner_ids, :previous_issue_changes, :updated_issue + attr_accessor :add_assigner_ids, :previous_issue_changes, :updated_issue, :atme_receivers validates :project, :issue, :current_user, presence: true @@ -40,23 +40,29 @@ class Api::V1::Issues::UpdateService < 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? - load_assigners(assigner_ids) unless assigner_ids.blank? - load_attachments(attachment_ids) unless attachment_ids.blank? - load_issue_tags(issue_tag_ids) unless issue_tag_ids.blank? + load_assigners(assigner_ids) + load_attachments(attachment_ids) + load_issue_tags(issue_tag_ids) load_atme_receivers(receivers_login) unless receivers_login.blank? - try_lock + try_lock("Api::V1::Issues::UpdateService:#{project.id}:#{issue.id}") @updated_issue = @issue issue_load_attributes - build_issue_journal_details if @updated_issue.previous_changes.present? # 操作记录 + build_assigner_issue_journal_details unless assigner_ids.nil?# 操作记录 + build_attachment_issue_journal_details unless attachment_ids.nil? + build_issue_tag_issue_journal_details unless issue_tag_ids.nil? build_issue_project_trends if status_id.present? # 开关时间记录 - build_assigner_participants unless assigner_ids.blank? # 负责人 - @updated_issue.assigners = @assigners unless assigner_ids.blank? - @updated_issue.attachments = @attachments unless attachment_ids.blank? - @updated_issue.issue_tags = @issue_tags unless issue_tag_ids.blank? - + build_assigner_participants unless assigner_ids.nil? # 负责人 + build_edit_participants + build_atme_participants if @atme_receivers.present? + @updated_issue.assigners = @assigners || User.none unless assigner_ids.nil? + @updated_issue.attachments = @attachments || Attachment.none unless attachment_ids.nil? + @updated_issue.issue_tags = @issue_tags || IssueTag.none unless issue_tag_ids.nil? + + @updated_issue.updated_on = Time.now @updated_issue.save! + build_after_issue_journal_details if @updated_issue.previous_changes.present? # 操作记录 build_previous_issue_changes # @信息发送 @@ -67,7 +73,7 @@ class Api::V1::Issues::UpdateService < ApplicationService SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id, add_assigner_ids) unless add_assigner_ids.blank? end - unlock + unlock("Api::V1::Issues::UpdateService:#{project.id}:#{issue.id}") return @updated_issue end @@ -87,108 +93,147 @@ class Api::V1::Issues::UpdateService < ApplicationService end def build_assigner_participants - @updated_issue.issue_participants.where(participant_type: "assigned").where.not(participant_id: assigner_ids).each(&:destroy!) - assigner_ids.each do |aid| - next if @updated_issue.issue_participants.exists?(participant_type: "assigned", participant_id: aid) - @updated_issue.issue_participants.new({participant_type: "assigned", participant_id: aid}) - @add_assigner_ids << aid + if assigner_ids.blank? + @updated_issue.issue_participants.where(participant_type: "assigned").each(&:destroy!) + else + @updated_issue.issue_participants.where(participant_type: "assigned").where.not(participant_id: assigner_ids).each(&:destroy!) + assigner_ids.each do |aid| + next if @updated_issue.issue_participants.exists?(participant_type: "assigned", participant_id: aid) + @updated_issue.issue_participants.new({participant_type: "assigned", participant_id: aid}) + @add_assigner_ids << aid + end + end + end + + def build_edit_participants + @updated_issue.issue_participants.new({participant_type: "edited", participant_id: current_user.id}) unless @updated_issue.issue_participants.exists?(participant_type: "edited", participant_id: current_user.id) + end + + def build_atme_participants + atme_receivers.each do |receiver| + next if @updated_issue.issue_participants.exists?(participant_type: "atme", participant_id: receiver.id) + @updated_issue.issue_participants.new({participant_type: "atme", participant_id: receiver.id}) end end def build_previous_issue_changes @previous_issue_changes = @updated_issue.previous_changes.except("updated_on", "created_on") - if @updated_issue.previous_changes[:start_date].present? - @previous_issue_changes.merge!(start_date: [@updated_issue.previous_changes[:start_date][0].to_s, @updated_issue.previous_changes[:start_date][1].to_s]) + if @updated_issue.previous_changes["start_date"].present? + @previous_issue_changes.merge!(start_date: [@updated_issue.previous_changes["start_date"][0].to_s, @updated_issue.previous_changes["start_date"][1].to_s]) end - if @updated_issue.previous_changes[:due_date].present? - @previous_issue_changes.merge!(due_date: [@updated_issue.previous_changes[:due_date][0].to_s, @updated_issue.previous_changes[:due_date][1].to_s]) + if @updated_issue.previous_changes["due_date"].present? + @previous_issue_changes.merge!(due_date: [@updated_issue.previous_changes["due_date"][0].to_s, @updated_issue.previous_changes["due_date"][1].to_s]) end end def build_issue_project_trends - if @updated_issue.previous_changes[:status_id].present? && @updated_issue.previous_changes[:status_id][1] == 5 + if @updated_issue.previous_changes["status_id"].present? && @updated_issue.previous_changes["status_id"][1] == 5 @updated_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE}) end - if @updated_issue.previous_changes[:status_id].present? && @updated_issue.previous_changes[:status_id][0] == 5 + if @updated_issue.previous_changes["status_id"].present? && @updated_issue.previous_changes["status_id"][0] == 5 @updated_issue.project_trends.where(action_type: ProjectTrend::CLOSE).each(&:destroy!) end end - def build_issue_journal_details - # 更改标题 - if @updated_issue.previous_changes[:subject].present? - journal = @updated_issue.journals.new({user_id: current_user.id}) - journal.journal_details.new({property: "attr", prop_key: "subject", old_value: @updated_issue.previous_changes[:subject][0], value: @updated_issue.previous_changes[:subject][1]}) - end + def build_after_issue_journal_details + begin + # 更改标题 + if @updated_issue.previous_changes["subject"].present? + journal = @updated_issue.journals.create!({user_id: current_user.id}) + journal.journal_details.create!({property: "attr", prop_key: "subject", old_value: @updated_issue.previous_changes["subject"][0], value: @updated_issue.previous_changes["subject"][1]}) + end - # 更改描述 - if @updated_issue.previous_changes[:description].present? - journal = @updated_issue.journals.new({user_id: current_user.id}) - journal.journal_details.new({property: "attr", prop_key: "description", old_value: @updated_issue.previous_changes[:description][0], value: @updated_issue.previous_changes[:description][1]}) - end + # 更改描述 + if @updated_issue.previous_changes["description"].present? + journal = @updated_issue.journals.create!({user_id: current_user.id}) + journal.journal_details.create!({property: "attr", prop_key: "description", old_value: @updated_issue.previous_changes["description"][0], value: @updated_issue.previous_changes["description"][1]}) + end - # 修改状态 - if @updated_issue.previous_changes[:status_id].present? - journal = @updated_issue.journals.new({user_id: current_user.id}) - journal.journal_details.new({property: "attr", prop_key: "status_id", old_value: @updated_issue.previous_changes[:status_id][0], value: @updated_issue.previous_changes[:status_id][1]}) - end + # 修改状态 + if @updated_issue.previous_changes["status_id"].present? + journal = @updated_issue.journals.create!({user_id: current_user.id}) + journal.journal_details.create!({property: "attr", prop_key: "status_id", old_value: @updated_issue.previous_changes["status_id"][0], value: @updated_issue.previous_changes["status_id"][1]}) + end - # 修改优先级 - if @updated_issue.previous_changes[:priority_id].present? - journal = @updated_issue.journals.new({user_id: current_user.id}) - journal.journal_details.new({property: "attr", prop_key: "priority_id", old_value: @updated_issue.previous_changes[:priority_id][0], value: @updated_issue.previous_changes[:priority_id][1]}) - end + # 修改优先级 + if @updated_issue.previous_changes["priority_id"].present? + journal = @updated_issue.journals.create!({user_id: current_user.id}) + journal.journal_details.create!({property: "attr", prop_key: "priority_id", old_value: @updated_issue.previous_changes["priority_id"][0], value: @updated_issue.previous_changes["priority_id"][1]}) + end - # 修改里程碑 - if @updated_issue.previous_changes[:fixed_version_id].present? - journal = @updated_issue.journals.new({user_id: current_user.id}) - journal.journal_details.new({property: "attr", prop_key: "fixed_version_id", old_value: @updated_issue.previous_changes[:fixed_version_id][0], value: @updated_issue.previous_changes[:fixed_version_id][1]}) - end + # 修改里程碑 + if @updated_issue.previous_changes["fixed_version_id"].present? + journal = @updated_issue.journals.create!({user_id: current_user.id}) + journal.journal_details.create!({property: "attr", prop_key: "fixed_version_id", old_value: @updated_issue.previous_changes["fixed_version_id"][0], value: @updated_issue.previous_changes["fixed_version_id"][1]}) + end - # 更改分支 - if @updated_issue.previous_changes[:branch_name].present? - journal = @updated_issue.journals.new({user_id: current_user.id}) - journal.journal_details.new({property: "attr", prop_key: "branch_name", old_value: @updated_issue.previous_changes[:branch_name][0], value: @updated_issue.previous_changes[:branch_name][1]}) - end + # 更改分支 + if @updated_issue.previous_changes["branch_name"].present? + journal = @updated_issue.journals.create!({user_id: current_user.id}) + journal.journal_details.create!({property: "attr", prop_key: "branch_name", old_value: @updated_issue.previous_changes["branch_name"][0], value: @updated_issue.previous_changes["branch_name"][1]}) + end - # 更改开始时间 - if @updated_issue.previous_changes[:start_date].present? - journal = @updated_issue.journals.new({user_id: current_user.id}) - journal.journal_details.new({property: "attr", prop_key: "start_date", old_value: @updated_issue.previous_changes[:start_date][0], value: @updated_issue.previous_changes[:start_date][1]}) - end + # 更改开始时间 + if @updated_issue.previous_changes["start_date"].present? + journal = @updated_issue.journals.create!({user_id: current_user.id}) + journal.journal_details.create!({property: "attr", prop_key: "start_date", old_value: @updated_issue.previous_changes["start_date"][0], value: @updated_issue.previous_changes["start_date"][1]}) + end - # 更改结束时间 - if @updated_issue.previous_changes[:due_date].present? - journal = @updated_issue.journals.new({user_id: current_user.id}) - journal.journal_details.new({property: "attr", prop_key: "due_date", old_value: @updated_issue.previous_changes[:due_date][0], value: @updated_issue.previous_changes[:due_date][1]}) + # 更改结束时间 + if @updated_issue.previous_changes["due_date"].present? + journal = @updated_issue.journals.create!({user_id: current_user.id}) + journal.journal_details.create!({property: "attr", prop_key: "due_date", old_value: @updated_issue.previous_changes["due_date"][0], value: @updated_issue.previous_changes["due_date"][1]}) + end + rescue + raise Error, "创建操作记录失败!" end + end - # 更改负责人 - if !@updated_issue.assigners.pluck(:id).sort! == assigner_ids.sort! - journal = @updated_issue.journals.new({user_id: current_user.id}) - journal.journal_details.new({property: "assigner", prop_key: "#{assigner_ids.size}", old_value: @updated_issue.assigners.pluck(:nickname).join(","), value: @assigners.pluck(:nickname).join(",")}) - end + def build_assigner_issue_journal_details + begin + # 更改负责人 + new_assigner_ids = @assigner_ids + new_assigner_ids = [] if @assigner_ids.nil? + now_assigner_ids = @updated_issue.assigners.pluck(:id) + if !(now_assigner_ids & assigner_ids).empty? || !(now_assigner_ids.empty? && new_assigner_ids.empty?) + journal = @updated_issue.journals.create!({user_id: current_user.id}) + journal.journal_details.create!({property: "assigner", prop_key: "#{new_assigner_ids.size}", old_value: now_assigner_ids.join(","), value: new_assigner_ids.join(",")}) + end - # 更改标记 - if !@updated_issue.issue_tags.pluck(:id).sort! == issue_tag_ids.sort! - journal = @updated_issue.journals.new({user_id: current_user.id}) - journal.journal_details.new({property: "issue_tag", prop_key: "#{issue_tag_ids.size}", old_value: @updated_issue.issue_tags.pluck(:name).join(","), value: @issue_tags.pluck(:name).join(",")}) + rescue + raise Error, "创建操作记录失败!" end + end - # 更改附件 - if !@updated_issue.attachments.pluck(:id).sort! == attachment_ids.sort! - journal = @updated_issue.journals.new({user_id: current_user.id}) - journal.journal_details.new({property: "attachment", prop_key: "#{attachment_ids.size}", old_value: @updated_issue.attachments.pluck(:filename).join(","), value: @attachments.pluck(:filename).join(",")}) + def build_issue_tag_issue_journal_details + begin + # 更改标记 + new_issue_tag_ids = @issue_tag_ids + new_issue_tag_ids = [] if @issue_tag_ids.nil? + now_issue_tag_ids = @updated_issue.issue_tags.pluck(:id) + if !(now_issue_tag_ids & new_issue_tag_ids).empty? || !(now_issue_tag_ids.empty? && new_issue_tag_ids.empty?) + journal = @updated_issue.journals.create!({user_id: current_user.id}) + journal.journal_details.create!({property: "issue_tag", prop_key: "#{new_issue_tag_ids.size}", old_value: now_issue_tag_ids.join(","), value: new_issue_tag_ids.join(",")}) + end + rescue + raise Error, "创建操作记录失败!" end end - def try_lock - raise Error, "请稍后再试!" unless $redis_cache.set("Api::V1::Issues::UpdateService:#{project.id}:#{issue.id}", 1, nx: true, ex: 60.seconds) - end - def unlock - $redis_cache.del("Api::V1::Issues::UpdateService:#{project.id}:#{issue.id}") + def build_attachment_issue_journal_details + begin + # 更改附件 + new_attachment_ids = @attachment_ids + new_attachment_ids = [] if @attachment_ids.nil? + now_attachment_ids = @updated_issue.attachments.pluck(:id) + if !(now_attachment_ids & new_attachment_ids).empty? || !(now_attachment_ids.empty? && new_attachment_ids.empty?) + journal = @updated_issue.journals.create!({user_id: current_user.id}) + journal.journal_details.create!({property: "attachment", prop_key: "#{new_attachment_ids.size}", old_value: now_attachment_ids.join(","), value: new_attachment_ids.join(",")}) + end + rescue + raise Error, "创建操作记录失败!" + end end - end \ No newline at end of file diff --git a/app/services/application_service.rb b/app/services/application_service.rb index 2fa59ed29..93f7ed48c 100644 --- a/app/services/application_service.rb +++ b/app/services/application_service.rb @@ -9,6 +9,15 @@ class ApplicationService content.gsub(regex, '') end + protected + def try_lock(key) + raise Error, "请稍后再试!" unless $redis_cache.set(key, 1, nx: true, ex: 60.seconds) + end + + def unlock(key) + $redis_cache.del(key) + end + private def strip(str) diff --git a/app/views/api/v1/issues/index.json.jbuilder b/app/views/api/v1/issues/index.json.jbuilder index 3e820f6f4..1a324eb27 100644 --- a/app/views/api/v1/issues/index.json.jbuilder +++ b/app/views/api/v1/issues/index.json.jbuilder @@ -1,6 +1,6 @@ json.total_count @issues.total_count -json.opened_count @issues.opened.size -json.closed_count @issues.closed.size +json.opened_count @opened_issues_count +json.closed_count @closed_issues_count json.issues @issues.each do |issue| json.partial! "simple_detail", locals: {issue: issue} end \ No newline at end of file diff --git a/app/views/api/v1/issues/journals/_children_detail.json.jbuilder b/app/views/api/v1/issues/journals/_children_detail.json.jbuilder new file mode 100644 index 000000000..38bbda404 --- /dev/null +++ b/app/views/api/v1/issues/journals/_children_detail.json.jbuilder @@ -0,0 +1,17 @@ +json.(journal, :id, :notes, :comments_count) +json.created_at journal.created_on.strftime("%Y-%m-%d %H:%M") +json.updated_at journal.updated_on.strftime("%Y-%m-%d %H:%M") +json.user do + if journal.user.present? + json.partial! "api/v1/users/simple_user", user: journal.user + else + json.nil! + end +end +json.reply_user do + if journal.reply_journal&.user&.present? + json.partial! "api/v1/users/simple_user", user: journal.reply_journal.user + else + json.nil! + end +end \ No newline at end of file diff --git a/app/views/api/v1/issues/journals/_detail.json.jbuilder b/app/views/api/v1/issues/journals/_detail.json.jbuilder new file mode 100644 index 000000000..418da24a8 --- /dev/null +++ b/app/views/api/v1/issues/journals/_detail.json.jbuilder @@ -0,0 +1,20 @@ +json.id journal.id +json.is_journal_detail journal.is_journal_detail? +json.created_at journal.created_on.strftime("%Y-%m-%d %H:%M") +json.updated_at journal.updated_on.strftime("%Y-%m-%d %H:%M") +json.user do + if journal.user.present? + json.partial! "api/v1/users/simple_user", user: journal.user + else + json.nil! + end +end +if journal.is_journal_detail? + json.operate_content journal.is_journal_detail? ? journal.operate_content : nil +else + json.notes journal.notes + json.comments_count journal.comments_count + json.children_journals journal.first_ten_children_journals.each do |journal| + json.partial! "children_detail", journal: journal + end +end diff --git a/app/views/api/v1/issues/journals/create.json.jbuilder b/app/views/api/v1/issues/journals/create.json.jbuilder new file mode 100644 index 000000000..91f3f3174 --- /dev/null +++ b/app/views/api/v1/issues/journals/create.json.jbuilder @@ -0,0 +1 @@ +json.partial! "detail", journal: @object_result \ No newline at end of file diff --git a/app/views/api/v1/issues/journals/index.json.jbuilder b/app/views/api/v1/issues/journals/index.json.jbuilder new file mode 100644 index 000000000..bea6746a6 --- /dev/null +++ b/app/views/api/v1/issues/journals/index.json.jbuilder @@ -0,0 +1,4 @@ +json.total_count @journals.total_count +json.journals @journals do |journal| + json.partial! "detail", journal: journal +end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index 15ebc44f1..6c9b3dcdf 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -30,6 +30,14 @@ defaults format: :json do patch :batch_update delete :batch_destroy end + + member do + resources :journals, module: :issues, only: [:index, :create, :update, :destroy] do + member do + get :children_journals + end + end + end end scope module: :issues do resources :issue_tags, except: [:new, :edit] From df38df45d5427097fa0ed953591f6ca4d41615cc Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 17 Feb 2023 17:24:27 +0800 Subject: [PATCH 017/438] =?UTF-8?q?fixed=20=E5=90=91jianmu=E6=8E=A8?= =?UTF-8?q?=E9=80=81=E6=97=B6=E9=A1=B9=E7=9B=AE=E4=B8=8D=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E6=97=B6=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/open_project_dev_ops_job.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/jobs/open_project_dev_ops_job.rb b/app/jobs/open_project_dev_ops_job.rb index 64115f25f..b3fe99e6f 100644 --- a/app/jobs/open_project_dev_ops_job.rb +++ b/app/jobs/open_project_dev_ops_job.rb @@ -5,6 +5,7 @@ class OpenProjectDevOpsJob < ApplicationJob def perform(project_id, user_id) project = Project.find_by(id: project_id) + return if project.blank? user = User.find_by(id: user_id) code = jianmu_devops_code(project, user) uri = URI.parse("#{jianmu_devops_url}/activate?code=#{URI.encode_www_form_component(code)}") From 15d71bfd24afe4e10297a8889389e993fb4d3d41 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 17 Feb 2023 17:40:09 +0800 Subject: [PATCH 018/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E6=95=B0=E6=8D=AE=E6=97=A0=E6=B3=95=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E8=B4=9F=E8=B4=A3=E4=BA=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 ++ 1 file changed, 2 insertions(+) diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index f5d9c7fa6..ffc08eb96 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -39,6 +39,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? + load_assigners(assigner_ids) unless assigner_ids.blank? load_attachments(attachment_ids) unless attachment_ids.blank? load_issue_tags(issue_tag_ids) unless issue_tag_ids.blank? load_atme_receivers(receivers_login) unless receivers_login.blank? @@ -50,6 +51,7 @@ class Api::V1::Issues::CreateService < ApplicationService build_atme_participants if @atme_receivers.present? build_issue_journal_details build_issue_project_trends + @created_issue.assigners = @assigners unless assigner_ids.blank? @created_issue.attachments = @attachments unless attachment_ids.blank? @created_issue.issue_tags = @issue_tags unless issue_tag_ids.blank? From c63a86a797059320b22f3939735a099c12dbf99e Mon Sep 17 00:00:00 2001 From: yystopf Date: Sat, 18 Feb 2023 23:23:33 +0800 Subject: [PATCH 019/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E8=AF=84?= =?UTF-8?q?=E8=AE=BA=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3=E8=A1=A5=E8=B6=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/issues/journals_controller.rb | 19 ++++++--- app/models/journal.rb | 2 +- .../api/v1/issues/concerns/checkable.rb | 3 ++ .../issues/journals/children_list_service.rb | 42 +++++++++++++++++++ .../api/v1/issues/journals/create_service.rb | 21 +++++++--- .../api/v1/issues/journals/update_service.rb | 37 ++++++++++++++++ .../journals/children_journals.json.jbuilder | 4 ++ .../v1/issues/journals/update.json.jbuilder | 1 + 8 files changed, 118 insertions(+), 11 deletions(-) create mode 100644 app/services/api/v1/issues/journals/children_list_service.rb create mode 100644 app/services/api/v1/issues/journals/update_service.rb create mode 100644 app/views/api/v1/issues/journals/children_journals.json.jbuilder create mode 100644 app/views/api/v1/issues/journals/update.json.jbuilder diff --git a/app/controllers/api/v1/issues/journals_controller.rb b/app/controllers/api/v1/issues/journals_controller.rb index c3185a755..55e820611 100644 --- a/app/controllers/api/v1/issues/journals_controller.rb +++ b/app/controllers/api/v1/issues/journals_controller.rb @@ -1,8 +1,8 @@ class Api::V1::Issues::JournalsController < Api::V1::IssuesController - before_action :require_public_and_member_above, only: [:index, :create, :destroy] - before_action :load_issue, only: [:index, :create, :destroy] - before_action :load_journal, only: [:destroy] + before_action :require_public_and_member_above, only: [:index, :create, :children_journals, :update, :destroy] + before_action :load_issue, only: [:index, :create, :children_journals, :update, :destroy] + before_action :load_journal, only: [:children_journals, :update, :destroy] def index @object_results = Api::V1::Issues::Journals::ListService.call(@issue, query_params, current_user) @@ -13,6 +13,15 @@ class Api::V1::Issues::JournalsController < Api::V1::IssuesController @object_result = Api::V1::Issues::Journals::CreateService.call(@issue, journal_params, current_user) end + def children_journals + @object_results = Api::V1::Issues::Journals::ChildrenListService.call(@issue, @journal, query_params, current_user) + @journals = kaminari_paginate(@object_results) + end + + def update + @object_result = Api::V1::Issues::Journals::UpdateService.call(@issue, @journal, journal_params, current_user) + end + def destroy if @journal.destroy! render_ok @@ -28,11 +37,11 @@ class Api::V1::Issues::JournalsController < Api::V1::IssuesController end def journal_params - params.permit(:notes, :parent_id, :attachment_ids => []) + params.permit(:notes, :parent_id, :reply_id, :attachment_ids => []) end def load_journal - @journal = @issue.journals.find_by_id(params[:id]) + @journal = Journal.find_by_id(params[:id]) return render_not_found("评论不存在!") unless @journal.present? end diff --git a/app/models/journal.rb b/app/models/journal.rb index 382ebd017..6472d559d 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -40,7 +40,7 @@ class Journal < ApplicationRecord belongs_to :journalized, polymorphic: true belongs_to :review, optional: true belongs_to :resolveer, class_name: 'User', foreign_key: :resolveer_id, optional: true - belongs_to :parent_journal, class_name: 'Journal', foreign_key: :parent_id, optional: true + belongs_to :parent_journal, class_name: 'Journal', foreign_key: :parent_id, optional: true, counter_cache: :comments_count belongs_to :reply_journal, class_name: 'Journal', foreign_key: :reply_id, optional: true has_many :journal_details, :dependent => :delete_all has_many :attachments, as: :container, dependent: :destroy diff --git a/app/services/api/v1/issues/concerns/checkable.rb b/app/services/api/v1/issues/concerns/checkable.rb index 8ac03f053..d013c3033 100644 --- a/app/services/api/v1/issues/concerns/checkable.rb +++ b/app/services/api/v1/issues/concerns/checkable.rb @@ -42,4 +42,7 @@ module Api::V1::Issues::Concerns::Checkable end end + def check_parent_journal(parent_id) + raise ApplicationService::Error, "ParentJournal不存在!" unless Journal.find_by_id(parent_id).present? + end end diff --git a/app/services/api/v1/issues/journals/children_list_service.rb b/app/services/api/v1/issues/journals/children_list_service.rb new file mode 100644 index 000000000..d46f9fbbe --- /dev/null +++ b/app/services/api/v1/issues/journals/children_list_service.rb @@ -0,0 +1,42 @@ +class Api::V1::Issues::Journals::ChildrenListService < ApplicationService + + include ActiveModel::Model + + attr_reader :issue, :journal, :keyword, :sort_by, :sort_direction + attr_accessor :queried_journals + + validates :sort_by, inclusion: {in: Journal.column_names, message: '请输入正确的SortBy'}, allow_blank: true + validates :sort_direction, inclusion: {in: %w(asc desc), message: '请输入正确的SortDirection'}, allow_blank: true + + + def initialize(issue, journal, params, current_user=nil) + @issue = issue + @journal = journal + @keyword = params[:keyword] + @sort_by = params[:sort_by].present? ? params[:sort_by] : 'created_on' + @sort_direction = (params[:sort_direction].present? ? params[:sort_direction] : 'asc').downcase + end + + def call + raise Error, errors.full_messages.join(", ") unless valid? + begin + journal_query_data + + return @queried_journals + rescue + raise Error, "服务器错误,请联系系统管理员!" + + end + end + + private + def journal_query_data + @queried_journals = journal.children_journals + + @queried_journals = @queried_journals.ransack(notes_cont: keyword).result if keyword.present? + @queried_journals = @queried_journals.includes(:user, :attachments, :reply_journal) + @queried_journals = @queried_journals.reorder("journals.#{sort_by} #{sort_direction}").distinct + + @queried_journals + end +end \ No newline at end of file diff --git a/app/services/api/v1/issues/journals/create_service.rb b/app/services/api/v1/issues/journals/create_service.rb index 6fe096426..6bd2479d9 100644 --- a/app/services/api/v1/issues/journals/create_service.rb +++ b/app/services/api/v1/issues/journals/create_service.rb @@ -1,32 +1,41 @@ class Api::V1::Issues::Journals::CreateService < ApplicationService include ActiveModel::Model + include Api::V1::Issues::Concerns::Checkable + include Api::V1::Issues::Concerns::Loadable - attr_reader :issue, :current_user, :notes, :parent_id, :attachment_ids + attr_reader :issue, :current_user, :notes, :parent_id, :reply_id, :attachment_ids + attr_accessor :created_journal - validates :issue, :current_user, presence: true + validates :notes, :issue, :current_user, presence: true def initialize(issue, params, current_user=nil) @issue = issue @notes = params[:notes] @parent_id = params[:parent_id] + @reply_id = params[:reply_id] @attachment_ids = params[:attachment_ids] @current_user = current_user end def call raise Error, errors.full_messages.join(", ") unless valid? + raise Error, "请输入回复的评论ID" if parent_id.present? && !reply_id.present? ActiveRecord::Base.transaction do + check_parent_journal(parent_id) if parent_id.present? + check_parent_journal(reply_id) if reply_id.present? check_attachments(attachment_ids) unless attachment_ids.blank? load_attachments(attachment_ids) unless attachment_ids.blank? try_lock("Api::V1::Issues::Journals::CreateService:#{@issue.id}") - @created_journal = Journal.new(journal_attributes) + @created_journal = @issue.journals.new(journal_attributes) build_comment_participants - @created_journal.attachments = @attachments + @created_journal.attachments = @attachments unless attachment_ids.blank? @created_journal.save! unlock("Api::V1::Issues::Journals::CreateService:#{@issue.id}") + + @created_journal end end @@ -34,10 +43,12 @@ class Api::V1::Issues::Journals::CreateService < ApplicationService def journal_attributes journal_attributes = { - notes: notes + notes: notes, + user_id: current_user.id } journal_attributes.merge!({parent_id: parent_id}) if parent_id.present? + journal_attributes.merge!({reply_id: reply_id}) if reply_id.present? journal_attributes end diff --git a/app/services/api/v1/issues/journals/update_service.rb b/app/services/api/v1/issues/journals/update_service.rb new file mode 100644 index 000000000..321c79cdb --- /dev/null +++ b/app/services/api/v1/issues/journals/update_service.rb @@ -0,0 +1,37 @@ +class Api::V1::Issues::Journals::UpdateService < ApplicationService + include ActiveModel::Model + include Api::V1::Issues::Concerns::Checkable + include Api::V1::Issues::Concerns::Loadable + + attr_reader :issue, :journal, :current_user, :notes, :attachment_ids + attr_accessor :updated_journal + + validates :notes, :issue, :journal, :current_user, presence: true + + def initialize(issue, journal, params, current_user=nil) + @issue = issue + @journal = journal + @notes = params[:notes] + @attachment_ids = params[:attachment_ids] + @current_user = current_user + end + + def call + raise Error, errors.full_messages.join(", ") unless valid? + ActiveRecord::Base.transaction do + check_attachments(attachment_ids) unless attachment_ids.blank? + load_attachments(attachment_ids) unless attachment_ids.blank? + + try_lock("Api::V1::Issues::Journals::UpdateService:#{@issue.id}:#{@journal.id}") + @updated_journal = @journal + @updated_journal.notes = notes + @updated_journal.attachments = @attachments unless attachment_ids.blank? + + @updated_journal.save! + unlock("Api::V1::Issues::Journals::UpdateService:#{@issue.id}:#{@journal.id}") + + @updated_journal + end + end + +end \ No newline at end of file diff --git a/app/views/api/v1/issues/journals/children_journals.json.jbuilder b/app/views/api/v1/issues/journals/children_journals.json.jbuilder new file mode 100644 index 000000000..c0cd04501 --- /dev/null +++ b/app/views/api/v1/issues/journals/children_journals.json.jbuilder @@ -0,0 +1,4 @@ +json.total_count @journals.total_count +json.journals @journals do |journal| + json.partial! "children_detail", journal: journal +end \ No newline at end of file diff --git a/app/views/api/v1/issues/journals/update.json.jbuilder b/app/views/api/v1/issues/journals/update.json.jbuilder new file mode 100644 index 000000000..91f3f3174 --- /dev/null +++ b/app/views/api/v1/issues/journals/update.json.jbuilder @@ -0,0 +1 @@ +json.partial! "detail", journal: @object_result \ No newline at end of file From 121fa2bff47f6faa771fc08fe900552a9792cedb Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 20 Feb 2023 11:42:22 +0800 Subject: [PATCH 020/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E9=87=8C?= =?UTF-8?q?=E7=A8=8B=E7=A2=91=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/issues/milestones_controller.rb | 55 +++++++++++++---- app/models/version.rb | 10 +++- .../api/v1/issues/batch_update_service.rb | 4 +- .../milestones/detail_issues_service.rb | 59 +++++++++++++++++++ .../issues/milestones/_detail.json.jbuilder | 6 ++ .../v1/issues/milestones/index.json.jbuilder | 2 + .../v1/issues/milestones/show.json.jbuilder | 11 ++++ 7 files changed, 135 insertions(+), 12 deletions(-) create mode 100644 app/services/api/v1/issues/milestones/detail_issues_service.rb create mode 100644 app/views/api/v1/issues/milestones/_detail.json.jbuilder create mode 100644 app/views/api/v1/issues/milestones/show.json.jbuilder diff --git a/app/controllers/api/v1/issues/milestones_controller.rb b/app/controllers/api/v1/issues/milestones_controller.rb index bb5033904..79b1aa15b 100644 --- a/app/controllers/api/v1/issues/milestones_controller.rb +++ b/app/controllers/api/v1/issues/milestones_controller.rb @@ -1,32 +1,67 @@ class Api::V1::Issues::MilestonesController < Api::V1::BaseController - before_action :require_public_and_member_above, only: [:index] + before_action :require_public_and_member_above + before_action :load_milestone, only: [:show, :update, :destroy] # 里程碑列表 def index if params[:only_name] - @milestones = @project.versions + @milestones = @project.versions.select(:id, :name) + @milestones = @milestones.ransack(name_or_description_cont: params[:keyword]).result if params[:keyword].present? + @milestones = kaminary_select_paginate(@milestones) else - @milestones = @project.versions.includes(:issues) + @milestones = @project.versions.includes(:issues, :closed_issues, :opened_issues) + @milestones = params[:category] == "closed" ? @milestones.closed : @milestones.opening + @milestones = @milestones.ransack(name_or_description_cont: params[:keyword]).result if params[:keyword].present? + @milestones = kaminari_paginate(@milestones) end - @milestones = @milestones.ransack(name_or_description_cont: params[:keyword]).result if params[:keyword].present? - @milestones = kaminary_select_paginate(@milestones) end - # 里程碑详情 - def show + def create + @milestone = @project.versions.new(milestone_params) + if @milestone.save! + render_ok + else + render_error(@milestone.errors.full_messages.join(",")) + end end - def create + # 里程碑详情 + def show + @object_results = Api::V1::Issues::Milestones::DetailIssuesService.call(@project, @milestone, query_params, current_user) + @closed_issues_count = @object_results.closed.size + @opened_issues_count = @object_results.opened.size + @issues = kaminari_paginate(@object_results) end def update + @milestone.attributes = milestone_params + if @milestone.save! + render_ok + else + render_error(@milestone.errors.full_messages.join(",")) + end end def destroy + if @milestone.destroy! + render_ok + else + render_error("删除里程碑失败!") + end end - private - + def milestone_params + params.permit(:name, :description, :effective_date) + end + + def query_params + params.permit(:category, :author_id, :assigner_id, :sort_by, :sort_direction, :issue_tag_ids => []) + end + + def load_milestone + @milestone = @project.versions.find_by_id(params[:id]) + return render_not_found('里程碑不存在!') unless @milestone.present? + end end \ No newline at end of file diff --git a/app/models/version.rb b/app/models/version.rb index 41256833a..fab193b96 100644 --- a/app/models/version.rb +++ b/app/models/version.rb @@ -28,6 +28,9 @@ class Version < ApplicationRecord has_many :issues, class_name: "Issue", foreign_key: "fixed_version_id" belongs_to :user, optional: true + has_many :opened_issues, -> {where(issue_classify: "Issue").where.not(status_id: 5)}, class_name: "Issue", foreign_key: :fixed_version_id + has_many :closed_issues, -> {where(issue_classify: "Issue", status_id: 5)}, class_name: "Issue", foreign_key: :fixed_version_id + scope :version_includes, ->{includes(:issues, :user)} scope :closed, ->{where(status: 'closed')} scope :opening, ->{where(status: 'open')} @@ -43,6 +46,11 @@ class Version < ApplicationRecord after_create :send_create_message_to_notice_system after_save :send_update_message_to_notice_system + def issue_percent + issues_total_count = opened_issues.size + closed_issues.size + issues_total_count.zero? ? 0.0 : closed_issues.size.to_f / issues_total_count + end + def version_user User.select(:login, :lastname,:firstname, :nickname)&.find_by_id(self.user_id) end @@ -53,6 +61,6 @@ class Version < ApplicationRecord end def send_update_message_to_notice_system - SendTemplateMessageJob.perform_later('ProjectMilestoneCompleted', self.id) if Site.has_notice_menu? && self.percent == 1.0 + SendTemplateMessageJob.perform_later('ProjectMilestoneCompleted', self.id) if Site.has_notice_menu? && self.issue_percent == 1.0 end end diff --git a/app/services/api/v1/issues/batch_update_service.rb b/app/services/api/v1/issues/batch_update_service.rb index ffa1ba7df..cf09650ce 100644 --- a/app/services/api/v1/issues/batch_update_service.rb +++ b/app/services/api/v1/issues/batch_update_service.rb @@ -20,7 +20,9 @@ class Api::V1::Issues::BatchUpdateService < ApplicationService raise Error, errors.full_messages.join(", ") unless valid? ActiveRecord::Base.transaction do @issues.each do |issue| - Api::V1::Issues::UpdateService.call(project, issue, params, current_user) + if issue.issue_classify == "Issue" + Api::V1::Issues::UpdateService.call(project, issue, params, current_user) + end end return true diff --git a/app/services/api/v1/issues/milestones/detail_issues_service.rb b/app/services/api/v1/issues/milestones/detail_issues_service.rb new file mode 100644 index 000000000..1328805b3 --- /dev/null +++ b/app/services/api/v1/issues/milestones/detail_issues_service.rb @@ -0,0 +1,59 @@ +class Api::V1::Issues::Milestones::DetailIssuesService < ApplicationService + include ActiveModel::Model + + attr_reader :project, :category, :author_id, :assigner_id, :issue_tag_ids, :sort_by, :sort_direction, :current_user + attr_accessor :queried_issues + + validates :category, inclusion: {in: %w(all opened closed), message: "请输入正确的Category"} + validates :sort_by, inclusion: {in: Issue.column_names, message: '请输入正确的SortBy'}, allow_blank: true + validates :sort_direction, inclusion: {in: %w(asc desc), message: '请输入正确的SortDirection'}, allow_blank: true + validates :current_user, presence: true + + def initialize(project, milestone, params, current_user=nil) + @project = project + @milestone = milestone + @category = params[:category] || 'all' + @author_id = params[:author_id] + @assigner_id = params[:assigner_id] + @issue_tag_ids = params[:issue_tag_ids] + @sort_by = params[:sort_by].present? ? params[:sort_by] : 'updated_on' + @sort_direction = (params[:sort_direction].present? ? params[:sort_direction] : 'desc').downcase + @current_user = current_user + end + + def call + raise Error, errors.full_messages.join(", ") unless valid? + begin + issue_query_data + + queried_issues + rescue + raise Error, "服务器错误,请联系系统管理员!" + end + end + + private + def issue_query_data + issues = @milestone.issues.issue_issue + + case category + when 'closed' + issues = issues.closed + when 'opened' + issues = issues.opened + end + + # author_id + issues = issues.where(author_id: author_id) if author_id.present? + + # assigner_id + issues = issues.joins(:assigners).where(users: {id: assigner_id}).or(issues.where(assigned_to_id: assigner_id)) if assigner_id.present? + + scope = issues.includes(:priority, :issue_status, :user, :assigners, :version, :issue_tags, :comment_journals) + + scope = scope.reorder("issues.#{sort_by} #{sort_direction}").distinct + + @queried_issues = scope + end + +end \ No newline at end of file diff --git a/app/views/api/v1/issues/milestones/_detail.json.jbuilder b/app/views/api/v1/issues/milestones/_detail.json.jbuilder new file mode 100644 index 000000000..a7d66ae28 --- /dev/null +++ b/app/views/api/v1/issues/milestones/_detail.json.jbuilder @@ -0,0 +1,6 @@ +json.(milestone, :id, :name, :description, :effective_date, :status) +json.issues_count milestone.opened_issues.size + milestone.closed_issues.size +json.close_issues_count milestone.closed_issues.size +json.percent milestone.issue_percent +json.created_at milestone.created_on.strftime("%Y-%m-%d %H:%M") +json.updated_on milestone.updated_on.strftime("%Y-%m-%d %H:%M") diff --git a/app/views/api/v1/issues/milestones/index.json.jbuilder b/app/views/api/v1/issues/milestones/index.json.jbuilder index 012549bd3..cea2b43b7 100644 --- a/app/views/api/v1/issues/milestones/index.json.jbuilder +++ b/app/views/api/v1/issues/milestones/index.json.jbuilder @@ -2,5 +2,7 @@ json.total_count @milestones.total_count json.milestones @milestones.each do |milestone| if params[:only_name] json.partial! "simple_detail", locals: {milestone: milestone} + else + json.partial! "detail", locals: {milestone: milestone} end end \ No newline at end of file diff --git a/app/views/api/v1/issues/milestones/show.json.jbuilder b/app/views/api/v1/issues/milestones/show.json.jbuilder new file mode 100644 index 000000000..01632e9d0 --- /dev/null +++ b/app/views/api/v1/issues/milestones/show.json.jbuilder @@ -0,0 +1,11 @@ +json.milestone do + json.partial! "detail", locals: {milestone: @milestone} +end +json.total_issues_count @issues.total_count +json.closed_issues_count @closed_issues_count +json.opened_issues_count @opened_issues_count +json.issues @issues.each do |issue| + if issue.issue_classify == "Issue" + json.partial! "api/v1/issues/simple_detail", locals: {issue: issue} + end +end \ No newline at end of file From 656d5b69b6e4e693189c76c072630d272d47da4c Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 20 Feb 2023 13:54:00 +0800 Subject: [PATCH 021/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E9=99=84=E4=BB=B6=E5=86=85=E5=AE=B9=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/attachments/_simple_detail.json.jbuilder | 7 +++++++ app/views/api/v1/issues/_detail.json.jbuilder | 5 ++++- .../api/v1/issues/journals/_children_detail.json.jbuilder | 3 +++ app/views/api/v1/issues/journals/_detail.json.jbuilder | 3 +++ 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 app/views/api/v1/attachments/_simple_detail.json.jbuilder diff --git a/app/views/api/v1/attachments/_simple_detail.json.jbuilder b/app/views/api/v1/attachments/_simple_detail.json.jbuilder new file mode 100644 index 000000000..3d56eb82f --- /dev/null +++ b/app/views/api/v1/attachments/_simple_detail.json.jbuilder @@ -0,0 +1,7 @@ +json.id attachment.id +json.title attachment.title +json.filesize number_to_human_size(attachment.filesize) +json.is_pdf attachment.is_pdf? +json.url attachment.is_pdf? ? download_url(attachment,disposition:"inline") : download_url(attachment) +json.created_on attachment.created_on.strftime("%Y-%m-%d %H:%M") +json.content_type attachment.content_type diff --git a/app/views/api/v1/issues/_detail.json.jbuilder b/app/views/api/v1/issues/_detail.json.jbuilder index 82fea8098..3961270ae 100644 --- a/app/views/api/v1/issues/_detail.json.jbuilder +++ b/app/views/api/v1/issues/_detail.json.jbuilder @@ -39,4 +39,7 @@ json.participants issue.participants.distinct.each do |participant| json.partial! "api/v1/users/simple_user", locals: {user: participant} end json.comment_journals_count issue.comment_journals.size -json.operate_journals_count issue.operate_journals.size \ No newline at end of file +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 diff --git a/app/views/api/v1/issues/journals/_children_detail.json.jbuilder b/app/views/api/v1/issues/journals/_children_detail.json.jbuilder index 38bbda404..3fbb438b3 100644 --- a/app/views/api/v1/issues/journals/_children_detail.json.jbuilder +++ b/app/views/api/v1/issues/journals/_children_detail.json.jbuilder @@ -14,4 +14,7 @@ json.reply_user do else json.nil! end +end +json.attachments journal.attachments.each do |attachment| + json.partial! "api/v1/attachments/simple_detail", locals: {attachment: attachment} end \ No newline at end of file diff --git a/app/views/api/v1/issues/journals/_detail.json.jbuilder b/app/views/api/v1/issues/journals/_detail.json.jbuilder index 418da24a8..7e8232bdc 100644 --- a/app/views/api/v1/issues/journals/_detail.json.jbuilder +++ b/app/views/api/v1/issues/journals/_detail.json.jbuilder @@ -17,4 +17,7 @@ else json.children_journals journal.first_ten_children_journals.each do |journal| json.partial! "children_detail", journal: journal end + json.attachments journal.attachments do |attachment| + json.partial! "api/v1/attachments/simple_detail", locals: {attachment: attachment} + end end From cb3bb23e7918159e14f7b928e7db160524e1c4b7 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 20 Feb 2023 16:47:19 +0800 Subject: [PATCH 022/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/base_controller.rb | 1 - .../api/v1/issues/issue_tags_controller.rb | 3 ++- app/controllers/api/v1/issues/journals_controller.rb | 5 +++++ .../api/v1/issues/milestones_controller.rb | 3 ++- app/controllers/api/v1/issues_controller.rb | 12 +++++++----- .../api/v1/projects/collaborators_controller.rb | 2 +- app/views/api/v1/issues/show.json.jbuilder | 1 + 7 files changed, 18 insertions(+), 9 deletions(-) diff --git a/app/controllers/api/v1/base_controller.rb b/app/controllers/api/v1/base_controller.rb index 771adcc05..c6a4f180d 100644 --- a/app/controllers/api/v1/base_controller.rb +++ b/app/controllers/api/v1/base_controller.rb @@ -52,7 +52,6 @@ class Api::V1::BaseController < ApplicationController # 具有仓库的操作权限或者fork仓库的操作权限 def require_operate_above_or_fork_project @project = load_project - puts !current_user.admin? && !@project.operator?(current_user) && !(@project.fork_project.present? && @project.fork_project.operator?(current_user)) return render_forbidden if !current_user.admin? && !@project.operator?(current_user) && !(@project.fork_project.present? && @project.fork_project.operator?(current_user)) end diff --git a/app/controllers/api/v1/issues/issue_tags_controller.rb b/app/controllers/api/v1/issues/issue_tags_controller.rb index 63d8fb605..7038ddcae 100644 --- a/app/controllers/api/v1/issues/issue_tags_controller.rb +++ b/app/controllers/api/v1/issues/issue_tags_controller.rb @@ -1,6 +1,7 @@ class Api::V1::Issues::IssueTagsController < Api::V1::BaseController - before_action :require_public_and_member_above, only: [:index, :create, :update, :destroy] + before_action :require_public_and_member_above, only: [:index] + before_action :require_operate_above, only: [:create, :update, :destroy] def index @issue_tags = @project.issue_tags.order("#{order_by} #{order_direction}") diff --git a/app/controllers/api/v1/issues/journals_controller.rb b/app/controllers/api/v1/issues/journals_controller.rb index 55e820611..cd0996277 100644 --- a/app/controllers/api/v1/issues/journals_controller.rb +++ b/app/controllers/api/v1/issues/journals_controller.rb @@ -3,6 +3,7 @@ class Api::V1::Issues::JournalsController < Api::V1::IssuesController before_action :require_public_and_member_above, only: [:index, :create, :children_journals, :update, :destroy] before_action :load_issue, only: [:index, :create, :children_journals, :update, :destroy] before_action :load_journal, only: [:children_journals, :update, :destroy] + before_action :check_journal_operate_permission, only: [:update, :destroy] def index @object_results = Api::V1::Issues::Journals::ListService.call(@issue, query_params, current_user) @@ -45,4 +46,8 @@ class Api::V1::Issues::JournalsController < Api::V1::IssuesController return render_not_found("评论不存在!") unless @journal.present? end + def check_journal_operate_permission + return render_forbidden("您没有操作权限!") unless current_user.present? && current_user.logged? && (@project.member?(current_user) || current_user.admin? || @issue.user == current_user || @journal.user == current_user) + end + end \ No newline at end of file diff --git a/app/controllers/api/v1/issues/milestones_controller.rb b/app/controllers/api/v1/issues/milestones_controller.rb index 79b1aa15b..3bbbbdefa 100644 --- a/app/controllers/api/v1/issues/milestones_controller.rb +++ b/app/controllers/api/v1/issues/milestones_controller.rb @@ -1,5 +1,6 @@ class Api::V1::Issues::MilestonesController < Api::V1::BaseController - before_action :require_public_and_member_above + before_action :require_public_and_member_above, only: [:index, :show] + before_action :require_operate_above, only: [:create, :update, :destroy] before_action :load_milestone, only: [:show, :update, :destroy] # 里程碑列表 diff --git a/app/controllers/api/v1/issues_controller.rb b/app/controllers/api/v1/issues_controller.rb index d1f8a83a1..562a360dc 100644 --- a/app/controllers/api/v1/issues_controller.rb +++ b/app/controllers/api/v1/issues_controller.rb @@ -1,6 +1,8 @@ class Api::V1::IssuesController < Api::V1::BaseController - before_action :require_public_and_member_above, only: [:index, :show, :create, :update, :destroy, :batch_update, :batch_destroy] + before_action :require_public_and_member_above, only: [:index, :show, :create, :update, :destroy] + before_action :require_operate_above, only: [:batch_update, :batch_destroy] + before_action :check_issue_operate_permission, only: [:update, :destroy] def index @object_results = Api::V1::Issues::ListService.call(@project, query_params, current_user) @@ -17,6 +19,7 @@ class Api::V1::IssuesController < Api::V1::BaseController before_action :load_issue, only: [:show, :update, :destroy] def show + @user_permission = current_user.present? && current_user.logged? && (@project.member?(current_user) || current_user.admin? || @issue.user == current_user) end def update @@ -58,8 +61,6 @@ class Api::V1::IssuesController < Api::V1::BaseController @issue = @project.issues.where(project_issues_index: params[:id]).where.not(id: params[:id]).take || Issue.find_by_id(params[:id]) if @issue.blank? render_not_found("疑修不存在!") - elsif @issue.present? && @issue.is_lock &&!(@project.member?(current_user) || current_user.admin?) - render_forbidden("您没有权限操作!") end end @@ -69,13 +70,14 @@ class Api::V1::IssuesController < Api::V1::BaseController @issue = Issue.find_by_id(id) if @issue.blank? return render_not_found("ID为#{id}的疑修不存在!") - elsif @issue.present? && @issue.is_lock &&!(@project.member?(current_user) || current_user.admin?) - return render_forbidden("ID为#{id}的疑修您没有权限操作!") end end @issues = Issue.where(id: params[:ids]) end + def check_issue_operate_permission + return render_forbidden("您没有操作权限!") unless current_user.present? && current_user.logged? && (@project.member?(current_user) || current_user.admin? || @issue.user == current_user) + end private diff --git a/app/controllers/api/v1/projects/collaborators_controller.rb b/app/controllers/api/v1/projects/collaborators_controller.rb index 67a96378e..cd9002a99 100644 --- a/app/controllers/api/v1/projects/collaborators_controller.rb +++ b/app/controllers/api/v1/projects/collaborators_controller.rb @@ -3,7 +3,7 @@ class Api::V1::Projects::CollaboratorsController < Api::V1::BaseController before_action :require_public_and_member_above, only: [:index] def index - @collaborators = @project.all_collaborators.ransack(name_or_login_cont: params[:keyword]).result + @collaborators = @project.all_collaborators.like(params[:keyword]) @collaborators = kaminary_select_paginate(@collaborators) end diff --git a/app/views/api/v1/issues/show.json.jbuilder b/app/views/api/v1/issues/show.json.jbuilder index 8746417b5..55028fc64 100644 --- a/app/views/api/v1/issues/show.json.jbuilder +++ b/app/views/api/v1/issues/show.json.jbuilder @@ -1 +1,2 @@ json.partial! "api/v1/issues/detail", locals: {issue: @issue} +json.user_permission @user_permission From 465761875336542e1bed6bb602226d9116b15cf7 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 20 Feb 2023 17:25:07 +0800 Subject: [PATCH 023/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=95=B0=E6=8D=AErake=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/issue_status.rb | 17 +++++- app/models/issue_tag.rb | 20 +++++++ lib/tasks/fix_issue_project_issues_index.rake | 22 -------- lib/tasks/upgrade_issue_generate_data.rake | 53 +++++++++++++++++++ 4 files changed, 89 insertions(+), 23 deletions(-) delete mode 100644 lib/tasks/fix_issue_project_issues_index.rake create mode 100644 lib/tasks/upgrade_issue_generate_data.rake diff --git a/app/models/issue_status.rb b/app/models/issue_status.rb index a58346ea7..819313866 100644 --- a/app/models/issue_status.rb +++ b/app/models/issue_status.rb @@ -20,10 +20,25 @@ class IssueStatus < ApplicationRecord ADD = 1 SOLVING = 2 SOLVED = 3 - FEEDBACK = 4 + # FEEDBACK = 4 CLOSED = 5 REJECTED = 6 has_many :issues belongs_to :project, optional: true + + def self.init_data + map = { + "1" => "新增", + "2" => "正在解决", + "3" => "已解决", + "5" => "关闭", + "6" => "拒绝" + } + IssueStatus.order(id: :asc).each do |stat| + next if map[stat.id] == stat.name + Issue.where(status_id: stat.id).each{|i| i.update_column(:status_id, 1)} + stat.destroy! + end + end end diff --git a/app/models/issue_tag.rb b/app/models/issue_tag.rb index 2c62117d0..b111ad2db 100644 --- a/app/models/issue_tag.rb +++ b/app/models/issue_tag.rb @@ -26,4 +26,24 @@ class IssueTag < ApplicationRecord belongs_to :project, optional: true, counter_cache: true belongs_to :user, optional: true + def self.init_data(project_id) + data = [ + ["缺陷", "表示项目存在问题", "#d92d4c"], + ["功能", "表示新功能申请", "#ee955a"], + ["疑问", "表示存在的问题", "#2d6ddc"], + ["支持", "表示特定功能或特定需求", "#019549"], + ["任务", "表示需要分配的任务", "#01a30d"], + ["协助", "表示需要社区用户协助", "#2a0dc1"], + ["搁置", "表示此问题不会继续处理", "#892794"], + ["文档", "表示文档材料补充", "#9ed600"], + ["测试", "表示需要测试的需求", "#2897b9"], + ["重复", "表示已存在类似的疑修", "#bb5332"] + ] + data.each do |item| + next if IssueTag.exists?(project_id: project_id, name: item[0]) + IssueTag.create!(project_id: project_id, name: item[0], description: item[1], color: item[2]) + end + end + + end diff --git a/lib/tasks/fix_issue_project_issues_index.rake b/lib/tasks/fix_issue_project_issues_index.rake deleted file mode 100644 index 010df5f4b..000000000 --- a/lib/tasks/fix_issue_project_issues_index.rake +++ /dev/null @@ -1,22 +0,0 @@ -# 执行示例 bundle exec rake sync_version_issues:update_issues -# 线上环境执行示例 RAILS_ENV=production bundle exec rake sync_version_issues:update_issues - -namespace :fix_issue_project_issues_index do - desc "update issue project_issues_index" - - task update_issues: :environment do - puts "____________fix start________________" - - Issue.update_all(project_issues_index: nil) - - Issue.where(project_issues_index: nil).group(:project_id).count.each do |pid, count| - p = Project.find_by_id(pid) - issues = p.issues.order(created_on: :asc) - issues.find_each.with_index do |issue, index| - issue.update_column(:project_issues_index, index+1) - end - end - puts "____________fix end________________" - end - -end \ No newline at end of file diff --git a/lib/tasks/upgrade_issue_generate_data.rake b/lib/tasks/upgrade_issue_generate_data.rake new file mode 100644 index 000000000..47cfb145d --- /dev/null +++ b/lib/tasks/upgrade_issue_generate_data.rake @@ -0,0 +1,53 @@ + + +namespace :upgrade_issue_generate_data do + # 执行示例 bundle exec rake upgrade_issue_generate_data:project_issues_index + # 线上环境执行示例 RAILS_ENV=production bundle exec rake upgrade_issue_generate_data:project_issues_index + desc "upgrade_issue_generate_data: fix issue project_issues_index" + + task project_issues_index: :environment do + puts "____________fix start________________" + + Issue.update_all(project_issues_index: nil) + count = 0 + Issue.where(project_issues_index: nil).group(:project_id).count.each do |pid, count| + p = Project.find_by_id(pid) + issues = p.issues.order(created_on: :asc) + issues.find_each.with_index do |issue, index| + count += 1 + issue.update_column(:project_issues_index, index+1) + end + end + puts "____________fix end_______total:#{count}_________" + end + + # 执行示例 bundle exec rake upgrade_issue_generate_data:project_init_issue_tags_and_status + # 线上环境执行示例 RAILS_ENV=production bundle exec rake upgrade_issue_generate_data:project_init_issue_tags_and_status + desc "upgrade_issue_generate_data: fix project init issue_tags" + + task project_init_issue_tags_and_status: :environment do + puts "____________fix start________________" + IssueStatus.init_data + IssueTag.where(user_id: nil).destroy_all + count = 0 + Project.order(created_at: :desc).find_each do |project| + count += 1 + IssueTag.init_data(project.id) + end + puts "____________fix end____total:#{count}__________" + end + + # 执行示例 bundle exec rake upgrade_issue_generate_data:move_assigned_to_id_to_assigners + # 线上环境执行示例 RAILS_ENV=production bundle exec rake upgrade_issue_generate_data:move_assigned_to_id_to_assigners + desc "upgrade_issue_generate_data: fix issue assigner to assigners" + + task move_assigned_to_id_to_assigners: :environment do + puts "____________fix start________________" + count = 0 + Issue.where.not(assigned_to_id: nil).find_each do |issue| + count += 1 + issue.assigners = User.where(id: issue.assigned_to_id) + end + puts "____________fix end____total:#{count}__________" + end +end \ No newline at end of file From 02526878fe91db9ff20d15d9116806196f283473 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 20 Feb 2023 18:22:14 +0800 Subject: [PATCH 024/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=97=A0=E6=B3=95=E8=AE=BE=E7=BD=AE=E7=A9=BA=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/issues_controller.rb | 1 + app/models/issue_status.rb | 9 ++++++--- app/services/api/v1/issues/update_service.rb | 10 +++++----- app/services/projects/create_service.rb | 1 + 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/controllers/api/v1/issues_controller.rb b/app/controllers/api/v1/issues_controller.rb index 562a360dc..93de448af 100644 --- a/app/controllers/api/v1/issues_controller.rb +++ b/app/controllers/api/v1/issues_controller.rb @@ -5,6 +5,7 @@ class Api::V1::IssuesController < Api::V1::BaseController before_action :check_issue_operate_permission, only: [:update, :destroy] def index + IssueTag.init_data(@project.id) if @project.issue_tags.size < 10 @object_results = Api::V1::Issues::ListService.call(@project, query_params, current_user) @opened_issues_count = @object_results.opened.size @closed_issues_count = @object_results.closed.size diff --git a/app/models/issue_status.rb b/app/models/issue_status.rb index 819313866..eb4db1dcc 100644 --- a/app/models/issue_status.rb +++ b/app/models/issue_status.rb @@ -36,9 +36,12 @@ class IssueStatus < ApplicationRecord "6" => "拒绝" } IssueStatus.order(id: :asc).each do |stat| - next if map[stat.id] == stat.name - Issue.where(status_id: stat.id).each{|i| i.update_column(:status_id, 1)} - stat.destroy! + if map[stat.id] == stat.name + IssueStatus.find_or_create_by(id: stat.id, name: stat.name) + else + Issue.where(status_id: stat.id).each{|i| i.update_column(:status_id, 1)} + stat.destroy! + end end end end diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 8abc6aae4..597880eb3 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -84,12 +84,12 @@ class Api::V1::Issues::UpdateService < ApplicationService def issue_load_attributes @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 if milestone_id.present? - @updated_issue.branch_name = branch_name if branch_name.present? - @updated_issue.start_date = start_date if start_date.present? - @updated_issue.due_date = due_date if due_date.present? + @updated_issue.fixed_version_id = milestone_id unless milestone_id.nil? + @updated_issue.branch_name = branch_name unless branch_name.nil? + @updated_issue.start_date = start_date unless start_date.nil? + @updated_issue.due_date = due_date unless due_date.nil? @updated_issue.subject = subject if subject.present? - @updated_issue.description = description if description.present? + @updated_issue.description = description unless description.nil? end def build_assigner_participants diff --git a/app/services/projects/create_service.rb b/app/services/projects/create_service.rb index 2b4523bf5..ff36dfe52 100644 --- a/app/services/projects/create_service.rb +++ b/app/services/projects/create_service.rb @@ -14,6 +14,7 @@ class Projects::CreateService < ApplicationService ActiveRecord::Base.transaction do if @project.save! Project.update_common_projects_count! + IssueTag.init_data(@project.id) ProjectUnit.init_types(@project.id) Repositories::CreateService.new(user, @project, repository_params).call upgrade_project_category_private_projects_count From b18051ec31dc19e3ed429568b444873656091958 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 21 Feb 2023 13:55:40 +0800 Subject: [PATCH 025/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E9=87=8C?= =?UTF-8?q?=E7=A8=8B=E7=A2=91=E7=9B=B8=E5=85=B3=E6=95=B0=E9=87=8F=E8=BF=94?= =?UTF-8?q?=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/issues/milestones_controller.rb | 20 ++++++++++++++----- .../issues/milestones/_detail.json.jbuilder | 1 + .../v1/issues/milestones/index.json.jbuilder | 2 ++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/v1/issues/milestones_controller.rb b/app/controllers/api/v1/issues/milestones_controller.rb index 3bbbbdefa..4de6dffbf 100644 --- a/app/controllers/api/v1/issues/milestones_controller.rb +++ b/app/controllers/api/v1/issues/milestones_controller.rb @@ -5,14 +5,16 @@ class Api::V1::Issues::MilestonesController < Api::V1::BaseController # 里程碑列表 def index + @milestones = @project.versions + @milestones = @milestones.ransack(name_or_description_cont: params[:keyword]).result if params[:keyword].present? + @closed_milestone_count = @milestones.closed.size + @opening_milestone_count = @milestones.opening.size + @milestones = params[:category] == "closed" ? @milestones.closed : @milestones.opening if params[:only_name] - @milestones = @project.versions.select(:id, :name) - @milestones = @milestones.ransack(name_or_description_cont: params[:keyword]).result if params[:keyword].present? + @milestones = @milestones.select(:id, :name) @milestones = kaminary_select_paginate(@milestones) else - @milestones = @project.versions.includes(:issues, :closed_issues, :opened_issues) - @milestones = params[:category] == "closed" ? @milestones.closed : @milestones.opening - @milestones = @milestones.ransack(name_or_description_cont: params[:keyword]).result if params[:keyword].present? + @milestones = @milestones.includes(:issues, :closed_issues, :opened_issues) @milestones = kaminari_paginate(@milestones) end end @@ -65,4 +67,12 @@ class Api::V1::Issues::MilestonesController < Api::V1::BaseController return render_not_found('里程碑不存在!') unless @milestone.present? end + def sort_by + Version.columns.include?(params.fetch(:sort_by, "created_on")) ? params.fetch(:sort_by, "created_on") : "created_on" + end + + def sort_direction + %w(desc asc).include?(params.fetch(:sort_direction, "updated_on")) ? params.fetch(:sort_direction, "updated_on") : "updated_on" + end + end \ No newline at end of file diff --git a/app/views/api/v1/issues/milestones/_detail.json.jbuilder b/app/views/api/v1/issues/milestones/_detail.json.jbuilder index a7d66ae28..b71f41c7e 100644 --- a/app/views/api/v1/issues/milestones/_detail.json.jbuilder +++ b/app/views/api/v1/issues/milestones/_detail.json.jbuilder @@ -1,5 +1,6 @@ json.(milestone, :id, :name, :description, :effective_date, :status) json.issues_count milestone.opened_issues.size + milestone.closed_issues.size +json.opened_issues_count milestone.opened_issues.size json.close_issues_count milestone.closed_issues.size json.percent milestone.issue_percent json.created_at milestone.created_on.strftime("%Y-%m-%d %H:%M") diff --git a/app/views/api/v1/issues/milestones/index.json.jbuilder b/app/views/api/v1/issues/milestones/index.json.jbuilder index cea2b43b7..38623d2b4 100644 --- a/app/views/api/v1/issues/milestones/index.json.jbuilder +++ b/app/views/api/v1/issues/milestones/index.json.jbuilder @@ -1,3 +1,5 @@ +json.closed_milestone_count @closed_milestone_count +json.opening_milestone_count @opening_milestone_count json.total_count @milestones.total_count json.milestones @milestones.each do |milestone| if params[:only_name] From cab5466ae4f04c9311606ea5936c6e61c45e5c7b Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 21 Feb 2023 15:31:00 +0800 Subject: [PATCH 026/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=8E=92=E8=A1=8C=E6=A6=9C=E9=A1=B9=E7=9B=AE=E9=9C=80?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=85=A8=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/admins/projects_rank/index.html.erb | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/views/admins/projects_rank/index.html.erb b/app/views/admins/projects_rank/index.html.erb index 056e0a0da..d3a7926b7 100644 --- a/app/views/admins/projects_rank/index.html.erb +++ b/app/views/admins/projects_rank/index.html.erb @@ -19,15 +19,15 @@ 排名 - 项目 - 得分 - 访问数 - 关注数 - 点赞数 - fork数 - 疑修数 - 合并请求数 - 提交数 + 项目 + 得分 + 访问数 + 关注数 + 点赞数 + fork数 + 疑修数 + 合并请求数 + 提交数 @@ -38,7 +38,7 @@ <% owner_common = $redis_cache.hgetall("v2-owner-common:#{project_common["owner_id"]}")%> /<%= project_common["identifier"]%>"> - <%= project_common["name"] %> + <%= "#{owner_common["name"]}/#{project_common["name"]}" %> From 3a5d8e75df408ac987a29b5d68e75b0718ef50bb Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 21 Feb 2023 15:39:52 +0800 Subject: [PATCH 027/438] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9A=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E7=AE=A1=E7=90=86sidebar=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/admins/shared/_sidebar.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/admins/shared/_sidebar.html.erb b/app/views/admins/shared/_sidebar.html.erb index 88ba91205..5e6cb4d24 100644 --- a/app/views/admins/shared/_sidebar.html.erb +++ b/app/views/admins/shared/_sidebar.html.erb @@ -15,9 +15,9 @@
  • <%= sidebar_item(admins_path, '概览', icon: 'dashboard', controller: 'admins-dashboards') %>
  • - <%= sidebar_item_group('#user-submenu', '排行榜', icon: 'user') do %> + <%= sidebar_item_group('#rank-submenu', '排行榜', icon: 'calendar') do %>
  • <%= sidebar_item(admins_users_rank_index_path, '用户排行榜', icon: 'user', controller: 'admins-users_rank') %>
  • -
  • <%= sidebar_item(admins_projects_rank_index_path, '项目排行榜', icon: 'user', controller: 'admins-projects_rank') %>
  • +
  • <%= sidebar_item(admins_projects_rank_index_path, '项目排行榜', icon: 'database', controller: 'admins-projects_rank') %>
  • <% end %>
  • From 47a5fe24c8ce0b386db5f049f586e8c3dbafd7c2 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 21 Feb 2023 16:43:28 +0800 Subject: [PATCH 028/438] =?UTF-8?q?=E8=B0=83=E6=95=B4Bot=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3,fixed=E6=B3=A8=E5=86=8C=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=89=8B=E6=9C=BA=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index 20dd25e40..3379af47c 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -37,7 +37,7 @@ class InstallationsController < ApplicationController # 注册bot对应oauth应用 Doorkeeper::Application.create!(name: @bot.name, uid: @bot.client_id, secret: @bot.client_secret, redirect_uri: "https://gitlink.org.cn") # 注册bot对应用户 - result = autologin_register(User.generate_user_login('b'), nil, "#{SecureRandom.hex(6)}", 'bot', nickname: @bot.name) + result = autologin_register(User.generate_user_login('b'), nil, "#{SecureRandom.hex(6)}", 'bot', nil, nickname: @bot.name) tip_exception(-1, result[:message]) if result[:message].present? @bot.uid = result[:user][:id] @bot.save From 311776a00414f6b7cff8da424e8744591b235e35 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 21 Feb 2023 18:30:29 +0800 Subject: [PATCH 029/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E5=88=97=E8=A1=A8=E6=97=A0id=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/issue_tags/_detail.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/api/v1/issues/issue_tags/_detail.json.jbuilder b/app/views/api/v1/issues/issue_tags/_detail.json.jbuilder index 644badf3e..332e47373 100644 --- a/app/views/api/v1/issues/issue_tags/_detail.json.jbuilder +++ b/app/views/api/v1/issues/issue_tags/_detail.json.jbuilder @@ -1,4 +1,4 @@ -json.(tag, :name, :description, :color, :issues_count) +json.(tag,:id, :name, :description, :color, :issues_count) json.project do if tag.project.present? json.partial! "api/v1/projects/simple_detail", project: tag.project From b9e2a3736c40ecd7fbdc1ebc104b994c5757ca73 Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Tue, 21 Feb 2023 17:38:09 +0800 Subject: [PATCH 030/438] admins org list --- .../javascripts/admins/organizations.js | 2 + .../stylesheets/admins/organizations.scss | 3 ++ .../admins/organizations_controller.rb | 23 ++++++++ app/helpers/admins/organizations_helper.rb | 2 + app/models/organization.rb | 51 ++++++++++++++++++ .../admins/delete_organization_service.rb | 28 ++++++++++ app/views/admins/organizations/edit.html.erb | 41 ++++++++++++++ app/views/admins/organizations/index.html.erb | 8 +++ app/views/admins/organizations/index.js.erb | 1 + .../admins/organizations/index.json.jbuilder | 6 +++ .../organizations/shared/_org_list.html.erb | 45 ++++++++++++++++ .../shared/_project_list.html.erb | 53 +++++++++++++++++++ app/views/admins/organizations/show.html.erb | 38 +++++++++++++ app/views/admins/shared/_sidebar.html.erb | 3 +- config/routes.rb | 2 +- .../admins/organizations_controller_spec.rb | 5 ++ .../admins/organizations_helper_spec.rb | 15 ++++++ 17 files changed, 324 insertions(+), 2 deletions(-) create mode 100644 app/assets/javascripts/admins/organizations.js create mode 100644 app/assets/stylesheets/admins/organizations.scss create mode 100644 app/controllers/admins/organizations_controller.rb create mode 100644 app/helpers/admins/organizations_helper.rb create mode 100644 app/services/admins/delete_organization_service.rb create mode 100644 app/views/admins/organizations/edit.html.erb create mode 100644 app/views/admins/organizations/index.html.erb create mode 100644 app/views/admins/organizations/index.js.erb create mode 100644 app/views/admins/organizations/index.json.jbuilder create mode 100644 app/views/admins/organizations/shared/_org_list.html.erb create mode 100644 app/views/admins/organizations/shared/_project_list.html.erb create mode 100644 app/views/admins/organizations/show.html.erb create mode 100644 spec/controllers/admins/organizations_controller_spec.rb create mode 100644 spec/helpers/admins/organizations_helper_spec.rb diff --git a/app/assets/javascripts/admins/organizations.js b/app/assets/javascripts/admins/organizations.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/admins/organizations.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/admins/organizations.scss b/app/assets/stylesheets/admins/organizations.scss new file mode 100644 index 000000000..a3cf9ca1f --- /dev/null +++ b/app/assets/stylesheets/admins/organizations.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the admins/organizations controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/admins/organizations_controller.rb b/app/controllers/admins/organizations_controller.rb new file mode 100644 index 000000000..4e40a509e --- /dev/null +++ b/app/controllers/admins/organizations_controller.rb @@ -0,0 +1,23 @@ +class Admins::OrganizationsController < Admins::BaseController + before_action :finder_org, except: [:index] + + def index + @orgs = paginate Organization.all + end + + def show + end + + def destroy + @org.destroy! + Admins::DeleteOrganizationService.call(@org.login) + render_delete_success + end + + private + + def finder_org + @org = Organization.find(params[:id]) + end + +end diff --git a/app/helpers/admins/organizations_helper.rb b/app/helpers/admins/organizations_helper.rb new file mode 100644 index 000000000..0265ab1e4 --- /dev/null +++ b/app/helpers/admins/organizations_helper.rb @@ -0,0 +1,2 @@ +module Admins::OrganizationsHelper +end diff --git a/app/models/organization.rb b/app/models/organization.rb index adf43a2cd..17eb28918 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -144,6 +144,57 @@ class Organization < Owner end end + def projects_count + Project.where( user_id: self.id).count + end + + # 用户账号状态 + def active? + status == User::STATUS_ACTIVE + end + + def registered? + status == User::STATUS_REGISTERED + end + + def locked? + status == User::STATUS_LOCKED + end + + def need_edit_info? + status == User::STATUS_EDIT_INFO + end + + def activate + self.status = User::STATUS_ACTIVE + end + + def register + self.status = User::STATUS_REGISTERED + end + + def lock + self.status = User::STATUS_LOCKED + end + + def need_edit_info + self.status = User::STATUS_EDIT_INFO + end + + def activate! + update_attribute(:status, STATUS_ACTIVE) + prohibit_gitea_user_login!(false) + end + + def register! + update_attribute(:status, STATUS_REGISTERED) + end + + def lock! + update_attribute(:status, STATUS_LOCKED) + prohibit_gitea_user_login! + end + def real_name name = lastname + firstname name = name.blank? ? (nickname.blank? ? login : nickname) : name diff --git a/app/services/admins/delete_organization_service.rb b/app/services/admins/delete_organization_service.rb new file mode 100644 index 000000000..db842845b --- /dev/null +++ b/app/services/admins/delete_organization_service.rb @@ -0,0 +1,28 @@ +class Admins::DeleteOrganizationService < Gitea::ClientService + attr_reader :token, :name + + def initialize(name) + @name = name + end + + def call + response = delete(url, params) + render_status(response) + end + + private + def params + Hash.new.merge(token: token) + end + + def url + "/orgs/#{name}".freeze + end + + def token + { + username: GiteaService.gitea_config[:access_key_id], + password: GiteaService.gitea_config[:access_key_secret] + } + end +end diff --git a/app/views/admins/organizations/edit.html.erb b/app/views/admins/organizations/edit.html.erb new file mode 100644 index 000000000..0cc9909f0 --- /dev/null +++ b/app/views/admins/organizations/edit.html.erb @@ -0,0 +1,41 @@ +<% + define_admin_breadcrumbs do + add_admin_breadcrumb('组织管理', admins_organizations_path) + add_admin_breadcrumb('组织详情') + end +%> + +
    + + + <%= simple_form_for(@org, url: admins_organization_path(@org)) do |f| %> + +
    基本信息
    +
    +
    + <%= f.input :login, label: '登录名', wrapper_html: { class: 'col-md-3' }, input_html: { readonly: true, class: 'col-md-11', value: @org.login } %> +
    + +
    + <%= f.input :lastname, label: '姓名', wrapper_html: { class: 'col-md-3' }, input_html: { class: 'col-md-11', value: @org.real_name } %> +
    + + +
    + +
    + <%= f.button :submit, value: '保存', class: 'btn-primary mr-3 px-4' %> + <%= link_to '取消', admins_organizations_path, class: 'btn btn-secondary px-4' %> +
    + <% end %> +
    diff --git a/app/views/admins/organizations/index.html.erb b/app/views/admins/organizations/index.html.erb new file mode 100644 index 000000000..7c96b57ee --- /dev/null +++ b/app/views/admins/organizations/index.html.erb @@ -0,0 +1,8 @@ +<% define_admin_breadcrumbs do %> + <% add_admin_breadcrumb('组织管理', admins_organizations_path) %> +<% end %> + +
    + <%= render partial: 'admins/organizations/shared/org_list', locals: { organizations: @orgs } %> +
    + diff --git a/app/views/admins/organizations/index.js.erb b/app/views/admins/organizations/index.js.erb new file mode 100644 index 000000000..7e750ecf9 --- /dev/null +++ b/app/views/admins/organizations/index.js.erb @@ -0,0 +1 @@ +$('.users-list-container').html("<%= j( render partial: 'admins/organizations/shared/org_list', locals: { organizations: @orgs } ) %>"); \ No newline at end of file diff --git a/app/views/admins/organizations/index.json.jbuilder b/app/views/admins/organizations/index.json.jbuilder new file mode 100644 index 000000000..1278c3c13 --- /dev/null +++ b/app/views/admins/organizations/index.json.jbuilder @@ -0,0 +1,6 @@ +json.count @orgs.total_count +json.orgs do + json.array! @orgs.each do |org| + json.extract! org, :id, :login, :nickname + end +end \ No newline at end of file diff --git a/app/views/admins/organizations/shared/_org_list.html.erb b/app/views/admins/organizations/shared/_org_list.html.erb new file mode 100644 index 000000000..b8fac30d0 --- /dev/null +++ b/app/views/admins/organizations/shared/_org_list.html.erb @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + <% if organizations.present? %> + <% organizations.each_with_index do |org, index| %> + + + + + + + + + + <% end %> + <% else %> + <%= render 'admins/shared/no_data_for_table' %> + <% end %> + +
    序号login昵称<%= sort_tag('创建于', name: 'created_on', path: admins_organizations_path) %><%= sort_tag('最后登录', name: 'last_login_on', path: admins_organizations_path) %>项目数操作
    <%= list_index_no((params[:page] || 1).to_i, index) %> + <%= link_to "/#{org.login}", target: '_blank' do %> + <%= overflow_hidden_span org.login, width: 100 %> + <% end %> + <%= org.nickname %> <%= display_text(org.created_on&.strftime('%Y-%m-%d %H:%M')) %><%= display_text(org.last_login_on&.strftime('%Y-%m-%d %H:%M')) %><%= link_to org.projects_count, "/#{org.login}", target: "_blank" %> + <%= link_to '查看', admins_organization_path(org), class: 'action' %> +
    + <%= javascript_void_link('更多', class: 'action dropdown-toggle', 'data-toggle': 'dropdown', 'aria-haspopup': true, 'aria-expanded': false) %> + +
    +
    + +<%= render partial: 'admins/shared/paginate', locals: { objects: organizations } %> diff --git a/app/views/admins/organizations/shared/_project_list.html.erb b/app/views/admins/organizations/shared/_project_list.html.erb new file mode 100644 index 000000000..e828938ff --- /dev/null +++ b/app/views/admins/organizations/shared/_project_list.html.erb @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + <% if projects.present? %> + <% projects.each_with_index do |project, index| %> + + + + + + + + + + + + + + + + <% end %> + <% else %> + <%= render 'admins/shared/no_data_for_table' %> + <% end %> + +
    序号ID项目名称公开推荐Issues资源Pulls里程碑成员管理员<%= sort_tag('创建时间', name: 'created_on', path: admins_projects_path) %>操作
    <%= list_index_no((params[:page] || 1).to_i, index) %><%= project.id %> + <%= link_to(project.name, "/#{project&.owner&.login}/#{project.identifier}", target: '_blank') %> + <%= project.is_public ? '√' : '' %><%= project.recommend ? '√' : '' %><%= project.issues.size %><%= project.attachments.size %><%= project&.pull_requests_count %><%= project.versions.size %><%= project.members.size %> + <%= link_to_project(project) %> + <%= project.created_on&.strftime('%Y-%m-%d %H:%M') %> + <% if project.is_public %> + <%= javascript_void_link '推荐', class: 'action recommend-action', data: { id: project.id }, style: project.recommend ? 'display: none;' : '' %> + <%= javascript_void_link '取消推荐', class: 'action unrecommend-action', data: { id: project.id }, style: project.recommend ? '' : 'display: none;' %> + <%= link_to "设置推荐等级", edit_admins_project_path(project.id), remote: true, class: "action edit-recommend-action", style: project.recommend ? '' : 'display: none;' %> + <% end %> + <%= link_to "删除", admins_project_path(project.id), method: :delete, data:{confirm: "确认删除的吗?"}, class: "delete-project-action" %> +
    \ No newline at end of file diff --git a/app/views/admins/organizations/show.html.erb b/app/views/admins/organizations/show.html.erb new file mode 100644 index 000000000..b40f1c258 --- /dev/null +++ b/app/views/admins/organizations/show.html.erb @@ -0,0 +1,38 @@ +<% + define_admin_breadcrumbs do + add_admin_breadcrumb('组织管理', admins_organizations_path) + add_admin_breadcrumb('组织详情') + end +%> + +
    + + + <%= simple_form_for(@org, url: admins_organization_path(@org)) do |f| %> + +
    基本信息
    +
    +
    + <%= f.input :login, label: '登录名', wrapper_html: { class: 'col-md-3' }, input_html: { readonly: true, class: 'col-md-11', value: @org.login } %> +
    + +
    + <%= f.input :lastname, label: '姓名', wrapper_html: { class: 'col-md-3' }, input_html: { readonly: true, class: 'col-md-11', value: @org.real_name } %> +
    + + +
    + <% end %> +

    组织项目

    + <%= render partial: 'admins/organizations/shared/project_list', locals: { projects: @org.projects } %> + +
    diff --git a/app/views/admins/shared/_sidebar.html.erb b/app/views/admins/shared/_sidebar.html.erb index dc2d2944e..e1199f787 100644 --- a/app/views/admins/shared/_sidebar.html.erb +++ b/app/views/admins/shared/_sidebar.html.erb @@ -15,7 +15,7 @@
    • <%= sidebar_item(admins_path, '概览', icon: 'dashboard', controller: 'admins-dashboards') %>
    • - <%= sidebar_item_group('#rank-submenu', '排行榜', icon: 'calendar') do %> + <%= sidebar_item_group('#user-rank-submenu', '排行榜', icon: 'calendar') do %>
    • <%= sidebar_item(admins_users_rank_index_path, '用户排行榜', icon: 'user', controller: 'admins-users_rank') %>
    • <%= sidebar_item(admins_projects_rank_index_path, '项目排行榜', icon: 'database', controller: 'admins-projects_rank') %>
    • <% end %> @@ -23,6 +23,7 @@
    • <%= sidebar_item_group('#user-submenu', '用户', icon: 'user') do %>
    • <%= sidebar_item(admins_users_path, '用户列表', icon: 'user', controller: 'admins-users') %>
    • +
    • <%= sidebar_item(admins_organizations_path, '组织列表', icon: 'user', controller: 'admins-organization') %>
    • <% end %>
    • diff --git a/config/routes.rb b/config/routes.rb index 3d6cc8f55..3488bacb4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -816,7 +816,7 @@ Rails.application.routes.draw do resources :school_statistics, only: [:index] do get :contrast, on: :collection end - + resources :organizations, only: [:index, :edit, :show, :destroy] resources :users, only: [:index, :edit, :update, :destroy] do member do post :reward_grade diff --git a/spec/controllers/admins/organizations_controller_spec.rb b/spec/controllers/admins/organizations_controller_spec.rb new file mode 100644 index 000000000..a0df61f17 --- /dev/null +++ b/spec/controllers/admins/organizations_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Admins::OrganizationsController, type: :controller do + +end diff --git a/spec/helpers/admins/organizations_helper_spec.rb b/spec/helpers/admins/organizations_helper_spec.rb new file mode 100644 index 000000000..2f0a719a0 --- /dev/null +++ b/spec/helpers/admins/organizations_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Admins::OrganizationsHelper. For example: +# +# describe Admins::OrganizationsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe Admins::OrganizationsHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end From ac8372d7e142bc07b8b84608fd12969e508bf8bc Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Wed, 22 Feb 2023 08:26:59 +0800 Subject: [PATCH 031/438] orgs search --- .../admins/organizations_controller.rb | 6 +++++- app/queries/admins/organization_query.rb | 21 +++++++++++++++++++ app/views/admins/organizations/index.html.erb | 9 ++++++++ app/views/admins/organizations/index.js.erb | 2 +- .../organizations/shared/_org_list.html.erb | 2 ++ 5 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 app/queries/admins/organization_query.rb diff --git a/app/controllers/admins/organizations_controller.rb b/app/controllers/admins/organizations_controller.rb index 4e40a509e..35fb4dee8 100644 --- a/app/controllers/admins/organizations_controller.rb +++ b/app/controllers/admins/organizations_controller.rb @@ -2,7 +2,11 @@ class Admins::OrganizationsController < Admins::BaseController before_action :finder_org, except: [:index] def index - @orgs = paginate Organization.all + params[:sort_by] = params[:sort_by].presence || 'created_on' + params[:sort_direction] = params[:sort_direction].presence || 'desc' + + orgs = Admins::OrganizationQuery.call(params) + @orgs = paginate orgs end def show diff --git a/app/queries/admins/organization_query.rb b/app/queries/admins/organization_query.rb new file mode 100644 index 000000000..09dbab9e3 --- /dev/null +++ b/app/queries/admins/organization_query.rb @@ -0,0 +1,21 @@ +class Admins::OrganizationQuery < ApplicationQuery + include CustomSortable + attr_reader :params + sort_columns :created_on, :last_login_on, :experience, :grade, default_by: :created_on, default_direction: :desc + + def initialize(params) + @params = params + end + + def call + orgs = Organization.all + # 关键字检索 + keyword = params[:keyword].to_s.strip.presence + if keyword + sql = 'nickname LIKE :keyword OR login LIKE :keyword' + orgs = orgs.where(sql, keyword: "%#{keyword}%") + end + + custom_sort(orgs, params[:sort_by], params[:sort_direction]) + end +end \ No newline at end of file diff --git a/app/views/admins/organizations/index.html.erb b/app/views/admins/organizations/index.html.erb index 7c96b57ee..7cd2ba8fa 100644 --- a/app/views/admins/organizations/index.html.erb +++ b/app/views/admins/organizations/index.html.erb @@ -1,6 +1,15 @@ <% define_admin_breadcrumbs do %> <% add_admin_breadcrumb('组织管理', admins_organizations_path) %> <% end %> +
      + <%= form_tag(admins_organizations_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %> + + <%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-sm-2 ml-3', placeholder: 'login/昵称') %> + + <%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %> + <% end %> + +
      <%= render partial: 'admins/organizations/shared/org_list', locals: { organizations: @orgs } %> diff --git a/app/views/admins/organizations/index.js.erb b/app/views/admins/organizations/index.js.erb index 7e750ecf9..5cf62a739 100644 --- a/app/views/admins/organizations/index.js.erb +++ b/app/views/admins/organizations/index.js.erb @@ -1 +1 @@ -$('.users-list-container').html("<%= j( render partial: 'admins/organizations/shared/org_list', locals: { organizations: @orgs } ) %>"); \ No newline at end of file +$('.organizations-list-container').html("<%= j( render partial: 'admins/organizations/shared/org_list', locals: { organizations: @orgs } ) %>"); \ No newline at end of file diff --git a/app/views/admins/organizations/shared/_org_list.html.erb b/app/views/admins/organizations/shared/_org_list.html.erb index b8fac30d0..9f3f857e8 100644 --- a/app/views/admins/organizations/shared/_org_list.html.erb +++ b/app/views/admins/organizations/shared/_org_list.html.erb @@ -2,6 +2,7 @@ 序号 + ID login 昵称 <%= sort_tag('创建于', name: 'created_on', path: admins_organizations_path) %> @@ -15,6 +16,7 @@ <% organizations.each_with_index do |org, index| %> <%= list_index_no((params[:page] || 1).to_i, index) %> + <%= org.id %> <%= link_to "/#{org.login}", target: '_blank' do %> <%= overflow_hidden_span org.login, width: 100 %> From 05f103b0c49f6cbc4cee1f7c1fb6b9a397806564 Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Wed, 22 Feb 2023 09:12:16 +0800 Subject: [PATCH 032/438] team count and delete orgs --- app/models/organization.rb | 47 ++----------------- .../admins/delete_organization_service.rb | 13 +---- .../organizations/shared/_org_list.html.erb | 18 +++---- 3 files changed, 15 insertions(+), 63 deletions(-) diff --git a/app/models/organization.rb b/app/models/organization.rb index 17eb28918..d61dda567 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -147,52 +147,13 @@ class Organization < Owner def projects_count Project.where( user_id: self.id).count end - - # 用户账号状态 - def active? - status == User::STATUS_ACTIVE - end - - def registered? - status == User::STATUS_REGISTERED - end - - def locked? - status == User::STATUS_LOCKED - end - - def need_edit_info? - status == User::STATUS_EDIT_INFO - end - - def activate - self.status = User::STATUS_ACTIVE - end - - def register - self.status = User::STATUS_REGISTERED - end - - def lock - self.status = User::STATUS_LOCKED - end - - def need_edit_info - self.status = User::STATUS_EDIT_INFO - end - - def activate! - update_attribute(:status, STATUS_ACTIVE) - prohibit_gitea_user_login!(false) - end - def register! - update_attribute(:status, STATUS_REGISTERED) + def teams_count + teams.count end - def lock! - update_attribute(:status, STATUS_LOCKED) - prohibit_gitea_user_login! + def organization_users_count + organization_users.count end def real_name diff --git a/app/services/admins/delete_organization_service.rb b/app/services/admins/delete_organization_service.rb index db842845b..f5760b364 100644 --- a/app/services/admins/delete_organization_service.rb +++ b/app/services/admins/delete_organization_service.rb @@ -1,24 +1,15 @@ class Admins::DeleteOrganizationService < Gitea::ClientService attr_reader :token, :name - + def initialize(name) @name = name end def call - response = delete(url, params) - render_status(response) + Gitea::Organization::DeleteService.call(token,name) end private - def params - Hash.new.merge(token: token) - end - - def url - "/orgs/#{name}".freeze - end - def token { username: GiteaService.gitea_config[:access_key_id], diff --git a/app/views/admins/organizations/shared/_org_list.html.erb b/app/views/admins/organizations/shared/_org_list.html.erb index 9f3f857e8..25878b296 100644 --- a/app/views/admins/organizations/shared/_org_list.html.erb +++ b/app/views/admins/organizations/shared/_org_list.html.erb @@ -1,14 +1,14 @@ - - + - - - - - + + + + + + @@ -16,7 +16,6 @@ <% organizations.each_with_index do |org, index| %> - - + + + @@ -15,6 +16,7 @@ <% organizations.each_with_index do |org, index| %> +
      序号ID序号 login昵称<%= sort_tag('创建于', name: 'created_on', path: admins_organizations_path) %><%= sort_tag('最后登录', name: 'last_login_on', path: admins_organizations_path) %>项目数操作昵称<%= sort_tag('创建于', name: 'created_on', path: admins_organizations_path) %>团队成员项目数操作
      <%= list_index_no((params[:page] || 1).to_i, index) %><%= org.id %> <%= link_to "/#{org.login}", target: '_blank' do %> <%= overflow_hidden_span org.login, width: 100 %> @@ -24,7 +23,8 @@ <%= org.nickname %> <%= display_text(org.created_on&.strftime('%Y-%m-%d %H:%M')) %><%= display_text(org.last_login_on&.strftime('%Y-%m-%d %H:%M')) %><%= link_to org.teams_count, "/#{org.login}", target: "_blank" %><%= link_to org.organization_users_count, "/#{org.login}", target: "_blank" %> <%= link_to org.projects_count, "/#{org.login}", target: "_blank" %> <%= link_to '查看', admins_organization_path(org), class: 'action' %> From ee77be7c8abfa4edda738f464f263c5024de98e2 Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Wed, 22 Feb 2023 09:25:49 +0800 Subject: [PATCH 033/438] fix --- app/views/admins/shared/_sidebar.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admins/shared/_sidebar.html.erb b/app/views/admins/shared/_sidebar.html.erb index e1199f787..37f819bde 100644 --- a/app/views/admins/shared/_sidebar.html.erb +++ b/app/views/admins/shared/_sidebar.html.erb @@ -15,7 +15,7 @@
      • <%= sidebar_item(admins_path, '概览', icon: 'dashboard', controller: 'admins-dashboards') %>
      • - <%= sidebar_item_group('#user-rank-submenu', '排行榜', icon: 'calendar') do %> + <%= sidebar_item_group('#rank-submenu', '排行榜', icon: 'calendar') do %>
      • <%= sidebar_item(admins_users_rank_index_path, '用户排行榜', icon: 'user', controller: 'admins-users_rank') %>
      • <%= sidebar_item(admins_projects_rank_index_path, '项目排行榜', icon: 'database', controller: 'admins-projects_rank') %>
      • <% end %> From 5f3d51027e03fe413ec8e8688c3af03aa9ecdf26 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 22 Feb 2023 09:36:13 +0800 Subject: [PATCH 034/438] =?UTF-8?q?fixed=20=E5=B7=A6=E4=BE=A7=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E7=BB=84=E7=BB=87=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/admins/shared/_sidebar.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admins/shared/_sidebar.html.erb b/app/views/admins/shared/_sidebar.html.erb index 37f819bde..00ae3e821 100644 --- a/app/views/admins/shared/_sidebar.html.erb +++ b/app/views/admins/shared/_sidebar.html.erb @@ -23,7 +23,7 @@
      • <%= sidebar_item_group('#user-submenu', '用户', icon: 'user') do %>
      • <%= sidebar_item(admins_users_path, '用户列表', icon: 'user', controller: 'admins-users') %>
      • -
      • <%= sidebar_item(admins_organizations_path, '组织列表', icon: 'user', controller: 'admins-organization') %>
      • +
      • <%= sidebar_item(admins_organizations_path, '组织列表', icon: 'user', controller: 'admins-organizations') %>
      • s <% end %>
      • From 6c1f9cabda4ac98a6a86c4d4341c11db2b177fcf Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 22 Feb 2023 09:38:32 +0800 Subject: [PATCH 035/438] =?UTF-8?q?fixed=20=E5=B7=A6=E4=BE=A7=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E7=BB=84=E7=BB=87=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/admins/shared/_sidebar.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admins/shared/_sidebar.html.erb b/app/views/admins/shared/_sidebar.html.erb index 00ae3e821..fc2fe6068 100644 --- a/app/views/admins/shared/_sidebar.html.erb +++ b/app/views/admins/shared/_sidebar.html.erb @@ -23,7 +23,7 @@
      • <%= sidebar_item_group('#user-submenu', '用户', icon: 'user') do %>
      • <%= sidebar_item(admins_users_path, '用户列表', icon: 'user', controller: 'admins-users') %>
      • -
      • <%= sidebar_item(admins_organizations_path, '组织列表', icon: 'user', controller: 'admins-organizations') %>
      • s +
      • <%= sidebar_item(admins_organizations_path, '组织列表', icon: 'user', controller: 'admins-organizations') %>
      • <% end %>
      • From 8239f13eaa89809d429b5407ab03973fb566cfa1 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 22 Feb 2023 09:55:05 +0800 Subject: [PATCH 036/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E8=A6=81?= =?UTF-8?q?=E6=B1=82=E7=99=BB=E5=BD=95=E6=8E=A5=E5=8F=A3=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/issues/issue_tags_controller.rb | 2 +- .../api/v1/issues/journals_controller.rb | 2 +- .../api/v1/issues/milestones_controller.rb | 1 + app/controllers/api/v1/issues_controller.rb | 4 ++-- lib/tasks/upgrade_issue_generate_data.rake | 14 ++++++++------ 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/controllers/api/v1/issues/issue_tags_controller.rb b/app/controllers/api/v1/issues/issue_tags_controller.rb index 7038ddcae..077ac1474 100644 --- a/app/controllers/api/v1/issues/issue_tags_controller.rb +++ b/app/controllers/api/v1/issues/issue_tags_controller.rb @@ -1,5 +1,5 @@ class Api::V1::Issues::IssueTagsController < Api::V1::BaseController - + before_action :require_login, except: [:index] before_action :require_public_and_member_above, only: [:index] before_action :require_operate_above, only: [:create, :update, :destroy] diff --git a/app/controllers/api/v1/issues/journals_controller.rb b/app/controllers/api/v1/issues/journals_controller.rb index cd0996277..b184392a0 100644 --- a/app/controllers/api/v1/issues/journals_controller.rb +++ b/app/controllers/api/v1/issues/journals_controller.rb @@ -1,5 +1,5 @@ class Api::V1::Issues::JournalsController < Api::V1::IssuesController - + before_action :require_login, except: [:index, :children_journals] before_action :require_public_and_member_above, only: [:index, :create, :children_journals, :update, :destroy] before_action :load_issue, only: [:index, :create, :children_journals, :update, :destroy] before_action :load_journal, only: [:children_journals, :update, :destroy] diff --git a/app/controllers/api/v1/issues/milestones_controller.rb b/app/controllers/api/v1/issues/milestones_controller.rb index 4de6dffbf..b3f30e084 100644 --- a/app/controllers/api/v1/issues/milestones_controller.rb +++ b/app/controllers/api/v1/issues/milestones_controller.rb @@ -1,4 +1,5 @@ class Api::V1::Issues::MilestonesController < Api::V1::BaseController + before_action :require_login, except: [:index, :show] before_action :require_public_and_member_above, only: [:index, :show] before_action :require_operate_above, only: [:create, :update, :destroy] before_action :load_milestone, only: [:show, :update, :destroy] diff --git a/app/controllers/api/v1/issues_controller.rb b/app/controllers/api/v1/issues_controller.rb index 93de448af..35634a1ad 100644 --- a/app/controllers/api/v1/issues_controller.rb +++ b/app/controllers/api/v1/issues_controller.rb @@ -1,5 +1,5 @@ class Api::V1::IssuesController < Api::V1::BaseController - + before_action :require_login, except: [:index, :show] before_action :require_public_and_member_above, only: [:index, :show, :create, :update, :destroy] before_action :require_operate_above, only: [:batch_update, :batch_destroy] before_action :check_issue_operate_permission, only: [:update, :destroy] @@ -77,7 +77,7 @@ class Api::V1::IssuesController < Api::V1::BaseController end def check_issue_operate_permission - return render_forbidden("您没有操作权限!") unless current_user.present? && current_user.logged? && (@project.member?(current_user) || current_user.admin? || @issue.user == current_user) + return render_forbidden("您没有操作权限!") unless @project.member?(current_user) || current_user.admin? || @issue.user == current_user end private diff --git a/lib/tasks/upgrade_issue_generate_data.rake b/lib/tasks/upgrade_issue_generate_data.rake index 47cfb145d..3cefd32b8 100644 --- a/lib/tasks/upgrade_issue_generate_data.rake +++ b/lib/tasks/upgrade_issue_generate_data.rake @@ -37,16 +37,18 @@ namespace :upgrade_issue_generate_data do puts "____________fix end____total:#{count}__________" end - # 执行示例 bundle exec rake upgrade_issue_generate_data:move_assigned_to_id_to_assigners - # 线上环境执行示例 RAILS_ENV=production bundle exec rake upgrade_issue_generate_data:move_assigned_to_id_to_assigners - desc "upgrade_issue_generate_data: fix issue assigner to assigners" + # 执行示例 bundle exec rake upgrade_issue_generate_data:build_assigners_and_participants + # 线上环境执行示例 RAILS_ENV=production bundle exec rake upgrade_issue_generate_data:build_assigners_and_participants + desc "upgrade_issue_generate_data: fix issue assigners and participants" - task move_assigned_to_id_to_assigners: :environment do + task build_assigners_and_participants: :environment do puts "____________fix start________________" count = 0 - Issue.where.not(assigned_to_id: nil).find_each do |issue| + Issue.order(created_on: :desc)find_each do |issue| count += 1 - issue.assigners = User.where(id: issue.assigned_to_id) + issue.issue_assigners.find_or_create_by(assigner_id: issue.assigned_to_id) + issue.issue_participants.find_or_create_by(participant_id: issue.assigned_to_id, participant_type: 'assigned') + issue.issue_participants.find_or_create_by(participant_id: issue.author_id, participant_type: 'authored') end puts "____________fix end____total:#{count}__________" end From ed5d12654ef9566456bde8c58f780e1c55ff66a8 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 22 Feb 2023 09:57:39 +0800 Subject: [PATCH 037/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/upgrade_issue_generate_data.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/upgrade_issue_generate_data.rake b/lib/tasks/upgrade_issue_generate_data.rake index 3cefd32b8..857644eee 100644 --- a/lib/tasks/upgrade_issue_generate_data.rake +++ b/lib/tasks/upgrade_issue_generate_data.rake @@ -44,7 +44,7 @@ namespace :upgrade_issue_generate_data do task build_assigners_and_participants: :environment do puts "____________fix start________________" count = 0 - Issue.order(created_on: :desc)find_each do |issue| + Issue.order(created_on: :desc).find_each do |issue| count += 1 issue.issue_assigners.find_or_create_by(assigner_id: issue.assigned_to_id) issue.issue_participants.find_or_create_by(participant_id: issue.assigned_to_id, participant_type: 'assigned') From e440ee8483a6d76b3599d42d93ce523ba37e3aab Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Wed, 22 Feb 2023 10:38:40 +0800 Subject: [PATCH 038/438] api/users/{{user}}/messages add check auth --- app/controllers/users/messages_controller.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/controllers/users/messages_controller.rb b/app/controllers/users/messages_controller.rb index 5116f580f..4feb4a98e 100644 --- a/app/controllers/users/messages_controller.rb +++ b/app/controllers/users/messages_controller.rb @@ -1,6 +1,7 @@ class Users::MessagesController < Users::BaseController before_action :private_user_resources! before_action :find_receivers, only: [:create] + before_action :check_auth def index limit = params[:limit] || params[:per_page] @@ -63,6 +64,10 @@ class Users::MessagesController < Users::BaseController end private + def check_auth + return render_forbidden unless current_user.admin? || observed_logged_user? + end + def message_type @message_type = begin case params[:type] From 54b7f2c72666018cf94a2dec6a3573cc7d44cb55 Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Wed, 22 Feb 2023 10:48:23 +0800 Subject: [PATCH 039/438] fix api/users/:login/headmaps.json bug --- app/controllers/users/headmaps_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/users/headmaps_controller.rb b/app/controllers/users/headmaps_controller.rb index 7c88b5681..7faba1e50 100644 --- a/app/controllers/users/headmaps_controller.rb +++ b/app/controllers/users/headmaps_controller.rb @@ -10,15 +10,15 @@ class Users::HeadmapsController < Users::BaseController private def start_stamp if params[:year].present? - Date.new(params[:year], 1).to_time.to_i + Date.new(params[:year].to_i, 1).to_time.to_i else - Date.today.to_time.to_i - 365*24*60*60 + (Date.today - 1.years).to_time.to_i end end def end_stamp if params[:year].present? - Date.new(params[:year], 1).to_time.to_i + 365*24*60*60 + (Date.new(params[:year].to_i, 1) + 1.years).to_time.to_i else Date.today.to_time.to_i end From 54a85a60fab8c4a1a712896157eb68b9c4a1e050 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 22 Feb 2023 13:56:02 +0800 Subject: [PATCH 040/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E7=96=91?= =?UTF-8?q?=E4=BF=AE=E5=88=97=E8=A1=A8=E5=BC=80=E5=90=AF=E3=80=81=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E6=95=B0=E9=87=8F=E8=A7=84=E5=88=99=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?=E6=8E=92=E5=BA=8F=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/issues_controller.rb | 8 ++++---- app/models/issue_priority.rb | 17 +++++++++++++++++ app/models/issue_status.rb | 2 +- app/services/api/v1/issues/list_service.rb | 18 ++++++++++-------- lib/tasks/upgrade_issue_generate_data.rake | 1 + 5 files changed, 33 insertions(+), 13 deletions(-) diff --git a/app/controllers/api/v1/issues_controller.rb b/app/controllers/api/v1/issues_controller.rb index 35634a1ad..782c87813 100644 --- a/app/controllers/api/v1/issues_controller.rb +++ b/app/controllers/api/v1/issues_controller.rb @@ -6,11 +6,11 @@ class Api::V1::IssuesController < Api::V1::BaseController def index IssueTag.init_data(@project.id) if @project.issue_tags.size < 10 - @object_results = Api::V1::Issues::ListService.call(@project, query_params, current_user) - @opened_issues_count = @object_results.opened.size - @closed_issues_count = @object_results.closed.size + @object_result = Api::V1::Issues::ListService.call(@project, query_params, current_user) + @opened_issues_count = @object_result[:opened_issues_count] + @closed_issues_count = @object_result[:closed_issues_count] - @issues = kaminari_paginate(@object_results) + @issues = kaminari_paginate(@object_result[:data]) end def create diff --git a/app/models/issue_priority.rb b/app/models/issue_priority.rb index 27865a70f..c8ef73299 100644 --- a/app/models/issue_priority.rb +++ b/app/models/issue_priority.rb @@ -15,4 +15,21 @@ class IssuePriority < ApplicationRecord has_many :issues + + def self.init_data + map = { + "1" => "低", + "2" => "正常", + "3" => "高", + "4" => "紧急" + } + IssuePriority.order(id: :asc).each do |prty| + if map["#{prty.id}"] == prty.name + IssuePriority.find_or_create_by(id: prty.id, name: prty.name) + else + Issue.where(priority_id: prty.id).each{|i| i.update_column(:priority_id, 2)} + prty.destroy! + end + end + end end diff --git a/app/models/issue_status.rb b/app/models/issue_status.rb index eb4db1dcc..fcce29c32 100644 --- a/app/models/issue_status.rb +++ b/app/models/issue_status.rb @@ -36,7 +36,7 @@ class IssueStatus < ApplicationRecord "6" => "拒绝" } IssueStatus.order(id: :asc).each do |stat| - if map[stat.id] == stat.name + if map["#{stat.id}"] == stat.name IssueStatus.find_or_create_by(id: stat.id, name: stat.name) else Issue.where(status_id: stat.id).each{|i| i.update_column(:status_id, 1)} diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index 6383a6e12..8acf20133 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -3,11 +3,11 @@ class Api::V1::Issues::ListService < ApplicationService attr_reader :project, :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 + attr_accessor :queried_issues, :closed_issues_count, :opened_issues_count validates :category, inclusion: {in: %w(all opened closed), message: "请输入正确的Category"} validates :participant_category, inclusion: {in: %w(all aboutme authoredme assignedme atme), message: "请输入正确的ParticipantCategory"} - validates :sort_by, inclusion: {in: Issue.column_names, message: '请输入正确的SortBy'}, allow_blank: true + validates :sort_by, inclusion: {in: ['issues.created_on', 'issues.updated_on', 'issue_priorities.position'], message: '请输入正确的SortBy'}, allow_blank: true validates :sort_direction, inclusion: {in: %w(asc desc), message: '请输入正确的SortDirection'}, allow_blank: true validates :current_user, presence: true @@ -21,7 +21,7 @@ class Api::V1::Issues::ListService < ApplicationService @milestone_id = params[:milestone_id] @assigner_id = params[:assigner_id] @status_id = params[:status_id] - @sort_by = params[:sort_by].present? ? params[:sort_by] : 'updated_on' + @sort_by = params[:sort_by].present? ? params[:sort_by] : 'issues.updated_on' @sort_direction = (params[:sort_direction].present? ? params[:sort_direction] : 'desc').downcase @current_user = current_user end @@ -31,7 +31,7 @@ class Api::V1::Issues::ListService < ApplicationService begin issue_query_data - queried_issues + return {data: queried_issues, closed_issues_count: @closed_issues_count, opened_issues_count: @opened_issues_count} rescue raise Error, "服务器错误,请联系系统管理员!" end @@ -40,6 +40,8 @@ class Api::V1::Issues::ListService < ApplicationService private def issue_query_data issues = @project.issues.issue_issue + @closed_issues_count = issues.closed.size + @opened_issues_count = issues.opened.size case category when 'closed' @@ -52,11 +54,11 @@ class Api::V1::Issues::ListService < ApplicationService when 'aboutme' # 关于我的 issues = issues.joins(:participants, :issue_participants).where(issue_participants: {participant_type: %(authored assigned atme)},users: {id: current_user&.id}) when 'authoredme' # 我创建的 - issues = issues.joins(:participants, :issue_participants).where(issue_participants: {participant_type: %(authored)},users: {id: current_user&.id}) + issues = issues.joins(:participants, :issue_participants).where(issue_participants: {participant_type: 'assigned'},users: {id: current_user&.id}) when 'assignedme' # 我负责的 - issues = issues.joins(:participants, :issue_participants).where(issue_participants: {participant_type: %(assigned)},users: {id: current_user&.id}) + issues = issues.joins(:participants, :issue_participants).where(issue_participants: {participant_type: 'assigned'},users: {id: current_user&.id}) when 'atme' # @我的 - issues = issues.joins(:participants, :issue_participants).where(issue_participants: {participant_type: %(atme)},users: {id: current_user&.id}) + issues = issues.joins(:participants, :issue_participants).where(issue_participants: {participant_type: 'atme'},users: {id: current_user&.id}) end # author_id @@ -79,7 +81,7 @@ class Api::V1::Issues::ListService < ApplicationService scope = q.result.includes(:priority, :issue_status, :user, :assigners, :version, :issue_tags, :comment_journals) - scope = scope.reorder("issues.#{sort_by} #{sort_direction}").distinct + scope = scope.reorder("#{sort_by} #{sort_direction}").distinct @queried_issues = scope end diff --git a/lib/tasks/upgrade_issue_generate_data.rake b/lib/tasks/upgrade_issue_generate_data.rake index 857644eee..1fbe5df24 100644 --- a/lib/tasks/upgrade_issue_generate_data.rake +++ b/lib/tasks/upgrade_issue_generate_data.rake @@ -27,6 +27,7 @@ namespace :upgrade_issue_generate_data do task project_init_issue_tags_and_status: :environment do puts "____________fix start________________" + IssuePriority.init_data IssueStatus.init_data IssueTag.where(user_id: nil).destroy_all count = 0 From a07da79e89d4d564d1b71822346472890390b7ac Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 22 Feb 2023 14:42:52 +0800 Subject: [PATCH 041/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E5=88=9D=E5=A7=8B=E5=8C=96=E6=A0=87=E7=AD=BE=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/issues_controller.rb | 3 ++- app/models/issue_tag.rb | 1 + app/services/api/v1/issues/list_service.rb | 24 +++++++++++---------- app/views/api/v1/issues/index.json.jbuilder | 3 ++- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/app/controllers/api/v1/issues_controller.rb b/app/controllers/api/v1/issues_controller.rb index 782c87813..c511f88b2 100644 --- a/app/controllers/api/v1/issues_controller.rb +++ b/app/controllers/api/v1/issues_controller.rb @@ -5,8 +5,9 @@ class Api::V1::IssuesController < Api::V1::BaseController before_action :check_issue_operate_permission, only: [:update, :destroy] def index - IssueTag.init_data(@project.id) if @project.issue_tags.size < 10 + IssueTag.init_data(@project.id) unless $redis_cache.hget("project_init_issue_tags", @project.id) @object_result = Api::V1::Issues::ListService.call(@project, query_params, current_user) + @total_issues_count = @object_result[:total_issues_count] @opened_issues_count = @object_result[:opened_issues_count] @closed_issues_count = @object_result[:closed_issues_count] diff --git a/app/models/issue_tag.rb b/app/models/issue_tag.rb index b111ad2db..c938e8386 100644 --- a/app/models/issue_tag.rb +++ b/app/models/issue_tag.rb @@ -43,6 +43,7 @@ class IssueTag < ApplicationRecord next if IssueTag.exists?(project_id: project_id, name: item[0]) IssueTag.create!(project_id: project_id, name: item[0], description: item[1], color: item[2]) end + $redis_cache.hset("project_init_issue_tags", project_id, 1) end diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index 8acf20133..6cea89327 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -3,7 +3,7 @@ class Api::V1::Issues::ListService < ApplicationService attr_reader :project, :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, :closed_issues_count, :opened_issues_count + attr_accessor :queried_issues, :total_issues_count, :closed_issues_count, :opened_issues_count validates :category, inclusion: {in: %w(all opened closed), message: "请输入正确的Category"} validates :participant_category, inclusion: {in: %w(all aboutme authoredme assignedme atme), message: "请输入正确的ParticipantCategory"} @@ -31,7 +31,7 @@ class Api::V1::Issues::ListService < ApplicationService begin issue_query_data - return {data: queried_issues, closed_issues_count: @closed_issues_count, opened_issues_count: @opened_issues_count} + return {data: queried_issues, total_issues_count: @total_issues_count, closed_issues_count: @closed_issues_count, opened_issues_count: @opened_issues_count} rescue raise Error, "服务器错误,请联系系统管理员!" end @@ -40,15 +40,6 @@ class Api::V1::Issues::ListService < ApplicationService private def issue_query_data issues = @project.issues.issue_issue - @closed_issues_count = issues.closed.size - @opened_issues_count = issues.opened.size - - case category - when 'closed' - issues = issues.closed - when 'opened' - issues = issues.opened - end case participant_category when 'aboutme' # 关于我的 @@ -61,6 +52,17 @@ class Api::V1::Issues::ListService < ApplicationService issues = issues.joins(:participants, :issue_participants).where(issue_participants: {participant_type: 'atme'},users: {id: current_user&.id}) end + @total_issues_count = issues.size + @closed_issues_count = issues.closed.size + @opened_issues_count = issues.opened.size + + case category + when 'closed' + issues = issues.closed + when 'opened' + issues = issues.opened + end + # author_id issues = issues.where(author_id: author_id) if author_id.present? diff --git a/app/views/api/v1/issues/index.json.jbuilder b/app/views/api/v1/issues/index.json.jbuilder index 1a324eb27..50165b60b 100644 --- a/app/views/api/v1/issues/index.json.jbuilder +++ b/app/views/api/v1/issues/index.json.jbuilder @@ -1,6 +1,7 @@ -json.total_count @issues.total_count +json.total_issues_count @opened_issues_count json.opened_count @opened_issues_count json.closed_count @closed_issues_count +json.total_count @issues.total_count json.issues @issues.each do |issue| json.partial! "simple_detail", locals: {issue: issue} end \ No newline at end of file From c781ca0da13b61f6abadbb8eff869b674495714e Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 22 Feb 2023 15:56:44 +0800 Subject: [PATCH 042/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E9=83=A8?= =?UTF-8?q?=E5=88=86=E7=BB=86=E8=8A=82=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/issues/milestones_controller.rb | 2 +- app/controllers/api/v1/issues_controller.rb | 2 +- app/models/issue_tag.rb | 2 +- app/services/api/v1/issues/list_service.rb | 28 +++++++++---------- .../milestones/detail_issues_service.rb | 12 ++++---- .../v1/issues/journals/_detail.json.jbuilder | 2 ++ 6 files changed, 26 insertions(+), 22 deletions(-) diff --git a/app/controllers/api/v1/issues/milestones_controller.rb b/app/controllers/api/v1/issues/milestones_controller.rb index b3f30e084..d0fc0be4a 100644 --- a/app/controllers/api/v1/issues/milestones_controller.rb +++ b/app/controllers/api/v1/issues/milestones_controller.rb @@ -60,7 +60,7 @@ class Api::V1::Issues::MilestonesController < Api::V1::BaseController end def query_params - params.permit(:category, :author_id, :assigner_id, :sort_by, :sort_direction, :issue_tag_ids => []) + params.permit(:category, :author_id, :assigner_id, :sort_by, :sort_direction, :issue_tag_ids) end def load_milestone diff --git a/app/controllers/api/v1/issues_controller.rb b/app/controllers/api/v1/issues_controller.rb index c511f88b2..7f2b5ee4d 100644 --- a/app/controllers/api/v1/issues_controller.rb +++ b/app/controllers/api/v1/issues_controller.rb @@ -91,7 +91,7 @@ class Api::V1::IssuesController < Api::V1::BaseController :milestone_id, :assigner_id, :status_id, :sort_by, :sort_direction, - :issue_tag_ids => []) + :issue_tag_ids) end def issue_params diff --git a/app/models/issue_tag.rb b/app/models/issue_tag.rb index c938e8386..787b72bca 100644 --- a/app/models/issue_tag.rb +++ b/app/models/issue_tag.rb @@ -34,7 +34,7 @@ class IssueTag < ApplicationRecord ["支持", "表示特定功能或特定需求", "#019549"], ["任务", "表示需要分配的任务", "#01a30d"], ["协助", "表示需要社区用户协助", "#2a0dc1"], - ["搁置", "表示此问题不会继续处理", "#892794"], + ["搁置", "表示此问题暂时不会继续处理", "#892794"], ["文档", "表示文档材料补充", "#9ed600"], ["测试", "表示需要测试的需求", "#2897b9"], ["重复", "表示已存在类似的疑修", "#bb5332"] diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index 6cea89327..ed9a43a46 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -17,7 +17,7 @@ class Api::V1::Issues::ListService < ApplicationService @participant_category = params[:participant_category] || 'all' @keyword = params[:keyword] @author_id = params[:author_id] - @issue_tag_ids = params[:issue_tag_ids] + @issue_tag_ids = params[:issue_tag_ids].split(",") @milestone_id = params[:milestone_id] @assigner_id = params[:assigner_id] @status_id = params[:status_id] @@ -52,17 +52,6 @@ class Api::V1::Issues::ListService < ApplicationService issues = issues.joins(:participants, :issue_participants).where(issue_participants: {participant_type: 'atme'},users: {id: current_user&.id}) end - @total_issues_count = issues.size - @closed_issues_count = issues.closed.size - @opened_issues_count = issues.opened.size - - case category - when 'closed' - issues = issues.closed - when 'opened' - issues = issues.opened - end - # author_id issues = issues.where(author_id: author_id) if author_id.present? @@ -79,9 +68,20 @@ class Api::V1::Issues::ListService < ApplicationService issues = issues.where(status_id: status_id) if status_id.present? # keyword - q = issues.ransack(subject_or_description_cont: keyword) + issues = issues.ransack(subject_or_description_cont: keyword).result + + @total_issues_count = issues.size + @closed_issues_count = issues.closed.size + @opened_issues_count = issues.opened.size + + case category + when 'closed' + issues = issues.closed + when 'opened' + issues = issues.opened + end - scope = q.result.includes(:priority, :issue_status, :user, :assigners, :version, :issue_tags, :comment_journals) + scope = issues.includes(:priority, :issue_status, :user, :assigners, :version, :issue_tags, :comment_journals) scope = scope.reorder("#{sort_by} #{sort_direction}").distinct diff --git a/app/services/api/v1/issues/milestones/detail_issues_service.rb b/app/services/api/v1/issues/milestones/detail_issues_service.rb index 1328805b3..c6b250a58 100644 --- a/app/services/api/v1/issues/milestones/detail_issues_service.rb +++ b/app/services/api/v1/issues/milestones/detail_issues_service.rb @@ -5,7 +5,7 @@ class Api::V1::Issues::Milestones::DetailIssuesService < ApplicationService attr_accessor :queried_issues validates :category, inclusion: {in: %w(all opened closed), message: "请输入正确的Category"} - validates :sort_by, inclusion: {in: Issue.column_names, message: '请输入正确的SortBy'}, allow_blank: true + validates :sort_by, inclusion: {in: ['issues.created_on', 'issues.updated_on', 'issue_priorities.position'], message: '请输入正确的SortBy'}, allow_blank: true validates :sort_direction, inclusion: {in: %w(asc desc), message: '请输入正确的SortDirection'}, allow_blank: true validates :current_user, presence: true @@ -15,7 +15,7 @@ class Api::V1::Issues::Milestones::DetailIssuesService < ApplicationService @category = params[:category] || 'all' @author_id = params[:author_id] @assigner_id = params[:assigner_id] - @issue_tag_ids = params[:issue_tag_ids] + @issue_tag_ids = params[:issue_tag_ids].present? ? params[:issue_tag_ids].split(",") : [] @sort_by = params[:sort_by].present? ? params[:sort_by] : 'updated_on' @sort_direction = (params[:sort_direction].present? ? params[:sort_direction] : 'desc').downcase @current_user = current_user @@ -47,11 +47,13 @@ class Api::V1::Issues::Milestones::DetailIssuesService < ApplicationService issues = issues.where(author_id: author_id) if author_id.present? # assigner_id - issues = issues.joins(:assigners).where(users: {id: assigner_id}).or(issues.where(assigned_to_id: assigner_id)) if assigner_id.present? + issues = issues.joins(:assigners).where(users: {id: assigner_id}).or(issues.joins(:assigners).where(assigned_to_id: assigner_id)) if assigner_id.present? - scope = issues.includes(:priority, :issue_status, :user, :assigners, :version, :issue_tags, :comment_journals) + issues = issues.joins(:issue_tags).where(issue_tags: {id: issue_tag_ids}) if issue_tag_ids.present? - scope = scope.reorder("issues.#{sort_by} #{sort_direction}").distinct + scope = issues.includes(:priority, :issue_status, :user, :assigners, :version, :issue_tags, :comment_journals).references(:assigners) + + scope = scope.reorder("#{sort_by} #{sort_direction}").distinct @queried_issues = scope end diff --git a/app/views/api/v1/issues/journals/_detail.json.jbuilder b/app/views/api/v1/issues/journals/_detail.json.jbuilder index 7e8232bdc..264997bbd 100644 --- a/app/views/api/v1/issues/journals/_detail.json.jbuilder +++ b/app/views/api/v1/issues/journals/_detail.json.jbuilder @@ -10,6 +10,8 @@ json.user do end end if journal.is_journal_detail? + detail = journal.journal_details.take + json.operate_category detail.property == "attr" ? detail.prop_key : detail.property json.operate_content journal.is_journal_detail? ? journal.operate_content : nil else json.notes journal.notes From 317ff3c76b6ed1f1ed180ea5ab16ece60e527c6f Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 22 Feb 2023 16:05:24 +0800 Subject: [PATCH 043/438] =?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/list_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index ed9a43a46..c1b386345 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -17,7 +17,7 @@ class Api::V1::Issues::ListService < ApplicationService @participant_category = params[:participant_category] || 'all' @keyword = params[:keyword] @author_id = params[:author_id] - @issue_tag_ids = params[:issue_tag_ids].split(",") + @issue_tag_ids = params[:issue_tag_ids].present? ? params[:issue_tag_ids].split(",") : [] @milestone_id = params[:milestone_id] @assigner_id = params[:assigner_id] @status_id = params[:status_id] From edc00d28a7cd0da0de8381429c01ce5a61f1a7d5 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 22 Feb 2023 16:25:40 +0800 Subject: [PATCH 044/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=A0=87?= =?UTF-8?q?=E8=AE=B0=E5=88=97=E8=A1=A8=E8=BF=94=E5=9B=9E=E5=90=88=E5=B9=B6?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/issues/issue_tags_controller.rb | 2 +- app/models/issue_tag.rb | 2 ++ app/views/api/v1/issues/index.json.jbuilder | 2 +- app/views/api/v1/issues/issue_tags/_detail.json.jbuilder | 4 +++- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/v1/issues/issue_tags_controller.rb b/app/controllers/api/v1/issues/issue_tags_controller.rb index 077ac1474..2a5038e63 100644 --- a/app/controllers/api/v1/issues/issue_tags_controller.rb +++ b/app/controllers/api/v1/issues/issue_tags_controller.rb @@ -9,7 +9,7 @@ class Api::V1::Issues::IssueTagsController < Api::V1::BaseController if params[:only_name] @issue_tags = kaminary_select_paginate(@issue_tags.select(:id, :name, :color)) else - @issue_tags = kaminari_paginate(@issue_tags.includes(:project, :user)) + @issue_tags = kaminari_paginate(@issue_tags.includes(:project, :user, :issue_issues, :pull_request_issues)) end end diff --git a/app/models/issue_tag.rb b/app/models/issue_tag.rb index 787b72bca..5381da9be 100644 --- a/app/models/issue_tag.rb +++ b/app/models/issue_tag.rb @@ -23,6 +23,8 @@ class IssueTag < ApplicationRecord has_many :issue_tags_relates, dependent: :destroy has_many :issues, through: :issue_tags_relates + has_many :issue_issues, -> {where(issue_classify: [nil,"issue"])}, source: :issue, through: :issue_tags_relates + has_many :pull_request_issues, -> {where(issue_classify: "pull_request")}, source: :issue, through: :issue_tags_relates belongs_to :project, optional: true, counter_cache: true belongs_to :user, optional: true diff --git a/app/views/api/v1/issues/index.json.jbuilder b/app/views/api/v1/issues/index.json.jbuilder index 50165b60b..8d9861f24 100644 --- a/app/views/api/v1/issues/index.json.jbuilder +++ b/app/views/api/v1/issues/index.json.jbuilder @@ -1,4 +1,4 @@ -json.total_issues_count @opened_issues_count +json.total_issues_count @total_issues_count json.opened_count @opened_issues_count json.closed_count @closed_issues_count json.total_count @issues.total_count diff --git a/app/views/api/v1/issues/issue_tags/_detail.json.jbuilder b/app/views/api/v1/issues/issue_tags/_detail.json.jbuilder index 332e47373..43daf1a4a 100644 --- a/app/views/api/v1/issues/issue_tags/_detail.json.jbuilder +++ b/app/views/api/v1/issues/issue_tags/_detail.json.jbuilder @@ -1,4 +1,6 @@ -json.(tag,:id, :name, :description, :color, :issues_count) +json.(tag,:id, :name, :description, :color) +json.issues_count tag.issue_issues.size +json.pull_requests_count tag.pull_request_issues.size json.project do if tag.project.present? json.partial! "api/v1/projects/simple_detail", project: tag.project From dc9ca7d0ca6dc5fee5a590f6d9749584fd283bbe Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 23 Feb 2023 15:24:30 +0800 Subject: [PATCH 045/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E7=96=91?= =?UTF-8?q?=E4=BF=AEparam=E4=B8=BAindex=E4=BB=A5=E5=8F=8A=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E7=BB=9F=E8=AE=A1=E6=A0=87=E7=AD=BE=E4=B8=8B=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E8=AF=B7=E6=B1=82=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/issues/journals_controller.rb | 13 ++++++++++--- .../api/v1/issues/milestones_controller.rb | 1 + app/controllers/api/v1/issues_controller.rb | 8 +++----- app/models/issue_tags_relate.rb | 12 +++++++++++- .../v1/issues/milestones/detail_issues_service.rb | 2 +- app/views/api/v1/issues/index.json.jbuilder | 1 + .../api/v1/issues/issue_tags/_detail.json.jbuilder | 4 ++-- config/routes/api.rb | 2 +- ...30223065106_add_some_columns_to_issue_upgrade.rb | 5 +++++ lib/tasks/upgrade_issue_generate_data.rake | 6 +++++- 10 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 db/migrate/20230223065106_add_some_columns_to_issue_upgrade.rb diff --git a/app/controllers/api/v1/issues/journals_controller.rb b/app/controllers/api/v1/issues/journals_controller.rb index b184392a0..596c8d9e9 100644 --- a/app/controllers/api/v1/issues/journals_controller.rb +++ b/app/controllers/api/v1/issues/journals_controller.rb @@ -1,7 +1,7 @@ -class Api::V1::Issues::JournalsController < Api::V1::IssuesController +class Api::V1::Issues::JournalsController < Api::V1::BaseController before_action :require_login, except: [:index, :children_journals] - before_action :require_public_and_member_above, only: [:index, :create, :children_journals, :update, :destroy] - before_action :load_issue, only: [:index, :create, :children_journals, :update, :destroy] + before_action :require_public_and_member_above + before_action :load_issue before_action :load_journal, only: [:children_journals, :update, :destroy] before_action :check_journal_operate_permission, only: [:update, :destroy] @@ -41,6 +41,13 @@ class Api::V1::Issues::JournalsController < Api::V1::IssuesController params.permit(:notes, :parent_id, :reply_id, :attachment_ids => []) end + def load_issue + @issue = @project.issues.where(project_issues_index: params[:index]).where.not(id: params[:index]).take || Issue.find_by_id(params[:index]) + if @issue.blank? + render_not_found("疑修不存在!") + end + end + def load_journal @journal = Journal.find_by_id(params[:id]) return render_not_found("评论不存在!") unless @journal.present? diff --git a/app/controllers/api/v1/issues/milestones_controller.rb b/app/controllers/api/v1/issues/milestones_controller.rb index d0fc0be4a..fba207c5c 100644 --- a/app/controllers/api/v1/issues/milestones_controller.rb +++ b/app/controllers/api/v1/issues/milestones_controller.rb @@ -11,6 +11,7 @@ class Api::V1::Issues::MilestonesController < Api::V1::BaseController @closed_milestone_count = @milestones.closed.size @opening_milestone_count = @milestones.opening.size @milestones = params[:category] == "closed" ? @milestones.closed : @milestones.opening + @milestones = milestones.order("#{sort_by} #{sort_direction}") if params[:only_name] @milestones = @milestones.select(:id, :name) @milestones = kaminary_select_paginate(@milestones) diff --git a/app/controllers/api/v1/issues_controller.rb b/app/controllers/api/v1/issues_controller.rb index 7f2b5ee4d..acf92e834 100644 --- a/app/controllers/api/v1/issues_controller.rb +++ b/app/controllers/api/v1/issues_controller.rb @@ -57,10 +57,10 @@ class Api::V1::IssuesController < Api::V1::BaseController end end - protected + private def load_issue - @issue = @project.issues.where(project_issues_index: params[:id]).where.not(id: params[:id]).take || Issue.find_by_id(params[:id]) + @issue = @project.issues.where(project_issues_index: params[:index]).where.not(id: params[:index]).take || Issue.find_by_id(params[:index]) if @issue.blank? render_not_found("疑修不存在!") end @@ -79,9 +79,7 @@ class Api::V1::IssuesController < Api::V1::BaseController def check_issue_operate_permission return render_forbidden("您没有操作权限!") unless @project.member?(current_user) || current_user.admin? || @issue.user == current_user - end - - private + end def query_params params.permit( diff --git a/app/models/issue_tags_relate.rb b/app/models/issue_tags_relate.rb index df9fd81ae..8bd1486d7 100644 --- a/app/models/issue_tags_relate.rb +++ b/app/models/issue_tags_relate.rb @@ -15,5 +15,15 @@ class IssueTagsRelate < ApplicationRecord belongs_to :issue - belongs_to :issue_tag, counter_cache: :issues_count + belongs_to :issue_tag + + after_create :increment_issue_tags_counter_cache + + def increment_issue_tags_counter_cache + if self.issue.issue_classify == "Issue" + IssueTag.increment_counter :issues_count, issue_tag_id + else + IssueTag.increment_counter :pull_requests_count, issue_tag_id + end + end end diff --git a/app/services/api/v1/issues/milestones/detail_issues_service.rb b/app/services/api/v1/issues/milestones/detail_issues_service.rb index c6b250a58..a6fc5815d 100644 --- a/app/services/api/v1/issues/milestones/detail_issues_service.rb +++ b/app/services/api/v1/issues/milestones/detail_issues_service.rb @@ -16,7 +16,7 @@ class Api::V1::Issues::Milestones::DetailIssuesService < ApplicationService @author_id = params[:author_id] @assigner_id = params[:assigner_id] @issue_tag_ids = params[:issue_tag_ids].present? ? params[:issue_tag_ids].split(",") : [] - @sort_by = params[:sort_by].present? ? params[:sort_by] : 'updated_on' + @sort_by = params[:sort_by].present? ? params[:sort_by] : 'issues.updated_on' @sort_direction = (params[:sort_direction].present? ? params[:sort_direction] : 'desc').downcase @current_user = current_user end diff --git a/app/views/api/v1/issues/index.json.jbuilder b/app/views/api/v1/issues/index.json.jbuilder index 8d9861f24..6a04c56ac 100644 --- a/app/views/api/v1/issues/index.json.jbuilder +++ b/app/views/api/v1/issues/index.json.jbuilder @@ -2,6 +2,7 @@ json.total_issues_count @total_issues_count json.opened_count @opened_issues_count json.closed_count @closed_issues_count json.total_count @issues.total_count +json.has_created_issues @project.issues.size > 0 json.issues @issues.each do |issue| json.partial! "simple_detail", locals: {issue: issue} end \ No newline at end of file diff --git a/app/views/api/v1/issues/issue_tags/_detail.json.jbuilder b/app/views/api/v1/issues/issue_tags/_detail.json.jbuilder index 43daf1a4a..8fef8b1f6 100644 --- a/app/views/api/v1/issues/issue_tags/_detail.json.jbuilder +++ b/app/views/api/v1/issues/issue_tags/_detail.json.jbuilder @@ -1,6 +1,6 @@ json.(tag,:id, :name, :description, :color) -json.issues_count tag.issue_issues.size -json.pull_requests_count tag.pull_request_issues.size +json.issues_count tag.issues_count +json.pull_requests_count tag.pull_requests_count json.project do if tag.project.present? json.partial! "api/v1/projects/simple_detail", project: tag.project diff --git a/config/routes/api.rb b/config/routes/api.rb index 6c9b3dcdf..5c82d3367 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -25,7 +25,7 @@ defaults format: :json do end end - resources :issues, except: [:new, :edit] do + resources :issues, param: :index, except: [:new, :edit] do collection do patch :batch_update delete :batch_destroy diff --git a/db/migrate/20230223065106_add_some_columns_to_issue_upgrade.rb b/db/migrate/20230223065106_add_some_columns_to_issue_upgrade.rb new file mode 100644 index 000000000..161328746 --- /dev/null +++ b/db/migrate/20230223065106_add_some_columns_to_issue_upgrade.rb @@ -0,0 +1,5 @@ +class AddSomeColumnsToIssueUpgrade < ActiveRecord::Migration[5.2] + def change + add_column :issue_tags, :pull_requests_count, :integer, default: 0 + end +end diff --git a/lib/tasks/upgrade_issue_generate_data.rake b/lib/tasks/upgrade_issue_generate_data.rake index 1fbe5df24..6d016a653 100644 --- a/lib/tasks/upgrade_issue_generate_data.rake +++ b/lib/tasks/upgrade_issue_generate_data.rake @@ -29,9 +29,13 @@ namespace :upgrade_issue_generate_data do puts "____________fix start________________" IssuePriority.init_data IssueStatus.init_data + IssueTag.order(created_at: :desc).find_each do |it| + it.update_column(:issues_count, it.issue_issues.size) + it.update_column(:pull_requests_count, it.pull_request_issues.size) + end IssueTag.where(user_id: nil).destroy_all count = 0 - Project.order(created_at: :desc).find_each do |project| + Project.order(created_on: :desc).find_each do |project| count += 1 IssueTag.init_data(project.id) end From 1fcdbe9dcef890434e8b5271cffeb40c1c5682df Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 23 Feb 2023 15:26:30 +0800 Subject: [PATCH 046/438] =?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/milestones_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/v1/issues/milestones_controller.rb b/app/controllers/api/v1/issues/milestones_controller.rb index fba207c5c..426dca0bf 100644 --- a/app/controllers/api/v1/issues/milestones_controller.rb +++ b/app/controllers/api/v1/issues/milestones_controller.rb @@ -11,7 +11,7 @@ class Api::V1::Issues::MilestonesController < Api::V1::BaseController @closed_milestone_count = @milestones.closed.size @opening_milestone_count = @milestones.opening.size @milestones = params[:category] == "closed" ? @milestones.closed : @milestones.opening - @milestones = milestones.order("#{sort_by} #{sort_direction}") + @milestones = @milestones.order("#{sort_by} #{sort_direction}") if params[:only_name] @milestones = @milestones.select(:id, :name) @milestones = kaminary_select_paginate(@milestones) From c589fcc6a4c6fd4e1dc8138f02cc0baf9f1b7972 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 23 Feb 2023 15:27:26 +0800 Subject: [PATCH 047/438] =?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/milestones_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/v1/issues/milestones_controller.rb b/app/controllers/api/v1/issues/milestones_controller.rb index 426dca0bf..535dbe05d 100644 --- a/app/controllers/api/v1/issues/milestones_controller.rb +++ b/app/controllers/api/v1/issues/milestones_controller.rb @@ -11,7 +11,7 @@ class Api::V1::Issues::MilestonesController < Api::V1::BaseController @closed_milestone_count = @milestones.closed.size @opening_milestone_count = @milestones.opening.size @milestones = params[:category] == "closed" ? @milestones.closed : @milestones.opening - @milestones = @milestones.order("#{sort_by} #{sort_direction}") + @milestones = @milestones.order("versions.#{sort_by} #{sort_direction}") if params[:only_name] @milestones = @milestones.select(:id, :name) @milestones = kaminary_select_paginate(@milestones) From 7cb2321c02af0c3a4282d1144e1724611c800cc5 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 23 Feb 2023 15:31:03 +0800 Subject: [PATCH 048/438] =?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/milestones_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/issues/milestones_controller.rb b/app/controllers/api/v1/issues/milestones_controller.rb index 535dbe05d..26a3dbbf6 100644 --- a/app/controllers/api/v1/issues/milestones_controller.rb +++ b/app/controllers/api/v1/issues/milestones_controller.rb @@ -11,7 +11,7 @@ class Api::V1::Issues::MilestonesController < Api::V1::BaseController @closed_milestone_count = @milestones.closed.size @opening_milestone_count = @milestones.opening.size @milestones = params[:category] == "closed" ? @milestones.closed : @milestones.opening - @milestones = @milestones.order("versions.#{sort_by} #{sort_direction}") + @milestones = @milestones.reorder("versions.#{sort_by} #{sort_direction}") if params[:only_name] @milestones = @milestones.select(:id, :name) @milestones = kaminary_select_paginate(@milestones) @@ -74,7 +74,7 @@ class Api::V1::Issues::MilestonesController < Api::V1::BaseController end def sort_direction - %w(desc asc).include?(params.fetch(:sort_direction, "updated_on")) ? params.fetch(:sort_direction, "updated_on") : "updated_on" + %w(desc asc).include?(params.fetch(:sort_direction, "desc")) ? params.fetch(:sort_direction, "desc") : "desc" end end \ No newline at end of file From dc01d7fc3edf0cc12cf1197fb572cd41aedc79f7 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 23 Feb 2023 16:18:09 +0800 Subject: [PATCH 049/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/issues/milestones_controller.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/v1/issues/milestones_controller.rb b/app/controllers/api/v1/issues/milestones_controller.rb index 26a3dbbf6..760ece707 100644 --- a/app/controllers/api/v1/issues/milestones_controller.rb +++ b/app/controllers/api/v1/issues/milestones_controller.rb @@ -70,11 +70,16 @@ class Api::V1::Issues::MilestonesController < Api::V1::BaseController end def sort_by - Version.columns.include?(params.fetch(:sort_by, "created_on")) ? params.fetch(:sort_by, "created_on") : "created_on" + sort_by = params.fetch(:sort_by, "created_on") + sort_by = Version.column_names.include?(sort_by) ? sort_by : "created_on" + + sort_by end - def sort_direction - %w(desc asc).include?(params.fetch(:sort_direction, "desc")) ? params.fetch(:sort_direction, "desc") : "desc" + def sort_direction + sort_direction = params.fetch(:sort_direction, "desc").downcase + sort_direction = %w(desc asc).include?(sort_direction) ? sort_direction : "desc" + sort_direction end end \ No newline at end of file From 8487c67bab006dcda462638210a276ff2901d3be Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 23 Feb 2023 17:32:55 +0800 Subject: [PATCH 050/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Aissue=5Fclas?= =?UTF-8?q?sify=20=E4=BD=BF=E7=94=A8=E5=B0=8F=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/issue.rb | 3 +++ app/models/issue_tags_relate.rb | 2 +- app/models/version.rb | 4 ++-- app/services/api/v1/issues/batch_update_service.rb | 2 +- app/services/api/v1/issues/create_service.rb | 2 +- app/services/api/v1/issues/list_service.rb | 6 +++--- app/services/api/v1/issues/update_service.rb | 10 +++++----- app/views/api/v1/issues/_detail.json.jbuilder | 2 +- app/views/api/v1/issues/_simple_detail.json.jbuilder | 4 ++-- 9 files changed, 19 insertions(+), 16 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 78ffaead7..fefa6960c 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -73,6 +73,9 @@ class Issue < ApplicationRecord has_many :issue_participants, dependent: :destroy has_many :participants, through: :issue_participants has_many :show_participants, -> {joins(:issue_participants).where.not(issue_participants: {participant_type: "atme"}).distinct}, through: :issue_participants, source: :participant + has_many :show_assigners, -> {order("issue_assigners.created_at desc").limit(5)}, through: :issue_assigners, source: :assigner + has_many :show_issue_tags, -> {order("issue_tags_relates.created_at desc").limit(3)}, through: :issue_tags_relates, source: :issue_tag + has_many :comment_journals, -> {where.not(notes: nil)}, class_name: "Journal", :as => :journalized has_many :operate_journals, -> {where(notes: nil)}, class_name: "Journal", :as => :journalized diff --git a/app/models/issue_tags_relate.rb b/app/models/issue_tags_relate.rb index 8bd1486d7..13eaa780f 100644 --- a/app/models/issue_tags_relate.rb +++ b/app/models/issue_tags_relate.rb @@ -20,7 +20,7 @@ class IssueTagsRelate < ApplicationRecord after_create :increment_issue_tags_counter_cache def increment_issue_tags_counter_cache - if self.issue.issue_classify == "Issue" + if self.issue.issue_classify == "issue" IssueTag.increment_counter :issues_count, issue_tag_id else IssueTag.increment_counter :pull_requests_count, issue_tag_id diff --git a/app/models/version.rb b/app/models/version.rb index fab193b96..1e14a135c 100644 --- a/app/models/version.rb +++ b/app/models/version.rb @@ -28,8 +28,8 @@ class Version < ApplicationRecord has_many :issues, class_name: "Issue", foreign_key: "fixed_version_id" belongs_to :user, optional: true - has_many :opened_issues, -> {where(issue_classify: "Issue").where.not(status_id: 5)}, class_name: "Issue", foreign_key: :fixed_version_id - has_many :closed_issues, -> {where(issue_classify: "Issue", status_id: 5)}, class_name: "Issue", foreign_key: :fixed_version_id + has_many :opened_issues, -> {where(issue_classify: "issue").where.not(status_id: 5)}, class_name: "Issue", foreign_key: :fixed_version_id + has_many :closed_issues, -> {where(issue_classify: "issue", status_id: 5)}, class_name: "Issue", foreign_key: :fixed_version_id scope :version_includes, ->{includes(:issues, :user)} scope :closed, ->{where(status: 'closed')} diff --git a/app/services/api/v1/issues/batch_update_service.rb b/app/services/api/v1/issues/batch_update_service.rb index cf09650ce..ccf783dca 100644 --- a/app/services/api/v1/issues/batch_update_service.rb +++ b/app/services/api/v1/issues/batch_update_service.rb @@ -20,7 +20,7 @@ class Api::V1::Issues::BatchUpdateService < ApplicationService raise Error, errors.full_messages.join(", ") unless valid? ActiveRecord::Base.transaction do @issues.each do |issue| - if issue.issue_classify == "Issue" + if issue.issue_classify == "issue" Api::V1::Issues::UpdateService.call(project, issue, params, current_user) end end diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index ffc08eb96..b6b785188 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -85,7 +85,7 @@ class Api::V1::Issues::CreateService < ApplicationService priority_id: priority_id, project_issues_index: (project.get_last_project_issues_index + 1), issue_type: "1", - issue_classify: "Issue" + issue_classify: "issue" } issue_attributes.merge!({description: description}) if description.present? diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index c1b386345..979f50c3d 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -56,7 +56,7 @@ class Api::V1::Issues::ListService < ApplicationService issues = issues.where(author_id: author_id) if author_id.present? # issue_tag_ids - issues = issues.joins(:issue_tags).where(issue_tags: {id: issue_tag_ids}) unless issue_tag_ids.blank? + issues = issues.joins(:issue_tags).ransack(issue_tags_id_in_all: issue_tag_ids).result unless issue_tag_ids.blank? # milestone_id issues = issues.where(fixed_version_id: milestone_id) if milestone_id.present? @@ -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 + issues = issues.ransack(subject_or_description_cont: keyword).result if keyword.present? @total_issues_count = issues.size @closed_issues_count = issues.closed.size @@ -81,7 +81,7 @@ class Api::V1::Issues::ListService < ApplicationService issues = issues.opened end - scope = issues.includes(:priority, :issue_status, :user, :assigners, :version, :issue_tags, :comment_journals) + scope = issues.includes(:priority, :issue_status, :user, :show_assigners, :show_issue_tags, :version, :issue_tags, :comment_journals) scope = scope.reorder("#{sort_by} #{sort_direction}").distinct diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 597880eb3..a120dabc7 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -36,14 +36,14 @@ class Api::V1::Issues::UpdateService < ApplicationService check_issue_status(status_id) if status_id.present? check_issue_priority(priority_id) if priority_id.present? check_milestone(milestone_id) if milestone_id.present? - check_issue_tags(issue_tag_ids) unless issue_tag_ids.blank? - check_assigners(assigner_ids) unless assigner_ids.blank? - check_attachments(attachment_ids) unless attachment_ids.blank? - check_atme_receivers(receivers_login) unless receivers_login.blank? + check_issue_tags(issue_tag_ids) unless issue_tag_ids.nil? + check_assigners(assigner_ids) unless assigner_ids.nil? + check_attachments(attachment_ids) unless attachment_ids.nil? + check_atme_receivers(receivers_login) unless receivers_login.nil? load_assigners(assigner_ids) load_attachments(attachment_ids) load_issue_tags(issue_tag_ids) - load_atme_receivers(receivers_login) unless receivers_login.blank? + load_atme_receivers(receivers_login) unless receivers_login.nil? try_lock("Api::V1::Issues::UpdateService:#{project.id}:#{issue.id}") @updated_issue = @issue diff --git a/app/views/api/v1/issues/_detail.json.jbuilder b/app/views/api/v1/issues/_detail.json.jbuilder index 3961270ae..a39cdde9e 100644 --- a/app/views/api/v1/issues/_detail.json.jbuilder +++ b/app/views/api/v1/issues/_detail.json.jbuilder @@ -32,7 +32,7 @@ json.author do json.nil! end end -json.assigners issue.assigners.each do |assigner| +json.assigners issue.show_assigners.each do |assigner| json.partial! "api/v1/users/simple_user", locals: {user: assigner} end json.participants issue.participants.distinct.each do |participant| diff --git a/app/views/api/v1/issues/_simple_detail.json.jbuilder b/app/views/api/v1/issues/_simple_detail.json.jbuilder index bfc2693cf..7e0d6b11f 100644 --- a/app/views/api/v1/issues/_simple_detail.json.jbuilder +++ b/app/views/api/v1/issues/_simple_detail.json.jbuilder @@ -1,7 +1,7 @@ json.(issue, :id, :subject, :project_issues_index) 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.issue_tags.each do |tag| +json.tags issue.show_issue_tags.each do |tag| json.partial! "api/v1/issues/issue_tags/simple_detail", locals: {tag: tag} end json.status_name issue.issue_status&.name @@ -14,7 +14,7 @@ json.author do json.nil! end end -json.assigners issue.assigners.each do |assigner| +json.assigners issue.show_assigners.each do |assigner| json.partial! "api/v1/users/simple_user", locals: {user: assigner} end json.comment_journals_count issue.comment_journals.size \ No newline at end of file From 3fd04109d61c1f274c71f4c844671d1fa1df7457 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 23 Feb 2023 20:54:48 +0800 Subject: [PATCH 051/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/issues/journals_controller.rb | 4 ++-- app/models/issue.rb | 4 ++-- app/services/api/v1/issues/create_service.rb | 1 + .../api/v1/issues/journals/create_service.rb | 16 ++++++++++++++- .../api/v1/issues/journals/update_service.rb | 20 ++++++++++++++++++- app/services/api/v1/issues/list_service.rb | 4 ++-- app/services/api/v1/issues/update_service.rb | 1 + 7 files changed, 42 insertions(+), 8 deletions(-) diff --git a/app/controllers/api/v1/issues/journals_controller.rb b/app/controllers/api/v1/issues/journals_controller.rb index 596c8d9e9..12406ef49 100644 --- a/app/controllers/api/v1/issues/journals_controller.rb +++ b/app/controllers/api/v1/issues/journals_controller.rb @@ -38,7 +38,7 @@ class Api::V1::Issues::JournalsController < Api::V1::BaseController end def journal_params - params.permit(:notes, :parent_id, :reply_id, :attachment_ids => []) + params.permit(:notes, :parent_id, :reply_id, :attachment_ids => [], :receivers_login => []) end def load_issue @@ -54,7 +54,7 @@ class Api::V1::Issues::JournalsController < Api::V1::BaseController end def check_journal_operate_permission - return render_forbidden("您没有操作权限!") unless current_user.present? && current_user.logged? && (@project.member?(current_user) || current_user.admin? || @issue.user == current_user || @journal.user == current_user) + return render_forbidden("您没有操作权限!") unless @project.member?(current_user) || current_user.admin? || @issue.user == current_user || @journal.user == current_user || @journal.parent_journal&.user == current_user end end \ No newline at end of file diff --git a/app/models/issue.rb b/app/models/issue.rb index fefa6960c..3efaac03a 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -73,8 +73,8 @@ class Issue < ApplicationRecord has_many :issue_participants, dependent: :destroy has_many :participants, through: :issue_participants has_many :show_participants, -> {joins(:issue_participants).where.not(issue_participants: {participant_type: "atme"}).distinct}, through: :issue_participants, source: :participant - has_many :show_assigners, -> {order("issue_assigners.created_at desc").limit(5)}, through: :issue_assigners, source: :assigner - has_many :show_issue_tags, -> {order("issue_tags_relates.created_at desc").limit(3)}, through: :issue_tags_relates, source: :issue_tag + has_many :show_assigners, -> {joins(:issue_assigners).order("issue_assigners.created_at desc").limit(5)}, through: :issue_assigners, source: :assigner + has_many :show_issue_tags, -> {joins(:issue_tags_relates).order("issue_tags_relates.created_at desc").limit(3)}, through: :issue_tags_relates, source: :issue_tag has_many :comment_journals, -> {where.not(notes: nil)}, class_name: "Journal", :as => :journalized has_many :operate_journals, -> {where(notes: nil)}, class_name: "Journal", :as => :journalized diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index b6b785188..e353b86e0 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -55,6 +55,7 @@ class Api::V1::Issues::CreateService < ApplicationService @created_issue.attachments = @attachments unless attachment_ids.blank? @created_issue.issue_tags = @issue_tags unless issue_tag_ids.blank? + @created_issue.issue_tags_value = @issue_tags.order("id asc").pluck(:id).join(",") unless issue_tag_ids.blank? @created_issue.save! project.del_project_issue_cache_delete_count # 把缓存里存储项目删除issue的个数清除掉 diff --git a/app/services/api/v1/issues/journals/create_service.rb b/app/services/api/v1/issues/journals/create_service.rb index 6bd2479d9..470636120 100644 --- a/app/services/api/v1/issues/journals/create_service.rb +++ b/app/services/api/v1/issues/journals/create_service.rb @@ -3,7 +3,7 @@ class Api::V1::Issues::Journals::CreateService < ApplicationService include Api::V1::Issues::Concerns::Checkable include Api::V1::Issues::Concerns::Loadable - attr_reader :issue, :current_user, :notes, :parent_id, :reply_id, :attachment_ids + attr_reader :issue, :current_user, :notes, :parent_id, :reply_id, :attachment_ids, :receivers_login attr_accessor :created_journal validates :notes, :issue, :current_user, presence: true @@ -14,6 +14,7 @@ class Api::V1::Issues::Journals::CreateService < ApplicationService @parent_id = params[:parent_id] @reply_id = params[:reply_id] @attachment_ids = params[:attachment_ids] + @receivers_login = params[:receivers_login] @current_user = current_user end @@ -24,15 +25,22 @@ class Api::V1::Issues::Journals::CreateService < ApplicationService check_parent_journal(parent_id) if parent_id.present? check_parent_journal(reply_id) if reply_id.present? check_attachments(attachment_ids) unless attachment_ids.blank? + check_atme_receivers(receivers_login) unless receivers_login.blank? load_attachments(attachment_ids) unless attachment_ids.blank? + load_atme_receivers(receivers_login) unless receivers_login.blank? try_lock("Api::V1::Issues::Journals::CreateService:#{@issue.id}") @created_journal = @issue.journals.new(journal_attributes) build_comment_participants + build_atme_participants if @atme_receivers.present? @created_journal.attachments = @attachments unless attachment_ids.blank? @created_journal.save! + + # @信息发送 + AtmeService.call(current_user, @atme_receivers, @issue) unless receivers_login.blank? + unlock("Api::V1::Issues::Journals::CreateService:#{@issue.id}") @created_journal @@ -56,4 +64,10 @@ class Api::V1::Issues::Journals::CreateService < ApplicationService def build_comment_participants @issue.issue_participants.new({participant_type: "commented", participant_id: current_user.id}) unless @issue.issue_participants.exists?(participant_type: "commented", participant_id: current_user.id) end + + def build_atme_participants + atme_receivers.each do |receiver| + @created_issue.issue_participants.new({participant_type: "atme", participant_id: receiver.id}) + end + end end \ No newline at end of file diff --git a/app/services/api/v1/issues/journals/update_service.rb b/app/services/api/v1/issues/journals/update_service.rb index 321c79cdb..0b356f93e 100644 --- a/app/services/api/v1/issues/journals/update_service.rb +++ b/app/services/api/v1/issues/journals/update_service.rb @@ -3,7 +3,7 @@ class Api::V1::Issues::Journals::UpdateService < ApplicationService include Api::V1::Issues::Concerns::Checkable include Api::V1::Issues::Concerns::Loadable - attr_reader :issue, :journal, :current_user, :notes, :attachment_ids + attr_reader :issue, :journal, :current_user, :notes, :attachment_ids, :receivers_login attr_accessor :updated_journal validates :notes, :issue, :journal, :current_user, presence: true @@ -13,6 +13,7 @@ class Api::V1::Issues::Journals::UpdateService < ApplicationService @journal = journal @notes = params[:notes] @attachment_ids = params[:attachment_ids] + @receivers_login = params[:receivers_login] @current_user = current_user end @@ -20,18 +21,35 @@ class Api::V1::Issues::Journals::UpdateService < ApplicationService raise Error, errors.full_messages.join(", ") unless valid? ActiveRecord::Base.transaction do check_attachments(attachment_ids) unless attachment_ids.blank? + check_atme_receivers(receivers_login) unless receivers_login.blank? load_attachments(attachment_ids) unless attachment_ids.blank? + load_atme_receivers(receivers_login) unless receivers_login.blank? try_lock("Api::V1::Issues::Journals::UpdateService:#{@issue.id}:#{@journal.id}") @updated_journal = @journal @updated_journal.notes = notes + + build_atme_participants if @atme_receivers.present? + @updated_journal.attachments = @attachments unless attachment_ids.blank? @updated_journal.save! + + # @信息发送 + AtmeService.call(current_user, @atme_receivers, @issue) unless receivers_login.blank? + unlock("Api::V1::Issues::Journals::UpdateService:#{@issue.id}:#{@journal.id}") @updated_journal end end + private + + def build_atme_participants + atme_receivers.each do |receiver| + @created_issue.issue_participants.new({participant_type: "atme", participant_id: receiver.id}) + end + end + end \ No newline at end of file diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index 979f50c3d..a57fbf34d 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -56,8 +56,8 @@ class Api::V1::Issues::ListService < ApplicationService issues = issues.where(author_id: author_id) if author_id.present? # issue_tag_ids - issues = issues.joins(:issue_tags).ransack(issue_tags_id_in_all: issue_tag_ids).result unless issue_tag_ids.blank? - + issues = issues.ransack(issue_tags_value_cont: issue_tag_ids.sort!.join(",")).result unless issue_tag_ids.blank? + # milestone_id issues = issues.where(fixed_version_id: milestone_id) if milestone_id.present? diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index a120dabc7..25b9d23c1 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -58,6 +58,7 @@ class Api::V1::Issues::UpdateService < ApplicationService @updated_issue.assigners = @assigners || User.none unless assigner_ids.nil? @updated_issue.attachments = @attachments || Attachment.none unless attachment_ids.nil? @updated_issue.issue_tags = @issue_tags || IssueTag.none unless issue_tag_ids.nil? + @created_issue.issue_tags_value = @issue_tags.order("id asc").pluck(:id).join(",") unless issue_tag_ids.nil? @updated_issue.updated_on = Time.now @updated_issue.save! From e53d6cd7631c216f2565ba62ea47ef4940f3ecd4 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 23 Feb 2023 21:03:40 +0800 Subject: [PATCH 052/438] =?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/update_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 25b9d23c1..9f6a1f736 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -58,7 +58,7 @@ class Api::V1::Issues::UpdateService < ApplicationService @updated_issue.assigners = @assigners || User.none unless assigner_ids.nil? @updated_issue.attachments = @attachments || Attachment.none unless attachment_ids.nil? @updated_issue.issue_tags = @issue_tags || IssueTag.none unless issue_tag_ids.nil? - @created_issue.issue_tags_value = @issue_tags.order("id asc").pluck(:id).join(",") unless issue_tag_ids.nil? + @updated_issue.issue_tags_value = @issue_tags.order("id asc").pluck(:id).join(",") unless issue_tag_ids.nil? @updated_issue.updated_on = Time.now @updated_issue.save! From 267279df2d03f76f498f2f414b671431fe2efa20 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 24 Feb 2023 09:04:29 +0800 Subject: [PATCH 053/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/issues/issue_tags_controller.rb | 18 +++++++++--------- app/services/api/v1/issues/list_service.rb | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/controllers/api/v1/issues/issue_tags_controller.rb b/app/controllers/api/v1/issues/issue_tags_controller.rb index 2a5038e63..99fc7d45c 100644 --- a/app/controllers/api/v1/issues/issue_tags_controller.rb +++ b/app/controllers/api/v1/issues/issue_tags_controller.rb @@ -4,8 +4,8 @@ class Api::V1::Issues::IssueTagsController < Api::V1::BaseController before_action :require_operate_above, only: [:create, :update, :destroy] def index - @issue_tags = @project.issue_tags.order("#{order_by} #{order_direction}") @issue_tags = @issue_tags.ransack(name_cont: params[:keyword]).result if params[:keyword].present? + @issue_tags = @project.issue_tags.reorder("#{sort_by} #{sort_direction}") if params[:only_name] @issue_tags = kaminary_select_paginate(@issue_tags.select(:id, :name, :color)) else @@ -43,16 +43,16 @@ class Api::V1::Issues::IssueTagsController < Api::V1::BaseController private - def order_by - order_by = params.fetch(:order_by, "created_at") - order_by = IssueTag.column_names.include?(order_by) ? order_by : "created_at" - order_by + def sort_by + sort_by = params.fetch(:sort_by, "created_at") + sort_by = IssueTag.column_names.include?(sort_by) ? sort_by : "created_at" + sort_by end - def order_direction - order_direction = params.fetch(:order_direction, "desc").downcase - order_direction = %w(desc asc).include?(order_direction) ? order_direction : "desc" - order_direction + def sort_direction + sort_direction = params.fetch(:sort_direction, "desc").downcase + sort_direction = %w(desc asc).include?(sort_direction) ? sort_direction : "desc" + sort_direction end def issue_tag_params diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index a57fbf34d..e5a96a481 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -70,9 +70,9 @@ class Api::V1::Issues::ListService < ApplicationService # keyword issues = issues.ransack(subject_or_description_cont: keyword).result if keyword.present? - @total_issues_count = issues.size - @closed_issues_count = issues.closed.size - @opened_issues_count = issues.opened.size + @total_issues_count = issues.distinct.size + @closed_issues_count = issues.closed.distinct.size + @opened_issues_count = issues.opened.distinct.size case category when 'closed' From 35bb8fbc1113b845b8a99010be95ba3136d4c12b Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 24 Feb 2023 10:24:57 +0800 Subject: [PATCH 054/438] =?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 +- app/models/issue.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/v1/issues_controller.rb b/app/controllers/api/v1/issues_controller.rb index acf92e834..1f155c5ea 100644 --- a/app/controllers/api/v1/issues_controller.rb +++ b/app/controllers/api/v1/issues_controller.rb @@ -2,7 +2,6 @@ class Api::V1::IssuesController < Api::V1::BaseController before_action :require_login, except: [:index, :show] before_action :require_public_and_member_above, only: [:index, :show, :create, :update, :destroy] before_action :require_operate_above, only: [:batch_update, :batch_destroy] - before_action :check_issue_operate_permission, only: [:update, :destroy] def index IssueTag.init_data(@project.id) unless $redis_cache.hget("project_init_issue_tags", @project.id) @@ -19,6 +18,7 @@ class Api::V1::IssuesController < Api::V1::BaseController end before_action :load_issue, only: [:show, :update, :destroy] + before_action :check_issue_operate_permission, only: [:update, :destroy] def show @user_permission = current_user.present? && current_user.logged? && (@project.member?(current_user) || current_user.admin? || @issue.user == current_user) diff --git a/app/models/issue.rb b/app/models/issue.rb index 3efaac03a..fa25c06a6 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -73,8 +73,8 @@ class Issue < ApplicationRecord has_many :issue_participants, dependent: :destroy has_many :participants, through: :issue_participants has_many :show_participants, -> {joins(:issue_participants).where.not(issue_participants: {participant_type: "atme"}).distinct}, through: :issue_participants, source: :participant - has_many :show_assigners, -> {joins(:issue_assigners).order("issue_assigners.created_at desc").limit(5)}, through: :issue_assigners, source: :assigner - has_many :show_issue_tags, -> {joins(:issue_tags_relates).order("issue_tags_relates.created_at desc").limit(3)}, through: :issue_tags_relates, source: :issue_tag + has_many :show_assigners, -> {joins(:issue_assigners).order("issue_assigners.created_at desc").distinct.limit(5)}, through: :issue_assigners, source: :assigner + has_many :show_issue_tags, -> {joins(:issue_tags_relates).order("issue_tags_relates.created_at desc").distinct.limit(3)}, through: :issue_tags_relates, source: :issue_tag has_many :comment_journals, -> {where.not(notes: nil)}, class_name: "Journal", :as => :journalized has_many :operate_journals, -> {where(notes: nil)}, class_name: "Journal", :as => :journalized From b616c971dbf0f7c42e76b0959fc85f0cc4590f66 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 24 Feb 2023 14:32:21 +0800 Subject: [PATCH 055/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/issues/issue_tags_controller.rb | 2 +- app/models/issue.rb | 4 ++-- app/models/issue_tag.rb | 4 ++++ app/models/issue_tags_relate.rb | 14 ++++++++++++++ app/services/api/v1/issues/list_service.rb | 2 +- app/services/api/v1/issues/update_service.rb | 2 +- app/views/api/v1/issues/_detail.json.jbuilder | 2 +- lib/tasks/upgrade_issue_generate_data.rake | 3 +-- 8 files changed, 25 insertions(+), 8 deletions(-) diff --git a/app/controllers/api/v1/issues/issue_tags_controller.rb b/app/controllers/api/v1/issues/issue_tags_controller.rb index 99fc7d45c..fe2ecceab 100644 --- a/app/controllers/api/v1/issues/issue_tags_controller.rb +++ b/app/controllers/api/v1/issues/issue_tags_controller.rb @@ -4,8 +4,8 @@ class Api::V1::Issues::IssueTagsController < Api::V1::BaseController before_action :require_operate_above, only: [:create, :update, :destroy] def index - @issue_tags = @issue_tags.ransack(name_cont: params[:keyword]).result if params[:keyword].present? @issue_tags = @project.issue_tags.reorder("#{sort_by} #{sort_direction}") + @issue_tags = @issue_tags.ransack(name_cont: params[:keyword]).result if params[:keyword].present? if params[:only_name] @issue_tags = kaminary_select_paginate(@issue_tags.select(:id, :name, :color)) else diff --git a/app/models/issue.rb b/app/models/issue.rb index fa25c06a6..9fe7b0a9a 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -73,8 +73,8 @@ class Issue < ApplicationRecord has_many :issue_participants, dependent: :destroy has_many :participants, through: :issue_participants has_many :show_participants, -> {joins(:issue_participants).where.not(issue_participants: {participant_type: "atme"}).distinct}, through: :issue_participants, source: :participant - has_many :show_assigners, -> {joins(:issue_assigners).order("issue_assigners.created_at desc").distinct.limit(5)}, through: :issue_assigners, source: :assigner - has_many :show_issue_tags, -> {joins(:issue_tags_relates).order("issue_tags_relates.created_at desc").distinct.limit(3)}, through: :issue_tags_relates, source: :issue_tag + has_many :show_assigners, -> {joins(:issue_assigners).distinct}, through: :issue_assigners, source: :assigner + has_many :show_issue_tags, -> {joins(:issue_tags_relates).distinct}, through: :issue_tags_relates, source: :issue_tag has_many :comment_journals, -> {where.not(notes: nil)}, class_name: "Journal", :as => :journalized has_many :operate_journals, -> {where(notes: nil)}, class_name: "Journal", :as => :journalized diff --git a/app/models/issue_tag.rb b/app/models/issue_tag.rb index 5381da9be..100373e80 100644 --- a/app/models/issue_tag.rb +++ b/app/models/issue_tag.rb @@ -48,5 +48,9 @@ class IssueTag < ApplicationRecord $redis_cache.hset("project_init_issue_tags", project_id, 1) end + def reset_counter_field + self.update_column(:issues_count, issue_issues.size) + self.update_column(:pull_requests_count, pull_request_issues.size) + end end diff --git a/app/models/issue_tags_relate.rb b/app/models/issue_tags_relate.rb index 13eaa780f..fc753e95b 100644 --- a/app/models/issue_tags_relate.rb +++ b/app/models/issue_tags_relate.rb @@ -18,12 +18,26 @@ class IssueTagsRelate < ApplicationRecord belongs_to :issue_tag after_create :increment_issue_tags_counter_cache + after_destroy :decrement_issue_tags_counter_cache def increment_issue_tags_counter_cache + Rails.logger.info "11111" + Rails.logger.info self.issue.issue_classify + if self.issue.issue_classify == "issue" IssueTag.increment_counter :issues_count, issue_tag_id else IssueTag.increment_counter :pull_requests_count, issue_tag_id end end + + def decrement_issue_tags_counter_cache + Rails.logger.info "2222222" + Rails.logger.info self.issue.issue_classify + if self.issue.issue_classify == "issue" + IssueTag.decrement_counter :issues_count, issue_tag_id + else + IssueTag.decrement_counter :pull_requests_count, issue_tag_id + end + end end diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index e5a96a481..f88e1fc63 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -81,7 +81,7 @@ class Api::V1::Issues::ListService < ApplicationService issues = issues.opened end - scope = issues.includes(:priority, :issue_status, :user, :show_assigners, :show_issue_tags, :version, :issue_tags, :comment_journals) + scope = issues.includes(:priority, :issue_status, :user, :show_assigners, :show_issue_tags, :version, :comment_journals) scope = scope.reorder("#{sort_by} #{sort_direction}").distinct diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 9f6a1f736..6a472a9fc 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -57,7 +57,7 @@ class Api::V1::Issues::UpdateService < ApplicationService build_atme_participants if @atme_receivers.present? @updated_issue.assigners = @assigners || User.none unless assigner_ids.nil? @updated_issue.attachments = @attachments || Attachment.none unless attachment_ids.nil? - @updated_issue.issue_tags = @issue_tags || IssueTag.none unless issue_tag_ids.nil? + @updated_issue.issue_tags_relates.destroy_all & @updated_issue.issue_tags = @issue_tags || IssueTag.none unless issue_tag_ids.nil? @updated_issue.issue_tags_value = @issue_tags.order("id asc").pluck(:id).join(",") unless issue_tag_ids.nil? @updated_issue.updated_on = Time.now diff --git a/app/views/api/v1/issues/_detail.json.jbuilder b/app/views/api/v1/issues/_detail.json.jbuilder index a39cdde9e..193357ce1 100644 --- a/app/views/api/v1/issues/_detail.json.jbuilder +++ b/app/views/api/v1/issues/_detail.json.jbuilder @@ -1,7 +1,7 @@ json.(issue, :id, :subject, :project_issues_index, :description, :branch_name, :start_date, :due_date) 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.issue_tags.each do |tag| +json.tags issue.show_issue_tags.each do |tag| json.partial! "api/v1/issues/issue_tags/simple_detail", locals: {tag: tag} end json.status do diff --git a/lib/tasks/upgrade_issue_generate_data.rake b/lib/tasks/upgrade_issue_generate_data.rake index 6d016a653..34a266f25 100644 --- a/lib/tasks/upgrade_issue_generate_data.rake +++ b/lib/tasks/upgrade_issue_generate_data.rake @@ -30,8 +30,7 @@ namespace :upgrade_issue_generate_data do IssuePriority.init_data IssueStatus.init_data IssueTag.order(created_at: :desc).find_each do |it| - it.update_column(:issues_count, it.issue_issues.size) - it.update_column(:pull_requests_count, it.pull_request_issues.size) + it.reset_counter_field end IssueTag.where(user_id: nil).destroy_all count = 0 From dab636d1228e49dd856afedc84968cf16f1c03f2 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 24 Feb 2023 15:26:40 +0800 Subject: [PATCH 056/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/issues/milestones_controller.rb | 10 ++++--- .../milestones/detail_issues_service.rb | 26 +++++++++++-------- .../v1/issues/milestones/show.json.jbuilder | 5 ++-- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/app/controllers/api/v1/issues/milestones_controller.rb b/app/controllers/api/v1/issues/milestones_controller.rb index 760ece707..2ccd2ab90 100644 --- a/app/controllers/api/v1/issues/milestones_controller.rb +++ b/app/controllers/api/v1/issues/milestones_controller.rb @@ -32,10 +32,12 @@ class Api::V1::Issues::MilestonesController < Api::V1::BaseController # 里程碑详情 def show - @object_results = Api::V1::Issues::Milestones::DetailIssuesService.call(@project, @milestone, query_params, current_user) - @closed_issues_count = @object_results.closed.size - @opened_issues_count = @object_results.opened.size - @issues = kaminari_paginate(@object_results) + @object_result = Api::V1::Issues::Milestones::DetailIssuesService.call(@project, @milestone, query_params, current_user) + @total_issues_count = @object_result[:total_issues_count] + @opened_issues_count = @object_result[:opened_issues_count] + @closed_issues_count = @object_result[:closed_issues_count] + + @issues = kaminari_paginate(@object_result[:data]) end def update diff --git a/app/services/api/v1/issues/milestones/detail_issues_service.rb b/app/services/api/v1/issues/milestones/detail_issues_service.rb index a6fc5815d..8b6f69aed 100644 --- a/app/services/api/v1/issues/milestones/detail_issues_service.rb +++ b/app/services/api/v1/issues/milestones/detail_issues_service.rb @@ -2,7 +2,7 @@ class Api::V1::Issues::Milestones::DetailIssuesService < ApplicationService include ActiveModel::Model attr_reader :project, :category, :author_id, :assigner_id, :issue_tag_ids, :sort_by, :sort_direction, :current_user - attr_accessor :queried_issues + attr_accessor :queried_issues, :total_issues_count, :closed_issues_count, :opened_issues_count validates :category, inclusion: {in: %w(all opened closed), message: "请输入正确的Category"} validates :sort_by, inclusion: {in: ['issues.created_on', 'issues.updated_on', 'issue_priorities.position'], message: '请输入正确的SortBy'}, allow_blank: true @@ -26,7 +26,7 @@ class Api::V1::Issues::Milestones::DetailIssuesService < ApplicationService begin issue_query_data - queried_issues + return {data: queried_issues, total_issues_count: @total_issues_count, closed_issues_count: @closed_issues_count, opened_issues_count: @opened_issues_count} rescue raise Error, "服务器错误,请联系系统管理员!" end @@ -36,22 +36,26 @@ class Api::V1::Issues::Milestones::DetailIssuesService < ApplicationService def issue_query_data issues = @milestone.issues.issue_issue - case category - when 'closed' - issues = issues.closed - when 'opened' - issues = issues.opened - end - # author_id issues = issues.where(author_id: author_id) if author_id.present? # assigner_id issues = issues.joins(:assigners).where(users: {id: assigner_id}).or(issues.joins(:assigners).where(assigned_to_id: assigner_id)) if assigner_id.present? - issues = issues.joins(:issue_tags).where(issue_tags: {id: issue_tag_ids}) if issue_tag_ids.present? + issues = issues.ransack(issue_tags_value_cont: issue_tag_ids.sort!.join(",")).result unless issue_tag_ids.blank? + + @total_issues_count = issues.distinct.size + @closed_issues_count = issues.closed.distinct.size + @opened_issues_count = issues.opened.distinct.size + + case category + when 'closed' + issues = issues.closed + when 'opened' + issues = issues.opened + end - scope = issues.includes(:priority, :issue_status, :user, :assigners, :version, :issue_tags, :comment_journals).references(:assigners) + scope = issues.includes(:priority, :issue_status, :user, :show_assigners, :version, :show_issue_tags, :comment_journals).references(:assigners) scope = scope.reorder("#{sort_by} #{sort_direction}").distinct diff --git a/app/views/api/v1/issues/milestones/show.json.jbuilder b/app/views/api/v1/issues/milestones/show.json.jbuilder index 01632e9d0..ce1886522 100644 --- a/app/views/api/v1/issues/milestones/show.json.jbuilder +++ b/app/views/api/v1/issues/milestones/show.json.jbuilder @@ -1,11 +1,12 @@ json.milestone do json.partial! "detail", locals: {milestone: @milestone} end -json.total_issues_count @issues.total_count +json.total_issues_count @total_issues_count json.closed_issues_count @closed_issues_count json.opened_issues_count @opened_issues_count +json.total_count @issues.total_count json.issues @issues.each do |issue| - if issue.issue_classify == "Issue" + if issue.issue_classify == "issue" json.partial! "api/v1/issues/simple_detail", locals: {issue: issue} end end \ No newline at end of file From 2e0b32f86b961ecaaab59099780c9afabda87cc2 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 27 Feb 2023 10:46:56 +0800 Subject: [PATCH 057/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Aatme?= =?UTF-8?q?=E5=92=8Cissue=20category=20=E6=97=A0=E6=B3=95=E6=AD=A3?= =?UTF-8?q?=E5=B8=B8=E6=90=9C=E7=B4=A2?= 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/list_service.rb | 16 ++++++++-------- app/services/api/v1/issues/update_service.rb | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index e353b86e0..ec4aeac0b 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -109,7 +109,7 @@ class Api::V1::Issues::CreateService < ApplicationService end def build_atme_participants - atme_receivers.each do |receiver| + @atme_receivers.each do |receiver| @created_issue.issue_participants.new({participant_type: "atme", participant_id: receiver.id}) end end diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index f88e1fc63..66e64d02b 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -28,13 +28,13 @@ class Api::V1::Issues::ListService < ApplicationService def call raise Error, errors.full_messages.join(", ") unless valid? - begin + # begin issue_query_data return {data: queried_issues, total_issues_count: @total_issues_count, closed_issues_count: @closed_issues_count, opened_issues_count: @opened_issues_count} - rescue - raise Error, "服务器错误,请联系系统管理员!" - end + # rescue + # raise Error, "服务器错误,请联系系统管理员!" + # end end private @@ -43,13 +43,13 @@ class Api::V1::Issues::ListService < ApplicationService case participant_category when 'aboutme' # 关于我的 - issues = issues.joins(:participants, :issue_participants).where(issue_participants: {participant_type: %(authored assigned atme)},users: {id: current_user&.id}) + issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: %(authored assigned atme), participant_id: current_user&.id}) when 'authoredme' # 我创建的 - issues = issues.joins(:participants, :issue_participants).where(issue_participants: {participant_type: 'assigned'},users: {id: current_user&.id}) + issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: 'authored', participant_id: current_user&.id}) when 'assignedme' # 我负责的 - issues = issues.joins(:participants, :issue_participants).where(issue_participants: {participant_type: 'assigned'},users: {id: current_user&.id}) + issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: 'assigned', participant_id: current_user&.id}) when 'atme' # @我的 - issues = issues.joins(:participants, :issue_participants).where(issue_participants: {participant_type: 'atme'},users: {id: current_user&.id}) + issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: 'atme', participant_id: current_user&.id}) end # author_id diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 6a472a9fc..45274b9c4 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -111,7 +111,7 @@ class Api::V1::Issues::UpdateService < ApplicationService end def build_atme_participants - atme_receivers.each do |receiver| + @atme_receivers.each do |receiver| next if @updated_issue.issue_participants.exists?(participant_type: "atme", participant_id: receiver.id) @updated_issue.issue_participants.new({participant_type: "atme", participant_id: receiver.id}) end From a30a3c56b60b920cba056e76a054e4f1d3470443 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 27 Feb 2023 10:55:53 +0800 Subject: [PATCH 058/438] =?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/api/v1/issues/journals/update_service.rb | 2 +- app/services/api/v1/issues/list_service.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/services/api/v1/issues/journals/create_service.rb b/app/services/api/v1/issues/journals/create_service.rb index 470636120..72270f63e 100644 --- a/app/services/api/v1/issues/journals/create_service.rb +++ b/app/services/api/v1/issues/journals/create_service.rb @@ -66,7 +66,7 @@ class Api::V1::Issues::Journals::CreateService < ApplicationService end def build_atme_participants - atme_receivers.each do |receiver| + @atme_receivers.each do |receiver| @created_issue.issue_participants.new({participant_type: "atme", participant_id: receiver.id}) end end diff --git a/app/services/api/v1/issues/journals/update_service.rb b/app/services/api/v1/issues/journals/update_service.rb index 0b356f93e..4c301bc41 100644 --- a/app/services/api/v1/issues/journals/update_service.rb +++ b/app/services/api/v1/issues/journals/update_service.rb @@ -47,7 +47,7 @@ class Api::V1::Issues::Journals::UpdateService < ApplicationService private def build_atme_participants - atme_receivers.each do |receiver| + @atme_receivers.each do |receiver| @created_issue.issue_participants.new({participant_type: "atme", participant_id: receiver.id}) end end diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index 66e64d02b..fa27f4ee4 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -43,7 +43,7 @@ class Api::V1::Issues::ListService < ApplicationService case participant_category when 'aboutme' # 关于我的 - issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: %(authored assigned atme), participant_id: current_user&.id}) + issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: %w(authored assigned atme), participant_id: current_user&.id}) when 'authoredme' # 我创建的 issues = issues.joins(:issue_participants).where(issue_participants: {participant_type: 'authored', participant_id: current_user&.id}) when 'assignedme' # 我负责的 From 4c26085e58615bede02b57a57056cf07f9714f52 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 27 Feb 2023 11:07:09 +0800 Subject: [PATCH 059/438] =?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/api/v1/issues/journals/update_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 72270f63e..0fd7b3760 100644 --- a/app/services/api/v1/issues/journals/create_service.rb +++ b/app/services/api/v1/issues/journals/create_service.rb @@ -67,7 +67,7 @@ class Api::V1::Issues::Journals::CreateService < ApplicationService def build_atme_participants @atme_receivers.each do |receiver| - @created_issue.issue_participants.new({participant_type: "atme", participant_id: receiver.id}) + @issue.issue_participants.new({participant_type: "atme", participant_id: receiver.id}) end end end \ No newline at end of file diff --git a/app/services/api/v1/issues/journals/update_service.rb b/app/services/api/v1/issues/journals/update_service.rb index 4c301bc41..3ac35b519 100644 --- a/app/services/api/v1/issues/journals/update_service.rb +++ b/app/services/api/v1/issues/journals/update_service.rb @@ -48,7 +48,7 @@ class Api::V1::Issues::Journals::UpdateService < ApplicationService def build_atme_participants @atme_receivers.each do |receiver| - @created_issue.issue_participants.new({participant_type: "atme", participant_id: receiver.id}) + @issue.issue_participants.new({participant_type: "atme", participant_id: receiver.id}) end end From ff025e07dd89747e5610a2f0612140b54815b829 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 27 Feb 2023 11:25:37 +0800 Subject: [PATCH 060/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E9=87=8C?= =?UTF-8?q?=E7=A8=8B=E7=A2=91=E5=88=97=E8=A1=A8=E6=94=AF=E6=8C=81id?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/issues/milestones_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/v1/issues/milestones_controller.rb b/app/controllers/api/v1/issues/milestones_controller.rb index 2ccd2ab90..003a464dc 100644 --- a/app/controllers/api/v1/issues/milestones_controller.rb +++ b/app/controllers/api/v1/issues/milestones_controller.rb @@ -7,7 +7,7 @@ class Api::V1::Issues::MilestonesController < Api::V1::BaseController # 里程碑列表 def index @milestones = @project.versions - @milestones = @milestones.ransack(name_or_description_cont: params[:keyword]).result if params[:keyword].present? + @milestones = @milestones.ransack(id_eq: params[:keyword]).result.or(@milestones.ransack(name_or_description_cont: params[:keyword]).result) if params[:keyword].present? @closed_milestone_count = @milestones.closed.size @opening_milestone_count = @milestones.opening.size @milestones = params[:category] == "closed" ? @milestones.closed : @milestones.opening From f05cf0c000a181447b27c46724c8ba0454ba5530 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 27 Feb 2023 14:12:25 +0800 Subject: [PATCH 061/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/journal.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/journal.rb b/app/models/journal.rb index 6472d559d..57f53c125 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -45,7 +45,7 @@ class Journal < ApplicationRecord has_many :journal_details, :dependent => :delete_all has_many :attachments, as: :container, dependent: :destroy has_many :first_ten_children_journals, -> { order(created_on: :asc).limit(10)}, class_name: 'Journal', foreign_key: :parent_id - has_many :children_journals, class_name: 'Journal', foreign_key: :parent_id + has_many :children_journals, class_name: 'Journal', foreign_key: :parent_id, dependent: :destroy scope :journal_includes, ->{includes(:user, :journal_details, :attachments)} scope :parent_journals, ->{where(parent_id: nil)} From ddb5010e6ddc250f5c4342829d47a71c5fde55b8 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 27 Feb 2023 15:04:18 +0800 Subject: [PATCH 062/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Aissue=20?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E9=9C=80=E6=8E=92=E9=99=A4pr=E4=B8=8Bissue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/issues/journals_controller.rb | 2 +- app/controllers/api/v1/issues_controller.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/issues/journals_controller.rb b/app/controllers/api/v1/issues/journals_controller.rb index 12406ef49..f7a24ea05 100644 --- a/app/controllers/api/v1/issues/journals_controller.rb +++ b/app/controllers/api/v1/issues/journals_controller.rb @@ -42,7 +42,7 @@ class Api::V1::Issues::JournalsController < Api::V1::BaseController end def load_issue - @issue = @project.issues.where(project_issues_index: params[:index]).where.not(id: params[:index]).take || Issue.find_by_id(params[:index]) + @issue = @project.issues.issue_issue.where(project_issues_index: params[:index]).where.not(id: params[:index]).take || Issue.find_by_id(params[:index]) if @issue.blank? render_not_found("疑修不存在!") end diff --git a/app/controllers/api/v1/issues_controller.rb b/app/controllers/api/v1/issues_controller.rb index 1f155c5ea..84f4dd722 100644 --- a/app/controllers/api/v1/issues_controller.rb +++ b/app/controllers/api/v1/issues_controller.rb @@ -60,7 +60,7 @@ class Api::V1::IssuesController < Api::V1::BaseController private def load_issue - @issue = @project.issues.where(project_issues_index: params[:index]).where.not(id: params[:index]).take || Issue.find_by_id(params[:index]) + @issue = @project.issues.issue_issue.where(project_issues_index: params[:index]).where.not(id: params[:index]).take || Issue.find_by_id(params[:index]) if @issue.blank? render_not_found("疑修不存在!") end From acaa28cd028c79dc7aed8c7ed71a825a2c5be390 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 27 Feb 2023 15:13:35 +0800 Subject: [PATCH 063/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Alast=20index?= =?UTF-8?q?=20=E8=8E=B7=E5=8F=96=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/project.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 4361118e4..55c3ba86c 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -426,7 +426,7 @@ class Project < ApplicationRecord end def get_last_project_issues_index - last_issue = self.issues.last + last_issue = self.issues.issue_issue.last deleted_issue_count = ($redis_cache.hget("issue_cache_delete_count", self.id) || 0).to_i last_issue&.project_issues_index.present? ? last_issue.project_issues_index + deleted_issue_count : 0 From ed7f5a08bb0d0a30ae19d2feefac57e4b6e857f8 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 27 Feb 2023 15:17:10 +0800 Subject: [PATCH 064/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Arake?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/upgrade_issue_generate_data.rake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tasks/upgrade_issue_generate_data.rake b/lib/tasks/upgrade_issue_generate_data.rake index 34a266f25..07382a1e9 100644 --- a/lib/tasks/upgrade_issue_generate_data.rake +++ b/lib/tasks/upgrade_issue_generate_data.rake @@ -8,9 +8,9 @@ namespace :upgrade_issue_generate_data do task project_issues_index: :environment do puts "____________fix start________________" - Issue.update_all(project_issues_index: nil) + Issue.issue_issue.update_all(project_issues_index: nil) count = 0 - Issue.where(project_issues_index: nil).group(:project_id).count.each do |pid, count| + Issue.issue_issue.where(project_issues_index: nil).group(:project_id).count.each do |pid, count| p = Project.find_by_id(pid) issues = p.issues.order(created_on: :asc) issues.find_each.with_index do |issue, index| From f8350c4043893ef410c89d047ceba1a66103df7a Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 27 Feb 2023 16:02:08 +0800 Subject: [PATCH 065/438] =?UTF-8?q?=E7=BE=A4=E6=99=BA=E7=86=B5=E5=88=86?= =?UTF-8?q?=E6=9E=90=E6=8A=A5=E8=A1=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/projects_helper.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index b4c21e044..877aca463 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -66,6 +66,9 @@ module ProjectsHelper jianmu_devops: jianmu_devops_code(project, user), jianmu_devops_url: jianmu_devops_url, cloud_ide_saas_url: cloud_ide_saas_url(user), + ai_shang_v1_url: ai_shang_url(project,"v1"), + ai_shang_v2_url: ai_shang_url(project,"v2"), + ai_shang_v3_url: ai_shang_v3_url(project,"v3"), ignore_id: project.ignore_id }).compact @@ -138,6 +141,34 @@ module ProjectsHelper "#{saas_url}/oauth/login?product_account_id=PA1001218&tenant_code=TI1001383&oauth_url=#{oauth_url}&token=#{token.value}" end + def ai_shang_url(project, version) + url = EduSetting.get("ai_shang_url") || "https://shang.gitlink.org.cn" + case project.identifier.to_s.downcase + when nil then "" + when 'rails' then "#{url}/#{version}/rails/entropy" + when 'jittor' then "#{url}/#{version}/jittor/entropy" + when 'paddle' then "#{url}/#{version}/Paddle/entropy" + when 'vue' then "#{url}/#{version}/vue/entropy" + when 'bootstrap' then "#{url}/#{version}/bootstrap/entropy" + when 'tensorflow' then "#{url}/#{version}/tensorflow/entropy" + else '' + end + end + + def ai_shang_v3_url(project, version) + url = EduSetting.get("ai_shang_v3_url") || "https://entropy.ingress.isa.buaanlsde.cn" + case project.identifier.to_s.downcase + when nil then "" + when 'rails' then "#{url}/rails/entropy" + when 'jittor' then "#{url}/jittor/entropy" + when 'paddle' then "#{url}/Paddle/entropy" + when 'vue' then "#{url}/vue/entropy" + when 'bootstrap' then "#{url}/bootstrap/entropy" + when 'tensorflow' then "#{url}/tensorflow/entropy" + else '' + end + end + def aes_encrypt(key, des_text) # des_text='{"access_key_id":"STS.NTuC9RVmWfJqj3JkcMzPnDf7X","access_key_secret":"E8NxRZWGNxxMfwgt5nFLnBFgg6AzgXCZkSNCyqygLuHM","end_point":"oss-accelerate.aliyuncs.com","security_token":"CAIS8gF1q6Ft5B2yfSjIr5fACIPmu7J20YiaaBX7j2MYdt9Cq6Ocujz2IHhMenVhA+8Wv/02n2hR7PcYlq9IS55VWEqc/VXLaywQo22beIPkl5Gfz95t0e+IewW6Dxr8w7WhAYHQR8/cffGAck3NkjQJr5LxaTSlWS7OU/TL8+kFCO4aRQ6ldzFLKc5LLw950q8gOGDWKOymP2yB4AOSLjIx6lAt2T8vs/7hmZPFukSFtjCglL9J/baWC4O/csxhMK14V9qIx+FsfsLDqnUIs0YWpf0p3P0doGyf54vMWUM05A6dduPS7txkLAJwerjVl1/ADxc0/hqAASXhPeiktbmDjwvnSn4iKcSGQ+xoQB468eHXNdvf13dUlbbE1+JhRi0pZIB2UCtN9oTsLHcwIHt+EJaoMd3+hGwPVmvHSXzECDFHylZ8l/pzTwlE/aCtZyVmI5cZEvmWu2xBa3GRbULo7lLvyeX1cHTVmVWf4Nk6D09PzTU8qlAj","bucket":"edu-bigfiles1","region":"oss-cn-hangzhou","callback_url":"https://data.educoder.net/api/buckets/callback.json","bucket_host":"data.educoder.net"}' # des = OpenSSL::Cipher::Cipher.new('aes-256-ctr') From 46da5a0d84f96d8d23628cdb2ebabbd372744d8d Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 27 Feb 2023 16:41:40 +0800 Subject: [PATCH 066/438] =?UTF-8?q?=E7=BE=A4=E6=99=BA=E7=86=B5=E5=88=86?= =?UTF-8?q?=E6=9E=90=E6=8A=A5=E8=A1=A8=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/projects_helper.rb | 36 +++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 877aca463..738463f22 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -66,9 +66,9 @@ module ProjectsHelper jianmu_devops: jianmu_devops_code(project, user), jianmu_devops_url: jianmu_devops_url, cloud_ide_saas_url: cloud_ide_saas_url(user), - ai_shang_v1_url: ai_shang_url(project,"v1"), - ai_shang_v2_url: ai_shang_url(project,"v2"), - ai_shang_v3_url: ai_shang_v3_url(project,"v3"), + ai_shang_v1_url: ai_shang_v1_url(project), + ai_shang_v2_url: ai_shang_v2_url(project), + ai_shang_v3_url: ai_shang_v3_url(project), ignore_id: project.ignore_id }).compact @@ -141,21 +141,35 @@ module ProjectsHelper "#{saas_url}/oauth/login?product_account_id=PA1001218&tenant_code=TI1001383&oauth_url=#{oauth_url}&token=#{token.value}" end - def ai_shang_url(project, version) + def ai_shang_v1_url(project) url = EduSetting.get("ai_shang_url") || "https://shang.gitlink.org.cn" case project.identifier.to_s.downcase when nil then "" - when 'rails' then "#{url}/#{version}/rails/entropy" - when 'jittor' then "#{url}/#{version}/jittor/entropy" - when 'paddle' then "#{url}/#{version}/Paddle/entropy" - when 'vue' then "#{url}/#{version}/vue/entropy" - when 'bootstrap' then "#{url}/#{version}/bootstrap/entropy" - when 'tensorflow' then "#{url}/#{version}/tensorflow/entropy" + when 'rails' then "#{url}/v1/rails/entropy" + when 'jittor' then "#{url}/v1/jittor/entropy" + when 'paddle' then "#{url}/v1/Paddle/entropy" + when 'vue' then "#{url}/v1/vue/entropy" + when 'bootstrap' then "#{url}/v1/bootstrap/entropy" + when 'tensorflow' then "#{url}/v1/tensorflow/entropy" else '' end end - def ai_shang_v3_url(project, version) + def ai_shang_v2_url(project) + url = EduSetting.get("ai_shang_url") || "https://shang.gitlink.org.cn" + case project.identifier.to_s.downcase + when nil then "" + when 'rails' then "#{url}/v2/getMediumData?repo_login=rails&repo_name=rails" + when 'jittor' then "#{url}/v2/getMediumData?repo_login=Jittor&repo_name=jittor" + when 'paddle' then "#{url}/v2/getMediumData?repo_login=PaddlePaddle&repo_name=Paddle" + when 'vue' then "#{url}/v2/getMediumData?repo_login=vuejs&repo_name=vue" + when 'bootstrap' then "#{url}/v2/getMediumData?repo_login=twbs&repo_name=bootstrap" + when 'tensorflow' then "#{url}/v2/getMediumData?repo_login=tensorflow&repo_name=tensorflow" + else '' + end + end + + def ai_shang_v3_url(project) url = EduSetting.get("ai_shang_v3_url") || "https://entropy.ingress.isa.buaanlsde.cn" case project.identifier.to_s.downcase when nil then "" From 558d720203ebd87b2d61a6def820a7d1f62248b4 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 28 Feb 2023 09:26:45 +0800 Subject: [PATCH 067/438] =?UTF-8?q?=E7=BE=A4=E6=99=BA=E7=86=B5=E5=88=86?= =?UTF-8?q?=E6=9E=90=E6=8A=A5=E8=A1=A8=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E5=88=B0=E9=A1=B9=E7=9B=AE=E5=8A=A8=E6=80=81=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/code_stats_controller.rb | 2 +- app/helpers/projects_helper.rb | 3 --- app/views/api/v1/projects/code_stats/index.json.jbuilder | 7 +++++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/v1/projects/code_stats_controller.rb b/app/controllers/api/v1/projects/code_stats_controller.rb index 7ec671f3c..0f2b2dd36 100644 --- a/app/controllers/api/v1/projects/code_stats_controller.rb +++ b/app/controllers/api/v1/projects/code_stats_controller.rb @@ -3,6 +3,6 @@ class Api::V1::Projects::CodeStatsController < Api::V1::BaseController def index @result_object = Api::V1::Projects::CodeStats::ListService.call(@project, {ref: params[:ref]}, current_user&.gitea_token) - puts @result_object + # puts @result_object end end \ No newline at end of file diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 738463f22..2728b7546 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -66,9 +66,6 @@ module ProjectsHelper jianmu_devops: jianmu_devops_code(project, user), jianmu_devops_url: jianmu_devops_url, cloud_ide_saas_url: cloud_ide_saas_url(user), - ai_shang_v1_url: ai_shang_v1_url(project), - ai_shang_v2_url: ai_shang_v2_url(project), - ai_shang_v3_url: ai_shang_v3_url(project), ignore_id: project.ignore_id }).compact diff --git a/app/views/api/v1/projects/code_stats/index.json.jbuilder b/app/views/api/v1/projects/code_stats/index.json.jbuilder index 0b64270f7..c41fbc1ba 100644 --- a/app/views/api/v1/projects/code_stats/index.json.jbuilder +++ b/app/views/api/v1/projects/code_stats/index.json.jbuilder @@ -4,11 +4,14 @@ json.change_files @result_object["change_files"] json.additions @result_object["additions"] json.deletions @result_object["deletions"] json.commit_count_in_all_branches @result_object["commit_count_in_all_branches"] -json.authors @result_object["authors"].each do |author| +json.authors @result_object["authors"].each do |author| json.author do json.partial! 'api/v1/users/commit_user_email', locals: { user: render_cache_commit_author(author), name: author['name'], email: author['email'] } end json.commits author["commits"] json.additions author["additions"] json.deletions author["deletions"] -end \ No newline at end of file +end +json.ai_shang_v1_url ai_shang_v1_url(@project) +json.ai_shang_v2_url ai_shang_v2_url(@project) +json.ai_shang_v3_url ai_shang_v3_url(@project) \ No newline at end of file From 5a7aaff11292702a557c0dd17b11ebe722247330 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 28 Feb 2023 09:37:18 +0800 Subject: [PATCH 068/438] =?UTF-8?q?=E7=BE=A4=E6=99=BA=E7=86=B5=E5=88=86?= =?UTF-8?q?=E6=9E=90=E6=8A=A5=E8=A1=A8=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E5=88=B0=E9=A1=B9=E7=9B=AE=E5=8A=A8=E6=80=81=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/api/v1/projects/code_stats/index.json.jbuilder | 5 +---- app/views/project_trends/index.json.jbuilder | 3 +++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/api/v1/projects/code_stats/index.json.jbuilder b/app/views/api/v1/projects/code_stats/index.json.jbuilder index c41fbc1ba..3f98fa1ee 100644 --- a/app/views/api/v1/projects/code_stats/index.json.jbuilder +++ b/app/views/api/v1/projects/code_stats/index.json.jbuilder @@ -11,7 +11,4 @@ json.authors @result_object["authors"].each do |author| json.commits author["commits"] json.additions author["additions"] json.deletions author["deletions"] -end -json.ai_shang_v1_url ai_shang_v1_url(@project) -json.ai_shang_v2_url ai_shang_v2_url(@project) -json.ai_shang_v3_url ai_shang_v3_url(@project) \ No newline at end of file +end \ No newline at end of file diff --git a/app/views/project_trends/index.json.jbuilder b/app/views/project_trends/index.json.jbuilder index 6dca7bdb5..14f975236 100644 --- a/app/views/project_trends/index.json.jbuilder +++ b/app/views/project_trends/index.json.jbuilder @@ -14,4 +14,7 @@ json.project_trends do json.partial! "detail", trend: trend end end +json.ai_shang_v1_url ai_shang_v1_url(@project) +json.ai_shang_v2_url ai_shang_v2_url(@project) +json.ai_shang_v3_url ai_shang_v3_url(@project) From 4091872091d8b56c4f9ee993f2786a3a50dac212 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 28 Feb 2023 14:40:27 +0800 Subject: [PATCH 069/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=A0=87=E8=AE=B0=E4=BB=BB=E5=8A=A1=E8=89=B2=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/issue_tag.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/issue_tag.rb b/app/models/issue_tag.rb index 100373e80..c6b6af8aa 100644 --- a/app/models/issue_tag.rb +++ b/app/models/issue_tag.rb @@ -34,7 +34,7 @@ class IssueTag < ApplicationRecord ["功能", "表示新功能申请", "#ee955a"], ["疑问", "表示存在的问题", "#2d6ddc"], ["支持", "表示特定功能或特定需求", "#019549"], - ["任务", "表示需要分配的任务", "#01a30d"], + ["任务", "表示需要分配的任务", "#c1a30d"], ["协助", "表示需要社区用户协助", "#2a0dc1"], ["搁置", "表示此问题暂时不会继续处理", "#892794"], ["文档", "表示文档材料补充", "#9ed600"], From 6f9d902e70058678642188215c8dee7a26528043 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 28 Feb 2023 14:59:06 +0800 Subject: [PATCH 070/438] =?UTF-8?q?=E7=BE=A4=E6=99=BA=E7=86=B5=E5=88=86?= =?UTF-8?q?=E6=9E=90=E6=8A=A5=E8=A1=A8=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E5=88=B0=E9=A1=B9=E7=9B=AE=E5=8A=A8=E6=80=81=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/projects_helper.rb | 14 ++++++++++++++ app/views/project_trends/index.json.jbuilder | 1 + 2 files changed, 15 insertions(+) diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 2728b7546..99cf0e01a 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -166,6 +166,20 @@ module ProjectsHelper end end + def ai_shang_v4_url(project) + url = EduSetting.get("ai_shang_url") || "https://shang.gitlink.org.cn" + case project.identifier.to_s.downcase + when nil then "" + when 'rails' then "#{url}/v2/getIndexData?repo_login=rails&repo_name=rails" + when 'jittor' then "#{url}/v2/getIndexData?repo_login=Jittor&repo_name=jittor" + when 'paddle' then "#{url}/v2/getIndexData?repo_login=PaddlePaddle&repo_name=Paddle" + when 'vue' then "#{url}/v2/getIndexData?repo_login=vuejs&repo_name=vue" + when 'bootstrap' then "#{url}/v2/getIndexData?repo_login=twbs&repo_name=bootstrap" + when 'tensorflow' then "#{url}/v2/getIndexData?repo_login=tensorflow&repo_name=tensorflow" + else '' + end + end + def ai_shang_v3_url(project) url = EduSetting.get("ai_shang_v3_url") || "https://entropy.ingress.isa.buaanlsde.cn" case project.identifier.to_s.downcase diff --git a/app/views/project_trends/index.json.jbuilder b/app/views/project_trends/index.json.jbuilder index 14f975236..abfd651ef 100644 --- a/app/views/project_trends/index.json.jbuilder +++ b/app/views/project_trends/index.json.jbuilder @@ -17,4 +17,5 @@ end json.ai_shang_v1_url ai_shang_v1_url(@project) json.ai_shang_v2_url ai_shang_v2_url(@project) json.ai_shang_v3_url ai_shang_v3_url(@project) +json.ai_shang_v4_url ai_shang_v4_url(@project) From 2842df87c6f5ff0fa12ab21056c13e9eb19f6c08 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 28 Feb 2023 15:01:23 +0800 Subject: [PATCH 071/438] =?UTF-8?q?=E7=BE=A4=E6=99=BA=E7=86=B5=E5=88=86?= =?UTF-8?q?=E6=9E=90=E6=8A=A5=E8=A1=A8=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E5=88=B0=E9=A1=B9=E7=9B=AE=E5=8A=A8=E6=80=81=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/projects_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 99cf0e01a..5ed680ba3 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -186,7 +186,7 @@ module ProjectsHelper when nil then "" when 'rails' then "#{url}/rails/entropy" when 'jittor' then "#{url}/jittor/entropy" - when 'paddle' then "#{url}/Paddle/entropy" + when 'paddle' then "#{url}/paddle/entropy" when 'vue' then "#{url}/vue/entropy" when 'bootstrap' then "#{url}/bootstrap/entropy" when 'tensorflow' then "#{url}/tensorflow/entropy" From a80b4d954ee4f4bd3a8441fbac838a29d440b812 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 28 Feb 2023 16:03:33 +0800 Subject: [PATCH 072/438] =?UTF-8?q?dockerfile=E5=8F=AF=E9=A2=84=E8=A7=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/repositories/_simple_entry.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/repositories/_simple_entry.json.jbuilder b/app/views/repositories/_simple_entry.json.jbuilder index aae0e613c..339214cc4 100644 --- a/app/views/repositories/_simple_entry.json.jbuilder +++ b/app/views/repositories/_simple_entry.json.jbuilder @@ -2,7 +2,7 @@ if @project.forge? is_dir = @sub_entries.is_a?(Array) file_name = entry['name'] file_type = file_name.starts_with?('.') ? file_name[1..-1] : File.extname(file_name.to_s)[1..-1] - direct_download = file_name.to_s.downcase != "Makefile".downcase && download_type(file_type) + direct_download = ["makefile","dockerfile"].exclude?(file_name.to_s.downcase) && download_type(file_type) image_type = image_type?(file_type) json.name file_name json.sha entry['sha'] From ec44376e4d99fe01d9c6de41431b38673065e0ba Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 28 Feb 2023 16:57:44 +0800 Subject: [PATCH 073/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Aissue=20?= =?UTF-8?q?=E8=AF=84=E8=AE=BA=E4=B8=AD@=E6=97=A0=E5=8F=82=E4=B8=8E?= =?UTF-8?q?=E8=AE=B0=E5=BD=95?= 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/journals/create_service.rb | 5 +++-- app/services/api/v1/issues/journals/update_service.rb | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index ec4aeac0b..a7ddf7e77 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 project.del_project_issue_cache_delete_count # 把缓存里存储项目删除issue的个数清除掉 # @信息发送 - AtmeService.call(current_user, @atme_receivers, @issue) unless receivers_login.blank? + AtmeService.call(current_user, @atme_receivers, @created_issue) unless receivers_login.blank? # 发消息 if Site.has_notice_menu? diff --git a/app/services/api/v1/issues/journals/create_service.rb b/app/services/api/v1/issues/journals/create_service.rb index 0fd7b3760..82a279d45 100644 --- a/app/services/api/v1/issues/journals/create_service.rb +++ b/app/services/api/v1/issues/journals/create_service.rb @@ -4,7 +4,7 @@ class Api::V1::Issues::Journals::CreateService < ApplicationService include Api::V1::Issues::Concerns::Loadable attr_reader :issue, :current_user, :notes, :parent_id, :reply_id, :attachment_ids, :receivers_login - attr_accessor :created_journal + attr_accessor :created_journal, :atme_receivers validates :notes, :issue, :current_user, presence: true @@ -39,7 +39,7 @@ class Api::V1::Issues::Journals::CreateService < ApplicationService @created_journal.save! # @信息发送 - AtmeService.call(current_user, @atme_receivers, @issue) unless receivers_login.blank? + AtmeService.call(current_user, @atme_receivers, @created_journal) unless receivers_login.blank? unlock("Api::V1::Issues::Journals::CreateService:#{@issue.id}") @@ -67,6 +67,7 @@ class Api::V1::Issues::Journals::CreateService < ApplicationService def build_atme_participants @atme_receivers.each do |receiver| + next if @issue.issue_participants.exists?(participant_type: "atme", participant_id: receiver.id) @issue.issue_participants.new({participant_type: "atme", participant_id: receiver.id}) end end diff --git a/app/services/api/v1/issues/journals/update_service.rb b/app/services/api/v1/issues/journals/update_service.rb index 3ac35b519..70c6fe4d5 100644 --- a/app/services/api/v1/issues/journals/update_service.rb +++ b/app/services/api/v1/issues/journals/update_service.rb @@ -4,7 +4,7 @@ class Api::V1::Issues::Journals::UpdateService < ApplicationService include Api::V1::Issues::Concerns::Loadable attr_reader :issue, :journal, :current_user, :notes, :attachment_ids, :receivers_login - attr_accessor :updated_journal + attr_accessor :updated_journal, :atme_receivers validates :notes, :issue, :journal, :current_user, presence: true @@ -36,7 +36,7 @@ class Api::V1::Issues::Journals::UpdateService < ApplicationService @updated_journal.save! # @信息发送 - AtmeService.call(current_user, @atme_receivers, @issue) unless receivers_login.blank? + AtmeService.call(current_user, @atme_receivers, @created_journal) unless receivers_login.blank? unlock("Api::V1::Issues::Journals::UpdateService:#{@issue.id}:#{@journal.id}") @@ -48,6 +48,7 @@ class Api::V1::Issues::Journals::UpdateService < ApplicationService def build_atme_participants @atme_receivers.each do |receiver| + next if @issue.issue_participants.exists?(participant_type: "atme", participant_id: receiver.id) @issue.issue_participants.new({participant_type: "atme", participant_id: receiver.id}) end end From e59e4e4bd5432d6dd57008690b86af6648b93fde Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 28 Feb 2023 17:05:38 +0800 Subject: [PATCH 074/438] =?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 | 9 +++++---- app/services/api/v1/issues/journals/update_service.rb | 11 ++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/services/api/v1/issues/journals/create_service.rb b/app/services/api/v1/issues/journals/create_service.rb index 82a279d45..dce00349b 100644 --- a/app/services/api/v1/issues/journals/create_service.rb +++ b/app/services/api/v1/issues/journals/create_service.rb @@ -24,10 +24,10 @@ class Api::V1::Issues::Journals::CreateService < ApplicationService ActiveRecord::Base.transaction do check_parent_journal(parent_id) if parent_id.present? check_parent_journal(reply_id) if reply_id.present? - check_attachments(attachment_ids) unless attachment_ids.blank? - check_atme_receivers(receivers_login) unless receivers_login.blank? - load_attachments(attachment_ids) unless attachment_ids.blank? - load_atme_receivers(receivers_login) unless receivers_login.blank? + check_attachments(attachment_ids) unless attachment_ids.nil? + check_atme_receivers(receivers_login) unless receivers_login.nil? + load_attachments(attachment_ids) unless attachment_ids.nil? + load_atme_receivers(receivers_login) unless receivers_login.nil? try_lock("Api::V1::Issues::Journals::CreateService:#{@issue.id}") @created_journal = @issue.journals.new(journal_attributes) @@ -37,6 +37,7 @@ class Api::V1::Issues::Journals::CreateService < ApplicationService @created_journal.attachments = @attachments unless attachment_ids.blank? @created_journal.save! + @issue.save! # @信息发送 AtmeService.call(current_user, @atme_receivers, @created_journal) unless receivers_login.blank? diff --git a/app/services/api/v1/issues/journals/update_service.rb b/app/services/api/v1/issues/journals/update_service.rb index 70c6fe4d5..e5031aafe 100644 --- a/app/services/api/v1/issues/journals/update_service.rb +++ b/app/services/api/v1/issues/journals/update_service.rb @@ -20,10 +20,10 @@ class Api::V1::Issues::Journals::UpdateService < ApplicationService def call raise Error, errors.full_messages.join(", ") unless valid? ActiveRecord::Base.transaction do - check_attachments(attachment_ids) unless attachment_ids.blank? - check_atme_receivers(receivers_login) unless receivers_login.blank? - load_attachments(attachment_ids) unless attachment_ids.blank? - load_atme_receivers(receivers_login) unless receivers_login.blank? + check_attachments(attachment_ids) unless attachment_ids.nil? + check_atme_receivers(receivers_login) unless receivers_login.nil? + load_attachments(attachment_ids) unless attachment_ids.nil? + load_atme_receivers(receivers_login) unless receivers_login.nil? try_lock("Api::V1::Issues::Journals::UpdateService:#{@issue.id}:#{@journal.id}") @updated_journal = @journal @@ -31,9 +31,10 @@ class Api::V1::Issues::Journals::UpdateService < ApplicationService build_atme_participants if @atme_receivers.present? - @updated_journal.attachments = @attachments unless attachment_ids.blank? + @updated_journal.attachments = @attachments unless attachment_ids.nil? @updated_journal.save! + @issue.save! # @信息发送 AtmeService.call(current_user, @atme_receivers, @created_journal) unless receivers_login.blank? From b8724c02f7d1abe00e45057fb1cf373c53ae7089 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 1 Mar 2023 14:40:11 +0800 Subject: [PATCH 075/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E7=BB=84?= =?UTF-8?q?=E7=BB=87=E6=9D=83=E9=99=90=E5=85=B3=E4=BA=8E=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E6=9D=83=E9=99=90=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/concerns/project_operable.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/project_operable.rb b/app/models/concerns/project_operable.rb index 10b03cf72..0bac02ce6 100644 --- a/app/models/concerns/project_operable.rb +++ b/app/models/concerns/project_operable.rb @@ -194,7 +194,7 @@ module ProjectOperable if owner.is_a?(User) managers.exists?(user_id: user.id) elsif owner.is_a?(Organization) - managers.exists?(user_id: user.id) || owner.is_owner?(user.id) || owner.is_only_admin?(user.id) + managers.exists?(user_id: user.id) || owner.is_owner?(user.id) || (owner.is_only_admin?(user.id) && (teams.pluck(:id) & user.teams.pluck(:id)).size > 0) else false end @@ -205,7 +205,7 @@ module ProjectOperable if owner.is_a?(User) developers.exists?(user_id: user.id) elsif owner.is_a?(Organization) - developers.exists?(user_id: user.id) || owner.is_only_write?(user.id) + developers.exists?(user_id: user.id) || (owner.is_only_write?(user.id) && (teams.pluck(:id) & user.teams.pluck(:id)).size > 0) else false end From 5216e61479838911520a2e4c07b641f7ad61c1a5 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 1 Mar 2023 16:34:27 +0800 Subject: [PATCH 076/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E6=93=8D=E4=BD=9C=E6=97=A5=E5=BF=97=E4=B8=AD=E6=A0=87?= =?UTF-8?q?=E8=AE=B0=E7=9A=84=E8=89=B2=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/journal.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/journal.rb b/app/models/journal.rb index 57f53c125..a789f28cd 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -73,8 +73,8 @@ class Journal < ApplicationRecord content += "将附件由#{old_value}更改为#{new_value}" end when 'issue_tag' - old_value = IssueTag.where(id: detail.old_value.split(",")).pluck(:name, :color).map{|t| "#{t[0]}"}.join(" ") - new_value = IssueTag.where(id: detail.value.split(",")).pluck(:name, :color).map{|t| "#{t[0]}"}.join(" ") + old_value = IssueTag.where(id: detail.old_value.split(",")).pluck(:name).join("、") + new_value = IssueTag.where(id: detail.value.split(",")).pluck(:name).join("、") if old_value.nil? || old_value.blank? content += "添加了#{new_value}标记" else From b1c10d66f9cfb0e057bd8f517048c8f9a2784a4e Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 2 Mar 2023 13:49:50 +0800 Subject: [PATCH 077/438] =?UTF-8?q?=E5=8C=BA=E5=9D=97=E9=93=BE=E7=A1=AE?= =?UTF-8?q?=E6=9D=83=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 319 +++++++++++++++ app/controllers/issues_controller.rb | 13 +- app/controllers/journals_controller.rb | 7 +- app/controllers/projects_controller.rb | 3 +- app/controllers/pull_requests_controller.rb | 53 ++- app/controllers/users_controller.rb | 383 +++++++++++++++++- app/forms/base_form.rb | 8 + app/forms/projects/create_form.rb | 5 +- app/helpers/tag_chosen_helper.rb | 3 +- app/models/concerns/watchable.rb | 205 ++++++++-- app/queries/application_query.rb | 49 +++ app/queries/blockchain/balance_query.rb | 31 ++ .../blockchain/balance_query_one_project.rb | 12 + app/queries/blockchain/repo_basic_info.rb | 13 + app/queries/projects/list_my_query.rb | 6 + app/services/application_service.rb | 144 +++++-- app/services/blockchain/create_issue.rb | 28 ++ app/services/blockchain/create_trade.rb | 29 ++ app/services/blockchain/fix_issue.rb | 28 ++ .../blockchain/invoke_blockchain_api.rb | 34 ++ app/services/blockchain/transfer_service.rb | 36 ++ app/services/projects/create_service.rb | 14 +- config/configuration.yml.example | 3 + config/routes.rb | 15 + ...30070048_add_use_blockchain_to_projects.rb | 5 + ...81736_add_blockchain_token_num_to_issue.rb | 5 + 26 files changed, 1354 insertions(+), 97 deletions(-) create mode 100644 app/queries/blockchain/balance_query.rb create mode 100644 app/queries/blockchain/balance_query_one_project.rb create mode 100644 app/queries/blockchain/repo_basic_info.rb create mode 100644 app/services/blockchain/create_issue.rb create mode 100644 app/services/blockchain/create_trade.rb create mode 100644 app/services/blockchain/fix_issue.rb create mode 100644 app/services/blockchain/invoke_blockchain_api.rb create mode 100644 app/services/blockchain/transfer_service.rb create mode 100644 db/migrate/20201230070048_add_use_blockchain_to_projects.rb create mode 100644 db/migrate/20210421081736_add_blockchain_token_num_to_issue.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 8129df8f1..f98c3c456 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -832,6 +832,325 @@ class ApplicationController < ActionController::Base HotSearchKeyword.add(keyword) end + # author: zxh + # blockchain相关项目活动调用函数 + # return true: 表示上链操作成功; return false: 表示上链操作失败 + 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 find_atme_receivers @atme_receivers = User.where(login: params[:receivers_login]) end diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 67fe65641..dfc551e3c 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -151,6 +151,7 @@ class IssuesController < ApplicationController end @issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create") + @issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE) if params[:status_id].to_i == 5 @@ -159,6 +160,15 @@ 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 + + # 调用上链API存证 + push_activity_2_blockchain("issue_create", @issue) + render json: {status: 0, message: "创建成功", id: @issue.id} else normal_status(-1, "创建失败") @@ -546,7 +556,8 @@ class IssuesController < ApplicationController branch_name: params[:branch_name].to_s, issue_classify: "issue", author_id: current_user.id, - project_id: @project.id + project_id: @project.id, + blockchain_token_num: params[:blockchain_token_num] } end diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rb index 6dc1e29c9..ff5e28cc1 100644 --- a/app/controllers/journals_controller.rb +++ b/app/controllers/journals_controller.rb @@ -47,10 +47,15 @@ class JournalsController < ApplicationController Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}" AtmeService.call(current_user, @atme_receivers, journal) if @atme_receivers.size > 0 # @issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "journal") + + # author: zxh + # 调用上链API + push_activity_2_blockchain("issue_comment_create", journal) + render :json => { status: 0, message: "评论成功", id: journal.id} - # normal_status(0, "评论成功") else normal_status(-1, "评论失败") + raise ActiveRecord::Rollback end end end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 52c776477..053c89e02 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -273,7 +273,8 @@ class ProjectsController < ApplicationController private def project_params params.permit(:user_id, :name, :description, :repository_name, :website, :lesson_url, :default_branch, :identifier, - :project_category_id, :project_language_id, :license_id, :ignore_id, :private) + :project_category_id, :project_language_id, :license_id, :ignore_id, :private, + :blockchain, :blockchain_token_all, :blockchain_init_token) end def mirror_params diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 2b9bbbe6f..5a6742037 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -6,6 +6,7 @@ class PullRequestsController < ApplicationController before_action :find_pull_request, except: [:index, :new, :create, :check_can_merge,:get_branches,:create_merge_infos, :files, :commits] before_action :load_pull_request, only: [:files, :commits] before_action :find_atme_receivers, only: [:create, :update] + include TagChosenHelper include ApplicationHelper @@ -73,6 +74,11 @@ class PullRequestsController < ApplicationController SendTemplateMessageJob.perform_later('ProjectPullRequest', current_user.id, @pull_request&.id) if Site.has_notice_menu? Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}" AtmeService.call(current_user, @atme_receivers, @pull_request) if @atme_receivers.size > 0 + + # author: zxh + # 调用上链API + push_activity_2_blockchain("pull_request_create", @pull_request) + else render_error("create pull request error: #{@gitea_pull_request[:status]}") raise ActiveRecord::Rollback @@ -119,7 +125,7 @@ class PullRequestsController < ApplicationController end else return normal_status(-1, "请输入正确的标记。") - end + end end if params[:status_id].to_i == 5 @issue.issue_times.update_all(end_time: Time.now) @@ -149,12 +155,16 @@ class PullRequestsController < ApplicationController ActiveRecord::Base.transaction do begin colsed = PullRequests::CloseService.call(@owner, @repository, @pull_request, current_user) - if colsed === true + # author: zxh + # 调用上链API + push_activity_2_blockchain("pull_request_refuse", @pull_request) + + if colsed === true @pull_request.project_trends.create!(user: current_user, project: @project,action_type: ProjectTrend::CLOSE) # 合并请求下issue处理为关闭 @issue&.update_attributes!({status_id:5}) SendTemplateMessageJob.perform_later('PullRequestClosed', current_user.id, @pull_request.id) if Site.has_notice_menu? - normal_status(1, "已拒绝") + normal_status(1, "已拒绝") else normal_status(-1, '合并失败') end @@ -198,6 +208,43 @@ class PullRequestsController < ApplicationController # @pull_request.project_trend_status! @pull_request.project_trends.create!(user: current_user, project: @project,action_type: ProjectTrend::MERGE) @issue&.custom_journal_detail("merge", "", "该合并请求已被合并", current_user&.id) + + # author: zxh + # 调用上链API + 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 + end + end + # 合并请求下issue处理为关闭 @issue&.update_attributes!({status_id:5}) SendTemplateMessageJob.perform_later('PullRequestMerged', current_user.id, @pull_request.id) if Site.has_notice_menu? diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 33fd93f83..6aee4b584 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -2,8 +2,8 @@ class UsersController < ApplicationController include ApplicationHelper include Ci::DbConnectable - before_action :load_user, only: [:show, :homepage_info, :sync_token, :sync_gitea_pwd, :projects, :watch_users, :fan_users, :hovercard] - before_action :check_user_exist, only: [:show, :homepage_info,:projects, :watch_users, :fan_users, :hovercard] + before_action :load_user, only: [:show, :homepage_info, :sync_token, :sync_gitea_pwd, :projects, :watch_users, :fan_users, :hovercard, :hovercard4proj] + before_action :check_user_exist, only: [:show, :homepage_info,:projects, :watch_users, :fan_users, :hovercard, :hovercard4proj] before_action :require_login, only: %i[me sync_user_info] before_action :connect_to_ci_db, only: [:get_user_info] before_action :convert_image!, only: [:update, :update_image] @@ -81,9 +81,134 @@ class UsersController < ApplicationController @watchers = paginate(watchers) end + def contribution_perc + project_id = params[:project_id] + @project = Project.find(project_id) + user_id = params[:id] + @user = User.find(user_id) + + def cal_perc(count_user, count_all) + (count_user * 1.0 / (count_all + 0.000000001)).round(5) + end + + if @project['use_blockchain'] == true or @project['use_blockchain'] == 1 + balance_user = Blockchain::BalanceQueryOneProject.call({"user_id": user_id, "project_id": project_id}) + balance_all = Blockchain::RepoBasicInfo.call({"project_id": project_id})["cur_supply"] + scores = { + "final" => cal_perc(balance_user, balance_all), + "blockchain" => true + } + else + # 获取所有行为对应的项目内记录总数和个人记录数 + features = { + "requirement" => {}, + "development" => {}, + "review" => {} + } + + # 1. issue创建 + issues = Issue.where(project_id: project_id, issue_classify: 'issue') + issue_all = issues.count + issue_user = issues.where(author_id: user_id).count + features["requirement"] = features["requirement"].merge({"issue" => {"all" => issue_all, "perc" => cal_perc(issue_user, issue_all)}}) + # 2. 里程碑创建 + milestones = Version.where(project_id: project_id) + milestone_all = milestones.count + milestone_user = milestones.where(user_id: user_id).count + features["requirement"] = features["requirement"].merge({"milestone" => {"all" => milestone_all, "perc" => cal_perc(milestone_user, milestone_all)}}) + # 3. issue评论 + issue_comments = Journal.joins("INNER JOIN issues on journals.journalized_id=issues.id").where("issues.project_id=#{project_id} and journalized_type='Issue' and issues.issue_classify='issue'") + issue_comment_all = issue_comments.count + issue_comment_user = issue_comments.where("journals.user_id=#{user_id}").count + features["requirement"] = features["requirement"].merge({"issue_comment" => {"all" => issue_comment_all, "perc" => cal_perc(issue_comment_user, issue_comment_all)}}) + # 4. 合并请求 + prs = PullRequest.where(project_id: project_id) + pr_all = prs.count + pr_user = prs.where(user_id: user_id).count + features["development"] = features["development"].merge({"pr" => {"all" => pr_all, "perc" => cal_perc(pr_user, pr_all)}}) + # 5. pr评论 + pr_comments = Journal.joins("INNER JOIN issues on journals.journalized_id=issues.id").where("issues.project_id=#{project_id} and journalized_type='Issue' and issues.issue_classify='pull_request'") + pr_comment_all = pr_comments.count + pr_comment_user = pr_comments.where("journals.user_id=#{user_id}").count + features["review"] = features["review"].merge({"pr_comment" => {"all" => pr_comment_all, "perc" => cal_perc(pr_comment_user, pr_comment_all)}}) + # 6. 代码行评论 + line_comments = Journal.joins("INNER JOIN pull_requests on journals.journalized_id=pull_requests.id").where("pull_requests.project_id=#{project_id} and journalized_type='PullRequest'") + line_comment_all = line_comments.count + line_comment_user = line_comments.where("journals.user_id=#{user_id}").count + features["review"] = features["review"].merge({"line_comment" => {"all" => line_comment_all, "perc" => cal_perc(line_comment_user, line_comment_all)}}) + # 7. 代码行、commit贡献统计 + code_contributions = Api::V1::Projects::CodeStats::ListService.call(@project, {ref: nil}) + commit_all = code_contributions["commit_count"] + addition_all = code_contributions["additions"] + deletion_all = code_contributions["deletions"] + + commit_user = 0 + addition_user = 0 + deletion_user = 0 + code_contributions["authors"].each do |author| + if author["name"] == @user.login + commit_user = author["commits"] + addition_user = author["additions"] + deletion_user = author["deletions"] + end + end + + features["development"] = features["development"].merge({"commit" => {"all" => commit_all, "perc" => cal_perc(commit_user, commit_all)}}) + features["development"] = features["development"].merge({"addition" => {"all" => addition_all, "perc" => cal_perc(addition_user, addition_all)}}) + features["development"] = features["development"].merge({"deletion" => {"all" => deletion_all, "perc" => cal_perc(deletion_user, deletion_all)}}) + + def cal_weight(features) + weights = {} # 计算每一项的权重 + categories = [] + features.each do |key, _| + categories << key + weights[key] = Hash.new + end + count_all = 0 + counts = {} + categories.each do |category| + count_1 = 0 + features[category].each do |_, value| + count_1 += value["all"] + end + count_all += count_1 + counts[category] = count_1 + features[category].each do |key, value| + weight = cal_perc(value["all"], count_1) + weights[category] = weights[category].merge({key => weight}) + end + end + categories.each do |category| + weight = cal_perc(counts[category], count_all) + weights[category] = weights[category].merge({"category_weight" => weight}) + end + return weights + end + + weights_categories = cal_weight(features) + scores = { + "final" => 0.0, + "blockchain" => false + } + features.each do |category, value_1| + category_score = 0.0 + value_1.each do |action, value_2| + category_score += weights_categories[category][action] * value_2["perc"] + end + scores["final"] += weights_categories[category]["category_weight"] * category_score.round(4) + scores = scores.merge({category => category_score.round(4)}) + end + end + render json: { scores: scores } + end + def hovercard end + # author: zxh, 查询贡献者的贡献度 + def hovercard4proj + end + def update return render_not_found unless @user = User.find_by(login: params[:id]) || User.find_by_id(params[:id]) return render_forbidden unless User.current.logged? && (current_user&.admin? || current_user.id == @user.id) @@ -94,11 +219,11 @@ class UsersController < ApplicationController end end - def update_image - return render_not_found unless @user = User.find_by(login: params[:id]) || User.find_by_id(params[:id]) + def update_image + return render_not_found unless @user = User.find_by(login: params[:id]) || User.find_by_id(params[:id]) return render_forbidden unless User.current.logged? && (current_user&.admin? || current_user.id == @user.id) - Util.write_file(@image, avatar_path(@user)) + Util.write_file(@image, avatar_path(@user)) return render_ok({message: '头像修改成功'}) rescue Exception => e uid_logger_error(e.message) @@ -284,6 +409,252 @@ class UsersController < ApplicationController @projects = paginate(scope) end + + # query all projects with tokens by a user + def blockchain_balance + #is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == params['user_id'].to_i) + is_current_admin_user = true + results = Blockchain::BalanceQuery.call(params, is_current_admin_user) + if results[:status] == 0 + @total_count = results[:projects].size + @projects = results[:projects] + else + @total_count = -1 + @projects = [] + end + + render json: { status: results[:status], projects: @projects, total_count: @total_count } + end + + # query one balance + def blockchain_balance_one_project + #is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == params['user_id'].to_i) + is_current_admin_user = true + if is_current_admin_user + owner = User.find_by(login: params['owner_login']) + if owner.nil? + normal_status(-1, "创建者无法找到") + else + p = Project.find_by(user_id: owner.id, identifier: params['project_identifier']) + balance = Blockchain::BalanceQueryOneProject.call({"user_id": params['user_id'].to_i, "project_id": p.id.to_i}) + render json: { status: 0, balance: balance} + end + else + normal_status(-1, "缺少权限") + end + + end + + + def blockchain_transfer + #is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == params['payer_id'].to_i) + is_current_admin_user = true + + if is_current_admin_user + Blockchain::TransferService.call(params) + render json: {status: 2} # 重新查询余额 + else + normal_status(-1, "缺少权限") + end + rescue Exception => e + normal_status(-1, e.to_s) + end + + # exchange money + def blockchain_exchange + #is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == params['user_id'].to_i) + #require 'alipay' + ## setup the client to communicate with either production API or sandbox API + ## https://openapi.alipay.com/gateway.do (Production) + ## https://openapi.alipaydev.com/gateway.do (Sandbox) + #api_url = 'https://openapi.alipay.com/gateway.do' + # + ## setup your own credentials and certificates + #app_id = '2021002140631434' + #app_private_key="-----BEGIN RSA PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCPDsgc0n0RWRnbe9OMqtUbde8gu88OyjuZm8cJXeiSING18HX56C5zV4DsHQ6K9/JmQi/NYCc7/2Prh66Bei0L4Xm5TysJTPYi90+WlbJJESFF6fqULi8sSqZXUtaoMKRcUyeR144l2GQgXbZWBbVSQeZW5DqUDlurTF0I7vQ21wGqxQqBjQK8PSVw5hF+aIsNOfAY9M1tzdD5Jzo2Y3FJdsbXIJNMyhJJCZ+7KHFqma7lpjkXdCoyh/nOISkQdGtFI29gI94sqewI2AMU84uxuBIE3h90iLT+8xrd2dQKdBS7qfhQ3PgkBPVNs5jxsVBqSFdSFT6zcqFdHJzulCUJAgMBAAECggEAWocAGz0X5+J6emnhdSKluLrol85BORrAnHP3f/XtNouOKZQBFCPZQSQecUvx5/7/ZbZ8iXpPWahDkshJpaWq29nTLXDryvboyze1JZWVPKeaZqOp7htLvrt+h8PkEoq1d7cnUyMU0N4eflzPBaCXHXaWTGYgq5Bqcfvg48ZSxGBYeHt5WWU2+GW5fpsaVBBYkdyxxGMoy/bzYzGhvfSJkexqnl0XkAAODa02mu3WsHrzRid6Mf+3syYbq/MfUodU6Vng2tbCqwnWrHCyrD4RYl6rg1TKuAv2YAfBhLzwBxHYVC4SRqzjs+8AaOQoF+lCjr4JklPhEuRThzD31YwIAQKBgQDAg4S7ciMmxvbNxR+1eimoAYLLF9jPpPU6w3VFNPb4rDu4tX77bNf082YplfJX5TYtZKjKPKyYG87K6slGunyPL4AFRW81WPB9u1uP26dihyPCBSUE01jKRPPfRrQnnru5fpm8LL3L03V3yA6J+GyQ8wltRJJi1eBSSm+IWRsZewKBgQC+PBD9J1LYOEIVeK9KvN8BpkA1ZIkk//VuJaoGfVXn+1EzM1yFB05fnsEQkHFynisvuCIr7pH63HcdyffQhe1YOnw9iDCG1zPjsi5uTe9WAM0dnb7xdsaLPr/Q2LyoDOTN9344Qovy1AAnpWtGTn6omgHst5nZpp/mHOuBlKiqSwKBgBKRXM77fjpyPEGyfpFxW+0xYB0YirfUUDa/vWLUbfGkIwp4ruuvHtEoXLUsGjiyCdys9b6zxW3SWMqnhIxG1la1HSLlBInfryphVL52UBmnsSI4fs6NV+YCaocheaTMoYyNkmRc6F1tYsoPyJ80D7yXRFR+paPUvxMQzNsYxQ1bAoGAHd2uSSBQWFPUxCwzUQd/93FTaU6EXYO103okTGqG/ymsoN4ya0wvWMHCy8fxl64PV6mP69fDoV/Vb57SwjEUhyJ/eOWVwMWuhtPliDnCFn1/tmOao6wjFZ9fW/l6/OMxVMjDTy/bat8vuwm0YtBWAEBVhwV4KPyI5AasTqa5KCsCgYB/usnqhVx2zt+MxpBt2Q9Vxc0zXcZxMDs69UUdTY86gjcJyCFGe3bbumUcyfSJzIznC2hfFX5ZyS0oMwiAzWtslRMh9LRh3kofD/6BogL3RKOlBk3iekvQ8Gn0tbwk2Qzr4WJgfA7A4GTf5r7Y+bvOfazzsUQAfSK6nUTIlOj2Ew==\n-----END RSA PRIVATE KEY-----\n" + #alipay_public_key="-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgHXLD1BshMymbqqtZVKNyo95FNfxzXzaw3P1eI0KeO6RaL+JzrWxzIBFfTjkWv/8WM9u/NcXMOFt2QO9q5KIDx6PkqjRDTd1hgP/cTgdjOHQqnVSihCrQDVCDBSOXIujC8Lk/P4pFVRhQkYeZqEb1qb8b/2tzTY8g9PKKBSCQv7SfgL2TBcpAVbb+9xdJ6VainC/wYGk8T+c+st1hXnuBJSS0m7LFxJOsYkNk0wbA0tfdZLrO3us2F7sjC9t4h/05nr+gSuDkzo+1kCEefYLqScexN+vnQiLoylp/C82wNiP6okxfhmHz3EcYfUqUyGTN/oFaFcPFPpUtFNS8jFV9QIDAQAB\n-----END PUBLIC KEY-----\n" + # + ## initialize a client to communicate with the Alipay API + #@alipay_client = Alipay::Client.new( + # url: api_url, + # app_id: app_id, + # app_private_key: app_private_key, + # alipay_public_key: alipay_public_key + #) + # + #return_result = @alipay_client.page_execute_url( + # method: 'alipay.trade.page.pay', + # biz_content: JSON.generate({ + # out_trade_no: '20210420104600', + # product_code: 'FAST_INSTANT_TRADE_PAY', + # total_amount: '0.01', + # subject: 'test' + # }, ascii_only: true), # ascii_only is important! + # timestamp: '2021-04-20 10:46:00' + #) + #render json: { pay_url: return_result } + # + + # 替代解决方案 + # 读取所有交易信息 + end + # # + # # def blockchain_create_trade + # # #is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == params['user_id'].to_i) + # # is_current_admin_user = true + # # if is_current_admin_user + # # user_id = params['user_id'].to_i + # # project_id = params['project_id'].to_i + # # money = params['money'].to_f + # # #description = params['description'] + # # token_num = params['token_num'].to_i + # # # 锁仓 + # # result = Blockchain::CreateTrade.call({user_id: user_id, project_id: project_id, token_num: token_num}) + # # if result == false + # # normal_status(-1, "创建交易失败") + # # else + # # bt = BlockchainTrade.new(user_id: user_id, project_id: project_id, token_num: token_num, money: money, state: 0) # state=0表示创建交易; state=1表示执行中; state=2表示执行完成 + # # bt.save() + # # status = 2 # 交易创建成功 + # # render json: { status: status } + # # end + # # else + # # normal_status(-1, "缺少权限") + # # end + # # end + # # + # # + # # def blockchain_get_trades + # # trades = BlockchainTrade.where(state: 0).all() + # # results = [] + # # trades.each do |t| + # # project_id = t.project_id + # # project = Project.find_by(id: project_id) + # # if !project.nil? + # # owner = User.find_by(id: project.user_id) + # # else + # # owner = nil + # # end + # # user_id = t.user_id + # # creator = User.find_by(id: user_id) + # # if project.nil? || owner.nil? || creator.nil? + # # else + # # results << [creator, owner, project, t] + # # end + # # end + # # render json: { results: results } + # # end + # # + # # def blockchain_trade + # # #is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == params['user_id'].to_i) + # # is_current_admin_user = true + # # if is_current_admin_user + # # user_id2 = params['user_id2'].to_i + # # trade_id = params['trade_id'].to_i + # # BlockchainTrade.find(trade_id).update(user_id2: user_id2, state: 1) # state=1表示锁定了,等待线下卖家发货 + # # render json: {status: 2} # window.location.reload() + # # else + # # normal_status(-1, "缺少权限") + # # end + # # end + # + # + # def blockchain_verify_trade + # #is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == params['user_id'].to_i) + # is_current_admin_user = true + # if is_current_admin_user + # trade_id = params['trade_id'].to_i + # BlockchainTrade.find(trade_id).update(state: 2) # state=2表示确认收货 + # render json: {status: 2} # window.location.reload() + # else + # normal_status(-1, "缺少权限") + # end + # end + # + # def blockchain_get_verify_trades + # #is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == params['user_id'].to_i) + # is_current_admin_user = true + # if is_current_admin_user + # trades = BlockchainTrade.where(state: 1).all() + # results = [] + # trades.each do |t| + # project_id = t.project_id + # project = Project.find_by(id: project_id) + # if !project.nil? + # owner = User.find_by(id: project.user_id) + # else + # owner = nil + # end + # user_id = t.user_id + # creator = User.find_by(id: user_id) + # user_id2 = t.user_id2 + # buyer = User.find_by(id: user_id2) + # if project.nil? || owner.nil? || creator.nil? || buyer.nil? + # else + # results << [creator, owner, project, t, buyer] + # end + # end + # render json: { results: results } + # else + # normal_status(-1, "缺少权限") + # end + # end + # + # def blockchain_get_history_trades + # #is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == params['user_id'].to_i) + # is_current_admin_user = true + # if is_current_admin_user + # trades = BlockchainTrade.where(state: 2).all() + # results = [] + # trades.each do |t| + # project_id = t.project_id + # project = Project.find_by(id: project_id) + # if !project.nil? + # owner = User.find_by(id: project.user_id) + # else + # owner = nil + # end + # user_id = t.user_id + # creator = User.find_by(id: user_id) + # user_id2 = t.user_id2 + # buyer = User.find_by(id: user_id2) + # if project.nil? || owner.nil? || creator.nil? || buyer.nil? + # else + # results << [creator, owner, project, t, buyer] + # end + # end + # render json: { results: results } + # else + # normal_status(-1, "缺少权限") + # end + # end + + + def blockchain_get_issue_token_num + issue_id = params["issue_id"]['orderId'].to_i + issue = Issue.find_by(id: issue_id) + project = Project.find(issue.project_id) + if project[:use_blockchain] + render json: {"blockchain_token_num": issue.blockchain_token_num} + else + render json: {"blockchain_token_num": -1} # 未使用blockchain + end + end + + + def blockchain_get_unclosed_issue_list + ownername = params["ownername"] + identifier = params["reponame"] + owner = User.find_by(login: ownername) + project = Project.find_by(user_id: owner.id, identifier: identifier) + unclosed_issues = Issue.where(project_id: project.id, issue_classify: "issue").where.not(status_id: 5) + results = [] + unclosed_issues.each do |i| + results << [i.id, i.subject] + end + render json: {unclosed_issues: results} + end + # TODO 其他平台登录时同步修改gitea平台对应用户的密码 # 该方法主要用于:别的平台初次部署对接forge平台,同步用户后,gitea平台对应的用户密码与forge平台用户密码不一致是问题 def sync_gitea_pwd @@ -322,7 +693,7 @@ class UsersController < ApplicationController end end - def email_search + def email_search return render_error('请输入email') if params[:email].blank? @user = User.find_by(mail: params[:email]) end diff --git a/app/forms/base_form.rb b/app/forms/base_form.rb index ca82fa4bb..db745e8d8 100644 --- a/app/forms/base_form.rb +++ b/app/forms/base_form.rb @@ -30,6 +30,14 @@ class BaseForm raise "项目名称已被使用." if Project.where(user_id: user_id, name: project_name.strip).exists? end + def check_blockchain_token_all(blockchain_token_all) + raise "请正确填写项目token总数." if (Float(blockchain_token_all) rescue false) == false or blockchain_token_all.to_i < 0 or Float(blockchain_token_all) != blockchain_token_all.to_i + 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 + end + def check_reversed_keyword(repository_name) raise "项目标识已被占用." if ReversedKeyword.check_exists?(repository_name) end diff --git a/app/forms/projects/create_form.rb b/app/forms/projects/create_form.rb index c51c2c60f..c9fcb44e6 100644 --- a/app/forms/projects/create_form.rb +++ b/app/forms/projects/create_form.rb @@ -1,6 +1,7 @@ class Projects::CreateForm < BaseForm attr_accessor :user_id, :name, :description, :repository_name, :project_category_id, - :project_language_id, :ignore_id, :license_id, :private, :owner + :project_language_id, :ignore_id, :license_id, :private, :owner, + :blockchain, :blockchain_token_all, :blockchain_init_token validates :user_id, :name, :repository_name, presence: true validates :repository_name, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" } @@ -15,6 +16,8 @@ class Projects::CreateForm < BaseForm check_project_language(project_language_id) check_project_name(user_id, name) unless name.blank? check_repository_name(user_id, repository_name) unless repository_name.blank? + check_blockchain_token_all(blockchain_token_all) unless blockchain_token_all.blank? + check_blockchain_init_token(blockchain_init_token) unless blockchain_init_token.blank? end def check_license diff --git a/app/helpers/tag_chosen_helper.rb b/app/helpers/tag_chosen_helper.rb index 520b868fa..784efcf29 100644 --- a/app/helpers/tag_chosen_helper.rb +++ b/app/helpers/tag_chosen_helper.rb @@ -21,7 +21,8 @@ module TagChosenHelper "issue_tag": render_issue_tags(project), "issue_type": render_issue_species, "all_issues": all_issues, - "branches": render_branches(project) + "branches": render_branches(project), + "use_blockchain": project['use_blockchain'] } end diff --git a/app/models/concerns/watchable.rb b/app/models/concerns/watchable.rb index 008d382f3..9eb0172d7 100644 --- a/app/models/concerns/watchable.rb +++ b/app/models/concerns/watchable.rb @@ -1,45 +1,160 @@ -module Watchable - extend ActiveSupport::Concern - - included do - has_many :watchers, as: :watchable, dependent: :destroy - has_many :watcher_users, through: :watchers, source: :user, validate: false - - scope :watched_by, -> (user_id) { includes(:watchers).where(watchers: { user_id: user_id }) } - scope :following, -> (user_id) { watched_by(user_id) } - end - - def watched?(watchable) - watchable.watchers.exists?(user: self) - end - - def watch!(watchable) - watchable.watchers.create!(user: self, created_at: Time.current) - end - - def unwatch!(watchable) - obj = watchable.watchers.find_by(user: self) - obj.destroy! if obj.present? - end - - # 我正在关注的、我追随的 - def following - User.following(self.id) - end - - def following_count - following.size - end - - # 关注我的、我的粉丝、我的追随者 - def followers - watcher_users - end - - def followers_count - followers.size - end - - module ClassMethods - end -end +module Watchable + extend ActiveSupport::Concern + + included do + has_many :watchers, as: :watchable, dependent: :destroy + has_many :watcher_users, through: :watchers, source: :user, validate: false + + scope :watched_by, -> (user_id) { includes(:watchers).where(watchers: { user_id: user_id }) } + scope :following, -> (user_id) { watched_by(user_id) } + end + + def watched?(watchable) + watchable.watchers.exists?(user: self) + end + + def watch!(watchable) + watchable.watchers.create!(user: self, created_at: Time.current) + end + + def unwatch!(watchable) + obj = watchable.watchers.find_by(user: self) + obj.destroy! if obj.present? + end + + # 我正在关注的、我追随的 + def following + User.following(self.id) + end + + def following_count + 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 cal_perc(count_user, count_all) + (count_user * 1.0 / (count_all + 0.000000001)).round(5) + end + + if @project['use_blockchain'] == true or @project['use_blockchain'] == 1 + balance_user = Blockchain::BalanceQueryOneProject.call({"user_id": @user.id, "project_id": @project.id}) + balance_all = Blockchain::RepoBasicInfo.call({"project_id": @project.id})["cur_supply"] + score = cal_perc(balance_user, balance_all) + else + # 获取所有行为对应的项目内记录总数和个人记录数 + features = { + "requirement" => {}, + "development" => {}, + "review" => {} + } + + # 1. issue创建 + issues = Issue.where(project_id: @project.id, issue_classify: 'issue') + issue_all = issues.count + issue_user = issues.where(author_id: @user.id).count + features["requirement"] = features["requirement"].merge({"issue" => {"all" => issue_all, "perc" => cal_perc(issue_user, issue_all)}}) + # 2. 里程碑创建 + milestones = Version.where(project_id: @project.id) + milestone_all = milestones.count + milestone_user = milestones.where(user_id: @user.id).count + features["requirement"] = features["requirement"].merge({"milestone" => {"all" => milestone_all, "perc" => cal_perc(milestone_user, milestone_all)}}) + # 3. issue评论 + issue_comments = Journal.joins("INNER JOIN issues on journals.journalized_id=issues.id").where("issues.project_id=#{@project.id} and journalized_type='Issue' and issues.issue_classify='issue'") + issue_comment_all = issue_comments.count + issue_comment_user = issue_comments.where("journals.user_id=#{@user.id}").count + features["requirement"] = features["requirement"].merge({"issue_comment" => {"all" => issue_comment_all, "perc" => cal_perc(issue_comment_user, issue_comment_all)}}) + # 4. 合并请求 + prs = PullRequest.where(project_id: @project.id) + pr_all = prs.count + pr_user = prs.where(user_id: @user.id).count + features["development"] = features["development"].merge({"pr" => {"all" => pr_all, "perc" => cal_perc(pr_user, pr_all)}}) + # 5. pr评论 + pr_comments = Journal.joins("INNER JOIN issues on journals.journalized_id=issues.id").where("issues.project_id=#{@project.id} and journalized_type='Issue' and issues.issue_classify='pull_request'") + pr_comment_all = pr_comments.count + pr_comment_user = pr_comments.where("journals.user_id=#{@user.id}").count + features["review"] = features["review"].merge({"pr_comment" => {"all" => pr_comment_all, "perc" => cal_perc(pr_comment_user, pr_comment_all)}}) + # 6. 代码行评论 + line_comments = Journal.joins("INNER JOIN pull_requests on journals.journalized_id=pull_requests.id").where("pull_requests.project_id=#{@project.id} and journalized_type='PullRequest'") + line_comment_all = line_comments.count + line_comment_user = line_comments.where("journals.user_id=#{@user.id}").count + features["review"] = features["review"].merge({"line_comment" => {"all" => line_comment_all, "perc" => cal_perc(line_comment_user, line_comment_all)}}) + # 7. 代码行、commit贡献统计 + code_contributions = Api::V1::Projects::CodeStats::ListService.call(@project, {ref: nil}) + commit_all = code_contributions["commit_count"] + addition_all = code_contributions["additions"] + deletion_all = code_contributions["deletions"] + + commit_user = 0 + addition_user = 0 + deletion_user = 0 + code_contributions["authors"].each do |author| + if author["name"] == @user.login + commit_user = author["commits"] + addition_user = author["additions"] + deletion_user = author["deletions"] + end + end + + features["development"] = features["development"].merge({"commit" => {"all" => commit_all, "perc" => cal_perc(commit_user, commit_all)}}) + features["development"] = features["development"].merge({"addition" => {"all" => addition_all, "perc" => cal_perc(addition_user, addition_all)}}) + features["development"] = features["development"].merge({"deletion" => {"all" => deletion_all, "perc" => cal_perc(deletion_user, deletion_all)}}) + + def cal_weight(features) + weights = {} # 计算每一项的权重 + categories = [] + features.each do |key, _| + categories << key + weights[key] = Hash.new + end + count_all = 0 + counts = {} + categories.each do |category| + count_1 = 0 + features[category].each do |_, value| + count_1 += value["all"] + end + count_all += count_1 + counts[category] = count_1 + features[category].each do |key, value| + weight = cal_perc(value["all"], count_1) + weights[category] = weights[category].merge({key => weight}) + end + end + categories.each do |category| + weight = cal_perc(counts[category], count_all) + weights[category] = weights[category].merge({"category_weight" => weight}) + end + return weights + end + + weights_categories = cal_weight(features) + score = 0.0 + features.each do |category, value_1| + category_score = 0.0 + value_1.each do |action, value_2| + category_score += weights_categories[category][action] * value_2["perc"] + end + score += weights_categories[category]["category_weight"] * category_score.round(4) + end + end + score + (score * 100).round(1).to_s + "%" + end + + # 关注我的、我的粉丝、我的追随者 + def followers + watcher_users + end + + def followers_count + followers.size + end + + module ClassMethods + end +end diff --git a/app/queries/application_query.rb b/app/queries/application_query.rb index c66af94c0..fdef1b71d 100644 --- a/app/queries/application_query.rb +++ b/app/queries/application_query.rb @@ -6,4 +6,53 @@ class ApplicationQuery def strip_param(key) params[key].to_s.strip.presence end + + # find all the repos that a user has tokens + def find_repo_with_token(user_id) + params = { + "request-type": "query user balance of all repos", + "username": user_id.to_s + }.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 + end + end + + + # find one repo that a user has tokens + def find_one_balance(user_id, project_id) + # return 3 statuses: UnknownErr/ResUserNotExisted/Success + params = { + "request-type": "query user balance of single repo", + "username": user_id.to_s, + "token_name": project_id.to_s + }.to_json + resp_body = Blockchain::InvokeBlockchainApi.call(params) + if resp_body['status'] == 0 + return resp_body['balance'] + elsif resp_body['status'] == 100 + return 0 # 找不到用户返回0 + else + raise "区块链接口请求失败." + end + end + + # query the basic info of a repository + def find_blockchain_repo_info(project_id) + params = { + "request-type": "query repo basic info", + "token_name": project_id.to_s + }.to_json + resp_body = Blockchain::InvokeBlockchainApi.call(params) + if resp_body['status'] == 0 + return resp_body + else + raise "区块链接口请求失败." + end + end + end \ No newline at end of file diff --git a/app/queries/blockchain/balance_query.rb b/app/queries/blockchain/balance_query.rb new file mode 100644 index 000000000..669370a54 --- /dev/null +++ b/app/queries/blockchain/balance_query.rb @@ -0,0 +1,31 @@ +class Blockchain::BalanceQuery < ApplicationQuery + + attr_reader :params, :is_current_admin_user + + def initialize(params,is_current_admin_user) + @params = params + @is_current_admin_user = is_current_admin_user + end + + def call + if is_current_admin_user + token_list = find_repo_with_token(params["user_id"]) + result_list = [] + token_list.each do |t| + project = Project.find_by(id: t['token_name'].to_i) + if project.nil? + next + end + owner = User.find_by(id: project.user_id) + if owner.nil? || project.nil? + else + balance = t['balance'] + result_list << [owner, project, balance] + end + end + results = {"status": 0, "projects": result_list} + else + results = {"status": 1} # query failed + end + end +end diff --git a/app/queries/blockchain/balance_query_one_project.rb b/app/queries/blockchain/balance_query_one_project.rb new file mode 100644 index 000000000..c4ec19e21 --- /dev/null +++ b/app/queries/blockchain/balance_query_one_project.rb @@ -0,0 +1,12 @@ +class Blockchain::BalanceQueryOneProject < ApplicationQuery + + attr_reader :params, :is_current_admin_user + + def initialize(params) + @params = params + end + + def call + find_one_balance(params[:user_id].to_s, params[:project_id].to_s) + end +end diff --git a/app/queries/blockchain/repo_basic_info.rb b/app/queries/blockchain/repo_basic_info.rb new file mode 100644 index 000000000..df17b7a04 --- /dev/null +++ b/app/queries/blockchain/repo_basic_info.rb @@ -0,0 +1,13 @@ +class Blockchain::RepoBasicInfo < ApplicationQuery + + attr_reader :params, :is_current_admin_user + + def initialize(params) + @params = params + end + + def call + info = find_blockchain_repo_info(params[:project_id].to_s) + return info + end +end diff --git a/app/queries/projects/list_my_query.rb b/app/queries/projects/list_my_query.rb index 6c7f38d9c..7e555b529 100644 --- a/app/queries/projects/list_my_query.rb +++ b/app/queries/projects/list_my_query.rb @@ -38,6 +38,12 @@ class Projects::ListMyQuery < ApplicationQuery # projects = projects.visible.joins(:members).where(members: { user_id: user.id }) # 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) + project_names = token_list.map { |x| x['token_name'] } + projects = projects.where(name: project_names) + tokens = token_list.map { |x| x['balance'] } + puts "pause" end if params[:is_public].present? diff --git a/app/services/application_service.rb b/app/services/application_service.rb index 9c70bbeb2..df06f3960 100644 --- a/app/services/application_service.rb +++ b/app/services/application_service.rb @@ -1,35 +1,109 @@ -class ApplicationService - include Callable - - Error = Class.new(StandardError) - - def regix_emoji content - " " if content.blank? - regex = /[^a-zA-Z0-9\u4E00-\u9FFF]/ - content.gsub(regex, '') - end - - protected - def try_lock(key) - raise Error, "请稍后再试!" unless $redis_cache.set(key, 1, nx: true, ex: 60.seconds) - end - - def unlock(key) - $redis_cache.del(key) - end - - private - - def strip(str) - str.to_s.strip.presence - end - - def str_to_boolean str - ActiveModel::Type::Boolean.new.cast str - end - - def phone_mail_type value - value =~ /^1\d{10}$/ ? 1 : 0 - end - -end +class ApplicationService + include Callable + + Error = Class.new(StandardError) + + def regix_emoji content + " " if content.blank? + regex = /[^a-zA-Z0-9\u4E00-\u9FFF]/ + content.gsub(regex, '') + end + + protected + def try_lock(key) + raise Error, "请稍后再试!" unless $redis_cache.set(key, 1, nx: true, ex: 60.seconds) + end + + def unlock(key) + $redis_cache.del(key) + end + + private + + def strip(str) + str.to_s.strip.presence + end + + def str_to_boolean str + ActiveModel::Type::Boolean.new.cast str + end + + # params: params from index.js page + def create_repo_on_blockchain(params, project) + 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]] + + params = { + "request-type": "create repo", + "username": username, + "token_name": token_name, + "total_supply": total_supply, + "token_balance": token_balance + }.to_json + resp_body = Blockchain::InvokeBlockchainApi.call(params) + if resp_body['status'] != 0 + raise "区块链接口请求失败." + end + end + + + def transfer_balance_on_blockchain(payer, payee, token_name, amount) + + params = { + "request-type": "transfer amount", + "payer": payer, + "payee": payee, + "token_name": token_name, + "amount": amount + }.to_json + resp_body = Blockchain::InvokeBlockchainApi.call(params) + if resp_body['status'] == 5 or resp_body['status'] == 106 or resp_body['status'] == 105 + raise resp_body['message'] + elsif resp_body['status'] != 0 + raise "区块链接口请求失败." + else + end + end + + + def lock_balance_on_blockchain(username, tokenname, amount) + + params = { + "request-type": "lock user balance", + "username": username, + "token_name": tokenname, + "amount": amount + }.to_json + resp_body = Blockchain::InvokeBlockchainApi.call(params) + if resp_body['status'] == 5 or resp_body['status'] == 106 or resp_body['status'] == 103 + raise resp_body['message'] + elsif resp_body['status'] != 0 + raise "区块链接口请求失败." + else + end + end + + + def unlock_balance_on_blockchain(username, tokenname, amount) + + params = { + "request-type": "unlock user balance", + "username": username, + "token_name": tokenname, + "amount": amount + }.to_json + resp_body = Blockchain::InvokeBlockchainApi.call(params) + if resp_body['status'] == 5 or resp_body['status'] == 106 or resp_body['status'] == 104 + raise resp_body['message'] + elsif resp_body['status'] != 0 + raise "区块链接口请求失败." + else + end + end + def phone_mail_type value + value =~ /^1\d{10}$/ ? 1 : 0 + end + +end diff --git a/app/services/blockchain/create_issue.rb b/app/services/blockchain/create_issue.rb new file mode 100644 index 000000000..c3ab5ad49 --- /dev/null +++ b/app/services/blockchain/create_issue.rb @@ -0,0 +1,28 @@ +class Blockchain::CreateIssue < ApplicationService + + attr_reader :params + + def initialize(params) + @params = params + end + + def call + ActiveRecord::Base.transaction do + username = @params[:user_id].to_s + token_name = @params[:project_id].to_s + amount = @params[:token_num].to_i + + # 调用token锁仓函数 + lock_balance_on_blockchain(username, token_name, amount) + end + rescue => e + puts "转账失败: #{e.message}" + raise Error, e.message + end + + private + + def no_use + puts "this function does not have any usage" + end +end \ No newline at end of file diff --git a/app/services/blockchain/create_trade.rb b/app/services/blockchain/create_trade.rb new file mode 100644 index 000000000..a4de98783 --- /dev/null +++ b/app/services/blockchain/create_trade.rb @@ -0,0 +1,29 @@ +class Blockchain::CreateTrade < ApplicationService + + attr_reader :params + + def initialize(params) + @params = params + end + + def call + ActiveRecord::Base.transaction do + username = @params[:user_id].to_s + token_name = @params[:project_id].to_s + amount = @params[:token_num].to_i + + # 调用token锁仓函数 + results = lock_balance_on_blockchain(username, token_name, amount) + return results + end + rescue => e + puts "转账失败: #{e.message}" + raise Error, e.message + end + + private + + def no_use + puts "this function does not have any usage" + end +end \ No newline at end of file diff --git a/app/services/blockchain/fix_issue.rb b/app/services/blockchain/fix_issue.rb new file mode 100644 index 000000000..332202792 --- /dev/null +++ b/app/services/blockchain/fix_issue.rb @@ -0,0 +1,28 @@ +class Blockchain::FixIssue < ApplicationService + + attr_reader :params + + def initialize(params) + @params = params + end + + def call + ActiveRecord::Base.transaction do + username = @params[:user_id].to_s + token_name = @params[:project_id].to_s + amount = @params[:token_num].to_i + + # 调用token锁仓函数 + unlock_balance_on_blockchain(username, token_name, amount) + end + rescue => e + puts "关联issue失败: #{e.message}" + raise Error, e.message + end + + private + + def no_use + puts "this function does not have any usage" + end +end \ No newline at end of file diff --git a/app/services/blockchain/invoke_blockchain_api.rb b/app/services/blockchain/invoke_blockchain_api.rb new file mode 100644 index 000000000..d485e171c --- /dev/null +++ b/app/services/blockchain/invoke_blockchain_api.rb @@ -0,0 +1,34 @@ +class Blockchain::InvokeBlockchainApi < ApplicationService + # 调用blockchain + + attr_reader :params + + def initialize(params) + @params = params + end + + def call + begin + uri = Blockchain.blockchain_config[:api_url] + uri = URI.parse(URI.encode(uri.strip)) + res = Net::HTTP.start(uri.host, uri.port) do |http| + req = Net::HTTP::Post.new(uri) + req['Content-Type'] = 'application/json' + req.body = @params + http.request(req) + end + if res.code.to_i != 200 + raise "区块链接口请求失败." + else + res_body = JSON.parse(res.body) + if res_body.has_key?("status") + else + raise "区块链接口请求失败." + end + end + return res_body + rescue Exception => e + raise "区块链接口请求失败." + end + end +end \ No newline at end of file diff --git a/app/services/blockchain/transfer_service.rb b/app/services/blockchain/transfer_service.rb new file mode 100644 index 000000000..4f7425e5d --- /dev/null +++ b/app/services/blockchain/transfer_service.rb @@ -0,0 +1,36 @@ +class Blockchain::TransferService < ApplicationService + + attr_reader :params + + def initialize(params) + @params = params + end + + def call + ActiveRecord::Base.transaction do + transfer_amount = params['transfer_amount'] + if (Float(transfer_amount) rescue false) == false or transfer_amount.to_i < 0 or Float(transfer_amount) != transfer_amount.to_i + raise Error, "请输入正确的转账金额" + end + transfer_amount = params['transfer_amount'].to_i + transfer_login = params['transfer_login'] + payer = params['payer_id'].to_s + payee = User.find_by(login: transfer_login) + if payee.nil? + raise Error, "未找到接收转账的用户" + else + payee = payee.id.to_s + token_name = params['project_id'].to_s + # 调用token转移函数 + transfer_balance_on_blockchain(payer, payee, token_name, transfer_amount) + end + end + end + + private + + def no_use + puts "this function does not have any usage" + end + +end \ No newline at end of file diff --git a/app/services/projects/create_service.rb b/app/services/projects/create_service.rb index ff36dfe52..c4f892f7f 100644 --- a/app/services/projects/create_service.rb +++ b/app/services/projects/create_service.rb @@ -18,6 +18,9 @@ class Projects::CreateService < ApplicationService ProjectUnit.init_types(@project.id) Repositories::CreateService.new(user, @project, repository_params).call upgrade_project_category_private_projects_count + if repo_use_blockchain + create_repo_on_blockchain(params, @project) + end else Rails.logger.info("#############___________create_project_erros______###########{@project.errors.messages}") end @@ -30,7 +33,7 @@ class Projects::CreateService < ApplicationService private - def upgrade_project_category_private_projects_count + def upgrade_project_category_private_projects_count # 如果为空或者项目为公有项目直接返回 return unless params[:project_category_id].present? return if repo_is_public @@ -38,7 +41,7 @@ class Projects::CreateService < ApplicationService project_category.increment!(:private_projects_count, 1) end - def authroize_user_id_success + def authroize_user_id_success (user.id == params[:user_id].to_i) || (user.organizations.find_by_id(params[:user_id]).present?) end @@ -53,7 +56,8 @@ class Projects::CreateService < ApplicationService ignore_id: params[:ignore_id], license_id: params[:license_id], website: params[:website], - identifier: params[:repository_name] + identifier: params[:repository_name], + use_blockchain: repo_use_blockchain # 新增,zxh } end @@ -72,4 +76,8 @@ class Projects::CreateService < ApplicationService def repo_is_public params[:private].blank? ? true : !(ActiveModel::Type::Boolean.new.cast(params[:private]).nil? ? false : ActiveModel::Type::Boolean.new.cast(params[:private])) end + + def repo_use_blockchain + params[:blockchain].blank? ? false : params[:blockchain] + end end diff --git a/config/configuration.yml.example b/config/configuration.yml.example index f056dee1b..6ae32e4f3 100644 --- a/config/configuration.yml.example +++ b/config/configuration.yml.example @@ -75,6 +75,9 @@ default: &default forum: domain: '' base_url: '/api' + # 区块链相关配置 + blockchain: + api_url: 'blockchain service url' production: <<: *default diff --git a/config/routes.rb b/config/routes.rb index 3488bacb4..2a837190f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -123,6 +123,20 @@ Rails.application.routes.draw do put 'commons/unhidden', to: 'commons#unhidden' delete 'commons/delete', to: 'commons#delete' + # blockchain related routes + get 'users/blockchain/balance', to: 'users#blockchain_balance' + post 'users/blockchain/balance_project', to: 'users#blockchain_balance_one_project' + post 'users/blockchain/transfer', to: 'users#blockchain_transfer' + post 'users/blockchain/exchange', to: 'users#blockchain_exchange' + post 'users/blockchain/create_trade', to: 'users#blockchain_create_trade' + get '/users/blockchain/get_trades', to: 'users#blockchain_get_trades' + post '/users/blockchain/trade', to: 'users#blockchain_trade' + get '/users/blockchain/get_verify_trades', to: 'users#blockchain_get_verify_trades' + post '/users/blockchain/verify_trade', to: 'users#blockchain_verify_trade' + get '/users/blockchain/get_history_trades', to: 'users#blockchain_get_history_trades' + post '/blockchain/issue/get_token_num', to: 'users#blockchain_get_issue_token_num' + get '/projects/blockchain/get_unclosed_issue_list', to: 'users#blockchain_get_unclosed_issue_list' + resources :owners, only: [:index, :show] scope module: :organizations do @@ -243,6 +257,7 @@ Rails.application.routes.draw do get :watch_users get :fan_users get :hovercard + get :hovercard4proj # author: zxh, 获取用户对项目的贡献情况 put :update_image get :get_image end diff --git a/db/migrate/20201230070048_add_use_blockchain_to_projects.rb b/db/migrate/20201230070048_add_use_blockchain_to_projects.rb new file mode 100644 index 000000000..f7e2fdde0 --- /dev/null +++ b/db/migrate/20201230070048_add_use_blockchain_to_projects.rb @@ -0,0 +1,5 @@ +class AddUseBlockchainToProjects < ActiveRecord::Migration[5.2] + def change + add_column :projects, :use_blockchain, :boolean, default: 0 + end +end diff --git a/db/migrate/20210421081736_add_blockchain_token_num_to_issue.rb b/db/migrate/20210421081736_add_blockchain_token_num_to_issue.rb new file mode 100644 index 000000000..1391667e5 --- /dev/null +++ b/db/migrate/20210421081736_add_blockchain_token_num_to_issue.rb @@ -0,0 +1,5 @@ +class AddBlockchainTokenNumToIssue < ActiveRecord::Migration[5.2] + def change + add_column :issues, :blockchain_token_num, :integer + end +end From 8e547c178ad246bdf13debf534cb57f1e2e64e7c Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Tue, 21 Feb 2023 17:38:09 +0800 Subject: [PATCH 078/438] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E7=BB=84=E7=BB=87?= =?UTF-8?q?=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../javascripts/admins/organizations.js | 2 + .../stylesheets/admins/organizations.scss | 3 ++ .../admins/organizations_controller.rb | 23 ++++++++ app/helpers/admins/organizations_helper.rb | 2 + app/models/organization.rb | 51 ++++++++++++++++++ .../admins/delete_organization_service.rb | 28 ++++++++++ app/views/admins/organizations/edit.html.erb | 41 ++++++++++++++ app/views/admins/organizations/index.html.erb | 8 +++ app/views/admins/organizations/index.js.erb | 1 + .../admins/organizations/index.json.jbuilder | 6 +++ .../organizations/shared/_org_list.html.erb | 45 ++++++++++++++++ .../shared/_project_list.html.erb | 53 +++++++++++++++++++ app/views/admins/organizations/show.html.erb | 38 +++++++++++++ app/views/admins/shared/_sidebar.html.erb | 5 +- config/routes.rb | 2 +- .../admins/organizations_controller_spec.rb | 5 ++ .../admins/organizations_helper_spec.rb | 15 ++++++ 17 files changed, 325 insertions(+), 3 deletions(-) create mode 100644 app/assets/javascripts/admins/organizations.js create mode 100644 app/assets/stylesheets/admins/organizations.scss create mode 100644 app/controllers/admins/organizations_controller.rb create mode 100644 app/helpers/admins/organizations_helper.rb create mode 100644 app/services/admins/delete_organization_service.rb create mode 100644 app/views/admins/organizations/edit.html.erb create mode 100644 app/views/admins/organizations/index.html.erb create mode 100644 app/views/admins/organizations/index.js.erb create mode 100644 app/views/admins/organizations/index.json.jbuilder create mode 100644 app/views/admins/organizations/shared/_org_list.html.erb create mode 100644 app/views/admins/organizations/shared/_project_list.html.erb create mode 100644 app/views/admins/organizations/show.html.erb create mode 100644 spec/controllers/admins/organizations_controller_spec.rb create mode 100644 spec/helpers/admins/organizations_helper_spec.rb diff --git a/app/assets/javascripts/admins/organizations.js b/app/assets/javascripts/admins/organizations.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/admins/organizations.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/admins/organizations.scss b/app/assets/stylesheets/admins/organizations.scss new file mode 100644 index 000000000..a3cf9ca1f --- /dev/null +++ b/app/assets/stylesheets/admins/organizations.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the admins/organizations controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/admins/organizations_controller.rb b/app/controllers/admins/organizations_controller.rb new file mode 100644 index 000000000..4e40a509e --- /dev/null +++ b/app/controllers/admins/organizations_controller.rb @@ -0,0 +1,23 @@ +class Admins::OrganizationsController < Admins::BaseController + before_action :finder_org, except: [:index] + + def index + @orgs = paginate Organization.all + end + + def show + end + + def destroy + @org.destroy! + Admins::DeleteOrganizationService.call(@org.login) + render_delete_success + end + + private + + def finder_org + @org = Organization.find(params[:id]) + end + +end diff --git a/app/helpers/admins/organizations_helper.rb b/app/helpers/admins/organizations_helper.rb new file mode 100644 index 000000000..0265ab1e4 --- /dev/null +++ b/app/helpers/admins/organizations_helper.rb @@ -0,0 +1,2 @@ +module Admins::OrganizationsHelper +end diff --git a/app/models/organization.rb b/app/models/organization.rb index adf43a2cd..17eb28918 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -144,6 +144,57 @@ class Organization < Owner end end + def projects_count + Project.where( user_id: self.id).count + end + + # 用户账号状态 + def active? + status == User::STATUS_ACTIVE + end + + def registered? + status == User::STATUS_REGISTERED + end + + def locked? + status == User::STATUS_LOCKED + end + + def need_edit_info? + status == User::STATUS_EDIT_INFO + end + + def activate + self.status = User::STATUS_ACTIVE + end + + def register + self.status = User::STATUS_REGISTERED + end + + def lock + self.status = User::STATUS_LOCKED + end + + def need_edit_info + self.status = User::STATUS_EDIT_INFO + end + + def activate! + update_attribute(:status, STATUS_ACTIVE) + prohibit_gitea_user_login!(false) + end + + def register! + update_attribute(:status, STATUS_REGISTERED) + end + + def lock! + update_attribute(:status, STATUS_LOCKED) + prohibit_gitea_user_login! + end + def real_name name = lastname + firstname name = name.blank? ? (nickname.blank? ? login : nickname) : name diff --git a/app/services/admins/delete_organization_service.rb b/app/services/admins/delete_organization_service.rb new file mode 100644 index 000000000..db842845b --- /dev/null +++ b/app/services/admins/delete_organization_service.rb @@ -0,0 +1,28 @@ +class Admins::DeleteOrganizationService < Gitea::ClientService + attr_reader :token, :name + + def initialize(name) + @name = name + end + + def call + response = delete(url, params) + render_status(response) + end + + private + def params + Hash.new.merge(token: token) + end + + def url + "/orgs/#{name}".freeze + end + + def token + { + username: GiteaService.gitea_config[:access_key_id], + password: GiteaService.gitea_config[:access_key_secret] + } + end +end diff --git a/app/views/admins/organizations/edit.html.erb b/app/views/admins/organizations/edit.html.erb new file mode 100644 index 000000000..0cc9909f0 --- /dev/null +++ b/app/views/admins/organizations/edit.html.erb @@ -0,0 +1,41 @@ +<% + define_admin_breadcrumbs do + add_admin_breadcrumb('组织管理', admins_organizations_path) + add_admin_breadcrumb('组织详情') + end +%> + +
        + + + <%= simple_form_for(@org, url: admins_organization_path(@org)) do |f| %> + +
        基本信息
        +
        +
        + <%= f.input :login, label: '登录名', wrapper_html: { class: 'col-md-3' }, input_html: { readonly: true, class: 'col-md-11', value: @org.login } %> +
        + +
        + <%= f.input :lastname, label: '姓名', wrapper_html: { class: 'col-md-3' }, input_html: { class: 'col-md-11', value: @org.real_name } %> +
        + + +
        + +
        + <%= f.button :submit, value: '保存', class: 'btn-primary mr-3 px-4' %> + <%= link_to '取消', admins_organizations_path, class: 'btn btn-secondary px-4' %> +
        + <% end %> +
        diff --git a/app/views/admins/organizations/index.html.erb b/app/views/admins/organizations/index.html.erb new file mode 100644 index 000000000..7c96b57ee --- /dev/null +++ b/app/views/admins/organizations/index.html.erb @@ -0,0 +1,8 @@ +<% define_admin_breadcrumbs do %> + <% add_admin_breadcrumb('组织管理', admins_organizations_path) %> +<% end %> + +
        + <%= render partial: 'admins/organizations/shared/org_list', locals: { organizations: @orgs } %> +
        + diff --git a/app/views/admins/organizations/index.js.erb b/app/views/admins/organizations/index.js.erb new file mode 100644 index 000000000..7e750ecf9 --- /dev/null +++ b/app/views/admins/organizations/index.js.erb @@ -0,0 +1 @@ +$('.users-list-container').html("<%= j( render partial: 'admins/organizations/shared/org_list', locals: { organizations: @orgs } ) %>"); \ No newline at end of file diff --git a/app/views/admins/organizations/index.json.jbuilder b/app/views/admins/organizations/index.json.jbuilder new file mode 100644 index 000000000..1278c3c13 --- /dev/null +++ b/app/views/admins/organizations/index.json.jbuilder @@ -0,0 +1,6 @@ +json.count @orgs.total_count +json.orgs do + json.array! @orgs.each do |org| + json.extract! org, :id, :login, :nickname + end +end \ No newline at end of file diff --git a/app/views/admins/organizations/shared/_org_list.html.erb b/app/views/admins/organizations/shared/_org_list.html.erb new file mode 100644 index 000000000..b8fac30d0 --- /dev/null +++ b/app/views/admins/organizations/shared/_org_list.html.erb @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + <% if organizations.present? %> + <% organizations.each_with_index do |org, index| %> + + + + + + + + + + <% end %> + <% else %> + <%= render 'admins/shared/no_data_for_table' %> + <% end %> + +
        序号login昵称<%= sort_tag('创建于', name: 'created_on', path: admins_organizations_path) %><%= sort_tag('最后登录', name: 'last_login_on', path: admins_organizations_path) %>项目数操作
        <%= list_index_no((params[:page] || 1).to_i, index) %> + <%= link_to "/#{org.login}", target: '_blank' do %> + <%= overflow_hidden_span org.login, width: 100 %> + <% end %> + <%= org.nickname %> <%= display_text(org.created_on&.strftime('%Y-%m-%d %H:%M')) %><%= display_text(org.last_login_on&.strftime('%Y-%m-%d %H:%M')) %><%= link_to org.projects_count, "/#{org.login}", target: "_blank" %> + <%= link_to '查看', admins_organization_path(org), class: 'action' %> +
        + <%= javascript_void_link('更多', class: 'action dropdown-toggle', 'data-toggle': 'dropdown', 'aria-haspopup': true, 'aria-expanded': false) %> + +
        +
        + +<%= render partial: 'admins/shared/paginate', locals: { objects: organizations } %> diff --git a/app/views/admins/organizations/shared/_project_list.html.erb b/app/views/admins/organizations/shared/_project_list.html.erb new file mode 100644 index 000000000..e828938ff --- /dev/null +++ b/app/views/admins/organizations/shared/_project_list.html.erb @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + <% if projects.present? %> + <% projects.each_with_index do |project, index| %> + + + + + + + + + + + + + + + + <% end %> + <% else %> + <%= render 'admins/shared/no_data_for_table' %> + <% end %> + +
        序号ID项目名称公开推荐Issues资源Pulls里程碑成员管理员<%= sort_tag('创建时间', name: 'created_on', path: admins_projects_path) %>操作
        <%= list_index_no((params[:page] || 1).to_i, index) %><%= project.id %> + <%= link_to(project.name, "/#{project&.owner&.login}/#{project.identifier}", target: '_blank') %> + <%= project.is_public ? '√' : '' %><%= project.recommend ? '√' : '' %><%= project.issues.size %><%= project.attachments.size %><%= project&.pull_requests_count %><%= project.versions.size %><%= project.members.size %> + <%= link_to_project(project) %> + <%= project.created_on&.strftime('%Y-%m-%d %H:%M') %> + <% if project.is_public %> + <%= javascript_void_link '推荐', class: 'action recommend-action', data: { id: project.id }, style: project.recommend ? 'display: none;' : '' %> + <%= javascript_void_link '取消推荐', class: 'action unrecommend-action', data: { id: project.id }, style: project.recommend ? '' : 'display: none;' %> + <%= link_to "设置推荐等级", edit_admins_project_path(project.id), remote: true, class: "action edit-recommend-action", style: project.recommend ? '' : 'display: none;' %> + <% end %> + <%= link_to "删除", admins_project_path(project.id), method: :delete, data:{confirm: "确认删除的吗?"}, class: "delete-project-action" %> +
        \ No newline at end of file diff --git a/app/views/admins/organizations/show.html.erb b/app/views/admins/organizations/show.html.erb new file mode 100644 index 000000000..b40f1c258 --- /dev/null +++ b/app/views/admins/organizations/show.html.erb @@ -0,0 +1,38 @@ +<% + define_admin_breadcrumbs do + add_admin_breadcrumb('组织管理', admins_organizations_path) + add_admin_breadcrumb('组织详情') + end +%> + +
        + + + <%= simple_form_for(@org, url: admins_organization_path(@org)) do |f| %> + +
        基本信息
        +
        +
        + <%= f.input :login, label: '登录名', wrapper_html: { class: 'col-md-3' }, input_html: { readonly: true, class: 'col-md-11', value: @org.login } %> +
        + +
        + <%= f.input :lastname, label: '姓名', wrapper_html: { class: 'col-md-3' }, input_html: { readonly: true, class: 'col-md-11', value: @org.real_name } %> +
        + + +
        + <% end %> +

        组织项目

        + <%= render partial: 'admins/organizations/shared/project_list', locals: { projects: @org.projects } %> + +
        diff --git a/app/views/admins/shared/_sidebar.html.erb b/app/views/admins/shared/_sidebar.html.erb index fb96f088e..fc2fe6068 100644 --- a/app/views/admins/shared/_sidebar.html.erb +++ b/app/views/admins/shared/_sidebar.html.erb @@ -15,14 +15,15 @@
        • <%= sidebar_item(admins_path, '概览', icon: 'dashboard', controller: 'admins-dashboards') %>
        • - <%= sidebar_item_group('#user-submenu', '排行榜', icon: 'user') do %> + <%= sidebar_item_group('#rank-submenu', '排行榜', icon: 'calendar') do %>
        • <%= sidebar_item(admins_users_rank_index_path, '用户排行榜', icon: 'user', controller: 'admins-users_rank') %>
        • -
        • <%= sidebar_item(admins_projects_rank_index_path, '项目排行榜', icon: 'user', controller: 'admins-projects_rank') %>
        • +
        • <%= sidebar_item(admins_projects_rank_index_path, '项目排行榜', icon: 'database', controller: 'admins-projects_rank') %>
        • <% end %>
        • <%= sidebar_item_group('#user-submenu', '用户', icon: 'user') do %>
        • <%= sidebar_item(admins_users_path, '用户列表', icon: 'user', controller: 'admins-users') %>
        • +
        • <%= sidebar_item(admins_organizations_path, '组织列表', icon: 'user', controller: 'admins-organizations') %>
        • <% end %>
        • diff --git a/config/routes.rb b/config/routes.rb index 3d6cc8f55..3488bacb4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -816,7 +816,7 @@ Rails.application.routes.draw do resources :school_statistics, only: [:index] do get :contrast, on: :collection end - + resources :organizations, only: [:index, :edit, :show, :destroy] resources :users, only: [:index, :edit, :update, :destroy] do member do post :reward_grade diff --git a/spec/controllers/admins/organizations_controller_spec.rb b/spec/controllers/admins/organizations_controller_spec.rb new file mode 100644 index 000000000..a0df61f17 --- /dev/null +++ b/spec/controllers/admins/organizations_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Admins::OrganizationsController, type: :controller do + +end diff --git a/spec/helpers/admins/organizations_helper_spec.rb b/spec/helpers/admins/organizations_helper_spec.rb new file mode 100644 index 000000000..2f0a719a0 --- /dev/null +++ b/spec/helpers/admins/organizations_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Admins::OrganizationsHelper. For example: +# +# describe Admins::OrganizationsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe Admins::OrganizationsHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end From e81b04bb381e1e54d0cc076ed40f2513f7a5b657 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 3 Mar 2023 10:26:53 +0800 Subject: [PATCH 079/438] =?UTF-8?q?=E6=89=B9=E9=87=8Fforked=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=B9=B6=E5=8A=A0=E5=85=A5=E6=88=90=E5=91=98=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_forked_project.rake | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lib/tasks/batch_forked_project.rake diff --git a/lib/tasks/batch_forked_project.rake b/lib/tasks/batch_forked_project.rake new file mode 100644 index 000000000..e7eb4a95c --- /dev/null +++ b/lib/tasks/batch_forked_project.rake @@ -0,0 +1,31 @@ +namespace :batch_forked_project do + desc "batch forked project" + task done: :environment do + project_id = ENV['project_id'] + puts "project_id=================#{project_id}" + next if project_id.blank? + user_logins = ['p89346015','p25371846','p69217483','p69805714','p78920563','p54261380','p18934275','p41273960','p76281309','p97134028','p89450236','p28097461','p60437152','p16925078','p13420986','p02315697','p73950468','p72348916','p65874312','p94723568','p35407816','p61830975','p48127056','p17832064','p06472319','p59827036','p49583267','p36120475','p63428509','p51029748','p98071642','p17580394','p96175348','p41672830','p68109573','p23185094','p62105398','p78052941','p39784256','p31704586','p25768904','p30916782','p97142530','p25706341','p90421386','p30547691','p12598607','p34096851','p56902314','p95014723','p57810362','p27049618','p21035879','p47560312','p45902861','p28534760','p95064217','p06819345','p24786109','p47862359','p67201548','p38275619','p02713685','p20516978','p92801564','p12894530','p38146059','p36259710','p65298073','p45926780','p65849120','p19425386','p41038257','p64871093','p49017526','p76438951','p09842165','p07546132','p74189326','p20819356','p79041358','p68315204','p23671945','p75086429','p75246983','p86719302','p57046318','p36402875','p29370514','p39284567','p84973510','p70912653','p87013296','p45801397','p75632498','p15097863','p37298104','p26813470','p80596471','p50234679','p94836501','p97481306','p03826457','p64398250','p06728315','p95802743','p10893624','p32197506','p60475139','p86321945','p26708531','p40531786','p43216578','p81793025','p65974130','p86049152','p68735142','p98625074','p08619275','p48179362','p81507936','p48719350','p79346812','p35027486','p60329715','p60539481','p76059481','p32659470','p73492805','p05214867','p83527960','p57284961','p84921730','p78614302','p58043692','p83795012','p72490365','p74031526','p19072458','p78305942','p79210548','p04273869','p20894137','p38905462','p46109723','p17250849','p79863042','p86354072','p70381452','p70852634','p01439876','p85409726','p13072985','p06975321','p42786905','p84576012','p63541897','p92760841','p83741256','p53029167','p80254167','p57062419','p52071649','p38649571','p54687012','p35487621','p90182463','p40937281','p56809147','p19543078','p69304857','p68457901','p63190852','p86140357','p57491630','p32801694','p16539028','p35182647','p81065927','p98142307','p57806943','p13286457','p61349702','p35168907','p59713608','p61397402','p42673859','p49085271','p31790624','p86451732','p31682759','p29108563','p64157932','p24086573','p50786231','p41237908','p58712463','p02635481','p63289457','p29836504','p42591076','p37620514','p58016429','p91068472','p21489537','p42068571','p09413782','p27456893','p30871956','p14983026','p09567821','p15038967','p34802159','p89234176','p97038246','p60173295','p02418537','p16423790','p71034629','p10284537','p08539174','p26359018','p32981056','p94538276','p92354178','p46271580','p46150238','p97850142','p81604759','p91084637','p04637589','p73852460','p52189704','p19084632','p14763208','p32746591','p47620913','p47068915','p02596781','p48530276','p28309164','p38564297','p14728506','p09413785','p56127938','p24085137','p60517892','p48261730','p45012768','p95741268','p97205463','p32816504','p93410257','p24736950','p07946812','p37408162','p97062183','p02763814','p37142856','p72063459','p36921540','p97583401','p95183074','p90816354','p20768431','p45763201','p07549382','p67502814','p79641052','p09471635','p56234879','p35214687','p25708641','p06452378','p05843697','p89562143','p76435829','p32574608','p24780615','p16408279','p48051237','p70695184','p01297543','p19647583','p41297630','p45163207','p08362159','p20853741','p52436710','p98243601','p97240356','p45980172','p91287634','p65903241','p16543708','p32968140','p72054981','p25904731','p42137095','p32480967','p81739025','p43590716','p04152936','p78094351','p24719605','p35078941','p26875103','p39617540','p32046579','p38614905','p37904815','p04637219','p16072398','p14509327','p64915802','p86901372','p23689415','p13627904','p07649125','p63974102','p90372815','p76839152','p70621953','p62783154','p69127034','p35762149','p46718029','p49038615','p13625784','p74835920','p71894530','p67253149','p95476182','p85632907','p64315790','p38150427','p98024156','p70684592','p39427165','p09682531','p24178095','p60927481','p56873024','p63702845','p21495036','p35468209','p37546918','p86092715','p54927031','p70428196','p16943057','p84301759','p06957132','p41075982','p78134290','p18732456','p28654079','p73518624','p56124037','p08416932','p06127935','p42178659','p25047183','p30592648','p72693851','p92453867','p56297804','p34759102','p31495620','p21053468','p72836954','p05426871','p03485972','p72408193','p65907124','p42953718','p05176823','p28635019','p15607483','p20183675','p70348295','p95602314','p18750962','p27396041','p65039842','p29861504','p12450839','p32164907','p08974362','p97310846','p57326049','p46039257','p16308954','p08927143','p96805214','p39687025','p02345978','p68704231','p65074391','p74130682','p56394728','p85971406','p34920175','p85497610','p98413562','p90841576','p52987460','p58426091','p70493586','p97831640','p65309184','p90462513','p37104865','p40217938','p80975236','p39142076','p14278930','p54731860','p50761948','p69431802','p20479615','p93710546','p17329085','p05327968','p62384590','p83964120','p82013564','p05248176','p91756083','p98314765','p91740526','p41870593','p82617439','p35621840','p94752683','p82149057','p65792034','p89762031','p20835149','p93681520','p47356108','p14578620','p90174356','p62917034','p16289450','p92061735','p51296307','p63854721','p28630741','p68347910','p81405976','p53904721','p21306457','p15937680','p43086715','p04731582','p01549628','p36590127','p81236547','p04372865','p17698354','p69548273','p75834209','p43905172','p51839024','p14027953','p59167832','p98301572','p97610358','p98235607','p84107325','p62073841','p57103248','p38061974','p63527048','p25417803','p29758346','p50461937','p45901728','p79032614','p90138467','p07652843','p57390261','p20654879','p94120685','p49328706','p91542867','p79038562','p46217093','p64350789','p07846235','p82730541','p79216034','p82403975','p85013724','p61359482','p29741638','p87961534','p63850471','p96701452','p87956143','p82501346','p15830476','p34296517','p54603217','p25386701','p59486271','p76250183','p50681423','p92356710','p72013695','p25174896','p87319624','p97583024','p95467102','p80627345','p29015467','p57318920','p13852069','p15490287','p05796328','p83027541','p76189403','p26193804','p34502967','p70368514','p43627890','p07961235','p68197045','p79368205','p25189364','p47560938','p04163285','p59834107','p52017496','p28539176','p76103582','p67214983','p25809413','p01684375','p54367192','p81940257','p31928657','p89572041','p10297384','p53291604','p47201568','p76409812','p63701854','p67135490','p04139825','p01472693','p97521430','p12346870','p08319675','p98250137','p02743168','p19427063','p72894315','p79358120','p70529146','p48130625','p92576038','p21796540','p59417328','p23701854','p61270835','p52913407','p21408795','p89253407','p68590432','p14056283','p83290617','p03754268','p65291703','p71835460','p63028519','p45397861','p96803572','p03741962','p85194607','p84652793','p76534189','p87346592','p51609348','p51728903','p20735491','p53249801','p90821357','p90271845','p36174902','p82345971','p39658240','p29037645','p19523084','p24735089','p23790645','p25780419','p72836401','p51473608','p89253710','p92435681','p71695423','p06298514','p84765192','p80973145','p76234901','p29041386','p48253917','p79326504','p67854932','p70846953','p49137086','p59132670','p45180932','p46208597','p75498316','p01928463','p72189630','p97081625','p74982531','p36217950','p70496351','p49085612','p45872916','p74368291','p67502819','p60493127','p91874265','p18407625','p09315486','p71306428','p68924531','p56934812','p92864103','p46891705','p48965017','p93284710','p62975041','p85013926','p13845267','p41367089','p86952047','p46715938','p84209513','p13695478','p27139648','p03549281','p96124038','p30816759','p98027543','p35809714','p02364951','p86129435','p14357092','p13604872','p46971853','p93105248','p56173408','p07419258','p05896741','p40859721','p57138092','p62083541','p37421598','p45739201','p81453902','p30679528','p51923746','p74081592','p87260935','p25603419','p82419076','p28561793','p71624835','p20685197','p95032418','p12305678','p01382794','p79416325','p71852639','p15297340','p80253914','p27985106','p62387095','p09615784','p69810735','p92046185','p04691538','p29561438','p96748523','p26349178','p53140687','p79360245','p96725043','p08946735','p41569073','p27018563','p63125809','p52014786','p95248160','p02173589','p42098156','p05321647','p89536047','p45701263','p59216748','p69850317','p70185432','p92018756','p29347815','p93240785','p40312865','p61894753','p53219607','p24385071','p74238150','p84760521','p63072491','p03596817','p41027368','p34527869','p29380451','p78934062','p32759104','p20934185','p89154230','p93870142','p31096457','p20743869','p32805697','p18674359','p97451280','p49680215','p85974201','p85346710','p21734698','p86942751','p85620714','p83769402','p58103429','p39701654','p09684175','p15094387','p90381257','p93680157','p49670125','p70293168','p24037156','p18736450','p01973852','p72459680','p92876154','p62587391','p02986317','p14390675','p36591724','p96538124','p38460152','p34291607','p26938541','p59071463','p51962430','p74639081','p32507896','p60975123','p36091572','p48071263','p34298105','p91365204','p98726041','p92168307','p31067542','p72961085','p94386207','p02453769','p18742503','p67835190','p85147902','p23079415','p62543087','p21873546','p96405328','p43586129','p24108635','p83026951','p68350421','p09318647','p97162543','p67185342','p35601974','p18450267','p30286179','p24179356','p13052498','p01962874','p78132509','p17562843','p65380429','p89670245','p34196587','p74392018','p54129673','p89705213','p80271365','p43168705','p18423067','p39057864','p70984165','p06841275','p84753160','p82465391','p70138459','p67024951','p50146287','p67904382','p29507168','p53628974','p90625378','p87619420','p81059632','p14786923','p53096748','p60783415','p51703482','p75401392','p67984023','p98523701','p40185679','p34057982','p65832097','p10742358','p45219703','p85914207','p96432058','p97043516','p68305921','p26135047','p60852143','p45671893','p41936527','p27015389','p78902156','p36895204','p16490573','p26185734','p59127306','p35071862','p24739165','p56179042','p18293604','p12074369','p32740518','p73028546','p29153687','p07328914','p63471052','p31849052','p25041869','p68427519','p12394508','p36710529','p59278036','p03518462','p25913408','p67905318','p64379201','p63948721','p36415870','p36874915','p73201598','p98534102','p27816504','p42056187','p25891046','p05872314','p19368045','p14390275','p08246193','p29863574','p76285934','p02835649','p84176235','p14603857','p06723581','p21580347','p92064571','p02459738','p73428590','p24807695','p79058623','p41297308','p34785092','p53206971','p90782563','p16024853','p03619725','p07123965','p36281475','p20654139','p79826134','p83215674','p80359714','p34857162','p02945871','p04317958','p85170239','p74051823','p26518940','p02635814','p82413657','p39607485','p62387409','p46081923','p10742853','p97126084','p01423876','p42679310','p09561482','p95862703','p37186459','p82406371','p78410965','p84596130','p14925836','p80146275','p03562197','p04576312','p36527018','p59187234','p46170235','p02163475','p87615324','p05691234','p96231745','p01865974','p24836917','p68714093','p80415972','p96587304','p49381276','p69218740','p74301682','p56278934','p97546102','p37896405','p62150938','p42078136','p58629041','p56803129','p74352198','p86205347','p83504671','p27034956','p10579286','p04976285','p27458390','p45210837','p16725489','p37041586','p38615249','p64950718','p97186325','p97635402','p91856613','p92874165','p32480596','p39254801','p68210359','p12583746','p86273145','p67514920','p25807463','p06839571','p35284706','p04551581','p91268403','p02142315','p12560947','p98567210','p59473016','p97248351','p74830458','p86524071','p17948350','p45920387','p85793146','p38149205','p86591027','p57064318','p31402598','renwen','renzhong','yuzhong','jiaoyu','gongwuyuan','baihuaban','shuziban','p63490875','p02738164','p56308142','p56932418','p87639245','p02103822','p75403168','p25970648','p08147695','p73194685','p63507129','p04896132','p48216530','p28091634','p90547381','p46259107','p18602397','p40381925','p48679103','p62660364','p53816940','p67428510','p64903278','p70981432','p43569802','p15680732','p07569831','p54183069','p50973641','p10378259','p57386409','p90835724','p92157683','p72856403','p60297481','p25674903','p47062581','p51927683','p08945163','p67392401','p60128394','p30791248','p30865794','p14365860','p13574098','p65427390','p42530869','p81407259','p29781560','p85147269','p10864573','p06382417','p97143502','p70281539','p80215369','p01682597','p16029574','p15672984','p40617389','p34215896','p03269785','p50874913','p76831094','p54619032','p49076185','p40156829','p03872954','p42506873','p83206417','p51820974','p42978530','p85631740','p49082367','p30654712','p45150945','p61547820','p35906278','p65120487','p82316754','p75183246','p50674321','p69415803','p31705269','p47295031','p97162085','p90378654','p91328675','p53962470','p58173402','p95078342','p95402816','p45832960','p51497286','p71045832','p67495213','p75620834','p50783612','p45619023','p49016357','p92546713','p04786391','p24108675','p13092847','p41235890','p61520730','p38906512','p24137568','p42573618','p20896315','p48310965','p13647289','p15624870','p52674013','p83571920','p74326809','p54712038','p72495360','p60517924','p25968041','p57364910','p73018265','p32065189','p12598647','p50218637','p86079321','p81257430','p52306894','p73615490','p31952407','p23974860','p36872140','p14982630','p68435927','p52360941','p48590137','p58206197','p16538049','p86975142','p70452891','p98063742','p48602953','p85237609','p87150349','p51978620','p75238014','starkylin','p08614975','p49562018','p85469723','WHU-CSE-IH-Team','p94108356','p58974620','p34520981','p02345198','p34265091','p03967182','p52069314','p09518632','p43850721','p75694102','p52803174','p64017953','p64952873','p93246150','p45091368','p98360154','p04675823','p49327518','p26743081','p36410592','p05924613','p68459203','p35812796','p14925308','p84152039','p38069172','p19286705','p01452789','p54708329'] + user_logins.each do |username| + begin + user = User.find_by(login: username) + next if user.blank? + project = Project.find project_id + next if Project.exists?(user_id: user.id, identifier: project.identifier) + new_project = Projects::ForkService.new(user, project, nil).call + random_num = rand(20..25) + members = user_logins.sample(random_num) + members.each do |m| + m_user = User.find_by(login: m) + next if m_user.blank? + Projects::AddMemberInteractor.call(new_project.owner, project, m_user) + end + new_date = project.created_on + rand(5..60).day + rand(5..30).hour + new_project.update_columns(created_on: new_date, updated_on: new_date) + ForkUser.where(fork_project_id: new_project.id).where(user_id: user.id).update_all(created_at: new_date, updated_at: new_date) + puts "forked project success username: #{username}" + rescue Exception => e + puts "forked project error username: #{username}" + end + end + end +end \ No newline at end of file From 9aef00ce0606a672d6a8c885ccd735e4e6be833b Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Wed, 22 Feb 2023 08:26:59 +0800 Subject: [PATCH 080/438] orgs search --- .../admins/organizations_controller.rb | 6 +++++- app/queries/admins/organization_query.rb | 21 +++++++++++++++++++ app/views/admins/organizations/index.html.erb | 9 ++++++++ app/views/admins/organizations/index.js.erb | 2 +- .../organizations/shared/_org_list.html.erb | 2 ++ 5 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 app/queries/admins/organization_query.rb diff --git a/app/controllers/admins/organizations_controller.rb b/app/controllers/admins/organizations_controller.rb index 4e40a509e..35fb4dee8 100644 --- a/app/controllers/admins/organizations_controller.rb +++ b/app/controllers/admins/organizations_controller.rb @@ -2,7 +2,11 @@ class Admins::OrganizationsController < Admins::BaseController before_action :finder_org, except: [:index] def index - @orgs = paginate Organization.all + params[:sort_by] = params[:sort_by].presence || 'created_on' + params[:sort_direction] = params[:sort_direction].presence || 'desc' + + orgs = Admins::OrganizationQuery.call(params) + @orgs = paginate orgs end def show diff --git a/app/queries/admins/organization_query.rb b/app/queries/admins/organization_query.rb new file mode 100644 index 000000000..09dbab9e3 --- /dev/null +++ b/app/queries/admins/organization_query.rb @@ -0,0 +1,21 @@ +class Admins::OrganizationQuery < ApplicationQuery + include CustomSortable + attr_reader :params + sort_columns :created_on, :last_login_on, :experience, :grade, default_by: :created_on, default_direction: :desc + + def initialize(params) + @params = params + end + + def call + orgs = Organization.all + # 关键字检索 + keyword = params[:keyword].to_s.strip.presence + if keyword + sql = 'nickname LIKE :keyword OR login LIKE :keyword' + orgs = orgs.where(sql, keyword: "%#{keyword}%") + end + + custom_sort(orgs, params[:sort_by], params[:sort_direction]) + end +end \ No newline at end of file diff --git a/app/views/admins/organizations/index.html.erb b/app/views/admins/organizations/index.html.erb index 7c96b57ee..7cd2ba8fa 100644 --- a/app/views/admins/organizations/index.html.erb +++ b/app/views/admins/organizations/index.html.erb @@ -1,6 +1,15 @@ <% define_admin_breadcrumbs do %> <% add_admin_breadcrumb('组织管理', admins_organizations_path) %> <% end %> +
          + <%= form_tag(admins_organizations_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %> + + <%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-sm-2 ml-3', placeholder: 'login/昵称') %> + + <%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %> + <% end %> + +
          <%= render partial: 'admins/organizations/shared/org_list', locals: { organizations: @orgs } %> diff --git a/app/views/admins/organizations/index.js.erb b/app/views/admins/organizations/index.js.erb index 7e750ecf9..5cf62a739 100644 --- a/app/views/admins/organizations/index.js.erb +++ b/app/views/admins/organizations/index.js.erb @@ -1 +1 @@ -$('.users-list-container').html("<%= j( render partial: 'admins/organizations/shared/org_list', locals: { organizations: @orgs } ) %>"); \ No newline at end of file +$('.organizations-list-container').html("<%= j( render partial: 'admins/organizations/shared/org_list', locals: { organizations: @orgs } ) %>"); \ No newline at end of file diff --git a/app/views/admins/organizations/shared/_org_list.html.erb b/app/views/admins/organizations/shared/_org_list.html.erb index b8fac30d0..9f3f857e8 100644 --- a/app/views/admins/organizations/shared/_org_list.html.erb +++ b/app/views/admins/organizations/shared/_org_list.html.erb @@ -2,6 +2,7 @@
      序号ID login 昵称 <%= sort_tag('创建于', name: 'created_on', path: admins_organizations_path) %>
      <%= list_index_no((params[:page] || 1).to_i, index) %><%= org.id %> <%= link_to "/#{org.login}", target: '_blank' do %> <%= overflow_hidden_span org.login, width: 100 %> From 960337206bd21359b04ebd938e394c15f817d996 Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Wed, 22 Feb 2023 09:12:16 +0800 Subject: [PATCH 081/438] team count and delete orgs --- app/models/organization.rb | 47 ++----------------- .../admins/delete_organization_service.rb | 13 +---- .../organizations/shared/_org_list.html.erb | 18 +++---- 3 files changed, 15 insertions(+), 63 deletions(-) diff --git a/app/models/organization.rb b/app/models/organization.rb index 17eb28918..d61dda567 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -147,52 +147,13 @@ class Organization < Owner def projects_count Project.where( user_id: self.id).count end - - # 用户账号状态 - def active? - status == User::STATUS_ACTIVE - end - - def registered? - status == User::STATUS_REGISTERED - end - - def locked? - status == User::STATUS_LOCKED - end - - def need_edit_info? - status == User::STATUS_EDIT_INFO - end - - def activate - self.status = User::STATUS_ACTIVE - end - - def register - self.status = User::STATUS_REGISTERED - end - - def lock - self.status = User::STATUS_LOCKED - end - - def need_edit_info - self.status = User::STATUS_EDIT_INFO - end - - def activate! - update_attribute(:status, STATUS_ACTIVE) - prohibit_gitea_user_login!(false) - end - def register! - update_attribute(:status, STATUS_REGISTERED) + def teams_count + teams.count end - def lock! - update_attribute(:status, STATUS_LOCKED) - prohibit_gitea_user_login! + def organization_users_count + organization_users.count end def real_name diff --git a/app/services/admins/delete_organization_service.rb b/app/services/admins/delete_organization_service.rb index db842845b..f5760b364 100644 --- a/app/services/admins/delete_organization_service.rb +++ b/app/services/admins/delete_organization_service.rb @@ -1,24 +1,15 @@ class Admins::DeleteOrganizationService < Gitea::ClientService attr_reader :token, :name - + def initialize(name) @name = name end def call - response = delete(url, params) - render_status(response) + Gitea::Organization::DeleteService.call(token,name) end private - def params - Hash.new.merge(token: token) - end - - def url - "/orgs/#{name}".freeze - end - def token { username: GiteaService.gitea_config[:access_key_id], diff --git a/app/views/admins/organizations/shared/_org_list.html.erb b/app/views/admins/organizations/shared/_org_list.html.erb index 9f3f857e8..25878b296 100644 --- a/app/views/admins/organizations/shared/_org_list.html.erb +++ b/app/views/admins/organizations/shared/_org_list.html.erb @@ -1,14 +1,14 @@ - - + - - - - - + + + + + + @@ -16,7 +16,6 @@ <% organizations.each_with_index do |org, index| %> - - + + - From c02ea218b39f826b9516642b31a696194c1d59e2 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 16 Mar 2023 17:44:11 +0800 Subject: [PATCH 186/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E8=80=85=E8=BF=94=E5=9B=9E=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/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 ed036aae3..2aa232fa6 100644 --- a/app/views/repositories/_contributor.json.jbuilder +++ b/app/views/repositories/_contributor.json.jbuilder @@ -2,13 +2,16 @@ user = $redis_cache.hgetall("v2-owner-common:#{contributor["name"]}-#{contributo if user.blank? json.contributions contributor["commits"] # json.id contributor["id"] - json.name contributor["name"] + json.login contributor["name"] + json.email contributor["email"] json.type nil json.name contributor["name"] json.image_url User::Avatar.get_letter_avatar_url(contributor["name"]) else json.contributions contributor["commits"] json.id user["id"] + json.login user["login"] + json.email user["email"] json.name user["name"] json.type user["type"] json.name user["name"] From ac49edc8e8c2e08225512e719265f3cc5cbf2951 Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Fri, 17 Mar 2023 08:43:02 +0800 Subject: [PATCH 187/438] remove user list th --- app/views/admins/users/shared/_user_list.html.erb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/views/admins/users/shared/_user_list.html.erb b/app/views/admins/users/shared/_user_list.html.erb index 67571178a..d3061e5ae 100644 --- a/app/views/admins/users/shared/_user_list.html.erb +++ b/app/views/admins/users/shared/_user_list.html.erb @@ -5,7 +5,6 @@ - From a6307534854f4c6367e0a0d1f56c16b0a3446c0d Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 20 Mar 2023 10:11:20 +0800 Subject: [PATCH 188/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=88=86=E6=94=AFHash=20to=20Array?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/contents/batch_create_service.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/services/api/v1/projects/contents/batch_create_service.rb b/app/services/api/v1/projects/contents/batch_create_service.rb index 7c514c376..6503fd88c 100644 --- a/app/services/api/v1/projects/contents/batch_create_service.rb +++ b/app/services/api/v1/projects/contents/batch_create_service.rb @@ -84,9 +84,9 @@ class Api::V1::Projects::Contents::BatchCreateService < ApplicationService def check_branch_exist result = $gitea_hat_client.get_repos_branch_name_set_by_owner_repo(owner, repo, {query: request_params} ) rescue nil - raise Error, '查询分支名称失败!' unless result.is_a?(Hash) - raise Error, '分支不存在!' unless result['branch_name'].include?(branch) - raise Error, '分支已存在!' if result['branch_name'].include?(new_branch) && !new_branch.nil? + raise Error, '查询分支名称失败!' unless result.is_a?(Array) + raise Error, '分支不存在!' unless result.include?(branch) + raise Error, '分支已存在!' if result.include?(new_branch) && !new_branch.nil? end end \ No newline at end of file From 0a7c41d97c5d874bde0924271a11154557950d2a Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Mon, 20 Mar 2023 14:47:48 +0800 Subject: [PATCH 189/438] user fresh gitea token method --- app/models/user.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/models/user.rb b/app/models/user.rb index 5e21212ab..1818bccb1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -449,6 +449,19 @@ class User < Owner self.status = STATUS_EDIT_INFO end + def fresh_gitea_token + result = $gitea_client.get_users_tokens_by_username(self.login, {query: {sudo: self.login}}) + if result[:data].present? + result[:data].map{ |e| + $gitea_client.delete_users_tokens_by_username_token(self.login, e["name"], {query: {sudo: self.login} }) + } + end + new_result = $gitea_client.post_users_tokens_by_username(self.login, { query: {sudo: self.login}, body:{ name: self.login} }) + if new_result["sha1"].present? + update(gitea_token: new_result["sha1"]) + end + end + def activate! update_attribute(:status, STATUS_ACTIVE) prohibit_gitea_user_login!(false) From 7da1c7e13bbfe83479156e8c9afe64d8ad0b2575 Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Mon, 20 Mar 2023 15:25:47 +0800 Subject: [PATCH 190/438] add admin user view button for gitea token reset --- app/assets/javascripts/admins/users/index.js | 14 ++++++++++++++ app/controllers/admins/users_controller.rb | 6 ++++++ app/views/admins/users/shared/_user_list.html.erb | 3 +-- config/routes.rb | 1 + 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/admins/users/index.js b/app/assets/javascripts/admins/users/index.js index 0ef024bfd..55dabed19 100644 --- a/app/assets/javascripts/admins/users/index.js +++ b/app/assets/javascripts/admins/users/index.js @@ -94,6 +94,20 @@ $(document).on('turbolinks:load', function(){ } }); }); + // reset user login times + $('.users-list-container').on('click', '.fresh-gitea-token-action', function(){ + var $action = $(this); + + var userId = $action.data('id'); + $.ajax({ + url: '/admins/users/' + userId + '/fresh_gitea_token', + method: 'POST', + dataType: 'json', + success: function() { + showSuccessNotify(); + } + }); + }); // ***************** reward grade modal ***************** var $rewardGradeModal = $('.admin-users-reward-grade-modal'); diff --git a/app/controllers/admins/users_controller.rb b/app/controllers/admins/users_controller.rb index 8ff5908c6..9137e218e 100644 --- a/app/controllers/admins/users_controller.rb +++ b/app/controllers/admins/users_controller.rb @@ -57,6 +57,12 @@ class Admins::UsersController < Admins::BaseController render_ok end + + def fresh_gitea_token + @user.fresh_gitea_token + render_ok + end + private def finder_user diff --git a/app/views/admins/users/shared/_user_list.html.erb b/app/views/admins/users/shared/_user_list.html.erb index d3061e5ae..4ef85bc5a 100644 --- a/app/views/admins/users/shared/_user_list.html.erb +++ b/app/views/admins/users/shared/_user_list.html.erb @@ -42,9 +42,8 @@
      <%= javascript_void_link('更多', class: 'action dropdown-toggle', 'data-toggle': 'dropdown', 'aria-haspopup': true, 'aria-expanded': false) %>
      diff --git a/config/routes.rb b/config/routes.rb index 3488bacb4..0d29e403f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -824,6 +824,7 @@ Rails.application.routes.draw do post :unlock post :active post :reset_login_times + post :fresh_gitea_token end end resource :import_disciplines, only: [:create] From 1ce55b27f410882481405dc94cd17901038a2355 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 20 Mar 2023 16:13:29 +0800 Subject: [PATCH 191/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E7=96=91?= =?UTF-8?q?=E4=BF=AE=E5=88=97=E8=A1=A8=E5=88=87=E6=8D=A2=E5=85=B3=E9=97=AD?= =?UTF-8?q?status=20count=E4=B8=8D=E5=8F=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/issues/list_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index 9804d63c2..256ad222c 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -68,7 +68,7 @@ class Api::V1::Issues::ListService < ApplicationService issues = issues.joins(:assigners).where(users: {id: assigner_id}) if assigner_id.present? # status_id - issues = issues.where(status_id: status_id) if status_id.present? + issues = issues.where(status_id: status_id) if status_id.present? && category != 'closed' if begin_date&.present? || end_date&.present? issues = issues.where("issues.created_on between ? and ?", begin_date&.present? ? begin_date.to_time : Time.now.beginning_of_day, end_date&.present? ? end_date.to_time.end_of_day : Time.now.end_of_day) From 26ea240303512b5e45792ca7fcbdf6fe72bf8500 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 21 Mar 2023 15:59:19 +0800 Subject: [PATCH 192/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/api/v1/projects/branches/all.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/api/v1/projects/branches/all.json.jbuilder b/app/views/api/v1/projects/branches/all.json.jbuilder index d89b1ee16..4a9f2a12b 100644 --- a/app/views/api/v1/projects/branches/all.json.jbuilder +++ b/app/views/api/v1/projects/branches/all.json.jbuilder @@ -1,3 +1,3 @@ -json.array! @result_object["branch_name"] do |branch| +json.array! @result_object do |branch| json.partial! "api/v1/projects/branches/simple_detail", branch: branch end \ No newline at end of file From 50696de804fb9591cac8dbc45ec39a32823c17b0 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 21 Mar 2023 17:48:02 +0800 Subject: [PATCH 193/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Aheatmap?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E6=AD=A3=E5=B8=B8=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users/statistics_controller.rb | 10 +++++++--- app/services/gitea/user/headmap_service.rb | 7 ++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/controllers/users/statistics_controller.rb b/app/controllers/users/statistics_controller.rb index 1948af9b3..417aecd17 100644 --- a/app/controllers/users/statistics_controller.rb +++ b/app/controllers/users/statistics_controller.rb @@ -4,7 +4,8 @@ class Users::StatisticsController < Users::BaseController # 近期活动统计 def activity date_range = (1.week.ago.to_date..Date.today).to_a - commit_request = Gitea::User::HeadmapService.call(observed_user.login, 1.week.ago.to_date.to_time.to_i, Date.today.to_time.to_i) + commit_request = Gitea::User::HeadmapService.call(observed_user.login, 1.week.ago.to_date.to_time.to_i, Date.today.end_of_day.to_time.to_i, observed_user.gitea_token) + puts commit_request commit_data = commit_request[2] @date_data = [] @issue_data = [] @@ -14,8 +15,11 @@ class Users::StatisticsController < Users::BaseController @date_data << date.strftime("%Y.%m.%d") @issue_data << observed_user.issues.issue_issue.where("DATE(created_on) = ?", date).size @pull_request_data << observed_user.pull_requests.where("DATE(created_at) = ?", date).size - date_commit_data = commit_data.blank? ? nil : commit_data.select{|item| item["timestamp"] == date.to_time.to_i} - @commit_data << (date_commit_data.blank? ? 0 : date_commit_data[0]["contributions"].to_i) + contribution = 0 + commit_data.each do |item| + contribution += item["contributions"] if Time.at(item["timestamp"]).strftime("%Y-%m-%d") == date.to_s + end + @commit_data << contribution end render :json => {dates: @date_data, issues_count: @issue_data, pull_requests_count: @pull_request_data, commits_count: @commit_data} end diff --git a/app/services/gitea/user/headmap_service.rb b/app/services/gitea/user/headmap_service.rb index d066d0f16..eef8e21a9 100644 --- a/app/services/gitea/user/headmap_service.rb +++ b/app/services/gitea/user/headmap_service.rb @@ -1,10 +1,11 @@ class Gitea::User::HeadmapService < Gitea::ClientService - attr_reader :start_time, :end_time, :username + attr_reader :start_time, :end_time, :username, :token - def initialize(username, start_time, end_time) + def initialize(username, start_time, end_time, token=nil) @username = username @start_time = start_time @end_time = end_time + @token = token end def call @@ -14,7 +15,7 @@ class Gitea::User::HeadmapService < Gitea::ClientService private def params - Hash.new.merge(start: start_time, end: end_time) + Hash.new.merge(start: start_time, end: end_time, token: token) end def url From 132eb79b9fe42b234ff7d91f0263238792269ba0 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 21 Mar 2023 18:36:40 +0800 Subject: [PATCH 194/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Aachive?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 2 +- app/controllers/users/statistics_controller.rb | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index e6fef78f0..71c174f42 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -262,7 +262,7 @@ class RepositoriesController < ApplicationController archive_url = "/repos/#{@owner.login}/#{@repository.identifier}/archive/#{Addressable::URI.escape(params[:archive])}" file_path = [domain, api_url, archive_url].join - file_path = [file_path, "access_token=#{current_user&.gitea_token}"].join("?") if @repository.hidden? + file_path = [file_path, "access_token=#{current_user&.gitea_token}"].join("?") return render_not_found if !request.format.zip? && !request.format.gzip? diff --git a/app/controllers/users/statistics_controller.rb b/app/controllers/users/statistics_controller.rb index 417aecd17..013191910 100644 --- a/app/controllers/users/statistics_controller.rb +++ b/app/controllers/users/statistics_controller.rb @@ -5,7 +5,6 @@ class Users::StatisticsController < Users::BaseController def activity date_range = (1.week.ago.to_date..Date.today).to_a commit_request = Gitea::User::HeadmapService.call(observed_user.login, 1.week.ago.to_date.to_time.to_i, Date.today.end_of_day.to_time.to_i, observed_user.gitea_token) - puts commit_request commit_data = commit_request[2] @date_data = [] @issue_data = [] From 481a7fd6262535728de145fdb1eee69ab89996bc Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 22 Mar 2023 11:03:05 +0800 Subject: [PATCH 195/438] =?UTF-8?q?mindspore=E4=B8=89=E4=B8=AA=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=BC=80=E5=90=AF=E7=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/projects_helper.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 804e2aa46..5bd2f68f2 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -149,6 +149,9 @@ module ProjectsHelper when 'vue' then "#{url}/v1/vue/entropy" when 'bootstrap' then "#{url}/v1/bootstrap/entropy" when 'tensorflow' then "#{url}/v1/tensorflow/entropy" + when 'openeuler' then "#{url}/v1/openeuler/entropy" + when 'opengauss' then "#{url}/v1/opengauss/entropy" + when 'mindspore' then "#{url}/v1/mindspore/entropy" else '' end end @@ -163,6 +166,9 @@ module ProjectsHelper when 'vue' then "#{url}/v2/getMediumData?repo_login=vuejs&repo_name=vue" when 'bootstrap' then "#{url}/v2/getMediumData?repo_login=twbs&repo_name=bootstrap" when 'tensorflow' then "#{url}/v2/getMediumData?repo_login=tensorflow&repo_name=tensorflow" + when 'openeuler' then "#{url}/v2/getMediumData?repo_login=openeuler&repo_name=openeuler" + when 'opengauss' then "#{url}/v2/getMediumData?repo_login=opengauss&repo_name=opengauss" + when 'mindspore' then "#{url}/v2/getMediumData?repo_login=mindspore&repo_name=mindspore" else '' end end @@ -177,6 +183,9 @@ module ProjectsHelper when 'vue' then "#{url}/v2/getIndexData?repo_login=vuejs&repo_name=vue" when 'bootstrap' then "#{url}/v2/getIndexData?repo_login=twbs&repo_name=bootstrap" when 'tensorflow' then "#{url}/v2/getIndexData?repo_login=tensorflow&repo_name=tensorflow" + when 'openeuler' then "#{url}/v2/getIndexData?repo_login=openeuler&repo_name=openeuler" + when 'opengauss' then "#{url}/v2/getIndexData?repo_login=opengauss&repo_name=opengauss" + when 'mindspore' then "#{url}/v2/getIndexData?repo_login=mindspore&repo_name=mindspore" else '' end end @@ -191,6 +200,9 @@ module ProjectsHelper when 'vue' then "#{url}/vue/entropy" when 'bootstrap' then "#{url}/bootstrap/entropy" when 'tensorflow' then "#{url}/tensorflow/entropy" + when 'openeuler' then "#{url}/openeuler/entropy" + when 'opengauss' then "#{url}/opengauss/entropy" + when 'mindspore' then "#{url}/mindspore/entropy" else '' end end From b65b920a1e6413c940d8e712276b3d6e86cfd51a Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 22 Mar 2023 11:13:27 +0800 Subject: [PATCH 196/438] =?UTF-8?q?=E5=B7=B2=E5=AE=89=E8=A3=85bot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/installations/index.json.jbuilder | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/installations/index.json.jbuilder b/app/views/installations/index.json.jbuilder index b2f674f20..3d64a3323 100644 --- a/app/views/installations/index.json.jbuilder +++ b/app/views/installations/index.json.jbuilder @@ -2,6 +2,7 @@ json.status 0 json.message "success" json.data do json.array! @install_bots do |install_bot| + json.installation_id install_bot.id json.extract! install_bot.bot, :id, :name end end \ No newline at end of file From 97c673ab07acecb593719d63975861a3fba6d557 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 22 Mar 2023 11:03:05 +0800 Subject: [PATCH 197/438] =?UTF-8?q?mindspore=E4=B8=89=E4=B8=AA=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=BC=80=E5=90=AF=E7=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/projects_helper.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 804e2aa46..5bd2f68f2 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -149,6 +149,9 @@ module ProjectsHelper when 'vue' then "#{url}/v1/vue/entropy" when 'bootstrap' then "#{url}/v1/bootstrap/entropy" when 'tensorflow' then "#{url}/v1/tensorflow/entropy" + when 'openeuler' then "#{url}/v1/openeuler/entropy" + when 'opengauss' then "#{url}/v1/opengauss/entropy" + when 'mindspore' then "#{url}/v1/mindspore/entropy" else '' end end @@ -163,6 +166,9 @@ module ProjectsHelper when 'vue' then "#{url}/v2/getMediumData?repo_login=vuejs&repo_name=vue" when 'bootstrap' then "#{url}/v2/getMediumData?repo_login=twbs&repo_name=bootstrap" when 'tensorflow' then "#{url}/v2/getMediumData?repo_login=tensorflow&repo_name=tensorflow" + when 'openeuler' then "#{url}/v2/getMediumData?repo_login=openeuler&repo_name=openeuler" + when 'opengauss' then "#{url}/v2/getMediumData?repo_login=opengauss&repo_name=opengauss" + when 'mindspore' then "#{url}/v2/getMediumData?repo_login=mindspore&repo_name=mindspore" else '' end end @@ -177,6 +183,9 @@ module ProjectsHelper when 'vue' then "#{url}/v2/getIndexData?repo_login=vuejs&repo_name=vue" when 'bootstrap' then "#{url}/v2/getIndexData?repo_login=twbs&repo_name=bootstrap" when 'tensorflow' then "#{url}/v2/getIndexData?repo_login=tensorflow&repo_name=tensorflow" + when 'openeuler' then "#{url}/v2/getIndexData?repo_login=openeuler&repo_name=openeuler" + when 'opengauss' then "#{url}/v2/getIndexData?repo_login=opengauss&repo_name=opengauss" + when 'mindspore' then "#{url}/v2/getIndexData?repo_login=mindspore&repo_name=mindspore" else '' end end @@ -191,6 +200,9 @@ module ProjectsHelper when 'vue' then "#{url}/vue/entropy" when 'bootstrap' then "#{url}/bootstrap/entropy" when 'tensorflow' then "#{url}/tensorflow/entropy" + when 'openeuler' then "#{url}/openeuler/entropy" + when 'opengauss' then "#{url}/opengauss/entropy" + when 'mindspore' then "#{url}/mindspore/entropy" else '' end end From 8c1cc9ace84803d43805fe89b95fa068823fbad3 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 22 Mar 2023 11:13:27 +0800 Subject: [PATCH 198/438] =?UTF-8?q?=E5=B7=B2=E5=AE=89=E8=A3=85bot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/installations/index.json.jbuilder | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/installations/index.json.jbuilder b/app/views/installations/index.json.jbuilder index b2f674f20..3d64a3323 100644 --- a/app/views/installations/index.json.jbuilder +++ b/app/views/installations/index.json.jbuilder @@ -2,6 +2,7 @@ json.status 0 json.message "success" json.data do json.array! @install_bots do |install_bot| + json.installation_id install_bot.id json.extract! install_bot.bot, :id, :name end end \ No newline at end of file From 7cc0dfd08ded5212b5766b88a158dfbf67e31d93 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 22 Mar 2023 16:05:31 +0800 Subject: [PATCH 199/438] =?UTF-8?q?=E5=AF=BC=E5=85=A5gitee=20issue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_add_issues.rake | 128 ++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 lib/tasks/batch_add_issues.rake diff --git a/lib/tasks/batch_add_issues.rake b/lib/tasks/batch_add_issues.rake new file mode 100644 index 000000000..992666da8 --- /dev/null +++ b/lib/tasks/batch_add_issues.rake @@ -0,0 +1,128 @@ +namespace :batch_add_issues do + desc "batch_add_issues" + task gitee: :environment do + project_id = ENV['project_id'] + puts "project_id=================#{project_id}" + next if project_id.blank? + project = Project.find project_id + # count = 100000 + # if ENV['count'].present? + # count = ENV['count'] + # end + + total_count = 2066 + 499 + 16675 + 451 + puts "total_count==========#{total_count}" + if total_count > 100 + total_page = (total_count / 100) + 1 + total_page.times do |i| + add_issues_to_project(project, i + 1) + end + else + add_issues_to_project(project, 1) + end + + + end + + def add_issues_to_project(project,page) + # curl -X GET --header 'Content-Type: application/json;charset=UTF-8' 'https://gitee.com/api/v5/repos/mindspore/mindspore/issues?access_token=5ccebd935915fb6cfcae634b161047a2&state=open&sort=created&direction=desc&page=1&per_page=10' + api_url = "https://gitee.com/api/v5/repos/mindspore/mindspore/issues?access_token=5ccebd935915fb6cfcae634b161047a2&state=all&sort=created&direction=desc&page=#{page}&per_page=100" + uri = URI.parse(api_url) + response = Net::HTTP.get_response(uri) + puts "gitee api response.code ===== #{response.code}" + lists = JSON.parse(response.body) + puts "lists.size =====#{lists.size}" + + # "1" => "新增", + # "2" => "正在解决", + # "3" => "已解决", + # "5" => "关闭", + # "6" => "拒绝" + # Issue的状态: open(开启的), progressing(进行中), closed(关闭的), rejected(拒绝的)。 默认: open + lists.each do |issue| + created_issue = Issue.find_by(project_id: project.id, subject: issue['title']) + unless created_issue.present? + priority = [1, 2, 3, 4].include?(issue['priority'].to_i) ? issue['priority'].to_i : 2 + issue_status = ["", "open", "progressing", "", "", "closed", "rejected"].index(issue['state']) + issue_status = 1 if issue_status.nil? + user_login = issue['user']['login'] + issue_created_at = issue['created_at'] + issue_updated_at = issue['updated_at'] + user = User.find_by(login: user_login) + unless user.present? + username = user_login + email = "#{username}@gitlink.org.cn" + phone = "" + password = "a12345678" + user = User.new(nickname: user_login, login: username, mail: email, password: password, type: 'User', phone: phone) + interactor = Gitea::RegisterInteractor.call({ username: username, email: email, password: password }) + gitea_user = interactor.result + result = Gitea::User::GenerateTokenService.call(username, password) + user.gitea_token = result['sha1'] + user.gitea_uid = gitea_user[:body]['id'] + user.created_on = issue_created_at + user.updated_on = issue_created_at + user.is_test = true + user.save! + UserExtension.create!(user_id: user.id) + puts "import_user batch success: phone #{phone} email: #{email}" + end + + issue_params = { + :status_id => issue_status, + :priority_id => priority, + # :milestone_id, + # :branch_name, + # :start_date, + # :due_date, + :subject => issue['title'], + :description => issue['body'], + # :blockchain_token_num, + :issue_tag_ids => [], + :assigner_ids => [], + :attachment_ids => [], + :receivers_login => [] + } + created_issue = Api::V1::Issues::CreateService.call(project, issue_params, user) + created_issue.update_columns(created_on: issue_created_at, updated_on: issue_updated_at) + end + + issue_number = issue['number'] + comment_api_url = "https://gitee.com/api/v5/repos/mindspore/mindspore/issues/#{issue_number}/comments?access_token=5ccebd935915fb6cfcae634b161047a2&page=1&per_page=100&order=asc" + comment_uri = URI.parse(comment_api_url) + comment_response = Net::HTTP.get_response(comment_uri) + comment_lists = JSON.parse(comment_response.body) + + comment_lists.each do |comment| + next if Journal.find_by(journalized_id: created_issue.id, journalized_type: 'Issue', notes: comment['body']).present? + user_login = comment['user']['login'] + comment_created_at = comment['created_at'] + comment_updated_at = comment['updated_at'] + comment_user = User.find_by(login: user_login) + unless comment_user.present? + username = user_login + email = "#{username}@gitlink.org.cn" + phone = "" + password = "a12345678" + comment_user = User.new(nickname: user_login, login: username, mail: email, password: password, type: 'User', phone: phone) + interactor = Gitea::RegisterInteractor.call({ username: username, email: email, password: password }) + gitea_user = interactor.result + result = Gitea::User::GenerateTokenService.call(username, password) + comment_user.gitea_token = result['sha1'] + comment_user.gitea_uid = gitea_user[:body]['id'] + comment_user.created_on = comment_created_at + comment_user.updated_on = comment_created_at + comment_user.save! + UserExtension.create!(user_id: comment_user.id) + end + + journal_params = {:notes => comment['body'], + :attachment_ids => [], + :receivers_login => []} + + object_result = Api::V1::Issues::Journals::CreateService.call(created_issue, journal_params, comment_user) + object_result.update_columns(created_on: comment_created_at, updated_on: comment_updated_at) + end + end + end +end \ No newline at end of file From f44c24401599beb98b7ccfbcbc71c3ca8ced67a1 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 22 Mar 2023 17:50:42 +0800 Subject: [PATCH 200/438] =?UTF-8?q?=E5=AF=BC=E5=85=A5gitee=20issue?= =?UTF-8?q?=EF=BC=8C=E5=B7=B2=E6=89=A7=E8=A1=8C=E9=A1=B5=E7=A0=81=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_add_issues.rake | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/tasks/batch_add_issues.rake b/lib/tasks/batch_add_issues.rake index 992666da8..0c3a281d4 100644 --- a/lib/tasks/batch_add_issues.rake +++ b/lib/tasks/batch_add_issues.rake @@ -5,17 +5,17 @@ namespace :batch_add_issues do puts "project_id=================#{project_id}" next if project_id.blank? project = Project.find project_id - # count = 100000 - # if ENV['count'].present? - # count = ENV['count'] - # end + count = 0 + if ENV['count'].present? + count = ENV['count'] + end total_count = 2066 + 499 + 16675 + 451 puts "total_count==========#{total_count}" if total_count > 100 total_page = (total_count / 100) + 1 total_page.times do |i| - add_issues_to_project(project, i + 1) + add_issues_to_project(project, i + 1 + count) end else add_issues_to_project(project, 1) @@ -50,7 +50,7 @@ namespace :batch_add_issues do issue_updated_at = issue['updated_at'] user = User.find_by(login: user_login) unless user.present? - username = user_login + username = user_login[0..28] email = "#{username}@gitlink.org.cn" phone = "" password = "a12345678" From 2a660b8b75c5dac1654851c5872933b175afd8bb Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 22 Mar 2023 17:51:31 +0800 Subject: [PATCH 201/438] =?UTF-8?q?=E5=AF=BC=E5=85=A5gitee=20issue?= =?UTF-8?q?=EF=BC=8C=E5=B7=B2=E6=89=A7=E8=A1=8C=E9=A1=B5=E7=A0=81=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_add_issues.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/batch_add_issues.rake b/lib/tasks/batch_add_issues.rake index 0c3a281d4..120c6a204 100644 --- a/lib/tasks/batch_add_issues.rake +++ b/lib/tasks/batch_add_issues.rake @@ -7,7 +7,7 @@ namespace :batch_add_issues do project = Project.find project_id count = 0 if ENV['count'].present? - count = ENV['count'] + count = ENV['count'].to_i end total_count = 2066 + 499 + 16675 + 451 From cddbf2a7ccb4c088870756a79d549a09bed563e8 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 22 Mar 2023 18:04:30 +0800 Subject: [PATCH 202/438] =?UTF-8?q?=E5=AF=BC=E5=85=A5gitee=20issue?= =?UTF-8?q?=EF=BC=8C=E5=B7=B2=E6=89=A7=E8=A1=8C=E9=A1=B5=E7=A0=81=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_add_issues.rake | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/tasks/batch_add_issues.rake b/lib/tasks/batch_add_issues.rake index 120c6a204..541a79c6e 100644 --- a/lib/tasks/batch_add_issues.rake +++ b/lib/tasks/batch_add_issues.rake @@ -96,6 +96,7 @@ namespace :batch_add_issues do comment_lists.each do |comment| next if Journal.find_by(journalized_id: created_issue.id, journalized_type: 'Issue', notes: comment['body']).present? user_login = comment['user']['login'] + next if user_login.size >29 comment_created_at = comment['created_at'] comment_updated_at = comment['updated_at'] comment_user = User.find_by(login: user_login) From a02a15ac12c017e7ce4fb25dee6ff9c5e90943a3 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 22 Mar 2023 18:04:35 +0800 Subject: [PATCH 203/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Aheatmap?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users/headmaps_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/users/headmaps_controller.rb b/app/controllers/users/headmaps_controller.rb index 7faba1e50..83efd99fb 100644 --- a/app/controllers/users/headmaps_controller.rb +++ b/app/controllers/users/headmaps_controller.rb @@ -1,6 +1,6 @@ class Users::HeadmapsController < Users::BaseController def index - result = Gitea::User::HeadmapService.call(observed_user.login, start_stamp, end_stamp) + result = Gitea::User::HeadmapService.call(observed_user.login, start_stamp, end_stamp, observed_user&.gitea_token) @headmaps = result[2].blank? ? [] : result[2] rescue Exception => e uid_logger_error(e.message) From ec85b80a98ea2927938b451dfecade721d6ee827 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 22 Mar 2023 18:24:42 +0800 Subject: [PATCH 204/438] =?UTF-8?q?=E5=AF=BC=E5=85=A5gitee=20issue?= =?UTF-8?q?=EF=BC=8C=E7=94=A8=E6=88=B7=E5=90=8D=E5=A4=AA=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_add_issues.rake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/tasks/batch_add_issues.rake b/lib/tasks/batch_add_issues.rake index 541a79c6e..82beaf01d 100644 --- a/lib/tasks/batch_add_issues.rake +++ b/lib/tasks/batch_add_issues.rake @@ -46,11 +46,12 @@ namespace :batch_add_issues do issue_status = ["", "open", "progressing", "", "", "closed", "rejected"].index(issue['state']) issue_status = 1 if issue_status.nil? user_login = issue['user']['login'] + user_login = user_login[0..20] if user_login.size > 29 issue_created_at = issue['created_at'] issue_updated_at = issue['updated_at'] user = User.find_by(login: user_login) unless user.present? - username = user_login[0..28] + username = user_login email = "#{username}@gitlink.org.cn" phone = "" password = "a12345678" From 3762a54effbdf5f0a24a1ce3e9fec80b1eedd62f Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 22 Mar 2023 18:57:56 +0800 Subject: [PATCH 205/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E8=80=85=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 5 ++-- .../repository/contributors/get_service.rb | 24 +++++++++++++++---- .../repositories/contributors.json.jbuilder | 3 +-- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index e32b31017..e6fef78f0 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -166,8 +166,9 @@ class RepositoriesController < ApplicationController if params[:filepath].present? || @project.educoder? @contributors = [] else - result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier) - @contributors = result.is_a?(Hash) && result.key?(:status) ? [] : result + result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier, {page: params[:page], limit: params[:limit]}) + @total_count = result[:total_count] + @contributors = result.is_a?(Hash) ? result[:body] : [] end rescue @contributors = [] diff --git a/app/services/gitea/repository/contributors/get_service.rb b/app/services/gitea/repository/contributors/get_service.rb index 1ee1c3955..b20a4a408 100644 --- a/app/services/gitea/repository/contributors/get_service.rb +++ b/app/services/gitea/repository/contributors/get_service.rb @@ -1,22 +1,38 @@ class Gitea::Repository::Contributors::GetService < Gitea::ClientService - attr_reader :owner, :repo_name + attr_reader :owner, :repo_name, :page, :limit - def initialize(owner, repo_name) + def initialize(owner, repo_name, page, limit) @owner = owner @repo_name = repo_name + @page = params[:page] || 1 + @limit = params[:limit] || 20 end def call response = get(url, params) - render_status(response) + render_result(response) end private def params - Hash.new.merge(token: owner.gitea_token) + Hash.new.merge(token: owner.gitea_token, page: page, limit: limit) end def url "/repos/#{owner.login}/#{repo_name}/contributors" end + + def render_result(response) + case response.status + when 200 + result = {} + headers = response.headers.to_hash + body = JSON.parse(response.body) + total_count = headers["x-total"] + result.merge(total_count: total_count.to_i, body: body) + else + nil + # {status: -1, message: "#{body['message']}"} + end + end end \ No newline at end of file diff --git a/app/views/repositories/contributors.json.jbuilder b/app/views/repositories/contributors.json.jbuilder index 4534de693..3947fb967 100644 --- a/app/views/repositories/contributors.json.jbuilder +++ b/app/views/repositories/contributors.json.jbuilder @@ -1,7 +1,6 @@ -total_count = @contributors.size json.list @contributors.each do |contributor| json.partial! 'contributor', locals: { contributor: contributor, project: @project } end -json.total_count total_count +json.total_count @total_count From 6c6f1cfd42f7b549f38bfb4e6d47a91bbdc3b561 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 22 Mar 2023 21:09:07 +0800 Subject: [PATCH 206/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E8=80=85=E5=88=86=E9=A1=B5=E5=8F=82=E6=95=B0=E4=BC=A0?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/gitea/repository/contributors/get_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/gitea/repository/contributors/get_service.rb b/app/services/gitea/repository/contributors/get_service.rb index b20a4a408..ea121a50d 100644 --- a/app/services/gitea/repository/contributors/get_service.rb +++ b/app/services/gitea/repository/contributors/get_service.rb @@ -1,7 +1,7 @@ class Gitea::Repository::Contributors::GetService < Gitea::ClientService attr_reader :owner, :repo_name, :page, :limit - def initialize(owner, repo_name, page, limit) + def initialize(owner, repo_name, params) @owner = owner @repo_name = repo_name @page = params[:page] || 1 From ee50083a5744fcb5ba256090a9828e317944a118 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 23 Mar 2023 09:33:52 +0800 Subject: [PATCH 207/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E7=89=B9?= =?UTF-8?q?=E6=AE=8A=E7=BB=9F=E8=AE=A1commit=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 7 +++- lib/tasks/special_commit.rake | 40 ++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 lib/tasks/special_commit.rake diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index e6fef78f0..7ac3984db 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -322,7 +322,12 @@ class RepositoriesController < ApplicationController def get_latest_commit latest_commit = @project.educoder? ? nil : project_commits @latest_commit = latest_commit.present? ? latest_commit[:body][0] : nil - @commits_count = latest_commit.present? ? latest_commit[:total_count] : 0 + cache_total_commits = $redis_cache.get("ProjectSpecialCommit:#{project.id}") + if cache_total_commits.present? + @commits_count = cache_total_commits.to_i + else + @commits_count = latest_commit.present? ? latest_commit[:total_count] : 0 + end end def content_params diff --git a/lib/tasks/special_commit.rake b/lib/tasks/special_commit.rake new file mode 100644 index 000000000..4d5e04f7a --- /dev/null +++ b/lib/tasks/special_commit.rake @@ -0,0 +1,40 @@ +namespace :special_commit do + desc "batch_add_issues" + task :load, [:login, :identifier] => :environment do |t, args| + owner = Owner.find_by(login: args.login) + project = Project.find_by(user_id: owner&.id, identifier: args.identifier) + if owner.nil? || project.nil? + puts "====Project is not found.====" + else + puts "====Sync Project: #{owner.real_name}/#{project.name}====" + puts "====Sync Count Project Self Commit====" + self_commit_list_result = $gitea_client.get_repos_commits_by_owner_repo(owner.login, project.identifier) + total_commits = self_commit_list_result[:total_data].to_i + puts "====Sync Count Project Submodule Commit====" + entries = $gitea_client.get_repos_contents_by_owner_repo(owner.login, project.identifier) + entries.each do |entry| + next if entry["submodule_git_url"].nil? + submodule_git_url = entry["submodule_git_url"].gsub(Rails.application.config_for(:configuration)['platform_url'], '').gsub(".git", '') + real_relative_path = File.expand_path(submodule_git_url, "#{owner.login}/#{project.identifier}").gsub("#{Rails.root}/", '') + sub_project_owner_login = real_relative_path.split("/")[0] + sub_project_identifier = real_relative_path.split("/")[1] + sub_owner = Owner.find_by(login: sub_project_owner_login) + sub_project = sub_owner.projects.find_by(identifier: sub_project_identifier) + next if sub_owner.nil? || sub_project.nil? + sub_commit_list_result = $gitea_client.get_repos_commits_by_owner_repo(sub_project_owner_login, sub_project_identifier) + total_commits += sub_commit_list_result[:total_data].to_i + end + puts "====Sync Count Project forkproject Commit====" + project.forked_projects.each do |p| + forked_project_owner_login = p.owner&.login + forked_project_identifier = p.identifier + next if forked_project_owner_login.nil? || forked_project_owner_login.nil? + forked_commit_list_result = $gitea_client.get_repos_commits_by_owner_repo(forked_project_owner_login, forked_project_identifier) + total_commits += forked_commit_list_result[:total_data].to_i + end + puts "====Write total commits to cache====" + $redis_cache.set("ProjectSpecialCommit:#{project.id}", total_commits) + $redis_cache.expireat("ProjectSpecialCommit:#{project.id}", (Date.today+30.days).to_time.to_i) + end + end +end \ No newline at end of file From e0692bd92acfeb29f3ec82838e1b5ff73913f51c Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 23 Mar 2023 09:49:35 +0800 Subject: [PATCH 208/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Afork?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E4=B8=BA=E5=AD=90=E9=A1=B9=E7=9B=AE=E4=B8=8B?= =?UTF-8?q?=E7=9A=84fork=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/special_commit.rake | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/tasks/special_commit.rake b/lib/tasks/special_commit.rake index 4d5e04f7a..922c51cfe 100644 --- a/lib/tasks/special_commit.rake +++ b/lib/tasks/special_commit.rake @@ -23,15 +23,16 @@ namespace :special_commit do next if sub_owner.nil? || sub_project.nil? sub_commit_list_result = $gitea_client.get_repos_commits_by_owner_repo(sub_project_owner_login, sub_project_identifier) total_commits += sub_commit_list_result[:total_data].to_i + puts "====Sync Count Project Submodule forkproject Commit====" + sub_project.forked_projects.each do |p| + forked_project_owner_login = p.owner&.login + forked_project_identifier = p.identifier + next if forked_project_owner_login.nil? || forked_project_owner_login.nil? + forked_commit_list_result = $gitea_client.get_repos_commits_by_owner_repo(forked_project_owner_login, forked_project_identifier) + total_commits += forked_commit_list_result[:total_data].to_i + end end - puts "====Sync Count Project forkproject Commit====" - project.forked_projects.each do |p| - forked_project_owner_login = p.owner&.login - forked_project_identifier = p.identifier - next if forked_project_owner_login.nil? || forked_project_owner_login.nil? - forked_commit_list_result = $gitea_client.get_repos_commits_by_owner_repo(forked_project_owner_login, forked_project_identifier) - total_commits += forked_commit_list_result[:total_data].to_i - end + puts "====Write total commits to cache====" $redis_cache.set("ProjectSpecialCommit:#{project.id}", total_commits) $redis_cache.expireat("ProjectSpecialCommit:#{project.id}", (Date.today+30.days).to_time.to_i) From 511cbf45655df614dd9c3c0e4328413347108266 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 23 Mar 2023 10:00:14 +0800 Subject: [PATCH 209/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=89=A7?= =?UTF-8?q?=E8=A1=8Crake=E4=BB=BB=E5=8A=A1=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/special_commit.rake | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/tasks/special_commit.rake b/lib/tasks/special_commit.rake index 922c51cfe..ab6c63767 100644 --- a/lib/tasks/special_commit.rake +++ b/lib/tasks/special_commit.rake @@ -1,5 +1,8 @@ +# 执行示例 bundle exec rake "special_commit:load[yystopf, pig]" +# RAILS_ENV=production bundle exec rake "special_commit:load[yystopf, pig]" +# namespace :special_commit do - desc "batch_add_issues" + desc "Sync Special Commit to Cache" task :load, [:login, :identifier] => :environment do |t, args| owner = Owner.find_by(login: args.login) project = Project.find_by(user_id: owner&.id, identifier: args.identifier) From b127323589f06f7d3ad17e5939583fa3cab93fca Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 23 Mar 2023 10:41:52 +0800 Subject: [PATCH 210/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=85=B3?= =?UTF-8?q?=E6=B3=A8=E3=80=81=E7=82=B9=E8=B5=9E=E3=80=81fork=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=9B=B4=E6=96=B0=E6=97=B6=E9=97=B4=EF=BC=8C=E4=BB=A5?= =?UTF-8?q?=E5=8F=8Aissue=E5=88=97=E8=A1=A8=E8=BF=94=E5=9B=9E=E9=87=8C?= =?UTF-8?q?=E7=A8=8B=E7=A2=91ID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/fork_user.rb | 2 ++ app/models/praise_tread.rb | 2 ++ app/models/watcher.rb | 2 ++ app/views/api/v1/issues/_simple_detail.json.jbuilder | 1 + 4 files changed, 7 insertions(+) diff --git a/app/models/fork_user.rb b/app/models/fork_user.rb index 2d74af4a4..92040ad13 100644 --- a/app/models/fork_user.rb +++ b/app/models/fork_user.rb @@ -25,10 +25,12 @@ class ForkUser < ApplicationRecord def incre_project_common CacheAsyncSetJob.perform_later("project_common_service", {forks: 1}, self.project_id) + self.project.update_column(:updated_on, Time.now) end def decre_project_common CacheAsyncSetJob.perform_later("project_common_service", {forks: -1}, self.project_id) + self.project.update_column(:updated_on, Time.now) end def incre_user_statistic diff --git a/app/models/praise_tread.rb b/app/models/praise_tread.rb index 5d4ae0d80..0250f012e 100644 --- a/app/models/praise_tread.rb +++ b/app/models/praise_tread.rb @@ -26,10 +26,12 @@ class PraiseTread < ApplicationRecord def incre_project_common CacheAsyncSetJob.perform_later("project_common_service", {praises: 1}, self.praise_tread_object_id) if self.praise_tread_object_type == "Project" + self.praise_tread_object.update_column(:updated_on, Time.now) if self.praise_tread_object_type == "Project" end def decre_project_common CacheAsyncSetJob.perform_later("project_common_service", {praises: -1}, self.praise_tread_object_id) if self.praise_tread_object_type == "Project" + self.praise_tread_object.update_column(:updated_on, Time.now) if self.praise_tread_object_type == "Project" end def incre_user_statistic diff --git a/app/models/watcher.rb b/app/models/watcher.rb index 5a2cd96fb..f9d646ca9 100644 --- a/app/models/watcher.rb +++ b/app/models/watcher.rb @@ -28,10 +28,12 @@ class Watcher < ApplicationRecord def incre_project_common CacheAsyncSetJob.perform_later("project_common_service", {watchers: 1}, self.watchable_id) if self.watchable_type == "Project" + self.watchable.update_column(:updated_on, Time.now) if self.watchable_type == "Project" end def decre_project_common CacheAsyncSetJob.perform_later("project_common_service", {watchers: -1}, self.watchable_id) if self.watchable_type == "Project" + self.watchable.update_column(:updated_on, Time.now) if self.watchable_type == "Project" end def incre_user_statistic diff --git a/app/views/api/v1/issues/_simple_detail.json.jbuilder b/app/views/api/v1/issues/_simple_detail.json.jbuilder index 7e0d6b11f..e5a1a2cdc 100644 --- a/app/views/api/v1/issues/_simple_detail.json.jbuilder +++ b/app/views/api/v1/issues/_simple_detail.json.jbuilder @@ -7,6 +7,7 @@ end json.status_name issue.issue_status&.name json.priority_name issue.priority&.name json.milestone_name issue.version&.name +json.milestone_id issue.fixed_version_id json.author do if issue.user.present? json.partial! "api/v1/users/simple_user", locals: {user: issue.user} From 7fe204056d554ce2f8684db1eed748ead6061ba6 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 23 Mar 2023 11:59:08 +0800 Subject: [PATCH 211/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Aforks?= =?UTF-8?q?=E7=89=B9=E6=AE=8A=E6=98=BE=E7=A4=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 8 +++++++- app/views/repositories/detail.json.jbuilder | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 7ac3984db..24bc937de 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -22,6 +22,12 @@ class RepositoriesController < ApplicationController def detail @user = current_user @result = Repositories::DetailService.call(@owner, @repository, @user) + cache_total_forks = $redis_cache.get("ProjectSpecialForks:#{@project.id}") + if cache_total_forks.present? + @project_forked_count = @project.forked_count.to_i + else + @project_forked_count = cache_total_forks.to_i + end @project_fork_id = @project.try(:forked_from_project_id) if @project_fork_id.present? @fork_project = Project.find_by(id: @project_fork_id) @@ -322,7 +328,7 @@ class RepositoriesController < ApplicationController def get_latest_commit latest_commit = @project.educoder? ? nil : project_commits @latest_commit = latest_commit.present? ? latest_commit[:body][0] : nil - cache_total_commits = $redis_cache.get("ProjectSpecialCommit:#{project.id}") + cache_total_commits = $redis_cache.get("ProjectSpecialCommit:#{@project.id}") if cache_total_commits.present? @commits_count = cache_total_commits.to_i else diff --git a/app/views/repositories/detail.json.jbuilder b/app/views/repositories/detail.json.jbuilder index 508d4c658..2498379da 100644 --- a/app/views/repositories/detail.json.jbuilder +++ b/app/views/repositories/detail.json.jbuilder @@ -11,7 +11,7 @@ json.issues_count @project.issues.issue_issue.size - @project.issues.issue_issue json.pull_requests_count @project.pull_requests.opening.size json.project_identifier render_identifier(@project) json.praises_count @project.praises_count.to_i -json.forked_count @project.forked_count.to_i +json.forked_count @project_forked_count.to_i json.watchers_count @project.watchers_count.to_i json.versions_count @project.versions.opening.size #里程碑数量 json.version_releases_count @project.releases_size(@user.try(:id), "all") From c891fcf83680047853c5ac89ba0d357ec31f2dc9 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 23 Mar 2023 12:01:09 +0800 Subject: [PATCH 212/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Aforks?= =?UTF-8?q?=E7=89=B9=E6=AE=8A=E6=98=BE=E7=A4=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 24bc937de..1d98b17f4 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -24,9 +24,9 @@ class RepositoriesController < ApplicationController @result = Repositories::DetailService.call(@owner, @repository, @user) cache_total_forks = $redis_cache.get("ProjectSpecialForks:#{@project.id}") if cache_total_forks.present? - @project_forked_count = @project.forked_count.to_i - else @project_forked_count = cache_total_forks.to_i + else + @project_forked_count = @project.forked_count.to_i end @project_fork_id = @project.try(:forked_from_project_id) if @project_fork_id.present? From 4952373655cedd7bbd33cdcb0bb7911cfc548a9d Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 22 Mar 2023 18:05:45 +0800 Subject: [PATCH 213/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=9B=BA?= =?UTF-8?q?=E5=AE=9A=E6=95=B0=E6=8D=AE=E6=B8=85=E6=B4=97=E5=8F=8A=E8=8E=B7?= =?UTF-8?q?=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/concerns/watchable.rb | 19 + app/models/project.rb | 28 + .../repositories/_contributor.json.jbuilder | 8 +- lib/tasks/sync_mindspore_contributors.rake | 54 + public/mindspore_authors | 1151 +++++++++++++++++ 5 files changed, 1259 insertions(+), 1 deletion(-) create mode 100644 lib/tasks/sync_mindspore_contributors.rake create mode 100644 public/mindspore_authors diff --git a/app/models/concerns/watchable.rb b/app/models/concerns/watchable.rb index dc2b67f67..3ca9f04e3 100644 --- a/app/models/concerns/watchable.rb +++ b/app/models/concerns/watchable.rb @@ -31,6 +31,25 @@ module Watchable following.size end + def mindspore_contribution_perc(project) + @project = project + @user = self + + def cal_perc(count_user, count_all) + (count_user * 1.0 / (count_all + 0.000000001)).round(5) + end + + if @project['use_blockchain'] == true or @project['use_blockchain'] == 1 + balance_user = Blockchain::BalanceQueryOneProject.call({"user_id": @user.id, "project_id": @project.id}) + balance_all = Blockchain::RepoBasicInfo.call({"project_id": @project.id})["cur_supply"] + score = cal_perc(balance_user, balance_all) + else + commits_all = Project.mindspore_contributors.map{|i| i['contributions']}.sum + commit_user = Project.mindspore_contributors.select{|i| i['login'] == @user.login}.map{|i| i['contributions']}.sum + score = cal_perc(commit_user, commits_all) + end + end + def contribution_perc(project) @project = project @user = self diff --git a/app/models/project.rb b/app/models/project.rb index 54d6ac520..fc0828307 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -438,4 +438,32 @@ class Project < ApplicationRecord def del_project_issue_cache_delete_count $redis_cache.hdel("issue_cache_delete_count", self.id) end + + def self.mindspore_contributors + cache_result = $redis_cache.get("ProjectMindsporeContributors") + if cache_result.nil? + contributors = [] + file = File.open('public/mindspore_authors', 'r') + file.each_line do |l| + itemArray = l.gsub("\r\n", "").split("|:|") + email = itemArray[0] + username = itemArray[1] + commits = itemArray[2].to_i + if username =~ CustomRegexp::LOGIN && email =~ CustomRegexp::EMAIL + user = User.find_by(login: username, mail: email) + else + user = User.find_by(mail: email) unless username =~ CustomRegexp::LOGIN + user = User.find_by(login: username) unless email =~ CustomRegexp::EMAIL + end + contributors << {contributions: commits, name: username, login: username, email: email, id: user&.id}.stringify_keys + end + file.close + + $redis_cache.set("ProjectMindsporeContributors", contributors.to_json) + + return contributors + else + return JSON.parse(cache_result) + end + end end diff --git a/app/views/repositories/_contributor.json.jbuilder b/app/views/repositories/_contributor.json.jbuilder index bd1a037f7..b607f070a 100644 --- a/app/views/repositories/_contributor.json.jbuilder +++ b/app/views/repositories/_contributor.json.jbuilder @@ -14,5 +14,11 @@ 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) if db_user.present? + if db_user.present? + if @project&.id == 1428586 + json.contribution_perc db_user.mindspore_contribution_perc(project) + else + json.contribution_perc db_user.contribution_perc(project) + end + end end diff --git a/lib/tasks/sync_mindspore_contributors.rake b/lib/tasks/sync_mindspore_contributors.rake new file mode 100644 index 000000000..c2b55e7d4 --- /dev/null +++ b/lib/tasks/sync_mindspore_contributors.rake @@ -0,0 +1,54 @@ +desc "mindspore项目贡献者数据" + +# 同步mindspre贡献者数据至用户表 + +namespace :sync_mindspore do + desc "同步用户信息" + task contributor_to_user: :environment do + i = 1 + fail_users = [] + file = File.open('public/mindspore_authors', 'r') + file.each_line do |l| + itemArray = l.gsub("\r\n", "").split("|:|") + email = itemArray[0] + username = itemArray[1] + password = '12345678' + puts "=======Generate:[#{i}] Username: #{username}, Password: #{password}, Email: #{email}=======" + puts "=======Create User Begin====== " + + user = User.new(admin: false, login: username, mail: email, type: "User", is_test: 1) + user.password = password + user.platform = 'forge' + user.activate + + unless user.valid? + puts "=======Create User Fail!====== " + fail_users << [username, email] + next + end + + interactor = Gitea::RegisterInteractor.call({username: username, email: email, password: password}) + if interactor.success? + gitea_user = interactor.result + result = Gitea::User::GenerateTokenService.call(username, password) + user.gitea_token = result['sha1'] + user.gitea_uid = gitea_user[:body]['id'] + if user.save! + UserExtension.create!(user_id: user.id) + end + end + + i += 1 + puts "=======Create User End====== " + end + + puts "=======Fail Users:#{fail_users}====== " + + file.close + end + + desc "初始化区块链项目" + task init_project_blockchain: :environment do + + end +end diff --git a/public/mindspore_authors b/public/mindspore_authors new file mode 100644 index 000000000..28fc3ec73 --- /dev/null +++ b/public/mindspore_authors @@ -0,0 +1,1151 @@ +huawei_ci_bot@163.com|:|i-robot|:|19054 +314202276@qq.com|:|mindspore-ci-bot|:|10784 +mindspore_ci@huawei.com|:|mindspore-ci-bot|:|961 +tommylike@qq.com|:|mindspore-ci-bot|:|420 +zhoupeichen@huawei.com|:|ZPaC|:|386 +zhoufeng54@huawei.com|:|zhoufeng|:|352 +limingqi@huawei.com|:|limingqi107|:|325 +caifubi1@huawei.com|:|jojobugfree|:|317 +wangrui178@huawei.com|:|Margaret_wangrui|:|310 +limengyuan4@huawei.com|:|mengyuanli|:|310 +yefeng24@huawei.com|:|yefeng|:|303 +sunsuodong@huawei.com|:|sunsuodong|:|301 +yanghaoran2@huawei.com|:|yanghaoran|:|292 +yeyunpeng1@huawei.com|:|yeyunpeng|:|289 +xuanyue@huawei.com|:|xuanyue|:|277 +lianliguang@huawei.com|:|lianliguang|:|275 +lizhenyu13@huawei.com|:|lizhenyu|:|266 +zhujingxuan@huawei.com|:|zhujingxuan|:|247 +yangruoqi@huawei.com|:|yangruoqi713|:|242 +huanghui44@huawei.com|:|huanghui|:|238 +zhaozhenlong1@huawei.com|:|zhaozhenlong|:|236 +luoyang42@huawei.com|:|Yang|:|233 +zhuzhongrui1@huawei.com|:|z00512249|:|233 +liangzhibo@huawei.com|:|l00591931|:|232 +yuchaojie1@huawei.com|:|yuchaojie|:|230 +wangkaisheng2@huawei.com|:|kswang|:|226 +changzherui1@huawei.com|:|changzherui|:|225 +chenweifeng720@huawei.com|:|wilfChen|:|224 +lingqiaomin@huawei.com|:|ling|:|223 +yujianfeng5@huawei.com|:|GinFung|:|220 +liubuyu1@huawei.com|:|liubuyu|:|218 +shiliang10@huawei.com|:|VectorSL|:|216 +yuhan24@h-partners.com|:|yu-han39|:|214 +yaoyifan1@huawei.com|:|yao_yf|:|211 +gaoyong10@huawei.com|:|gaoyong10|:|210 +changpan_yin@163.com|:|greatpanc|:|209 +wangshaocong1@huawei.com|:|wsc|:|204 +zhangqinghua3@huawei.com|:|Zhang_Qinghua|:|194 +guozhijian@huawei.com|:|jonyguo|:|194 +hangangqiang2@huawei.com|:|hangangqiang|:|193 +xiefangqi2@huawei.com|:|xiefangqi|:|192 +jiaorui3@huawei.com|:|hwjiaorui|:|184 +laiyongqiang1@huawei.com|:|laiyongqiang|:|184 +lvliang18@huawei.com|:|lvliang|:|181 +jiangjianfei3@huawei.com|:|jjfeing|:|174 +huangbingjian1@huawei.com|:|HuangBingjian|:|174 +chendeshi@huawei.com|:|dayschan|:|170 +hewei@huawei.com|:|He_Wei|:|166 +chenfei52@huawei.com|:|chenfei|:|165 +huangxinjing@huawei.com|:|huangxinjing|:|162 +zhangjun0@huawei.com|:|zjun|:|158 +zengxianglong1@huawei.com|:|AGroupofProbiotocs|:|157 +baihuawei@huawei.com|:|baihuawei|:|154 +shenwei41@huawei.com|:|shenwei|:|153 +cathy.wong@huawei.com|:|cathwong|:|148 +zhangzhaoju@huawei.com|:|zhangzhaoju|:|148 +linqingke@huawei.com|:|linqingke|:|148 +zhangbuxue@huawei.com|:|buxue|:|144 +liuxiao93@huawei.com|:|liuxiao|:|144 +zongshuai1@huawei.com|:|zong_shuai|:|141 +liuzhongkai2@huawei.com|:|liuzhongkai2|:|139 +jpc.chen@huawei.com|:|chenjianping|:|138 +chujinjin52@huawei.com|:|chujinjin|:|136 +jianghui58@huawei.com|:|jianghui58|:|135 +liyong126@huawei.com|:|liyong|:|133 +xiaotianci1@huawei.com|:|Xiao_Tianci|:|129 +hezhenhao1@huawei.com|:|hezhenhao1|:|128 +lilinjie11@huawei.com|:|lilinjie|:|127 +wangnan39@huawei.com|:|wangnan39@huawei.com|:|126 +fanjibin@huawei.com|:|fan-ji-bin|:|124 +xuhui78@huawei.com|:|looop5|:|122 +yangzhenzhang@huawei.com|:|yangzhenzhang|:|121 +yuzhenhua.yuzhenhua@huawei.com|:|yuzhenhua|:|120 +chengang82@huawei.com|:|chengang|:|116 +jiaoyang25@huawei.com|:|Yang_Jiao|:|115 +zhangxiaoda@huawei.com|:|Xiaoda_Zhang|:|115 +zhaoting23@huawei.com|:|zhaoting|:|114 +dusijia@huawei.com|:|dusijia|:|113 +zhangyi267@huawei.com|:|zhangyi|:|111 +zhengjun10@huawei.com|:|zhengjun10|:|111 +tina.mengting.zhang@huawei.com|:|Tinazhang|:|110 +gongdaguo1@huawei.com|:|gongdaguo|:|107 +yanglinfeng2@huawei.com|:|yanglf1121|:|107 +h.farahat@huawei.com|:|hesham|:|106 +lingqiaomin@huawei.com|:|ling|:|106 +zhengyuanhua1@huawei.com|:|zhengyuanhua|:|104 +fuzhiye@huawei.com|:|fuzhiye|:|103 +panfengfeng@huawei.com|:|panfengfeng|:|102 +chenhaozhe1@huawei.com|:|chenhaozhe|:|102 +dinglinhe@huawei.com|:|dinglinhe|:|102 +lichen79@huawei.com|:|lichenever|:|101 +lilei120@huawei.com|:|lilei|:|101 +zengzitao@huawei.com|:|zengzitao|:|100 +zhousiyi@huawei.com|:|zhousiyi|:|99 +chendongsheng1@huawei.com|:|chendongsheng|:|99 +luoyuan7@huawei.com|:|luoyuan|:|96 +wangshuide@huawei.com|:|wangshuide2020|:|96 +tanghuikang@huawei.com|:|tanghuikang|:|95 +zhaodezan@huawei.com|:|zhaodezan|:|95 +zichun.ye@huawei.com|:|Zichun_Ye|:|94 +gongdaguo@huawei.com|:|gongdaguo|:|92 +peilin.wang@huawei.com|:|Peilin_Wang|:|92 +lvyufeng@cqu.edu.cn|:|lvyufeng|:|91 +chengjiahui@huawei.com|:|cjh9368|:|91 +peixu.ren1@huawei.com|:|peixu_ren|:|90 +fangzehua1@huawei.com|:|fangzehua|:|88 +zhaojichen1@huawei.com|:|zhaojichen|:|87 +liangzelang1@huawei.com|:|liangzelang|:|85 +fengyihang1@huawei.com|:|fengyihang|:|84 +jaclyn.huang@huawei.com|:|huangmengxi|:|84 +zhangxuetong@huawei.com|:|z00505269|:|84 +jiangjinsheng@huawei.com|:|jiangjinsheng|:|83 +liuxu72@huawei.com|:|Liu_Xuu|:|82 +xulei201@huawei.com|:|xulei|:|81 +chenzomi12@gmail.com|:|chenzomi|:|81 +zhangzhaochuang@huawei.com|:|Tron_Zhang|:|80 +qiuzhongya@huawei.com|:|qiuzhongya|:|80 +yanghaitao1@huawei.com|:|yanghaitao|:|80 +yiren19920727@163.com|:|buxue|:|80 +zhanghao491@huawei.com|:|hw_hz|:|77 +chenzupeng@huawei.com|:|chenzupeng|:|77 +wangyucheng12@huawei.com|:|reku1997|:|76 +hanhuifeng1@huawei.com|:|hanhuifeng2020|:|76 +yanpanhui@huawei.com|:|ms_yan|:|76 +eric.zhang1@huawei.com|:|eric|:|76 +liuyongqi5@huawei.com|:|liu-yongqi-63|:|74 +albert.liyan@huawei.com|:|albert.liyan@huawei.com|:|74 +liqiliang1@huawei.com|:|liqiliang|:|74 +xiongkun5@huawei.com|:|xiongkun|:|73 +liuluobin@huawei.com|:|liuluobin|:|73 +wanyiming@huawei.com|:|wanyiming|:|73 +wandongdong1@huawei.com|:|wandongdong|:|73 +2713219276@qq.com|:|guohongzilong|:|73 +maning36@huawei.com|:|maning202007|:|72 +chenlei154@huawei.com|:|chenlei_autodiff|:|72 +xiaruijie@huawei.com|:|r1chardf1d0|:|71 +xumengjuan1@huawei.com|:|xumengjuan1|:|71 +parastoo.ashtari@huawei.com|:|Parastoo_Ashtari|:|71 +yanzhenxiang@huawei.com|:|yanzhenxiang2020|:|70 +liuyu195@huawei.com|:|yvetteliu|:|69 +xutianchun@huawei.com|:|xutianchun|:|69 +huoxinyou1@huawei.com|:|huoxinyou|:|68 +liutongtong9@huawei.com|:|liutongtong|:|68 +lanzhineng@huawei.com|:|lanzhineng|:|68 +1814619459@qq.com|:|zhanghuiyao|:|67 +6576637+ms_yan@user.noreply.gitee.com|:|ms_yan|:|67 +dingpeifei1@huawei.com|:|d00455729|:|66 +fary.fanrui@huawei.com|:|fary86|:|66 +jiangzhenguang1@huawei.com|:|jiangzhenguang|:|65 +zhouyaqiang2@huawei.com|:|unknown|:|65 +zirui.wu@huawei.com|:|Zirui_Wu|:|64 +wukesong1@huawei.com|:|wukesong|:|63 +yeyunpeng2020@huawei.com|:|yeyunpeng|:|63 +xuyongfei@huawei.com|:|xuyongfei|:|62 +wangrao1@huawei.com|:|wangrao|:|62 +liuyang655@huawei.com|:|liuyang_655|:|62 +jinxiulang@huawei.com|:|jin-xiulang|:|61 +junsongshao@163.com|:|shaojunsong|:|61 +gongziyan1@huawei.com|:|Ziyan|:|60 +jinyaohui@huawei.com|:|jinyaohui|:|60 +weiluning@huawei.com|:|Wei_Luning|:|60 +yiyanzhi@huawei.com|:|yiyanzhi_akane|:|59 +ckey.chengbin@huawei.com|:|ckey_Dou|:|59 +lixia.chen@huawei.com|:|Lixia_Chen|:|59 +liuwenhao4@huawei.com|:|liuwenhao4|:|59 +liulili715@huawei.com|:|liu_lili|:|58 +zhanyuan1@huawei.com|:|zhanyuan|:|58 +huchunmei1@huawei.com|:|huchunmei|:|57 +gengdongjie@huawei.com|:|gengdongjie|:|56 +wangmin106@huawei.com|:|wangmin|:|56 +yihuaijie@huawei.com|:|Yi_Huaijie|:|56 +liuchuting1@huawei.com|:|liuchuting|:|55 +chenzhuo42@huawei.com|:|chenzhuo|:|55 +wudengsong@huawei.com|:|Simson|:|55 +panzhihui3@huawei.com|:|panzhihui|:|54 +zhupuxu@huawei.com|:|zhupuxu|:|54 +yangjie159@huawei.com|:|yangjie159|:|54 +shuo.jia@huawei.com|:|TFbunny|:|54 +yangshuo22@huawei.com|:|y00451588|:|53 +wangyanling10@huawei.com|:|wangyanling|:|53 +pengyongrong@huawei.com|:|pengyongrong|:|52 +wangyan250@huawei.com|:|wYann|:|51 +zhangfanghe1@huawei.com|:|zhangfanghe|:|51 +xun.deng@huawei.com|:|Xun_Deng|:|51 +dengyepeng@huawei.com|:|Erpim|:|50 +zhengzuohe@huawei.com|:|zhengzuohe|:|50 +zuochuanyong@huawei.com|:|zuochuanyong|:|50 +lihongkang1@huawei.com|:|lihongkang|:|50 +xulei83@huawei.com|:|xulei2020|:|50 +qianjiahong@huawei.com|:|q00596439|:|49 +wangjun289@huawei.com|:|alouhahaha|:|49 +ougongchang@huawei.com|:|ougongchang|:|49 +lichentrue@163.com|:|lichenever|:|49 +zangqingxiang@huawei.com|:|zang-qing-xiang|:|48 +tacyi@139.com|:|tacyi139|:|48 +hujiahui8@huawei.com|:|hujiahui8|:|47 +shixinyu1@huawei.com|:|Henry_Shi|:|47 +jesse.lee@huawei.com|:|Jesse_Lee|:|47 +zhangyongxian@huawei.com|:|zhang-yong-xian|:|46 +amir.lashkari1@huawei.com|:|Amir_Lashkari|:|46 +zhouchao46@huawei.com|:|zhou_chao1993|:|45 +chenying113@huawei.com|:|yingchen|:|45 +lixian16@huawei.com|:|lixian|:|45 +wangzhe128@huawei.com|:|wangzhe|:|45 +zhuyuxiao@huawei.com|:|zhuyuxiao|:|44 +zhangxiaoxiao16@huawei.com|:|zhangxiaoxiao16|:|44 +zhouyuanshen@huawei.com|:|zhouyuanshen|:|44 +tanweicheng@huawei.com|:|twc|:|43 +john.tzanakakis@huawei.com|:|John_Tzanakakis|:|43 +zhouneng2@huawei.com|:|zhouneng|:|43 +wuxuejian1@huawei.com|:|wuxuejian|:|43 +jonathan.yan1@huawei.com|:|Jonathan_Yan|:|43 +qiuyunlei@huawei.com|:|yoonlee666|:|43 +fandawei2@huawei.com|:|fandawei|:|42 +wangchangheng1@huawei.com|:|wangchangheng|:|42 +guozhaohong@huawei.com|:|gzhcv|:|42 +chefei52@huawei.com|:|chenfei|:|42 +lijiaqi0612@163.com|:|Jiaqi|:|42 +danish.farid@huawei.com|:|Danish_Farid|:|42 +526422051@qq.com|:|simson|:|42 +lvmingfu@huawei.com|:|lvmingfu|:|41 +wangdongxu6@huawei.com|:|wang-dong-xu|:|41 +shuojia@huawei.com|:|TFbunny|:|41 +zhaoyingzhuo2@huawei.com|:|zhaoyingzhuo|:|40 +liuzhidan5@huawei.com|:|ZhidanLiu|:|40 +wuweikang@huawei.com|:|wuweikang|:|40 +lizheng53@huawei.com|:|lz|:|40 +emir.haleva@huawei.com|:|Emir_Haleva|:|40 +7511764+wangshuide2020@user.noreply.gitee.com|:|wangshuide2020|:|40 +285824651@qq.com|:|yangzhenzhang|:|40 +3174348550@qq.com|:|huanxiaoling|:|39 +yoni.baehr@huawei.com|:|yoni_baehr|:|39 +liujiabin5@huawei.com|:|louei5|:|39 +anzhengqi@huawei.com|:|anzhengqi|:|39 +wangyide10@huawei.com|:|yide12|:|38 +adam.xiaoyao@huawei.com|:|xiao_yao1994|:|38 +chengxianbin@huawei.com|:|chengxianbin|:|38 +chenweitao4@huawei.com|:|chenweitao_295|:|38 +jiangzhiwen8@huawei.com|:|jiangzhiwen|:|38 +panyifeng@huawei.com|:|panyifeng|:|38 +shaojunsong@huawei.com|:|shaojunsong|:|37 +2823612538@qq.com|:|duzhixing|:|37 +949144093@qq.com|:|fengyihang|:|37 +lilingyun4@huawei.com|:|lingyunli63|:|37 +huangdongrun@huawei.com|:|huangdongrun|:|37 +huangchengnuo1@huawei.com|:|huangchengnuo|:|36 +wutiancheng@huawei.com|:|w00517672|:|36 +liuchao195@huawei.com|:|Corleone|:|36 +1196608768@qq.com|:|taipingchangan|:|36 +tom.chen1@huawei.com|:|tom__chen|:|36 +zhangxinfeng3@huawei.com|:|zhangxinfeng3|:|36 +caojian5@huawei.com|:|CaoJian|:|36 +wangqiuliang@huawei.com|:|kingfo|:|36 +zhangzhongpeng1@huawei.com|:|z00478463|:|35 +zhangyanhui17@huawei.com|:|zhangyanhui|:|34 +zhaizhiqiang@huawei.com|:|zhaizhiqiang|:|34 +gaojing22@huawei.com|:|gaojing|:|34 +caojian5@huawei.com|:|caojian05|:|34 +zhangdong37@huawei.com|:|zhangdong|:|33 +chenyijie6@huawei.com|:|chenyijie6|:|33 +jiangshuqiang1@huawei.com|:|jiangshuqiang|:|33 +shenjx161212@gmail.com|:|shen_jingxing|:|33 +zhangyihui7@huawei.com|:|zhangyihui|:|33 +zhaosida2@huawei.com|:|zhaosida|:|33 +lizhenglong2@huawei.com|:|lizhenglong|:|33 +760161589@qq.com|:|chang_zherui|:|33 +luojianing1@huawei.com|:|luojianing|:|32 +qinzheng4@huawei.com|:|qinzheng|:|32 +zhoushan7@huawei.com|:|zhoushan|:|32 +877518222@qq.com|:|w30006229|:|32 +mahdi.rahmani.hanzaki@huawei.com|:|Mahdi|:|32 +hubin79@huawei.com|:|hbhu_bin|:|31 +hedongdong@huawei.com|:|hedongdong|:|31 +18865382565@163.com|:|zheng_pengfei|:|31 +yelihua2@huawei.com|:|yelihua|:|31 +huangbo77@huawei.com|:|huangbo77|:|31 +lvchangquan@huawei.com|:|lvchangquan|:|31 +caozhou1@huawei.com|:|caozhou|:|31 +yangsijia2@huawei.com|:|dabaiji|:|30 +andy.wangrui@huawei.com|:|andy_wangrui|:|30 +hukang22@huawei.com|:|hukang_hwx963878|:|30 +luopengting@huawei.com|:|luopengting|:|30 +libokai@huawei.com|:|libokai|:|29 +wangchenghao14@huawei.com|:|cheng-hao-wang|:|29 +shibeiji@huawei.com|:|shibeiji|:|29 +leon.wanghui@huawei.com|:|leonwanghui|:|29 +anzhengqi@huawei.com|:|anzhengqi|:|29 +yankai10@huawei.com|:|y00445136|:|29 +cjh9368@163.com|:|cjh9368|:|29 +zhangyinxia@huawei.com|:|zhangyinxia|:|28 +xupan25@huawei.com|:|xupan|:|28 +417994009@qq.com|:|chenx2ovo|:|28 +yepei6@huawei.com|:|yepei6|:|28 +lihongzhang1@huawei.com|:|li-hong-zhang|:|28 +wuyongkang7@huawei.com|:|Kang|:|28 +caikairui@huawei.com|:|nomindcarry|:|27 +caojiewen@huawei.com|:|caojiewen|:|27 +mohammad.motallebi@huawei.com|:|mohammad|:|27 +zetong.zhao@huawei.com|:|zetongzhao|:|27 +maijianqiang1@huawei.com|:|maijianqiang|:|27 +xxq250@qq.com|:|xxq250|:|26 +wangpingan2@huawei.com|:|wangpingan2|:|26 +bichaoyang@huawei.com|:|b00518648|:|26 +wangtongyu6@huawei.com|:|TonyWang222|:|26 +2597798649@qq.com|:|zx|:|26 +wengbingya@huawei.com|:|bingyaweng|:|26 +payneye93@gmail.com|:|Payne|:|26 +zhangzheng44@huawei.com|:|zhangz0911gm|:|26 +qujianwei@huawei.com|:|qujianwei|:|25 +lianghao23@huawei.com|:|lianghao|:|25 +hexia15@huawei.com|:|hexia|:|25 +wangchangkai@huawei.com|:|kai00|:|25 +naireen.hussain@huawei.com|:|nhussain|:|25 +179220644@qq.com|:|lixian|:|25 +fanzhedong1@huawei.com|:|sjtujayyyy|:|24 +xiong.gao@huawei.com|:|Gaoxiong|:|24 +liangcanli@huawei.com|:|Liangcan-Li|:|24 +huangxiaopeng2@huawei.com|:|muxiyin|:|24 +heleiwang@huawei.com|:|heleiwang|:|24 +baiyangfan@huawei.com|:|baiyangfan|:|24 +liyiqi5@huawei.com|:|liyiqi|:|23 +ligan15@huawei.com|:|ligan|:|23 +chenmai@huawei.com|:|chen-mai|:|23 +liangchenghui@huawei.com|:|liangchenghui|:|23 +wanghua36@huawei.com|:|wanghua|:|23 +maoyaomin4@huawei.com|:|maoyaomin|:|22 +g13827276024@163.com|:|gaoshuanglong|:|22 +david.anugraha@huawei.com|:|David|:|22 +chenyu289@huawei.com|:|CHEN_YU|:|22 +yangwei79@huawei.com|:|weiyang|:|22 +song.yuanwei@huawei.com|:|songyuanwei|:|22 +sabrina.sun1@huawei.com|:|sabrinasun|:|22 +gaozeyang1@huawei.com|:|ZeyangGAO|:|22 +zhangshanshan15@huawei.com|:|zhang__sss|:|22 +daisurong@mail.nankai.edu.cn|:|Dai_Surong|:|22 +zhengbin25@huawei.com|:|zhengbin|:|22 +harshvardhan.gupta@huawei.com|:|Harshvardhan_Gupta|:|22 +yue.yu1@huawei.com|:|alex-yuyue|:|22 +6517937+tronzhang@user.noreply.gitee.com|:|tronzhang|:|22 +pengyanjun1@huawei.com|:|Yanjun_Peng|:|22 +gukecai@huawei.com|:|gukecai|:|22 +qianlong3@huawei.com|:|qianlong|:|22 +meixiaowei1@huawei.com|:|meixiaowei|:|22 +wenkai8@huawei.com|:|wenkai|:|21 +harshvardhan.gupta1@huawei.com|:|Harshvardhan_Gupta|:|21 +zhanghaibo5@huawei.com|:|zhanghaibo5@huawei.com|:|21 +xulei83@huawei.com|:|xulei2020|:|21 +liuxiao78@huawei.com|:|_liuxiao_|:|21 +liujunzhu@huawei.com|:|liujunzhu|:|20 +1228862915@qq.com|:|zhangyuqwer|:|20 +2460204039@qq.com|:|wang-chao|:|20 +lixiaohui33@huawei.com|:|lixiaohui|:|20 +taoyunhao@huawei.com|:|tao_yunhao|:|20 +hongxingwang@huawei.com|:|hongxing|:|20 +dengwentao1@huawei.com|:|dengwentao|:|20 +tangcong9@huawei.com|:|emmmmtang|:|19 +nizzan.kimhi@huawei.com|:|nizzan|:|19 +2111082400@nbu.edu.cn|:|NBUFabio|:|19 +baiyouhui@huawei.com|:|Bert0108|:|19 +wuwenbing@huawei.com|:|wuwenbing|:|19 +wangcong64@huawei.com|:|wangcong|:|19 +wuyichao4@huawei.com|:|xiaoyisd|:|19 +kuangbowen@huawei.com|:|BowenK|:|19 +chentingting13@huawei.com|:|c00425699|:|19 +yangyongjie@7huawei.com|:|yangyongjie|:|19 +youshu1@huawei.com|:|youshu|:|18 +zhuguodong0001@163.com|:|Zhu_Guodong|:|18 +gaopan44@huawei.com|:|gaopan12|:|18 +wangwenzhe7@huawei.com|:|wangwenzhe|:|18 +guoqi5@huawei.com|:|guoqi|:|18 +haoranwang950211@gmail.com|:|haoran.wang|:|18 +liuhe39@huawei.com|:|liuhe|:|18 +zhanke2@huawei.com|:|zhanke|:|18 +xuyongfei@huawei.com|:|xuyongfei|:|18 +wenchunjiang@huawei.com|:|wenchunjiang|:|18 +t.cai@huawei.com|:|seatea|:|18 +yuhuijun1@huawei.com|:|wan-wan-mei-xiang-dao|:|18 +luochao60@huawei.com|:|luochao|:|17 +zhujiaxing2@huawei.com|:|z30020733|:|17 +liuchongming1@huawei.com|:|liuchongming74|:|17 +shenjingxing2@huawei.com|:|shen_jingxing|:|17 +13722989033@163.com|:|yide12|:|17 +lixiangyi1@huawei.com|:|l00486551|:|17 +danish.farid1@huawei.com|:|danishfarid|:|17 +markus.kunej@huawei.com|:|markuskunej|:|17 +peiwenfang@huawei.com|:|wenfangpei|:|17 +islam.amin@huawei.com|:|islam_amin|:|17 +yvette@huawei.com|:|yvette|:|17 +jiangzg@huawei.com|:|jzg|:|17 +dinghao7@huawei.com|:|dinghao|:|17 +zhanzhan1@huawei.com|:|zhanzhan1|:|16 +guozhibin4@huawei.com|:|GuoZhibin|:|16 +wujueying1@huawei.com|:|wujueying|:|16 +zhangqi92@huawei.com|:|zhangqi|:|16 +suteng@huawei.com|:|Su_Teng|:|16 +fujianzhao@huawei.com|:|fujianzhao|:|16 +jinjiali@huawei.com|:|jinjiali|:|16 +liangyongxiong1@huawei.com|:|liangyongxiong|:|16 +1240419984@qq.com|:|Fazzie|:|16 +wangshuangling1@huawei.com|:|sl_wang|:|16 +adel.shafiei@huawei.com|:|Adel_Shafiei|:|16 +robin.grosman@huawei.com|:|RobinGrosman|:|15 +mohammadh.shabestari@huawei.com|:|mohammad|:|15 +zhangshukun1@huawei.com|:|Shukun_Zhang|:|15 +zjbc123@sina.com|:|baochong|:|15 +xuqiang40@huawei.com|:|xuqiang|:|15 +fengyixing@huawei.com|:|fengyixing|:|15 +liyuanshuo123@yeah.net|:|liwenshi|:|15 +jinxiaoxian@huawei.com|:|kingxian|:|15 +nat.sutyanyong@huawei.com|:|Nat_Sutyanyong|:|15 +etone.chan@huawei.com|:|Etone.Chan|:|15 +tangdezhi5@huawei.com|:|tangdezhi_123|:|14 +panshaowu@huawei.com|:|panshaowu|:|14 +kathy.wangting@huawei.com|:|Ting_Wang|:|14 +xcnick0412@gmail.com|:|xcnick|:|14 +gongxiaoqing1@huawei.com|:|xsmq|:|14 +sheng.yang1@huawei.com|:|sheng|:|14 +kuangpeiyu@huawei.com|:|kpy|:|14 +huyingtong1@huawei.com|:|Yingtong_Hu|:|13 +zouliqin@huawei.com|:|zlq2020|:|13 +1696730989@qq.com|:|zhixinaa|:|13 +ivan.shan@huawei.com|:|Ivan_Shan|:|13 +zhouxulin2@huawei.com|:|zhouxulin2|:|13 +huandong1@huawei.com|:|huandong|:|13 +yuximiao@huawei.com|:|yuximiao|:|13 +nilc@qq.com|:|leilei_snow|:|13 +mengchunyang1@huawei.com|:|meng_chunyang|:|13 +alexey.shevlyakov@huawei.com|:|Alexey_Shevlyakov|:|13 +zhangshucheng@huawei.com|:|candanzg|:|13 +lvhaoyu@huawei.com|:|lvhaoyu|:|12 +chenping38@huawei.com|:|chenping38|:|12 +haim.moushkatel@huawei.com|:|Haim_Moushkatel|:|12 +maxinjun1@huawei.com|:|xinjun_ma|:|12 +lijiaqi36@huawei.com|:|jiaqi|:|12 +yizhi.zhang@huawei.com|:|ervinzhang|:|12 +songhonglei@huawei.com|:|songhonglei413|:|12 +hanjun12@huawei.com|:|hanjun996|:|12 +giancarlo.colmenares@huawei.com|:|Giancarlo_Colmenares|:|12 +leo.zhoupeng@huawei.com|:|leopz|:|12 +wangziqi4@huawei.com|:|wang_ziqi|:|11 +anzhengqi1@huawei.com|:|anzhengqi|:|11 +yangxixin@huawei.com|:|yangxixin|:|11 +xiubo@zju.edu.cn|:|liang_xiubo|:|11 +735291378@qq.com|:|lh735291378|:|11 +zhangyong76@huawei.com|:|zhangyong|:|11 +iambowen.m@gmail.com|:|Bowen_Ma|:|11 +sawyer0503@gmail.com|:|Sawyer|:|11 +xiaoyao37@hisilicon.com|:|xiao_yao1994|:|11 +liucunwei@huawei.com|:|LiuCunwei|:|11 +yuhang-guo@foxmail.com|:|despicablemme|:|11 +wangchengyuan1@huawei.com|:|smurf|:|11 +islam.amin1@huawei.com|:|Islam_Amin|:|11 +anancds@163.com|:|anancds|:|11 +li.chen7@huawei.com|:|lichen_101010|:|11 +hoai.linh.tran@huawei.com|:|Hoai_Linh_Tran_h00472437|:|11 +lirongzhen1@huawei.com|:|lirongzhen|:|11 +junhan.hu@huawei.com|:|Junhan_Hu|:|11 +lihongcheng7@huawei.com|:|OwenSec|:|10 +dingyahao@huawei.com|:|izayoi|:|10 +wangshengnan12@huawei.com|:|wangshengnan123|:|10 +892729609@qq.com|:|YouShengzhe|:|10 +284831332@qq.com|:|kyr|:|10 +907832527@qq.com|:|Carry955|:|10 +545702457@qq.com|:|jinzi|:|10 +niningxi@huawei.com|:|mamba_ni|:|10 +980773780@qq.com|:|liruoxuan|:|10 +zhunaipan@huawei.com|:|zhunaipan|:|10 +peter.nie@huawei.com|:|polyhedral|:|10 +xiaopeng.yang@huawei.com|:|dessyang|:|10 +ng.ngai.fai@huawei.com|:|unknown|:|10 +1599637730@qq.com|:|qrd|:|10 +liuliyan2@huawei.com|:|liuliyan2|:|10 +togepro@163.com|:|wang-ming-gui|:|10 +huangyong92@huawei.com|:|unknown|:|9 +lishanni@huawei.com|:|lishanni513|:|9 +2980708493@qq.com|:|bsx|:|9 +hemaohua@huawei.com|:|hemaohua|:|9 +2545940674@qq.com|:|bubtltk|:|9 +wangqilin13@huawei.com|:|KylinMoriarty|:|9 +6560244+majorzhang@user.noreply.gitee.com|:|zhangzhenghai|:|9 +liangzelang1@hisilicon.com|:|liangzelang|:|9 +252664817@qq.com|:|hukang|:|9 +jamie.nisbet@huawei.com|:|Jamie_Nisbet|:|9 +dinglongwei1@huawei.com|:|dinglongwei|:|9 +zhuangbairong@huawei.com|:|Bairong|:|9 +lijiaqi@lijiaqidemacbook-pro.local|:|li-jia-qi|:|9 +panbingao@huawei.com|:|panbingao|:|9 +hw.huangyong@huawei.com|:|rick_sanchez|:|9 +suxin12@huawei.com|:|suxin|:|8 +moran2@huawei.com|:|moran|:|8 +zhangdanyang5@huawei.com|:|Zhangdanyang|:|8 +2021202010045@whu.edu.cn|:|XinWang2021|:|8 +2421018748@qq.com|:|gui-ning-xin|:|8 +wangxiaoli@mail.xidian.edu.cn|:|wangxiaoli_xidian|:|8 +867461411@qq.com|:|tangyibo123|:|8 +lvzhangcheng@huawei.com|:|lvzhangcheng|:|8 +1114120549@qq.com|:|Super_Wzb|:|8 +1040772198@qq.com|:|li-qiyao|:|8 +1875622668@qq.com|:|Arielxyx|:|8 +582373673@qq.com|:|ffe|:|8 +jimmy.ji.qi@huawei.com|:|Jimmy_Qi|:|8 +xuxusheng2@huawei.com|:|donghufeng|:|8 +253233345@qq.com|:|Atlas_ymc|:|8 +zhoulili20@huawei.com|:|zhou_lili|:|8 +yangyuan24@huawei.com|:|yangyuan|:|8 +hebotao5@huawei.com|:|hebotao|:|8 +wanghui71leon@gmail.com|:|leonwanghui|:|8 +ava.khonsari@huawei.com|:|avakh|:|8 +anthony2@huawei.com|:|anthonyaje|:|8 +chris.cheng.hz@gmail.com|:|cristoval|:|8 +shijianning@huawei.com|:|shijianning|:|8 +leiyuanzhe@huawei.com|:|lei-yuanzhe|:|7 +liyuxia8@huawei.com|:|liyuxia|:|7 +1428597510@qq.com|:|xuqiang|:|7 +1683884853@qq.com|:|dong-xue-tang|:|7 +wenyuan_echo@whut.edu.cn|:|yuan|:|7 +15355477746@163.com|:|fakeen|:|7 +dengjian@uestc.edu.cn|:|deng_jian|:|7 +latrawy@163.com|:|latrawy|:|7 +wangjunbao@huawei.com|:|wangjunbao|:|7 +137954843@qq.com|:|AHHOZP|:|7 +lijiaxing36@huawei.com|:|lijiaxing1999|:|7 +kylin_su@qq.com|:|kylin_su|:|7 +xutianyu9@huawei.com|:|Tianyu_Xu|:|7 +mahequn1@huawei.com|:|mahequn123|:|7 +lovelychurch@163.com|:|wanyiming|:|7 +marui36@huawei.com|:|marui|:|7 +shyhot@outlook.com|:|jjj|:|7 +xuguoyang@huawei.com|:|xuguoyang|:|7 +zhengqihao@huawei.com|:|zhengqihao|:|7 +yuanwei66@huawei.com|:|yuanwei66|:|7 +wanganrui1@huawei.com|:|w00535372|:|7 +tony.liu2@huawei.com|:|tony_liu2|:|7 +zhongligeng@huawei.com|:|zhongligeng|:|7 +fangwenyi@huawei.com|:|fangwenyi|:|6 +chuhaotian2@huawei.com|:|htchu|:|6 +chenmengyun1@huawei.com|:|cmy_melody|:|6 +1240208775@qq.com|:|yangfn777|:|6 +hujing_hjhj@163.com|:|hj-ustb|:|6 +785342685@qq.com|:|Megalomania|:|6 +liuliu18@huawei.com|:|pkuliuliu|:|6 +1228766517@qq.com|:|jin_jiaqi|:|6 +jaspreet.singh.sambee@huawei.com|:|Jaspreet_Singh_Sambee|:|6 +davidfffan@foxmail.com|:|fandawei|:|6 +980689557@qq.com|:|fyxz|:|6 +wangchenghaonl@163.com|:|cheng-hao-wang|:|6 +1925784979@qq.com|:|shenyu|:|6 +liangpeng18@huawei.com|:|cononlly|:|6 +chaijun@huawei.com|:|chaijun|:|6 +wanhanyang@huawei.com|:|Wan_Hanyang|:|6 +a.malyshev@expasoft.tech|:|Alexander_Malyshev|:|6 +1462492739@qq.com|:|djc|:|6 +het.shah@huawei.com|:|hetshah|:|6 +751871760@qq.com|:|liannai|:|6 +1586875939@qq.com|:|wangkc123|:|6 +shenghong@huawei.com|:|shenghong96|:|6 +yexijoe@163.com|:|yexijoe|:|6 +miaoyanming@huawei.com|:|askmiao|:|6 +chenshushu@huawei.com|:|chenshushu|:|6 +yuyiyang@huawei.com|:|yuyiyang_3418|:|6 +zhiqwang@outlook.com|:|zhiqwang|:|6 +zhangyunshu@huawei.com|:|zhangyunshu|:|6 +yangchun32@huawei.com|:|yang_chun|:|6 +962978787@qq.com|:|jiangshuqiang|:|6 +yuhanshi53@outlook.com|:|YuhanShi53|:|6 +yizhizhang@huawei.com|:|ervinzhang|:|6 +xiaohan.zhang@huawei.com|:|shaw_zhang|:|5 +657155628@qq.com|:|han-ze-yu|:|5 +z9901999@163.com|:|zwy9901|:|5 +fangzhou12@huawei.com|:|fangzhou12|:|5 +971180567@qq.com|:|ymy_forever|:|5 +zhudongyao1@huawei.com|:|zhudongyao1|:|5 +lisonglin@isrc.iscas.ac.cn|:|libit|:|5 +254711247@qq.com|:|unknown|:|5 +1327981541@qq.com|:|ruili|:|5 +15715193189@139.com|:|koumengwang|:|5 +1157539822@qq.com|:|Seeker|:|5 +862986375@qq.com|:|hu-xinyu-1216|:|5 +939670472@qq.com|:|whitewings|:|5 +zhengweimin1@huawei.com|:|wmzheng2020|:|5 +6574854+jjfeing@user.noreply.gitee.com|:|jjfeing|:|5 +ckczzj@zju.edu.cn|:|ckczzj|:|5 +zhangzhewei1@huawei.com|:|zhangzhewei|:|5 +xutianming7@huawei.com|:|xutianming|:|5 +dangjiaqi1@huawei.com|:|_dangjiaqi1_|:|5 +zhany2020@outlook.com|:|zhangyi|:|5 +mayang20@huawei.com|:|mayang|:|5 +83028974@qq.com|:|mxm|:|5 +youjiangkun@huawei.com|:|geekun|:|5 +guansongsong@huawei.com|:|guansongsong|:|5 +6573942+dayschan@user.noreply.gitee.com|:|dayschan|:|5 +zhaozhiqiang4@huawei.com|:|biffex|:|5 +ch.l@huawei.com|:|Chong|:|5 +weibiao.yu@huawei.com|:|WeibiaoYu|:|5 +984778782@qq.com|:|wqx|:|4 +hujingsong4@huawei.com|:|xiuyu0000|:|4 +lizhihao43@huawei.com|:|ZhihaoLi|:|4 +yujialiang@huawei.com|:|yujialiang|:|4 +941347244@qq.com|:|Luoziyi|:|4 +yanlichuan@whu.edu.cn|:|yan-li-chuan|:|4 +yyds12306@163.com|:|panshinanyi|:|4 +2375923356@qq.com|:|arranclo|:|4 +spcbruea@stu.xjtu.edu.cn|:|gp121|:|4 +1465199518@qq.com|:|uccInf|:|4 +kdaqiu@163.com|:|qiukaida|:|4 +qingkun_fan@whu.edu.cn|:|fan-qing-kun|:|4 +iruizewu@163.com|:|wu-rui-ze|:|4 +2582767108@qq.com|:|LHP-learning|:|4 +fengxun5@huawei.com|:|fengxun705612|:|4 +ztt2476674520@163.com|:|ztt-whu|:|4 +danansheng1@163.com|:|danansheng|:|4 +zhaiyukun@huawei.com|:|ConnZhai|:|4 +xuegui@isrc.iscas.ac.cn|:|ZhengXuegui|:|4 +2831148979@qq.com|:|luqilin|:|4 +1204989437@qq.com|:|wu-jun-ze|:|4 +hanhuiyu@huawei.com|:|hanhuiyu1996|:|4 +2974874275@qq.com|:|bcc2974874275|:|4 +zoutianyu@whut.edu.cn|:|zoutianyu|:|4 +shenghong2@huawei.com|:|shenghong96|:|4 +mina.rafinazari@huawei.com|:|minara|:|4 +yufeiwang.work@outlook.com|:|Yufei_Wang|:|4 +1261354409@qq.com|:|minashi-tanaka|:|4 +44614525@qq.com|:|Victor_Chen|:|4 +1297030928@qq.com|:|administrator|:|4 +15234076020@163.com|:|vddong|:|4 +xiaoheihzr@163.com|:|han-zheng-rong|:|4 +2403644657@qq.com|:|lyl116|:|4 +1640329159@qq.com|:|Isaac|:|4 +pengtaox@std.uestc.edu.cn|:|pengtao|:|4 +764685090@qq.com|:|hanxiaoyu|:|4 +lyb961201@foxmail.com|:|robert_luo_yibo|:|4 +liyang266@huawei.com|:|liyangstu|:|4 +904569170@qq.com|:|czh688|:|4 +643033786@qq.com|:|zcc|:|4 +2284498467@qq.com|:|xinping_li|:|4 +liuyihong536@gmail.com|:|liuyihong|:|4 +shaoxiangdong@huawei.com|:|shaoxiangdong|:|4 +zhengbin20@huawei.com|:|rainyhorse|:|4 +lxh@lxhdemacbook-pro.local|:|lxh|:|4 +1027252281@qq.com|:|xsmq|:|4 +xukailun@huawei.com|:|x00540480|:|4 +cj@huawei.com|:|cj|:|4 +zhifeng.hu@huawei.com|:|huzhifeng|:|4 +liangzelang@gmail.com|:|liangzelang|:|4 +guomenghao@huawei.com|:|GuoMengHao|:|4 +flyingcow8@gmail.com|:|zhanyuan|:|4 +zhangdengcheng@huawei.com|:|zhangdengcheng|:|4 +fangzhenglei@huawei.com|:|leilei_snow|:|4 +maoweiyong@huawei.com|:|maoweiyong|:|4 +gongchen6@huawei.com|:|gongchen|:|4 +chenkang45@huawei.com|:|chenkang|:|3 +yangluhang@huawei.com|:|yangluhang|:|3 +tangxiaolei10@huawei.com|:|tangxl|:|3 +610430156@qq.com|:|luo-hang777|:|3 +wang1@huawei.com|:|wangzidong|:|3 +2668608409@qq.com|:|15867023963|:|3 +1763362044@qq.com|:|jiang-nan-ming-zhou|:|3 +1661530355@qq.com|:|song-meng-yu|:|3 +164006656@qq.com|:|wanjun|:|3 +2293162700@qq.com|:|xfb-666|:|3 +540400877@qq.com|:|zhou-yu|:|3 +aiyun2021@163.com|:|mikkassa|:|3 +lixinwei_10@163.com|:|lxw_lxw_lxw|:|3 +463221580@qq.com|:|jingyu921|:|3 +549720715@qq.com|:|wupeiyuan1|:|3 +237750376@qq.com|:|lizhiheng|:|3 +995906889@qq.com|:|misitetong|:|3 +luolan13@huawei.com|:|sophie2020|:|3 +lilifan1@huawei.com|:|lilifan|:|3 +1789133296@qq.com|:|linjie|:|3 +694372703@qq.com|:|Liminglud|:|3 +823440605@qq.com|:|shen-miaoshui|:|3 +122443730@qq.com|:|WangWenZhong|:|3 +yanrong_tyut@163.com|:|YR0717|:|3 +1003178061@qq.com|:|yfyang112358|:|3 +1421578083@qq.com|:|miumiuC|:|3 +756183986@qq.com|:|jinduo|:|3 +bronyale@outlook.com|:|Bronyale|:|3 +yangge8@huawei.com|:|yangge|:|3 +liulei277@huawei.com|:|liulei277|:|3 +wytxiaer@163.com|:|wangyantao|:|3 +819091019@qq.com|:|luoyuchen|:|3 +908929260@qq.com|:|fattycat|:|3 +yuhuayu2.hi@163.com|:|Elvira0902|:|3 +mengting.tina.zhang@huawei.com|:|TinaMengtingZhang|:|3 +8623924@qq.com|:|Strung|:|3 +peiyingwu@whu.edu.cn|:|wupeiying|:|3 +1139114118@qq.com|:|cai-zhaoyuan|:|3 +1272024027@qq.com|:|wang-tian-hao|:|3 +2290506425@qq.com|:|yusi_wang|:|3 +xiefangqi3@huawei.com|:|xiefangqi|:|3 +2645168370@qq.com|:|chauneahhin|:|3 +wangyao1819@qq.com|:|Wang_Yao|:|3 +wei.sun2@huawei.com|:|Wei_Sun|:|3 +543376780@qq.com|:|zhangjie|:|3 +hz.wangzhiwei@huawei.com|:|wzw|:|3 +liuruotao@huawei.com|:|liuruotao|:|3 +1018944026@qq.com|:|detectiver|:|3 +fairyyuer@foxmail.com|:|gyuer|:|3 +969216914@qq.com|:|qkeys|:|3 +1923797784@qq.com|:|zhi-qing-wei|:|3 +1404988126@qq.com|:|_xuyulina_|:|3 +634727217@qq.com|:|wyj|:|3 +786049403@qq.com|:|hu-daiwang|:|3 +amiram.allouche@huawei.com|:|amiram|:|3 +782473006@qq.com|:|ZJM|:|3 +tongyue_136@163.com|:|tongyue|:|3 +1274573939@qq.com|:|xu127457|:|3 +zhujianfeng@huawei.com|:|helloiSCSI|:|3 +320702281@qq.com|:|windhxs|:|3 +shicaiwei@std.uestc.edu.cn|:|shicaiwei|:|3 +yangwm19@lzu.edu.cn|:|yangwm|:|3 +hankyang1992@gmail.com|:|hang_yang|:|3 +524446785@qq.com|:|hujiaxin|:|3 +2567501064@qq.com|:|lidongsheng|:|3 +17863107261@163.com|:|Gogery|:|3 +3236961631@qq.com|:|FOURTH|:|3 +715485601@qq.com|:|l_emon|:|3 +359666090@qq.com|:|lei-dao-wei-jiao|:|3 +softxmu@sina.com|:|Li_Kesen|:|3 +452622886@qq.com|:|fenglovebei|:|3 +xiexingxian@huawei.com|:|xiexingxian|:|3 +yyffcc1012@163.com|:|chen-yu-fan|:|3 +zhangzhenghai@huawei.com|:|zhangzhenghai|:|3 +405194527@qq.com|:|kanghui|:|3 +panfei27@huawei.com|:|panfei|:|3 +lipeng238@huawei.com|:|woshixiaoli|:|3 +zhushujing@huawei.com|:|zhushujing|:|3 +liujiahan1@huawei.com|:|liujiahan|:|3 +369376805@qq.com|:|An_Xiao|:|3 +6567503+r1chardf1d0@user.noreply.gitee.com|:|r1chardf1d0|:|3 +252664817@qq.com|:|hukang|:|3 +yanglf1121@163.com|:|yanglf1121|:|3 +you@example.com|:|JunYuLiu|:|3 +hedongodng@huawei.com|:|hedongodng|:|3 +pbxj938@china.huawei.com|:|public_04f0281d2d30|:|3 +wangyue53@huawei.com|:|wangyue01|:|3 +amirlashkari1@huawei.com|:|Amir_Lashkari|:|3 +liangchenghui@liangchenghuidemacbook-pro.local|:|liang-cheng-hui|:|3 +gong_chen@qq.com|:|gong_chen|:|3 +316297692@qq.com|:|Kang|:|3 +invisiblewei@gmail.com|:|Wei_Luning|:|3 +864733542@qq.com|:|VectorSL|:|2 +liyejun@huawei.com|:|Yejun_Li|:|2 +lijunbin4@huawei.com|:|l00500167|:|2 +2512235663@qq.com|:|qmckw|:|2 +wanjunling168@qq.com|:|wanjunling168|:|2 +826980835@qq.com|:|EvanBay|:|2 +506413424@qq.com|:|WangXiaoyin|:|2 +1656521000@qq.com|:|leiguang|:|2 +532925744@qq.com|:|ge-wu-zhi-zhi|:|2 +18407825861@163.com|:|jakcmanftr|:|2 +1287185332@qq.com|:|latrawy|:|2 +1700116957@qq.com|:|lwj19991209|:|2 +2647877536@qq.com|:|wang_tao|:|2 +1539890764@qq.com|:|minatofy|:|2 +3414897247@qq.com|:|wanyuming|:|2 +dqxxyysdyx@126.com|:|yu-yan-song|:|2 +1114316001@qq.com|:|xianduanpingsheiting|:|2 +875980605@qq.com|:|fbc|:|2 +2271683680@qq.com|:|jiajun135|:|2 +2573344091@qq.com|:|zhanghao|:|2 +1275243782@qq.com|:|zhaoyisen|:|2 +13355308989@163.com|:|13355308989|:|2 +1353963668@qq.com|:|JWY99|:|2 +2535030577@qq.com|:|fangzhibin|:|2 +1660079729@qq.com|:|Ferry|:|2 +1170866386@qq.com|:|al_raya|:|2 +1104228781@qq.com|:|chengchuanxing|:|2 +1541293039@qq.com|:|zhang-yu|:|2 +1951267464@qq.com|:|nefu-xiaobai|:|2 +1753473459@qq.com|:|wang-tai-ge|:|2 +huanxiaoling1@huawei.com|:|huanxiaoling|:|2 +qltan@stu.xidian.edu.cn|:|Qltan|:|2 +2318422361@qq.com|:|zhao-dong-jie|:|2 +3170102948@zju.edu.cn|:|Feve1986|:|2 +lambert2478@163.com|:|broccoli857|:|2 +1340952518@qq.com|:|zhong-chang-shuo|:|2 +tduuwv645@163.com|:|wang-gangke|:|2 +mgh_1202@163.com|:|Hu1GM|:|2 +leiyuning@huawei.com|:|leiyuning|:|2 +2664920154@qq.com|:|111chengxuyuan|:|2 +1379260832@qq.com|:|yux1ng|:|2 +lvxinyu.math@whu.edu.cn|:|lvxinyu|:|2 +878702291@qq.com|:|zsalliance|:|2 +916449642@qq.com|:|m1233|:|2 +yuanyanglv@qq.com|:|zhanglin|:|2 +1152040573@qq.com|:|jinguo123|:|2 +lujiale@huawei.com|:|lujiale|:|2 +1135354118@qq.com|:|_yzm_|:|2 +gongliyao@huawei.com|:|GongLiyao|:|2 +569835079@qq.com|:|fr199787|:|2 +13588337001@163.com|:|echo-yike|:|2 +769213934@qq.com|:|ZCX|:|2 +497776945@qq.com|:|lanmeng|:|2 +954076761@qq.com|:|mxxcdd|:|2 +13951781364@139.com|:|juzhong3|:|2 +1031672504@qq.com|:|dwang1108|:|2 +muchenjin2021@163.com|:|muchenjin|:|2 +522690987@qq.com|:|zheng-hao|:|2 +1287333831@qq.com|:|xialingtian|:|2 +1595862940@qq.com|:|mr_melos|:|2 +donrichnx@163.com|:|donrichnx|:|2 +469817795@qq.com|:|davilsu|:|2 +zhanlijun@huawei.com|:|zhanlijun|:|2 +jingyangxiang@foxmail.com|:|jingyangxiang|:|2 +m15300770736@163.com|:|m15300770736|:|2 +gaocongli@huawei.com|:|gaocongli|:|2 +1280190261@qq.com|:|17854299323|:|2 +kunpenggk@gmail.com|:|wild-fox|:|2 +707120797@qq.com|:|zorax|:|2 +1481815567@qq.com|:|jameszhangyukun|:|2 +lufei9026@qq.com|:|lufei9026|:|2 +3045465496@qq.com|:|RainWang6188|:|2 +13823355805@163.com|:|wmzheng2020|:|2 +1465199518@qq.com|:|_uccInf_|:|2 +1092936062@qq.com|:|Lizxxy|:|2 +yangyueren@outlook.com|:|yangyueren|:|2 +1294693043@qq.com|:|G-Dragon-Liu|:|2 +haosichong@qq.com|:|SichongHao|:|2 +oushibo@huawei.com|:|osbo|:|2 +chaikelun@gmail.com|:|klchai|:|2 +2479031300@qq.com|:|fan1997|:|2 +584897688@qq.com|:|RiEnRiu|:|2 +2501734853@qq.com|:|ziquan|:|2 +luxuff@foxmail.com|:|tan-hua-lin|:|2 +2579113595@qq.com|:|hulx|:|2 +fancyshun@163.com|:|changshun|:|2 +liuzhicheng01@huawei.com|:|liuzhicheng01|:|2 +honghu_zero@163.com|:|liuhonghu|:|2 +361122924@qq.com|:|Kaide|:|2 +chengyun9@huawei.com|:|cy|:|2 +lingxling3@163.com|:|lingxling2|:|2 +wanglixinsg0@qq.com|:|wanglixin|:|2 +2356719439@qq.com|:|Humanyue|:|2 +duanbo5@huawei.com|:|mindmender_duan|:|2 +920014365@qq.com|:|czp|:|2 +351440916@qq.com|:|chenweipeng|:|2 +lapriv@outlook.com|:|fb3bdcff5d|:|2 +zdc9012@foxmail.com|:|MapleGrove|:|2 +qiaolei1@huawei.com|:|ql_12345|:|2 +windaway@live.com|:|windaway|:|2 +1415109792@qq.com|:|shuait|:|2 +yuruil@qq.com|:|liyurui|:|2 +meetoyy@qq.com|:|ouyang_xx|:|2 +l_w_zeng@163.com|:|wittlu|:|2 +920389187@qq.com|:|yyyzzzhao|:|2 +c.cwithpku@pku.edu.cn|:|chenchang|:|2 +1764164338@qq.com|:|Zhu_Wenyong|:|2 +wudenggang@outlook.com|:|wudenggang|:|2 +kangzhaoxiang2018@163.com|:|kzx2018|:|2 +huenrui1@huawei.com|:|huenrui|:|2 +doyushui@163.com|:|dong-li|:|2 +yiannis.lamprou@gmail.com|:|Ioannis_Lamprou|:|2 +thuxuxs@163.com|:|xuxs|:|2 +5719707+jonyguo@user.noreply.gitee.com|:|guozhijian|:|2 +summyflyer@163.com|:|13465716071|:|2 +chentanjie@huawei.com|:|Daniel|:|2 +rmdyh@hotmail.com|:|rmdyh|:|2 +lishixing3@huawei.com|:|lishixing3|:|2 +meizhiyuan@huawei.com|:|meizhiyuan|:|2 +wanghua1@huawei.com|:|wanghua|:|2 +zhangrunjiao1@huawei.com|:|zhangrunjiao|:|2 +yinwei23@huawei.com|:|yinwei|:|2 +ngngaifai@ngs-macbook-air.local|:|Ng_Ngai_Fai|:|2 +shenyeping@huawei.com|:|shenyeping|:|2 +l00356578@china.huawei.com|:|linqingke|:|2 +yinding1@huawei.com|:|y00369862|:|2 +940619583@qq.com|:|zhu_xiaochen|:|2 +lanxuan365@qq.com|:|Geng_Fei|:|2 +root@gigabyte-aero15.localdomain|:|gigabyte|:|2 +jzhang46@lenovo.com|:|Jolin_Zhang46|:|2 +dengyutao@huawei.com|:|dengyutao|:|2 +shida.he1@huawei.com|:|Shida_He|:|2 +duxiutao@gmail.com|:|duxiutao|:|2 +wangchengke3@huawei.com|:|w00517616|:|2 +xianweizhao1@huawei.com|:|Xian_Weizhao|:|2 +kouzhenzhong@huawei.com|:|kouzhenzhong|:|2 +wangjun260@huawei.com|:|wangjun260|:|2 +simple_hlw@163.com|:|helloway|:|2 +caiyimeng1@huawei.com|:|caiyimeng|:|1 +mayadong@huawei.com|:|mayadong|:|1 +jiaoyi4@huawei.com|:|KevinYi|:|1 +michael.zhu1@huawei.com|:|Michael|:|1 +linxin40@huawei.com|:|JoeyLin|:|1 +guchuancai@huawei.com|:|Chuancai_Gu|:|1 +yuedongli1@huawei.com|:|yuedongli1|:|1 +gengchenhua@huawei.com|:|xwkgch|:|1 +zhouhongye1@huawei.com|:|hyzhou|:|1 +1589300958@qq.com|:|yafeng19|:|1 +421640644@qq.com|:|pengyonghui|:|1 +wyann0202@gmail.com|:|wyann|:|1 +xjtulkw@163.com|:|1Yanxiaolin1|:|1 +1137138362@qq.com|:|userw|:|1 +379235142@qq.com|:|yyyyygc|:|1 +x940476895@163.com|:|xie-zhongjie|:|1 +18851659065@163.com|:|Li-chenyangV|:|1 +308861679@stu.cqut.edu.cn|:|CccJ|:|1 +2227933115@qq.com|:|stcloud|:|1 +1310733530@qq.com|:|chenzeyu|:|1 +1356524380@qq.com|:|amornjr|:|1 +1922351820@qq.com|:|hhxtryyoubest|:|1 +jiaxian@isrc.iscas.ac.cn|:|renjiaxian|:|1 +chchen0531@126.com|:|chenchen|:|1 +xyulin211@163.com|:|xyuuuyx|:|1 +465742153@qq.com|:|xh|:|1 +2442428737@qq.com|:|xuuuG|:|1 +2642968087@qq.com|:|jinjianxin|:|1 +940584454@qq.com|:|chaoshijiecy|:|1 +3240670024@qq.com|:|deng-lianbin|:|1 +shenjiajun169@gmail.com|:|jiajun169|:|1 +2607121836@qq.com|:|cse260|:|1 +1824172913@qq.com|:|zhangyf|:|1 +1257927286@qq.com|:|YangShuq|:|1 +1033296297@qq.com|:|chentao|:|1 +1298505693@qq.com|:|wang-jia-wei|:|1 +2499241187@stu.cqut.edu.cn|:|zy_980301|:|1 +yanghao20000105@163.com|:|yh|:|1 +cheng.cheung.yu@huawei.com|:|raymondzxyu|:|1 +1042882264@qq.com|:|lu-yi-chun|:|1 +haif_zh@163.com|:|zhf|:|1 +longji.huang018@gmail.com|:|Longji_Huang|:|1 +2021202010061@whu.edu.cn|:|shen-miaoshui|:|1 +supreme@lsder.cn|:|lsder|:|1 +haku20010427@gmail.com|:|Xin_Yi|:|1 +jijiarong@huawei.com|:|ji-jia-rong|:|1 +zhaozhenyao@huawei.com|:|z00617246|:|1 +383297671@qq.com|:|ClementineZTW|:|1 +huangziling1@huawei.com|:|huangziling|:|1 +hutianyi@whu.edu.cn|:|hutianyi|:|1 +yanfu@isrc.iscas.ac.cn|:|_achengyanfu|:|1 +duhy001512@163.com|:|Changri-Liuhen|:|1 +zhangrn98@outlook.com|:|ZRN|:|1 +738129634@qq.com|:|ding_chenjun|:|1 +lizt@pcl.ac.cn|:|lizeting-pcl|:|1 +wudongen1122@163.com|:|wu-dongen|:|1 +603409022@qq.com|:|Rthete|:|1 +1026078943@qq.com|:|p-nian|:|1 +rivercoldjh@163.com|:|river_cold|:|1 +365699132@qq.com|:|weng-yiyang|:|1 +1390871916@qq.com|:|liuyong|:|1 +zyz_bamboo@126.com|:|bam-bo-o|:|1 +hmtbgc@163.com|:|hmtbgc|:|1 +1320765753@qq.com|:|gaochong|:|1 +1457493024@qq.com|:|yball|:|1 +876949366@qq.com|:|beefbill|:|1 +fisheryung@outlook.com|:|Fisher|:|1 +2356186697@qq.com|:|mt129|:|1 +dsf_claire@163.com|:|dong-shi-fei|:|1 +379121898@qq.com|:|kangzige|:|1 +946079208@qq.com|:|zhouzekai1|:|1 +468156975@qq.com|:|yejingyu|:|1 +793185273@qq.com|:|hmy0123|:|1 +632842443@qq.com|:|liurishen|:|1 +1823192871@qq.com|:|liujinnan|:|1 +kaixin@isrc.iscas.ac.cn|:|sunkaixin1|:|1 +liuhongsheng4@huawei.com|:|hsliu_ustc|:|1 +971813982@qq.com|:|HWalkingMan|:|1 +1326609656@qq.com|:|huangjirui|:|1 +2303633806@qq.com|:|FelliYang|:|1 +1136160101@qq.com|:|fateld|:|1 +hj_math@whu.edu.cn|:|Huang-Jingg|:|1 +1175149853@qq.com|:|xuxiny|:|1 +2659464450@qq.com|:|Yu-Qi-hang|:|1 +yvleee@outlook.com|:|yvlee|:|1 +379121898@qq.com|:|_kangzige_|:|1 +875876066@qq.com|:|li-jian-wei|:|1 +1741767789@qq.com|:|maeyon-z|:|1 +zhangrenwei1@huawei.com|:|anyrenwei|:|1 +cheng.ding@huawei.com|:|dingcheng|:|1 +1732631237@qq.com|:|_|:|1 +henulyh@163.com|:|17613100226|:|1 +muyu0223@outlook.com|:|Lan-Ling|:|1 +zrn123123@outlook.com|:|ZRN|:|1 +1545239885@qq.com|:|wulizzya|:|1 +1301550100@qq.com|:|pikapika|:|1 +1585852980@qq.com|:|mareda|:|1 +2214501000@qq.com|:|ge-chao|:|1 +1013608322@qq.com|:|ying|:|1 +nightwiyr@gmail.com|:|wiyr|:|1 +18158899570@163.com|:|zhangxuebao|:|1 +1219465568@qq.com|:|mengsuiwei|:|1 +1156427025@qq.com|:|shengqianwen|:|1 +yushulinfeng@whu.edu.cn|:|yushu-linfeng|:|1 +ppzheng@stu.xidian.edu.cn|:|Zwink|:|1 +zhangyi@zhangyi267@huawei.com|:|zhangyi|:|1 +a15623827661@163.com|:|zzp|:|1 +1240348479@qq.com|:|xu-zhi-jie|:|1 +mahequn@huawei.com|:|mahequn123|:|1 +acheer@126.com|:|chen-jun0211|:|1 +1205703021@qq.com|:|Weijun|:|1 +lidingv@whu.edu.cn|:|ldv|:|1 +hello_lbk@163.com|:|lbk|:|1 +unseenme@163.com|:|unseenme|:|1 +2254902922@qq.com|:|Eden|:|1 +977180923@qq.com|:|zjuter0126|:|1 +sunyuhan@zju.edu.cn|:|sun-yu-han|:|1 +442653227@qq.com|:|nuo-zhe|:|1 +xiehf@shanghaitech.edu.cn|:|xiehf|:|1 +1379347218@qq.com|:|zhang-wen-xiang|:|1 +guikun.chen@qq.com|:|guikunchen|:|1 +463411759@qq.com|:|haohaonannan97|:|1 +lilongfei15@huawei.com|:|lilongfei|:|1 +345368251@qq.com|:|lamuxiaoyu|:|1 +603817372@qq.com|:|ether|:|1 +3484391612@qq.com|:|findexplore|:|1 +617500087@qq.com|:|oida|:|1 +568776550@qq.com|:|wangwenqing2021|:|1 +zhjgtao@gmail.com|:|Ardcy|:|1 +1395498360@qq.com|:|xuyang|:|1 +425291275@qq.com|:|wen-ze-kai|:|1 +2230639016@qq.com|:|JT0623|:|1 +22151031@zju.edu.cn|:|daq|:|1 +luonuosaha@163.com|:|luon|:|1 +861613130@qq.com|:|wzharies|:|1 +zhuchuang526@qq.com|:|zhuchuang|:|1 +hongxing1227@gmail.com|:|hongxing|:|1 +894855066@qq.com|:|kman066|:|1 +562778582@qq.com|:|wjb|:|1 +healing1219@163.com|:|healing|:|1 +artlesbol@gmail.com|:|Artlesbol|:|1 +samuelbatissou@gmail.com|:|Samuel_Batissou|:|1 +820199855@qq.com|:|zzb|:|1 +1290540177@qq.com|:|Lu|:|1 +599037417@qq.com|:|hzw|:|1 +geconglin2008@qq.com|:|ge-chong-lin|:|1 +3344681919@qq.com|:|WPX|:|1 +15061130105@163.com|:|cyx2|:|1 +1835452075@qq.com|:|thirteen-and-fourteen|:|1 +3195016850@qq.com|:|YJfuel123|:|1 +45701574@qq.com|:|yaoyuan|:|1 +760019473@qq.com|:|gitsYu|:|1 +guoruiming@stu.scu.edu.cn|:|guo-rui-ming|:|1 +huzhiheng2@huawei.com|:|zhihenghu|:|1 +haizhouye@163.com|:|haizhouye|:|1 +dandelight@qq.com|:|guo-rui-ming|:|1 +651149627@qq.com|:|jihaoqin|:|1 +1319670017@qq.com|:|henry_tujia|:|1 +kun.tan@huawei.com|:|kuntan|:|1 +cohen_tan@hotmail.com|:|sora-city|:|1 +970094905@qq.com|:|wangjq|:|1 +3357995289@qq.com|:|guyuehuo|:|1 +15652803838@163.com|:|blingbling|:|1 +847516517@qq.com|:|zsw12138|:|1 +2407121029@qq.com|:|Ren_Wenhao|:|1 +zhangguizong123@sina.com|:|Boyka_Occam|:|1 +li.haoyang@huawei.com|:|lihaoyang|:|1 +1179931743@qq.com|:|tongzh|:|1 +1258374432@qq.com|:|smullwy|:|1 +mingchung.suen@gmail.com|:|Mingchung-Suen|:|1 +tuyanlun9716@163.com|:|Outliers1106|:|1 +cometemejackson@outlook.com|:|cometeme|:|1 +1025997470@qq.com|:|ucalan|:|1 +lukeluocn@outlook.com|:|lukelook|:|1 +wdxwj@vip.qq.com|:|wdxwj|:|1 +1265272552@qq.com|:|liang-jia-cheng|:|1 +525244039@qq.com|:|Zikun97|:|1 +ariaotp@163.com|:|ariaotp|:|1 +603049648@qq.com|:|huang_gang_hong|:|1 +qu0604@163.com|:|wukesong|:|1 +491686106@qq.com|:|lizy|:|1 +2602688060@qq.com|:|wanglin|:|1 +kqzhang@stu.xidian.edu.cn|:|kqzhang|:|1 +qingshanxiaozi@163.com|:|qingshanxiaozi|:|1 +530711667@qq.com|:|guan_wen_cong|:|1 +zhanggy9@mail2.sysu.edu.cn|:|yuanAIhan|:|1 +qb990531@outlook.com|:|jhzj|:|1 +yiqiang.chen@yahoo.fr|:|chen-yiqiang|:|1 +2571337695@qq.com|:|jiang|:|1 +20174280@cqu.edu.cn|:|esther|:|1 +daiqizhu@cqu.edu.cn|:|daiqizhu123|:|1 +13260523842@163.com|:|dlliu123|:|1 +emyc@163.com|:|cuihu|:|1 +hujingsong3@huawei.com|:|hu-jingsong|:|1 +zhouhongfei1217@163.com|:|zhouhongfei|:|1 +liangcai1@huawei.com|:|cliang|:|1 +736940188@qq.com|:|warrior0|:|1 +brandonye@qq.com|:|brandonye|:|1 +wangweining2@huawei.com|:|wwx691809|:|1 +dangjiaqi1@huawei.com|:|Author_dangjiaqi1|:|1 +2045391730@qq.com|:|hit_zyh|:|1 +2567773985@qq.com|:|yuruilee|:|1 +marvin_tec@126.com|:|chenyang_Marvin|:|1 +jinghongzhang@pku.edu.cn|:|JinghongZhang|:|1 +maomingqian0105@qq.com|:|mao-ming-qian|:|1 +lizi4@huawei.com|:|Clement_Li|:|1 +majianwei4@huawei.com|:|majianwei|:|1 +1121099234@qq.com|:|hpc-research|:|1 +361046262@qq.com|:|xuyixing|:|1 +321652527@qq.com|:|_lxz_|:|1 +919179287@qq.com|:|gerayking|:|1 +lixintao2@huawei.com|:|lixintao|:|1 +kaihana@163.com|:|iamhankai|:|1 +chenxinghaothu@gmail.com|:|Xinghao_Chen|:|1 +1159941086@qq.com|:|ouyangyangxy|:|1 +1901110358@pku.edu.cn|:|GAO_HYP_XYJ|:|1 +fuyu_wang@126.com|:|Fuyu_Wang|:|1 +zhanghui_china2020@163.com|:|ZhangHui|:|1 +liyiming1998@qq.com|:|neoming|:|1 +8315094+panpanrui@user.noreply.gitee.com|:|panpanrui|:|1 +chuckchy0819@126.com|:|chuck|:|1 +dff@pku.edu.cn|:|dff|:|1 +chengjunjie@126.com|:|Junjie_Cheng|:|1 +alashkari@msi.localdomain|:|Amir_Lashkari|:|1 +fireinthehole1024@126.com|:|fireinthehole1024|:|1 +yangorwell@pku.edu.cn|:|MingHan-Y|:|1 +taroxd@outlook.com|:|taroxd|:|1 +apyuan@126.com|:|niu-huang-jie-du-pian|:|1 +kingcong@kingcongdemacbook-pro.local|:|kingcong|:|1 +jiahanliuncu@163.com|:|liujiahan|:|1 +1350689549@qq.com|:|feng-zi-zou-le|:|1 +wang.bochao1@huawei.com|:|Wang_Bochao|:|1 +hyt@mail.ustc.edu.cn|:|yitongh|:|1 +zwx5320437@china.huawei.com|:|zhengbin_G|:|1 +zhuyun_gray@163.com|:|Yunzhu0v0|:|1 +chenbo116@huawei.com|:|chenbo|:|1 +duanhao10@hisilicon.com|:|HaoJtr|:|1 +317958662@qq.com|:|zymaa|:|1 +sunsuodong@126.com|:|sunsuodong|:|1 +xiangyunwu@huawei.com|:|xiangyunwu21|:|1 +fxy.rebecca@163.com|:|xinyun_Fan|:|1 +lawliethk@outlook.com|:|HulkTang|:|1 +tx1103mark@163.com|:|tx1103mark|:|1 +zhangxueheng@sjtu.edu.cn|:|GreyZzzzzzXh|:|1 +han.xiao@jina.ai|:|Han_Xiao|:|1 +yingjiangyong@huawei.com|:|y00488820|:|1 +es_chow@163.com|:|es_chow|:|1 +281130306@qq.com|:|mcgrady00h|:|1 +yq2207@columbia.edu|:|yoonlee666|:|1 +poodll@163.com|:|li-hong-zhang|:|1 +l00421674@huawei.com|:|l00421674|:|1 +genglishuai1@huawei.com|:|genglishuai|:|1 +lvwenyuan@huawei.com|:|lvwenyuan_00536823|:|1 +han.haocheng@huawei.com|:|hanhaocheng|:|1 +root@desktop-4jpga6b.localdomain|:|root|:|1 +tomzwang11@gmail.com|:|wz|:|1 +grchang123@163.com|:|codesausage|:|1 +alexey_shevlyakov@huawei.com|:|ale|:|1 +duxiutao@huawei.com|:|duxiutao|:|1 +xun.xue@huawei.com|:|xunxue|:|1 +738965460@qq.com|:|liangzelang|:|1 +yangjie1305@163.com|:|yangjie|:|1 +lilei123@huawei.com|:|lilei|:|1 +lihongkang1@huawei.com|:|lihongkang|:|1 +6517995+hanyuanai@user.noreply.gitee.com|:|hanyuanai|:|1 +linyifan@huawei.com|:|lyfne|:|1 +lupengcheng4@huawei.com|:|lupengcheng|:|1 +jzw@desktop-2orpq19.localdomain|:|jzw|:|1 +chujinjin52@hauwei.com|:|chujinjin|:|1 +296584292@qq.com|:|root|:|1 +yifengpan@yifengpandemacbook-pro.local|:|yi-feng-pan|:|1 From bb59f0ead8455b107e1f9a1cdb3facb1c703bceb Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 23 Mar 2023 14:08:51 +0800 Subject: [PATCH 214/438] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/total_commit_count.rake | 54 +++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 lib/tasks/total_commit_count.rake diff --git a/lib/tasks/total_commit_count.rake b/lib/tasks/total_commit_count.rake new file mode 100644 index 000000000..e121dcff5 --- /dev/null +++ b/lib/tasks/total_commit_count.rake @@ -0,0 +1,54 @@ +namespace :total_commit_count do + desc "total_commit_count" + task git_demo_raw: :environment do + project_name = ENV['name'] || "mindspore" + puts "project_id=================#{project_name}" + projects = Project.where("name like ?", "%#{project_name}%") + if ENV['count'].present? + projects = projects.limit(ENV['count'].to_i) + end + + @date_count_hash = {} + # projects = Project.where(:name => 'opensource0311') + projects.each_with_index do |project, index| + result = Gitea::Repository::Commits::ListService.call(project.owner.login,project.identifier,sha: "", page: 1, limit: 5, token: project.owner.gitea_token) + total_count = result[:total_count] + puts "#{index} total_count==========#{total_count}" + if total_count > 50 + total_page = (total_count / 50) + 1 + total_page.times do |i| + add_commit_to_index(project, i + 1) + end + else + add_commit_to_index(project, 1) + end + + end + puts "@date_count_hash===========#{@date_count_hash.to_json}" + + + + + # Time.now + # Wed Mar 15 14:12:09 2023 +0800 + # Time.now.strftime("%a %b %d %H:%M:%S %Y") + # Time.now.strftime("%a %b %d %H:%M:%S %Y +0800") + Time.parse("2023-03-15 14:12:09").strftime("%a %b %d %H:%M:%S %Y +0800") + + end + + def add_commit_to_index(project, page) + # Gitea::Repository::Commits::ListSliceService.call(project.owner.login,project.identifier,sha: "", page: 1, limit: 1000, token: "a9244ecac647dd33fee3b480c5898baab1d3fe7d") + result = Gitea::Repository::Commits::ListService.call(project.owner.login,project.identifier,sha: "", page: page, limit: 50, token: project.owner.gitea_token) + result[:body].each do |commit| + commit_date = Time.parse(commit['commit']['author']['date']) + commit_date_str = commit_date.strftime("%Y-%m") + if @date_count_hash[commit_date_str].present? + @date_count_hash[commit_date_str] = @date_count_hash[commit_date_str] + 1 + else + @date_count_hash[commit_date_str] = 1 + end + end + end + +end \ No newline at end of file From e9c7009c39ad94a0936cf8b870706f472a873310 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 23 Mar 2023 14:10:33 +0800 Subject: [PATCH 215/438] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E6=95=B0rake?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/total_commit_count.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/total_commit_count.rake b/lib/tasks/total_commit_count.rake index e121dcff5..7c0f8b470 100644 --- a/lib/tasks/total_commit_count.rake +++ b/lib/tasks/total_commit_count.rake @@ -1,6 +1,6 @@ namespace :total_commit_count do desc "total_commit_count" - task git_demo_raw: :environment do + task done: :environment do project_name = ENV['name'] || "mindspore" puts "project_id=================#{project_name}" projects = Project.where("name like ?", "%#{project_name}%") From 200b954f41bc65f1fb4d051c5c1a9afcd40d8716 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 23 Mar 2023 15:54:37 +0800 Subject: [PATCH 216/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E5=8C=BA=E5=9D=97=E9=93=BE=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/project.rb | 13 ++++++---- lib/tasks/sync_mindspore_contributors.rake | 29 ++++++++++++++++++++-- public/mindspore_authors | 14 +++++------ 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index fc0828307..2d2976459 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -449,13 +449,16 @@ class Project < ApplicationRecord email = itemArray[0] username = itemArray[1] commits = itemArray[2].to_i - if username =~ CustomRegexp::LOGIN && email =~ CustomRegexp::EMAIL - user = User.find_by(login: username, mail: email) + user = User.find_by(login: username, mail: email) + user = User.find_by(login: username) if user.nil? + user = User.find_by(mail: email) if user.nil? + # next if user.nil? + search_contributor = contributors.select{|con| con["id"]==user.id}[0] + if search_contributor.present? + search_contributor["contributions"] += commits else - user = User.find_by(mail: email) unless username =~ CustomRegexp::LOGIN - user = User.find_by(login: username) unless email =~ CustomRegexp::EMAIL + contributors << {contributions: commits, name: username, login: username, email: email, id: user&.id}.stringify_keys end - contributors << {contributions: commits, name: username, login: username, email: email, id: user&.id}.stringify_keys end file.close diff --git a/lib/tasks/sync_mindspore_contributors.rake b/lib/tasks/sync_mindspore_contributors.rake index c2b55e7d4..0c8ace17c 100644 --- a/lib/tasks/sync_mindspore_contributors.rake +++ b/lib/tasks/sync_mindspore_contributors.rake @@ -1,3 +1,5 @@ +# 执行示例 bundle exec rake "sync_mindspore:contributor_to_user" +# RAILS_ENV=production bundle exec rake "sync_mindspore:contributor_to_user" desc "mindspore项目贡献者数据" # 同步mindspre贡献者数据至用户表 @@ -46,9 +48,32 @@ namespace :sync_mindspore do file.close end - + # 执行示例 bundle exec rake "sync_mindspore:init_project_blockchain[1,2]" + # RAILS_ENV=production bundle exec rake "sync_mindspore:init_project_blockchain[1,2]" desc "初始化区块链项目" - task init_project_blockchain: :environment do + task :init_project_blockchain, [:id, :init_id] => :environment do |t, args| + puts "=====Init Project Blockchain: #{args.id}=====" + project = Project.find_by_id(args.id) + project.update_column(:use_blockchain, true) + username = project.user_id.to_s + token_name = project.id.to_s + total_supply = 10000 + token_balance = [[init_id.to_s, 100]] + + contributions = Project.mindspore_contributors + total_contributions = contributions.sum{|i| i["contributions"]} + contributions.each do |con| + cont_balance = Float(con["contributions"]*9900/total_contributions).round(0) + token_balance << [con["id"], cont_balance] if cont_balance > 0 + end + params = { + "request-type": "create repo", + "username": username, + "token_name": token_name, + "total_supply": total_supply, + "token_balance": token_balance + }.to_json + resp_body = Blockchain::InvokeBlockchainApi.call(params) end end diff --git a/public/mindspore_authors b/public/mindspore_authors index 28fc3ec73..c5b30789a 100644 --- a/public/mindspore_authors +++ b/public/mindspore_authors @@ -66,7 +66,7 @@ liyong126@huawei.com|:|liyong|:|133 xiaotianci1@huawei.com|:|Xiao_Tianci|:|129 hezhenhao1@huawei.com|:|hezhenhao1|:|128 lilinjie11@huawei.com|:|lilinjie|:|127 -wangnan39@huawei.com|:|wangnan39@huawei.com|:|126 +wangnan39@huawei.com|:|wangnan39|:|126 fanjibin@huawei.com|:|fan-ji-bin|:|124 xuhui78@huawei.com|:|looop5|:|122 yangzhenzhang@huawei.com|:|yangzhenzhang|:|121 @@ -124,7 +124,7 @@ hanhuifeng1@huawei.com|:|hanhuifeng2020|:|76 yanpanhui@huawei.com|:|ms_yan|:|76 eric.zhang1@huawei.com|:|eric|:|76 liuyongqi5@huawei.com|:|liu-yongqi-63|:|74 -albert.liyan@huawei.com|:|albert.liyan@huawei.com|:|74 +albert.liyan@huawei.com|:|albert.liyan|:|74 liqiliang1@huawei.com|:|liqiliang|:|74 xiongkun5@huawei.com|:|xiongkun|:|73 liuluobin@huawei.com|:|liuluobin|:|73 @@ -336,14 +336,14 @@ daisurong@mail.nankai.edu.cn|:|Dai_Surong|:|22 zhengbin25@huawei.com|:|zhengbin|:|22 harshvardhan.gupta@huawei.com|:|Harshvardhan_Gupta|:|22 yue.yu1@huawei.com|:|alex-yuyue|:|22 -6517937+tronzhang@user.noreply.gitee.com|:|tronzhang|:|22 +tronzhang@huawei.com|:|tronzhang|:|22 pengyanjun1@huawei.com|:|Yanjun_Peng|:|22 gukecai@huawei.com|:|gukecai|:|22 qianlong3@huawei.com|:|qianlong|:|22 meixiaowei1@huawei.com|:|meixiaowei|:|22 wenkai8@huawei.com|:|wenkai|:|21 harshvardhan.gupta1@huawei.com|:|Harshvardhan_Gupta|:|21 -zhanghaibo5@huawei.com|:|zhanghaibo5@huawei.com|:|21 +zhanghaibo5@huawei.com|:|zhanghaibo5|:|21 xulei83@huawei.com|:|xulei2020|:|21 liuxiao78@huawei.com|:|_liuxiao_|:|21 liujunzhu@huawei.com|:|liujunzhu|:|20 @@ -853,7 +853,7 @@ huenrui1@huawei.com|:|huenrui|:|2 doyushui@163.com|:|dong-li|:|2 yiannis.lamprou@gmail.com|:|Ioannis_Lamprou|:|2 thuxuxs@163.com|:|xuxs|:|2 -5719707+jonyguo@user.noreply.gitee.com|:|guozhijian|:|2 +guozhijian@huawei.com|:|guozhijian|:|2 summyflyer@163.com|:|13465716071|:|2 chentanjie@huawei.com|:|Daniel|:|2 rmdyh@hotmail.com|:|rmdyh|:|2 @@ -1097,7 +1097,7 @@ chenxinghaothu@gmail.com|:|Xinghao_Chen|:|1 fuyu_wang@126.com|:|Fuyu_Wang|:|1 zhanghui_china2020@163.com|:|ZhangHui|:|1 liyiming1998@qq.com|:|neoming|:|1 -8315094+panpanrui@user.noreply.gitee.com|:|panpanrui|:|1 +panpanrui@huawei.com|:|panpanrui|:|1 chuckchy0819@126.com|:|chuck|:|1 dff@pku.edu.cn|:|dff|:|1 chengjunjie@126.com|:|Junjie_Cheng|:|1 @@ -1142,7 +1142,7 @@ xun.xue@huawei.com|:|xunxue|:|1 yangjie1305@163.com|:|yangjie|:|1 lilei123@huawei.com|:|lilei|:|1 lihongkang1@huawei.com|:|lihongkang|:|1 -6517995+hanyuanai@user.noreply.gitee.com|:|hanyuanai|:|1 +hanyuanai@huawei.com|:|hanyuanai|:|1 linyifan@huawei.com|:|lyfne|:|1 lupengcheng4@huawei.com|:|lupengcheng|:|1 jzw@desktop-2orpq19.localdomain|:|jzw|:|1 From bbb8132a1bced11c33fcc6840af0bd2b371d7599 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 23 Mar 2023 16:09:11 +0800 Subject: [PATCH 217/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E6=9A=82=E6=97=B6=E5=8E=BB=E6=8E=89?= 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, 1 insertion(+), 5 deletions(-) diff --git a/app/views/repositories/_contributor.json.jbuilder b/app/views/repositories/_contributor.json.jbuilder index b607f070a..c8b2db373 100644 --- a/app/views/repositories/_contributor.json.jbuilder +++ b/app/views/repositories/_contributor.json.jbuilder @@ -15,10 +15,6 @@ else json.image_url user["avatar_url"] db_user = User.find_by_id(user["id"]) if db_user.present? - if @project&.id == 1428586 - json.contribution_perc db_user.mindspore_contribution_perc(project) - else - json.contribution_perc db_user.contribution_perc(project) - end + json.contribution_perc db_user.contribution_perc(project) end end From 243e2e2667abaf78fa8ee0e014585774f1298500 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 23 Mar 2023 16:32:37 +0800 Subject: [PATCH 218/438] =?UTF-8?q?=E7=BE=A4=E6=99=BA=E7=86=B5=E5=88=86?= =?UTF-8?q?=E6=9E=90=E6=8A=A5=E8=A1=A8=E5=A2=9E=E5=8A=A0=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/projects_helper.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 5bd2f68f2..e50bd22d3 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -149,8 +149,8 @@ module ProjectsHelper when 'vue' then "#{url}/v1/vue/entropy" when 'bootstrap' then "#{url}/v1/bootstrap/entropy" when 'tensorflow' then "#{url}/v1/tensorflow/entropy" - when 'openeuler' then "#{url}/v1/openeuler/entropy" - when 'opengauss' then "#{url}/v1/opengauss/entropy" + when 'kernel' then "#{url}/v1/openeuler/entropy" + when 'opengauss-server' then "#{url}/v1/opengauss/entropy" when 'mindspore' then "#{url}/v1/mindspore/entropy" else '' end @@ -166,9 +166,9 @@ module ProjectsHelper when 'vue' then "#{url}/v2/getMediumData?repo_login=vuejs&repo_name=vue" when 'bootstrap' then "#{url}/v2/getMediumData?repo_login=twbs&repo_name=bootstrap" when 'tensorflow' then "#{url}/v2/getMediumData?repo_login=tensorflow&repo_name=tensorflow" - when 'openeuler' then "#{url}/v2/getMediumData?repo_login=openeuler&repo_name=openeuler" - when 'opengauss' then "#{url}/v2/getMediumData?repo_login=opengauss&repo_name=opengauss" - when 'mindspore' then "#{url}/v2/getMediumData?repo_login=mindspore&repo_name=mindspore" + when 'kernel' then "#{url}/v2/getMediumData?repo_login=openeuler&repo_name=kernel" + when 'opengauss-server' then "#{url}/v2/getMediumData?repo_login=opengauss&repo_name=openGauss-server" + when 'mindspore' then "#{url}/v2/getMediumData?repo_login=mindspore&repo_name=mindspore" else '' end end @@ -183,9 +183,9 @@ module ProjectsHelper when 'vue' then "#{url}/v2/getIndexData?repo_login=vuejs&repo_name=vue" when 'bootstrap' then "#{url}/v2/getIndexData?repo_login=twbs&repo_name=bootstrap" when 'tensorflow' then "#{url}/v2/getIndexData?repo_login=tensorflow&repo_name=tensorflow" - when 'openeuler' then "#{url}/v2/getIndexData?repo_login=openeuler&repo_name=openeuler" - when 'opengauss' then "#{url}/v2/getIndexData?repo_login=opengauss&repo_name=opengauss" - when 'mindspore' then "#{url}/v2/getIndexData?repo_login=mindspore&repo_name=mindspore" + when 'kernel' then "#{url}/v2/getIndexData?repo_login=openeuler&repo_name=kernel" + when 'opengauss-server' then "#{url}/v2/getIndexData?repo_login=opengauss&repo_name=openGauss-server" + when 'mindspore' then "#{url}/v2/getIndexData?repo_login=mindspore&repo_name=mindspore" else '' end end @@ -199,9 +199,9 @@ module ProjectsHelper when 'paddle' then "#{url}/paddle/entropy" when 'vue' then "#{url}/vue/entropy" when 'bootstrap' then "#{url}/bootstrap/entropy" - when 'tensorflow' then "#{url}/tensorflow/entropy" - when 'openeuler' then "#{url}/openeuler/entropy" - when 'opengauss' then "#{url}/opengauss/entropy" + when 'tensorflow' then "#{url}/tensorflow/entropy" + when 'kernel' then "#{url}/openeuler/entropy" + when 'opengauss-server' then "#{url}/opengauss/entropy" when 'mindspore' then "#{url}/mindspore/entropy" else '' end From 2977ded4bdaf1e200ee7b5d3ab570c7d61b814d5 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 23 Mar 2023 16:35:09 +0800 Subject: [PATCH 219/438] =?UTF-8?q?=E7=BE=A4=E6=99=BA=E7=86=B5=E5=88=86?= =?UTF-8?q?=E6=9E=90=E6=8A=A5=E8=A1=A8=E5=A2=9E=E5=8A=A0=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/projects_helper.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 5bd2f68f2..e50bd22d3 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -149,8 +149,8 @@ module ProjectsHelper when 'vue' then "#{url}/v1/vue/entropy" when 'bootstrap' then "#{url}/v1/bootstrap/entropy" when 'tensorflow' then "#{url}/v1/tensorflow/entropy" - when 'openeuler' then "#{url}/v1/openeuler/entropy" - when 'opengauss' then "#{url}/v1/opengauss/entropy" + when 'kernel' then "#{url}/v1/openeuler/entropy" + when 'opengauss-server' then "#{url}/v1/opengauss/entropy" when 'mindspore' then "#{url}/v1/mindspore/entropy" else '' end @@ -166,9 +166,9 @@ module ProjectsHelper when 'vue' then "#{url}/v2/getMediumData?repo_login=vuejs&repo_name=vue" when 'bootstrap' then "#{url}/v2/getMediumData?repo_login=twbs&repo_name=bootstrap" when 'tensorflow' then "#{url}/v2/getMediumData?repo_login=tensorflow&repo_name=tensorflow" - when 'openeuler' then "#{url}/v2/getMediumData?repo_login=openeuler&repo_name=openeuler" - when 'opengauss' then "#{url}/v2/getMediumData?repo_login=opengauss&repo_name=opengauss" - when 'mindspore' then "#{url}/v2/getMediumData?repo_login=mindspore&repo_name=mindspore" + when 'kernel' then "#{url}/v2/getMediumData?repo_login=openeuler&repo_name=kernel" + when 'opengauss-server' then "#{url}/v2/getMediumData?repo_login=opengauss&repo_name=openGauss-server" + when 'mindspore' then "#{url}/v2/getMediumData?repo_login=mindspore&repo_name=mindspore" else '' end end @@ -183,9 +183,9 @@ module ProjectsHelper when 'vue' then "#{url}/v2/getIndexData?repo_login=vuejs&repo_name=vue" when 'bootstrap' then "#{url}/v2/getIndexData?repo_login=twbs&repo_name=bootstrap" when 'tensorflow' then "#{url}/v2/getIndexData?repo_login=tensorflow&repo_name=tensorflow" - when 'openeuler' then "#{url}/v2/getIndexData?repo_login=openeuler&repo_name=openeuler" - when 'opengauss' then "#{url}/v2/getIndexData?repo_login=opengauss&repo_name=opengauss" - when 'mindspore' then "#{url}/v2/getIndexData?repo_login=mindspore&repo_name=mindspore" + when 'kernel' then "#{url}/v2/getIndexData?repo_login=openeuler&repo_name=kernel" + when 'opengauss-server' then "#{url}/v2/getIndexData?repo_login=opengauss&repo_name=openGauss-server" + when 'mindspore' then "#{url}/v2/getIndexData?repo_login=mindspore&repo_name=mindspore" else '' end end @@ -199,9 +199,9 @@ module ProjectsHelper when 'paddle' then "#{url}/paddle/entropy" when 'vue' then "#{url}/vue/entropy" when 'bootstrap' then "#{url}/bootstrap/entropy" - when 'tensorflow' then "#{url}/tensorflow/entropy" - when 'openeuler' then "#{url}/openeuler/entropy" - when 'opengauss' then "#{url}/opengauss/entropy" + when 'tensorflow' then "#{url}/tensorflow/entropy" + when 'kernel' then "#{url}/openeuler/entropy" + when 'opengauss-server' then "#{url}/opengauss/entropy" when 'mindspore' then "#{url}/mindspore/entropy" else '' end From 2302ad9b88aa4752f4b310783984f4891d20457b Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 23 Mar 2023 16:45:48 +0800 Subject: [PATCH 220/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=8C=BA?= =?UTF-8?q?=E5=9D=97=E7=A1=AE=E6=9D=83=E8=B4=A1=E7=8C=AE=E8=80=85=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 18 ++++++++++++------ lib/tasks/sync_mindspore_contributors.rake | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 1d98b17f4..8610f5f16 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -169,12 +169,18 @@ class RepositoriesController < ApplicationController end def contributors - if params[:filepath].present? || @project.educoder? - @contributors = [] - else - result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier, {page: params[:page], limit: params[:limit]}) - @total_count = result[:total_count] - @contributors = result.is_a?(Hash) ? result[:body] : [] + cache_result = $redis_cache.get("ProjectSpecialCommit:#{@project.id}") + if cache_result.present? + @total_count = Project.mindspore_contributors.size + @contributors = kaminari_array_paginate(Project.mindspore_contributors) + else + if params[:filepath].present? || @project.educoder? + @contributors = [] + else + result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier, {page: params[:page], limit: params[:limit]}) + @total_count = result[:total_count] + @contributors = result.is_a?(Hash) ? result[:body] : [] + end end rescue @contributors = [] diff --git a/lib/tasks/sync_mindspore_contributors.rake b/lib/tasks/sync_mindspore_contributors.rake index 0c8ace17c..564ee38eb 100644 --- a/lib/tasks/sync_mindspore_contributors.rake +++ b/lib/tasks/sync_mindspore_contributors.rake @@ -65,7 +65,7 @@ namespace :sync_mindspore do total_contributions = contributions.sum{|i| i["contributions"]} contributions.each do |con| cont_balance = Float(con["contributions"]*9900/total_contributions).round(0) - token_balance << [con["id"], cont_balance] if cont_balance > 0 + token_balance << [con["id"].to_s, cont_balance] if cont_balance > 0 end params = { "request-type": "create repo", From 64d9d21457f2a9b25c0a8a59e08df32af03bad54 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 23 Mar 2023 17:01:19 +0800 Subject: [PATCH 221/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=8C=BA?= =?UTF-8?q?=E5=9D=97=E7=A1=AE=E6=9D=83=E8=B4=A1=E7=8C=AE=E8=80=85=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 4 ++-- app/views/repositories/_contributor.json.jbuilder | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 8610f5f16..d7fdb51ac 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -169,8 +169,8 @@ class RepositoriesController < ApplicationController end def contributors - cache_result = $redis_cache.get("ProjectSpecialCommit:#{@project.id}") - if cache_result.present? + @cache_result = $redis_cache.get("ProjectSpecialCommit:#{@project.id}") + if @cache_result.present? @total_count = Project.mindspore_contributors.size @contributors = kaminari_array_paginate(Project.mindspore_contributors) else diff --git a/app/views/repositories/_contributor.json.jbuilder b/app/views/repositories/_contributor.json.jbuilder index c8b2db373..dca0a93bf 100644 --- a/app/views/repositories/_contributor.json.jbuilder +++ b/app/views/repositories/_contributor.json.jbuilder @@ -6,6 +6,12 @@ if user.blank? json.type nil json.name contributor["login"] json.image_url User::Avatar.get_letter_avatar_url(contributor["login"]) + if @cache_result.present? + db_user = User.find_by_id(contributor["id"]) + if db_user.present? + json.contribution_perc db_user.contribution_perc(project) + end + end else json.contributions contributor["contributions"] # json.gid contributor["id"] From 52eeee31d6df380c8756819042fe66c2b1d09542 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 23 Mar 2023 17:33:38 +0800 Subject: [PATCH 222/438] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/total_commit_count.rake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/tasks/total_commit_count.rake b/lib/tasks/total_commit_count.rake index 7c0f8b470..5b7351825 100644 --- a/lib/tasks/total_commit_count.rake +++ b/lib/tasks/total_commit_count.rake @@ -13,6 +13,7 @@ namespace :total_commit_count do projects.each_with_index do |project, index| result = Gitea::Repository::Commits::ListService.call(project.owner.login,project.identifier,sha: "", page: 1, limit: 5, token: project.owner.gitea_token) total_count = result[:total_count] + next if total_count > 2000 puts "#{index} total_count==========#{total_count}" if total_count > 50 total_page = (total_count / 50) + 1 @@ -22,6 +23,7 @@ namespace :total_commit_count do else add_commit_to_index(project, 1) end + puts "#{index} date_count_hash===========#{@date_count_hash.to_json}" end puts "@date_count_hash===========#{@date_count_hash.to_json}" From 9dd8de07dc5e1dcc7e60d8e4b995d941470aa351 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 23 Mar 2023 17:37:00 +0800 Subject: [PATCH 223/438] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E6=95=B0=20log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/total_commit_count.rake | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/tasks/total_commit_count.rake b/lib/tasks/total_commit_count.rake index 5b7351825..5be659db4 100644 --- a/lib/tasks/total_commit_count.rake +++ b/lib/tasks/total_commit_count.rake @@ -12,6 +12,7 @@ namespace :total_commit_count do # projects = Project.where(:name => 'opensource0311') projects.each_with_index do |project, index| result = Gitea::Repository::Commits::ListService.call(project.owner.login,project.identifier,sha: "", page: 1, limit: 5, token: project.owner.gitea_token) + next if result.blank? || result[:total_count].blank? total_count = result[:total_count] next if total_count > 2000 puts "#{index} total_count==========#{total_count}" From 0fc705fcde046318feea5f70704cf1aa3fbe3824 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 24 Mar 2023 10:56:17 +0800 Subject: [PATCH 224/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E4=B8=AA?= =?UTF-8?q?=E4=BA=BA=E4=B8=BB=E9=A1=B5=E9=A1=B9=E7=9B=AE=E6=96=B0=E5=A2=9E?= =?UTF-8?q?admin=E6=9F=A5=E8=AF=A2=E6=88=91=E7=AE=A1=E7=90=86=E7=9A=84?= =?UTF-8?q?=E4=BB=93=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/queries/projects/list_my_query.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/queries/projects/list_my_query.rb b/app/queries/projects/list_my_query.rb index bc0cda1a2..510ecf9fd 100644 --- a/app/queries/projects/list_my_query.rb +++ b/app/queries/projects/list_my_query.rb @@ -34,6 +34,10 @@ class Projects::ListMyQuery < ApplicationQuery elsif params[:category].to_s == "forked" #我fork的 fork_ids = user.fork_users.select(:id, :fork_project_id).pluck(:fork_project_id) projects = projects.where(id: fork_ids) + elsif params[:category].to_s == "admin" + normal_projects = projects.joins(members: :roles).where(members: {user_id: user.id}, roles: {name: %w(Manager)}).to_sql + org_projects = projects.joins(team_projects: [team: :team_users]).where(teams: {authorize: "owner"},team_users: {user_id: user.id}).to_sql + projects = Project.from("( #{ normal_projects} UNION #{ org_projects } ) AS projects").distinct # elsif params[:category].to_s == "public" # projects = projects.visible.joins(:members).where(members: { user_id: user.id }) # elsif params[:category].to_s == "private" From d6888a03e35c7c30aeaa9afe46c547ff418234fa Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 24 Mar 2023 14:10:33 +0800 Subject: [PATCH 225/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E4=BD=BF=E7=94=A8owner=E7=9A=84gitea=5Ftoken?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 71c174f42..fab93b518 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -262,7 +262,7 @@ class RepositoriesController < ApplicationController archive_url = "/repos/#{@owner.login}/#{@repository.identifier}/archive/#{Addressable::URI.escape(params[:archive])}" file_path = [domain, api_url, archive_url].join - file_path = [file_path, "access_token=#{current_user&.gitea_token}"].join("?") + file_path = [file_path, "access_token=#{@owner&.gitea_token}"].join("?") return render_not_found if !request.format.zip? && !request.format.gzip? @@ -275,7 +275,7 @@ class RepositoriesController < ApplicationController url = "/repos/#{@owner.login}/#{@repository.identifier}/raw/#{Addressable::URI.escape(params[:filepath])}?ref=#{Addressable::URI.escape(params[:ref])}" file_path = [domain, api_url, url].join - file_path = [file_path, "access_token=#{current_user&.gitea_token}"].join("&") + file_path = [file_path, "access_token=#{@owner&.gitea_token}"].join("&") redirect_to file_path end From 2683b03a6931c1743a32d90fdc4e5864acb9e105 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 24 Mar 2023 14:23:11 +0800 Subject: [PATCH 226/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9:=20=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=95=B0=E6=8D=AE=E4=BD=BF=E7=94=A8owner=E7=9A=84toke?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index fab93b518..d5e259893 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -303,16 +303,16 @@ class RepositoriesController < ApplicationController if params[:filepath].present? file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip)) Gitea::Repository::Commits::FileListService.new(@project.owner.login, @project.identifier, file_path_uri, - sha: get_ref, page: 1, limit: 1, token: current_user&.gitea_token).call + sha: get_ref, page: 1, limit: 1, token: @project&.owner&.gitea_token).call else Gitea::Repository::Commits::ListService.new(@project.owner.login, @project.identifier, - sha: get_ref, page: 1, limit: 1, token: current_user&.gitea_token).call + sha: get_ref, page: 1, limit: 1, token: @project&.owner&.gitea_token).call end end def get_statistics @branches_count = @project.educoder? ? 0 : Gitea::Repository::Branches::ListService.new(@project.owner, @project.identifier).call&.size - @tags_count = @project.educoder? ? 0 : Gitea::Repository::Tags::ListService.new(current_user&.gitea_token, @project.owner.login, @project.identifier).call&.size + @tags_count = @project.educoder? ? 0 : Gitea::Repository::Tags::ListService.new(@project&.owner&.gitea_token, @project.owner.login, @project.identifier).call&.size end def get_ref From b37ff07bcfdf46fd6a0c65e57e6f71fa576a9e44 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 24 Mar 2023 14:34:42 +0800 Subject: [PATCH 227/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E4=B8=AA?= =?UTF-8?q?=E4=BA=BA=E9=A1=B9=E7=9B=AE=E5=88=86=E9=A1=B5limit=E4=BD=BF?= =?UTF-8?q?=E7=94=A89999?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 8 ++++++++ app/controllers/users_controller.rb | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 8129df8f1..4e21949b0 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -680,6 +680,14 @@ class ApplicationController < ActionController::Base relation.page(page).per(limit) end + def kaminari_unlimit_paginate(ralation) + limit = params[:limit] || params[:per_page] + limit = (limit.to_i.zero? || limit.to_i > 9999) ? 9999 : limit.to_i + page = params[:page].to_i.zero? ? 1 : params[:page].to_i + + relation.page(page).per(limit) + end + def kaminari_array_paginate(relation) limit = params[:limit] || params[:per_page] limit = (limit.to_i.zero? || limit.to_i > 20) ? 20 : limit.to_i diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 33fd93f83..c4c745a7d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -281,7 +281,7 @@ class UsersController < ApplicationController is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == @user.id) scope = Projects::ListMyQuery.call(params, @user,is_current_admin_user) @total_count = scope.size - @projects = paginate(scope) + @projects = kaminari_unlimit_paginate(scope) end # TODO 其他平台登录时同步修改gitea平台对应用户的密码 From 01467a3d2adcdafa2cec2459d6d77abe8b3eeeb3 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 24 Mar 2023 14:37:42 +0800 Subject: [PATCH 228/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E4=B8=AA?= =?UTF-8?q?=E4=BA=BA=E9=A1=B9=E7=9B=AE=E5=88=86=E9=A1=B5limit=E4=BD=BF?= =?UTF-8?q?=E7=94=A89999?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4e21949b0..517e1b2df 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -680,7 +680,7 @@ class ApplicationController < ActionController::Base relation.page(page).per(limit) end - def kaminari_unlimit_paginate(ralation) + def kaminari_unlimit_paginate(relation) limit = params[:limit] || params[:per_page] limit = (limit.to_i.zero? || limit.to_i > 9999) ? 9999 : limit.to_i page = params[:page].to_i.zero? ? 1 : params[:page].to_i From 29217ff3453d9a43655f8abf689e337971692eef Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 24 Mar 2023 23:05:01 +0800 Subject: [PATCH 229/438] =?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=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/concerns/watchable.rb | 12 +++++++----- .../gitea/repository/contributors/get_service.rb | 9 ++++++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/models/concerns/watchable.rb b/app/models/concerns/watchable.rb index 3ca9f04e3..f152124a8 100644 --- a/app/models/concerns/watchable.rb +++ b/app/models/concerns/watchable.rb @@ -31,7 +31,7 @@ module Watchable following.size end - def mindspore_contribution_perc(project) + def simple_contribution_perc(project) @project = project @user = self @@ -39,14 +39,16 @@ module Watchable (count_user * 1.0 / (count_all + 0.000000001)).round(5) end - if @project['use_blockchain'] == true or @project['use_blockchain'] == 1 + if (@project['use_blockchain'] == true or @project['use_blockchain'] == 1) && @user.id.present? balance_user = Blockchain::BalanceQueryOneProject.call({"user_id": @user.id, "project_id": @project.id}) balance_all = Blockchain::RepoBasicInfo.call({"project_id": @project.id})["cur_supply"] score = cal_perc(balance_user, balance_all) else - commits_all = Project.mindspore_contributors.map{|i| i['contributions']}.sum - commit_user = Project.mindspore_contributors.select{|i| i['login'] == @user.login}.map{|i| i['contributions']}.sum - score = cal_perc(commit_user, commits_all) + contributors = [] + result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier,{q_name: self.login, q_email: self.mail}) + user_contribution = result[:body][0] + commits_all = result[:total_contributions] + score = cal_perc(user_contribution["contributions"], commits_all) end end diff --git a/app/services/gitea/repository/contributors/get_service.rb b/app/services/gitea/repository/contributors/get_service.rb index ea121a50d..cfc2e9340 100644 --- a/app/services/gitea/repository/contributors/get_service.rb +++ b/app/services/gitea/repository/contributors/get_service.rb @@ -1,11 +1,13 @@ class Gitea::Repository::Contributors::GetService < Gitea::ClientService - attr_reader :owner, :repo_name, :page, :limit + attr_reader :owner, :repo_name, :page, :limit, :q_name, :q_email def initialize(owner, repo_name, params) @owner = owner @repo_name = repo_name @page = params[:page] || 1 @limit = params[:limit] || 20 + @q_name = params[:q_name] || "" + @q_email = params[:q_email] || "" end def call @@ -15,7 +17,7 @@ class Gitea::Repository::Contributors::GetService < Gitea::ClientService private def params - Hash.new.merge(token: owner.gitea_token, page: page, limit: limit) + Hash.new.merge(token: owner.gitea_token, page: page, limit: limit, q_name: q_name, q_email: q_email) end def url @@ -29,7 +31,8 @@ class Gitea::Repository::Contributors::GetService < Gitea::ClientService headers = response.headers.to_hash body = JSON.parse(response.body) total_count = headers["x-total"] - result.merge(total_count: total_count.to_i, body: body) + total_contributions = headers["x-total-contributions"] + result.merge(total_count: total_count.to_i, total_contributions: total_contributions.to_i, body: body) else nil # {status: -1, message: "#{body['message']}"} From 4b5df918fcea69345597f2791be77299883f5f22 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 24 Mar 2023 23:35:41 +0800 Subject: [PATCH 230/438] =?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=E5=B1=95=E7=A4=BA=E5=9C=A8=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E8=80=85=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/concerns/watchable.rb | 4 +++- app/views/repositories/_contributor.json.jbuilder | 9 ++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/app/models/concerns/watchable.rb b/app/models/concerns/watchable.rb index f152124a8..a6a89881f 100644 --- a/app/models/concerns/watchable.rb +++ b/app/models/concerns/watchable.rb @@ -45,11 +45,13 @@ module Watchable score = cal_perc(balance_user, balance_all) else contributors = [] - result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier,{q_name: self.login, q_email: self.mail}) + result = Gitea::Repository::Contributors::GetService.call(@user, @project.identifier,{q_name: @user.login, q_email: @user.mail}) user_contribution = result[:body][0] commits_all = result[:total_contributions] score = cal_perc(user_contribution["contributions"], commits_all) end + + (score * 100).round(1).to_s + "%" end def contribution_perc(project) diff --git a/app/views/repositories/_contributor.json.jbuilder b/app/views/repositories/_contributor.json.jbuilder index dca0a93bf..d1bc16024 100644 --- a/app/views/repositories/_contributor.json.jbuilder +++ b/app/views/repositories/_contributor.json.jbuilder @@ -6,12 +6,7 @@ if user.blank? json.type nil json.name contributor["login"] json.image_url User::Avatar.get_letter_avatar_url(contributor["login"]) - if @cache_result.present? - db_user = User.find_by_id(contributor["id"]) - if db_user.present? - json.contribution_perc db_user.contribution_perc(project) - end - end + json.contribution_perc User.new(login: contributor["login"], mail: contributor["email"]).simple_contribution_perc(project) else json.contributions contributor["contributions"] # json.gid contributor["id"] @@ -21,6 +16,6 @@ else json.image_url user["avatar_url"] db_user = User.find_by_id(user["id"]) if db_user.present? - json.contribution_perc db_user.contribution_perc(project) + json.contribution_perc db_user.simple_contribution_perc(project) end end From c7f21fed4fcdf36962c62db797e74971bad19efa Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 24 Mar 2023 23:40:20 +0800 Subject: [PATCH 231/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Awatchable?= =?UTF-8?q?=E4=BD=BF=E7=94=A8project.owner?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/concerns/watchable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/concerns/watchable.rb b/app/models/concerns/watchable.rb index a6a89881f..a8a19a40a 100644 --- a/app/models/concerns/watchable.rb +++ b/app/models/concerns/watchable.rb @@ -45,7 +45,7 @@ module Watchable score = cal_perc(balance_user, balance_all) else contributors = [] - result = Gitea::Repository::Contributors::GetService.call(@user, @project.identifier,{q_name: @user.login, q_email: @user.mail}) + result = Gitea::Repository::Contributors::GetService.call(@project.owner, @project.identifier,{q_name: @user.login, q_email: @user.mail}) user_contribution = result[:body][0] commits_all = result[:total_contributions] score = cal_perc(user_contribution["contributions"], commits_all) From 3bfc6e1c2a7f713c99370bf7764aa06ab88cc2c2 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 24 Mar 2023 23:44:24 +0800 Subject: [PATCH 232/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E8=80=85=E7=A7=BB=E9=99=A4=E8=8E=B7=E5=8F=96cache?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 18 ++++++------------ .../repositories/_contributor.json.jbuilder | 4 ++-- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index d7fdb51ac..1d98b17f4 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -169,18 +169,12 @@ class RepositoriesController < ApplicationController end def contributors - @cache_result = $redis_cache.get("ProjectSpecialCommit:#{@project.id}") - if @cache_result.present? - @total_count = Project.mindspore_contributors.size - @contributors = kaminari_array_paginate(Project.mindspore_contributors) - else - if params[:filepath].present? || @project.educoder? - @contributors = [] - else - result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier, {page: params[:page], limit: params[:limit]}) - @total_count = result[:total_count] - @contributors = result.is_a?(Hash) ? result[:body] : [] - end + if params[:filepath].present? || @project.educoder? + @contributors = [] + else + result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier, {page: params[:page], limit: params[:limit]}) + @total_count = result[:total_count] + @contributors = result.is_a?(Hash) ? result[:body] : [] end rescue @contributors = [] diff --git a/app/views/repositories/_contributor.json.jbuilder b/app/views/repositories/_contributor.json.jbuilder index d1bc16024..e93bdf370 100644 --- a/app/views/repositories/_contributor.json.jbuilder +++ b/app/views/repositories/_contributor.json.jbuilder @@ -2,9 +2,9 @@ user = $redis_cache.hgetall("v2-owner-common:#{contributor["login"]}-#{contribut if user.blank? json.contributions contributor["contributions"] # json.gid contributor["id"] - json.login contributor["login"] + json.login contributor["login"].downcase json.type nil - json.name contributor["login"] + json.name contributor["login"].downcase json.image_url User::Avatar.get_letter_avatar_url(contributor["login"]) json.contribution_perc User.new(login: contributor["login"], mail: contributor["email"]).simple_contribution_perc(project) else From e95eb8bd2372986076c15a925ed3e5f2a420565a Mon Sep 17 00:00:00 2001 From: xxq250 Date: Sat, 25 Mar 2023 10:21:57 +0800 Subject: [PATCH 233/438] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E6=95=B0=E5=88=B0db?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/total_commit_to_db.rake | 65 +++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 lib/tasks/total_commit_to_db.rake diff --git a/lib/tasks/total_commit_to_db.rake b/lib/tasks/total_commit_to_db.rake new file mode 100644 index 000000000..cdb29e108 --- /dev/null +++ b/lib/tasks/total_commit_to_db.rake @@ -0,0 +1,65 @@ +namespace :total_commit_to_db do + desc "total_commit_to_db" + task done: :environment do + project_name = ENV['name'] || "mindspore" + puts "project_id=================#{project_name}" + projects = Project.where(identifier: ['MindSpore-first-experience', ' MindSpore-install', 'MindSpore-Application-practice', 'MindSpore-Model-Development', 'MindSpore-Data-preprocessing', 'Mindspore-Data-storage-use', 'MindSpore-Data-storage-kunpeng', 'MindSpore-LeNet-jzx3', 'MindSpore-competition'] ) + + projects.each_with_index do |project, index| + result = Gitea::Repository::Commits::ListService.call(project.owner.login,project.identifier,sha: "", page: 1, limit: 5, token: project.owner.gitea_token) + next if result.blank? || result[:total_count].blank? + total_count = result[:total_count] + # next if total_count > 2000 + puts "#{index} total_count==========#{total_count}" + if total_count > 200 + total_page = (total_count / 200) + 1 + total_page.times do |i| + add_commit_to_index(project, i + 1) + end + else + # add_commit_to_index(project, 1) + data = "" + result[:body].each do |commit| + commit_date = Time.parse(commit['commit']['author']['date']) + commit_date_str = commit_date.strftime("%Y-%m-%d") + data += "(\"#{commit_date_str}\",1)," + end + data = data[0,data.length-1] + sql_connection = ActiveRecord::Base.connection + sql_connection.begin_db_transaction + sql = "insert into mindspore_commit(week_date,num) values #{data}" + sql_connection.execute(sql) + end + puts "#{index} date_count_hash===========#{@date_count_hash.to_json}" + + end + puts "@date_count_hash===========#{@date_count_hash.to_json}" + + + + + # Time.now + # Wed Mar 15 14:12:09 2023 +0800 + # Time.now.strftime("%a %b %d %H:%M:%S %Y") + # Time.now.strftime("%a %b %d %H:%M:%S %Y +0800") + Time.parse("2023-03-15 14:12:09").strftime("%a %b %d %H:%M:%S %Y +0800") + + end + + def add_commit_to_index(project, page) + # Gitea::Repository::Commits::ListSliceService.call(project.owner.login,project.identifier,sha: "", page: 1, limit: 1000, token: "a9244ecac647dd33fee3b480c5898baab1d3fe7d") + result = Gitea::Repository::Commits::ListService.call(project.owner.login,project.identifier,sha: "", page: page, limit: 200, token: project.owner.gitea_token) + data = "" + result[:body].each do |commit| + commit_date = Time.parse(commit['commit']['author']['date']) + commit_date_str = commit_date.strftime("%Y-%m-%d") + data += "(\"#{commit_date_str}\",1)," + end + data = data[0,data.length-1] + sql_connection = ActiveRecord::Base.connection + sql_connection.begin_db_transaction + sql = "insert into mindspore_commit(week_date,num) values #{data}" + sql_connection.execute(sql) + end + +end \ No newline at end of file From a4e26065b498d3bf4cbdc76b8de01caf40c97bfe Mon Sep 17 00:00:00 2001 From: xxq250 Date: Sat, 25 Mar 2023 10:44:26 +0800 Subject: [PATCH 234/438] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E6=95=B0=E5=88=B0db=EF=BC=8C=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/total_commit_to_db.rake | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/tasks/total_commit_to_db.rake b/lib/tasks/total_commit_to_db.rake index cdb29e108..f6d2c9c83 100644 --- a/lib/tasks/total_commit_to_db.rake +++ b/lib/tasks/total_commit_to_db.rake @@ -3,10 +3,13 @@ namespace :total_commit_to_db do task done: :environment do project_name = ENV['name'] || "mindspore" puts "project_id=================#{project_name}" - projects = Project.where(identifier: ['MindSpore-first-experience', ' MindSpore-install', 'MindSpore-Application-practice', 'MindSpore-Model-Development', 'MindSpore-Data-preprocessing', 'Mindspore-Data-storage-use', 'MindSpore-Data-storage-kunpeng', 'MindSpore-LeNet-jzx3', 'MindSpore-competition'] ) - + if ENV['project_id'].present? + projects = Project.where(id: ENV['project_id']) + else + projects = Project.where(identifier: ['MindSpore-first-experience', ' MindSpore-install', 'MindSpore-Application-practice', 'MindSpore-Model-Development', 'MindSpore-Data-preprocessing', 'Mindspore-Data-storage-use', 'MindSpore-Data-storage-kunpeng', 'MindSpore-LeNet-jzx3', 'MindSpore-competition'] ) + end projects.each_with_index do |project, index| - result = Gitea::Repository::Commits::ListService.call(project.owner.login,project.identifier,sha: "", page: 1, limit: 5, token: project.owner.gitea_token) + result = Gitea::Repository::Commits::ListService.call(project.owner.login,project.identifier,sha: "", page: 1, limit: 200, token: project.owner.gitea_token) next if result.blank? || result[:total_count].blank? total_count = result[:total_count] # next if total_count > 2000 From f5db3273cd1c5739cbdc556d3796890bf839f251 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 27 Mar 2023 13:55:12 +0800 Subject: [PATCH 235/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E4=BB=93=E5=BA=93=E6=95=B0=E6=8D=AE=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E6=8B=A5=E6=9C=89=E8=80=85token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index d5e259893..f03215ace 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -122,10 +122,10 @@ class RepositoriesController < ApplicationController if params[:filepath].present? file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip)) @hash_commit = Gitea::Repository::Commits::FileListService.new(@owner.login, @project.identifier, file_path_uri, - sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call + sha: params[:sha], page: params[:page], limit: params[:limit], token: @owner&.gitea_token).call else @hash_commit = Gitea::Repository::Commits::ListService.new(@owner.login, @project.identifier, - sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call + sha: params[:sha], page: params[:page], limit: params[:limit], token: @owner&.gitea_token).call end end end @@ -140,8 +140,8 @@ class RepositoriesController < ApplicationController if @project.educoder? return render_error('暂未开放,敬请期待.') else - @commit = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token) - @commit_diff = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token, {diff: true}) + @commit = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, @owner&.gitea_token) + @commit_diff = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, @owner&.gitea_token, {diff: true}) render_error(@commit[:message], @commit[:status]) if @commit.has_key?(:status) || @commit_diff.has_key?(:status) end end @@ -156,7 +156,7 @@ class RepositoriesController < ApplicationController @tag_names = result.is_a?(Hash) && result.key?(:status) ? [] : name_result - result = Gitea::Repository::Tags::ListService.call(current_user&.gitea_token, @owner.login, @project.identifier, {page: params[:page], limit: params[:limit]}) + result = Gitea::Repository::Tags::ListService.call(@owner&.gitea_token, @owner.login, @project.identifier, {page: params[:page], limit: params[:limit]}) @tags = result.is_a?(Hash) && result.key?(:status) ? [] : result end From 67fb6fce94cfdf557082833e66b18b467040ac4d Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 27 Mar 2023 14:16:06 +0800 Subject: [PATCH 236/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E4=BB=93=E5=BA=93=E6=95=B0=E6=8D=AE=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E6=8B=A5=E6=9C=89=E8=80=85token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 2 +- app/controllers/pull_requests_controller.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 63427aa45..941dcf35f 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -36,7 +36,7 @@ class AttachmentsController < ApplicationController domain = GiteaService.gitea_config[:domain] api_url = GiteaService.gitea_config[:base_url] url = ("/repos"+url.split(base_url + "/api")[1]).gsub('?filepath=', '/').gsub('&', '?') - request_url = [domain, api_url, url, "?ref=#{params[:ref]}&access_token=#{current_user&.gitea_token}"].join + request_url = [domain, api_url, url, "?ref=#{params[:ref]}&access_token=#{User.where(admin: true).take&.gitea_token}"].join response = Faraday.get(request_url) filename = url.to_s.split("/").pop() else diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 2b9bbbe6f..d02bb1deb 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -173,7 +173,7 @@ class PullRequestsController < ApplicationController @issue_user = @issue.user @issue_assign_to = @issue.get_assign_user @gitea_pull = Gitea::PullRequest::GetService.call(@owner.login, - @repository.identifier, @pull_request.gitea_number, current_user&.gitea_token) + @repository.identifier, @pull_request.gitea_number, @owner&.gitea_token) @last_review = @pull_request.reviews.take end @@ -237,12 +237,12 @@ class PullRequestsController < ApplicationController def files - @files_result = Gitea::PullRequest::FilesService.call(@owner.login, @project.identifier, @pull_request.gitea_number, current_user&.gitea_token) + @files_result = Gitea::PullRequest::FilesService.call(@owner.login, @project.identifier, @pull_request.gitea_number, @owner&.gitea_token) # render json: @files_result end def commits - @commits_result = Gitea::PullRequest::CommitsService.call(@owner.login, @project.identifier, @pull_request.gitea_number, current_user&.gitea_token) + @commits_result = Gitea::PullRequest::CommitsService.call(@owner.login, @project.identifier, @pull_request.gitea_number, @owner&.gitea_token) # render json: @commits_result end From a9ecb5e47ea6501149645f2321510cb382514d26 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 27 Mar 2023 15:11:21 +0800 Subject: [PATCH 237/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E6=9B=B4?= =?UTF-8?q?=E6=94=B9=E5=8F=91=E8=A1=8C=E7=89=88=E6=9D=83=E9=99=90=E9=99=8D?= =?UTF-8?q?=E8=87=B3=E5=BC=80=E5=8F=91=E8=80=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/version_releases_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/version_releases_controller.rb b/app/controllers/version_releases_controller.rb index dd59098f7..8324b05bb 100644 --- a/app/controllers/version_releases_controller.rb +++ b/app/controllers/version_releases_controller.rb @@ -163,7 +163,7 @@ class VersionReleasesController < ApplicationController end def check_release_authorize - return render_forbidden("您没有权限进行此操作.") unless current_user.admin? || @project.manager?(current_user) + return render_forbidden("您没有权限进行此操作.") unless current_user.admin? || @project.develper?(current_user) end end From 1e75c8c0793dfb944afc31e92e86af2fda00c832 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 28 Mar 2023 14:22:32 +0800 Subject: [PATCH 238/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=9B=B4=E6=94=B9=E9=A1=B9=E7=9B=AE=E8=AF=AD=E8=A8=80?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/concerns/repository/languages_percentagable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/concerns/repository/languages_percentagable.rb b/app/controllers/concerns/repository/languages_percentagable.rb index 83374dad1..dce5c7ffc 100644 --- a/app/controllers/concerns/repository/languages_percentagable.rb +++ b/app/controllers/concerns/repository/languages_percentagable.rb @@ -13,7 +13,7 @@ module Repository::LanguagesPercentagable def update_project_language(language) return if @project.project_language.present? db_language = ProjectLanguage.find_or_create_by!(name: language.keys.first.downcase.upcase_first) - @project.update_column(:project_language_id, db_language.id) + @project.update_attribute(:project_language_id, db_language.id) rescue return end From 007edd38bea3c7cb478a57be7bf6bde3d55aac32 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 28 Mar 2023 14:36:05 +0800 Subject: [PATCH 239/438] =?UTF-8?q?=E9=87=8D=E5=86=99user.gitea=5Ftoken,?= =?UTF-8?q?=E5=BD=93=E7=94=A8=E6=88=B7=E4=B8=BAbot=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E6=9B=BF=E6=8D=A2=E6=88=90=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/user.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/models/user.rb b/app/models/user.rb index 5e21212ab..dbaf74ccc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -845,6 +845,15 @@ class User < Owner end end + # 重写gitea_token,当用户为bot类型时,替换成管理员token + def gitea_token + if self.platform == "bot" + GiteaService.gitea_config[:admin_token] + else + self['gitea_token'] + end + end + protected def validate_password_length # 管理员的初始密码是5位 From 38ddb850c1e6f8f166f45163b47b3889fb9ac845 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 28 Mar 2023 14:36:58 +0800 Subject: [PATCH 240/438] =?UTF-8?q?=E9=87=8D=E5=86=99user.gitea=5Ftoken,?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=98token,yml=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/configuration.yml.example | 1 + 1 file changed, 1 insertion(+) diff --git a/config/configuration.yml.example b/config/configuration.yml.example index 6ae32e4f3..b446c0109 100644 --- a/config/configuration.yml.example +++ b/config/configuration.yml.example @@ -55,6 +55,7 @@ default: &default access_key_secret: '' domain: 'https://testgit.trustie.net' base_url: '/api/v1' + admin_token: '123123' accelerator: access_key_id: '' access_key_secret: '' From ca449ccc8a2a97737f516435ecce0051a2d55d93 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 28 Mar 2023 14:38:44 +0800 Subject: [PATCH 241/438] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=9D=83=E9=99=90?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0bot=E7=94=A8=E6=88=B7=E6=9D=83=E9=99=90?= =?UTF-8?q?=EF=BC=8C=E5=B7=B2=E5=AE=89=E8=A3=85bot=EF=BC=8C=E5=BD=93?= =?UTF-8?q?=E5=89=8Dbot=E7=94=A8=E6=88=B7=E5=8D=B3=E6=8B=A5=E6=9C=89?= =?UTF-8?q?=E6=9D=83=E9=99=90=EF=BC=8C=E6=9D=83=E9=99=90=E7=B2=92=E5=BA=A6?= =?UTF-8?q?=E5=BE=85=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/concerns/project_operable.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/models/concerns/project_operable.rb b/app/models/concerns/project_operable.rb index 0bac02ce6..d5d45a468 100644 --- a/app/models/concerns/project_operable.rb +++ b/app/models/concerns/project_operable.rb @@ -190,22 +190,24 @@ module ProjectOperable end # 项目管理员(包含项目拥有者),权限:仓库设置、仓库可读可写 + # 增加bot用户权限,已安装bot,当前bot用户即拥有权限,权限粒度待完善 def manager?(user) if owner.is_a?(User) - managers.exists?(user_id: user.id) + managers.exists?(user_id: user.id) || (user.platform == "bot" && BotInstall.joins(:bot).where(bot: { uid: user.id }).where(store_id: self.id).exists?) elsif owner.is_a?(Organization) - managers.exists?(user_id: user.id) || owner.is_owner?(user.id) || (owner.is_only_admin?(user.id) && (teams.pluck(:id) & user.teams.pluck(:id)).size > 0) + managers.exists?(user_id: user.id) || owner.is_owner?(user.id) || (owner.is_only_admin?(user.id) && (teams.pluck(:id) & user.teams.pluck(:id)).size > 0) || (user.platform == "bot" && BotInstall.joins(:bot).where(bot: { uid: user.id }).where(store_id: self.id).exists?) else false end end # 项目开发者,可读可写权限 + # 增加bot用户权限,已安装当前bot用户对应的bot即拥有权限,权限粒度待完善 def develper?(user) if owner.is_a?(User) - developers.exists?(user_id: user.id) + developers.exists?(user_id: user.id) || (user.platform == "bot" && BotInstall.joins(:bot).where(bot: { uid: user.id }).where(store_id: self.id).exists?) elsif owner.is_a?(Organization) - developers.exists?(user_id: user.id) || (owner.is_only_write?(user.id) && (teams.pluck(:id) & user.teams.pluck(:id)).size > 0) + developers.exists?(user_id: user.id) || (owner.is_only_write?(user.id) && (teams.pluck(:id) & user.teams.pluck(:id)).size > 0) || (user.platform == "bot" && BotInstall.joins(:bot).where(bot: { uid: user.id }).where(store_id: self.id).exists?) else false end From b8869bd0e2dc78bdef742592516cc773c8cc678f Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 28 Mar 2023 14:48:11 +0800 Subject: [PATCH 242/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E8=80=85=E8=B4=A1=E7=8C=AE=E5=8D=A0=E6=AF=94=E8=AE=A1?= =?UTF-8?q?=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/concerns/watchable.rb | 20 +++++++++++++++++++ .../repositories/_contributor.json.jbuilder | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/watchable.rb b/app/models/concerns/watchable.rb index dc2b67f67..31093cad1 100644 --- a/app/models/concerns/watchable.rb +++ b/app/models/concerns/watchable.rb @@ -31,6 +31,26 @@ module Watchable following.size end + def simple_contribution_perc(project, perc=nil) + @project = project + @user = self + + def cal_perc(count_user, count_all) + (count_user * 1.0 / (count_all + 0.000000001)).round(5) + end + + if (@project['use_blockchain'] == true or @project['use_blockchain'] == 1) && @user.id.present? + balance_user = Blockchain::BalanceQueryOneProject.call({"user_id": @user.id, "project_id": @project.id}) + balance_all = Blockchain::RepoBasicInfo.call({"project_id": @project.id})["cur_supply"] + score = cal_perc(balance_user, balance_all) + score = (score * 100).round(1).to_s + "%" + else + score = perc + end + + score + end + def contribution_perc(project) @project = project @user = self diff --git a/app/views/repositories/_contributor.json.jbuilder b/app/views/repositories/_contributor.json.jbuilder index bd1a037f7..41edbf4af 100644 --- a/app/views/repositories/_contributor.json.jbuilder +++ b/app/views/repositories/_contributor.json.jbuilder @@ -6,6 +6,7 @@ if user.blank? json.type nil json.name contributor["login"] json.image_url User::Avatar.get_letter_avatar_url(contributor["login"]) + json.contribution_perc User.new(login: contributor["login"], mail: contributor["email"]).simple_contribution_perc(project, contributor["contribution_perc"]) else json.contributions contributor["contributions"] # json.gid contributor["id"] @@ -14,5 +15,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) if db_user.present? + json.contribution_perc db_user.simple_contribution_perc(project) if db_user.present? end From 33e503ed9a72aa0538628a206e2fbbbcdf2cd036 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 28 Mar 2023 14:57:35 +0800 Subject: [PATCH 243/438] =?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 41edbf4af..49ec699bc 100644 --- a/app/views/repositories/_contributor.json.jbuilder +++ b/app/views/repositories/_contributor.json.jbuilder @@ -15,5 +15,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.simple_contribution_perc(project) if db_user.present? + json.contribution_perc db_user.simple_contribution_perc(project, contributor["contribution_perc"]) if db_user.present? end From 7e0158345c82abd3041e88abbf92b84db48b552d Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 28 Mar 2023 15:00:37 +0800 Subject: [PATCH 244/438] =?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 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/repositories/_contributor.json.jbuilder b/app/views/repositories/_contributor.json.jbuilder index 49ec699bc..bbfa08262 100644 --- a/app/views/repositories/_contributor.json.jbuilder +++ b/app/views/repositories/_contributor.json.jbuilder @@ -1,12 +1,12 @@ -user = $redis_cache.hgetall("v2-owner-common:#{contributor["login"]}-#{contributor["email"]}") +user = $redis_cache.hgetall("v2-owner-common:#{contributor["name"]}-#{contributor["email"]}") if user.blank? json.contributions contributor["contributions"] # json.gid contributor["id"] - json.login contributor["login"] + json.login contributor["name"] json.type nil - json.name contributor["login"] - json.image_url User::Avatar.get_letter_avatar_url(contributor["login"]) - json.contribution_perc User.new(login: contributor["login"], mail: contributor["email"]).simple_contribution_perc(project, contributor["contribution_perc"]) + json.name contributor["name"] + json.image_url User::Avatar.get_letter_avatar_url(contributor["name"]) + json.contribution_perc User.new(login: contributor["name"], mail: contributor["email"]).simple_contribution_perc(project, contributor["contribution_perc"]) else json.contributions contributor["contributions"] # json.gid contributor["id"] From 6a6a257d2a51169150be5ccdd11fe05a473b21c8 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 28 Mar 2023 15:03:13 +0800 Subject: [PATCH 245/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E8=80=85=E5=A4=A7=E5=B0=8F=E5=86=99=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=AD=A3=E5=B8=B8=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/repositories/_contributor.json.jbuilder | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/repositories/_contributor.json.jbuilder b/app/views/repositories/_contributor.json.jbuilder index bbfa08262..fa5151264 100644 --- a/app/views/repositories/_contributor.json.jbuilder +++ b/app/views/repositories/_contributor.json.jbuilder @@ -2,17 +2,17 @@ user = $redis_cache.hgetall("v2-owner-common:#{contributor["name"]}-#{contributo if user.blank? json.contributions contributor["contributions"] # json.gid contributor["id"] - json.login contributor["name"] + json.login contributor["name"].downcase json.type nil - json.name contributor["name"] + json.name contributor["name"].downcase json.image_url User::Avatar.get_letter_avatar_url(contributor["name"]) json.contribution_perc User.new(login: contributor["name"], mail: contributor["email"]).simple_contribution_perc(project, contributor["contribution_perc"]) else json.contributions contributor["contributions"] # json.gid contributor["id"] - json.login user["login"] + json.login user["login"].downcase json.type user["type"] - json.name user["name"] + json.name user["name"].downcase json.image_url user["avatar_url"] db_user = User.find_by_id(user["id"]) json.contribution_perc db_user.simple_contribution_perc(project, contributor["contribution_perc"]) if db_user.present? From 6992bf4959955271fba2d174a277ed91ce59b479 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 28 Mar 2023 15:15:08 +0800 Subject: [PATCH 246/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=9C=80?= =?UTF-8?q?=E6=96=B0=E8=B4=A1=E7=8C=AE=E8=80=85=E8=AF=BB=E5=8F=96=E8=A7=84?= =?UTF-8?q?=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/repositories/_contributor.json.jbuilder | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/views/repositories/_contributor.json.jbuilder b/app/views/repositories/_contributor.json.jbuilder index fa5151264..4a8f5611d 100644 --- a/app/views/repositories/_contributor.json.jbuilder +++ b/app/views/repositories/_contributor.json.jbuilder @@ -1,14 +1,16 @@ user = $redis_cache.hgetall("v2-owner-common:#{contributor["name"]}-#{contributor["email"]}") if user.blank? - json.contributions contributor["contributions"] + json.contributions contributor["commits"] # json.gid contributor["id"] - json.login contributor["name"].downcase + json.login nil json.type nil json.name contributor["name"].downcase + json.email contributor["email"] json.image_url User::Avatar.get_letter_avatar_url(contributor["name"]) json.contribution_perc User.new(login: contributor["name"], mail: contributor["email"]).simple_contribution_perc(project, contributor["contribution_perc"]) else - json.contributions contributor["contributions"] + json.contributions contributor["commits"] + json.id user["id"] # json.gid contributor["id"] json.login user["login"].downcase json.type user["type"] From 4bf14974dfb212aa7a6fb4f3d81477cc16574b11 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 28 Mar 2023 15:51:51 +0800 Subject: [PATCH 247/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=98=AF=E5=90=A6=E5=88=9B=E5=BB=BA=E4=BA=86pr?= =?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/views/pull_requests/index.json.jbuilder | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/pull_requests/index.json.jbuilder b/app/views/pull_requests/index.json.jbuilder index ace52945c..299db0283 100644 --- a/app/views/pull_requests/index.json.jbuilder +++ b/app/views/pull_requests/index.json.jbuilder @@ -9,6 +9,7 @@ json.user_admin_or_developer @user_admin_or_developer json.project_name @project.name json.project_author @project.owner.try(:login) json.project_author_name @project.owner.try(:show_real_name) +json.has_created_pull_requests @project.pull_requests.size > 0 json.issues do json.array! @issues.to_a do |issue| From 189348cbd816d3180555daffbd2151f4debe6571 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 29 Mar 2023 10:12:32 +0800 Subject: [PATCH 248/438] =?UTF-8?q?=E6=9B=B4=E6=8D=A2bot=20client=5Fid?= =?UTF-8?q?=E7=94=9F=E6=88=90=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index d299f6710..2addade2d 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -29,7 +29,7 @@ class InstallationsController < ApplicationController begin @bot = Bot.find params[:id] tip_exception("该Bot已激活") if Doorkeeper::Application.find_by(uid: @bot.client_id, secret: @bot.client_secret).present? - @bot.client_id = Doorkeeper::OAuth::Helpers::UniqueToken.generate if params[:client_id].blank? + @bot.client_id = SecureRandom.uuid.gsub("-", "") if params[:client_id].blank? @bot.client_secret = Doorkeeper::OAuth::Helpers::UniqueToken.generate if params[:client_secret].blank? @bot.private_key = OpenSSL::PKey::RSA::generate(2048).to_s @bot.owner_id = current_user.id From f0dca4c0c134a92f821ded78501fcfeabc097587 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 29 Mar 2023 14:14:25 +0800 Subject: [PATCH 249/438] =?UTF-8?q?softbot=E8=A1=A5=E5=85=85=E5=92=8C?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 32 +++++++++++++++++++ app/views/installations/app.json.jbuilder | 4 +++ app/views/installations/index.json.jbuilder | 3 ++ .../installations/repositories.json.jbuilder | 15 +++++++++ app/views/installations/show.json.jbuilder | 5 +++ config/routes.rb | 11 +++++-- 6 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 app/views/installations/app.json.jbuilder create mode 100644 app/views/installations/repositories.json.jbuilder create mode 100644 app/views/installations/show.json.jbuilder diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index 2addade2d..fb819444a 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -2,10 +2,23 @@ class InstallationsController < ApplicationController include RegisterHelper before_action :require_login + # app详情 + def app + @bot = Bot.find_by(uid: current_user.id) + end + def index @install_bots = BotInstall.where(:installer_id => current_user.id) end + def show + @install_bot = BotInstall.find params[:id] + end + + def repositories + @install_bots = BotInstall.where(:installer_id => current_user.id) + end + def update_secret ActiveRecord::Base.transaction do bot = Bot.find params[:id] @@ -25,6 +38,24 @@ class InstallationsController < ApplicationController render_ok end + def update_callback_url + bot = Bot.find params[:id] + application = Doorkeeper::Application.find_by(uid: bot.client_id, secret: bot.client_secret) + # application.redirect_uri = bot.callback_url + application.save + render_ok + end + + def suspended + @install_bot = BotInstall.find params[:id] + @install_bot.update_attributes!(state: 0) + render_ok + end + def unsuspended + @install_bot = BotInstall.find params[:id] + @install_bot.update_attributes!(state: 1) + render_ok + end def auth_active begin @bot = Bot.find params[:id] @@ -60,6 +91,7 @@ class InstallationsController < ApplicationController :expires_in => "604800", :use_refresh_token => true }) + @install_bot.update_attributes!(state: 1) render_ok(token: @access_token.token) end diff --git a/app/views/installations/app.json.jbuilder b/app/views/installations/app.json.jbuilder new file mode 100644 index 000000000..cc738e6b9 --- /dev/null +++ b/app/views/installations/app.json.jbuilder @@ -0,0 +1,4 @@ +json.partial! "commons/success" + +json.extract! @bot, :id, :bot_name, :bot_des, :webhook, :is_public, :logo, :state, :web_url, :install_num, :owner_id, :create_time, :update_time + diff --git a/app/views/installations/index.json.jbuilder b/app/views/installations/index.json.jbuilder index 3d64a3323..2163567ed 100644 --- a/app/views/installations/index.json.jbuilder +++ b/app/views/installations/index.json.jbuilder @@ -4,5 +4,8 @@ json.data do json.array! @install_bots do |install_bot| json.installation_id install_bot.id json.extract! install_bot.bot, :id, :name + json.bot_id install_bot.bot.id + json.bot_name install_bot.bot.name + end end \ No newline at end of file diff --git a/app/views/installations/repositories.json.jbuilder b/app/views/installations/repositories.json.jbuilder new file mode 100644 index 000000000..01e873378 --- /dev/null +++ b/app/views/installations/repositories.json.jbuilder @@ -0,0 +1,15 @@ +json.status 0 +json.message "success" +json.total_count @install_bots.size +json.repositories do + json.array! @install_bots do |install_bot| + project = Project.find_by(id: install_bot.store_id) + if project.present? + json.id install_bot.store_id + json.url "#{base_url}/#{project.owner.login}/#{project.owner.identifier}.git" + json.name project.owner.identifier + json.owner_name project.owner.login + json.is_public project.is_public + end + end +end \ No newline at end of file diff --git a/app/views/installations/show.json.jbuilder b/app/views/installations/show.json.jbuilder new file mode 100644 index 000000000..33c7ba206 --- /dev/null +++ b/app/views/installations/show.json.jbuilder @@ -0,0 +1,5 @@ +json.partial! "commons/success" + +json.extract! @install_bot, :id, :bot_id, :installer_id, :state, :create_time, :update_time +json.bot_name @install_bot.bot.name + diff --git a/config/routes.rb b/config/routes.rb index c544c9198..9c280e2bf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1064,18 +1064,23 @@ Rails.application.routes.draw do resources :commit_logs, :only => [:create] scope '/app' do + get '/', to: 'installations#app' post ':id/auth_active', to: 'installations#auth_active' post ':id/update_private_key', to: 'installations#update_private_key' post ':id/update_secret', to: 'installations#update_secret' - resources :installations do - get :repositories, on: :collection + resources :installations, only: [:index, :show] do member do post :access_tokens - put :suspended + put :suspended, to: 'installations#suspended' + delete :suspended, to: 'installations#unsuspended' end end end + resources :installations, only: [] do + get :repositories, on: :collection + end + root 'main#index' From abaec8c1156475b0d77bbc5243de0b023c981d4f Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 29 Mar 2023 14:22:11 +0800 Subject: [PATCH 250/438] =?UTF-8?q?softbot=E8=A1=A5=E5=85=85=E5=92=8C?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=8E=A5=E5=8F=A3=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/installations/app.json.jbuilder | 5 +++-- app/views/installations/repositories.json.jbuilder | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/views/installations/app.json.jbuilder b/app/views/installations/app.json.jbuilder index cc738e6b9..598cd1725 100644 --- a/app/views/installations/app.json.jbuilder +++ b/app/views/installations/app.json.jbuilder @@ -1,4 +1,5 @@ json.partial! "commons/success" - -json.extract! @bot, :id, :bot_name, :bot_des, :webhook, :is_public, :logo, :state, :web_url, :install_num, :owner_id, :create_time, :update_time +if @bot.present? + json.extract! @bot, :id, :bot_name, :bot_des, :webhook, :is_public, :logo, :state, :web_url, :install_num, :owner_id, :create_time, :update_time +end diff --git a/app/views/installations/repositories.json.jbuilder b/app/views/installations/repositories.json.jbuilder index 01e873378..6d17f2770 100644 --- a/app/views/installations/repositories.json.jbuilder +++ b/app/views/installations/repositories.json.jbuilder @@ -6,8 +6,10 @@ json.repositories do project = Project.find_by(id: install_bot.store_id) if project.present? json.id install_bot.store_id - json.url "#{base_url}/#{project.owner.login}/#{project.owner.identifier}.git" - json.name project.owner.identifier + json.url "#{base_url}/#{project.owner.login}/#{project.identifier}.git" + json.identifier project.identifier + json.name project.name + json.description Nokogiri::HTML(project.description).text json.owner_name project.owner.login json.is_public project.is_public end From 7045fb3960b742e3fda3a0ba6f617a9a846d3939 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 29 Mar 2023 16:57:19 +0800 Subject: [PATCH 251/438] =?UTF-8?q?oauth=20=E5=9B=9E=E8=B0=83=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E5=85=81=E8=AE=B8=E9=9D=9Ehttps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/initializers/doorkeeper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/doorkeeper.rb b/config/initializers/doorkeeper.rb index 0cc9a02a4..9655f88cc 100644 --- a/config/initializers/doorkeeper.rb +++ b/config/initializers/doorkeeper.rb @@ -285,7 +285,7 @@ Doorkeeper.configure do # #call can be used in order to allow conditional checks (to allow non-SSL # redirects to localhost for example). # - # force_ssl_in_redirect_uri !Rails.env.development? + force_ssl_in_redirect_uri false # # force_ssl_in_redirect_uri { |uri| uri.host != 'localhost' } From 3d61b920ace96af566e0a81bd5dac39680688667 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 29 Mar 2023 17:29:42 +0800 Subject: [PATCH 252/438] =?UTF-8?q?=E5=90=8C=E6=AD=A5bot=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=EF=BC=8C=E5=9B=9E=E8=B0=83=E5=9C=B0=E5=9D=80=E5=92=8C=E5=90=8D?= =?UTF-8?q?=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index fb819444a..66baf1050 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -38,10 +38,16 @@ class InstallationsController < ApplicationController render_ok end + # 同步bot信息,回调地址和名称 def update_callback_url bot = Bot.find params[:id] application = Doorkeeper::Application.find_by(uid: bot.client_id, secret: bot.client_secret) - # application.redirect_uri = bot.callback_url + application.redirect_uri = bot.oauth_callback_url + application.name = bot.name + if bot.uid.present? + bot_user = User.find_by(id: bot.uid) + bot_user.update_column(:nickname, bot.name) if bot_user.present? + end application.save render_ok end @@ -66,7 +72,7 @@ class InstallationsController < ApplicationController @bot.owner_id = current_user.id ActiveRecord::Base.transaction do # 注册bot对应oauth应用 - Doorkeeper::Application.create!(name: @bot.name, uid: @bot.client_id, secret: @bot.client_secret, redirect_uri: "https://gitlink.org.cn") + Doorkeeper::Application.create!(name: @bot.name, uid: @bot.client_id, secret: @bot.client_secret, redirect_uri: @bot.oauth_callback_url) # 注册bot对应用户 result = autologin_register(User.generate_user_login('b'), nil, "#{SecureRandom.hex(6)}", 'bot', nil, @bot.name) tip_exception(-1, result[:message]) if result[:message].present? From 0e009202fcf0862343655714bd0c4112085fc24e Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 29 Mar 2023 17:58:52 +0800 Subject: [PATCH 253/438] =?UTF-8?q?=E5=90=8C=E6=AD=A5bot=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=EF=BC=8C=E5=9B=9E=E8=B0=83=E5=9C=B0=E5=9D=80=E5=92=8C=E5=90=8D?= =?UTF-8?q?=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/routes.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/routes.rb b/config/routes.rb index 9c280e2bf..fb4e6185c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1068,6 +1068,7 @@ Rails.application.routes.draw do post ':id/auth_active', to: 'installations#auth_active' post ':id/update_private_key', to: 'installations#update_private_key' post ':id/update_secret', to: 'installations#update_secret' + post ':id/update_callback_url', to: 'installations#update_callback_url' resources :installations, only: [:index, :show] do member do post :access_tokens From 4fdb28ec3c7a47d43ddf720eb2ba6f76a5274c46 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 29 Mar 2023 18:13:17 +0800 Subject: [PATCH 254/438] =?UTF-8?q?bot=E6=8E=88=E6=9D=83token=E6=9C=89?= =?UTF-8?q?=E6=95=88=E6=9C=9F=E6=94=B9=E4=B8=BA30=E5=A4=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index 66baf1050..f7bf4f0d6 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -94,7 +94,7 @@ class InstallationsController < ApplicationController @access_token = Doorkeeper::AccessToken.create!({ :application_id => @application.id, :resource_owner_id => @bot.uid, :scopes => "public write", - :expires_in => "604800", + :expires_in => "2592000", :use_refresh_token => true }) @install_bot.update_attributes!(state: 1) From e1b17d1dfa99af8b22a4721f521ec9a54be73a55 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 30 Mar 2023 11:44:39 +0800 Subject: [PATCH 255/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Awebhook?= =?UTF-8?q?=E7=B1=BB=E5=9E=8Bsoftbot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/projects/webhooks/create_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/api/v1/projects/webhooks/create_service.rb b/app/services/api/v1/projects/webhooks/create_service.rb index edc8b2263..a6ee5e6c1 100644 --- a/app/services/api/v1/projects/webhooks/create_service.rb +++ b/app/services/api/v1/projects/webhooks/create_service.rb @@ -8,7 +8,7 @@ class Api::V1::Projects::Webhooks::CreateService < ApplicationService validates :active, inclusion: {in: [true, false]} validates :http_method, inclusion: { in: %w(POST GET), message: "请输入正确的请求方式"} validates :content_type, inclusion: { in: %w(json form), message: "请输入正确的Content Type"} - validates :type, inclusion: {in: %w(gitea slack discord dingtalk telegram msteams feishu matrix jianmu), message: "请输入正确的Webhook Type"} + validates :type, inclusion: {in: %w(gitea slack discord dingtalk telegram msteams feishu matrix jianmu softbot), message: "请输入正确的Webhook Type"} def initialize(project, params, token=nil) @project = project @owner = project&.owner.login From 428864952896822ee8c83d0c4c8b449ab2113cf2 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 30 Mar 2023 14:34:17 +0800 Subject: [PATCH 256/438] =?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=E5=8C=BA=E5=9D=97=E9=93=BE=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E9=9C=80=E8=A6=81=E5=85=A8=E5=B1=80=E5=BC=80=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/concerns/watchable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/concerns/watchable.rb b/app/models/concerns/watchable.rb index 31093cad1..6d3d94e66 100644 --- a/app/models/concerns/watchable.rb +++ b/app/models/concerns/watchable.rb @@ -39,7 +39,7 @@ module Watchable (count_user * 1.0 / (count_all + 0.000000001)).round(5) end - if (@project['use_blockchain'] == true or @project['use_blockchain'] == 1) && @user.id.present? + if Site.has_blockchain? && (@project['use_blockchain'] == true or @project['use_blockchain'] == 1) && @user.id.present? balance_user = Blockchain::BalanceQueryOneProject.call({"user_id": @user.id, "project_id": @project.id}) balance_all = Blockchain::RepoBasicInfo.call({"project_id": @project.id})["cur_supply"] score = cal_perc(balance_user, balance_all) From c78badf0917277ee2b273254abd330df85306823 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 31 Mar 2023 10:11:30 +0800 Subject: [PATCH 257/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E5=8F=91=E8=A1=8C=E7=89=88403?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/version_releases_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/version_releases_controller.rb b/app/controllers/version_releases_controller.rb index 8324b05bb..76a214d0f 100644 --- a/app/controllers/version_releases_controller.rb +++ b/app/controllers/version_releases_controller.rb @@ -163,7 +163,7 @@ class VersionReleasesController < ApplicationController end def check_release_authorize - return render_forbidden("您没有权限进行此操作.") unless current_user.admin? || @project.develper?(current_user) + return render_forbidden("您没有权限进行此操作.") unless current_user.admin? || @project.manager?(current_user) || @project.develper?(current_user) end end From 53458dab8fc6bec527e94c50bca8a1839e4d853d Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 31 Mar 2023 10:31:10 +0800 Subject: [PATCH 258/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=88=86?= =?UTF-8?q?=E6=94=AF=E8=BF=94=E5=9B=9E=E6=9B=B4=E6=94=B9=E4=B8=BA=E6=95=B0?= =?UTF-8?q?=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 2 +- app/controllers/traces/projects_controller.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 52c776477..2d9ddc014 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -94,7 +94,7 @@ class ProjectsController < ApplicationController # result = Gitea::Repository::Branches::ListService.call(@owner, @project.identifier) result = Gitea::Repository::Branches::ListNameService.call(@owner, @project.identifier, params[:name]) - @branches = result.is_a?(Hash) ? (result.key?(:status) ? [] : result["branch_name"]) : result + @branches = result.is_a?(Hash) ? (result.key?(:status) ? [] : result) : result end def branches_slice diff --git a/app/controllers/traces/projects_controller.rb b/app/controllers/traces/projects_controller.rb index 74e683f85..1377b4522 100644 --- a/app/controllers/traces/projects_controller.rb +++ b/app/controllers/traces/projects_controller.rb @@ -12,7 +12,7 @@ class Traces::ProjectsController < Traces::BaseController return render_error("无可用检测次数") if @project.user_trace_tasks.size >= 5 return render_error("分支名不能为空!") if branch_name.blank? @all_branches = Gitea::Repository::Branches::ListNameService.call(@project&.owner, @project.identifier) - return render_error("请输入正确的分支名!") unless @all_branches["branch_name"].include?(branch_name) + return render_error("请输入正确的分支名!") unless @all_branches.include?(branch_name) code, data, error = Trace::CheckService.call(current_user.trace_token, @project, "1", branch_name) if code == 200 UserTraceTask.create!( @@ -51,7 +51,7 @@ class Traces::ProjectsController < Traces::BaseController branch_name = params[:branch_name] return render_error("分支名不能为空!") if branch_name.blank? @all_branches = Gitea::Repository::Branches::ListNameService.call(@project&.owner, @project.identifier) - return render_error("请输入正确的分支名!") unless @all_branches["branch_name"].include?(branch_name) + return render_error("请输入正确的分支名!") unless @all_branches.include?(branch_name) code, data, error = Trace::ReloadCheckService.call(current_user.trace_token, params[:project_id]) if code == 200 UserTraceTask.create!( From 56790f85588ff7e1a5762dcbb4ddaa40ffc48078 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 31 Mar 2023 11:18:58 +0800 Subject: [PATCH 259/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E5=BA=A6=E8=AF=BB=E5=8F=96=E6=95=B0=E6=8D=AE=E8=A7=84?= =?UTF-8?q?=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users/headmaps_controller.rb | 14 ++++++++++++-- app/views/users/headmaps/index.json.jbuilder | 8 ++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/controllers/users/headmaps_controller.rb b/app/controllers/users/headmaps_controller.rb index 83efd99fb..15ce56769 100644 --- a/app/controllers/users/headmaps_controller.rb +++ b/app/controllers/users/headmaps_controller.rb @@ -2,6 +2,16 @@ class Users::HeadmapsController < Users::BaseController def index result = Gitea::User::HeadmapService.call(observed_user.login, start_stamp, end_stamp, observed_user&.gitea_token) @headmaps = result[2].blank? ? [] : result[2] + headmaps_result = {} + @headmaps.each do |entry| + date = Time.at(entry["timestamp"]).strftime("%Y-%m-%d") + if headmaps_result[date].nil? + headmaps_result[date] = { "contributions" => entry["contributions"] } + else + headmaps_result[date]["contributions"] += entry["contributions"] + end + end + @headmaps = headmaps_result rescue Exception => e uid_logger_error(e.message) tip_exception(e.message) @@ -18,9 +28,9 @@ class Users::HeadmapsController < Users::BaseController def end_stamp if params[:year].present? - (Date.new(params[:year].to_i, 1) + 1.years).to_time.to_i + (Date.new(params[:year].to_i, 1) + 1.years).to_time.end_of_day.to_i else - Date.today.to_time.to_i + Date.today.to_time.end_of_day.to_i end end end \ No newline at end of file diff --git a/app/views/users/headmaps/index.json.jbuilder b/app/views/users/headmaps/index.json.jbuilder index 0e6a540b5..30f3ff4b4 100644 --- a/app/views/users/headmaps/index.json.jbuilder +++ b/app/views/users/headmaps/index.json.jbuilder @@ -1,5 +1,5 @@ -json.total_contributions @headmaps.collect{|map| map["contributions"]}.reduce(0, :+) -json.headmaps @headmaps.each do |map| - json.date Time.at(map["timestamp"].to_i).strftime("%Y-%m-%d") - json.contributions map["contributions"] +json.total_contributions @headmaps.collect{|k, value| value["contributions"]}.reduce(0, :+) +json.headmaps @headmaps.each do |k, value| + json.date k + json.contributions value["contributions"] end From 5226196f4eb0cae9b0453f1c6ae751bbfa204028 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 31 Mar 2023 14:57:56 +0800 Subject: [PATCH 260/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=AE=A1=E7=90=86=E7=9A=84=E9=A1=B9=E7=9B=AE=E9=9C=80?= =?UTF-8?q?=E5=8C=85=E6=8B=ACadmin=E5=9B=A2=E9=98=9F=E4=B8=8B=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/queries/projects/list_my_query.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/queries/projects/list_my_query.rb b/app/queries/projects/list_my_query.rb index 510ecf9fd..acea71f31 100644 --- a/app/queries/projects/list_my_query.rb +++ b/app/queries/projects/list_my_query.rb @@ -36,7 +36,7 @@ class Projects::ListMyQuery < ApplicationQuery projects = projects.where(id: fork_ids) elsif params[:category].to_s == "admin" normal_projects = projects.joins(members: :roles).where(members: {user_id: user.id}, roles: {name: %w(Manager)}).to_sql - org_projects = projects.joins(team_projects: [team: :team_users]).where(teams: {authorize: "owner"},team_users: {user_id: user.id}).to_sql + org_projects = projects.joins(team_projects: [team: :team_users]).where(teams: {authorize: %w(owner admin)},team_users: {user_id: user.id}).to_sql projects = Project.from("( #{ normal_projects} UNION #{ org_projects } ) AS projects").distinct # elsif params[:category].to_s == "public" # projects = projects.visible.joins(:members).where(members: { user_id: user.id }) From 6f0595616d8f63b6dbcb75652e3f64d7e0d537b2 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 31 Mar 2023 17:23:58 +0800 Subject: [PATCH 261/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E9=82=AE=E7=AE=B1=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/users/update_email_service.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/services/api/v1/users/update_email_service.rb b/app/services/api/v1/users/update_email_service.rb index 7841a7100..93ddf706d 100644 --- a/app/services/api/v1/users/update_email_service.rb +++ b/app/services/api/v1/users/update_email_service.rb @@ -30,7 +30,7 @@ class Api::V1::Users::UpdateEmailService < ApplicationService ActiveRecord::Base.transaction do change_user_email excute_data_to_gitea - excute_change_email_from_gitea + excute_change_email_from_gitea remove_old_cache_for_user end @@ -61,13 +61,17 @@ class Api::V1::Users::UpdateEmailService < ApplicationService end def excute_data_to_gitea - Rails.logger.info request_body @gitea_data = $gitea_client.patch_admin_users_by_username(@user.login, {body: request_body.to_json}) end def excute_change_email_from_gitea - $gitea_client.delete_user_emails({body: {emails: [@old_mail]}.to_json, query: request_params}) - $gitea_client.post_user_emails({body: {emails: [@mail]}.to_json, query: request_params}) + emails = $gitea_client.get_user_emails({query: request_params}) + puts "emails=#{emails}" + emails.each do |email| + email = email.stringify_keys + next if email["email"] == @mail + $gitea_client.delete_user_emails({body: {emails: [email["email"]]}.to_json, query: request_params}) + end end def remove_old_cache_for_user From adce0c962762a82402a58042517ae16c8dc633be Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 3 Apr 2023 09:39:41 +0800 Subject: [PATCH 262/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Areadme?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E4=BD=BF=E7=94=A8owner=20token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index f03215ace..5d8745397 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -235,9 +235,9 @@ class RepositoriesController < ApplicationController def readme if params[:filepath].present? - result = Gitea::Repository::Readme::DirService.call(@owner.login, @repository.identifier, params[:filepath], params[:ref], current_user&.gitea_token) + result = Gitea::Repository::Readme::DirService.call(@owner.login, @repository.identifier, params[:filepath], params[:ref], @owner&.gitea_token) else - result = Gitea::Repository::Readme::GetService.call(@owner.login, @repository.identifier, params[:ref], current_user&.gitea_token) + result = Gitea::Repository::Readme::GetService.call(@owner.login, @repository.identifier, params[:ref], @owner&.gitea_token) end @path = GiteaService.gitea_config[:domain]+"/#{@owner.login}/#{@repository.identifier}/raw/branch/#{params[:ref]}/" @readme = result[:status] === :success ? result[:body] : nil From 05b33171527ed3155f974486b64e0a82e7052238 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 3 Apr 2023 17:13:38 +0800 Subject: [PATCH 263/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=8F=98=E6=9B=B4=E8=B7=AF=E5=BE=84=E4=BD=BF=E7=94=A8?= =?UTF-8?q?base64?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gitea/create_file_interactor.rb | 12 ++++++++-- .../gitea/delete_file_interactor.rb | 12 ++++++++-- .../gitea/update_file_interactor.rb | 22 ++++++++++++++++--- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/app/interactors/gitea/create_file_interactor.rb b/app/interactors/gitea/create_file_interactor.rb index cf753767c..70e2f6e81 100644 --- a/app/interactors/gitea/create_file_interactor.rb +++ b/app/interactors/gitea/create_file_interactor.rb @@ -25,7 +25,7 @@ module Gitea def run Contents::CreateForm.new(valid_params).validate! result = Gitea::Repository::Entries::CreateService.call(token, - owner, @params[:identifier], @params[:filepath], file_params) + owner, @params[:identifier], file_path, file_params) if result[:status] == :success @result = result[:body] @@ -50,9 +50,17 @@ module Gitea @result = response end + def file_path + if @params[:base64_filepath].present? + Base64.decode64(params[:base64_filepath]) + else + @params[:filepath] + end + end + def valid_params { - filepath: @params[:filepath], + filepath: file_path, branch: @params[:branch], new_branch: @params[:new_branch] } diff --git a/app/interactors/gitea/delete_file_interactor.rb b/app/interactors/gitea/delete_file_interactor.rb index 9a48c9e56..103df6cd4 100644 --- a/app/interactors/gitea/delete_file_interactor.rb +++ b/app/interactors/gitea/delete_file_interactor.rb @@ -24,7 +24,7 @@ module Gitea def run Contents::DeleteForm.new(valid_params).validate! - response = Gitea::Repository::Entries::DeleteService.new(token, owner, @params[:identifier], @params[:filepath], file_params).call + response = Gitea::Repository::Entries::DeleteService.new(token, owner, @params[:identifier], file_path, file_params).call render_result(response) rescue Exception => exception fail!(exception.message) @@ -45,9 +45,17 @@ module Gitea end end + def file_path + if @params[:base64_filepath].present? + Base64.decode64(params[:base64_filepath]) + else + @params[:filepath] + end + end + def valid_params { - filepath: @params[:filepath], + filepath: file_path, sha: @params[:sha] } end diff --git a/app/interactors/gitea/update_file_interactor.rb b/app/interactors/gitea/update_file_interactor.rb index 7dc0c017f..38cfd98a8 100644 --- a/app/interactors/gitea/update_file_interactor.rb +++ b/app/interactors/gitea/update_file_interactor.rb @@ -24,7 +24,7 @@ module Gitea def run Contents::UpdateForm.new(valid_params).validate! - response = Gitea::Repository::Entries::UpdateService.new(token, owner, @params[:identifier], @params[:filepath], file_params).call + response = Gitea::Repository::Entries::UpdateService.new(token, owner, @params[:identifier], file_path, file_params).call render_result(response) rescue Exception => exception fail!(exception.message) @@ -45,9 +45,25 @@ module Gitea end end + def file_path + if @params[:base64_filepath].present? + Base64.decode64(params[:base64_filepath]) + else + @params[:filepath] + end + end + + def from_file_path + if @params[:base64_from_path].present? + Base64.decode64(params[:base64_from_path]) + else + @params[:from_path] + end + end + def valid_params { - filepath: @params[:filepath], + filepath: file_path, branch: @params[:branch], new_branch: @params[:new_branch], sha: @params[:sha] @@ -59,7 +75,7 @@ module Gitea branch: @params[:branch], sha: @params[:sha], new_branch: @params[:new_branch], - from_path: @params[:from_path], + from_path: from_file_path, message: @params[:message], content: Base64.encode64(@params[:content]) ).compact From 1cd2e712a769d475e37a3e8ee9eebcf91b5f9bc0 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 09:38:39 +0800 Subject: [PATCH 264/438] =?UTF-8?q?fixed=20=E4=BB=93=E5=BA=93=E6=A0=91?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E4=B8=8D=E5=8A=A0=E8=BD=BD=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/repositories/entries.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/repositories/entries.json.jbuilder b/app/views/repositories/entries.json.jbuilder index c86219785..aa8ea76cd 100644 --- a/app/views/repositories/entries.json.jbuilder +++ b/app/views/repositories/entries.json.jbuilder @@ -54,7 +54,7 @@ if @project.forge? json.submodule_git_url entry['submodule_git_url'].nil? ? nil : repo_git_submodule_url(@owner, @repository, entry['submodule_git_url']) json.size entry['size'] json.is_readme_file is_readme?(entry['type'], entry['name']) - json.content decode64_content(entry, @owner, @repository, @ref, @path) + json.content nil #decode64_content(entry, @owner, @repository, @ref, @path) json.target entry['target'] json.commit do json.partial! 'last_commit', latest_commit: entry['latest_commit'] From 85c12b2cd49baa98f3233bd748c3a555116f2b9e Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 09:40:05 +0800 Subject: [PATCH 265/438] =?UTF-8?q?fixed=20=E4=BB=93=E5=BA=93=E6=A0=91?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E4=B8=8D=E5=8A=A0=E8=BD=BD=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/repositories/entries.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/repositories/entries.json.jbuilder b/app/views/repositories/entries.json.jbuilder index c86219785..aa8ea76cd 100644 --- a/app/views/repositories/entries.json.jbuilder +++ b/app/views/repositories/entries.json.jbuilder @@ -54,7 +54,7 @@ if @project.forge? json.submodule_git_url entry['submodule_git_url'].nil? ? nil : repo_git_submodule_url(@owner, @repository, entry['submodule_git_url']) json.size entry['size'] json.is_readme_file is_readme?(entry['type'], entry['name']) - json.content decode64_content(entry, @owner, @repository, @ref, @path) + json.content nil #decode64_content(entry, @owner, @repository, @ref, @path) json.target entry['target'] json.commit do json.partial! 'last_commit', latest_commit: entry['latest_commit'] From 5fff8bc23dc1478294a114278dc54eec4025075a Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 11:34:52 +0800 Subject: [PATCH 266/438] =?UTF-8?q?fixed=20=E9=A1=B9=E7=9B=AEmember?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0bot=E8=AE=BF=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/concerns/project_operable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/concerns/project_operable.rb b/app/models/concerns/project_operable.rb index d5d45a468..42fbc79a2 100644 --- a/app/models/concerns/project_operable.rb +++ b/app/models/concerns/project_operable.rb @@ -95,7 +95,7 @@ module ProjectOperable def member?(user_id) if owner.is_a?(User) - members.exists?(user_id: user_id) + members.exists?(user_id: user_id) || (user.platform == "bot" && BotInstall.joins(:bot).where(bot: { uid: user_id }).where(store_id: self.id).exists?) elsif owner.is_a?(Organization) members.exists?(user_id: user_id) || team_projects.joins(team: :team_users).where(team_users: {user_id: user_id}).present? else From 17c87f1043cfc99553f0df6fb259031c4ddfd3f8 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 11:48:42 +0800 Subject: [PATCH 267/438] =?UTF-8?q?fixed=20=E9=A1=B9=E7=9B=AEmember?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0bot=E8=AE=BF=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/concerns/project_operable.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/project_operable.rb b/app/models/concerns/project_operable.rb index 42fbc79a2..31d16dc9e 100644 --- a/app/models/concerns/project_operable.rb +++ b/app/models/concerns/project_operable.rb @@ -93,9 +93,14 @@ module ProjectOperable team_user.destroy! if team_user end + # 安装bot后的权限 + def is_install_bot?(user) + user.platform == "bot" && BotInstall.joins(:bot).where(bot: { uid: user_id }).where(store_id: self.id).exists? + end + def member?(user_id) if owner.is_a?(User) - members.exists?(user_id: user_id) || (user.platform == "bot" && BotInstall.joins(:bot).where(bot: { uid: user_id }).where(store_id: self.id).exists?) + members.exists?(user_id: user_id) || is_install_bot?(User.find_by(id: user_id)) elsif owner.is_a?(Organization) members.exists?(user_id: user_id) || team_projects.joins(team: :team_users).where(team_users: {user_id: user_id}).present? else From 004f5a096deec35cba76f466519e6383e9ef7c48 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 12:24:22 +0800 Subject: [PATCH 268/438] =?UTF-8?q?fixed=20=E9=A1=B9=E7=9B=AEmember?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0bot=E8=AE=BF=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/concerns/project_operable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/concerns/project_operable.rb b/app/models/concerns/project_operable.rb index 31d16dc9e..4fee9ea33 100644 --- a/app/models/concerns/project_operable.rb +++ b/app/models/concerns/project_operable.rb @@ -95,7 +95,7 @@ module ProjectOperable # 安装bot后的权限 def is_install_bot?(user) - user.platform == "bot" && BotInstall.joins(:bot).where(bot: { uid: user_id }).where(store_id: self.id).exists? + user.platform == "bot" && BotInstall.joins(:bot).where(bot: { uid: user.id }).where(store_id: self.id).exists? end def member?(user_id) From 844d121c7f2c7cd858f57931c8cbcc5968782012 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 4 Apr 2023 14:00:09 +0800 Subject: [PATCH 269/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E6=88=90=E5=8A=9F=E4=B9=8B=E5=90=8E=E6=B8=85=E9=99=A4?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/accounts_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 4a104129b..f70cd5773 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -207,7 +207,8 @@ class AccountsController < ApplicationController successful_authentication(@user) sync_pwd_to_gitea!(@user, {password: params[:password].to_s}) # TODO用户密码未同步 - + LimitForbidControl::UserLogin.new(user).clear + # session[:user_id] = @user.id end From 1e3fd4dfbcf6cd78e88b732408f933eb4b02117c Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 4 Apr 2023 14:02:50 +0800 Subject: [PATCH 270/438] fix --- app/controllers/accounts_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index f70cd5773..2046dfa20 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -205,9 +205,9 @@ class AccountsController < ApplicationController return end + LimitForbidControl::UserLogin.new(@user).clear successful_authentication(@user) sync_pwd_to_gitea!(@user, {password: params[:password].to_s}) # TODO用户密码未同步 - LimitForbidControl::UserLogin.new(user).clear # session[:user_id] = @user.id end From 5302490d609259cda814781f196ce9f08bfc3ef5 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 14:37:09 +0800 Subject: [PATCH 271/438] =?UTF-8?q?fixed=20bot=E5=AE=89=E8=A3=85=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index f7bf4f0d6..74d66ce7f 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -16,7 +16,8 @@ class InstallationsController < ApplicationController end def repositories - @install_bots = BotInstall.where(:installer_id => current_user.id) + bot = Bot.find_by(uid: current_user.id) + @install_bots = BotInstall.where(:installer_id => bot.owner_id) end def update_secret From 1b183811dd2d801b22152aa4563b05517d0d8fe8 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 14:39:51 +0800 Subject: [PATCH 272/438] =?UTF-8?q?fixed=20bot=E5=AE=89=E8=A3=85=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index 74d66ce7f..a08174022 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -17,7 +17,7 @@ class InstallationsController < ApplicationController def repositories bot = Bot.find_by(uid: current_user.id) - @install_bots = BotInstall.where(:installer_id => bot.owner_id) + @install_bots = BotInstall.where(bot_id: bot.id).where(:installer_id => bot.owner_id) end def update_secret From 1d2ea48812aee74b75076a65b5847b69880ac48a Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 15:30:28 +0800 Subject: [PATCH 273/438] =?UTF-8?q?fixed=20bot=E5=AE=89=E8=A3=85=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E5=88=97=E8=A1=A8=EF=BC=8C=E4=B8=8Egithub=E5=B7=AE?= =?UTF-8?q?=E5=BC=82=EF=BC=8C=E6=89=80=E4=BB=A5=E5=8F=96=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=92=8Cbot=E5=AF=B9=E5=BA=94=E6=89=80?= =?UTF-8?q?=E6=9C=89=E7=9A=84=E4=BB=93=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index a08174022..a87916271 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -16,8 +16,10 @@ class InstallationsController < ApplicationController end def repositories + # 与github差异,所以取安装用户和bot对应所有的仓库 + install_bot = BotInstall.find params[:id] bot = Bot.find_by(uid: current_user.id) - @install_bots = BotInstall.where(bot_id: bot.id).where(:installer_id => bot.owner_id) + @install_bots = BotInstall.where(bot_id: bot.id).where(:installer_id => install_bot.installer_id) end def update_secret From c2cda6a4a29337102bdf4d2f27117b3975b2121b Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 15:30:39 +0800 Subject: [PATCH 274/438] =?UTF-8?q?fixed=20bot=E5=AE=89=E8=A3=85=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E5=88=97=E8=A1=A8=EF=BC=8C=E4=B8=8Egithub=E5=B7=AE?= =?UTF-8?q?=E5=BC=82=EF=BC=8C=E6=89=80=E4=BB=A5=E5=8F=96=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=92=8Cbot=E5=AF=B9=E5=BA=94=E6=89=80?= =?UTF-8?q?=E6=9C=89=E7=9A=84=E4=BB=93=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index dea64f215..d9990c523 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1080,7 +1080,7 @@ Rails.application.routes.draw do end resources :installations, only: [] do - get :repositories, on: :collection + get :repositories, on: :member end root 'main#index' From b9998ecf4bd3a0ff79a666e1dacf6ecfdaa4ce9d Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 4 Apr 2023 16:13:31 +0800 Subject: [PATCH 275/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E4=BD=BF=E7=94=A8tip=5Fexception?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/concerns/api/project_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/concerns/api/project_helper.rb b/app/controllers/concerns/api/project_helper.rb index 44cac08c7..56f826b55 100644 --- a/app/controllers/concerns/api/project_helper.rb +++ b/app/controllers/concerns/api/project_helper.rb @@ -1,7 +1,7 @@ module Api::ProjectHelper extend ActiveSupport::Concern - def load_project + def load_project namespace = params[:owner] repo = params[:repo] @@ -14,7 +14,7 @@ module Api::ProjectHelper else logger.info "###########:project not found" @project = nil - render_not_found and return + tip_exception(404, '您访问的页面不存在或已被删除') end @project end From a3093c82c6e1d8f024ce3e949b0238cf29431894 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 16:55:30 +0800 Subject: [PATCH 276/438] =?UTF-8?q?fixed=20bot=E5=AE=89=E8=A3=85id?= =?UTF-8?q?=E6=8D=A2=E6=88=90installer=5Fid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 25 ++++++++++++++++----- app/views/installations/index.json.jbuilder | 7 ++---- app/views/installations/show.json.jbuilder | 2 +- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index a87916271..76984ee58 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -8,18 +8,17 @@ class InstallationsController < ApplicationController end def index - @install_bots = BotInstall.where(:installer_id => current_user.id) + @install_bots = BotInstall.where(bot_id: get_bot_id) end def show - @install_bot = BotInstall.find params[:id] + @install_bot = BotInstall.find_by(bot_id: get_bot_id, installer_id: params[:id]) || BotInstall.find_by(id: params[:id]) + tip_exception "参数installer_id错误" if @install_bot.blank? end def repositories # 与github差异,所以取安装用户和bot对应所有的仓库 - install_bot = BotInstall.find params[:id] - bot = Bot.find_by(uid: current_user.id) - @install_bots = BotInstall.where(bot_id: bot.id).where(:installer_id => install_bot.installer_id) + @install_bots = BotInstall.where(bot_id: get_bot_id).where(installer_id: params[:id]) end def update_secret @@ -60,11 +59,13 @@ class InstallationsController < ApplicationController @install_bot.update_attributes!(state: 0) render_ok end + def unsuspended @install_bot = BotInstall.find params[:id] @install_bot.update_attributes!(state: 1) render_ok end + def auth_active begin @bot = Bot.find params[:id] @@ -89,7 +90,8 @@ class InstallationsController < ApplicationController end def access_tokens - @install_bot = BotInstall.find params[:id] + @install_bot = BotInstall.find_by(bot_id: get_bot_id, installer_id: params[:id]) || BotInstall.find_by(id: params[:id]) + tip_exception "参数installer_id错误" if @install_bot.blank? @bot = @install_bot.bot @application = Doorkeeper::Application.find_by(uid: @bot.client_id, secret: @bot.client_secret) tip_exception("该Bot未激活") if @application.blank? @@ -104,5 +106,16 @@ class InstallationsController < ApplicationController render_ok(token: @access_token.token) end + private + + def get_bot_id + header = request.authorization + pattern = /^Bearer /i + token = header.gsub(pattern, "") + decoded_token = JWT.decode token, nil, false + # 前面已验证token有效期和正确性 + decoded_token[0]["iss"] + end + end diff --git a/app/views/installations/index.json.jbuilder b/app/views/installations/index.json.jbuilder index 2163567ed..532f4c91f 100644 --- a/app/views/installations/index.json.jbuilder +++ b/app/views/installations/index.json.jbuilder @@ -2,10 +2,7 @@ json.status 0 json.message "success" json.data do json.array! @install_bots do |install_bot| - json.installation_id install_bot.id - json.extract! install_bot.bot, :id, :name - json.bot_id install_bot.bot.id - json.bot_name install_bot.bot.name - + json.extract! install_bot, :id, :bot_id, :installer_id, :state, :create_time, :update_time + json.bot_name install_bot&.bot&.name end end \ No newline at end of file diff --git a/app/views/installations/show.json.jbuilder b/app/views/installations/show.json.jbuilder index 33c7ba206..ee605b860 100644 --- a/app/views/installations/show.json.jbuilder +++ b/app/views/installations/show.json.jbuilder @@ -1,5 +1,5 @@ json.partial! "commons/success" json.extract! @install_bot, :id, :bot_id, :installer_id, :state, :create_time, :update_time -json.bot_name @install_bot.bot.name +json.bot_name @install_bot&.bot&.name From 7fdbc3dad1044d3db4ffb4dfcb85516f976278d3 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 4 Apr 2023 16:57:54 +0800 Subject: [PATCH 277/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Aapi=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E5=AE=98=E7=BD=91=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/docs/api.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/docs/api.html b/public/docs/api.html index ed8ee0500..88dfceb72 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -719,7 +719,7 @@ http://localhost:3000/api/licenses
      await octokit.request('GET /api/licenses')
       

      HTTP Request

      -

      GET https://forgeplus.trustie.net/api/licenses.json

      +

      GET https://www.gitlink.org.cn/api/licenses.json

      请求参数

      序号ID序号 login昵称<%= sort_tag('创建于', name: 'created_on', path: admins_organizations_path) %><%= sort_tag('最后登录', name: 'last_login_on', path: admins_organizations_path) %>项目数操作昵称<%= sort_tag('创建于', name: 'created_on', path: admins_organizations_path) %>团队成员项目数操作
      <%= list_index_no((params[:page] || 1).to_i, index) %><%= org.id %> <%= link_to "/#{org.login}", target: '_blank' do %> <%= overflow_hidden_span org.login, width: 100 %> @@ -24,7 +23,8 @@ <%= org.nickname %> <%= display_text(org.created_on&.strftime('%Y-%m-%d %H:%M')) %><%= display_text(org.last_login_on&.strftime('%Y-%m-%d %H:%M')) %><%= link_to org.teams_count, "/#{org.login}", target: "_blank" %><%= link_to org.organization_users_count, "/#{org.login}", target: "_blank" %> <%= link_to org.projects_count, "/#{org.login}", target: "_blank" %> <%= link_to '查看', admins_organization_path(org), class: 'action' %> From 355ea7df8eb8189aa6fdc268a5d940d1e3b55abb Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Tue, 21 Feb 2023 17:38:09 +0800 Subject: [PATCH 082/438] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E7=BB=84=E7=BB=87?= =?UTF-8?q?=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/admins/organizations/index.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/admins/organizations/index.html.erb b/app/views/admins/organizations/index.html.erb index 7cd2ba8fa..d716313b3 100644 --- a/app/views/admins/organizations/index.html.erb +++ b/app/views/admins/organizations/index.html.erb @@ -5,10 +5,10 @@ <%= form_tag(admins_organizations_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %> <%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-sm-2 ml-3', placeholder: 'login/昵称') %> - + <%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %> <% end %> - +
      From fd1b4e10869cf52eddce41d3a9253d6cbc01b439 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 3 Mar 2023 14:29:04 +0800 Subject: [PATCH 083/438] =?UTF-8?q?=E6=89=B9=E9=87=8Fforked=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=B9=B6=E5=8A=A0=E5=85=A5=E6=88=90=E5=91=98=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_forked_project.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/batch_forked_project.rake b/lib/tasks/batch_forked_project.rake index e7eb4a95c..f04e77c5d 100644 --- a/lib/tasks/batch_forked_project.rake +++ b/lib/tasks/batch_forked_project.rake @@ -17,7 +17,7 @@ namespace :batch_forked_project do members.each do |m| m_user = User.find_by(login: m) next if m_user.blank? - Projects::AddMemberInteractor.call(new_project.owner, project, m_user) + Projects::AddMemberInteractor.call(new_project.owner, new_project, m_user) end new_date = project.created_on + rand(5..60).day + rand(5..30).hour new_project.update_columns(created_on: new_date, updated_on: new_date) From bc862f8d98324fee25f9eb76cae5f153967c8c4a Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 3 Mar 2023 18:01:46 +0800 Subject: [PATCH 084/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E9=83=A8?= =?UTF-8?q?=E5=88=86=E7=94=A8=E6=88=B7=E6=97=A0=E6=B3=95=E6=94=B6=E5=88=B0?= =?UTF-8?q?=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/send_template_message_job.rb | 10 +++------- app/models/message_template/issue_changed.rb | 8 ++++---- app/services/api/v1/issues/update_service.rb | 15 +++++++++------ 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/app/jobs/send_template_message_job.rb b/app/jobs/send_template_message_job.rb index a45516ae5..c40a3c9bd 100644 --- a/app/jobs/send_template_message_job.rb +++ b/app/jobs/send_template_message_job.rb @@ -35,11 +35,7 @@ class SendTemplateMessageJob < ApplicationJob operator = User.find_by_id(operator_id) issue = Issue.find_by_id(issue_id) return unless operator.present? && issue.present? - if args[2].present? - receivers = User.where(id: args[2]).where.not(id: operator&.id) - else - receivers = User.where(id: issue&.assigned_to_id).where.not(id: operator&.id) - end + receivers = issue&.assigners.where.not(id: operator&.id) receivers_string, content, notification_url = MessageTemplate::IssueAssigned.get_message_content(receivers, operator, issue) Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, issue_id: issue.id}) receivers.find_each do |receiver| @@ -60,7 +56,7 @@ class SendTemplateMessageJob < ApplicationJob operator = User.find_by_id(operator_id) issue = Issue.find_by_id(issue_id) return unless operator.present? && issue.present? - receivers = User.where(id: [issue&.assigned_to_id, issue&.author_id]).where.not(id: operator&.id) + receivers = User.where(id: issue.assigners.pluck(:id).append(issue&.author_id)).where.not(id: operator&.id) receivers_string, content, notification_url = MessageTemplate::IssueChanged.get_message_content(receivers, operator, issue, change_params.symbolize_keys) Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, issue_id: issue.id, change_params: change_params.symbolize_keys}) receivers.find_each do |receiver| @@ -71,7 +67,7 @@ class SendTemplateMessageJob < ApplicationJob issue_id = args[0] issue = Issue.find_by_id(issue_id) return unless issue.present? - receivers = User.where(id: [issue&.assigned_to_id, issue&.author_id]) + receivers = User.where(id: issue.assigners.pluck(:id).append(issue&.author_id)) receivers_string, content, notification_url = MessageTemplate::IssueExpire.get_message_content(receivers, issue) Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {issue_id: issue.id}) receivers.find_each do |receiver| diff --git a/app/models/message_template/issue_changed.rb b/app/models/message_template/issue_changed.rb index e8a5e5cdb..f5e8c7628 100644 --- a/app/models/message_template/issue_changed.rb +++ b/app/models/message_template/issue_changed.rb @@ -209,16 +209,16 @@ class MessageTemplate::IssueChanged < MessageTemplate change_count = change_params.keys.size # 疑修负责人修改 if change_params[:assigned_to_id].present? - assigner1 = User.find_by_id(change_params[:assigned_to_id][0]) - assigner2 = User.find_by_id(change_params[:assigned_to_id][1]) + assigner1 = User.where(id: change_params[:assigned_to_id][0]) + assigner2 = User.where(id: change_params[:assigned_to_id][1]) if change_count > 1 content.sub!('{ifassigner}', '
      ') else content.sub!('{ifassigner}', '') end content.sub!('{endassigner}', '') - content.gsub!('{assigner1}', assigner1.present? ? assigner1&.real_name : '未指派成员') - content.gsub!('{assigner2}', assigner2.present? ? assigner2&.real_name : '未指派成员') + content.gsub!('{assigner1}', assigner1.present? ? assigner1.map{|a| a&.real_name}.join("、") : '无') + content.gsub!('{assigner2}', assigner2.present? ? assigner2.map{|a| a&.real_name}.join("、") : '无') else content.gsub!(/({ifassigner})(.*)({endassigner})/, '') end diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 45274b9c4..9aa9d6bb1 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -55,7 +55,10 @@ class Api::V1::Issues::UpdateService < ApplicationService build_assigner_participants unless assigner_ids.nil? # 负责人 build_edit_participants build_atme_participants if @atme_receivers.present? - @updated_issue.assigners = @assigners || User.none unless assigner_ids.nil? + unless assigner_ids.nil? + @previous_issue_changes.merge!(assigned_to_id: [@updated_issue.assigners.pluck(:id), @assigners.pluck(:id)]) + @updated_issue.assigners = @assigners || User.none + end @updated_issue.attachments = @attachments || Attachment.none unless attachment_ids.nil? @updated_issue.issue_tags_relates.destroy_all & @updated_issue.issue_tags = @issue_tags || IssueTag.none unless issue_tag_ids.nil? @updated_issue.issue_tags_value = @issue_tags.order("id asc").pluck(:id).join(",") unless issue_tag_ids.nil? @@ -118,12 +121,12 @@ class Api::V1::Issues::UpdateService < ApplicationService end def build_previous_issue_changes - @previous_issue_changes = @updated_issue.previous_changes.except("updated_on", "created_on") - if @updated_issue.previous_changes["start_date"].present? - @previous_issue_changes.merge!(start_date: [@updated_issue.previous_changes["start_date"][0].to_s, @updated_issue.previous_changes["start_date"][1].to_s]) + @previous_issue_changes.merge!(@updated_issue.previous_changes.slice("status_id", "priority_id", "fixed_version_id", "issue_tags_value", "branch_name").symbolize_keys) + if @updated_issue.previous_changes[:start_date].present? + @previous_issue_changes.merge!(start_date: [@updated_issue.previous_changes[:start_date][0].to_s, @updated_issue.previous_changes[:start_date][1].to_s]) end - if @updated_issue.previous_changes["due_date"].present? - @previous_issue_changes.merge!(due_date: [@updated_issue.previous_changes["due_date"][0].to_s, @updated_issue.previous_changes["due_date"][1].to_s]) + if @updated_issue.previous_changes[:due_date].present? + @previous_issue_changes.merge!(due_date: [@updated_issue.previous_changes[:due_date][0].to_s, @updated_issue.previous_changes[:due_date][1].to_s]) end end From b5383bfa5a8dffb1a661ec7dc5524f9320960bab Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 3 Mar 2023 18:43:18 +0800 Subject: [PATCH 085/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E5=86=85=E5=AE=B9=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 | 7 +++++-- app/models/message_template/issue_changed.rb | 12 ++++++------ app/views/api/v1/issues/index.json.jbuilder | 6 +++++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/controllers/api/v1/issues_controller.rb b/app/controllers/api/v1/issues_controller.rb index 84f4dd722..6f615e498 100644 --- a/app/controllers/api/v1/issues_controller.rb +++ b/app/controllers/api/v1/issues_controller.rb @@ -9,8 +9,11 @@ class Api::V1::IssuesController < Api::V1::BaseController @total_issues_count = @object_result[:total_issues_count] @opened_issues_count = @object_result[:opened_issues_count] @closed_issues_count = @object_result[:closed_issues_count] - - @issues = kaminari_paginate(@object_result[:data]) + if params[:only_name].present? + @issues = kaminary_select_paginate(@object_result[:data].pluck(:id, :subject)) + else + @issues = kaminari_paginate(@object_result[:data]) + end end def create diff --git a/app/models/message_template/issue_changed.rb b/app/models/message_template/issue_changed.rb index f5e8c7628..5ac3a120f 100644 --- a/app/models/message_template/issue_changed.rb +++ b/app/models/message_template/issue_changed.rb @@ -31,16 +31,16 @@ class MessageTemplate::IssueChanged < MessageTemplate change_count = change_params.keys.size # 疑修负责人修改 if change_params[:assigned_to_id].present? - assigner1 = User.find_by_id(change_params[:assigned_to_id][0]) - assigner2 = User.find_by_id(change_params[:assigned_to_id][1]) + assigner1 = User.where(id: change_params[:assigned_to_id][0]) + assigner2 = User.where(id: change_params[:assigned_to_id][1]) if change_count > 1 content.sub!('{ifassigner}', '
      ') else content.sub!('{ifassigner}', '') end content.sub!('{endassigner}', '') - content.gsub!('{assigner1}', assigner1.present? ? assigner1&.real_name : '未指派成员') - content.gsub!('{assigner2}', assigner2.present? ? assigner2&.real_name : '未指派成员') + content.gsub!('{assigner1}', assigner1.present? ? assigner1.map{|a| a&.real_name}.join("、") : '未指派成员') + content.gsub!('{assigner2}', assigner2.present? ? assigner2.map{|a| a&.real_name}.join("、") : '未指派成员') else content.gsub!(/({ifassigner})(.*)({endassigner})/, '') end @@ -217,8 +217,8 @@ class MessageTemplate::IssueChanged < MessageTemplate content.sub!('{ifassigner}', '') end content.sub!('{endassigner}', '') - content.gsub!('{assigner1}', assigner1.present? ? assigner1.map{|a| a&.real_name}.join("、") : '无') - content.gsub!('{assigner2}', assigner2.present? ? assigner2.map{|a| a&.real_name}.join("、") : '无') + content.gsub!('{assigner1}', assigner1.present? ? assigner1.map{|a| a&.real_name}.join("、") : '未指派成员') + content.gsub!('{assigner2}', assigner2.present? ? assigner2.map{|a| a&.real_name}.join("、") : '未指派成员') else content.gsub!(/({ifassigner})(.*)({endassigner})/, '') end diff --git a/app/views/api/v1/issues/index.json.jbuilder b/app/views/api/v1/issues/index.json.jbuilder index 6a04c56ac..ddc36ffb7 100644 --- a/app/views/api/v1/issues/index.json.jbuilder +++ b/app/views/api/v1/issues/index.json.jbuilder @@ -4,5 +4,9 @@ json.closed_count @closed_issues_count json.total_count @issues.total_count json.has_created_issues @project.issues.size > 0 json.issues @issues.each do |issue| - json.partial! "simple_detail", locals: {issue: issue} + if params[:only_name].present? + json.partial! "simple_detail", locals: {issue: issue} + else + json.(issue, :id, :subject) + end end \ No newline at end of file From 2827e28b0736c2028bce160dbe3bc39c1fae57b3 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 6 Mar 2023 10:33:26 +0800 Subject: [PATCH 086/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E8=AF=84?= =?UTF-8?q?=E8=AE=BA/=E6=93=8D=E4=BD=9C=E8=AE=B0=E5=BD=95=E6=80=BB?= =?UTF-8?q?=E6=95=B0=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/issues/journals_controller.rb | 7 +++++-- .../api/v1/issues/journals/list_service.rb | 20 +++++++++++-------- .../v1/issues/journals/index.json.jbuilder | 3 +++ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/app/controllers/api/v1/issues/journals_controller.rb b/app/controllers/api/v1/issues/journals_controller.rb index f7a24ea05..7a8b9b24b 100644 --- a/app/controllers/api/v1/issues/journals_controller.rb +++ b/app/controllers/api/v1/issues/journals_controller.rb @@ -6,8 +6,11 @@ class Api::V1::Issues::JournalsController < Api::V1::BaseController before_action :check_journal_operate_permission, only: [:update, :destroy] def index - @object_results = Api::V1::Issues::Journals::ListService.call(@issue, query_params, current_user) - @journals = kaminari_paginate(@object_results) + @object_result = Api::V1::Issues::Journals::ListService.call(@issue, query_params, current_user) + @total_journals_count = @object_result[:total_journals_count] + @total_operate_journals_count = @object_result[:total_operate_journals_count] + @total_comment_journals_count = @object_result[:total_comment_journals_count] + @journals = kaminari_paginate(@object_result[:data]) end def create diff --git a/app/services/api/v1/issues/journals/list_service.rb b/app/services/api/v1/issues/journals/list_service.rb index 02f709e55..486fa5d3f 100644 --- a/app/services/api/v1/issues/journals/list_service.rb +++ b/app/services/api/v1/issues/journals/list_service.rb @@ -3,7 +3,7 @@ class Api::V1::Issues::Journals::ListService < ApplicationService include ActiveModel::Model attr_reader :issue, :category, :keyword, :sort_by, :sort_direction - attr_accessor :queried_journals + attr_accessor :queried_journals, :total_journals_count, :total_operate_journals_count, :total_comment_journals_count validates :category, inclusion: {in: %w(all comment operate), message: "请输入正确的Category"} validates :sort_by, inclusion: {in: Journal.column_names, message: '请输入正确的SortBy'}, allow_blank: true @@ -22,7 +22,7 @@ class Api::V1::Issues::Journals::ListService < ApplicationService begin journal_query_data - @queried_journals + {data: @queried_journals, total_journals_count: @total_journals_count, total_operate_journals_count: total_operate_journals_count, total_comment_journals_count: total_comment_journals_count} rescue raise Error, "服务器错误,请联系系统管理员!" end @@ -33,17 +33,21 @@ class Api::V1::Issues::Journals::ListService < ApplicationService @queried_journals = issue.journals + @queried_journals = @queried_journals.parent_journals + + @queried_journals = @queried_journals.ransack(notes_cont: keyword).result if keyword.present? + + @total_journals_count = queried_journals.distinct.size + @total_operate_journals_count = @queried_journals.where(notes: nil).distinct.size + @total_comment_journals_count = @queried_journals.where.not(notes: nil).distinct.size + case category when 'comment' - @queried_journals = issue.comment_journals + @queried_journals = @queried_journals.where.not(notes: nil) when 'operate' - @queried_journals = issue.operate_journals + @queried_journals = @queried_journals.where(notes: nil) end - @queried_journals = @queried_journals.parent_journals - - @queried_journals = @queried_journals.ransack(notes_cont: keyword).result if keyword.present? - @queried_journals = @queried_journals.includes(:journal_details, :user, :attachments, first_ten_children_journals: [:parent_journal, :reply_journal]) @queried_journals = @queried_journals.reorder("journals.#{sort_by} #{sort_direction}").distinct diff --git a/app/views/api/v1/issues/journals/index.json.jbuilder b/app/views/api/v1/issues/journals/index.json.jbuilder index bea6746a6..49f94aa37 100644 --- a/app/views/api/v1/issues/journals/index.json.jbuilder +++ b/app/views/api/v1/issues/journals/index.json.jbuilder @@ -1,3 +1,6 @@ +json.total_journals_count @total_journals_count +json.total_operate_journals_count @total_operate_journals_count +json.total_comment_journals_count @total_comment_journals_count json.total_count @journals.total_count json.journals @journals do |journal| json.partial! "detail", journal: journal From 5580a96fe75e0f1520da10bd18a99b48337f62c6 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 6 Mar 2023 10:42:12 +0800 Subject: [PATCH 087/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/api/v1/issues/index.json.jbuilder | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/api/v1/issues/index.json.jbuilder b/app/views/api/v1/issues/index.json.jbuilder index ddc36ffb7..39a467dd4 100644 --- a/app/views/api/v1/issues/index.json.jbuilder +++ b/app/views/api/v1/issues/index.json.jbuilder @@ -5,8 +5,8 @@ json.total_count @issues.total_count json.has_created_issues @project.issues.size > 0 json.issues @issues.each do |issue| if params[:only_name].present? - json.partial! "simple_detail", locals: {issue: issue} - else json.(issue, :id, :subject) + else + json.partial! "simple_detail", locals: {issue: issue} end end \ No newline at end of file From 620ed26e45ad123a8dd824d068d1685f9227c4e6 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 6 Mar 2023 17:49:28 +0800 Subject: [PATCH 088/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E8=AF=84?= =?UTF-8?q?=E8=AE=BA=E5=88=97=E8=A1=A8=E5=88=86=E9=A1=B5=E6=95=B0=E9=87=8F?= =?UTF-8?q?=E9=99=90=E5=88=B6=E5=8F=98=E5=A4=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/base_controller.rb | 2 +- app/controllers/api/v1/issues/journals_controller.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/base_controller.rb b/app/controllers/api/v1/base_controller.rb index c6a4f180d..bcb0c4e86 100644 --- a/app/controllers/api/v1/base_controller.rb +++ b/app/controllers/api/v1/base_controller.rb @@ -23,7 +23,7 @@ class Api::V1::BaseController < ApplicationController def kaminary_select_paginate(relation) limit = params[:limit] || params[:per_page] - limit = (limit.to_i.zero? || limit.to_i > 100) ? 100 : limit.to_i + limit = (limit.to_i.zero? || limit.to_i > 200) ? 200 : limit.to_i page = params[:page].to_i.zero? ? 1 : params[:page].to_i relation.page(page).per(limit) diff --git a/app/controllers/api/v1/issues/journals_controller.rb b/app/controllers/api/v1/issues/journals_controller.rb index 7a8b9b24b..cee2b81e8 100644 --- a/app/controllers/api/v1/issues/journals_controller.rb +++ b/app/controllers/api/v1/issues/journals_controller.rb @@ -10,7 +10,7 @@ class Api::V1::Issues::JournalsController < Api::V1::BaseController @total_journals_count = @object_result[:total_journals_count] @total_operate_journals_count = @object_result[:total_operate_journals_count] @total_comment_journals_count = @object_result[:total_comment_journals_count] - @journals = kaminari_paginate(@object_result[:data]) + @journals = kaminary_select_paginate(@object_result[:data]) end def create From 9cd150be88e3cfaa4b9e0506fb20706f8426e366 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 7 Mar 2023 09:49:17 +0800 Subject: [PATCH 089/438] =?UTF-8?q?=E5=BC=80=E5=90=AF=E7=A1=AE=E6=9D=83?= =?UTF-8?q?=E6=BF=80=E5=8A=B1=E7=9A=84=E7=94=A8=E6=88=B7=E6=88=96=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/projects_helper.rb | 1 + app/views/users/get_user_info.json.jbuilder | 1 + 2 files changed, 2 insertions(+) diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 5ed680ba3..cef8c3e04 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: EduSetting.get("open_blockchain_projects").to_s.split(",").include?(project.id) || EduSetting.get("open_blockchain_users").to_s.split(",").include?(project.identifier), ignore_id: project.ignore_id }).compact diff --git a/app/views/users/get_user_info.json.jbuilder b/app/views/users/get_user_info.json.jbuilder index 68bfa6589..ee4e75179 100644 --- a/app/views/users/get_user_info.json.jbuilder +++ b/app/views/users/get_user_info.json.jbuilder @@ -28,3 +28,4 @@ json.message_unread_total @message_unread_total json.has_trace_user @user.trace_user.present? json.is_new @user.login.present? && params[:login].to_s.include?("#{@user.login}") json.nps EduSetting.get("nps-on-off-switch").to_s == 'true' && UserNp.where(user_id: current_user.id).where("created_at >= ?", (Time.now - 30.days).beginning_of_day ).blank? +json.open_blockchain EduSetting.get("open_blockchain_users").to_s.split(",").include?(@user.id) || EduSetting.get("open_blockchain_users").to_s.split(",").include?(@user.login) From db845e7df01c1f151b930dbe70380493b32accd6 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 7 Mar 2023 09:59:42 +0800 Subject: [PATCH 090/438] =?UTF-8?q?=E5=BC=80=E5=90=AF=E7=A1=AE=E6=9D=83?= =?UTF-8?q?=E6=BF=80=E5=8A=B1=E7=9A=84=E7=94=A8=E6=88=B7=E6=88=96=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/projects_helper.rb | 2 +- app/views/users/get_user_info.json.jbuilder | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index cef8c3e04..03e06ec6e 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -66,7 +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: EduSetting.get("open_blockchain_projects").to_s.split(",").include?(project.id) || EduSetting.get("open_blockchain_users").to_s.split(",").include?(project.identifier), + open_blockchain: EduSetting.get("open_blockchain_projects").to_s.split(",").include?(project.id.to_s) || EduSetting.get("open_blockchain_users").to_s.split(",").include?(project.identifier), ignore_id: project.ignore_id }).compact diff --git a/app/views/users/get_user_info.json.jbuilder b/app/views/users/get_user_info.json.jbuilder index ee4e75179..dc8315ea2 100644 --- a/app/views/users/get_user_info.json.jbuilder +++ b/app/views/users/get_user_info.json.jbuilder @@ -28,4 +28,4 @@ json.message_unread_total @message_unread_total json.has_trace_user @user.trace_user.present? json.is_new @user.login.present? && params[:login].to_s.include?("#{@user.login}") json.nps EduSetting.get("nps-on-off-switch").to_s == 'true' && UserNp.where(user_id: current_user.id).where("created_at >= ?", (Time.now - 30.days).beginning_of_day ).blank? -json.open_blockchain EduSetting.get("open_blockchain_users").to_s.split(",").include?(@user.id) || EduSetting.get("open_blockchain_users").to_s.split(",").include?(@user.login) +json.open_blockchain EduSetting.get("open_blockchain_users").to_s.split(",").include?(@user.id.to_s) || EduSetting.get("open_blockchain_users").to_s.split(",").include?(@user.login) From 9da61bd69e23974fc217a934a9db3048a728d153 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 7 Mar 2023 16:34:31 +0800 Subject: [PATCH 091/438] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E6=9F=A5=E8=AF=A2=E6=97=B6count=E6=80=A7?= =?UTF-8?q?=E8=83=BD=E9=97=AE=E9=A2=98=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 053c89e02..440379ac3 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -39,13 +39,14 @@ class ProjectsController < ApplicationController category_id = params[:category_id] @total_count = - if category_id.blank? - # ps = ProjectStatistic.first - # ps.common_projects_count + ps.mirror_projects_count unless ps.blank? + if category_id.blank? && params[:search].blank? + # 默认查询时count性能问题处理 + ProjectCategory.sum("projects_count") - Project.visible.joins("left join organization_extensions on organization_extensions.organization_id = projects.user_id").where("organization_extensions.visibility =2").count + elsif params[:search].present? @projects.total_count else - cate = ProjectCategory.find_by(id: category_id) - cate&.projects_count || 0 + cate = ProjectCategory.find_by(id: category_id) + cate&.projects_count || 0 end end From e6f8f5761113d2c6e8eb64821de2a43d29521f25 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 7 Mar 2023 16:34:31 +0800 Subject: [PATCH 092/438] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E6=9F=A5=E8=AF=A2=E6=97=B6count=E6=80=A7?= =?UTF-8?q?=E8=83=BD=E9=97=AE=E9=A2=98=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 52c776477..918b4533f 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -39,13 +39,14 @@ class ProjectsController < ApplicationController category_id = params[:category_id] @total_count = - if category_id.blank? - # ps = ProjectStatistic.first - # ps.common_projects_count + ps.mirror_projects_count unless ps.blank? + if category_id.blank? && params[:search].blank? + # 默认查询时count性能问题处理 + ProjectCategory.sum("projects_count") - Project.visible.joins("left join organization_extensions on organization_extensions.organization_id = projects.user_id").where("organization_extensions.visibility =2").count + elsif params[:search].present? @projects.total_count else - cate = ProjectCategory.find_by(id: category_id) - cate&.projects_count || 0 + cate = ProjectCategory.find_by(id: category_id) + cate&.projects_count || 0 end end From 57c54da02578d0d37b6560b107472e632ad56d17 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 8 Mar 2023 15:59:06 +0800 Subject: [PATCH 093/438] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=AD=A6=E4=B9=A0?= =?UTF-8?q?=E5=AD=A6=E5=91=98=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/import_repo.rb | 6 ++ lib/tasks/import_educoder_cource_repo.rake | 97 ++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 app/models/import_repo.rb create mode 100644 lib/tasks/import_educoder_cource_repo.rake diff --git a/app/models/import_repo.rb b/app/models/import_repo.rb new file mode 100644 index 000000000..8b53a7765 --- /dev/null +++ b/app/models/import_repo.rb @@ -0,0 +1,6 @@ + + +# for oauth2 application +class ImportRepo < ApplicationRecord + self.table_name = "open_shixuns" +end diff --git a/lib/tasks/import_educoder_cource_repo.rake b/lib/tasks/import_educoder_cource_repo.rake new file mode 100644 index 000000000..0b35882ee --- /dev/null +++ b/lib/tasks/import_educoder_cource_repo.rake @@ -0,0 +1,97 @@ +namespace :import_educoder_cource_repo do + desc "sync outer repository to gitlink" + task done: :environment do + data = ImportRepo.all + if ENV['name'].present? + data = data.where("name like '%#{ENV['name']}%'") + end + data.each_with_index do |row, index| + puts index + root_repo = Repository.find_by(mirror_url: row.git_url) + next if root_repo.blank? + root_project = root_repo.project + + begin + user = User.find_by(phone: row.myshixun_user_phone) || User.find_by(mail: row.myshixun_user_mail) + unless user.present? + username = generate_user_login('p') + email = row.myshixun_user_mail + phone = row.myshixun_user_phone + password = "a12345678" + user = User.new(nickname: row.myshixun_user_name, login: username, mail: email, password: password, type: 'User', phone: phone) + interactor = Gitea::RegisterInteractor.call({ username: username, email: email, password: password }) + gitea_user = interactor.result + result = Gitea::User::GenerateTokenService.call(username, password) + user.gitea_token = result['sha1'] + user.gitea_uid = gitea_user[:body]['id'] + user.save! + UserExtension.create!(user_id: user.id) + puts "import_user batch success: phone #{phone} email: #{email}" + end + + repo = Repository.find_by(mirror_url: row.myshixun_git_url) + next if repo.present? && repo.project.present? + mirror_params = { + user_id: user.id, + auth_username: "xxqfamous@gmail.com", + auth_password: "eHhxMTIzNDU2Nzg5NTIx", + name: root_project.name, + description: root_project.description, + repository_name: root_project.identifier, + project_category_id: root_project.project_category_id, + project_language_id: root_project.project_language_id, + clone_addr: row.myshixun_git_url + } + Projects::MigrateService.call(user, mirror_params) + + puts "sync outer repository to gitlink Success repo: #{row.myshixun_git_url}" + rescue Exception => e + puts "sync outer repository to gitlink Error repo: #{row.myshixun_git_url}, error:#{e}" + end + end + end + + desc "batch forked project" + task forked: :environment do + data =ImportRepo.all + if ENV['name'].present? + data = data.where("name like '%#{ENV['name']}%'") + end + puts data.to_sql + data.each do |row| + begin + puts row.id + user = User.find_by(phone: row.myshixun_user_phone) || User.find_by(mail: row.myshixun_user_mail) + next if user.blank? + root_repo = Repository.find_by(mirror_url: row.git_url) + next if root_repo.blank? + root_project = root_repo.project + repo = Repository.find_by(mirror_url: row.myshixun_git_url) + # 学员项目未导入就跳过 + next if repo.blank? + # 已绑定的跳过 + next if repo.project.forked_from_project_id.present? + # 绑定fork关系 + ForkUser.create(project_id: root_project.id, fork_project_id: repo.project.id, user_id: repo.project.user_id) + # 处理时间防止列表刷屏 + new_date = root_project.created_on > Time.now - 30.days ? Time.now - 1.years + rand(5..90).day + rand(5..60).hour : root_project.created_on + root_project.update_columns(created_on: new_date, updated_on: new_date, forked_count: (root_project.forked_count.to_i + 1)) + # fork时间同样处理在创建时间之后 + new_date2 = new_date + rand(5..50).day + rand(5..30).hour + repo.project.update_columns(created_on: new_date2, updated_on: new_date2, forked_from_project_id: root_project.id) + puts "forked project success username: #{user.id}:#{repo.project.id}" + rescue Exception => e + puts "forked project error username: #{username}" + end + end + end + + # 生成邀请码 + CODES = %W(0 1 2 3 4 5 6 7 8 9) + def generate_user_login type + code = CODES.sample(8).join + code = type + code.to_s + return generate_user_login(type) if User.where(login: code).present? + code + end +end \ No newline at end of file From e1171a96c443950e9fbe3eefb85dab5b88884ffc Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 9 Mar 2023 09:20:52 +0800 Subject: [PATCH 094/438] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=AD=A6=E4=B9=A0?= =?UTF-8?q?=E5=AD=A6=E5=91=98=E9=82=AE=E7=AE=B1=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/import_educoder_cource_repo.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/import_educoder_cource_repo.rake b/lib/tasks/import_educoder_cource_repo.rake index 0b35882ee..a861d9600 100644 --- a/lib/tasks/import_educoder_cource_repo.rake +++ b/lib/tasks/import_educoder_cource_repo.rake @@ -15,7 +15,7 @@ namespace :import_educoder_cource_repo do user = User.find_by(phone: row.myshixun_user_phone) || User.find_by(mail: row.myshixun_user_mail) unless user.present? username = generate_user_login('p') - email = row.myshixun_user_mail + email = row.myshixun_user_mail.blank? ? "#{username}@gitlink.org.cn" : row.myshixun_user_mail phone = row.myshixun_user_phone password = "a12345678" user = User.new(nickname: row.myshixun_user_name, login: username, mail: email, password: password, type: 'User', phone: phone) From e85a2346f454825ecdce6ae5fec5294d51dbfd7c Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 9 Mar 2023 09:33:55 +0800 Subject: [PATCH 095/438] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=AD=A6=E4=B9=A0?= =?UTF-8?q?=E5=AD=A6=E5=91=98=E5=A4=84=E7=90=86=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/import_educoder_cource_repo.rake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tasks/import_educoder_cource_repo.rake b/lib/tasks/import_educoder_cource_repo.rake index a861d9600..188e8e08b 100644 --- a/lib/tasks/import_educoder_cource_repo.rake +++ b/lib/tasks/import_educoder_cource_repo.rake @@ -58,9 +58,9 @@ namespace :import_educoder_cource_repo do data = data.where("name like '%#{ENV['name']}%'") end puts data.to_sql - data.each do |row| + data.each_with_index do |row, index| begin - puts row.id + puts index user = User.find_by(phone: row.myshixun_user_phone) || User.find_by(mail: row.myshixun_user_mail) next if user.blank? root_repo = Repository.find_by(mirror_url: row.git_url) From 8f67181b16da22eb2797905b549a69974e375b92 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 9 Mar 2023 09:40:24 +0800 Subject: [PATCH 096/438] =?UTF-8?q?=E6=89=B9=E9=87=8Ffork=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_forked_project.rake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/tasks/batch_forked_project.rake b/lib/tasks/batch_forked_project.rake index f04e77c5d..528bda3c6 100644 --- a/lib/tasks/batch_forked_project.rake +++ b/lib/tasks/batch_forked_project.rake @@ -5,6 +5,10 @@ namespace :batch_forked_project do puts "project_id=================#{project_id}" next if project_id.blank? user_logins = ['p89346015','p25371846','p69217483','p69805714','p78920563','p54261380','p18934275','p41273960','p76281309','p97134028','p89450236','p28097461','p60437152','p16925078','p13420986','p02315697','p73950468','p72348916','p65874312','p94723568','p35407816','p61830975','p48127056','p17832064','p06472319','p59827036','p49583267','p36120475','p63428509','p51029748','p98071642','p17580394','p96175348','p41672830','p68109573','p23185094','p62105398','p78052941','p39784256','p31704586','p25768904','p30916782','p97142530','p25706341','p90421386','p30547691','p12598607','p34096851','p56902314','p95014723','p57810362','p27049618','p21035879','p47560312','p45902861','p28534760','p95064217','p06819345','p24786109','p47862359','p67201548','p38275619','p02713685','p20516978','p92801564','p12894530','p38146059','p36259710','p65298073','p45926780','p65849120','p19425386','p41038257','p64871093','p49017526','p76438951','p09842165','p07546132','p74189326','p20819356','p79041358','p68315204','p23671945','p75086429','p75246983','p86719302','p57046318','p36402875','p29370514','p39284567','p84973510','p70912653','p87013296','p45801397','p75632498','p15097863','p37298104','p26813470','p80596471','p50234679','p94836501','p97481306','p03826457','p64398250','p06728315','p95802743','p10893624','p32197506','p60475139','p86321945','p26708531','p40531786','p43216578','p81793025','p65974130','p86049152','p68735142','p98625074','p08619275','p48179362','p81507936','p48719350','p79346812','p35027486','p60329715','p60539481','p76059481','p32659470','p73492805','p05214867','p83527960','p57284961','p84921730','p78614302','p58043692','p83795012','p72490365','p74031526','p19072458','p78305942','p79210548','p04273869','p20894137','p38905462','p46109723','p17250849','p79863042','p86354072','p70381452','p70852634','p01439876','p85409726','p13072985','p06975321','p42786905','p84576012','p63541897','p92760841','p83741256','p53029167','p80254167','p57062419','p52071649','p38649571','p54687012','p35487621','p90182463','p40937281','p56809147','p19543078','p69304857','p68457901','p63190852','p86140357','p57491630','p32801694','p16539028','p35182647','p81065927','p98142307','p57806943','p13286457','p61349702','p35168907','p59713608','p61397402','p42673859','p49085271','p31790624','p86451732','p31682759','p29108563','p64157932','p24086573','p50786231','p41237908','p58712463','p02635481','p63289457','p29836504','p42591076','p37620514','p58016429','p91068472','p21489537','p42068571','p09413782','p27456893','p30871956','p14983026','p09567821','p15038967','p34802159','p89234176','p97038246','p60173295','p02418537','p16423790','p71034629','p10284537','p08539174','p26359018','p32981056','p94538276','p92354178','p46271580','p46150238','p97850142','p81604759','p91084637','p04637589','p73852460','p52189704','p19084632','p14763208','p32746591','p47620913','p47068915','p02596781','p48530276','p28309164','p38564297','p14728506','p09413785','p56127938','p24085137','p60517892','p48261730','p45012768','p95741268','p97205463','p32816504','p93410257','p24736950','p07946812','p37408162','p97062183','p02763814','p37142856','p72063459','p36921540','p97583401','p95183074','p90816354','p20768431','p45763201','p07549382','p67502814','p79641052','p09471635','p56234879','p35214687','p25708641','p06452378','p05843697','p89562143','p76435829','p32574608','p24780615','p16408279','p48051237','p70695184','p01297543','p19647583','p41297630','p45163207','p08362159','p20853741','p52436710','p98243601','p97240356','p45980172','p91287634','p65903241','p16543708','p32968140','p72054981','p25904731','p42137095','p32480967','p81739025','p43590716','p04152936','p78094351','p24719605','p35078941','p26875103','p39617540','p32046579','p38614905','p37904815','p04637219','p16072398','p14509327','p64915802','p86901372','p23689415','p13627904','p07649125','p63974102','p90372815','p76839152','p70621953','p62783154','p69127034','p35762149','p46718029','p49038615','p13625784','p74835920','p71894530','p67253149','p95476182','p85632907','p64315790','p38150427','p98024156','p70684592','p39427165','p09682531','p24178095','p60927481','p56873024','p63702845','p21495036','p35468209','p37546918','p86092715','p54927031','p70428196','p16943057','p84301759','p06957132','p41075982','p78134290','p18732456','p28654079','p73518624','p56124037','p08416932','p06127935','p42178659','p25047183','p30592648','p72693851','p92453867','p56297804','p34759102','p31495620','p21053468','p72836954','p05426871','p03485972','p72408193','p65907124','p42953718','p05176823','p28635019','p15607483','p20183675','p70348295','p95602314','p18750962','p27396041','p65039842','p29861504','p12450839','p32164907','p08974362','p97310846','p57326049','p46039257','p16308954','p08927143','p96805214','p39687025','p02345978','p68704231','p65074391','p74130682','p56394728','p85971406','p34920175','p85497610','p98413562','p90841576','p52987460','p58426091','p70493586','p97831640','p65309184','p90462513','p37104865','p40217938','p80975236','p39142076','p14278930','p54731860','p50761948','p69431802','p20479615','p93710546','p17329085','p05327968','p62384590','p83964120','p82013564','p05248176','p91756083','p98314765','p91740526','p41870593','p82617439','p35621840','p94752683','p82149057','p65792034','p89762031','p20835149','p93681520','p47356108','p14578620','p90174356','p62917034','p16289450','p92061735','p51296307','p63854721','p28630741','p68347910','p81405976','p53904721','p21306457','p15937680','p43086715','p04731582','p01549628','p36590127','p81236547','p04372865','p17698354','p69548273','p75834209','p43905172','p51839024','p14027953','p59167832','p98301572','p97610358','p98235607','p84107325','p62073841','p57103248','p38061974','p63527048','p25417803','p29758346','p50461937','p45901728','p79032614','p90138467','p07652843','p57390261','p20654879','p94120685','p49328706','p91542867','p79038562','p46217093','p64350789','p07846235','p82730541','p79216034','p82403975','p85013724','p61359482','p29741638','p87961534','p63850471','p96701452','p87956143','p82501346','p15830476','p34296517','p54603217','p25386701','p59486271','p76250183','p50681423','p92356710','p72013695','p25174896','p87319624','p97583024','p95467102','p80627345','p29015467','p57318920','p13852069','p15490287','p05796328','p83027541','p76189403','p26193804','p34502967','p70368514','p43627890','p07961235','p68197045','p79368205','p25189364','p47560938','p04163285','p59834107','p52017496','p28539176','p76103582','p67214983','p25809413','p01684375','p54367192','p81940257','p31928657','p89572041','p10297384','p53291604','p47201568','p76409812','p63701854','p67135490','p04139825','p01472693','p97521430','p12346870','p08319675','p98250137','p02743168','p19427063','p72894315','p79358120','p70529146','p48130625','p92576038','p21796540','p59417328','p23701854','p61270835','p52913407','p21408795','p89253407','p68590432','p14056283','p83290617','p03754268','p65291703','p71835460','p63028519','p45397861','p96803572','p03741962','p85194607','p84652793','p76534189','p87346592','p51609348','p51728903','p20735491','p53249801','p90821357','p90271845','p36174902','p82345971','p39658240','p29037645','p19523084','p24735089','p23790645','p25780419','p72836401','p51473608','p89253710','p92435681','p71695423','p06298514','p84765192','p80973145','p76234901','p29041386','p48253917','p79326504','p67854932','p70846953','p49137086','p59132670','p45180932','p46208597','p75498316','p01928463','p72189630','p97081625','p74982531','p36217950','p70496351','p49085612','p45872916','p74368291','p67502819','p60493127','p91874265','p18407625','p09315486','p71306428','p68924531','p56934812','p92864103','p46891705','p48965017','p93284710','p62975041','p85013926','p13845267','p41367089','p86952047','p46715938','p84209513','p13695478','p27139648','p03549281','p96124038','p30816759','p98027543','p35809714','p02364951','p86129435','p14357092','p13604872','p46971853','p93105248','p56173408','p07419258','p05896741','p40859721','p57138092','p62083541','p37421598','p45739201','p81453902','p30679528','p51923746','p74081592','p87260935','p25603419','p82419076','p28561793','p71624835','p20685197','p95032418','p12305678','p01382794','p79416325','p71852639','p15297340','p80253914','p27985106','p62387095','p09615784','p69810735','p92046185','p04691538','p29561438','p96748523','p26349178','p53140687','p79360245','p96725043','p08946735','p41569073','p27018563','p63125809','p52014786','p95248160','p02173589','p42098156','p05321647','p89536047','p45701263','p59216748','p69850317','p70185432','p92018756','p29347815','p93240785','p40312865','p61894753','p53219607','p24385071','p74238150','p84760521','p63072491','p03596817','p41027368','p34527869','p29380451','p78934062','p32759104','p20934185','p89154230','p93870142','p31096457','p20743869','p32805697','p18674359','p97451280','p49680215','p85974201','p85346710','p21734698','p86942751','p85620714','p83769402','p58103429','p39701654','p09684175','p15094387','p90381257','p93680157','p49670125','p70293168','p24037156','p18736450','p01973852','p72459680','p92876154','p62587391','p02986317','p14390675','p36591724','p96538124','p38460152','p34291607','p26938541','p59071463','p51962430','p74639081','p32507896','p60975123','p36091572','p48071263','p34298105','p91365204','p98726041','p92168307','p31067542','p72961085','p94386207','p02453769','p18742503','p67835190','p85147902','p23079415','p62543087','p21873546','p96405328','p43586129','p24108635','p83026951','p68350421','p09318647','p97162543','p67185342','p35601974','p18450267','p30286179','p24179356','p13052498','p01962874','p78132509','p17562843','p65380429','p89670245','p34196587','p74392018','p54129673','p89705213','p80271365','p43168705','p18423067','p39057864','p70984165','p06841275','p84753160','p82465391','p70138459','p67024951','p50146287','p67904382','p29507168','p53628974','p90625378','p87619420','p81059632','p14786923','p53096748','p60783415','p51703482','p75401392','p67984023','p98523701','p40185679','p34057982','p65832097','p10742358','p45219703','p85914207','p96432058','p97043516','p68305921','p26135047','p60852143','p45671893','p41936527','p27015389','p78902156','p36895204','p16490573','p26185734','p59127306','p35071862','p24739165','p56179042','p18293604','p12074369','p32740518','p73028546','p29153687','p07328914','p63471052','p31849052','p25041869','p68427519','p12394508','p36710529','p59278036','p03518462','p25913408','p67905318','p64379201','p63948721','p36415870','p36874915','p73201598','p98534102','p27816504','p42056187','p25891046','p05872314','p19368045','p14390275','p08246193','p29863574','p76285934','p02835649','p84176235','p14603857','p06723581','p21580347','p92064571','p02459738','p73428590','p24807695','p79058623','p41297308','p34785092','p53206971','p90782563','p16024853','p03619725','p07123965','p36281475','p20654139','p79826134','p83215674','p80359714','p34857162','p02945871','p04317958','p85170239','p74051823','p26518940','p02635814','p82413657','p39607485','p62387409','p46081923','p10742853','p97126084','p01423876','p42679310','p09561482','p95862703','p37186459','p82406371','p78410965','p84596130','p14925836','p80146275','p03562197','p04576312','p36527018','p59187234','p46170235','p02163475','p87615324','p05691234','p96231745','p01865974','p24836917','p68714093','p80415972','p96587304','p49381276','p69218740','p74301682','p56278934','p97546102','p37896405','p62150938','p42078136','p58629041','p56803129','p74352198','p86205347','p83504671','p27034956','p10579286','p04976285','p27458390','p45210837','p16725489','p37041586','p38615249','p64950718','p97186325','p97635402','p91856613','p92874165','p32480596','p39254801','p68210359','p12583746','p86273145','p67514920','p25807463','p06839571','p35284706','p04551581','p91268403','p02142315','p12560947','p98567210','p59473016','p97248351','p74830458','p86524071','p17948350','p45920387','p85793146','p38149205','p86591027','p57064318','p31402598','renwen','renzhong','yuzhong','jiaoyu','gongwuyuan','baihuaban','shuziban','p63490875','p02738164','p56308142','p56932418','p87639245','p02103822','p75403168','p25970648','p08147695','p73194685','p63507129','p04896132','p48216530','p28091634','p90547381','p46259107','p18602397','p40381925','p48679103','p62660364','p53816940','p67428510','p64903278','p70981432','p43569802','p15680732','p07569831','p54183069','p50973641','p10378259','p57386409','p90835724','p92157683','p72856403','p60297481','p25674903','p47062581','p51927683','p08945163','p67392401','p60128394','p30791248','p30865794','p14365860','p13574098','p65427390','p42530869','p81407259','p29781560','p85147269','p10864573','p06382417','p97143502','p70281539','p80215369','p01682597','p16029574','p15672984','p40617389','p34215896','p03269785','p50874913','p76831094','p54619032','p49076185','p40156829','p03872954','p42506873','p83206417','p51820974','p42978530','p85631740','p49082367','p30654712','p45150945','p61547820','p35906278','p65120487','p82316754','p75183246','p50674321','p69415803','p31705269','p47295031','p97162085','p90378654','p91328675','p53962470','p58173402','p95078342','p95402816','p45832960','p51497286','p71045832','p67495213','p75620834','p50783612','p45619023','p49016357','p92546713','p04786391','p24108675','p13092847','p41235890','p61520730','p38906512','p24137568','p42573618','p20896315','p48310965','p13647289','p15624870','p52674013','p83571920','p74326809','p54712038','p72495360','p60517924','p25968041','p57364910','p73018265','p32065189','p12598647','p50218637','p86079321','p81257430','p52306894','p73615490','p31952407','p23974860','p36872140','p14982630','p68435927','p52360941','p48590137','p58206197','p16538049','p86975142','p70452891','p98063742','p48602953','p85237609','p87150349','p51978620','p75238014','starkylin','p08614975','p49562018','p85469723','WHU-CSE-IH-Team','p94108356','p58974620','p34520981','p02345198','p34265091','p03967182','p52069314','p09518632','p43850721','p75694102','p52803174','p64017953','p64952873','p93246150','p45091368','p98360154','p04675823','p49327518','p26743081','p36410592','p05924613','p68459203','p35812796','p14925308','p84152039','p38069172','p19286705','p01452789','p54708329'] + if ENV['count'].present? + user_logins = user_logins.sample(ENV['count'].to_i) + end + puts "user_count===#{user_logins.size}" user_logins.each do |username| begin user = User.find_by(login: username) From 4b618d1a6160e84ff771bd6d0a051b1b4c1821ce Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 9 Mar 2023 10:33:00 +0800 Subject: [PATCH 097/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E9=80=9A=E7=9F=A5issue=E8=B7=B3=E8=BD=AC=E4=BD=BF?= =?UTF-8?q?=E7=94=A8index?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/message_template/issue_assigned.rb | 4 ++-- app/models/message_template/issue_assigner_expire.rb | 2 +- app/models/message_template/issue_atme.rb | 2 +- app/models/message_template/issue_changed.rb | 4 ++-- app/models/message_template/issue_expire.rb | 4 ++-- app/models/message_template/project_issue.rb | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/models/message_template/issue_assigned.rb b/app/models/message_template/issue_assigned.rb index 7f8494f69..7973ed477 100644 --- a/app/models/message_template/issue_assigned.rb +++ b/app/models/message_template/issue_assigned.rb @@ -26,7 +26,7 @@ class MessageTemplate::IssueAssigned < MessageTemplate project = issue&.project owner = project&.owner content = sys_notice.gsub('{nickname1}', operator&.real_name).gsub('{nickname2}', owner&.real_name).gsub('{repository}', project&.name).gsub('{title}', issue&.subject) - url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.id.to_s) + url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.project_issues_index.to_s) return receivers_string(receivers), content, url rescue => e Rails.logger.info("MessageTemplate::IssueAssigned.get_message_content [ERROR] #{e}") @@ -52,7 +52,7 @@ class MessageTemplate::IssueAssigned < MessageTemplate content.gsub!('{repository}', project&.name) content.gsub!('{baseurl}', base_url) content.gsub!('{title}', issue&.subject) - content.gsub!('{id}', issue&.id.to_s) + content.gsub!('{id}', issue&.project_issues_index.to_s) content.gsub!('{platform}', PLATFORM) return receiver&.mail, title, content diff --git a/app/models/message_template/issue_assigner_expire.rb b/app/models/message_template/issue_assigner_expire.rb index 610c51175..8f9417a41 100644 --- a/app/models/message_template/issue_assigner_expire.rb +++ b/app/models/message_template/issue_assigner_expire.rb @@ -20,7 +20,7 @@ class MessageTemplate::IssueAssignerExpire < MessageTemplate project = issue&.project owner = project&.owner content = sys_notice.gsub('{title}', issue&.subject) - url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.id.to_s) + url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.project_issues_index.to_s) return receivers_string(receivers), content, url rescue => e Rails.logger.info("MessageTemplate::IssueAssignerExpire.get_message_content [ERROR] #{e}") diff --git a/app/models/message_template/issue_atme.rb b/app/models/message_template/issue_atme.rb index 04eb132e4..7709ed05f 100644 --- a/app/models/message_template/issue_atme.rb +++ b/app/models/message_template/issue_atme.rb @@ -20,7 +20,7 @@ class MessageTemplate::IssueAtme < MessageTemplate project = issue&.project owner = project&.owner content = sys_notice.gsub('{nickname}', operator&.real_name).gsub('{title}', issue&.subject) - url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.id.to_s) + url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.project_issues_index.to_s) return receivers_string(receivers), content, url rescue => e Rails.logger.info("MessageTemplate::IssueAtme.get_message_content [ERROR] #{e}") diff --git a/app/models/message_template/issue_changed.rb b/app/models/message_template/issue_changed.rb index 5ac3a120f..43e2cee7d 100644 --- a/app/models/message_template/issue_changed.rb +++ b/app/models/message_template/issue_changed.rb @@ -27,7 +27,7 @@ class MessageTemplate::IssueChanged < MessageTemplate project = issue&.project owner = project&.owner content = MessageTemplate::IssueChanged.sys_notice.gsub('{nickname1}', operator&.real_name).gsub('{nickname2}', owner&.real_name).gsub('{repository}', project&.name).gsub('{title}', issue&.subject) - url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.id.to_s) + url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.project_issues_index.to_s) change_count = change_params.keys.size # 疑修负责人修改 if change_params[:assigned_to_id].present? @@ -205,7 +205,7 @@ class MessageTemplate::IssueChanged < MessageTemplate content.gsub!('{identifier}', project&.identifier) content.gsub!('{repository}', project&.name) content.gsub!('{title}', issue&.subject) - content.gsub!('{id}', issue&.id.to_s) + content.gsub!('{id}', issue&.project_issues_index.to_s) change_count = change_params.keys.size # 疑修负责人修改 if change_params[:assigned_to_id].present? diff --git a/app/models/message_template/issue_expire.rb b/app/models/message_template/issue_expire.rb index d77965f13..eedd53500 100644 --- a/app/models/message_template/issue_expire.rb +++ b/app/models/message_template/issue_expire.rb @@ -28,7 +28,7 @@ class MessageTemplate::IssueExpire < MessageTemplate project = issue&.project owner = project&.owner content = sys_notice.gsub('{title}', issue&.subject) - url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.id.to_s) + url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.project_issues_index.to_s) return receivers_string(receivers), content, url rescue => e @@ -53,7 +53,7 @@ class MessageTemplate::IssueExpire < MessageTemplate content.gsub!('{repository}', project&.name) content.gsub!('{baseurl}', base_url) content.gsub!('{title}', issue&.subject) - content.gsub!('{id}', issue&.id.to_s) + content.gsub!('{id}', issue&.project_issues_index.to_s) content.gsub!('{platform}', PLATFORM) return receiver&.mail, title, content diff --git a/app/models/message_template/project_issue.rb b/app/models/message_template/project_issue.rb index e04830836..e262cd589 100644 --- a/app/models/message_template/project_issue.rb +++ b/app/models/message_template/project_issue.rb @@ -27,7 +27,7 @@ class MessageTemplate::ProjectIssue < MessageTemplate receivers = managers + followers return '', '', '' if receivers.blank? content = sys_notice.gsub('{nickname1}', operator&.real_name).gsub('{nickname2}', owner&.real_name).gsub('{repository}', project&.name).gsub('{title}', issue&.subject) - url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.id.to_s) + url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.project_issues_index.to_s) return receivers_string(receivers), content, url rescue => e @@ -54,7 +54,7 @@ class MessageTemplate::ProjectIssue < MessageTemplate content.gsub!('{repository}', project&.name) content.gsub!('{login2}', owner&.login) content.gsub!('{identifier}', project&.identifier) - content.gsub!('{id}', issue&.id.to_s) + content.gsub!('{id}', issue&.project_issues_index.to_s) content.gsub!('{title}', issue&.subject) content.gsub!('{platform}', PLATFORM) From 917bae4321d1bab1f377bb0bca4d1c0afd7238aa Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 9 Mar 2023 11:09:04 +0800 Subject: [PATCH 098/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E7=96=91=E4=BF=AE=E6=B6=88=E6=81=AF=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 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index a7ddf7e77..30f4a11ef 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -64,8 +64,8 @@ class Api::V1::Issues::CreateService < ApplicationService # 发消息 if Site.has_notice_menu? - SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id, assigner_ids) unless assigner_ids.blank? - SendTemplateMessageJob.perform_later('ProjectIssue', current_user.id, @issue&.id) + SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @created_issue&.id, assigner_ids) unless assigner_ids.blank? + SendTemplateMessageJob.perform_later('ProjectIssue', current_user.id, @created_issue&.id) end unlock("Api::V1::Issues::CreateService:#{project.id}") # 结束写数据,解锁 From ca6bd9a9a6eafeebf36a66a6b291623693247acd Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 9 Mar 2023 14:00:12 +0800 Subject: [PATCH 099/438] =?UTF-8?q?=E6=89=B9=E9=87=8Ffork=E5=9B=A2?= =?UTF-8?q?=E9=98=9F=E4=BA=BA=E6=95=B0=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_forked_project.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/batch_forked_project.rake b/lib/tasks/batch_forked_project.rake index 528bda3c6..3a49eb169 100644 --- a/lib/tasks/batch_forked_project.rake +++ b/lib/tasks/batch_forked_project.rake @@ -16,7 +16,7 @@ namespace :batch_forked_project do project = Project.find project_id next if Project.exists?(user_id: user.id, identifier: project.identifier) new_project = Projects::ForkService.new(user, project, nil).call - random_num = rand(20..25) + random_num = rand(2..8) members = user_logins.sample(random_num) members.each do |m| m_user = User.find_by(login: m) From 0384e811b9e77ef74fecda75daf00d88474acdf0 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 9 Mar 2023 14:05:49 +0800 Subject: [PATCH 100/438] =?UTF-8?q?=E6=89=B9=E9=87=8Ffork=E5=9B=A2?= =?UTF-8?q?=E9=98=9F=E4=BA=BA=E6=95=B0=E5=A4=84=E7=90=86,=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=82=B9=E8=B5=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_forked_project.rake | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/tasks/batch_forked_project.rake b/lib/tasks/batch_forked_project.rake index 3a49eb169..9018e8d10 100644 --- a/lib/tasks/batch_forked_project.rake +++ b/lib/tasks/batch_forked_project.rake @@ -23,6 +23,13 @@ namespace :batch_forked_project do next if m_user.blank? Projects::AddMemberInteractor.call(new_project.owner, new_project, m_user) end + # 点赞 + like_members = user_logins.sample(rand(5..50)) + like_members.each do |u| + like_user = User.find_by(login: u) + next if like_user.liked?(project) + like_user.like!(project) + end new_date = project.created_on + rand(5..60).day + rand(5..30).hour new_project.update_columns(created_on: new_date, updated_on: new_date) ForkUser.where(fork_project_id: new_project.id).where(user_id: user.id).update_all(created_at: new_date, updated_at: new_date) From 4d6df6988a5d9ab2989b05e8991129c971eec209 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 9 Mar 2023 14:18:25 +0800 Subject: [PATCH 101/438] =?UTF-8?q?=E6=89=B9=E9=87=8Ffork=E5=9B=A2?= =?UTF-8?q?=E9=98=9F=E4=BA=BA=E6=95=B0=E5=A4=84=E7=90=86,=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=82=B9=E8=B5=9E=E5=8D=95=E7=8B=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_forked_project.rake | 34 +++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/lib/tasks/batch_forked_project.rake b/lib/tasks/batch_forked_project.rake index 9018e8d10..5834f89f9 100644 --- a/lib/tasks/batch_forked_project.rake +++ b/lib/tasks/batch_forked_project.rake @@ -23,13 +23,6 @@ namespace :batch_forked_project do next if m_user.blank? Projects::AddMemberInteractor.call(new_project.owner, new_project, m_user) end - # 点赞 - like_members = user_logins.sample(rand(5..50)) - like_members.each do |u| - like_user = User.find_by(login: u) - next if like_user.liked?(project) - like_user.like!(project) - end new_date = project.created_on + rand(5..60).day + rand(5..30).hour new_project.update_columns(created_on: new_date, updated_on: new_date) ForkUser.where(fork_project_id: new_project.id).where(user_id: user.id).update_all(created_at: new_date, updated_at: new_date) @@ -38,5 +31,32 @@ namespace :batch_forked_project do puts "forked project error username: #{username}" end end + # 点赞 + like_members = user_logins.sample(rand(5..50)) + like_members.each do |u| + like_user = User.find_by(login: u) + next if like_user.liked?(project) + like_user.like!(project) + end + end + + + task zan: :environment do + project_id = ENV['project_id'] + puts "project_id=================#{project_id}" + next if project_id.blank? + user_logins = ['p89346015','p25371846','p69217483','p69805714','p78920563','p54261380','p18934275','p41273960','p76281309','p97134028','p89450236','p28097461','p60437152','p16925078','p13420986','p02315697','p73950468','p72348916','p65874312','p94723568','p35407816','p61830975','p48127056','p17832064','p06472319','p59827036','p49583267','p36120475','p63428509','p51029748','p98071642','p17580394','p96175348','p41672830','p68109573','p23185094','p62105398','p78052941','p39784256','p31704586','p25768904','p30916782','p97142530','p25706341','p90421386','p30547691','p12598607','p34096851','p56902314','p95014723','p57810362','p27049618','p21035879','p47560312','p45902861','p28534760','p95064217','p06819345','p24786109','p47862359','p67201548','p38275619','p02713685','p20516978','p92801564','p12894530','p38146059','p36259710','p65298073','p45926780','p65849120','p19425386','p41038257','p64871093','p49017526','p76438951','p09842165','p07546132','p74189326','p20819356','p79041358','p68315204','p23671945','p75086429','p75246983','p86719302','p57046318','p36402875','p29370514','p39284567','p84973510','p70912653','p87013296','p45801397','p75632498','p15097863','p37298104','p26813470','p80596471','p50234679','p94836501','p97481306','p03826457','p64398250','p06728315','p95802743','p10893624','p32197506','p60475139','p86321945','p26708531','p40531786','p43216578','p81793025','p65974130','p86049152','p68735142','p98625074','p08619275','p48179362','p81507936','p48719350','p79346812','p35027486','p60329715','p60539481','p76059481','p32659470','p73492805','p05214867','p83527960','p57284961','p84921730','p78614302','p58043692','p83795012','p72490365','p74031526','p19072458','p78305942','p79210548','p04273869','p20894137','p38905462','p46109723','p17250849','p79863042','p86354072','p70381452','p70852634','p01439876','p85409726','p13072985','p06975321','p42786905','p84576012','p63541897','p92760841','p83741256','p53029167','p80254167','p57062419','p52071649','p38649571','p54687012','p35487621','p90182463','p40937281','p56809147','p19543078','p69304857','p68457901','p63190852','p86140357','p57491630','p32801694','p16539028','p35182647','p81065927','p98142307','p57806943','p13286457','p61349702','p35168907','p59713608','p61397402','p42673859','p49085271','p31790624','p86451732','p31682759','p29108563','p64157932','p24086573','p50786231','p41237908','p58712463','p02635481','p63289457','p29836504','p42591076','p37620514','p58016429','p91068472','p21489537','p42068571','p09413782','p27456893','p30871956','p14983026','p09567821','p15038967','p34802159','p89234176','p97038246','p60173295','p02418537','p16423790','p71034629','p10284537','p08539174','p26359018','p32981056','p94538276','p92354178','p46271580','p46150238','p97850142','p81604759','p91084637','p04637589','p73852460','p52189704','p19084632','p14763208','p32746591','p47620913','p47068915','p02596781','p48530276','p28309164','p38564297','p14728506','p09413785','p56127938','p24085137','p60517892','p48261730','p45012768','p95741268','p97205463','p32816504','p93410257','p24736950','p07946812','p37408162','p97062183','p02763814','p37142856','p72063459','p36921540','p97583401','p95183074','p90816354','p20768431','p45763201','p07549382','p67502814','p79641052','p09471635','p56234879','p35214687','p25708641','p06452378','p05843697','p89562143','p76435829','p32574608','p24780615','p16408279','p48051237','p70695184','p01297543','p19647583','p41297630','p45163207','p08362159','p20853741','p52436710','p98243601','p97240356','p45980172','p91287634','p65903241','p16543708','p32968140','p72054981','p25904731','p42137095','p32480967','p81739025','p43590716','p04152936','p78094351','p24719605','p35078941','p26875103','p39617540','p32046579','p38614905','p37904815','p04637219','p16072398','p14509327','p64915802','p86901372','p23689415','p13627904','p07649125','p63974102','p90372815','p76839152','p70621953','p62783154','p69127034','p35762149','p46718029','p49038615','p13625784','p74835920','p71894530','p67253149','p95476182','p85632907','p64315790','p38150427','p98024156','p70684592','p39427165','p09682531','p24178095','p60927481','p56873024','p63702845','p21495036','p35468209','p37546918','p86092715','p54927031','p70428196','p16943057','p84301759','p06957132','p41075982','p78134290','p18732456','p28654079','p73518624','p56124037','p08416932','p06127935','p42178659','p25047183','p30592648','p72693851','p92453867','p56297804','p34759102','p31495620','p21053468','p72836954','p05426871','p03485972','p72408193','p65907124','p42953718','p05176823','p28635019','p15607483','p20183675','p70348295','p95602314','p18750962','p27396041','p65039842','p29861504','p12450839','p32164907','p08974362','p97310846','p57326049','p46039257','p16308954','p08927143','p96805214','p39687025','p02345978','p68704231','p65074391','p74130682','p56394728','p85971406','p34920175','p85497610','p98413562','p90841576','p52987460','p58426091','p70493586','p97831640','p65309184','p90462513','p37104865','p40217938','p80975236','p39142076','p14278930','p54731860','p50761948','p69431802','p20479615','p93710546','p17329085','p05327968','p62384590','p83964120','p82013564','p05248176','p91756083','p98314765','p91740526','p41870593','p82617439','p35621840','p94752683','p82149057','p65792034','p89762031','p20835149','p93681520','p47356108','p14578620','p90174356','p62917034','p16289450','p92061735','p51296307','p63854721','p28630741','p68347910','p81405976','p53904721','p21306457','p15937680','p43086715','p04731582','p01549628','p36590127','p81236547','p04372865','p17698354','p69548273','p75834209','p43905172','p51839024','p14027953','p59167832','p98301572','p97610358','p98235607','p84107325','p62073841','p57103248','p38061974','p63527048','p25417803','p29758346','p50461937','p45901728','p79032614','p90138467','p07652843','p57390261','p20654879','p94120685','p49328706','p91542867','p79038562','p46217093','p64350789','p07846235','p82730541','p79216034','p82403975','p85013724','p61359482','p29741638','p87961534','p63850471','p96701452','p87956143','p82501346','p15830476','p34296517','p54603217','p25386701','p59486271','p76250183','p50681423','p92356710','p72013695','p25174896','p87319624','p97583024','p95467102','p80627345','p29015467','p57318920','p13852069','p15490287','p05796328','p83027541','p76189403','p26193804','p34502967','p70368514','p43627890','p07961235','p68197045','p79368205','p25189364','p47560938','p04163285','p59834107','p52017496','p28539176','p76103582','p67214983','p25809413','p01684375','p54367192','p81940257','p31928657','p89572041','p10297384','p53291604','p47201568','p76409812','p63701854','p67135490','p04139825','p01472693','p97521430','p12346870','p08319675','p98250137','p02743168','p19427063','p72894315','p79358120','p70529146','p48130625','p92576038','p21796540','p59417328','p23701854','p61270835','p52913407','p21408795','p89253407','p68590432','p14056283','p83290617','p03754268','p65291703','p71835460','p63028519','p45397861','p96803572','p03741962','p85194607','p84652793','p76534189','p87346592','p51609348','p51728903','p20735491','p53249801','p90821357','p90271845','p36174902','p82345971','p39658240','p29037645','p19523084','p24735089','p23790645','p25780419','p72836401','p51473608','p89253710','p92435681','p71695423','p06298514','p84765192','p80973145','p76234901','p29041386','p48253917','p79326504','p67854932','p70846953','p49137086','p59132670','p45180932','p46208597','p75498316','p01928463','p72189630','p97081625','p74982531','p36217950','p70496351','p49085612','p45872916','p74368291','p67502819','p60493127','p91874265','p18407625','p09315486','p71306428','p68924531','p56934812','p92864103','p46891705','p48965017','p93284710','p62975041','p85013926','p13845267','p41367089','p86952047','p46715938','p84209513','p13695478','p27139648','p03549281','p96124038','p30816759','p98027543','p35809714','p02364951','p86129435','p14357092','p13604872','p46971853','p93105248','p56173408','p07419258','p05896741','p40859721','p57138092','p62083541','p37421598','p45739201','p81453902','p30679528','p51923746','p74081592','p87260935','p25603419','p82419076','p28561793','p71624835','p20685197','p95032418','p12305678','p01382794','p79416325','p71852639','p15297340','p80253914','p27985106','p62387095','p09615784','p69810735','p92046185','p04691538','p29561438','p96748523','p26349178','p53140687','p79360245','p96725043','p08946735','p41569073','p27018563','p63125809','p52014786','p95248160','p02173589','p42098156','p05321647','p89536047','p45701263','p59216748','p69850317','p70185432','p92018756','p29347815','p93240785','p40312865','p61894753','p53219607','p24385071','p74238150','p84760521','p63072491','p03596817','p41027368','p34527869','p29380451','p78934062','p32759104','p20934185','p89154230','p93870142','p31096457','p20743869','p32805697','p18674359','p97451280','p49680215','p85974201','p85346710','p21734698','p86942751','p85620714','p83769402','p58103429','p39701654','p09684175','p15094387','p90381257','p93680157','p49670125','p70293168','p24037156','p18736450','p01973852','p72459680','p92876154','p62587391','p02986317','p14390675','p36591724','p96538124','p38460152','p34291607','p26938541','p59071463','p51962430','p74639081','p32507896','p60975123','p36091572','p48071263','p34298105','p91365204','p98726041','p92168307','p31067542','p72961085','p94386207','p02453769','p18742503','p67835190','p85147902','p23079415','p62543087','p21873546','p96405328','p43586129','p24108635','p83026951','p68350421','p09318647','p97162543','p67185342','p35601974','p18450267','p30286179','p24179356','p13052498','p01962874','p78132509','p17562843','p65380429','p89670245','p34196587','p74392018','p54129673','p89705213','p80271365','p43168705','p18423067','p39057864','p70984165','p06841275','p84753160','p82465391','p70138459','p67024951','p50146287','p67904382','p29507168','p53628974','p90625378','p87619420','p81059632','p14786923','p53096748','p60783415','p51703482','p75401392','p67984023','p98523701','p40185679','p34057982','p65832097','p10742358','p45219703','p85914207','p96432058','p97043516','p68305921','p26135047','p60852143','p45671893','p41936527','p27015389','p78902156','p36895204','p16490573','p26185734','p59127306','p35071862','p24739165','p56179042','p18293604','p12074369','p32740518','p73028546','p29153687','p07328914','p63471052','p31849052','p25041869','p68427519','p12394508','p36710529','p59278036','p03518462','p25913408','p67905318','p64379201','p63948721','p36415870','p36874915','p73201598','p98534102','p27816504','p42056187','p25891046','p05872314','p19368045','p14390275','p08246193','p29863574','p76285934','p02835649','p84176235','p14603857','p06723581','p21580347','p92064571','p02459738','p73428590','p24807695','p79058623','p41297308','p34785092','p53206971','p90782563','p16024853','p03619725','p07123965','p36281475','p20654139','p79826134','p83215674','p80359714','p34857162','p02945871','p04317958','p85170239','p74051823','p26518940','p02635814','p82413657','p39607485','p62387409','p46081923','p10742853','p97126084','p01423876','p42679310','p09561482','p95862703','p37186459','p82406371','p78410965','p84596130','p14925836','p80146275','p03562197','p04576312','p36527018','p59187234','p46170235','p02163475','p87615324','p05691234','p96231745','p01865974','p24836917','p68714093','p80415972','p96587304','p49381276','p69218740','p74301682','p56278934','p97546102','p37896405','p62150938','p42078136','p58629041','p56803129','p74352198','p86205347','p83504671','p27034956','p10579286','p04976285','p27458390','p45210837','p16725489','p37041586','p38615249','p64950718','p97186325','p97635402','p91856613','p92874165','p32480596','p39254801','p68210359','p12583746','p86273145','p67514920','p25807463','p06839571','p35284706','p04551581','p91268403','p02142315','p12560947','p98567210','p59473016','p97248351','p74830458','p86524071','p17948350','p45920387','p85793146','p38149205','p86591027','p57064318','p31402598','renwen','renzhong','yuzhong','jiaoyu','gongwuyuan','baihuaban','shuziban','p63490875','p02738164','p56308142','p56932418','p87639245','p02103822','p75403168','p25970648','p08147695','p73194685','p63507129','p04896132','p48216530','p28091634','p90547381','p46259107','p18602397','p40381925','p48679103','p62660364','p53816940','p67428510','p64903278','p70981432','p43569802','p15680732','p07569831','p54183069','p50973641','p10378259','p57386409','p90835724','p92157683','p72856403','p60297481','p25674903','p47062581','p51927683','p08945163','p67392401','p60128394','p30791248','p30865794','p14365860','p13574098','p65427390','p42530869','p81407259','p29781560','p85147269','p10864573','p06382417','p97143502','p70281539','p80215369','p01682597','p16029574','p15672984','p40617389','p34215896','p03269785','p50874913','p76831094','p54619032','p49076185','p40156829','p03872954','p42506873','p83206417','p51820974','p42978530','p85631740','p49082367','p30654712','p45150945','p61547820','p35906278','p65120487','p82316754','p75183246','p50674321','p69415803','p31705269','p47295031','p97162085','p90378654','p91328675','p53962470','p58173402','p95078342','p95402816','p45832960','p51497286','p71045832','p67495213','p75620834','p50783612','p45619023','p49016357','p92546713','p04786391','p24108675','p13092847','p41235890','p61520730','p38906512','p24137568','p42573618','p20896315','p48310965','p13647289','p15624870','p52674013','p83571920','p74326809','p54712038','p72495360','p60517924','p25968041','p57364910','p73018265','p32065189','p12598647','p50218637','p86079321','p81257430','p52306894','p73615490','p31952407','p23974860','p36872140','p14982630','p68435927','p52360941','p48590137','p58206197','p16538049','p86975142','p70452891','p98063742','p48602953','p85237609','p87150349','p51978620','p75238014','starkylin','p08614975','p49562018','p85469723','WHU-CSE-IH-Team','p94108356','p58974620','p34520981','p02345198','p34265091','p03967182','p52069314','p09518632','p43850721','p75694102','p52803174','p64017953','p64952873','p93246150','p45091368','p98360154','p04675823','p49327518','p26743081','p36410592','p05924613','p68459203','p35812796','p14925308','p84152039','p38069172','p19286705','p01452789','p54708329'] + if ENV['count'].present? + user_logins = user_logins.sample(ENV['count'].to_i) + else + user_logins = user_logins.sample(rand(5..50)) + end + puts "user_count===#{user_logins.size}" + # 点赞 + user_logins.each do |u| + like_user = User.find_by(login: u) + next if like_user.liked?(project) + like_user.like!(project) + end end end \ No newline at end of file From 1139af2aff2a9fb2df803c6423ee13c965db5617 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 9 Mar 2023 14:20:00 +0800 Subject: [PATCH 102/438] =?UTF-8?q?=E6=89=B9=E9=87=8Ffork=E5=9B=A2?= =?UTF-8?q?=E9=98=9F=E4=BA=BA=E6=95=B0=E5=A4=84=E7=90=86,=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=82=B9=E8=B5=9E=E5=8D=95=E7=8B=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_forked_project.rake | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/tasks/batch_forked_project.rake b/lib/tasks/batch_forked_project.rake index 5834f89f9..be4140346 100644 --- a/lib/tasks/batch_forked_project.rake +++ b/lib/tasks/batch_forked_project.rake @@ -45,6 +45,7 @@ namespace :batch_forked_project do project_id = ENV['project_id'] puts "project_id=================#{project_id}" next if project_id.blank? + project = Project.find project_id user_logins = ['p89346015','p25371846','p69217483','p69805714','p78920563','p54261380','p18934275','p41273960','p76281309','p97134028','p89450236','p28097461','p60437152','p16925078','p13420986','p02315697','p73950468','p72348916','p65874312','p94723568','p35407816','p61830975','p48127056','p17832064','p06472319','p59827036','p49583267','p36120475','p63428509','p51029748','p98071642','p17580394','p96175348','p41672830','p68109573','p23185094','p62105398','p78052941','p39784256','p31704586','p25768904','p30916782','p97142530','p25706341','p90421386','p30547691','p12598607','p34096851','p56902314','p95014723','p57810362','p27049618','p21035879','p47560312','p45902861','p28534760','p95064217','p06819345','p24786109','p47862359','p67201548','p38275619','p02713685','p20516978','p92801564','p12894530','p38146059','p36259710','p65298073','p45926780','p65849120','p19425386','p41038257','p64871093','p49017526','p76438951','p09842165','p07546132','p74189326','p20819356','p79041358','p68315204','p23671945','p75086429','p75246983','p86719302','p57046318','p36402875','p29370514','p39284567','p84973510','p70912653','p87013296','p45801397','p75632498','p15097863','p37298104','p26813470','p80596471','p50234679','p94836501','p97481306','p03826457','p64398250','p06728315','p95802743','p10893624','p32197506','p60475139','p86321945','p26708531','p40531786','p43216578','p81793025','p65974130','p86049152','p68735142','p98625074','p08619275','p48179362','p81507936','p48719350','p79346812','p35027486','p60329715','p60539481','p76059481','p32659470','p73492805','p05214867','p83527960','p57284961','p84921730','p78614302','p58043692','p83795012','p72490365','p74031526','p19072458','p78305942','p79210548','p04273869','p20894137','p38905462','p46109723','p17250849','p79863042','p86354072','p70381452','p70852634','p01439876','p85409726','p13072985','p06975321','p42786905','p84576012','p63541897','p92760841','p83741256','p53029167','p80254167','p57062419','p52071649','p38649571','p54687012','p35487621','p90182463','p40937281','p56809147','p19543078','p69304857','p68457901','p63190852','p86140357','p57491630','p32801694','p16539028','p35182647','p81065927','p98142307','p57806943','p13286457','p61349702','p35168907','p59713608','p61397402','p42673859','p49085271','p31790624','p86451732','p31682759','p29108563','p64157932','p24086573','p50786231','p41237908','p58712463','p02635481','p63289457','p29836504','p42591076','p37620514','p58016429','p91068472','p21489537','p42068571','p09413782','p27456893','p30871956','p14983026','p09567821','p15038967','p34802159','p89234176','p97038246','p60173295','p02418537','p16423790','p71034629','p10284537','p08539174','p26359018','p32981056','p94538276','p92354178','p46271580','p46150238','p97850142','p81604759','p91084637','p04637589','p73852460','p52189704','p19084632','p14763208','p32746591','p47620913','p47068915','p02596781','p48530276','p28309164','p38564297','p14728506','p09413785','p56127938','p24085137','p60517892','p48261730','p45012768','p95741268','p97205463','p32816504','p93410257','p24736950','p07946812','p37408162','p97062183','p02763814','p37142856','p72063459','p36921540','p97583401','p95183074','p90816354','p20768431','p45763201','p07549382','p67502814','p79641052','p09471635','p56234879','p35214687','p25708641','p06452378','p05843697','p89562143','p76435829','p32574608','p24780615','p16408279','p48051237','p70695184','p01297543','p19647583','p41297630','p45163207','p08362159','p20853741','p52436710','p98243601','p97240356','p45980172','p91287634','p65903241','p16543708','p32968140','p72054981','p25904731','p42137095','p32480967','p81739025','p43590716','p04152936','p78094351','p24719605','p35078941','p26875103','p39617540','p32046579','p38614905','p37904815','p04637219','p16072398','p14509327','p64915802','p86901372','p23689415','p13627904','p07649125','p63974102','p90372815','p76839152','p70621953','p62783154','p69127034','p35762149','p46718029','p49038615','p13625784','p74835920','p71894530','p67253149','p95476182','p85632907','p64315790','p38150427','p98024156','p70684592','p39427165','p09682531','p24178095','p60927481','p56873024','p63702845','p21495036','p35468209','p37546918','p86092715','p54927031','p70428196','p16943057','p84301759','p06957132','p41075982','p78134290','p18732456','p28654079','p73518624','p56124037','p08416932','p06127935','p42178659','p25047183','p30592648','p72693851','p92453867','p56297804','p34759102','p31495620','p21053468','p72836954','p05426871','p03485972','p72408193','p65907124','p42953718','p05176823','p28635019','p15607483','p20183675','p70348295','p95602314','p18750962','p27396041','p65039842','p29861504','p12450839','p32164907','p08974362','p97310846','p57326049','p46039257','p16308954','p08927143','p96805214','p39687025','p02345978','p68704231','p65074391','p74130682','p56394728','p85971406','p34920175','p85497610','p98413562','p90841576','p52987460','p58426091','p70493586','p97831640','p65309184','p90462513','p37104865','p40217938','p80975236','p39142076','p14278930','p54731860','p50761948','p69431802','p20479615','p93710546','p17329085','p05327968','p62384590','p83964120','p82013564','p05248176','p91756083','p98314765','p91740526','p41870593','p82617439','p35621840','p94752683','p82149057','p65792034','p89762031','p20835149','p93681520','p47356108','p14578620','p90174356','p62917034','p16289450','p92061735','p51296307','p63854721','p28630741','p68347910','p81405976','p53904721','p21306457','p15937680','p43086715','p04731582','p01549628','p36590127','p81236547','p04372865','p17698354','p69548273','p75834209','p43905172','p51839024','p14027953','p59167832','p98301572','p97610358','p98235607','p84107325','p62073841','p57103248','p38061974','p63527048','p25417803','p29758346','p50461937','p45901728','p79032614','p90138467','p07652843','p57390261','p20654879','p94120685','p49328706','p91542867','p79038562','p46217093','p64350789','p07846235','p82730541','p79216034','p82403975','p85013724','p61359482','p29741638','p87961534','p63850471','p96701452','p87956143','p82501346','p15830476','p34296517','p54603217','p25386701','p59486271','p76250183','p50681423','p92356710','p72013695','p25174896','p87319624','p97583024','p95467102','p80627345','p29015467','p57318920','p13852069','p15490287','p05796328','p83027541','p76189403','p26193804','p34502967','p70368514','p43627890','p07961235','p68197045','p79368205','p25189364','p47560938','p04163285','p59834107','p52017496','p28539176','p76103582','p67214983','p25809413','p01684375','p54367192','p81940257','p31928657','p89572041','p10297384','p53291604','p47201568','p76409812','p63701854','p67135490','p04139825','p01472693','p97521430','p12346870','p08319675','p98250137','p02743168','p19427063','p72894315','p79358120','p70529146','p48130625','p92576038','p21796540','p59417328','p23701854','p61270835','p52913407','p21408795','p89253407','p68590432','p14056283','p83290617','p03754268','p65291703','p71835460','p63028519','p45397861','p96803572','p03741962','p85194607','p84652793','p76534189','p87346592','p51609348','p51728903','p20735491','p53249801','p90821357','p90271845','p36174902','p82345971','p39658240','p29037645','p19523084','p24735089','p23790645','p25780419','p72836401','p51473608','p89253710','p92435681','p71695423','p06298514','p84765192','p80973145','p76234901','p29041386','p48253917','p79326504','p67854932','p70846953','p49137086','p59132670','p45180932','p46208597','p75498316','p01928463','p72189630','p97081625','p74982531','p36217950','p70496351','p49085612','p45872916','p74368291','p67502819','p60493127','p91874265','p18407625','p09315486','p71306428','p68924531','p56934812','p92864103','p46891705','p48965017','p93284710','p62975041','p85013926','p13845267','p41367089','p86952047','p46715938','p84209513','p13695478','p27139648','p03549281','p96124038','p30816759','p98027543','p35809714','p02364951','p86129435','p14357092','p13604872','p46971853','p93105248','p56173408','p07419258','p05896741','p40859721','p57138092','p62083541','p37421598','p45739201','p81453902','p30679528','p51923746','p74081592','p87260935','p25603419','p82419076','p28561793','p71624835','p20685197','p95032418','p12305678','p01382794','p79416325','p71852639','p15297340','p80253914','p27985106','p62387095','p09615784','p69810735','p92046185','p04691538','p29561438','p96748523','p26349178','p53140687','p79360245','p96725043','p08946735','p41569073','p27018563','p63125809','p52014786','p95248160','p02173589','p42098156','p05321647','p89536047','p45701263','p59216748','p69850317','p70185432','p92018756','p29347815','p93240785','p40312865','p61894753','p53219607','p24385071','p74238150','p84760521','p63072491','p03596817','p41027368','p34527869','p29380451','p78934062','p32759104','p20934185','p89154230','p93870142','p31096457','p20743869','p32805697','p18674359','p97451280','p49680215','p85974201','p85346710','p21734698','p86942751','p85620714','p83769402','p58103429','p39701654','p09684175','p15094387','p90381257','p93680157','p49670125','p70293168','p24037156','p18736450','p01973852','p72459680','p92876154','p62587391','p02986317','p14390675','p36591724','p96538124','p38460152','p34291607','p26938541','p59071463','p51962430','p74639081','p32507896','p60975123','p36091572','p48071263','p34298105','p91365204','p98726041','p92168307','p31067542','p72961085','p94386207','p02453769','p18742503','p67835190','p85147902','p23079415','p62543087','p21873546','p96405328','p43586129','p24108635','p83026951','p68350421','p09318647','p97162543','p67185342','p35601974','p18450267','p30286179','p24179356','p13052498','p01962874','p78132509','p17562843','p65380429','p89670245','p34196587','p74392018','p54129673','p89705213','p80271365','p43168705','p18423067','p39057864','p70984165','p06841275','p84753160','p82465391','p70138459','p67024951','p50146287','p67904382','p29507168','p53628974','p90625378','p87619420','p81059632','p14786923','p53096748','p60783415','p51703482','p75401392','p67984023','p98523701','p40185679','p34057982','p65832097','p10742358','p45219703','p85914207','p96432058','p97043516','p68305921','p26135047','p60852143','p45671893','p41936527','p27015389','p78902156','p36895204','p16490573','p26185734','p59127306','p35071862','p24739165','p56179042','p18293604','p12074369','p32740518','p73028546','p29153687','p07328914','p63471052','p31849052','p25041869','p68427519','p12394508','p36710529','p59278036','p03518462','p25913408','p67905318','p64379201','p63948721','p36415870','p36874915','p73201598','p98534102','p27816504','p42056187','p25891046','p05872314','p19368045','p14390275','p08246193','p29863574','p76285934','p02835649','p84176235','p14603857','p06723581','p21580347','p92064571','p02459738','p73428590','p24807695','p79058623','p41297308','p34785092','p53206971','p90782563','p16024853','p03619725','p07123965','p36281475','p20654139','p79826134','p83215674','p80359714','p34857162','p02945871','p04317958','p85170239','p74051823','p26518940','p02635814','p82413657','p39607485','p62387409','p46081923','p10742853','p97126084','p01423876','p42679310','p09561482','p95862703','p37186459','p82406371','p78410965','p84596130','p14925836','p80146275','p03562197','p04576312','p36527018','p59187234','p46170235','p02163475','p87615324','p05691234','p96231745','p01865974','p24836917','p68714093','p80415972','p96587304','p49381276','p69218740','p74301682','p56278934','p97546102','p37896405','p62150938','p42078136','p58629041','p56803129','p74352198','p86205347','p83504671','p27034956','p10579286','p04976285','p27458390','p45210837','p16725489','p37041586','p38615249','p64950718','p97186325','p97635402','p91856613','p92874165','p32480596','p39254801','p68210359','p12583746','p86273145','p67514920','p25807463','p06839571','p35284706','p04551581','p91268403','p02142315','p12560947','p98567210','p59473016','p97248351','p74830458','p86524071','p17948350','p45920387','p85793146','p38149205','p86591027','p57064318','p31402598','renwen','renzhong','yuzhong','jiaoyu','gongwuyuan','baihuaban','shuziban','p63490875','p02738164','p56308142','p56932418','p87639245','p02103822','p75403168','p25970648','p08147695','p73194685','p63507129','p04896132','p48216530','p28091634','p90547381','p46259107','p18602397','p40381925','p48679103','p62660364','p53816940','p67428510','p64903278','p70981432','p43569802','p15680732','p07569831','p54183069','p50973641','p10378259','p57386409','p90835724','p92157683','p72856403','p60297481','p25674903','p47062581','p51927683','p08945163','p67392401','p60128394','p30791248','p30865794','p14365860','p13574098','p65427390','p42530869','p81407259','p29781560','p85147269','p10864573','p06382417','p97143502','p70281539','p80215369','p01682597','p16029574','p15672984','p40617389','p34215896','p03269785','p50874913','p76831094','p54619032','p49076185','p40156829','p03872954','p42506873','p83206417','p51820974','p42978530','p85631740','p49082367','p30654712','p45150945','p61547820','p35906278','p65120487','p82316754','p75183246','p50674321','p69415803','p31705269','p47295031','p97162085','p90378654','p91328675','p53962470','p58173402','p95078342','p95402816','p45832960','p51497286','p71045832','p67495213','p75620834','p50783612','p45619023','p49016357','p92546713','p04786391','p24108675','p13092847','p41235890','p61520730','p38906512','p24137568','p42573618','p20896315','p48310965','p13647289','p15624870','p52674013','p83571920','p74326809','p54712038','p72495360','p60517924','p25968041','p57364910','p73018265','p32065189','p12598647','p50218637','p86079321','p81257430','p52306894','p73615490','p31952407','p23974860','p36872140','p14982630','p68435927','p52360941','p48590137','p58206197','p16538049','p86975142','p70452891','p98063742','p48602953','p85237609','p87150349','p51978620','p75238014','starkylin','p08614975','p49562018','p85469723','WHU-CSE-IH-Team','p94108356','p58974620','p34520981','p02345198','p34265091','p03967182','p52069314','p09518632','p43850721','p75694102','p52803174','p64017953','p64952873','p93246150','p45091368','p98360154','p04675823','p49327518','p26743081','p36410592','p05924613','p68459203','p35812796','p14925308','p84152039','p38069172','p19286705','p01452789','p54708329'] if ENV['count'].present? user_logins = user_logins.sample(ENV['count'].to_i) From d4fecc0c9d07bb360278cd33b7a13a9aa7fb50f8 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 9 Mar 2023 14:27:01 +0800 Subject: [PATCH 103/438] =?UTF-8?q?=E6=89=B9=E9=87=8Ffork=E5=9B=A2?= =?UTF-8?q?=E9=98=9F=E4=BA=BA=E6=95=B0=E5=A4=84=E7=90=86,=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=82=B9=E8=B5=9E=E5=8D=95=E7=8B=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_forked_project.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/batch_forked_project.rake b/lib/tasks/batch_forked_project.rake index be4140346..447aff901 100644 --- a/lib/tasks/batch_forked_project.rake +++ b/lib/tasks/batch_forked_project.rake @@ -4,6 +4,7 @@ namespace :batch_forked_project do project_id = ENV['project_id'] puts "project_id=================#{project_id}" next if project_id.blank? + project = Project.find project_id user_logins = ['p89346015','p25371846','p69217483','p69805714','p78920563','p54261380','p18934275','p41273960','p76281309','p97134028','p89450236','p28097461','p60437152','p16925078','p13420986','p02315697','p73950468','p72348916','p65874312','p94723568','p35407816','p61830975','p48127056','p17832064','p06472319','p59827036','p49583267','p36120475','p63428509','p51029748','p98071642','p17580394','p96175348','p41672830','p68109573','p23185094','p62105398','p78052941','p39784256','p31704586','p25768904','p30916782','p97142530','p25706341','p90421386','p30547691','p12598607','p34096851','p56902314','p95014723','p57810362','p27049618','p21035879','p47560312','p45902861','p28534760','p95064217','p06819345','p24786109','p47862359','p67201548','p38275619','p02713685','p20516978','p92801564','p12894530','p38146059','p36259710','p65298073','p45926780','p65849120','p19425386','p41038257','p64871093','p49017526','p76438951','p09842165','p07546132','p74189326','p20819356','p79041358','p68315204','p23671945','p75086429','p75246983','p86719302','p57046318','p36402875','p29370514','p39284567','p84973510','p70912653','p87013296','p45801397','p75632498','p15097863','p37298104','p26813470','p80596471','p50234679','p94836501','p97481306','p03826457','p64398250','p06728315','p95802743','p10893624','p32197506','p60475139','p86321945','p26708531','p40531786','p43216578','p81793025','p65974130','p86049152','p68735142','p98625074','p08619275','p48179362','p81507936','p48719350','p79346812','p35027486','p60329715','p60539481','p76059481','p32659470','p73492805','p05214867','p83527960','p57284961','p84921730','p78614302','p58043692','p83795012','p72490365','p74031526','p19072458','p78305942','p79210548','p04273869','p20894137','p38905462','p46109723','p17250849','p79863042','p86354072','p70381452','p70852634','p01439876','p85409726','p13072985','p06975321','p42786905','p84576012','p63541897','p92760841','p83741256','p53029167','p80254167','p57062419','p52071649','p38649571','p54687012','p35487621','p90182463','p40937281','p56809147','p19543078','p69304857','p68457901','p63190852','p86140357','p57491630','p32801694','p16539028','p35182647','p81065927','p98142307','p57806943','p13286457','p61349702','p35168907','p59713608','p61397402','p42673859','p49085271','p31790624','p86451732','p31682759','p29108563','p64157932','p24086573','p50786231','p41237908','p58712463','p02635481','p63289457','p29836504','p42591076','p37620514','p58016429','p91068472','p21489537','p42068571','p09413782','p27456893','p30871956','p14983026','p09567821','p15038967','p34802159','p89234176','p97038246','p60173295','p02418537','p16423790','p71034629','p10284537','p08539174','p26359018','p32981056','p94538276','p92354178','p46271580','p46150238','p97850142','p81604759','p91084637','p04637589','p73852460','p52189704','p19084632','p14763208','p32746591','p47620913','p47068915','p02596781','p48530276','p28309164','p38564297','p14728506','p09413785','p56127938','p24085137','p60517892','p48261730','p45012768','p95741268','p97205463','p32816504','p93410257','p24736950','p07946812','p37408162','p97062183','p02763814','p37142856','p72063459','p36921540','p97583401','p95183074','p90816354','p20768431','p45763201','p07549382','p67502814','p79641052','p09471635','p56234879','p35214687','p25708641','p06452378','p05843697','p89562143','p76435829','p32574608','p24780615','p16408279','p48051237','p70695184','p01297543','p19647583','p41297630','p45163207','p08362159','p20853741','p52436710','p98243601','p97240356','p45980172','p91287634','p65903241','p16543708','p32968140','p72054981','p25904731','p42137095','p32480967','p81739025','p43590716','p04152936','p78094351','p24719605','p35078941','p26875103','p39617540','p32046579','p38614905','p37904815','p04637219','p16072398','p14509327','p64915802','p86901372','p23689415','p13627904','p07649125','p63974102','p90372815','p76839152','p70621953','p62783154','p69127034','p35762149','p46718029','p49038615','p13625784','p74835920','p71894530','p67253149','p95476182','p85632907','p64315790','p38150427','p98024156','p70684592','p39427165','p09682531','p24178095','p60927481','p56873024','p63702845','p21495036','p35468209','p37546918','p86092715','p54927031','p70428196','p16943057','p84301759','p06957132','p41075982','p78134290','p18732456','p28654079','p73518624','p56124037','p08416932','p06127935','p42178659','p25047183','p30592648','p72693851','p92453867','p56297804','p34759102','p31495620','p21053468','p72836954','p05426871','p03485972','p72408193','p65907124','p42953718','p05176823','p28635019','p15607483','p20183675','p70348295','p95602314','p18750962','p27396041','p65039842','p29861504','p12450839','p32164907','p08974362','p97310846','p57326049','p46039257','p16308954','p08927143','p96805214','p39687025','p02345978','p68704231','p65074391','p74130682','p56394728','p85971406','p34920175','p85497610','p98413562','p90841576','p52987460','p58426091','p70493586','p97831640','p65309184','p90462513','p37104865','p40217938','p80975236','p39142076','p14278930','p54731860','p50761948','p69431802','p20479615','p93710546','p17329085','p05327968','p62384590','p83964120','p82013564','p05248176','p91756083','p98314765','p91740526','p41870593','p82617439','p35621840','p94752683','p82149057','p65792034','p89762031','p20835149','p93681520','p47356108','p14578620','p90174356','p62917034','p16289450','p92061735','p51296307','p63854721','p28630741','p68347910','p81405976','p53904721','p21306457','p15937680','p43086715','p04731582','p01549628','p36590127','p81236547','p04372865','p17698354','p69548273','p75834209','p43905172','p51839024','p14027953','p59167832','p98301572','p97610358','p98235607','p84107325','p62073841','p57103248','p38061974','p63527048','p25417803','p29758346','p50461937','p45901728','p79032614','p90138467','p07652843','p57390261','p20654879','p94120685','p49328706','p91542867','p79038562','p46217093','p64350789','p07846235','p82730541','p79216034','p82403975','p85013724','p61359482','p29741638','p87961534','p63850471','p96701452','p87956143','p82501346','p15830476','p34296517','p54603217','p25386701','p59486271','p76250183','p50681423','p92356710','p72013695','p25174896','p87319624','p97583024','p95467102','p80627345','p29015467','p57318920','p13852069','p15490287','p05796328','p83027541','p76189403','p26193804','p34502967','p70368514','p43627890','p07961235','p68197045','p79368205','p25189364','p47560938','p04163285','p59834107','p52017496','p28539176','p76103582','p67214983','p25809413','p01684375','p54367192','p81940257','p31928657','p89572041','p10297384','p53291604','p47201568','p76409812','p63701854','p67135490','p04139825','p01472693','p97521430','p12346870','p08319675','p98250137','p02743168','p19427063','p72894315','p79358120','p70529146','p48130625','p92576038','p21796540','p59417328','p23701854','p61270835','p52913407','p21408795','p89253407','p68590432','p14056283','p83290617','p03754268','p65291703','p71835460','p63028519','p45397861','p96803572','p03741962','p85194607','p84652793','p76534189','p87346592','p51609348','p51728903','p20735491','p53249801','p90821357','p90271845','p36174902','p82345971','p39658240','p29037645','p19523084','p24735089','p23790645','p25780419','p72836401','p51473608','p89253710','p92435681','p71695423','p06298514','p84765192','p80973145','p76234901','p29041386','p48253917','p79326504','p67854932','p70846953','p49137086','p59132670','p45180932','p46208597','p75498316','p01928463','p72189630','p97081625','p74982531','p36217950','p70496351','p49085612','p45872916','p74368291','p67502819','p60493127','p91874265','p18407625','p09315486','p71306428','p68924531','p56934812','p92864103','p46891705','p48965017','p93284710','p62975041','p85013926','p13845267','p41367089','p86952047','p46715938','p84209513','p13695478','p27139648','p03549281','p96124038','p30816759','p98027543','p35809714','p02364951','p86129435','p14357092','p13604872','p46971853','p93105248','p56173408','p07419258','p05896741','p40859721','p57138092','p62083541','p37421598','p45739201','p81453902','p30679528','p51923746','p74081592','p87260935','p25603419','p82419076','p28561793','p71624835','p20685197','p95032418','p12305678','p01382794','p79416325','p71852639','p15297340','p80253914','p27985106','p62387095','p09615784','p69810735','p92046185','p04691538','p29561438','p96748523','p26349178','p53140687','p79360245','p96725043','p08946735','p41569073','p27018563','p63125809','p52014786','p95248160','p02173589','p42098156','p05321647','p89536047','p45701263','p59216748','p69850317','p70185432','p92018756','p29347815','p93240785','p40312865','p61894753','p53219607','p24385071','p74238150','p84760521','p63072491','p03596817','p41027368','p34527869','p29380451','p78934062','p32759104','p20934185','p89154230','p93870142','p31096457','p20743869','p32805697','p18674359','p97451280','p49680215','p85974201','p85346710','p21734698','p86942751','p85620714','p83769402','p58103429','p39701654','p09684175','p15094387','p90381257','p93680157','p49670125','p70293168','p24037156','p18736450','p01973852','p72459680','p92876154','p62587391','p02986317','p14390675','p36591724','p96538124','p38460152','p34291607','p26938541','p59071463','p51962430','p74639081','p32507896','p60975123','p36091572','p48071263','p34298105','p91365204','p98726041','p92168307','p31067542','p72961085','p94386207','p02453769','p18742503','p67835190','p85147902','p23079415','p62543087','p21873546','p96405328','p43586129','p24108635','p83026951','p68350421','p09318647','p97162543','p67185342','p35601974','p18450267','p30286179','p24179356','p13052498','p01962874','p78132509','p17562843','p65380429','p89670245','p34196587','p74392018','p54129673','p89705213','p80271365','p43168705','p18423067','p39057864','p70984165','p06841275','p84753160','p82465391','p70138459','p67024951','p50146287','p67904382','p29507168','p53628974','p90625378','p87619420','p81059632','p14786923','p53096748','p60783415','p51703482','p75401392','p67984023','p98523701','p40185679','p34057982','p65832097','p10742358','p45219703','p85914207','p96432058','p97043516','p68305921','p26135047','p60852143','p45671893','p41936527','p27015389','p78902156','p36895204','p16490573','p26185734','p59127306','p35071862','p24739165','p56179042','p18293604','p12074369','p32740518','p73028546','p29153687','p07328914','p63471052','p31849052','p25041869','p68427519','p12394508','p36710529','p59278036','p03518462','p25913408','p67905318','p64379201','p63948721','p36415870','p36874915','p73201598','p98534102','p27816504','p42056187','p25891046','p05872314','p19368045','p14390275','p08246193','p29863574','p76285934','p02835649','p84176235','p14603857','p06723581','p21580347','p92064571','p02459738','p73428590','p24807695','p79058623','p41297308','p34785092','p53206971','p90782563','p16024853','p03619725','p07123965','p36281475','p20654139','p79826134','p83215674','p80359714','p34857162','p02945871','p04317958','p85170239','p74051823','p26518940','p02635814','p82413657','p39607485','p62387409','p46081923','p10742853','p97126084','p01423876','p42679310','p09561482','p95862703','p37186459','p82406371','p78410965','p84596130','p14925836','p80146275','p03562197','p04576312','p36527018','p59187234','p46170235','p02163475','p87615324','p05691234','p96231745','p01865974','p24836917','p68714093','p80415972','p96587304','p49381276','p69218740','p74301682','p56278934','p97546102','p37896405','p62150938','p42078136','p58629041','p56803129','p74352198','p86205347','p83504671','p27034956','p10579286','p04976285','p27458390','p45210837','p16725489','p37041586','p38615249','p64950718','p97186325','p97635402','p91856613','p92874165','p32480596','p39254801','p68210359','p12583746','p86273145','p67514920','p25807463','p06839571','p35284706','p04551581','p91268403','p02142315','p12560947','p98567210','p59473016','p97248351','p74830458','p86524071','p17948350','p45920387','p85793146','p38149205','p86591027','p57064318','p31402598','renwen','renzhong','yuzhong','jiaoyu','gongwuyuan','baihuaban','shuziban','p63490875','p02738164','p56308142','p56932418','p87639245','p02103822','p75403168','p25970648','p08147695','p73194685','p63507129','p04896132','p48216530','p28091634','p90547381','p46259107','p18602397','p40381925','p48679103','p62660364','p53816940','p67428510','p64903278','p70981432','p43569802','p15680732','p07569831','p54183069','p50973641','p10378259','p57386409','p90835724','p92157683','p72856403','p60297481','p25674903','p47062581','p51927683','p08945163','p67392401','p60128394','p30791248','p30865794','p14365860','p13574098','p65427390','p42530869','p81407259','p29781560','p85147269','p10864573','p06382417','p97143502','p70281539','p80215369','p01682597','p16029574','p15672984','p40617389','p34215896','p03269785','p50874913','p76831094','p54619032','p49076185','p40156829','p03872954','p42506873','p83206417','p51820974','p42978530','p85631740','p49082367','p30654712','p45150945','p61547820','p35906278','p65120487','p82316754','p75183246','p50674321','p69415803','p31705269','p47295031','p97162085','p90378654','p91328675','p53962470','p58173402','p95078342','p95402816','p45832960','p51497286','p71045832','p67495213','p75620834','p50783612','p45619023','p49016357','p92546713','p04786391','p24108675','p13092847','p41235890','p61520730','p38906512','p24137568','p42573618','p20896315','p48310965','p13647289','p15624870','p52674013','p83571920','p74326809','p54712038','p72495360','p60517924','p25968041','p57364910','p73018265','p32065189','p12598647','p50218637','p86079321','p81257430','p52306894','p73615490','p31952407','p23974860','p36872140','p14982630','p68435927','p52360941','p48590137','p58206197','p16538049','p86975142','p70452891','p98063742','p48602953','p85237609','p87150349','p51978620','p75238014','starkylin','p08614975','p49562018','p85469723','WHU-CSE-IH-Team','p94108356','p58974620','p34520981','p02345198','p34265091','p03967182','p52069314','p09518632','p43850721','p75694102','p52803174','p64017953','p64952873','p93246150','p45091368','p98360154','p04675823','p49327518','p26743081','p36410592','p05924613','p68459203','p35812796','p14925308','p84152039','p38069172','p19286705','p01452789','p54708329'] if ENV['count'].present? user_logins = user_logins.sample(ENV['count'].to_i) @@ -13,7 +14,6 @@ namespace :batch_forked_project do begin user = User.find_by(login: username) next if user.blank? - project = Project.find project_id next if Project.exists?(user_id: user.id, identifier: project.identifier) new_project = Projects::ForkService.new(user, project, nil).call random_num = rand(2..8) From 6e16a9397c45a1ae0d6f44ad4b9b5a45573afe28 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 9 Mar 2023 16:02:50 +0800 Subject: [PATCH 104/438] =?UTF-8?q?fixed=20=E6=90=9C=E7=B4=A2=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=97=B6=E8=BF=87=E8=99=91=E8=A1=A8=E6=83=85=E5=AD=97?= =?UTF-8?q?=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/owner.rb | 2 ++ app/models/user.rb | 2 ++ 2 files changed, 4 insertions(+) diff --git a/app/models/owner.rb b/app/models/owner.rb index 2763dc80f..75ec6a2c3 100644 --- a/app/models/owner.rb +++ b/app/models/owner.rb @@ -69,6 +69,8 @@ class Owner < ApplicationRecord has_many :applied_transfer_projects, dependent: :destroy scope :like, lambda { |keywords| + # 表情处理 + keywords = keywords.each_char.select { |c| c.bytes.first < 240 }.join('') sql = "CONCAT(lastname, firstname) LIKE :search OR nickname LIKE :search OR login LIKE :search " where(sql, :search => "%#{keywords.strip}%") unless keywords.blank? } diff --git a/app/models/user.rb b/app/models/user.rb index 193e6c68f..997053e0c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -185,6 +185,8 @@ class User < Owner # Groups and active users scope :active, lambda { where(status: [STATUS_ACTIVE, STATUS_EDIT_INFO]) } scope :like, lambda { |keywords| + # 表情处理 + keywords = keywords.each_char.select { |c| c.bytes.first < 240 }.join('') sql = "CONCAT(lastname, firstname) LIKE :search OR nickname LIKE :search OR login LIKE :search OR mail LIKE :search OR nickname LIKE :search" where(sql, :search => "%#{keywords.strip}%") unless keywords.blank? } From 701d5dea4085d7869dbe59c82bcba37afeb7e094 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 9 Mar 2023 16:06:04 +0800 Subject: [PATCH 105/438] =?UTF-8?q?fixed=20=E6=90=9C=E7=B4=A2=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=97=B6=E8=BF=87=E8=99=91=E8=A1=A8=E6=83=85=E5=AD=97?= =?UTF-8?q?=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/owner.rb | 2 +- app/models/user.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/owner.rb b/app/models/owner.rb index 75ec6a2c3..d348970f0 100644 --- a/app/models/owner.rb +++ b/app/models/owner.rb @@ -70,7 +70,7 @@ class Owner < ApplicationRecord scope :like, lambda { |keywords| # 表情处理 - keywords = keywords.each_char.select { |c| c.bytes.first < 240 }.join('') + keywords = keywords.to_s.each_char.select { |c| c.bytes.first < 240 }.join('') sql = "CONCAT(lastname, firstname) LIKE :search OR nickname LIKE :search OR login LIKE :search " where(sql, :search => "%#{keywords.strip}%") unless keywords.blank? } diff --git a/app/models/user.rb b/app/models/user.rb index 997053e0c..5e21212ab 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -186,7 +186,7 @@ class User < Owner scope :active, lambda { where(status: [STATUS_ACTIVE, STATUS_EDIT_INFO]) } scope :like, lambda { |keywords| # 表情处理 - keywords = keywords.each_char.select { |c| c.bytes.first < 240 }.join('') + keywords = keywords.to_s.each_char.select { |c| c.bytes.first < 240 }.join('') sql = "CONCAT(lastname, firstname) LIKE :search OR nickname LIKE :search OR login LIKE :search OR mail LIKE :search OR nickname LIKE :search" where(sql, :search => "%#{keywords.strip}%") unless keywords.blank? } From d993df7df4de5472827eb57599bd91011b6cc6c5 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 9 Mar 2023 16:07:38 +0800 Subject: [PATCH 106/438] =?UTF-8?q?fixed=20=E6=90=9C=E7=B4=A2=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=97=B6=E8=BF=87=E8=99=91=E8=A1=A8=E6=83=85=E5=AD=97?= =?UTF-8?q?=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/owner.rb | 2 ++ app/models/user.rb | 2 ++ 2 files changed, 4 insertions(+) diff --git a/app/models/owner.rb b/app/models/owner.rb index 2763dc80f..d348970f0 100644 --- a/app/models/owner.rb +++ b/app/models/owner.rb @@ -69,6 +69,8 @@ class Owner < ApplicationRecord has_many :applied_transfer_projects, dependent: :destroy scope :like, lambda { |keywords| + # 表情处理 + keywords = keywords.to_s.each_char.select { |c| c.bytes.first < 240 }.join('') sql = "CONCAT(lastname, firstname) LIKE :search OR nickname LIKE :search OR login LIKE :search " where(sql, :search => "%#{keywords.strip}%") unless keywords.blank? } diff --git a/app/models/user.rb b/app/models/user.rb index 193e6c68f..5e21212ab 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -185,6 +185,8 @@ class User < Owner # Groups and active users scope :active, lambda { where(status: [STATUS_ACTIVE, STATUS_EDIT_INFO]) } scope :like, lambda { |keywords| + # 表情处理 + keywords = keywords.to_s.each_char.select { |c| c.bytes.first < 240 }.join('') sql = "CONCAT(lastname, firstname) LIKE :search OR nickname LIKE :search OR login LIKE :search OR mail LIKE :search OR nickname LIKE :search" where(sql, :search => "%#{keywords.strip}%") unless keywords.blank? } From 6f7b40ec244b436952deea79cd2b7341f5b79d9f Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 9 Mar 2023 16:22:48 +0800 Subject: [PATCH 107/438] =?UTF-8?q?fixed=20=E6=90=9C=E7=B4=A2=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E9=A1=B9=E7=9B=AE=E6=97=B6=E8=BF=87=E8=99=91=E8=A1=A8?= =?UTF-8?q?=E6=83=85=E5=AD=97=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/organizations/projects_controller.rb | 9 ++++++--- app/models/project.rb | 2 ++ app/queries/projects/list_my_query.rb | 6 ++++-- app/queries/projects/list_query.rb | 4 +++- app/services/api/v1/users/projects/list_service.rb | 4 +++- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/controllers/organizations/projects_controller.rb b/app/controllers/organizations/projects_controller.rb index b36a76125..ab5c9ef5d 100644 --- a/app/controllers/organizations/projects_controller.rb +++ b/app/controllers/organizations/projects_controller.rb @@ -8,14 +8,17 @@ class Organizations::ProjectsController < Organizations::BaseController .joins(team_projects: {team: :team_users}) .where(team_users: {user_id: current_user.id}).to_sql @projects = Project.from("( #{ public_projects_sql} UNION #{ private_projects_sql } ) AS projects") - - @projects = @projects.ransack(name_or_identifier_cont: params[:search]).result if params[:search].present? + # 表情处理 + keywords = params[:search].to_s.each_char.select { |c| c.bytes.first < 240 }.join('') + @projects = @projects.ransack(name_or_identifier_cont: keywords).result if params[:search].present? @projects = @projects.includes(:owner).order("projects.#{sort} #{sort_direction}") @projects = paginate(@projects) end def search tip_exception("请输入搜索关键词") if params[:search].nil? + # 表情处理 + keywords = params[:search].to_s.each_char.select { |c| c.bytes.first < 240 }.join('') public_projects_sql = @organization.projects.where(is_public: true).to_sql private_projects_sql = @organization.projects .where(is_public: false) @@ -23,7 +26,7 @@ class Organizations::ProjectsController < Organizations::BaseController .where(team_users: {user_id: current_user.id}).to_sql @projects = Project.from("( #{ public_projects_sql} UNION #{ private_projects_sql } ) AS projects") - @projects = @projects.ransack(name_or_identifier_cont: params[:search]).result + @projects = @projects.ransack(name_or_identifier_cont: keywords).result @projects = @projects.includes(:owner).order("projects.#{sort} #{sort_direction}") end diff --git a/app/models/project.rb b/app/models/project.rb index 68a8d071d..54d6ac520 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -240,6 +240,8 @@ class Project < ApplicationRecord end def self.search_project(search) + # 表情处理 + search = search.to_s.each_char.select { |c| c.bytes.first < 240 }.join('') ransack(name_or_identifier_cont: search) end # 创建者 diff --git a/app/queries/projects/list_my_query.rb b/app/queries/projects/list_my_query.rb index 6c7f38d9c..bc0cda1a2 100644 --- a/app/queries/projects/list_my_query.rb +++ b/app/queries/projects/list_my_query.rb @@ -52,8 +52,10 @@ class Projects::ListMyQuery < ApplicationQuery elsif params[:project_type].to_s === "sync_mirror" projects = projects.sync_mirror end - - q = projects.ransack(name_or_identifier_cont: params[:search]) + + # 表情处理 + keywords = params[:search].to_s.each_char.select { |c| c.bytes.first < 240 }.join('') + q = projects.ransack(name_or_identifier_cont: keywords) scope = q.result.includes(:project_category, :project_language,:owner, :repository, :has_pinned_users) diff --git a/app/queries/projects/list_query.rb b/app/queries/projects/list_query.rb index 6b0843540..2b048bd87 100644 --- a/app/queries/projects/list_query.rb +++ b/app/queries/projects/list_query.rb @@ -51,7 +51,9 @@ class Projects::ListQuery < ApplicationQuery # items = items.where(id: @ids).by_name_or_identifier(params[:search]) items = items.where(id: @ids) else - items = items.by_name_or_identifier(params[:search]).or(main_collection.where(user_id: Owner.like(params[:search]).pluck(:id))) + # 表情处理 + keywords = params[:search].to_s.each_char.select { |c| c.bytes.first < 240 }.join('') + items = items.by_name_or_identifier(keywords).or(main_collection.where(user_id: Owner.like(keywords).pluck(:id))) end items end diff --git a/app/services/api/v1/users/projects/list_service.rb b/app/services/api/v1/users/projects/list_service.rb index 8b3bffef0..47457c58c 100644 --- a/app/services/api/v1/users/projects/list_service.rb +++ b/app/services/api/v1/users/projects/list_service.rb @@ -73,8 +73,10 @@ class Api::V1::Users::Projects::ListService < ApplicationService end - projects = projects.with_project_type(project_type) + projects = projects.with_project_type(project_type) + # 表情处理 + search = search.to_s.each_char.select { |c| c.bytes.first < 240 }.join('') q = projects.ransack(name_or_identifier_cont: search) scope = q.result.includes(:project_category, :project_language,:owner, :repository, :has_pinned_users) From 6bb3f9297327a700147344d6fe6cded11519f55a Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 9 Mar 2023 17:45:03 +0800 Subject: [PATCH 108/438] =?UTF-8?q?=E5=BC=80=E5=90=AF=E7=A1=AE=E6=9D=83?= =?UTF-8?q?=E6=BF=80=E5=8A=B1=E7=9A=84=E7=94=A8=E6=88=B7=E6=88=96=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=8F=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/projects_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 03e06ec6e..3461160f8 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -66,7 +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: EduSetting.get("open_blockchain_projects").to_s.split(",").include?(project.id.to_s) || EduSetting.get("open_blockchain_users").to_s.split(",").include?(project.identifier), + open_blockchain: EduSetting.get("open_blockchain_projects").to_s.split(",").include?(project.id.to_s) || EduSetting.get("open_blockchain_projects").to_s.split(",").include?(project.identifier) || EduSetting.get("open_blockchain_users").to_s.split(",").include?(user.id) || EduSetting.get("open_blockchain_users").to_s.split(",").include?(user.login), ignore_id: project.ignore_id }).compact From e1c6cf3c544ea186e0741637d0b71b7da4fdbc54 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 10 Mar 2023 11:19:10 +0800 Subject: [PATCH 109/438] =?UTF-8?q?=E6=89=B9=E9=87=8Ffork=E5=9B=A2?= =?UTF-8?q?=E9=98=9F=E4=BA=BA=E6=95=B0=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_forked_project.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/batch_forked_project.rake b/lib/tasks/batch_forked_project.rake index 447aff901..4cb50a77a 100644 --- a/lib/tasks/batch_forked_project.rake +++ b/lib/tasks/batch_forked_project.rake @@ -16,7 +16,7 @@ namespace :batch_forked_project do next if user.blank? next if Project.exists?(user_id: user.id, identifier: project.identifier) new_project = Projects::ForkService.new(user, project, nil).call - random_num = rand(2..8) + random_num = rand(5..20) members = user_logins.sample(random_num) members.each do |m| m_user = User.find_by(login: m) From a0d4f2f404c6e8a808f43906c8313ca1c4cd5df0 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 10 Mar 2023 14:35:20 +0800 Subject: [PATCH 110/438] =?UTF-8?q?=E7=BE=A4=E6=99=BA=E7=86=B5=E5=88=86?= =?UTF-8?q?=E6=9E=90=E6=8A=A5=E8=A1=A8=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/projects_helper.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 3461160f8..c904b1743 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -66,7 +66,6 @@ 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: EduSetting.get("open_blockchain_projects").to_s.split(",").include?(project.id.to_s) || EduSetting.get("open_blockchain_projects").to_s.split(",").include?(project.identifier) || EduSetting.get("open_blockchain_users").to_s.split(",").include?(user.id) || EduSetting.get("open_blockchain_users").to_s.split(",").include?(user.login), ignore_id: project.ignore_id }).compact @@ -182,7 +181,7 @@ module ProjectsHelper end def ai_shang_v3_url(project) - url = EduSetting.get("ai_shang_v3_url") || "https://entropy.ingress.isa.buaanlsde.cn" + url = EduSetting.get("ai_shang_v3_url") || "https://shang.gitlink.org.cn/v3" case project.identifier.to_s.downcase when nil then "" when 'rails' then "#{url}/rails/entropy" From 18156ffd8d61324d67883fc5a6f96ed8efcb1cbb Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 2 Mar 2023 15:55:46 +0800 Subject: [PATCH 111/438] =?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 112/438] =?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 113/438] =?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 114/438] =?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 115/438] =?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 116/438] =?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 117/438] 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 118/438] =?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 119/438] =?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 120/438] =?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 121/438] =?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 122/438] =?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 123/438] =?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 124/438] =?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 125/438] =?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 126/438] =?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 127/438] =?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 128/438] =?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 129/438] =?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 130/438] =?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 131/438] =?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 132/438] =?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 133/438] =?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 134/438] =?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 135/438] =?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 136/438] =?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 137/438] =?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 138/438] =?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 139/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Atoken?= =?UTF-8?q?=E8=BD=AC=E8=B4=A6=E5=88=97=E8=A1=A8=E6=96=B0=E5=A2=9E=E5=88=86?= =?UTF-8?q?=E9=A1=B5=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 140/438] =?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 141/438] =?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 142/438] =?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 143/438] =?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 144/438] =?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 145/438] =?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 146/438] =?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 147/438] 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 148/438] 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 149/438] 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 150/438] 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 151/438] =?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 152/438] =?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}" From f601712a31f6acc3c4e22531d1deed108f675263 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Sat, 11 Mar 2023 13:15:41 +0800 Subject: [PATCH 153/438] =?UTF-8?q?=E7=BE=A4=E6=99=BA=E7=86=B5=E5=88=86?= =?UTF-8?q?=E6=9E=90=E6=8A=A5=E8=A1=A8=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/gitea/client_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/gitea/client_service.rb b/app/services/gitea/client_service.rb index e2bd9d491..e7e96328f 100644 --- a/app/services/gitea/client_service.rb +++ b/app/services/gitea/client_service.rb @@ -82,7 +82,7 @@ class Gitea::ClientService < ApplicationService req.headers['Content-Type'] = 'application/json' req.response :logger # 显示日志 req.adapter Faraday.default_adapter - req.options.timeout = 1200 # open/read timeout in seconds + req.options.timeout = 1800 # open/read timeout in seconds req.options.open_timeout = 10 # connection open timeout in seconds if token.blank? req.basic_auth(username, secret) From d665d6ff34e4f14f29bd36a4f04ad51e6d30565b Mon Sep 17 00:00:00 2001 From: xxq250 Date: Sat, 11 Mar 2023 13:56:38 +0800 Subject: [PATCH 154/438] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E5=BB=B6=E9=95=BF=E5=88=B01=E5=B0=8F=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/gitea/client_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/gitea/client_service.rb b/app/services/gitea/client_service.rb index e7e96328f..3d76c48b7 100644 --- a/app/services/gitea/client_service.rb +++ b/app/services/gitea/client_service.rb @@ -82,7 +82,7 @@ class Gitea::ClientService < ApplicationService req.headers['Content-Type'] = 'application/json' req.response :logger # 显示日志 req.adapter Faraday.default_adapter - req.options.timeout = 1800 # open/read timeout in seconds + req.options.timeout = 3600 # open/read timeout in seconds req.options.open_timeout = 10 # connection open timeout in seconds if token.blank? req.basic_auth(username, secret) From 2b63d48ecb8404b1604cc8b3b4fa976e99a97276 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 13 Mar 2023 14:36:32 +0800 Subject: [PATCH 155/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=A3=B0?= =?UTF-8?q?=E6=98=8E=E6=84=9F=E7=9F=A5=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/claims_controller.rb | 1 + app/jobs/send_template_message_job.rb | 10 ++++++- app/models/claim.rb | 1 + app/models/issue.rb | 1 + app/models/message_template.rb | 1 + app/models/message_template/issue_claim.rb | 31 ++++++++++++++++++++++ 6 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 app/models/message_template/issue_claim.rb diff --git a/app/controllers/claims_controller.rb b/app/controllers/claims_controller.rb index d9959bafd..9132f823f 100644 --- a/app/controllers/claims_controller.rb +++ b/app/controllers/claims_controller.rb @@ -39,6 +39,7 @@ class ClaimsController < ApplicationController journal = Journal.new(journal_params) if journal.save + SendTemplateMessageJob.perform_later('IssueClaim', current_user.id, @issue&.id) render file: 'app/views/claims/list.json.jbuilder' else normal_status(-1,"新建声明关联评论操作失败") diff --git a/app/jobs/send_template_message_job.rb b/app/jobs/send_template_message_job.rb index c40a3c9bd..da289857e 100644 --- a/app/jobs/send_template_message_job.rb +++ b/app/jobs/send_template_message_job.rb @@ -56,13 +56,21 @@ class SendTemplateMessageJob < ApplicationJob operator = User.find_by_id(operator_id) issue = Issue.find_by_id(issue_id) return unless operator.present? && issue.present? - receivers = User.where(id: issue.assigners.pluck(:id).append(issue&.author_id)).where.not(id: operator&.id) + receivers = User.where(id: (issue.assigners.pluck(:id).append(issue&.author_id) + issue.claim_users.pluck(:id)).uniq).where.not(id: operator&.id) receivers_string, content, notification_url = MessageTemplate::IssueChanged.get_message_content(receivers, operator, issue, change_params.symbolize_keys) Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, issue_id: issue.id, change_params: change_params.symbolize_keys}) receivers.find_each do |receiver| receivers_email_string, email_title, email_content = MessageTemplate::IssueChanged.get_email_message_content(receiver, operator, issue, change_params) Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content) end + when 'IssueClaim' + operator_id, issue_id = args[0], args[1] + operator = User.find_by_id(operator_id) + issue = Issue.find_by_id(issue_id) + return unless operator.present? && issue.present? + receivers = User.where(id: issue.author_id).where.not(id: operator&.id) + receivers_string, content, notification_url = MessageTemplate::IssueClaim.get_message_content(receivers, operator, issue) + Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, issue_id: issue.id}) when 'IssueExpire' issue_id = args[0] issue = Issue.find_by_id(issue_id) diff --git a/app/models/claim.rb b/app/models/claim.rb index 963b5f55a..25f333e3e 100644 --- a/app/models/claim.rb +++ b/app/models/claim.rb @@ -17,5 +17,6 @@ class Claim < ApplicationRecord belongs_to :user, foreign_key: :user_id + belongs_to :issue scope :claim_includes, ->{includes(:user)} end diff --git a/app/models/issue.rb b/app/models/issue.rb index 9c61f3ec3..0d38f7a2a 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -65,6 +65,7 @@ class Issue < ApplicationRecord has_many :journals, :as => :journalized, :dependent => :destroy has_many :journal_details, through: :journals has_many :claims, :dependent => :destroy + has_many :claim_users, through: :claims, source: :user has_many :issue_tags_relates, dependent: :destroy has_many :issue_tags, through: :issue_tags_relates has_many :issue_times, dependent: :destroy diff --git a/app/models/message_template.rb b/app/models/message_template.rb index 200c2f676..7ab7fdad8 100644 --- a/app/models/message_template.rb +++ b/app/models/message_template.rb @@ -24,6 +24,7 @@ class MessageTemplate < ApplicationRecord self.create(type: 'MessageTemplate::IssueAtme', sys_notice: '{nickname} 在疑修 {title} 中@我', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}') email_html = File.read("#{email_template_html_dir}/issue_changed.html") self.create(type: 'MessageTemplate::IssueChanged', sys_notice: '在项目 {nickname2}/{repository} 的疑修 {title} 中:{ifassigner}{nickname1}将负责人从 {assigner1} 修改为 {assigner2} {endassigner}{ifstatus}{nickname1}将状态从 {status1} 修改为 {status2} {endstatus}{iftracker}{nickname1}将类型从 {tracker1} 修改为 {tracker2} {endtracker}{ifpriority}{nickname1}将优先级从 {priority1} 修改为 {priority2} {endpriority}{ifmilestone}{nickname1}将里程碑从 {milestone1} 修改为 {milestone2} {endmilestone}{iftag}{nickname1}将标记从 {tag1} 修改为 {tag2} {endtag}{ifdoneratio}{nickname1}将完成度从 {doneratio1} 修改为 {doneratio2} {enddoneratio}{ifbranch}{nickname1}将指定分支从 {branch1} 修改为 {branch2} {endbranch}{ifstartdate}{nickname1}将开始日期从 {startdate1} 修改为 {startdate2} {endstartdate}{ifduedate}{nickname1}将结束日期从 {duedate1} 修改为 {duedate2} {endduedate}', email: email_html, email_title: "#{PLATFORM}: 疑修 {title} 有状态变更", notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}') + self.create(type: 'MessageTemplate::IssueClaim', sys_notice: '在 {nickname2}/{repository} 的疑修 {title} 中, {nickname1} 新建了一条声明', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}') email_html = File.read("#{email_template_html_dir}/issue_expire.html") self.create(type: 'MessageTemplate::IssueExpire', sys_notice: '疑修 {title} 已临近截止日期,请尽快处理', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}', email: email_html, email_title: "#{PLATFORM}: 疑修截止日期到达最后一天") email_html = File.read("#{email_template_html_dir}/issue_deleted.html") diff --git a/app/models/message_template/issue_claim.rb b/app/models/message_template/issue_claim.rb new file mode 100644 index 000000000..0a7b6e4e0 --- /dev/null +++ b/app/models/message_template/issue_claim.rb @@ -0,0 +1,31 @@ +# == Schema Information +# +# Table name: message_templates +# +# id :integer not null, primary key +# type :string(255) +# sys_notice :text(65535) +# email :text(65535) +# created_at :datetime not null +# updated_at :datetime not null +# notification_url :string(255) +# email_title :string(255) +# + +# 在疑修中创建声明 +class MessageTemplate::IssueClaim < MessageTemplate + + # MessageTemplate::IssueAtme.get_message_content(User.where(login: 'yystopf'), User.last, Issue.last) + def self.get_message_content(receivers, operator, issue) + return '', '', '' if receivers.blank? + project = issue&.project + owner = project&.owner + content = sys_notice.gsub('{nickname1}', operator&.real_name).gsub('{nickname2}', owner&.real_name).gsub('{repository}', project&.name).gsub('{title}', issue&.subject) + url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.project_issues_index.to_s) + + return receivers_string(receivers), content, url + rescue => e + Rails.logger.info("MessageTemplate::IssueClaim.get_message_content [ERROR] #{e}") + return 0, '', '' + end +end From b33c0408747997cf212f048b1f97701c83b9f3a6 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 13 Mar 2023 14:41:54 +0800 Subject: [PATCH 156/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E6=A0=87?= =?UTF-8?q?=E8=AE=B0=E9=BB=98=E8=AE=A4=E6=96=87=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/issue_tag.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/issue_tag.rb b/app/models/issue_tag.rb index c6b6af8aa..ad6a82763 100644 --- a/app/models/issue_tag.rb +++ b/app/models/issue_tag.rb @@ -30,9 +30,9 @@ class IssueTag < ApplicationRecord def self.init_data(project_id) data = [ - ["缺陷", "表示项目存在问题", "#d92d4c"], + ["缺陷", "表示存在意外问题或错误", "#d92d4c"], ["功能", "表示新功能申请", "#ee955a"], - ["疑问", "表示存在的问题", "#2d6ddc"], + ["疑问", "表示存在疑惑", "#2d6ddc"], ["支持", "表示特定功能或特定需求", "#019549"], ["任务", "表示需要分配的任务", "#c1a30d"], ["协助", "表示需要社区用户协助", "#2a0dc1"], From 17f6551fcc0647f9ae937c53a5f8d06a65eeeb49 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 13 Mar 2023 15:20:22 +0800 Subject: [PATCH 157/438] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/gitea/client_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/gitea/client_service.rb b/app/services/gitea/client_service.rb index 3d76c48b7..33447d5c9 100644 --- a/app/services/gitea/client_service.rb +++ b/app/services/gitea/client_service.rb @@ -82,7 +82,7 @@ class Gitea::ClientService < ApplicationService req.headers['Content-Type'] = 'application/json' req.response :logger # 显示日志 req.adapter Faraday.default_adapter - req.options.timeout = 3600 # open/read timeout in seconds + req.options.timeout = 7200 # open/read timeout in seconds req.options.open_timeout = 10 # connection open timeout in seconds if token.blank? req.basic_auth(username, secret) From d3f10d0814c4e8d49909bd861be15c2a3c3b6f77 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 13 Mar 2023 15:37:45 +0800 Subject: [PATCH 158/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E7=96=91?= =?UTF-8?q?=E4=BF=AE=E5=88=9B=E5=BB=BA=E6=97=B6=E9=97=B4=E8=8C=83=E5=9B=B4?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/issues_controller.rb | 1 + app/services/api/v1/issues/list_service.rb | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/app/controllers/api/v1/issues_controller.rb b/app/controllers/api/v1/issues_controller.rb index 6f615e498..433432048 100644 --- a/app/controllers/api/v1/issues_controller.rb +++ b/app/controllers/api/v1/issues_controller.rb @@ -91,6 +91,7 @@ class Api::V1::IssuesController < Api::V1::BaseController :keyword, :author_id, :milestone_id, :assigner_id, :status_id, + :begin_date, :end_date, :sort_by, :sort_direction, :issue_tag_ids) end diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index fa27f4ee4..0aeca052d 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -2,6 +2,7 @@ class Api::V1::Issues::ListService < ApplicationService include ActiveModel::Model attr_reader :project, :category, :participant_category, :keyword, :author_id, :issue_tag_ids + attr_reader :begin_date, :end_date attr_reader :milestone_id, :assigner_id, :status_id, :sort_by, :sort_direction, :current_user attr_accessor :queried_issues, :total_issues_count, :closed_issues_count, :opened_issues_count @@ -21,6 +22,8 @@ class Api::V1::Issues::ListService < ApplicationService @milestone_id = params[:milestone_id] @assigner_id = params[:assigner_id] @status_id = params[:status_id] + @begin_date = params[:begin_date] + @end_date = params[:end_date] @sort_by = params[:sort_by].present? ? params[:sort_by] : 'issues.updated_on' @sort_direction = (params[:sort_direction].present? ? params[:sort_direction] : 'desc').downcase @current_user = current_user @@ -67,6 +70,10 @@ class Api::V1::Issues::ListService < ApplicationService # status_id issues = issues.where(status_id: status_id) if status_id.present? + if begin_date&.present? || end_date&.present? + issues = issues.where("issues.created_on between ? and ?",begin_date&.present? ? begin_date.to_date : Time.now.to_date, end_date&.present? ? end_date.to_date : Time.now.to_date) + end + # keyword issues = issues.ransack(subject_or_description_cont: keyword).result if keyword.present? From 21875eb2c09d96348fe81ef2618cf2790166aa2a Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 13 Mar 2023 17:41:48 +0800 Subject: [PATCH 159/438] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/gitea/client_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/gitea/client_service.rb b/app/services/gitea/client_service.rb index 33447d5c9..bd7028f6d 100644 --- a/app/services/gitea/client_service.rb +++ b/app/services/gitea/client_service.rb @@ -82,7 +82,7 @@ class Gitea::ClientService < ApplicationService req.headers['Content-Type'] = 'application/json' req.response :logger # 显示日志 req.adapter Faraday.default_adapter - req.options.timeout = 7200 # open/read timeout in seconds + req.options.timeout = 10800 # open/read timeout in seconds req.options.open_timeout = 10 # connection open timeout in seconds if token.blank? req.basic_auth(username, secret) From bb7b7bc66cb6f78a861b24bcc11b7454c5651fd9 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 14 Mar 2023 09:12:12 +0800 Subject: [PATCH 160/438] =?UTF-8?q?=E5=A2=9E=E5=8A=A0sidekiq=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E7=9B=91=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Gemfile b/Gemfile index 0645fa72c..2f6d08f53 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,4 @@ + #source 'https://gems.ruby-china.com' source 'https://mirrors.cloud.tencent.com/rubygems/' git_source(:github) { |repo| "https://github.com/#{repo}.git" } @@ -102,6 +103,7 @@ gem 'rails-i18n', '~> 5.1' gem 'sidekiq' gem 'sinatra' gem "sidekiq-cron", "~> 1.1" +gem 'sidekiq-failures' # batch insert gem 'bulk_insert' From 7ec61409c6d608e15e14483625aa1137978928c6 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 14 Mar 2023 09:20:57 +0800 Subject: [PATCH 161/438] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/gitea/client_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/gitea/client_service.rb b/app/services/gitea/client_service.rb index bd7028f6d..2fb8ba4a3 100644 --- a/app/services/gitea/client_service.rb +++ b/app/services/gitea/client_service.rb @@ -82,7 +82,7 @@ class Gitea::ClientService < ApplicationService req.headers['Content-Type'] = 'application/json' req.response :logger # 显示日志 req.adapter Faraday.default_adapter - req.options.timeout = 10800 # open/read timeout in seconds + req.options.timeout =21600 # open/read timeout in seconds req.options.open_timeout = 10 # connection open timeout in seconds if token.blank? req.basic_auth(username, secret) From 4318293c1f2bb372dba2adf7d328c0e0bd870ecc Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 14 Mar 2023 13:52:46 +0800 Subject: [PATCH 162/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E8=8C=83=E5=9B=B4=E9=9C=80=E5=8C=85=E6=8B=AC=E4=B8=B4?= =?UTF-8?q?=E7=95=8C=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/issues/list_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index 0aeca052d..9804d63c2 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -71,7 +71,7 @@ class Api::V1::Issues::ListService < ApplicationService issues = issues.where(status_id: status_id) if status_id.present? if begin_date&.present? || end_date&.present? - issues = issues.where("issues.created_on between ? and ?",begin_date&.present? ? begin_date.to_date : Time.now.to_date, end_date&.present? ? end_date.to_date : Time.now.to_date) + issues = issues.where("issues.created_on between ? and ?", begin_date&.present? ? begin_date.to_time : Time.now.beginning_of_day, end_date&.present? ? end_date.to_time.end_of_day : Time.now.end_of_day) end # keyword From fca06c9816a824027e6db9b5aab0ab8aa08d6c09 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 14 Mar 2023 14:02:39 +0800 Subject: [PATCH 163/438] =?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=E7=94=A8=E6=88=B7=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E4=B8=BAreal=5Fname?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/journal.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/journal.rb b/app/models/journal.rb index 74b26b26e..5f56b6f78 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -82,8 +82,8 @@ class Journal < ApplicationRecord content += "将标记由#{old_value}更改为#{new_value}" end when 'assigner' - old_value = User.where(id: detail.old_value.split(",")).pluck(:nickname).join("、") - new_value = User.where(id: detail.value.split(",")).pluck(:nickname).join("、") + old_value = User.where(id: detail.old_value.split(",")).map{|u| u.real_name}.join("、") + new_value = User.where(id: detail.value.split(",")).map{|u| u.real_name}.join("、") if old_value.nil? || old_value.blank? content += "添加负责人#{new_value}" else @@ -122,8 +122,8 @@ class Journal < ApplicationRecord 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 + old_value = User.find_by_id(detail.old_value)&.real_name + new_value = User.find_by_id(detail.value)&.real_name content += "负责人" end if old_value.nil? || old_value.blank? From 91f2fab851c1be25ebb4310f35a050a8ee3b1675 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 14 Mar 2023 15:23:31 +0800 Subject: [PATCH 164/438] =?UTF-8?q?fixed=20bot=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index 3379af47c..d299f6710 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -37,7 +37,7 @@ class InstallationsController < ApplicationController # 注册bot对应oauth应用 Doorkeeper::Application.create!(name: @bot.name, uid: @bot.client_id, secret: @bot.client_secret, redirect_uri: "https://gitlink.org.cn") # 注册bot对应用户 - result = autologin_register(User.generate_user_login('b'), nil, "#{SecureRandom.hex(6)}", 'bot', nil, nickname: @bot.name) + result = autologin_register(User.generate_user_login('b'), nil, "#{SecureRandom.hex(6)}", 'bot', nil, @bot.name) tip_exception(-1, result[:message]) if result[:message].present? @bot.uid = result[:user][:id] @bot.save From edf0b7de4528c8c778db1da34830c4b0cefc16c8 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 14 Mar 2023 17:31:20 +0800 Subject: [PATCH 165/438] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E5=BB=B6=E9=95=BF=E5=88=B02=E5=B0=8F=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/gitea/client_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/gitea/client_service.rb b/app/services/gitea/client_service.rb index 2fb8ba4a3..efd43c4e7 100644 --- a/app/services/gitea/client_service.rb +++ b/app/services/gitea/client_service.rb @@ -82,7 +82,7 @@ class Gitea::ClientService < ApplicationService req.headers['Content-Type'] = 'application/json' req.response :logger # 显示日志 req.adapter Faraday.default_adapter - req.options.timeout =21600 # open/read timeout in seconds + req.options.timeout =7200 # open/read timeout in seconds req.options.open_timeout = 10 # connection open timeout in seconds if token.blank? req.basic_auth(username, secret) From 8e9c2232b08e741b293a0acab3616cd803ecb0d5 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 16 Jan 2023 18:05:27 +0800 Subject: [PATCH 166/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=96=B0?= =?UTF-8?q?=E7=89=88gitea=E8=B7=AF=E7=94=B1=E8=AF=B7=E6=B1=82=E5=9C=B0?= =?UTF-8?q?=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 +- Gemfile.lock | 42 +++++++++++++++++-- app/services/gitea/client_service.rb | 32 +++++++------- app/services/gitea/hooks/create_service.rb | 2 +- .../gitea/organization/create_service.rb | 2 +- .../gitea/organization/update_service.rb | 2 +- .../gitea/pull_request/commits_service.rb | 2 +- .../gitea/pull_request/files_service.rb | 2 +- .../gitea/pull_request/get_service.rb | 2 +- .../repository/branches/list_name_service.rb | 2 +- .../repository/branches/list_slice_service.rb | 2 +- .../repository/commits/compare_service.rb | 2 +- .../repository/commits/file_list_service.rb | 2 +- .../gitea/repository/commits/get_service.rb | 2 +- .../repository/commits/list_slice_service.rb | 2 +- .../repository/contributors/get_service.rb | 2 +- .../gitea/repository/entries/get_service.rb | 2 +- .../gitea/repository/entries/list_service.rb | 2 +- .../gitea/repository/files/get_service.rb | 2 +- .../get_branch_and_tag_total_num_service.rb | 2 +- .../gitea/repository/readme/dir_service.rb | 2 +- .../gitea/repository/readme/get_service.rb | 2 +- .../repository/tags/list_name_service.rb | 2 +- .../gitea/repository/tags/list_service.rb | 2 +- .../gitea/repository/transfer_service.rb | 2 +- .../repository/webhooks/tasks_service.rb | 2 +- app/services/gitea/user/headmap_service.rb | 2 +- app/services/gitea/user/update_service.rb | 2 +- app/services/gitea/versions/create_service.rb | 2 +- app/services/gitea/versions/get_service.rb | 2 +- app/services/gitea/versions/list_service.rb | 2 +- app/services/gitea/versions/update_service.rb | 2 +- config/configuration.yml.example | 1 + 33 files changed, 88 insertions(+), 47 deletions(-) diff --git a/Gemfile b/Gemfile index 0645fa72c..621ca4d0d 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,7 @@ gem 'puma', '~> 3.11' gem 'sass-rails', '~> 5.0' gem 'uglifier', '>= 1.3.0' -# gem 'coffee-rails', '~> 4.2' +# gem 'coffee-rails', '~> 4.2'[p-qwa9aq] gem 'turbolinks', '~> 5' gem 'jbuilder', '~> 2.5' gem 'groupdate', '~> 4.1.0' diff --git a/Gemfile.lock b/Gemfile.lock index e27c504aa..0001f2321 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -106,6 +106,8 @@ GEM activerecord (>= 3.1.0, < 7) diff-lcs (1.3) diffy (3.3.0) + domain_name (0.5.20190701) + unf (>= 0.0.5, < 1.0.0) doorkeeper (5.5.1) railties (>= 5) doorkeeper-jwt (0.4.1) @@ -127,12 +129,14 @@ GEM execjs (2.7.0) faraday (0.15.4) multipart-post (>= 1.2, < 3) - ffi (1.12.2) + ffi (1.15.5) font-awesome-sass (4.7.0) sass (>= 3.2) fugit (1.4.1) et-orbi (~> 1.1, >= 1.1.8) raabro (~> 1.4) + gitea-client (0.11.1) + rest-client (~> 2.1.0) globalid (0.4.2) activesupport (>= 4.2.0) grape-entity (0.7.1) @@ -143,6 +147,9 @@ GEM harmonious_dictionary (0.0.1) hashie (3.6.0) htmlentities (4.3.4) + http-accept (1.7.0) + http-cookie (1.0.5) + domain_name (~> 0.5) i18n (1.8.2) concurrent-ruby (~> 1.0) io-like (0.3.1) @@ -180,6 +187,9 @@ GEM mimemagic (~> 0.3.2) maruku (0.7.3) method_source (0.9.2) + mime-types (3.4.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2022.0105) mimemagic (0.3.10) nokogiri (~> 1) rake @@ -193,6 +203,7 @@ GEM mustermann (1.1.1) ruby2_keywords (~> 0.0.1) mysql2 (0.5.3) + netrc (0.11.0) nio4r (2.5.2) nokogiri (1.10.8) mini_portile2 (~> 2.4.0) @@ -209,9 +220,21 @@ GEM addressable (~> 2.3) nokogiri (~> 1.5) omniauth (~> 1.2) + omniauth-gitee (1.0.0) + omniauth (>= 1.5, < 3.0) + omniauth-oauth2 (>= 1.4.0, < 2.0) + omniauth-github (1.4.0) + omniauth (~> 1.5) + omniauth-oauth2 (>= 1.4.0, < 2.0) omniauth-oauth2 (1.6.0) oauth2 (~> 1.1) omniauth (~> 1.9) + omniauth-rails_csrf_protection (0.1.2) + actionpack (>= 4.2) + omniauth (>= 1.3.1) + omniauth-wechat-oauth2 (0.2.2) + omniauth (>= 1.3.2) + omniauth-oauth2 (>= 1.1.1) parallel (1.19.1) parser (2.7.1.1) ast (~> 2.4.0) @@ -292,6 +315,11 @@ GEM regexp_parser (1.7.0) request_store (1.5.0) rack (>= 1.4) + rest-client (2.1.0) + http-accept (>= 1.7.0, < 2.0) + http-cookie (>= 1.0.2, < 2.0) + mime-types (>= 1.16, < 4.0) + netrc (~> 0.8) reverse_markdown (1.4.0) nokogiri roo (2.8.3) @@ -346,7 +374,7 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) - sassc (2.2.1) + sassc (2.4.0) ffi (~> 1.9) sassc-rails (2.1.2) railties (>= 4.0.0) @@ -418,6 +446,9 @@ GEM thread_safe (~> 0.1) uglifier (4.2.0) execjs (>= 0.3.0, < 3) + unf (0.1.4) + unf_ext + unf_ext (0.0.8.2) unicode-display_width (1.6.1) web-console (3.7.0) actionview (>= 5.0) @@ -459,6 +490,7 @@ DEPENDENCIES enumerize faraday (~> 0.15.4) font-awesome-sass (= 4.7.0) + gitea-client (~> 0.11.1) grape-entity (~> 0.7.1) groupdate (~> 4.1.0) harmonious_dictionary (~> 0.0.1) @@ -472,7 +504,11 @@ DEPENDENCIES oauth2 omniauth (~> 1.9.0) omniauth-cas + omniauth-gitee (~> 1.0.0) + omniauth-github omniauth-oauth2 (~> 1.6.0) + omniauth-rails_csrf_protection + omniauth-wechat-oauth2 parallel (~> 1.19, >= 1.19.1) pdfkit prettier @@ -512,4 +548,4 @@ DEPENDENCIES wkhtmltopdf-binary BUNDLED WITH - 2.1.4 + 2.3.26 diff --git a/app/services/gitea/client_service.rb b/app/services/gitea/client_service.rb index e2bd9d491..fae4ae27e 100644 --- a/app/services/gitea/client_service.rb +++ b/app/services/gitea/client_service.rb @@ -18,19 +18,19 @@ class Gitea::ClientService < ApplicationService # token: {}, # data: {} # } - def post(url, params={}) + def post(url, params={}, is_hat=false) puts "[gitea] request params: #{params}" auth_token = authen_params(params[:token]) conn(auth_token).post do |req| - req.url full_url(url) + req.url full_url(url, "post", is_hat) req.body = params[:data].to_json end end - def get(url, params={}) + def get(url, params={}, is_hat = false) auth_token = authen_params(params[:token]) conn(auth_token).get do |req| - req.url full_url(url, 'get') + req.url full_url(url, 'get', is_hat) params.except(:token).each_pair do |key, value| req.params["#{key}"] = value end @@ -41,27 +41,27 @@ class Gitea::ClientService < ApplicationService # end #=> 响应头 end - def delete(url, params={}) + def delete(url, params={}, is_hat = false) auth_token = authen_params(params[:token]) conn(auth_token).delete do |req| - req.url full_url(url) + req.url full_url(url, "delete", is_hat) req.body = params[:data].to_json end end - def patch(url, params={}) + def patch(url, params={}, is_hat=false) puts "[gitea] request params: #{params}" auth_token = authen_params(params[:token]) conn(auth_token).patch do |req| - req.url full_url(url) + req.url full_url(url, 'patch', is_hat) req.body = params[:data].to_json end end - def put(url, params={}) + def put(url, params={}, is_hat=false) puts "[gitea] put request params: #{params}" conn(authen_params(params[:token])).put do |req| - req.url full_url(url) + req.url full_url(url, "put", is_hat) req.body = params[:data].to_json end end @@ -99,16 +99,20 @@ class Gitea::ClientService < ApplicationService GiteaService.gitea_config[:base_url] end + def hat_base_url + GiteaService.gitea_config[:hat_base_url] + end + def domain GiteaService.gitea_config[:domain] end - def api_url - [domain, base_url].join('') + def api_url(is_hat=false) + is_hat ? [domain, hat_base_url].join('') : [domain, base_url].join('') end - def full_url(api_rest, action='post') - url = [api_url, api_rest].join('').freeze + def full_url(api_rest, action='post', is_hat=false) + url = [api_url(is_hat), api_rest].join('').freeze url = action === 'get' ? url : URI.escape(url) url = URI.escape(url) unless url.ascii_only? puts "[gitea] request url: #{url}" diff --git a/app/services/gitea/hooks/create_service.rb b/app/services/gitea/hooks/create_service.rb index 6b65a6860..8b8d7f2c3 100644 --- a/app/services/gitea/hooks/create_service.rb +++ b/app/services/gitea/hooks/create_service.rb @@ -24,7 +24,7 @@ class Gitea::Hooks::CreateService < Gitea::ClientService end def call - response = post(url, params) + response = post(url, params, true) render_201_response(response) end diff --git a/app/services/gitea/organization/create_service.rb b/app/services/gitea/organization/create_service.rb index 4da1720cc..6f4c3d4f2 100644 --- a/app/services/gitea/organization/create_service.rb +++ b/app/services/gitea/organization/create_service.rb @@ -7,7 +7,7 @@ class Gitea::Organization::CreateService < Gitea::ClientService end def call - response = post(url, request_params) + response = post(url, request_params, true) render_status(response) end diff --git a/app/services/gitea/organization/update_service.rb b/app/services/gitea/organization/update_service.rb index 963099ad9..7a0fd1eec 100644 --- a/app/services/gitea/organization/update_service.rb +++ b/app/services/gitea/organization/update_service.rb @@ -8,7 +8,7 @@ class Gitea::Organization::UpdateService < Gitea::ClientService end def call - response = patch(url, request_params) + response = patch(url, request_params, true) render_status(response) end diff --git a/app/services/gitea/pull_request/commits_service.rb b/app/services/gitea/pull_request/commits_service.rb index dc2877eba..f85edd296 100644 --- a/app/services/gitea/pull_request/commits_service.rb +++ b/app/services/gitea/pull_request/commits_service.rb @@ -16,7 +16,7 @@ class Gitea::PullRequest::CommitsService < Gitea::ClientService end def call - response = get(url, params) + response = get(url, params, true) render_result(response) end diff --git a/app/services/gitea/pull_request/files_service.rb b/app/services/gitea/pull_request/files_service.rb index f7a2bd750..a5c2cf0d8 100644 --- a/app/services/gitea/pull_request/files_service.rb +++ b/app/services/gitea/pull_request/files_service.rb @@ -17,7 +17,7 @@ class Gitea::PullRequest::FilesService < Gitea::ClientService end def call - response = get(url, params.merge(token: token)) + response = get(url, params.merge(token: token), true) render_result(response) end diff --git a/app/services/gitea/pull_request/get_service.rb b/app/services/gitea/pull_request/get_service.rb index f9a35fdca..bd1fd8957 100644 --- a/app/services/gitea/pull_request/get_service.rb +++ b/app/services/gitea/pull_request/get_service.rb @@ -12,7 +12,7 @@ class Gitea::PullRequest::GetService < Gitea::ClientService end def call - response = get(url, params) + response = get(url, params, true) render_result(response) end diff --git a/app/services/gitea/repository/branches/list_name_service.rb b/app/services/gitea/repository/branches/list_name_service.rb index c005c8359..84f6d3a4c 100644 --- a/app/services/gitea/repository/branches/list_name_service.rb +++ b/app/services/gitea/repository/branches/list_name_service.rb @@ -8,7 +8,7 @@ class Gitea::Repository::Branches::ListNameService < Gitea::ClientService end def call - response = get(url, params) + response = get(url, params, true) render_200_response(response) end diff --git a/app/services/gitea/repository/branches/list_slice_service.rb b/app/services/gitea/repository/branches/list_slice_service.rb index 6b643831a..e04a4b6e6 100644 --- a/app/services/gitea/repository/branches/list_slice_service.rb +++ b/app/services/gitea/repository/branches/list_slice_service.rb @@ -7,7 +7,7 @@ class Gitea::Repository::Branches::ListSliceService < Gitea::ClientService end def call - response = get(url, params) + response = get(url, params, true) render_200_response(response) end diff --git a/app/services/gitea/repository/commits/compare_service.rb b/app/services/gitea/repository/commits/compare_service.rb index 502f6ce90..bdfd4ca3d 100644 --- a/app/services/gitea/repository/commits/compare_service.rb +++ b/app/services/gitea/repository/commits/compare_service.rb @@ -14,7 +14,7 @@ class Gitea::Repository::Commits::CompareService < Gitea::ClientService end def call - response = get(url, params) + response = get(url, params, true) render_status(response) end diff --git a/app/services/gitea/repository/commits/file_list_service.rb b/app/services/gitea/repository/commits/file_list_service.rb index b1606a0f3..77a193475 100644 --- a/app/services/gitea/repository/commits/file_list_service.rb +++ b/app/services/gitea/repository/commits/file_list_service.rb @@ -14,7 +14,7 @@ class Gitea::Repository::Commits::FileListService < Gitea::ClientService end def call - response = get(url, params) + response = get(url, params, true) render_result(response) end diff --git a/app/services/gitea/repository/commits/get_service.rb b/app/services/gitea/repository/commits/get_service.rb index d497f1e4f..a8fc67235 100644 --- a/app/services/gitea/repository/commits/get_service.rb +++ b/app/services/gitea/repository/commits/get_service.rb @@ -14,7 +14,7 @@ class Gitea::Repository::Commits::GetService < Gitea::ClientService end def call - response = get(url, params) + response = get(url, params, true) render_status(response) end diff --git a/app/services/gitea/repository/commits/list_slice_service.rb b/app/services/gitea/repository/commits/list_slice_service.rb index 04f45f55b..d31cf2bcd 100644 --- a/app/services/gitea/repository/commits/list_slice_service.rb +++ b/app/services/gitea/repository/commits/list_slice_service.rb @@ -13,7 +13,7 @@ class Gitea::Repository::Commits::ListSliceService < Gitea::ClientService end def call - response = get(url, params) + response = get(url, params, true) render_result(response) end diff --git a/app/services/gitea/repository/contributors/get_service.rb b/app/services/gitea/repository/contributors/get_service.rb index 1ee1c3955..e5ad32e38 100644 --- a/app/services/gitea/repository/contributors/get_service.rb +++ b/app/services/gitea/repository/contributors/get_service.rb @@ -7,7 +7,7 @@ class Gitea::Repository::Contributors::GetService < Gitea::ClientService end def call - response = get(url, params) + response = get(url, params, true) render_status(response) end diff --git a/app/services/gitea/repository/entries/get_service.rb b/app/services/gitea/repository/entries/get_service.rb index f8ac27543..f8e7b9451 100644 --- a/app/services/gitea/repository/entries/get_service.rb +++ b/app/services/gitea/repository/entries/get_service.rb @@ -13,7 +13,7 @@ class Gitea::Repository::Entries::GetService < Gitea::ClientService end def call - response = get(url, params) + response = get(url, params, true) render_result(response) end diff --git a/app/services/gitea/repository/entries/list_service.rb b/app/services/gitea/repository/entries/list_service.rb index dd62a1147..df9fdb1e3 100644 --- a/app/services/gitea/repository/entries/list_service.rb +++ b/app/services/gitea/repository/entries/list_service.rb @@ -10,7 +10,7 @@ class Gitea::Repository::Entries::ListService < Gitea::ClientService end def call - response = get(url, params) + response = get(url, params, true) render_result(response) end diff --git a/app/services/gitea/repository/files/get_service.rb b/app/services/gitea/repository/files/get_service.rb index e5b96e7ba..2a1589821 100644 --- a/app/services/gitea/repository/files/get_service.rb +++ b/app/services/gitea/repository/files/get_service.rb @@ -10,7 +10,7 @@ class Gitea::Repository::Files::GetService < Gitea::ClientService end def call - response = get(url, params) + response = get(url, params, true) render_status(response) end diff --git a/app/services/gitea/repository/get_branch_and_tag_total_num_service.rb b/app/services/gitea/repository/get_branch_and_tag_total_num_service.rb index 0b8a52467..f0fd2557b 100644 --- a/app/services/gitea/repository/get_branch_and_tag_total_num_service.rb +++ b/app/services/gitea/repository/get_branch_and_tag_total_num_service.rb @@ -11,7 +11,7 @@ module Gitea end def call - response = get(url, params) + response = get(url, params, true) render_result(response) end diff --git a/app/services/gitea/repository/readme/dir_service.rb b/app/services/gitea/repository/readme/dir_service.rb index 587fb5d55..830cceaa8 100644 --- a/app/services/gitea/repository/readme/dir_service.rb +++ b/app/services/gitea/repository/readme/dir_service.rb @@ -10,7 +10,7 @@ class Gitea::Repository::Readme::DirService < Gitea::ClientService end def call - response = get(url, params) + response = get(url, params, true) status, message, body = render_response(response) json_format(status, message, body) end diff --git a/app/services/gitea/repository/readme/get_service.rb b/app/services/gitea/repository/readme/get_service.rb index 48e2d4475..5af86b5ae 100644 --- a/app/services/gitea/repository/readme/get_service.rb +++ b/app/services/gitea/repository/readme/get_service.rb @@ -15,7 +15,7 @@ class Gitea::Repository::Readme::GetService < Gitea::ClientService end def call - response = get(url, params) + response = get(url, params, true) status, message, body = render_response(response) json_format(status, message, body) end diff --git a/app/services/gitea/repository/tags/list_name_service.rb b/app/services/gitea/repository/tags/list_name_service.rb index 0857ca11c..ac81c9d75 100644 --- a/app/services/gitea/repository/tags/list_name_service.rb +++ b/app/services/gitea/repository/tags/list_name_service.rb @@ -8,7 +8,7 @@ class Gitea::Repository::Tags::ListNameService < Gitea::ClientService end def call - response = get(url, params) + response = get(url, params, true) render_200_response(response) end diff --git a/app/services/gitea/repository/tags/list_service.rb b/app/services/gitea/repository/tags/list_service.rb index 0f8158b3e..958287179 100644 --- a/app/services/gitea/repository/tags/list_service.rb +++ b/app/services/gitea/repository/tags/list_service.rb @@ -11,7 +11,7 @@ class Gitea::Repository::Tags::ListService < Gitea::ClientService end def call - response = get(url, request_params) + response = get(url, request_params, true) render_result(response) end diff --git a/app/services/gitea/repository/transfer_service.rb b/app/services/gitea/repository/transfer_service.rb index 358ac9421..40cf5d1bf 100644 --- a/app/services/gitea/repository/transfer_service.rb +++ b/app/services/gitea/repository/transfer_service.rb @@ -9,7 +9,7 @@ class Gitea::Repository::TransferService < Gitea::ClientService end def call - response = post(url, request_params) + response = post(url, request_params, true) render_status(response) end diff --git a/app/services/gitea/repository/webhooks/tasks_service.rb b/app/services/gitea/repository/webhooks/tasks_service.rb index e4c62edb4..be5a59290 100644 --- a/app/services/gitea/repository/webhooks/tasks_service.rb +++ b/app/services/gitea/repository/webhooks/tasks_service.rb @@ -11,7 +11,7 @@ class Gitea::Repository::Webhooks::TasksService < Gitea::ClientService end def call - response = get(url, params) + response = get(url, params, true) render_response(response) end diff --git a/app/services/gitea/user/headmap_service.rb b/app/services/gitea/user/headmap_service.rb index 611a8b9d0..d066d0f16 100644 --- a/app/services/gitea/user/headmap_service.rb +++ b/app/services/gitea/user/headmap_service.rb @@ -8,7 +8,7 @@ class Gitea::User::HeadmapService < Gitea::ClientService end def call - response = get(url, params) + response = get(url, params, true) render_response(response) end diff --git a/app/services/gitea/user/update_service.rb b/app/services/gitea/user/update_service.rb index 9826c7ed0..24660158b 100644 --- a/app/services/gitea/user/update_service.rb +++ b/app/services/gitea/user/update_service.rb @@ -24,7 +24,7 @@ class Gitea::User::UpdateService < Gitea::ClientService end def call - patch(url, data_params) + patch(url, data_params, true) end private diff --git a/app/services/gitea/versions/create_service.rb b/app/services/gitea/versions/create_service.rb index 04fed00f2..4424fc276 100644 --- a/app/services/gitea/versions/create_service.rb +++ b/app/services/gitea/versions/create_service.rb @@ -18,7 +18,7 @@ class Gitea::Versions::CreateService < Gitea::ClientService end def call - response = post(url, request_params) + response = post(url, request_params, true) render_status(response) end diff --git a/app/services/gitea/versions/get_service.rb b/app/services/gitea/versions/get_service.rb index b3c6cf9cc..2af78ab28 100644 --- a/app/services/gitea/versions/get_service.rb +++ b/app/services/gitea/versions/get_service.rb @@ -12,7 +12,7 @@ class Gitea::Versions::GetService < Gitea::ClientService end def call - response = get(url, params) + response = get(url, params, true) render_result(response) end diff --git a/app/services/gitea/versions/list_service.rb b/app/services/gitea/versions/list_service.rb index 5d160fc3e..3505fa254 100644 --- a/app/services/gitea/versions/list_service.rb +++ b/app/services/gitea/versions/list_service.rb @@ -11,7 +11,7 @@ class Gitea::Versions::ListService < Gitea::ClientService end def call - response = get(url, params) + response = get(url, params, true) render_result(response) end diff --git a/app/services/gitea/versions/update_service.rb b/app/services/gitea/versions/update_service.rb index a4c9acfc2..c07620bc8 100644 --- a/app/services/gitea/versions/update_service.rb +++ b/app/services/gitea/versions/update_service.rb @@ -19,7 +19,7 @@ class Gitea::Versions::UpdateService < Gitea::ClientService end def call - patch(url, request_params) + patch(url, request_params, true) end private diff --git a/config/configuration.yml.example b/config/configuration.yml.example index f056dee1b..75d5eb5c0 100644 --- a/config/configuration.yml.example +++ b/config/configuration.yml.example @@ -55,6 +55,7 @@ default: &default access_key_secret: '' domain: 'https://testgit.trustie.net' base_url: '/api/v1' + hat_base_url: '/api/hat' accelerator: access_key_id: '' access_key_secret: '' From 2326bde96d45362306e42548eaed3b1e5e061e74 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 16 Jan 2023 18:10:13 +0800 Subject: [PATCH 167/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Agemfile?= =?UTF-8?q?=E5=9B=9E=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 +- Gemfile.lock | 42 +++--------------------------------------- 2 files changed, 4 insertions(+), 40 deletions(-) diff --git a/Gemfile b/Gemfile index 621ca4d0d..0645fa72c 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,7 @@ gem 'puma', '~> 3.11' gem 'sass-rails', '~> 5.0' gem 'uglifier', '>= 1.3.0' -# gem 'coffee-rails', '~> 4.2'[p-qwa9aq] +# gem 'coffee-rails', '~> 4.2' gem 'turbolinks', '~> 5' gem 'jbuilder', '~> 2.5' gem 'groupdate', '~> 4.1.0' diff --git a/Gemfile.lock b/Gemfile.lock index 0001f2321..e27c504aa 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -106,8 +106,6 @@ GEM activerecord (>= 3.1.0, < 7) diff-lcs (1.3) diffy (3.3.0) - domain_name (0.5.20190701) - unf (>= 0.0.5, < 1.0.0) doorkeeper (5.5.1) railties (>= 5) doorkeeper-jwt (0.4.1) @@ -129,14 +127,12 @@ GEM execjs (2.7.0) faraday (0.15.4) multipart-post (>= 1.2, < 3) - ffi (1.15.5) + ffi (1.12.2) font-awesome-sass (4.7.0) sass (>= 3.2) fugit (1.4.1) et-orbi (~> 1.1, >= 1.1.8) raabro (~> 1.4) - gitea-client (0.11.1) - rest-client (~> 2.1.0) globalid (0.4.2) activesupport (>= 4.2.0) grape-entity (0.7.1) @@ -147,9 +143,6 @@ GEM harmonious_dictionary (0.0.1) hashie (3.6.0) htmlentities (4.3.4) - http-accept (1.7.0) - http-cookie (1.0.5) - domain_name (~> 0.5) i18n (1.8.2) concurrent-ruby (~> 1.0) io-like (0.3.1) @@ -187,9 +180,6 @@ GEM mimemagic (~> 0.3.2) maruku (0.7.3) method_source (0.9.2) - mime-types (3.4.1) - mime-types-data (~> 3.2015) - mime-types-data (3.2022.0105) mimemagic (0.3.10) nokogiri (~> 1) rake @@ -203,7 +193,6 @@ GEM mustermann (1.1.1) ruby2_keywords (~> 0.0.1) mysql2 (0.5.3) - netrc (0.11.0) nio4r (2.5.2) nokogiri (1.10.8) mini_portile2 (~> 2.4.0) @@ -220,21 +209,9 @@ GEM addressable (~> 2.3) nokogiri (~> 1.5) omniauth (~> 1.2) - omniauth-gitee (1.0.0) - omniauth (>= 1.5, < 3.0) - omniauth-oauth2 (>= 1.4.0, < 2.0) - omniauth-github (1.4.0) - omniauth (~> 1.5) - omniauth-oauth2 (>= 1.4.0, < 2.0) omniauth-oauth2 (1.6.0) oauth2 (~> 1.1) omniauth (~> 1.9) - omniauth-rails_csrf_protection (0.1.2) - actionpack (>= 4.2) - omniauth (>= 1.3.1) - omniauth-wechat-oauth2 (0.2.2) - omniauth (>= 1.3.2) - omniauth-oauth2 (>= 1.1.1) parallel (1.19.1) parser (2.7.1.1) ast (~> 2.4.0) @@ -315,11 +292,6 @@ GEM regexp_parser (1.7.0) request_store (1.5.0) rack (>= 1.4) - rest-client (2.1.0) - http-accept (>= 1.7.0, < 2.0) - http-cookie (>= 1.0.2, < 2.0) - mime-types (>= 1.16, < 4.0) - netrc (~> 0.8) reverse_markdown (1.4.0) nokogiri roo (2.8.3) @@ -374,7 +346,7 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) - sassc (2.4.0) + sassc (2.2.1) ffi (~> 1.9) sassc-rails (2.1.2) railties (>= 4.0.0) @@ -446,9 +418,6 @@ GEM thread_safe (~> 0.1) uglifier (4.2.0) execjs (>= 0.3.0, < 3) - unf (0.1.4) - unf_ext - unf_ext (0.0.8.2) unicode-display_width (1.6.1) web-console (3.7.0) actionview (>= 5.0) @@ -490,7 +459,6 @@ DEPENDENCIES enumerize faraday (~> 0.15.4) font-awesome-sass (= 4.7.0) - gitea-client (~> 0.11.1) grape-entity (~> 0.7.1) groupdate (~> 4.1.0) harmonious_dictionary (~> 0.0.1) @@ -504,11 +472,7 @@ DEPENDENCIES oauth2 omniauth (~> 1.9.0) omniauth-cas - omniauth-gitee (~> 1.0.0) - omniauth-github omniauth-oauth2 (~> 1.6.0) - omniauth-rails_csrf_protection - omniauth-wechat-oauth2 parallel (~> 1.19, >= 1.19.1) pdfkit prettier @@ -548,4 +512,4 @@ DEPENDENCIES wkhtmltopdf-binary BUNDLED WITH - 2.3.26 + 2.1.4 From ad9c5fe0fbbba5325ff900fa83861494d48a1028 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 31 Jan 2023 10:04:07 +0800 Subject: [PATCH 168/438] =?UTF-8?q?=E6=9B=B4=E6=96=B0=EF=BC=9Areadme?= =?UTF-8?q?=E4=B8=ADgitea=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1bcd05cce..a1cadd1cc 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,7 @@ gitea: access_key_secret: 'password' domain: 'http://www.gitea.example.com' base_url: '/api/v1' + hat_base_url: '/api/hat' ``` #### 6. 安装redis环境 From 718457888d846f94713d778a5f4de210478500e7 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 31 Jan 2023 10:55:55 +0800 Subject: [PATCH 169/438] =?UTF-8?q?=E6=9B=B4=E6=96=B0=EF=BC=9Aclient?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E4=BB=A5=E5=8F=8Agitea=5Fclient=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=96=87=E4=BB=B6=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 +- app/services/api/v1/projects/blame_service.rb | 2 +- .../api/v1/projects/branches/all_list_service.rb | 2 +- .../api/v1/projects/branches/create_service.rb | 4 ++-- .../api/v1/projects/code_stats/list_service.rb | 2 +- app/services/api/v1/projects/commits/diff_service.rb | 2 +- .../api/v1/projects/contents/batch_create_service.rb | 4 ++-- app/services/api/v1/projects/get_service.rb | 2 +- app/services/api/v1/projects/pulls/get_service.rb | 2 +- .../v1/projects/pulls/versions/get_diff_service.rb | 2 +- .../api/v1/projects/pulls/versions/list_service.rb | 2 +- .../api/v1/projects/webhooks/create_service.rb | 2 +- .../api/v1/projects/webhooks/hooktasks_service.rb | 2 +- app/services/projects/transfer_service.rb | 2 +- config/initializers/gitea_client.rb | 11 ++++++++++- 15 files changed, 26 insertions(+), 17 deletions(-) diff --git a/Gemfile b/Gemfile index 0645fa72c..e0b2bcd12 100644 --- a/Gemfile +++ b/Gemfile @@ -140,4 +140,4 @@ gem 'doorkeeper' gem 'doorkeeper-jwt' -gem 'gitea-client', '~> 0.11.6' \ No newline at end of file +gem 'gitea-client', '~> 1.2.1' diff --git a/app/services/api/v1/projects/blame_service.rb b/app/services/api/v1/projects/blame_service.rb index d419fec14..cdd5739b8 100644 --- a/app/services/api/v1/projects/blame_service.rb +++ b/app/services/api/v1/projects/blame_service.rb @@ -32,7 +32,7 @@ class Api::V1::Projects::BlameService < ApplicationService end def load_gitea_data - @gitea_data = $gitea_client.get_repos_blame_by_owner_repo(owner, repo, {query: request_params}) + @gitea_data = $gitea_hat_client.get_repos_blame_by_owner_repo(owner, repo, {query: request_params}) raise Error, '获取项目blame失败!' unless @gitea_data.is_a?(Hash) end end \ No newline at end of file diff --git a/app/services/api/v1/projects/branches/all_list_service.rb b/app/services/api/v1/projects/branches/all_list_service.rb index 182495cdf..4d31f6534 100644 --- a/app/services/api/v1/projects/branches/all_list_service.rb +++ b/app/services/api/v1/projects/branches/all_list_service.rb @@ -24,7 +24,7 @@ class Api::V1::Projects::Branches::AllListService < ApplicationService end def load_gitea_data - @gitea_data = $gitea_client.get_repos_branch_name_set_by_owner_repo(owner, repo, {query: request_params}) rescue nil + @gitea_data = $gitea_hat_client.get_repos_branch_name_set_by_owner_repo(owner, repo, {query: request_params}) rescue nil raise Error, '获取所有分支失败!' unless @gitea_data.is_a?(Hash) end end \ No newline at end of file diff --git a/app/services/api/v1/projects/branches/create_service.rb b/app/services/api/v1/projects/branches/create_service.rb index eae3779f8..0f2ec1d5e 100644 --- a/app/services/api/v1/projects/branches/create_service.rb +++ b/app/services/api/v1/projects/branches/create_service.rb @@ -43,8 +43,8 @@ class Api::V1::Projects::Branches::CreateService < ApplicationService raise Error, '创建分支失败!' unless @gitea_data.is_a?(Hash) end - def check_branch_exist - result = $gitea_client.get_repos_branch_name_set_by_owner_repo(owner, repo, {query: request_params}) rescue nil + def check_new_branch_exist + result = $gitea_hat_client.get_repos_branch_name_set_by_owner_repo(owner, repo, {query: request_params}) rescue nil raise Error, '查询分支名称失败!' unless result.is_a?(Hash) raise Error, '旧分支不存在!' if !result['branch_name'].include?(@old_branch_name) raise Error, '新分支已存在!' if result['branch_name'].include?(@new_branch_name) diff --git a/app/services/api/v1/projects/code_stats/list_service.rb b/app/services/api/v1/projects/code_stats/list_service.rb index a5e330e21..0831bc722 100644 --- a/app/services/api/v1/projects/code_stats/list_service.rb +++ b/app/services/api/v1/projects/code_stats/list_service.rb @@ -28,7 +28,7 @@ class Api::V1::Projects::CodeStats::ListService < ApplicationService end def load_gitea_data - @gitea_data = $gitea_client.get_repos_code_stats_by_owner_repo(owner, repo, {query: request_params}) rescue nil + @gitea_data = $gitea_hat_client.get_repos_code_stats_by_owner_repo(owner, repo, {query: request_params}) rescue nil raise Error, '获取贡献者贡献度失败!' unless @gitea_data.is_a?(Hash) end end \ No newline at end of file diff --git a/app/services/api/v1/projects/commits/diff_service.rb b/app/services/api/v1/projects/commits/diff_service.rb index 71dd155a0..3de96fbaa 100644 --- a/app/services/api/v1/projects/commits/diff_service.rb +++ b/app/services/api/v1/projects/commits/diff_service.rb @@ -29,7 +29,7 @@ class Api::V1::Projects::Commits::DiffService < ApplicationService end def load_gitea_data - @gitea_data = $gitea_client.get_repos_commits_diff_by_owner_repo_sha(owner, repo, sha, {query: request_params}) rescue nil + @gitea_data = $gitea_hat_client.get_repos_commits_diff_by_owner_repo_sha(owner, repo, sha, {query: request_params}) rescue nil raise Error, '获取提交对比失败!' unless @gitea_data.is_a?(Hash) end diff --git a/app/services/api/v1/projects/contents/batch_create_service.rb b/app/services/api/v1/projects/contents/batch_create_service.rb index 92bd30a99..7c514c376 100644 --- a/app/services/api/v1/projects/contents/batch_create_service.rb +++ b/app/services/api/v1/projects/contents/batch_create_service.rb @@ -78,12 +78,12 @@ class Api::V1::Projects::Contents::BatchCreateService < ApplicationService def excute_data_to_gitea puts request_body.to_json - @gitea_data = $gitea_client.post_repos_contents_batch_by_owner_repo(owner, repo, {body: request_body.to_json, query: request_params}) rescue nil + @gitea_data = $gitea_hat_client.post_repos_contents_batch_by_owner_repo(owner, repo, {body: request_body.to_json, query: request_params}) rescue nil raise Error, '提交文件失败!' unless @gitea_data.is_a?(Hash) end def check_branch_exist - result = $gitea_client.get_repos_branch_name_set_by_owner_repo(owner, repo, {query: request_params} ) rescue nil + result = $gitea_hat_client.get_repos_branch_name_set_by_owner_repo(owner, repo, {query: request_params} ) rescue nil raise Error, '查询分支名称失败!' unless result.is_a?(Hash) raise Error, '分支不存在!' unless result['branch_name'].include?(branch) raise Error, '分支已存在!' if result['branch_name'].include?(new_branch) && !new_branch.nil? diff --git a/app/services/api/v1/projects/get_service.rb b/app/services/api/v1/projects/get_service.rb index ebb0d1cfa..480744bfc 100644 --- a/app/services/api/v1/projects/get_service.rb +++ b/app/services/api/v1/projects/get_service.rb @@ -45,6 +45,6 @@ class Api::V1::Projects::GetService < ApplicationService end def load_gitea_branch_tag_count - @gitea_branch_tag_count = $gitea_client.get_repos_branch_tag_count_by_owner_repo(owner, repo, {query: request_params}) rescue nil + @gitea_branch_tag_count = $gitea_hat_client.get_repos_branch_tag_count_by_owner_repo(owner, repo, {query: request_params}) rescue nil end end \ No newline at end of file diff --git a/app/services/api/v1/projects/pulls/get_service.rb b/app/services/api/v1/projects/pulls/get_service.rb index 3c1bba99b..f28881ae0 100644 --- a/app/services/api/v1/projects/pulls/get_service.rb +++ b/app/services/api/v1/projects/pulls/get_service.rb @@ -26,7 +26,7 @@ class Api::V1::Projects::Pulls::GetService < ApplicationService end def load_gitea_data - @gitea_data = $gitea_client.get_repos_pulls_by_owner_repo_index(owner, repo, index, {query: request_params}) + @gitea_data = $gitea_hat_client.get_repos_pulls_by_owner_repo_index(owner, repo, index, {query: request_params}) # raise Error, '获取合并请求失败!' unless @gitea_data.is_a?(Hash) end end \ No newline at end of file diff --git a/app/services/api/v1/projects/pulls/versions/get_diff_service.rb b/app/services/api/v1/projects/pulls/versions/get_diff_service.rb index 979bc33fb..1cae8c345 100644 --- a/app/services/api/v1/projects/pulls/versions/get_diff_service.rb +++ b/app/services/api/v1/projects/pulls/versions/get_diff_service.rb @@ -30,7 +30,7 @@ class Api::V1::Projects::Pulls::Versions::GetDiffService < ApplicationService end def load_gitea_data - @gitea_data = $gitea_client.get_repos_pulls_versions_diff_by_owner_repo_index_version_id(owner, repo, index, version_id, {query: request_params}) + @gitea_data = $gitea_hat_client.get_repos_pulls_versions_diff_by_owner_repo_index_version_id(owner, repo, index, version_id, {query: request_params}) raise Error, '获取合并请求版本diff失败!' unless @gitea_data.is_a?(Hash) end end \ No newline at end of file diff --git a/app/services/api/v1/projects/pulls/versions/list_service.rb b/app/services/api/v1/projects/pulls/versions/list_service.rb index ca88ff1f6..e9ae69c32 100644 --- a/app/services/api/v1/projects/pulls/versions/list_service.rb +++ b/app/services/api/v1/projects/pulls/versions/list_service.rb @@ -30,7 +30,7 @@ class Api::V1::Projects::Pulls::Versions::ListService < ApplicationService end def load_gitea_data - @gitea_data = $gitea_client.get_repos_pulls_versions_by_owner_repo_index(owner, repo, index, {query: request_params}) + @gitea_data = $gitea_hat_client.get_repos_pulls_versions_by_owner_repo_index(owner, repo, index, {query: request_params}) raise Error, '获取合并请求版本失败!' unless @gitea_data.is_a?(Hash) end end \ No newline at end of file diff --git a/app/services/api/v1/projects/webhooks/create_service.rb b/app/services/api/v1/projects/webhooks/create_service.rb index edc8b2263..cc9cf37f0 100644 --- a/app/services/api/v1/projects/webhooks/create_service.rb +++ b/app/services/api/v1/projects/webhooks/create_service.rb @@ -58,6 +58,6 @@ class Api::V1::Projects::Webhooks::CreateService < ApplicationService end def excute_data_to_gitea - @gitea_data = $gitea_client.post_repos_hooks_by_owner_repo(owner, repo, {body: request_body.to_json, query: request_params}) rescue nil + @gitea_data = $gitea_hat_client.post_repos_hooks_by_owner_repo(owner, repo, {body: request_body.to_json, query: request_params}) rescue nil end end \ No newline at end of file diff --git a/app/services/api/v1/projects/webhooks/hooktasks_service.rb b/app/services/api/v1/projects/webhooks/hooktasks_service.rb index 6be9c67c8..17ada9089 100644 --- a/app/services/api/v1/projects/webhooks/hooktasks_service.rb +++ b/app/services/api/v1/projects/webhooks/hooktasks_service.rb @@ -30,6 +30,6 @@ class Api::V1::Projects::Webhooks::ListService < ApplicationService end def load_gitea_data - @gitea_data = $gitea_client.get_repos_hooks_hooktasks_by_owner_repo(owner, repo, id, {query: request_params}) rescue nil + @gitea_data = $gitea_hat_client.get_repos_hooks_hooktasks_by_owner_repo(owner, repo, id, {query: request_params}) rescue nil end end \ No newline at end of file diff --git a/app/services/projects/transfer_service.rb b/app/services/projects/transfer_service.rb index 8ed58f8a7..07eab8981 100644 --- a/app/services/projects/transfer_service.rb +++ b/app/services/projects/transfer_service.rb @@ -51,7 +51,7 @@ class Projects::TransferService < ApplicationService def gitea_update_owner begin - @gitea_repo = $gitea_client.post_repos_transfer_by_owner_repo(owner&.login, project.identifier, {body: {new_owner: new_owner&.login}.to_json}) + @gitea_repo = $gitea_hat_client.post_repos_transfer_by_owner_repo(owner&.login, project.identifier, {body: {new_owner: new_owner&.login}.to_json}) # @gitea_repo = Gitea::Repository::TransferService.call(owner&.gitea_token, owner&.login, project.identifier, new_owner&.login) rescue Exception => e Rails.logger.info("##### Project transfer_service, gitea transfer error #{e}") diff --git a/config/initializers/gitea_client.rb b/config/initializers/gitea_client.rb index c909cebf4..15777ac30 100644 --- a/config/initializers/gitea_client.rb +++ b/config/initializers/gitea_client.rb @@ -7,5 +7,14 @@ $gitea_client = Gitea::Api::Client.new({ domain: gitea_config[:domain], base_url: gitea_config[:base_url], username: gitea_config[:access_key_id], - password: gitea_config[:access_key_secret] + password: gitea_config[:access_key_secret], + log_filepath: "log/gitea-client.log" +}) + +$gitea_hat_client = Gitea::Api::Hat::Client.new({ + domain: gitea_config[:domain], + hat_base_url: gitea_config[:hat_base_url], + username: gitea_config[:access_key_id], + password: gitea_config[:access_key_secret], + log_filepath: "log/gitea-client.log" }) \ No newline at end of file From 8463518adedd1f79a797fdf3c0fdf720eecc52d5 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 2 Feb 2023 15:31:38 +0800 Subject: [PATCH 170/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Atags?= =?UTF-8?q?=E5=88=97=E8=A1=A8commiter=E6=9B=B4=E6=94=B9=E4=B8=BAcommitter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/repositories/tags.json.jbuilder | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/repositories/tags.json.jbuilder b/app/views/repositories/tags.json.jbuilder index 4f5bb4330..5e3c7e39e 100644 --- a/app/views/repositories/tags.json.jbuilder +++ b/app/views/repositories/tags.json.jbuilder @@ -14,10 +14,10 @@ json.tags @tags do |tag| json.commit do json.sha tag['commit']['sha'] json.message tag['commit']['message'] - json.time_ago time_from_now(tag['commit']['commiter']['date'].to_time) - json.created_at_unix tag['commit']['commiter']['date'].to_time.to_i + json.time_ago time_from_now(tag['commit']['committer']['date'].to_time) + json.created_at_unix tag['commit']['committer']['date'].to_time.to_i json.committer do - json.partial! 'commit_author', user: render_cache_commit_author(tag['commit']['commiter']), name: tag['commit']['commiter']['name'] + json.partial! 'commit_author', user: render_cache_commit_author(tag['commit']['committer']), name: tag['commit']['committer']['name'] end json.author do json.partial! 'commit_author', user: render_cache_commit_author(tag['commit']['author']), name: tag['commit']['author']['name'] From 54b7cef1bd27b6eb7c1de042bf6b7c4a4541294d Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 17 Feb 2023 22:03:18 +0800 Subject: [PATCH 171/438] =?UTF-8?q?=E5=90=8C=E6=AD=A5develop=E6=9C=80?= =?UTF-8?q?=E6=96=B0=E4=BB=A3=E7=A0=81=E5=90=8E=E6=9B=B4=E6=94=B9client?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 +- app/controllers/api/v1/projects/tags_controller.rb | 1 + app/services/api/v1/projects/branches/all_list_service.rb | 2 +- app/services/api/v1/projects/branches/create_service.rb | 8 ++++---- app/services/api/v1/projects/branches/delete_service.rb | 6 +++--- .../v1/projects/branches/update_default_branch_service.rb | 6 +++--- app/services/api/v1/projects/tags/delete_service.rb | 2 +- app/services/api/v1/projects/tags/list_service.rb | 2 +- .../projects/branches/_simple_gitea_detail.json.jbuilder | 4 ++-- .../tags/_simple_gitea_index_detail.json.jbuilder | 6 +++--- 10 files changed, 20 insertions(+), 19 deletions(-) diff --git a/Gemfile b/Gemfile index e0b2bcd12..1528d502b 100644 --- a/Gemfile +++ b/Gemfile @@ -140,4 +140,4 @@ gem 'doorkeeper' gem 'doorkeeper-jwt' -gem 'gitea-client', '~> 1.2.1' +gem 'gitea-client', '~> 1.3.1' diff --git a/app/controllers/api/v1/projects/tags_controller.rb b/app/controllers/api/v1/projects/tags_controller.rb index 06c3b1c8e..b87d48429 100644 --- a/app/controllers/api/v1/projects/tags_controller.rb +++ b/app/controllers/api/v1/projects/tags_controller.rb @@ -4,6 +4,7 @@ class Api::V1::Projects::TagsController < Api::V1::BaseController def index @release_tags = @repository.version_releases.pluck(:tag_name) @result_object = Api::V1::Projects::Tags::ListService.call(@project, {page: page, limit: limit}, current_user&.gitea_token) + puts @result_object end before_action :require_operate_above, only: [:destroy] diff --git a/app/services/api/v1/projects/branches/all_list_service.rb b/app/services/api/v1/projects/branches/all_list_service.rb index 4d31f6534..9ca4ae7d0 100644 --- a/app/services/api/v1/projects/branches/all_list_service.rb +++ b/app/services/api/v1/projects/branches/all_list_service.rb @@ -25,6 +25,6 @@ class Api::V1::Projects::Branches::AllListService < ApplicationService def load_gitea_data @gitea_data = $gitea_hat_client.get_repos_branch_name_set_by_owner_repo(owner, repo, {query: request_params}) rescue nil - raise Error, '获取所有分支失败!' unless @gitea_data.is_a?(Hash) + raise Error, '获取所有分支失败!' unless @gitea_data.is_a?(Array) end end \ No newline at end of file diff --git a/app/services/api/v1/projects/branches/create_service.rb b/app/services/api/v1/projects/branches/create_service.rb index 0f2ec1d5e..39964e402 100644 --- a/app/services/api/v1/projects/branches/create_service.rb +++ b/app/services/api/v1/projects/branches/create_service.rb @@ -43,10 +43,10 @@ class Api::V1::Projects::Branches::CreateService < ApplicationService raise Error, '创建分支失败!' unless @gitea_data.is_a?(Hash) end - def check_new_branch_exist + def check_branch_exist result = $gitea_hat_client.get_repos_branch_name_set_by_owner_repo(owner, repo, {query: request_params}) rescue nil - raise Error, '查询分支名称失败!' unless result.is_a?(Hash) - raise Error, '旧分支不存在!' if !result['branch_name'].include?(@old_branch_name) - raise Error, '新分支已存在!' if result['branch_name'].include?(@new_branch_name) + raise Error, '查询分支名称失败!' unless result.is_a?(Array) + raise Error, '旧分支不存在!' if !result.include?(@old_branch_name) + raise Error, '新分支已存在!' if result.include?(@new_branch_name) end end \ No newline at end of file diff --git a/app/services/api/v1/projects/branches/delete_service.rb b/app/services/api/v1/projects/branches/delete_service.rb index 79a6ba0db..28836c797 100644 --- a/app/services/api/v1/projects/branches/delete_service.rb +++ b/app/services/api/v1/projects/branches/delete_service.rb @@ -40,8 +40,8 @@ class Api::V1::Projects::Branches::DeleteService < ApplicationService end def check_branch_exist - result = $gitea_client.get_repos_branch_name_set_by_owner_repo(owner, repo, {query: request_params}) rescue nil - raise Error, '查询分支名称失败!' unless result.is_a?(Hash) - raise Error, '分支不存在!' if !result['branch_name'].include?(@branch_name) + result = $gitea_hat_client.get_repos_branch_name_set_by_owner_repo(owner, repo, {query: request_params}) rescue nil + raise Error, '查询分支名称失败!' unless result.is_a?(Array) + raise Error, '分支不存在!' if !result.include?(@branch_name) end end \ No newline at end of file diff --git a/app/services/api/v1/projects/branches/update_default_branch_service.rb b/app/services/api/v1/projects/branches/update_default_branch_service.rb index 5c220aa5d..c79c33bd2 100644 --- a/app/services/api/v1/projects/branches/update_default_branch_service.rb +++ b/app/services/api/v1/projects/branches/update_default_branch_service.rb @@ -48,8 +48,8 @@ class Api::V1::Projects::Branches::UpdateDefaultBranchService < ApplicationServi end def check_branch_exist - result = $gitea_client.get_repos_branch_name_set_by_owner_repo(owner, repo, {query: request_params}) rescue nil - raise Error, '查询分支名称失败!' unless result.is_a?(Hash) - raise Error, '新默认分支不存在!' if !result['branch_name'].include?(@new_default_branch) + result = $gitea_hat_client.get_repos_branch_name_set_by_owner_repo(owner, repo, {query: request_params}) rescue nil + raise Error, '查询分支名称失败!' unless result.is_a?(Array) + raise Error, '新默认分支不存在!' if !result.include?(@new_default_branch) end end \ No newline at end of file diff --git a/app/services/api/v1/projects/tags/delete_service.rb b/app/services/api/v1/projects/tags/delete_service.rb index 492898b53..d0d317aa8 100644 --- a/app/services/api/v1/projects/tags/delete_service.rb +++ b/app/services/api/v1/projects/tags/delete_service.rb @@ -40,7 +40,7 @@ class Api::V1::Projects::Tags::DeleteService < ApplicationService end def check_tag_exist - result = $gitea_client.get_repos_tag_name_set_by_owner_repo(owner, repo, {query: request_params}) rescue nil + result = $gitea_hat_client.get_repos_tag_name_set_by_owner_repo(owner, repo, {query: request_params}) rescue nil raise Error, '查询标签名称失败!' unless result.is_a?(Array) raise Error, '标签不存在!' if !result.include?(@tag_name) end diff --git a/app/services/api/v1/projects/tags/list_service.rb b/app/services/api/v1/projects/tags/list_service.rb index a7743fe00..9bf4701fc 100644 --- a/app/services/api/v1/projects/tags/list_service.rb +++ b/app/services/api/v1/projects/tags/list_service.rb @@ -30,7 +30,7 @@ class Api::V1::Projects::Tags::ListService < ApplicationService end def load_gitea_data - @gitea_data = $gitea_client.get_repos_tags_by_owner_repo(owner, repo, {query: request_params}) rescue nil + @gitea_data = $gitea_hat_client.get_repos_tags_by_owner_repo(owner, repo, {query: request_params}) rescue nil raise Error, '获取标签列表失败!' unless @gitea_data.is_a?(Hash) end end \ No newline at end of file diff --git a/app/views/api/v1/projects/branches/_simple_gitea_detail.json.jbuilder b/app/views/api/v1/projects/branches/_simple_gitea_detail.json.jbuilder index 6a35b782e..98890eba4 100644 --- a/app/views/api/v1/projects/branches/_simple_gitea_detail.json.jbuilder +++ b/app/views/api/v1/projects/branches/_simple_gitea_detail.json.jbuilder @@ -17,9 +17,9 @@ end json.protected branch['protected'] json.user_can_push branch['user_can_push'] json.user_can_merge branch['user_can_merge'] -json.commit_id branch['commit_id'] +json.commit_id branch['commit']['id'] json.commit_time_from_now time_from_now(branch['commit']['timestamp'].to_time) -json.commit_time branch['commit_time'] +json.commit_time branch['commit']['timestamp'] json.default_branch branch['default_branch'] json.http_url render_http_url(@project) json.zip_url render_zip_url(@owner, @project.repository, branch['name']) diff --git a/app/views/api/v1/projects/tags/_simple_gitea_index_detail.json.jbuilder b/app/views/api/v1/projects/tags/_simple_gitea_index_detail.json.jbuilder index b8ba28f85..460b56f56 100644 --- a/app/views/api/v1/projects/tags/_simple_gitea_index_detail.json.jbuilder +++ b/app/views/api/v1/projects/tags/_simple_gitea_index_detail.json.jbuilder @@ -12,10 +12,10 @@ if tag.present? && tag.is_a?(Hash) json.commit do json.sha tag['commit']['sha'] json.message tag['commit']['message'] - json.time_ago time_from_now(tag['commit']['commiter']['date'].to_time) - json.created_at_unix tag['commit']['commiter']['date'].to_time.to_i + json.time_ago time_from_now(tag['commit']['committer']['date'].to_time) + json.created_at_unix tag['commit']['committer']['date'].to_time.to_i json.committer do - json.partial! 'api/v1/users/commit_user', user: render_cache_commit_author(tag['commit']['commiter']), name: tag['commit']['commiter']['name'] + json.partial! 'api/v1/users/commit_user', user: render_cache_commit_author(tag['commit']['committer']), name: tag['commit']['committer']['name'] end json.author do json.partial! 'api/v1/users/commit_user', user: render_cache_commit_author(tag['commit']['author']), name: tag['commit']['author']['name'] From de1e931c2f442c9d6cb2b02427ae7aa07e52aa84 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 23 Feb 2023 11:38:16 +0800 Subject: [PATCH 172/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E8=80=85=E8=8E=B7=E5=8F=96=E8=A7=84=E5=88=99=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E5=88=86=E6=94=AF=E5=88=97=E8=A1=A8=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E6=97=A7=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 5 ++-- .../api/v1/projects/branches/list_service.rb | 13 ++++++---- .../repository/contributors/get_service.rb | 24 +++++++++++++++---- .../repositories/_contributor.json.jbuilder | 18 +++++++------- .../repositories/contributors.json.jbuilder | 2 +- 5 files changed, 42 insertions(+), 20 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index e32b31017..e6fef78f0 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -166,8 +166,9 @@ class RepositoriesController < ApplicationController if params[:filepath].present? || @project.educoder? @contributors = [] else - result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier) - @contributors = result.is_a?(Hash) && result.key?(:status) ? [] : result + result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier, {page: params[:page], limit: params[:limit]}) + @total_count = result[:total_count] + @contributors = result.is_a?(Hash) ? result[:body] : [] end rescue @contributors = [] diff --git a/app/services/api/v1/projects/branches/list_service.rb b/app/services/api/v1/projects/branches/list_service.rb index e5c6fe442..f53dc1f49 100644 --- a/app/services/api/v1/projects/branches/list_service.rb +++ b/app/services/api/v1/projects/branches/list_service.rb @@ -1,7 +1,7 @@ class Api::V1::Projects::Branches::ListService < ApplicationService attr_accessor :project, :token, :owner, :repo, :name, :page, :limit - attr_accessor :gitea_data + attr_accessor :gitea_data, :gitea_repo_data def initialize(project, params, token=nil) @project = project @@ -16,6 +16,8 @@ class Api::V1::Projects::Branches::ListService < ApplicationService def call load_gitea_data + gitea_data["default_branch"] = gitea_repo_data["default_branch"] + gitea_data end @@ -32,9 +34,12 @@ class Api::V1::Projects::Branches::ListService < ApplicationService end def load_gitea_data - puts request_params - @gitea_data = $gitea_client.get_repos_branches_by_owner_repo(owner, repo, {query: request_params}) rescue nil - puts @gitea_data + @gitea_data = $gitea_hat_client.get_repos_branches_by_owner_repo(owner, repo, {query: request_params}) rescue nil raise Error, '获取分支列表失败!' unless @gitea_data.is_a?(Hash) end + + def load_default_branch + @gitea_repo_data = $gitea_client.get_repos_by_owner_repo('yystopf', 'pig') rescue nil + raise Error, '获取仓库信息失败!' unless @gitea_data.is_a?(Hash) + end end \ No newline at end of file diff --git a/app/services/gitea/repository/contributors/get_service.rb b/app/services/gitea/repository/contributors/get_service.rb index e5ad32e38..fe9ed2463 100644 --- a/app/services/gitea/repository/contributors/get_service.rb +++ b/app/services/gitea/repository/contributors/get_service.rb @@ -1,22 +1,38 @@ class Gitea::Repository::Contributors::GetService < Gitea::ClientService - attr_reader :owner, :repo_name + attr_reader :owner, :repo_name, :page, :limit - def initialize(owner, repo_name) + def initialize(owner, repo_name, params={}) @owner = owner @repo_name = repo_name + @page = params[:page] || 1 + @limit = params[:limit] || 20 end def call response = get(url, params, true) - render_status(response) + render_result(response) end private def params - Hash.new.merge(token: owner.gitea_token) + Hash.new.merge(token: owner.gitea_token, page: page, limit: limit) end def url "/repos/#{owner.login}/#{repo_name}/contributors" end + + def render_result(response) + case response.status + when 200 + result = {} + headers = response.headers.to_hash + body = JSON.parse(response.body) + total_count = headers["x-total"] + result.merge(total_count: total_count.to_i, body: body) + else + nil + # {status: -1, message: "#{body['message']}"} + end + end end \ No newline at end of file diff --git a/app/views/repositories/_contributor.json.jbuilder b/app/views/repositories/_contributor.json.jbuilder index 56fa9ce86..ed036aae3 100644 --- a/app/views/repositories/_contributor.json.jbuilder +++ b/app/views/repositories/_contributor.json.jbuilder @@ -1,15 +1,15 @@ -user = $redis_cache.hgetall("v2-owner-common:#{contributor["login"]}-#{contributor["email"]}") +user = $redis_cache.hgetall("v2-owner-common:#{contributor["name"]}-#{contributor["email"]}") if user.blank? - json.contributions contributor["contributions"] - # json.gid contributor["id"] - json.login contributor["login"] + json.contributions contributor["commits"] + # json.id contributor["id"] + json.name contributor["name"] json.type nil - json.name contributor["login"] - json.image_url User::Avatar.get_letter_avatar_url(contributor["login"]) + json.name contributor["name"] + json.image_url User::Avatar.get_letter_avatar_url(contributor["name"]) else - json.contributions contributor["contributions"] - # json.gid contributor["id"] - json.login user["login"] + json.contributions contributor["commits"] + json.id user["id"] + json.name user["name"] json.type user["type"] json.name user["name"] json.image_url user["avatar_url"] diff --git a/app/views/repositories/contributors.json.jbuilder b/app/views/repositories/contributors.json.jbuilder index 2fb6abae8..bec285523 100644 --- a/app/views/repositories/contributors.json.jbuilder +++ b/app/views/repositories/contributors.json.jbuilder @@ -1,4 +1,4 @@ -total_count = @contributors.size +total_count = @total_count json.list @contributors.each do |contributor| json.partial! 'contributor', locals: { contributor: contributor } end From 36dbf76d808718526d88216a32cddc1861334e8a Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 23 Feb 2023 13:45:30 +0800 Subject: [PATCH 173/438] =?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/projects/branches/list_service.rb | 9 +++++---- .../projects/branches/_simple_gitea_detail.json.jbuilder | 2 +- app/views/api/v1/projects/branches/create.json.jbuilder | 2 +- app/views/api/v1/projects/branches/index.json.jbuilder | 3 ++- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/services/api/v1/projects/branches/list_service.rb b/app/services/api/v1/projects/branches/list_service.rb index f53dc1f49..590c4884f 100644 --- a/app/services/api/v1/projects/branches/list_service.rb +++ b/app/services/api/v1/projects/branches/list_service.rb @@ -15,10 +15,11 @@ class Api::V1::Projects::Branches::ListService < ApplicationService def call load_gitea_data - - gitea_data["default_branch"] = gitea_repo_data["default_branch"] + load_default_branch - gitea_data + @gitea_data[:default_branch] = @gitea_repo_data["default_branch"] + + @gitea_data end private @@ -39,7 +40,7 @@ class Api::V1::Projects::Branches::ListService < ApplicationService end def load_default_branch - @gitea_repo_data = $gitea_client.get_repos_by_owner_repo('yystopf', 'pig') rescue nil + @gitea_repo_data = $gitea_client.get_repos_by_owner_repo(owner, repo) rescue nil raise Error, '获取仓库信息失败!' unless @gitea_data.is_a?(Hash) end end \ No newline at end of file diff --git a/app/views/api/v1/projects/branches/_simple_gitea_detail.json.jbuilder b/app/views/api/v1/projects/branches/_simple_gitea_detail.json.jbuilder index 98890eba4..c9235bdb4 100644 --- a/app/views/api/v1/projects/branches/_simple_gitea_detail.json.jbuilder +++ b/app/views/api/v1/projects/branches/_simple_gitea_detail.json.jbuilder @@ -20,7 +20,7 @@ json.user_can_merge branch['user_can_merge'] json.commit_id branch['commit']['id'] json.commit_time_from_now time_from_now(branch['commit']['timestamp'].to_time) json.commit_time branch['commit']['timestamp'] -json.default_branch branch['default_branch'] +json.default_branch default_branch || nil json.http_url render_http_url(@project) json.zip_url render_zip_url(@owner, @project.repository, branch['name']) json.tar_url render_tar_url(@owner, @project.repository, branch['name']) \ No newline at end of file diff --git a/app/views/api/v1/projects/branches/create.json.jbuilder b/app/views/api/v1/projects/branches/create.json.jbuilder index eed860b81..b7de0f576 100644 --- a/app/views/api/v1/projects/branches/create.json.jbuilder +++ b/app/views/api/v1/projects/branches/create.json.jbuilder @@ -1 +1 @@ -json.partial! "api/v1/projects/branches/simple_gitea_detail", branch: @result_object +json.partial! "api/v1/projects/branches/simple_gitea_detail", branch: @result_object, default_branch: @result_object[:default_branch] diff --git a/app/views/api/v1/projects/branches/index.json.jbuilder b/app/views/api/v1/projects/branches/index.json.jbuilder index cfb9bb647..80b3e4d03 100644 --- a/app/views/api/v1/projects/branches/index.json.jbuilder +++ b/app/views/api/v1/projects/branches/index.json.jbuilder @@ -1,4 +1,5 @@ json.total_count @result_object[:total_data].to_i json.branches @result_object[:data].each do |branch| - json.partial! "api/v1/projects/branches/simple_gitea_detail", branch: branch + json.partial! "api/v1/projects/branches/simple_gitea_detail", branch: branch, default_branch: @result_object[:default_branch] + end \ No newline at end of file From 222de17437b64485dc6dfb6f3b18cf713ec7ffb1 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 23 Feb 2023 13:54:18 +0800 Subject: [PATCH 174/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 1528d502b..216884ea6 100644 --- a/Gemfile +++ b/Gemfile @@ -140,4 +140,4 @@ gem 'doorkeeper' gem 'doorkeeper-jwt' -gem 'gitea-client', '~> 1.3.1' +gem 'gitea-client', '~> 1.3.2' From d9b2e98110664f4ce01ff80af5e7a2f31b9b8ced Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 28 Feb 2023 14:19:55 +0800 Subject: [PATCH 175/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Awebhook=20ht?= =?UTF-8?q?tp=5Fmethod=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 +- app/services/api/v1/projects/pulls/versions/get_diff_service.rb | 2 +- app/services/api/v1/projects/webhooks/update_service.rb | 2 +- app/services/gitea/repository/webhooks/create_service.rb | 2 +- app/services/gitea/repository/webhooks/update_service.rb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index 216884ea6..805e88fc6 100644 --- a/Gemfile +++ b/Gemfile @@ -140,4 +140,4 @@ gem 'doorkeeper' gem 'doorkeeper-jwt' -gem 'gitea-client', '~> 1.3.2' +gem 'gitea-client', '~> 1.3.3' diff --git a/app/services/api/v1/projects/pulls/versions/get_diff_service.rb b/app/services/api/v1/projects/pulls/versions/get_diff_service.rb index 1cae8c345..1f882fd3b 100644 --- a/app/services/api/v1/projects/pulls/versions/get_diff_service.rb +++ b/app/services/api/v1/projects/pulls/versions/get_diff_service.rb @@ -30,7 +30,7 @@ class Api::V1::Projects::Pulls::Versions::GetDiffService < ApplicationService end def load_gitea_data - @gitea_data = $gitea_hat_client.get_repos_pulls_versions_diff_by_owner_repo_index_version_id(owner, repo, index, version_id, {query: request_params}) + @gitea_data = $gitea_hat_client.get_repos_pulls_versions_diff_by_owner_repo_index_id(owner, repo, index, version_id, {query: request_params}) raise Error, '获取合并请求版本diff失败!' unless @gitea_data.is_a?(Hash) end end \ No newline at end of file diff --git a/app/services/api/v1/projects/webhooks/update_service.rb b/app/services/api/v1/projects/webhooks/update_service.rb index a632d6f2d..c98a24ad8 100644 --- a/app/services/api/v1/projects/webhooks/update_service.rb +++ b/app/services/api/v1/projects/webhooks/update_service.rb @@ -58,6 +58,6 @@ class Api::V1::Projects::Webhooks::UpdateService < ApplicationService end def excute_data_to_gitea - @gitea_data = $gitea_client.patch_repos_hooks_by_owner_repo_id(owner, repo, id, {body: request_body.to_json, query: request_params}) rescue nil + @gitea_data = $gitea_hat_client.patch_repos_hooks_by_owner_repo_id(owner, repo, id, {body: request_body.to_json, query: request_params}) rescue nil end end \ No newline at end of file diff --git a/app/services/gitea/repository/webhooks/create_service.rb b/app/services/gitea/repository/webhooks/create_service.rb index 33c9a9b0c..9105b39c5 100644 --- a/app/services/gitea/repository/webhooks/create_service.rb +++ b/app/services/gitea/repository/webhooks/create_service.rb @@ -8,7 +8,7 @@ class Gitea::Repository::Webhooks::CreateService < Gitea::ClientService end def call - response = post(url, request_params) + response = post(url, request_params, true) render_response(response) end diff --git a/app/services/gitea/repository/webhooks/update_service.rb b/app/services/gitea/repository/webhooks/update_service.rb index 6094c6c51..25456a801 100644 --- a/app/services/gitea/repository/webhooks/update_service.rb +++ b/app/services/gitea/repository/webhooks/update_service.rb @@ -9,7 +9,7 @@ class Gitea::Repository::Webhooks::UpdateService < Gitea::ClientService end def call - response = patch(url, data_params) + response = patch(url, data_params, true) render_response(response) end From 13e266aa282e177cc067c700ee4d4216f7237e4b Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 7 Mar 2023 15:27:22 +0800 Subject: [PATCH 176/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E8=AF=B7=E6=B1=82=E6=8C=87=E6=B4=BE=E4=BA=BA=E5=91=98?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E6=AD=A3=E5=B8=B8=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/gitea/pull_request/update_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/gitea/pull_request/update_service.rb b/app/services/gitea/pull_request/update_service.rb index a68981f29..339caa6ce 100644 --- a/app/services/gitea/pull_request/update_service.rb +++ b/app/services/gitea/pull_request/update_service.rb @@ -27,7 +27,7 @@ class Gitea::PullRequest::UpdateService < Gitea::ClientService end def call - response = patch(url, request_params) + response = patch(url, request_params, true) status, message, body = render_response(response) json_format(status, message, body) From 7bda0fd126c0d875e41c73611d205f754c5543ea Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 15 Mar 2023 10:30:02 +0800 Subject: [PATCH 177/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=A3=B0?= =?UTF-8?q?=E6=98=8E=E6=B6=88=E6=81=AF=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/send_template_message_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/send_template_message_job.rb b/app/jobs/send_template_message_job.rb index da289857e..05572d451 100644 --- a/app/jobs/send_template_message_job.rb +++ b/app/jobs/send_template_message_job.rb @@ -68,7 +68,7 @@ class SendTemplateMessageJob < ApplicationJob operator = User.find_by_id(operator_id) issue = Issue.find_by_id(issue_id) return unless operator.present? && issue.present? - receivers = User.where(id: issue.author_id).where.not(id: operator&.id) + receivers = User.where(id: issue.claim_users.pluck(:id).append(issue.author_id)).where.not(id: operator&.id) receivers_string, content, notification_url = MessageTemplate::IssueClaim.get_message_content(receivers, operator, issue) Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, issue_id: issue.id}) when 'IssueExpire' From 5207d901742fe5c1dc9e688957ca6b8416f11964 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 16 Mar 2023 09:42:12 +0800 Subject: [PATCH 178/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E7=96=91=E4=BF=AE=E5=BA=8F=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/api/v1/issues/index.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/api/v1/issues/index.json.jbuilder b/app/views/api/v1/issues/index.json.jbuilder index 39a467dd4..cde117fdc 100644 --- a/app/views/api/v1/issues/index.json.jbuilder +++ b/app/views/api/v1/issues/index.json.jbuilder @@ -5,7 +5,7 @@ json.total_count @issues.total_count json.has_created_issues @project.issues.size > 0 json.issues @issues.each do |issue| if params[:only_name].present? - json.(issue, :id, :subject) + json.(issue, :id, :subject, :project_issues_index) else json.partial! "simple_detail", locals: {issue: issue} end From 77b3c20e154ca0de1f77c5fc16c538a7845ad6ac Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 16 Mar 2023 09:47:11 +0800 Subject: [PATCH 179/438] =?UTF-8?q?=E6=9B=B4=E6=96=B0=EF=BC=9Agitea=20clie?= =?UTF-8?q?nt=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 805e88fc6..abe202581 100644 --- a/Gemfile +++ b/Gemfile @@ -140,4 +140,4 @@ gem 'doorkeeper' gem 'doorkeeper-jwt' -gem 'gitea-client', '~> 1.3.3' +gem 'gitea-client', '~> 1.4.1' From 553ac7306cb011d53286fec5489872eb3e9fee92 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 16 Mar 2023 10:36:43 +0800 Subject: [PATCH 180/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=8C=BA?= =?UTF-8?q?=E5=9D=97=E9=93=BE=E9=A1=B9=E7=9B=AE=E7=96=91=E4=BF=AE=E6=82=AC?= =?UTF-8?q?=E8=B5=8F=E9=87=91=E9=A2=9D=E6=98=BE=E7=A4=BA=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/api/v1/issues/_detail.json.jbuilder | 2 +- app/views/api/v1/issues/_simple_detail.json.jbuilder | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/api/v1/issues/_detail.json.jbuilder b/app/views/api/v1/issues/_detail.json.jbuilder index 712e7a960..7c3adecc3 100644 --- a/app/views/api/v1/issues/_detail.json.jbuilder +++ b/app/views/api/v1/issues/_detail.json.jbuilder @@ -1,5 +1,5 @@ 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.blockchain_token_num (Site.has_blockchain? && 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 4f288ce20..8b4bb6af3 100644 --- a/app/views/api/v1/issues/_simple_detail.json.jbuilder +++ b/app/views/api/v1/issues/_simple_detail.json.jbuilder @@ -1,5 +1,5 @@ json.(issue, :id, :subject, :project_issues_index) -json.blockchain_token_num issue.project&.use_blockchain ? issue.blockchain_token_num : nil +json.blockchain_token_num (Site.has_blockchain? && 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 5a2e642579f9504d1133a7e111140b466eff62f4 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 16 Mar 2023 11:33:39 +0800 Subject: [PATCH 181/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Areadme=20?= =?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/helpers/repositories_helper.rb | 4 ++-- app/views/repositories/_simple_entry.json.jbuilder | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index c98174777..0ca5a5071 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -108,8 +108,8 @@ module RepositoriesHelper file_path = readme_path.include?('/') ? readme_path.gsub("/#{readme_name}", '') : readme_path.gsub("#{readme_name}", '') return nil if str.blank? content = Base64.decode64(str).force_encoding('UTF-8') - s_regex = /\[.*?\]\((.*?)\)/ - src_regex = /src=\"(.*?)\"/ + s_regex = /\s\[.*?\]\((.*?)\)\s/ + src_regex = /\ssrc=\"(.*?)\"\s/ ss = content.to_s.scan(s_regex) ss_src = content.to_s.scan(src_regex) total_sources = ss + ss_src diff --git a/app/views/repositories/_simple_entry.json.jbuilder b/app/views/repositories/_simple_entry.json.jbuilder index 339214cc4..42342f07b 100644 --- a/app/views/repositories/_simple_entry.json.jbuilder +++ b/app/views/repositories/_simple_entry.json.jbuilder @@ -2,7 +2,7 @@ if @project.forge? is_dir = @sub_entries.is_a?(Array) file_name = entry['name'] file_type = file_name.starts_with?('.') ? file_name[1..-1] : File.extname(file_name.to_s)[1..-1] - direct_download = ["makefile","dockerfile"].exclude?(file_name.to_s.downcase) && download_type(file_type) + direct_download = %w(makefile dockerfile readme).exclude?(file_name.to_s.downcase) && download_type(file_type) image_type = image_type?(file_type) json.name file_name json.sha entry['sha'] From 2c9d2746bae861f66eda00f8619595bce17a70c5 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 16 Mar 2023 15:39:49 +0800 Subject: [PATCH 182/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Areadme=20?= =?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/helpers/repositories_helper.rb | 75 ++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 24 deletions(-) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 0ca5a5071..64ece82d1 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -104,39 +104,66 @@ module RepositoriesHelper end # author hui.he - def new_readme_render_decode64_content(str, owner, repo, ref, readme_path, readme_name) + def new_readme_render_decode64_content(str, owner, repo, ref, readme_path, readme_name) file_path = readme_path.include?('/') ? readme_path.gsub("/#{readme_name}", '') : readme_path.gsub("#{readme_name}", '') return nil if str.blank? content = Base64.decode64(str).force_encoding('UTF-8') - s_regex = /\s\[.*?\]\((.*?)\)\s/ - src_regex = /\ssrc=\"(.*?)\"\s/ + # s_regex = /\s\!\[.*?\]\((.*?)\)\s/ + s_regex = /```([\s\S]*?)```[\s]?/ + s_regex_1 = /\[.*?\]\((.*?)\)/ + src_regex = /src=\"(.*?)\"/ + src_regex_1 = /src=\'(.*?)\'/ ss = content.to_s.scan(s_regex) + ss_1 = content.to_s.scan(s_regex_1) ss_src = content.to_s.scan(src_regex) - total_sources = ss + ss_src - total_sources.uniq! - total_sources.each do |s| - begin - s_content = s[0] - # 链接直接跳过不做替换 - next if s_content.starts_with?('http://') || s_content.starts_with?('https://') || s_content.starts_with?('mailto:') || s_content.blank? - ext = File.extname(s_content)[1..-1] - if (image_type?(ext) || download_type(ext)) && !ext.blank? - s_content = File.expand_path(s_content, file_path) - s_content = s_content.split("#{Rails.root}/")[1] - # content = content.gsub(s[0], "/#{s_content}") - s_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw?filepath=#{s_content}&ref=#{ref}"].join - content = content.gsub(s[0], s_content) - else - path = [owner&.login, repo&.identifier, 'tree', ref, file_path].join("/") - s_content = File.expand_path(s_content, path) - s_content = s_content.split("#{Rails.root}/")[1] - content = content.gsub('('+s[0]+')', '('+"/#{s_content}"+')') + ss_src_1 = content.to_s.scan(src_regex_1) + total_sources = {ss: ss, ss_1: ss_1, ss_src: ss_src, ss_src_1: ss_src_1} + # total_sources.uniq! + total_sources.except(:ss).each do |k, sources| + sources.each do |s| + begin + s_content = s[0] + # 链接直接跳过不做替换 + next if s_content.starts_with?('http://') || s_content.starts_with?('https://') || s_content.starts_with?('mailto:') || s_content.blank? + ext = File.extname(s_content)[1..-1] + if (image_type?(ext) || download_type(ext)) && !ext.blank? + s_content = File.expand_path(s_content, file_path) + s_content = s_content.split("#{Rails.root}/")[1] + # content = content.gsub(s[0], "/#{s_content}") + s_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw?filepath=#{s_content}&ref=#{ref}"].join + case k + when 'ss_src' + content = content.gsub("src=\"#{s[0]}\"", "src=\"#{s_content}\"") + when 'ss_src_1' + content = content.gsub("src=\'#{s[0]}\'", "src=\'#{s_content}\'") + else + content = content.gsub("(#{s[0]})", "(#{s_content})") + end + else + path = [owner&.login, repo&.identifier, 'tree', ref, file_path].join("/") + s_content = File.expand_path(s_content, path) + s_content = s_content.split("#{Rails.root}/")[1] + case k + when 'ss_src' + content = content.gsub("src=\"#{s[0]}\"", "src=\"/#{s_content}\"") + when 'ss_src_1' + content = content.gsub("src=\'#{s[0]}\'", "src=\'/#{s_content}\'") + else + content = content.gsub("(#{s[0]})", "(/#{s_content})") + end + end + rescue + next end - rescue - next end end + after_ss_souces = content.to_s.scan(s_regex) + index =0 + after_ss_souces.each do |s| + content = content.gsub("#{s[0]}","#{total_sources[:ss][index][0]}") + index += 1 + end return content rescue return str From 9c1b21f246043b833dc9c987ea46613a9f961a6e Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 16 Mar 2023 15:46:56 +0800 Subject: [PATCH 183/438] =?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/helpers/repositories_helper.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 64ece82d1..d3a008515 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -109,17 +109,19 @@ module RepositoriesHelper return nil if str.blank? content = Base64.decode64(str).force_encoding('UTF-8') # s_regex = /\s\!\[.*?\]\((.*?)\)\s/ + s_regex_c = /`{1,2}[^`](.*?)`{1,2}/ s_regex = /```([\s\S]*?)```[\s]?/ s_regex_1 = /\[.*?\]\((.*?)\)/ src_regex = /src=\"(.*?)\"/ src_regex_1 = /src=\'(.*?)\'/ + ss_c = content.to_s.scan(s_regex_c) ss = content.to_s.scan(s_regex) ss_1 = content.to_s.scan(s_regex_1) ss_src = content.to_s.scan(src_regex) ss_src_1 = content.to_s.scan(src_regex_1) - total_sources = {ss: ss, ss_1: ss_1, ss_src: ss_src, ss_src_1: ss_src_1} + total_sources = {ss_c: ss_c,ss: ss, ss_1: ss_1, ss_src: ss_src, ss_src_1: ss_src_1} # total_sources.uniq! - total_sources.except(:ss).each do |k, sources| + total_sources.except(:ss, :ss_c).each do |k, sources| sources.each do |s| begin s_content = s[0] @@ -159,11 +161,14 @@ module RepositoriesHelper end after_ss_souces = content.to_s.scan(s_regex) - index =0 - after_ss_souces.each do |s| + after_ss_souces.each_with_index do |s, index| content = content.gsub("#{s[0]}","#{total_sources[:ss][index][0]}") - index += 1 end + after_ss_c_souces = content.to_s.scan(s_regex_c) + after_ss_c_souces.each_with_index do |s, index| + content = content.gsub("#{s[0]}","#{total_sources[:ss_c][index][0]}") + end + return content rescue return str From 24fe22398eeb622fcc9a435ec59cd9dd4149618d Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 16 Mar 2023 16:09:42 +0800 Subject: [PATCH 184/438] =?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/helpers/repositories_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index d3a008515..afde12d2c 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -133,7 +133,7 @@ module RepositoriesHelper s_content = s_content.split("#{Rails.root}/")[1] # content = content.gsub(s[0], "/#{s_content}") s_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw?filepath=#{s_content}&ref=#{ref}"].join - case k + case k.to_s when 'ss_src' content = content.gsub("src=\"#{s[0]}\"", "src=\"#{s_content}\"") when 'ss_src_1' @@ -145,7 +145,7 @@ module RepositoriesHelper path = [owner&.login, repo&.identifier, 'tree', ref, file_path].join("/") s_content = File.expand_path(s_content, path) s_content = s_content.split("#{Rails.root}/")[1] - case k + case k.to_s when 'ss_src' content = content.gsub("src=\"#{s[0]}\"", "src=\"/#{s_content}\"") when 'ss_src_1' From bd110bac00cf4ddeb28aa7c057d84813f410f17b Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Thu, 16 Mar 2023 16:48:00 +0800 Subject: [PATCH 185/438] remove identity for admins user --- app/controllers/admins/users_controller.rb | 6 ++--- app/views/admins/users/edit.html.erb | 22 ------------------- app/views/admins/users/index.html.erb | 6 +---- .../admins/users/shared/_user_list.html.erb | 1 - 4 files changed, 4 insertions(+), 31 deletions(-) diff --git a/app/controllers/admins/users_controller.rb b/app/controllers/admins/users_controller.rb index 07ea8261e..8ff5908c6 100644 --- a/app/controllers/admins/users_controller.rb +++ b/app/controllers/admins/users_controller.rb @@ -64,8 +64,8 @@ class Admins::UsersController < Admins::BaseController end def update_params - params.require(:user).permit(%i[lastname nickname gender identity technical_title student_id is_shixun_marker - mail phone location location_city school_id department_id admin business is_test - password professional_certification authentication login]) + params.require(:user).permit(%i[lastname nickname gender technical_title is_shixun_marker + mail phone location location_city school_id department_id admin + password login]) end end diff --git a/app/views/admins/users/edit.html.erb b/app/views/admins/users/edit.html.erb index 3b4801772..b407cbbe7 100644 --- a/app/views/admins/users/edit.html.erb +++ b/app/views/admins/users/edit.html.erb @@ -63,19 +63,6 @@ <%= f.input :gender, as: :radio_buttons, label: '性别', collection: [%w(男 0), %w(女 1)], wrapper_html: { class: 'col-md-3' } %>
      -
      -
      - <%= f.label :identity, label: '职业' %> - <%= select_tag('user[identity]', [], class: 'form-control identity-select optional', 'data-value': @user.user_extension&.identity, 'data-first-title': '请选择') %> -
      -
      - <%= f.label :technical_title, label: '职称' %> - <%= select_tag('user[technical_title]', [], class: 'form-control technical-title-select optional', 'data-value': @user.technical_title) %> -
      - - <%= f.input :student_id, as: :tel, label: '学号', wrapper_html: { class: 'col-md-2', style: @user&.user_extension&.student? ? '' : 'display:none;' }, input_html: { class: 'student-id-input' } %> -
      -
      <%= f.input :mail, as: :email, label: '邮箱地址', wrapper_html: { class: 'col-md-3' }, input_html: { class: 'col-sm-11' } %> <%= f.input :phone, as: :tel, label: '手机号', wrapper_html: { class: 'col-md-3' }, input_html: { class: 'col-sm-11', autocomplete: 'off' } %> @@ -102,19 +89,10 @@ <%= f.label :role, label: '角色' %>
      <%= f.input :admin, as: :boolean, label: '管理员', checked_value: 1, unchecked_value: 0 %> - <%= f.input :business, as: :boolean, label: '运营人员', wrapper_html: { class: 'ml-3' }, checked_value: 1, unchecked_value: 0 %> - <%= f.input :is_test, as: :boolean, label: '测试账号', wrapper_html: { class: 'ml-3' }, checked_value: 1, unchecked_value: 0 %>
      <% end %> -
      - <%= f.label :role, label: '认证信息' %> -
      - <%= f.input :professional_certification, as: :boolean, label: '职业认证', checked_value: 1, unchecked_value: 0 %> - <%= f.input :authentication, as: :boolean, label: '实名认证', wrapper_html: { class: 'ml-3' }, checked_value: 1, unchecked_value: 0 %> -
      -
      <%= f.input :password, as: :password, label: '修改密码', wrapper_html: { class: 'col-md-3' }, input_html: { class: 'col-sm-11', autocomplete: 'new-password' } %> diff --git a/app/views/admins/users/index.html.erb b/app/views/admins/users/index.html.erb index 4ba38c39a..3c355242e 100644 --- a/app/views/admins/users/index.html.erb +++ b/app/views/admins/users/index.html.erb @@ -10,11 +10,7 @@ <%= select_tag(:status, options_for_select(status_options), class: 'form-control') %>
      -
      - - <% identity_options = [['全部', ''], ['教师', 0], ['学生', 1], ['专业人士', 2]] %> - <%= select_tag(:identity, options_for_select(identity_options), class: 'form-control') %> -
      +
      <% open_user_type_options = [['所有用户', ''], ['头歌同步', "OpenUsers::Educoder"], ['平台注册', "Forge"],] %> diff --git a/app/views/admins/users/shared/_user_list.html.erb b/app/views/admins/users/shared/_user_list.html.erb index 716e7cc54..67571178a 100644 --- a/app/views/admins/users/shared/_user_list.html.erb +++ b/app/views/admins/users/shared/_user_list.html.erb @@ -24,7 +24,6 @@
      <%= overflow_hidden_span display_text(user.mail), width: 150 %> <%= overflow_hidden_span display_text(user.phone), width: 100 %><%= user.identity %> <%= display_text(user.created_on&.strftime('%Y-%m-%d %H:%M')) %> <%= display_text(user.last_login_on&.strftime('%Y-%m-%d %H:%M')) %> <%= link_to user.projects_count, "/#{user.login}/projects", target: "_blank" %>昵称 邮件地址 手机号码角色 <%= sort_tag('创建于', name: 'created_on', path: admins_users_path) %> <%= sort_tag('最后登录', name: 'last_login_on', path: admins_users_path) %> 项目数
      From 4f87c0697697b1df8c0d43a36fb7e11b5c32d1f4 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 17:15:45 +0800 Subject: [PATCH 278/438] =?UTF-8?q?fixed=20bot=E5=AE=89=E8=A3=85=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=8C=89=E5=AE=89=E8=A3=85=E8=80=85=E5=88=86=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 2 +- app/views/installations/index.json.jbuilder | 2 +- app/views/installations/show.json.jbuilder | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index 76984ee58..f13f7f459 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -8,7 +8,7 @@ class InstallationsController < ApplicationController end def index - @install_bots = BotInstall.where(bot_id: get_bot_id) + @install_bots = BotInstall.where(bot_id: get_bot_id).group(:installer_id) end def show diff --git a/app/views/installations/index.json.jbuilder b/app/views/installations/index.json.jbuilder index 532f4c91f..9235bd4f8 100644 --- a/app/views/installations/index.json.jbuilder +++ b/app/views/installations/index.json.jbuilder @@ -2,7 +2,7 @@ json.status 0 json.message "success" json.data do json.array! @install_bots do |install_bot| - json.extract! install_bot, :id, :bot_id, :installer_id, :state, :create_time, :update_time + json.extract! install_bot, :id, :bot_id, :installer_id json.bot_name install_bot&.bot&.name end end \ No newline at end of file diff --git a/app/views/installations/show.json.jbuilder b/app/views/installations/show.json.jbuilder index ee605b860..89db0107b 100644 --- a/app/views/installations/show.json.jbuilder +++ b/app/views/installations/show.json.jbuilder @@ -1,5 +1,5 @@ json.partial! "commons/success" -json.extract! @install_bot, :id, :bot_id, :installer_id, :state, :create_time, :update_time +json.extract! @install_bot, :id, :bot_id, :installer_id json.bot_name @install_bot&.bot&.name From e18063d7ca0ce2fe113e6e0aeb20364889d5da86 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 17:20:33 +0800 Subject: [PATCH 279/438] =?UTF-8?q?fixed=20bot=E5=AE=89=E8=A3=85=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=8C=89=E5=AE=89=E8=A3=85=E8=80=85=E5=88=86=E7=BB=84?= =?UTF-8?q?,=E5=A2=9E=E5=8A=A0=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/installations/index.json.jbuilder | 10 +++++++++- app/views/installations/show.json.jbuilder | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/views/installations/index.json.jbuilder b/app/views/installations/index.json.jbuilder index 9235bd4f8..366bdeeca 100644 --- a/app/views/installations/index.json.jbuilder +++ b/app/views/installations/index.json.jbuilder @@ -2,7 +2,15 @@ json.status 0 json.message "success" json.data do json.array! @install_bots do |install_bot| - json.extract! install_bot, :id, :bot_id, :installer_id + json.extract! install_bot, :id, :bot_id, :installer_id, :create_time, :update_time json.bot_name install_bot&.bot&.name + json.account do + user = User.find_by(id: install_bot.installer_id) + if user.present? + json.partial! "api/v1/users/simple_user", locals: {user: user} + else + json.nil! + end + end end end \ No newline at end of file diff --git a/app/views/installations/show.json.jbuilder b/app/views/installations/show.json.jbuilder index 89db0107b..4ab91c1e4 100644 --- a/app/views/installations/show.json.jbuilder +++ b/app/views/installations/show.json.jbuilder @@ -1,5 +1,13 @@ json.partial! "commons/success" -json.extract! @install_bot, :id, :bot_id, :installer_id +json.extract! @install_bot, :id, :bot_id, :installer_id, :create_time, :update_time json.bot_name @install_bot&.bot&.name +json.account do + user = User.find_by(id: @install_bot.installer_id) + if user.present? + json.partial! "api/v1/users/simple_user", locals: { user: user } + else + json.nil! + end +end From 04c30be5a6160d65bf63d29b449b6cec7e45a3dd Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 17:33:16 +0800 Subject: [PATCH 280/438] =?UTF-8?q?fixed=20bot=E5=AE=89=E8=A3=85log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index f13f7f459..7d47b2917 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -112,6 +112,7 @@ class InstallationsController < ApplicationController header = request.authorization pattern = /^Bearer /i token = header.gsub(pattern, "") + Rails.logger.info("request.authorization==#{request.authorization}") decoded_token = JWT.decode token, nil, false # 前面已验证token有效期和正确性 decoded_token[0]["iss"] From 80fa5330b2e374587eca29b5e835ac6a41bc517d Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 17:38:48 +0800 Subject: [PATCH 281/438] =?UTF-8?q?fixed=20bot=E5=AE=89=E8=A3=85=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E5=88=97=E8=A1=A8=E5=BF=85=E9=A1=BB=E4=BD=BF=E7=94=A8?= =?UTF-8?q?access=5Ftokens=E8=8E=B7=E5=8F=96=E5=88=B0bot=E7=9A=84token?= =?UTF-8?q?=E6=89=8D=E8=83=BD=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 5 +- test/jwt_github_test.rb | 32 ++++++++++++ test/jwt_test.rb | 55 ++++++++++++--------- 3 files changed, 69 insertions(+), 23 deletions(-) create mode 100644 test/jwt_github_test.rb diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index 7d47b2917..85e2da5cb 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -18,7 +18,10 @@ class InstallationsController < ApplicationController def repositories # 与github差异,所以取安装用户和bot对应所有的仓库 - @install_bots = BotInstall.where(bot_id: get_bot_id).where(installer_id: params[:id]) + # 必须使用access_tokens获取到bot的token才能查询 + tip_exception "Token无效" if current_user.platform != "bot" + bot = Bot.find_by(uid: current_user.id) + @install_bots = BotInstall.where(bot_id: bot.id).where(installer_id: params[:id]) end def update_secret diff --git a/test/jwt_github_test.rb b/test/jwt_github_test.rb new file mode 100644 index 000000000..ad1d41177 --- /dev/null +++ b/test/jwt_github_test.rb @@ -0,0 +1,32 @@ +require 'openssl' +require 'jwt' # https://rubygems.org/gems/jwt + +# Private key contents +private_pem = File.read("/Users/xxq/Documents/gitlink-webhook.2022-06-09.private-key.pem") +private_key = OpenSSL::PKey::RSA.new(private_pem) + +# Generate the JWT +payload = { + # issued at time, 60 seconds in the past to allow for clock drift + iat: Time.now.to_i - 60, + # JWT expiration time (10 minute maximum) + exp: Time.now.to_i + (10 * 60), + # GitHub App's identifier + iss: "209248" +} + +jwt = JWT.encode(payload, private_key, "RS256") +puts jwt +# puts OpenSSL::PKey::RSA.new(private_key33).public_key.to_s +# +# rsa_private = OpenSSL::PKey::RSA.new(private_key33) +# rsa_public = rsa_private.public_key +# +# + +# puts decoded_token[0] +# puts decoded_token[0]["iss"] + +# serialized_private_key = OpenSSL::PKey::RSA::generate(2048).to_s + + diff --git a/test/jwt_test.rb b/test/jwt_test.rb index 8d0faaa3f..7ea6dc8f3 100644 --- a/test/jwt_test.rb +++ b/test/jwt_test.rb @@ -2,12 +2,35 @@ require 'openssl' require 'jwt' # https://rubygems.org/gems/jwt # Private key contents -private_pem = File.read("/Users/xxq/Documents/gitlink-webhook.2022-06-09.private-key.pem") - -private_key22="-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEApOebWmRV/ooNq5Ks04YnDU7pEezGShGvaiF0cIvn9jvmYHu0\nFialojvJV3VpB6xE6QBPXZ0Pi1lokZ9dMx8F5UWNx9WA7wf7xK3hAJLNml+GeewF\nou8vk/Ry7n6diLxETNVd7YzPvztn5qaMp/DXa+65i11H8a/XXqR7kCVnCevVlufh\nNr/Dp6dW31W8TInnDQasJFMZ8GY7f+tCwLXNc0M8p+TeDp9xmXHOrEB+S/mgbUOF\nXgRr6icbMmlT9bsAxYHrrDkcVxJhs0hq5vD3BaoK06gcZEnN7/HVNzgVSOYNsVNh\n9006cMgDSOwc9F8aulP7cr8k74INq1xswoGs9wIDAQABAoIBAHayc2NkF3YJXv+h\nqx7yUEfHBgKuAKiuBCqLfCnKuqPFx/So9h5/oPeeuzVlwL0SJePlIjuK4vZ128v9\n/vLeILtADmbJ6m2jvHh8hBmKkc3Ndplp50C5k/CWoufCYZhbk3oOlvZ3Rc4rb4VZ\nWqNDu3voMMv8z91KqeZo1LwUAA/l9mU++zLkRA6qOuWGBJFsM8YpshzxL5lzRUb3\n7y+YJDyUZztfzKwr6pqm1n9B2e6e+znCw1vMZXp2TbUrpvrrXSxlgdNuK68SkZX6\nTdZUD8y0viwaioRVf3vR+e/Bf7yZannGdvcmVGs0A7dq9QgHkakqNHiRkQgwviSq\nbjBo7dECgYEAzekeP5j/dAPkv9X4qnmZ4du/+ZgrQrJckDD/JuNIBmQT9m286l4P\nmb2TBcWkswVOZaS5Qy2bN/69rwIbcdvbaROGBCabn3ATK4fSzmUk31M2rRKYZqaU\nMi0W2g2YtSRg+bV6S7aFXa98j5+JlqJeDZQoRuvL68ooq5WzFWmfYnkCgYEAzQTi\n4USqz2z66BfU+v2rchzK8URxnv7EW/CG3XFRsG+1UXCyEIct2L7rzvC7r7+jjS4s\ngmV3Civ1sckGMwikLzxFtUZ1LUBakZp/mmipIzxcHOeBsRdHei8BFvMNqveg1JpO\ncY/Fp+wEkSNLhfkb/IXRw0iwFalBRnyo4BJbLu8CgYBrQ7E6OB169jxHotNzGv2K\npssO3rJKgFev1ZZVT7jJe4Dasrfi7zT5RcQ9EYSGrZD1aiYIVM2zEcUGUfayDXHy\n/vSlXOdc2ylhV9P9KLtYiyTEbBdwAf7ZVJu+465VTqol6t/WaTJ4Z15gAx/NlK+i\nKzgAGf2Uyy78k3NDCE67IQKBgFwM0pUUEKEbLDhi4uRiWsTcep4C/gTGHIGvJ85r\nH6NZNI7BS6GyH/qOFjAO1CYfpB4yWhed2Om/PQw61sa5HYZ7yEyQuvG7UC7JsHsy\nfKZuZmkv5IIPkq8gRZv5OuzFS/fI5GmGhNdVV+OWdkVLyK4Do1/L1guTt9QfCm+4\nrioPAoGBALGr8aUAbz/A611M/bLnk04UYfV+M34/hCf6/rKiBHdQoIHOriSC9Nv7\nyhE5axTdmIWMxfbyb3vHJ5MizZkD/Qj0VDuMkyS2+3TepI6tySQE3YQeWnCMJI9i\nuoCZ31GBui4+W5udbx8NOVsJfXUQn/OAoOn6WuMNPdgB45KXcktj\n-----END RSA PRIVATE KEY-----\n" -private_key33= "-----BEGIN RSA PRIVATE KEY-----\nMIIEogIBAAKCAQEAq/wUH8N+5fzj3hArKY7ChC591R/uKyeNM/BbsR2OGxO5F1CE\nozy6thtPult96Gm9oK3sMpLdYCze2YgozgteFO1Ft0o1GEJ1A4SinOKzeixLpFy0\n5N9t+iz7Xa7jC/1E3uy/s2WvSYCS9NnK2Uj3DQOH8BUWfkvyTtt91a2pplbPCV3T\nw1PykAcDWIFXVJJCMtYd2x+DukSWKHRsYbBCMtVZhEVuKmTE3FBTDVu9sN3b7uLL\n5RzHUg13QZZr9OvMNR3nUZl6yDxw+wD4anDrtpL9C+tFjhMyqsyYpYWwcJm65YiD\ny7Ps24IdcLB4iOxJE91fu+MnicvyBrtEjoBP/wIDAQABAoIBAAcKc9x1CW3q8300\n1j+GS6pTqO0fuIVlwh8dOPPATQAIx6wPrM5t/wrThWkQs8/e/Fdmp2POpWd5jsoD\nDACbcIeUyyTc0d2jYtz5AhtAIK7gv1wEO5efGgaC7ut/7GWiQb6KnLKAeDOfIuUJ\nQYexuAN9YIRQqLIU89+MltM3n9liZTMuPWRFJcitaDytXa10TCe5RUqHGZf49pi7\njCgk0x7jDYqbIzsqOu741P8My/gkAjKPkRnjaj3o6MrwHzIlc4t/6mKbaPnywywk\n6roYMqmytgueA9wxFcj74ekBQAaXsu4xRkbZXxjcBtIvTId5IHHK5Z/r3fgE9K3J\nOuzzJ1kCgYEA3uu/pUjJbKegOsgSdu3cO/NvRV2YsRD4NUgtiMCEakE4VQXRK5pf\nV8xqQeH/rLjZf5aP5xe8n25krh/c+m0ezOMyu5MmhoxaWCPWIezsaKJXOcvsOxIu\n2sJ9GRMXabyuDuSdL7ZGYMpLhRclXYLyPCz7wzN445IluTHuD3lJ2qUCgYEAxYFh\ncVD73yNZn9BN1DSGWpfPtLqOKIdG+xi/ypCSGpJG0QCJRFi7R1qJOxFtJNI8DRiD\nZapPEGLVd/KY5NzBGZBfNQt4DQH9qR4l43c6NNkisWA9rvXvCDqXKmBq7wfpnkYr\n4Ul2hXYmsPJjP8e0BfG54PaSu3BDBMJMtcgDktMCgYBvzyDdnwdgVyc3tHgGbMFk\n1HHAAfT/ArrrxpsIFz+TJ8lAY92JGDGwENhO2TLrCAAXTYY5657w/GbFKzgj5y1m\nqKIekOzm2WjLApZ5h6L/zEUhuRVwf2s+0AP82qWIpFlNIP9yGeNs0qpUQ8q6/13O\nLuXL/3on8nq3S8LSwgv3/QKBgDfM+g7d5ouAnU29uH9/54Wo5pIVMxzYO4Gt2GIO\nvnirYz6hfCbHOwJJ3gPGRKPmkfjROC59E6F5iv48mF3w0M28MGn4N47VRSmGzwWZ\nJeTQhDDBFCxeZ45Xn2Xln9Cw15xUDwmzi7zhSMUtdkUK0x3q0a1xfLtgWE775lhl\njjzpAoGAdUXFW1elfjXpfIYZf7vUV7MPquKL7qAcopd96XBszhOn7g+ibzem+wgt\n1UTSeOBESYANHeJk2MuWPSRXk/FlQETVIcPAEp0kxbwQE+7YEdrMVeDcIe5lPwGD\n+WuS3kg0MPgUrXZXn74gcwWmSIOyHfqXULqOxWE25uU2icdV+2w=\n-----END RSA PRIVATE KEY-----\n" -private_key = OpenSSL::PKey::RSA.new(private_key33) -# puts private_key.to_json +# private_pem = File.read("/Users/xxq/Documents/gitlink-webhook.2022-06-09.private-key.pem") +private_pem = "-----BEGIN RSA PRIVATE KEY----- +MIIEowIBAAKCAQEAy3rJwhzC9K5f4Rc6KwYQKvdsUsbzrKdENBCjGq0kZ8LJltw+ +TRuLVp0hwrWXS9msadjBnzatYneBrqnggj87pU0Mf/f6KkTmIsFH2gDKNMN6hRg/ +JW5XXveexGa9dZIQHPKOmp9dC+YpLHOPRO0NsYJM/JoQ4rWRhtMvq0zR/fJDuXyt +xLehfH4N4ppVbdRGaK+FIKNCjHTmL/3jZ0b2J9D4Al9R5QWlEmRPa4ZFCOZNUMXK +nplNu2FE/ZjyKjE+f0MAn8hcSVR25XiQZ6StnxdyPvhXYNNU7yVJGTfCK/oTchTr +Tfk4bKIkct38datffjlhKM45VabhUfIStNr5uwIDAQABAoIBADSMgGBmBx8jjVVX +J0mHJlPCVDJIeROkmuOLTGQORPGbB26zcE9/houWxuo+9VS8YV9wgAh7GWntjQsr +ifR5GhFFha3iv7N82aYuHj05qP7ZYOHQcjZbearn7hOwqMsdLpYbOiLKd0Akb4uw +SFa3laq7CODPdP7nfy6/iXcGvtCC84E8XwDuUcFbzX8lLq0UI6HvdnySYOvglO3P +txqr76dc61nLEIu945uVKndzu65sWRfC397JG+hgYFUwikbiFPAVVH4jsiCzMAW0 +oaTp6zQiE+h7HTGGHhnxFmnynmuq01E+wfxNvf8NHteBIMJA8g/gGHdpp+8E85V7 +bcF8+fECgYEA5cs8nZHfrTdjqZB6vgY1sCVsuuHtmEACu3zbJu9dr21ps6bomnDW +Lw9Dx4tYSHPcL3zlu913qvXCnXsUGtjKeIVTHCdnwCnDTEam6GsDZab9zcmJ8Gkn +wqsjr/Cy7pjwxqT3nFRUGaJmrFUUfPQuNmSYWQbRiRIQirGY2JlZLvMCgYEA4q9Q +j8cwq5i1blWuyam8bx3efHBHMiMpJL/clc03//ddpsiae8GXZgRySJx9YPAYS+X/ +ApVfnB/en+xidCIg8P2rRjRW/GgW3Y6rjLUMIFMD/0ObezX/dp2AVHUdOdlZ7z+k +4Ba8TZ8u5sfUO7USTxFl+fextLdBDSetOw/GDBkCgYAsYSjuwYpyWJ0t1VJvOqHJ +yCCMoy+Q1OPyM7XbeiUcyUO9x4FquloTMp6DfjzpmT6wCS4RLz96TAZvBaMnYDES +P6WCbXXTHf2y0H5RqsE4M50WzlKOlLByHz1AMHtOK0ltA9UyYvLvFHdB1xii3UHD +jYACyZdUIqIBNzVut4cK0wKBgBNbHOnp/EHqvDM7pb0afTiPuFuvyqSBVBYLO+6e +o1V77cc8AdTnZuITJx8EHcCVP73bWbcCwjM2lW/aY12/PEjXoDRSa8sJqEoq0IMn +Qm3QKNs3DqOqrLGYKUkM5v31jTRcnttzlYibOwoBriGbCIEv3yFFASuJKkjRRn1w +j1yhAoGBALqwZzRAle7t2jEWOyLaJeHUoSiZJv5dHOMRog7k5H24uTEKf3JCovQO +wZd4cIA4oXD/3b5cK3H2e5YjhBunsMRhRBLgz8FD4y69cKxbcgPvtjhkwYRB0/cy +21dHe2o7HfuZgUuh0kOlT0e326gQPIIlwuCBEAq6LzWrg8nd9Loz +-----END RSA PRIVATE KEY-----" +private_key = OpenSSL::PKey::RSA.new(private_pem) # Generate the JWT payload = { @@ -16,27 +39,15 @@ payload = { # JWT expiration time (10 minute maximum) exp: Time.now.to_i + (10 * 60), # GitHub App's identifier - iss: "782" + iss: "803" } jwt = JWT.encode(payload, private_key, "RS256") puts jwt -# puts OpenSSL::PKey::RSA.new(private_key33).public_key.to_s -# -rsa_private = OpenSSL::PKey::RSA.new(private_key33) -rsa_public = rsa_private.public_key - -# decoded_token = JWT.decode jwt, nil, false -begin - decoded_token = JWT.decode jwt, rsa_private, true, { algorithm: 'RS256' } -rescue JWT::DecodeError - puts "jwt is not mmmmmm" -end -# -puts decoded_token[0] -puts decoded_token[0]["iss"] -# serialized_private_key = OpenSSL::PKey::RSA::generate(2048).to_s +decoded_token = JWT.decode "eyJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE2ODA1OTkzNDAsImV4cCI6MTY4MDYwMDAwMCwiaXNzIjoiODAzIn0.wOCCMVbrulTVCIKDvmLtxCkTLtWJMGmY2mIZgfdJcKcixqZek1y_9YD7wF07wqP6qTjQaNiSDjdJSDGzO_Qi3qQT_2BaR6EWBUIcbaNz5GTHKLcOW4SFWj13OFJwjom6egz489b6qA3MPXmliWYR6F5zlLu1jlXjaWVvUZAy0AuAdmWiSocdjurt_giEIDefiRcPu_NbccWG-mAwa9wV9ja2PoZUJyHlzXR6rioLIO1rtw5bIX3E4YNPde9EkEK1eYLmedmhKfwlgX2CgdGodSHPg5Vro09XWiGaJkBwoi1T41BLVsb5hxqQc3DLrz1ZFFY1vXEkxIw4BIXitpk3kg", nil, false +puts decoded_token +puts Time.now.to_i - 60 - decoded_token[0]["exp"].to_i > 0 From bbc113ec1bd4c10c1775d27662b394792e19afb1 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 17:39:12 +0800 Subject: [PATCH 282/438] =?UTF-8?q?=E5=88=A0=E9=99=A4log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index 85e2da5cb..f4640fb61 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -115,7 +115,6 @@ class InstallationsController < ApplicationController header = request.authorization pattern = /^Bearer /i token = header.gsub(pattern, "") - Rails.logger.info("request.authorization==#{request.authorization}") decoded_token = JWT.decode token, nil, false # 前面已验证token有效期和正确性 decoded_token[0]["iss"] From 13148890ecb4fb3c9dc73d1cbf87a67f53783c13 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 17:40:53 +0800 Subject: [PATCH 283/438] =?UTF-8?q?token=E8=A7=A3=E5=AF=86=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index f4640fb61..807554fb1 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -19,7 +19,7 @@ class InstallationsController < ApplicationController def repositories # 与github差异,所以取安装用户和bot对应所有的仓库 # 必须使用access_tokens获取到bot的token才能查询 - tip_exception "Token无效" if current_user.platform != "bot" + tip_exception "无效Token" if current_user.platform != "bot" bot = Bot.find_by(uid: current_user.id) @install_bots = BotInstall.where(bot_id: bot.id).where(installer_id: params[:id]) end @@ -118,6 +118,9 @@ class InstallationsController < ApplicationController decoded_token = JWT.decode token, nil, false # 前面已验证token有效期和正确性 decoded_token[0]["iss"] + rescue JWT::DecodeError + Rails.logger.error "jwt token decode error:#{token}" + tip_exception("无效Token") end end From fccd6bb950e215eb74274e671c397e8430343f1c Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 17:45:45 +0800 Subject: [PATCH 284/438] =?UTF-8?q?jwt=5Ftoken=E6=9C=89=E6=95=88=E6=9C=9F?= =?UTF-8?q?=E5=BB=B6=E9=95=BF=E5=88=B010=E5=88=86=E9=92=9F=EF=BC=8C?= =?UTF-8?q?=E9=98=B2=E6=AD=A2=E6=9C=8D=E5=8A=A1=E5=99=A8=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E8=AF=AF=E5=B7=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/bot.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/bot.rb b/app/models/bot.rb index 2098ac1e2..13ac70a78 100644 --- a/app/models/bot.rb +++ b/app/models/bot.rb @@ -36,7 +36,7 @@ class Bot < ApplicationRecord def self.decode_jwt_token(token) decoded_token = JWT.decode token, nil, false - return [nil, "Token已过期"] if Time.now.to_i - 60 - decoded_token[0]["exp"].to_i > 0 + return [nil, "Token已过期"] if Time.now.to_i - 10*60 - decoded_token[0]["exp"].to_i > 0 bot = Bot.find_by(id: decoded_token[0]["iss"]) return [nil, "Token不存在"] if bot.blank? rsa_private = OpenSSL::PKey::RSA.new(bot.private_key) From b336a1f33421b3d6a91a2e436a5ad2973b4a091f Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 21 Mar 2023 15:37:26 +0800 Subject: [PATCH 285/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=90=9C=E7=B4=A2=E6=A0=87=E7=AD=BE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/project_topics_controller.rb | 31 +++++++++++++++++++ app/controllers/projects_controller.rb | 2 +- app/models/concerns/matchable.rb | 1 + app/models/project.rb | 2 ++ app/models/project_topic.rb | 25 +++++++++++++++ app/models/project_topic_ralate.rb | 22 +++++++++++++ app/models/user.rb | 1 + app/queries/projects/list_query.rb | 7 ++++- .../api/v1/project_topics/index.json.jbuilder | 4 +++ app/views/projects/index.json.jbuilder | 3 ++ config/routes/api.rb | 3 +- .../20230321022108_create_project_topics.rb | 19 ++++++++++++ 12 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 app/controllers/api/v1/project_topics_controller.rb create mode 100644 app/models/project_topic.rb create mode 100644 app/models/project_topic_ralate.rb create mode 100644 app/views/api/v1/project_topics/index.json.jbuilder create mode 100644 db/migrate/20230321022108_create_project_topics.rb diff --git a/app/controllers/api/v1/project_topics_controller.rb b/app/controllers/api/v1/project_topics_controller.rb new file mode 100644 index 000000000..3a23fde4a --- /dev/null +++ b/app/controllers/api/v1/project_topics_controller.rb @@ -0,0 +1,31 @@ +class Api::V1::ProjectTopicsController < Api::V1::BaseController + + def index + @project_topics = ProjectTopic + @project_topics = @project_topics.ransack(name_cont: params[:keyword]) if params[:keyword].present? + @project_topics = @project_topics.includes(:projects) + @project_topics = kaminary_select_paginate(@project_topics) + end + + def create + ActiveRecord::Base.transaction do + @project = Project.find_by_id(create_params[:project_id]) + return render_not_found unless @project.present? + return render_error("请输入项目搜索标签名称.") unless create_params[:name].present? + + @project_topic = ProjectTopic.find_or_create_by!(name: create_params[:name].downcase) + @project_topic_ralate = @project_topic.project_topic_ralates.find_or_create_by!(project_id: create_params[:project_id]) + + if @project_topic.present? && @project_topic_ralate.present? + render_ok + else + render_error("项目关联搜索标签失败.") + end + end + end + + private + def create_params + params.permit(:project_id, :name) + end +end \ No newline at end of file diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 2d9ddc014..7639f2677 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -34,7 +34,7 @@ class ProjectsController < ApplicationController def index scope = current_user.logged? ? Projects::ListQuery.call(params, current_user.id) : Projects::ListQuery.call(params) - @projects = kaminari_paginate(scope.includes(:project_category, :project_language, :repository, :project_educoder, :owner, :project_units)) + @projects = kaminari_paginate(scope.includes(:project_category, :project_language, :repository, :project_educoder, :owner, :project_units, :project_topics)) # @projects = paginate scope.includes(:project_category, :project_language, :repository, :project_educoder, :owner, :project_units) category_id = params[:category_id] diff --git a/app/models/concerns/matchable.rb b/app/models/concerns/matchable.rb index 5c013f951..0640e7c74 100644 --- a/app/models/concerns/matchable.rb +++ b/app/models/concerns/matchable.rb @@ -6,6 +6,7 @@ module Matchable scope :with_project_language, ->(language_id) { where(project_language_id: language_id) unless language_id.blank? } scope :with_project_type, ->(project_type) { where(project_type: project_type) if Project.project_types.include?(project_type) } scope :by_name_or_identifier, ->(search) { where("name like :search or identifier LIKE :search", :search => "%#{search.split(" ").join('|')}%") unless search.blank? } + scope :with_project_topic, ->(topic_id) {joins(:project_topics).where(project_topics: {id: topic_id}) unless topic_id.blank?} end end diff --git a/app/models/project.rb b/app/models/project.rb index 54d6ac520..555269e5e 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -126,6 +126,8 @@ class Project < ApplicationRecord has_many :webhooks, class_name: "Gitea::Webhook", primary_key: :gpid, foreign_key: :repo_id has_many :user_trace_tasks, dependent: :destroy has_many :project_invite_links, dependent: :destroy + has_many :project_topic_ralates, dependent: :destroy + has_many :project_topics, through: :project_topic_ralates after_create :incre_user_statistic, :incre_platform_statistic after_save :check_project_members before_save :set_invite_code, :reset_unmember_followed, :set_recommend_and_is_pinned, :reset_cache_data diff --git a/app/models/project_topic.rb b/app/models/project_topic.rb new file mode 100644 index 000000000..94c9df9c7 --- /dev/null +++ b/app/models/project_topic.rb @@ -0,0 +1,25 @@ +# == Schema Information +# +# Table name: project_topics +# +# id :integer not null, primary key +# user_id :integer +# name :string(255) +# position :integer default("0") +# projects_count :integer default("0") +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_project_topics_on_user_id (user_id) +# + +class ProjectTopic < ApplicationRecord + + belongs_to :user, optional: true + has_many :project_topic_ralates, dependent: :destroy + has_many :projects, through: :project_topic_ralates + + validates :name, uniqueness: { case_sensitive: false } +end diff --git a/app/models/project_topic_ralate.rb b/app/models/project_topic_ralate.rb new file mode 100644 index 000000000..d8638699f --- /dev/null +++ b/app/models/project_topic_ralate.rb @@ -0,0 +1,22 @@ +# == Schema Information +# +# Table name: project_topic_ralates +# +# id :integer not null, primary key +# project_topic_id :integer +# project_id :integer +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_project_topic_ralates_on_project_id (project_id) +# index_project_topic_ralates_on_project_topic_id (project_topic_id) +# + +class ProjectTopicRalate < ApplicationRecord + + belongs_to :project_topic, counter_cache: :projects_count + belongs_to :project + +end diff --git a/app/models/user.rb b/app/models/user.rb index 1818bccb1..c3c62f9eb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -182,6 +182,7 @@ class User < Owner has_many :assigned_issues, through: :issue_assigners, source: :issue has_many :issue_participants, foreign_key: :participant_id has_many :participant_issues, through: :issue_participants, source: :issue + has_many :project_topics # Groups and active users scope :active, lambda { where(status: [STATUS_ACTIVE, STATUS_EDIT_INFO]) } scope :like, lambda { |keywords| diff --git a/app/queries/projects/list_query.rb b/app/queries/projects/list_query.rb index 2b048bd87..72776f7a2 100644 --- a/app/queries/projects/list_query.rb +++ b/app/queries/projects/list_query.rb @@ -3,7 +3,7 @@ class Projects::ListQuery < ApplicationQuery attr_reader :params, :current_user_id - sort_columns :updated_on, :created_on, :forked_count, :praises_count, default_by: :updated_on, default_direction: :desc + sort_columns :updated_on, :created_on, :forked_count, :praises_count, default_by: :updated_on, default_direction: :desc, default_table: 'projects' def initialize(params, current_user_id=nil) @params = params @@ -32,6 +32,7 @@ class Projects::ListQuery < ApplicationQuery collection = by_project_type(collection) collection = by_project_category(collection) collection = by_project_language(collection) + collection = by_project_topic(collection) collection end @@ -74,6 +75,10 @@ class Projects::ListQuery < ApplicationQuery (params[:pinned].present? && params[:category_id].present?) ? items.pinned : items end + def by_project_topic(items) + items.with_project_topic(params[:topic_id]) + end + # 优化排序 def optimize_sorting(relations, sort_by) if sort_by == "updated_on" diff --git a/app/views/api/v1/project_topics/index.json.jbuilder b/app/views/api/v1/project_topics/index.json.jbuilder new file mode 100644 index 000000000..5a39aaa56 --- /dev/null +++ b/app/views/api/v1/project_topics/index.json.jbuilder @@ -0,0 +1,4 @@ +json.total_count @project_topics.total_count +json.project_topics @project_topics.each do |topic| + json.(topic, :id, :name, :projects_count) +end \ No newline at end of file diff --git a/app/views/projects/index.json.jbuilder b/app/views/projects/index.json.jbuilder index 31d0db9c5..d3b96ab18 100644 --- a/app/views/projects/index.json.jbuilder +++ b/app/views/projects/index.json.jbuilder @@ -48,4 +48,7 @@ json.projects @projects do |project| json.name project.project_language.name end end + json.topics project.project_topics.each do |topic| + json.(topic, :id, :name) + end end diff --git a/config/routes/api.rb b/config/routes/api.rb index 6e688a632..799783f0d 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -2,7 +2,7 @@ defaults format: :json do namespace :api do namespace :v1 do scope ':owner' do - resource :users, path: '/', only: [:show, :update, :edit, :destroy] do + resource :users, path: '/', only: [:update, :edit, :destroy] do collection do get :send_email_vefify_code post :check_password @@ -97,6 +97,7 @@ defaults format: :json do end resources :projects, only: [:index] + resources :project_topics, only: [:index, :create] end diff --git a/db/migrate/20230321022108_create_project_topics.rb b/db/migrate/20230321022108_create_project_topics.rb new file mode 100644 index 000000000..07a03e20d --- /dev/null +++ b/db/migrate/20230321022108_create_project_topics.rb @@ -0,0 +1,19 @@ +class CreateProjectTopics < ActiveRecord::Migration[5.2] + def change + create_table :project_topics do |t| + t.references :user + t.string :name + t.integer :position, default: 0 + t.integer :projects_count, default: 0 + + t.timestamps + end + + create_table :project_topic_ralates do |t| + t.belongs_to :project_topic, index: true + t.belongs_to :project, index: true + + t.timestamps + end + end +end From 1f7a1ce73d8b2d406c728893502669e95d55c611 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 6 Apr 2023 14:23:07 +0800 Subject: [PATCH 286/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=90=9C=E7=B4=A2=E6=A0=87=E7=AD=BE=E5=8F=AF=E5=9C=A8?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E8=AE=BE=E7=BD=AE=E6=8E=A5=E5=8F=A3=E6=9B=B4?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 6 ++++++ app/queries/projects/list_my_query.rb | 2 +- app/views/projects/_project_detail.json.jbuilder | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 7639f2677..9586c1e91 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -129,6 +129,12 @@ class ProjectsController < ApplicationController # TODO: # 临时特殊处理修改website、lesson_url操作方法 if project_params.has_key?("website") + if params[:project_topic_names].present? && params[:project_topic_names].is_a?(Array) + params[:project_topic_names].each do |name| + project_topic = ProjectTopic.find_or_create_by!(name: name.downcase) + project_topic.project_topic_ralates.find_or_create_by!(project: @project) + end + end @project.update(project_params) elsif project_params.has_key?("default_branch") @project.update(project_params) diff --git a/app/queries/projects/list_my_query.rb b/app/queries/projects/list_my_query.rb index acea71f31..c265cafed 100644 --- a/app/queries/projects/list_my_query.rb +++ b/app/queries/projects/list_my_query.rb @@ -61,7 +61,7 @@ class Projects::ListMyQuery < ApplicationQuery keywords = params[:search].to_s.each_char.select { |c| c.bytes.first < 240 }.join('') q = projects.ransack(name_or_identifier_cont: keywords) - scope = q.result.includes(:project_category, :project_language,:owner, :repository, :has_pinned_users) + scope = q.result.includes(:project_category, :project_language,:owner, :repository, :has_pinned_users, :project_topics) sort = Project.column_names.include?(params[:sort_by]) ? params[:sort_by] : "updated_on" sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : "desc" diff --git a/app/views/projects/_project_detail.json.jbuilder b/app/views/projects/_project_detail.json.jbuilder index c9e03fa22..c5b071abf 100644 --- a/app/views/projects/_project_detail.json.jbuilder +++ b/app/views/projects/_project_detail.json.jbuilder @@ -50,3 +50,6 @@ json.language do json.name project.project_language.name end end +json.topics project.project_topics.each do |topic| + json.(topic, :id, :name) +end \ No newline at end of file From 08f89fd113c4a2e72e5ee05632299084744dc4be Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 6 Apr 2023 14:31:30 +0800 Subject: [PATCH 287/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E6=96=B0=E5=A2=9E=E9=A1=B9=E7=9B=AE=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/projects/update.json.jbuilder | 5 ++++- app/views/repositories/detail.json.jbuilder | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/views/projects/update.json.jbuilder b/app/views/projects/update.json.jbuilder index 01e70377e..3dd8c3cda 100644 --- a/app/views/projects/update.json.jbuilder +++ b/app/views/projects/update.json.jbuilder @@ -6,4 +6,7 @@ json.project_category_id @project.project_category_id json.project_language_id @project.project_language_id json.is_public @project.is_public json.website @project.website -json.lesson_url @project.lesson_url \ No newline at end of file +json.lesson_url @project.lesson_url +json.topics @project.project_topics.each do |topic| + json.(topic, :id, :name) +end \ No newline at end of file diff --git a/app/views/repositories/detail.json.jbuilder b/app/views/repositories/detail.json.jbuilder index 508d4c658..1164f4030 100644 --- a/app/views/repositories/detail.json.jbuilder +++ b/app/views/repositories/detail.json.jbuilder @@ -21,6 +21,9 @@ json.mirror_url @project&.repository.remote_mirror_url json.mirror @project&.repository.mirror_url.present? json.type @project.numerical_for_project_type json.open_devops @project.open_devops? +json.topics @project.project_topics.each do |topic| + json.(topic, :id, :name) +end unless @project.common? json.mirror_status @repository.mirror_status From 7a6d549fa04c63b7a7bafdec2b2081ab2ca63c91 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 6 Apr 2023 15:40:01 +0800 Subject: [PATCH 288/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=90=9C=E7=B4=A2=E6=A0=87=E7=AD=BE=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/project_topics_controller.rb | 15 +++++++++++++++ app/controllers/projects_controller.rb | 1 + config/routes/api.rb | 4 ++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/project_topics_controller.rb b/app/controllers/api/v1/project_topics_controller.rb index 3a23fde4a..5d353fbf4 100644 --- a/app/controllers/api/v1/project_topics_controller.rb +++ b/app/controllers/api/v1/project_topics_controller.rb @@ -24,6 +24,21 @@ class Api::V1::ProjectTopicsController < Api::V1::BaseController end end + def destroy + ActiveRecord::Base.transaction do + @project = Project.find_by_id(create_params[:project_id]) + return render_not_found unless @project.present? + + @project_topic = ProjectTopic.find_by_id(params[:id]) + @project_topic_ralate = @project_topic.project_topic_ralates.find_by(project_id: @project.id) + if @project_topic_ralate.destroy! + render_ok + else + render_error("项目取消关联搜索标签失败.") + end + end + end + private def create_params params.permit(:project_id, :name) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 9586c1e91..652e80ec6 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -130,6 +130,7 @@ class ProjectsController < ApplicationController # 临时特殊处理修改website、lesson_url操作方法 if project_params.has_key?("website") if params[:project_topic_names].present? && params[:project_topic_names].is_a?(Array) + ProjectTopicRalate.where(project: @project).destroy_all params[:project_topic_names].each do |name| project_topic = ProjectTopic.find_or_create_by!(name: name.downcase) project_topic.project_topic_ralates.find_or_create_by!(project: @project) diff --git a/config/routes/api.rb b/config/routes/api.rb index 799783f0d..a1945ab43 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -20,7 +20,7 @@ defaults format: :json do scope ':repo' do # projects - resource :projects, path: '/', only: [:show, :update, :edit, :destroy] do + resource :projects, path: '/', only: [:show, :update, :edit] do collection do get :compare get :blame @@ -97,7 +97,7 @@ defaults format: :json do end resources :projects, only: [:index] - resources :project_topics, only: [:index, :create] + resources :project_topics, only: [:index, :create, :destroy] end From 63196e018a3874641f01ac73d8e8f82fe3b38d92 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 6 Apr 2023 16:47:23 +0800 Subject: [PATCH 289/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E9=A1=B9=E7=9B=AE=E6=A0=87=E8=AF=86=E6=AD=A3=E5=88=99?= =?UTF-8?q?=E8=A7=84=E5=88=99=E4=BB=A5=E5=8F=8A=E5=B8=A6.=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E6=97=A0=E6=B3=95=E6=AD=A3=E5=B8=B8=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/libs/custom_regexp.rb | 2 +- config/routes.rb | 4 ++-- config/routes/api.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/libs/custom_regexp.rb b/app/libs/custom_regexp.rb index 889da4df8..1bfeb4b71 100644 --- a/app/libs/custom_regexp.rb +++ b/app/libs/custom_regexp.rb @@ -10,6 +10,6 @@ module CustomRegexp IP = /^((\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3}(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])$/ URL_REGEX = /\A(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?\z/i - REPOSITORY_NAME_REGEX = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾 + REPOSITORY_NAME_REGEX = /^[a-zA-Z0-9][a-zA-Z0-9\-\_\.]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾 MD_REGEX = /^.+(\.[m|M][d|D])$/ end diff --git a/config/routes.rb b/config/routes.rb index 0d29e403f..7e69c2e38 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -451,7 +451,7 @@ Rails.application.routes.draw do namespace :traces do resources :trace_users, only: [:create] - scope "/:owner/:repo" do + scope "/:owner/:repo", constraints: { repo: /[^\/]+/ } do resource :projects, path: '/', only: [:index] do member do post :tasks @@ -464,7 +464,7 @@ Rails.application.routes.draw do end # Project Area START - scope "/:owner/:repo" do + scope "/:owner/:repo",constraints: { repo: /[^\/]+/ } do scope do get( '/activity', diff --git a/config/routes/api.rb b/config/routes/api.rb index 6e688a632..f39fa76c5 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -18,7 +18,7 @@ defaults format: :json do resources :feedbacks, only: [:create] end - scope ':repo' do + scope ':repo', constraints: { repo: /[^\/]+/ } do # projects resource :projects, path: '/', only: [:show, :update, :edit, :destroy] do collection do From 43292362376d86823157ca8c5ad1d30c2f381aa8 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 7 Apr 2023 10:32:57 +0800 Subject: [PATCH 290/438] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9Arouter?= =?UTF-8?q?=E5=8C=B9=E9=85=8D.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/routes.rb | 4 ++-- config/routes/api.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 7e69c2e38..2206f2846 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -451,7 +451,7 @@ Rails.application.routes.draw do namespace :traces do resources :trace_users, only: [:create] - scope "/:owner/:repo", constraints: { repo: /[^\/]+/ } do + scope "/:owner/:repo", constraints: { repo: /[^\/|.json]+/ } do resource :projects, path: '/', only: [:index] do member do post :tasks @@ -464,7 +464,7 @@ Rails.application.routes.draw do end # Project Area START - scope "/:owner/:repo",constraints: { repo: /[^\/]+/ } do + scope "/:owner/:repo",constraints: { repo: /[^\/|.json]+/ } do scope do get( '/activity', diff --git a/config/routes/api.rb b/config/routes/api.rb index f39fa76c5..ccc80abe3 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -18,7 +18,7 @@ defaults format: :json do resources :feedbacks, only: [:create] end - scope ':repo', constraints: { repo: /[^\/]+/ } do + scope ':repo', constraints: { repo: /[^\/|.json]+/ } do # projects resource :projects, path: '/', only: [:show, :update, :edit, :destroy] do collection do From 39a851b74bfebd0ff27254b8ec1b27aaf441f81e Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 7 Apr 2023 10:35:44 +0800 Subject: [PATCH 291/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/routes.rb | 4 ++-- config/routes/api.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 2206f2846..7e69c2e38 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -451,7 +451,7 @@ Rails.application.routes.draw do namespace :traces do resources :trace_users, only: [:create] - scope "/:owner/:repo", constraints: { repo: /[^\/|.json]+/ } do + scope "/:owner/:repo", constraints: { repo: /[^\/]+/ } do resource :projects, path: '/', only: [:index] do member do post :tasks @@ -464,7 +464,7 @@ Rails.application.routes.draw do end # Project Area START - scope "/:owner/:repo",constraints: { repo: /[^\/|.json]+/ } do + scope "/:owner/:repo",constraints: { repo: /[^\/]+/ } do scope do get( '/activity', diff --git a/config/routes/api.rb b/config/routes/api.rb index ccc80abe3..f39fa76c5 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -18,7 +18,7 @@ defaults format: :json do resources :feedbacks, only: [:create] end - scope ':repo', constraints: { repo: /[^\/|.json]+/ } do + scope ':repo', constraints: { repo: /[^\/]+/ } do # projects resource :projects, path: '/', only: [:show, :update, :edit, :destroy] do collection do From eabf40468291e1bda4ab2cec6050cfeac51fc212 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 7 Apr 2023 10:57:13 +0800 Subject: [PATCH 292/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E9=A1=B9=E7=9B=AE=E6=8E=92=E9=99=A4.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/project.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 54d6ac520..4a356cbc7 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -380,7 +380,13 @@ class Project < ApplicationRecord user = Owner.find_by_login namespace_path user = User.new(login: namespace_path) if user.nil? - project = user&.projects&.find_by(identifier: identifier) || Project.find_by(identifier: "#{namespace_path}/#{identifier}") + if identifier.end_with?('.json') + project = user&.projects&.find_by(identifier: identifier) || Project.find_by(identifier: "#{namespace_path}/#{identifier}") + identifier = identifier.sub(/.*\K.json/, '') + project = user&.projects&.find_by(identifier: identifier) || Project.find_by(identifier: "#{namespace_path}/#{identifier}") + else + project = user&.projects&.find_by(identifier: identifier) || Project.find_by(identifier: "#{namespace_path}/#{identifier}") + end return nil if project.blank? [project, user] From d8eba81afd78783598f0b30285260d12b84c956d Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 7 Apr 2023 11:13:17 +0800 Subject: [PATCH 293/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Awebhook?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E6=95=B0=E6=8D=AE=E7=89=B9=E6=AE=8A=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../projects/webhooks/_simple_gitea_detail.json.jbuilder | 7 ++++++- app/views/projects/webhooks/edit.json.jbuilder | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/views/api/v1/projects/webhooks/_simple_gitea_detail.json.jbuilder b/app/views/api/v1/projects/webhooks/_simple_gitea_detail.json.jbuilder index 96c9eac12..09f9565a4 100644 --- a/app/views/api/v1/projects/webhooks/_simple_gitea_detail.json.jbuilder +++ b/app/views/api/v1/projects/webhooks/_simple_gitea_detail.json.jbuilder @@ -3,7 +3,12 @@ json.type webhook["type"] json.content_type webhook['config']['content_type'] json.http_method webhook['config']['http_method'] json.url webhook['config']['url'] -json.events webhook['events'] +event = webhook.events +if event["send_everything"] + json.events event["events"].keys.collect{|i| %w(pull_request issues).include?(i) ? i + "_only" : i} +else + json.events event["events"].select{|k, v| v}.keys.collect{|i| %w(pull_request issues).include?(i) ? i + "_only" : i} +end json.active webhook['active'] json.branch_filter webhook['branch_filter'] json.created_at format_time(webhook['created_at'].to_time) \ No newline at end of file diff --git a/app/views/projects/webhooks/edit.json.jbuilder b/app/views/projects/webhooks/edit.json.jbuilder index c54d10306..4085e2a64 100644 --- a/app/views/projects/webhooks/edit.json.jbuilder +++ b/app/views/projects/webhooks/edit.json.jbuilder @@ -5,7 +5,7 @@ json.create_time Time.at(@webhook.created_unix).strftime("%Y-%m-%d %H:%M:%S") event = @webhook.events json.branch_filter event["branch_filter"] if event["send_everything"] - json.events event["events"].keys.collect{|i| i == "pull_request" ? i + "_only" : i} + json.events event["events"].keys.collect{|i| %w(pull_request issues).include?(i) ? i + "_only" : i} else - json.events event["events"].select{|k, v| v}.keys.collect{|i| i == "pull_request" ? i + "_only" : i} + json.events event["events"].select{|k, v| v}.keys.collect{|i| %w(pull_request issues).include?(i) ? i + "_only" : i} end From 60b0ee6b28e9dac5479dd5e672f17626e81662bc Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 7 Apr 2023 11:27:19 +0800 Subject: [PATCH 294/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=A0=87=E8=AF=86=E6=8F=90=E7=A4=BA=E8=AF=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/forms/projects/create_form.rb | 2 +- app/forms/projects/migrate_form.rb | 2 +- app/forms/projects/update_form.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/forms/projects/create_form.rb b/app/forms/projects/create_form.rb index c51c2c60f..28cb296c0 100644 --- a/app/forms/projects/create_form.rb +++ b/app/forms/projects/create_form.rb @@ -3,7 +3,7 @@ class Projects::CreateForm < BaseForm :project_language_id, :ignore_id, :license_id, :private, :owner validates :user_id, :name, :repository_name, presence: true - validates :repository_name, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" } + validates :repository_name, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "项目标识只能包含数字,字母,下划线(_),中划线(-),英文句号(.),必须以数字和字母开头,不能以下划线/中划线开头和结尾" } validates :name, length: { maximum: 50 } validates :repository_name, length: { maximum: 100 } diff --git a/app/forms/projects/migrate_form.rb b/app/forms/projects/migrate_form.rb index ccd854478..c3684c2ef 100644 --- a/app/forms/projects/migrate_form.rb +++ b/app/forms/projects/migrate_form.rb @@ -3,7 +3,7 @@ class Projects::MigrateForm < BaseForm :project_language_id, :clone_addr, :private, :is_mirror, :auth_username, :auth_password, :owner validates :user_id, :name, :repository_name, :clone_addr, presence: true - validates :repository_name, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" } + validates :repository_name, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "项目标识只能包含数字,字母,下划线(_),中划线(-),英文句号(.),必须以数字和字母开头,不能以下划线/中划线开头和结尾" } validates :clone_addr, format: { with: CustomRegexp::URL_REGEX, multiline: true, message: "地址格式不正确" } validates :name, length: { maximum: 50 } validates :repository_name, length: { maximum: 100 } diff --git a/app/forms/projects/update_form.rb b/app/forms/projects/update_form.rb index a351420bc..2490fbed6 100644 --- a/app/forms/projects/update_form.rb +++ b/app/forms/projects/update_form.rb @@ -3,7 +3,7 @@ class Projects::UpdateForm < BaseForm validates :name, presence: true validates :name, length: { maximum: 50 } validates :description, length: { maximum: 200 } - validates :identifier, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" } + validates :identifier, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: '项目标识只能包含数字,字母,下划线(_),中划线(-),英文句号(.),必须以数字和字母开头,不能以下划线/中划线开头和结尾' } validate do check_project_category(project_category_id) From 5eff025f6232c63a533acce225d5c6c3e7e1b918 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 10 Apr 2023 15:09:41 +0800 Subject: [PATCH 295/438] =?UTF-8?q?=E7=BB=84=E7=BB=87=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E6=94=B9=E7=89=88=EF=BC=8C=E5=A2=9E=E5=8A=A0=E7=B2=BE=E9=80=89?= =?UTF-8?q?=E3=80=81=E6=96=B0=E9=97=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../is_pinned_projects_controller.rb | 56 +++++++++++++++ .../organizations/organizations_controller.rb | 68 ++++++++++++++++++- app/models/organization.rb | 22 +++--- app/models/organization_extension.rb | 3 + app/models/owner.rb | 1 + app/models/pinned_project.rb | 3 +- app/models/project.rb | 4 +- .../organizations/_detail.json.jbuilder | 7 +- config/routes.rb | 11 +++ ...063638_add_organization_extensions_news.rb | 7 ++ 10 files changed, 166 insertions(+), 16 deletions(-) create mode 100644 app/controllers/organizations/is_pinned_projects_controller.rb create mode 100644 db/migrate/20220727063638_add_organization_extensions_news.rb diff --git a/app/controllers/organizations/is_pinned_projects_controller.rb b/app/controllers/organizations/is_pinned_projects_controller.rb new file mode 100644 index 000000000..bcf659516 --- /dev/null +++ b/app/controllers/organizations/is_pinned_projects_controller.rb @@ -0,0 +1,56 @@ +class Organizations::IsPinnedProjectsController < Organizations::BaseController + before_action :load_organization + + def index + @is_pinned_projects = @organization.pinned_projects.order(position: :desc, created_at: :asc).includes(project: [:project_category, :project_language, :repository]).order(position: :desc) + @is_pinned_projects = kaminari_paginate(@is_pinned_projects) + end + + def pin + project_ids = params[:is_pinned_project_ids] || [] + @organization.is_pinned_project_ids = project_ids + + render_ok + rescue ActiveRecord::RecordNotFound => e + render_not_found + rescue Exception => e + uid_logger_error(e.message) + tip_exception(e.message) + end + + def update + @pinned_project = PinnedProject.find_by_id(params[:id]) + @pinned_project.attributes = pinned_project_params + if @pinned_project.save + render_ok + else + render_error + end + rescue Exception => e + uid_logger_error(e.message) + tip_exception(e.message) + end + + private + + def load_organization + @organization = Organization.find_by(login: params[:organization_id]) || Organization.find_by(id: params[:organization_id]) + return render_not_found("组织不存在") if @organization.nil? + return render_forbidden("没有查看组织的权限") if org_limited_condition || org_privacy_condition + end + + # def is_pinned_project_ids + # if params[:is_pinned_project_ids].present? + # return params[:is_pinned_project_ids].select { |id| @organization.full_member_projects.visible.pluck(:id).include?(id.to_i) } + # end + # if params[:is_pinned_project_id].present? + # return @organization.is_pinned_project_ids unless @organization.full_member_projects.visible.pluck(:id).include?(params[:is_pinned_project_id].to_i) + # return @organization.is_pinned_project_ids.include?(params[:is_pinned_project_id].to_i) ? @organization.is_pinned_project_ids : @organization.is_pinned_project_ids.push(params[:is_pinned_project_id].to_i) + # end + # end + + def pinned_project_params + params.require(:pinned_project).permit(:position) + end + +end \ No newline at end of file diff --git a/app/controllers/organizations/organizations_controller.rb b/app/controllers/organizations/organizations_controller.rb index 10aaa1ae6..0abd8d1ca 100644 --- a/app/controllers/organizations/organizations_controller.rb +++ b/app/controllers/organizations/organizations_controller.rb @@ -1,8 +1,8 @@ class Organizations::OrganizationsController < Organizations::BaseController - before_action :require_login, except: [:index, :show, :recommend] - before_action :require_profile_completed, only: [:create] + before_action :require_login, except: [:index, :show, :recommend, :languages] + # before_action :require_profile_completed, only: [:create] before_action :convert_image!, only: [:create, :update] - before_action :load_organization, only: [:show, :update, :destroy] + before_action :load_organization, only: [:show, :update, :destroy, :update_news, :update_memo, :update_other, :languages] before_action :check_user_can_edit_org, only: [:update, :destroy] def index @@ -62,6 +62,45 @@ class Organizations::OrganizationsController < Organizations::BaseController tip_exception(e.message) end + def update_news + @organization.organization_extension.update_attributes!(news_banner_id: params[:news_banner_id], + news_title: params[:news_title], + news_url: params[:news_url], + news_content: params[:news_content]) + render_ok + end + + def update_memo + @organization.organization_extension.update_attributes!(memo: params[:memo]) + render_ok + end + + def update_other + @organization.organization_extension.update_attributes!(news_banner_id: params[:news_banner_id], + news_content: params[:news_content], + news_title: params[:news_title], + news_url: params[:news_url], + memo: params[:memo]) + render_ok + end + + def languages + projects = @organization.projects + projects_count = @organization.projects.count + + languages_hash = Rails.cache.fetch("query/organizations/languages/#{@organization.id}", :expires_in => 1.days) do + total_languages(projects) + end + + languages_hash = languages_hash.sort { |x, y| y[1] <=> x[1] } + sort_hash = Hash[*languages_hash.flatten] + # Rails.logger.info "languages_hash=============#{sort_hash}" + sort_hash= sort_hash.transform_values { |v| + ActionController::Base.helpers.number_to_percentage((v / projects_count), precision: 1) + }.select { |k, v| v != "0.0%" } + render json: sort_hash + end + def destroy tip_exception("密码不正确") unless current_user.check_password?(password) ActiveRecord::Base.transaction do @@ -144,5 +183,28 @@ class Organizations::OrganizationsController < Organizations::BaseController # 更新对应所属分类下的项目数量(私有) project.project_category.decrement!(:private_projects_count, 1) if project.project_category.present? end + + def total_languages(projects) + languages_hash ={} + projects.each do |p| + result = Gitea::Repository::Languages::ListService.call(p.owner.login, + p.identifier, current_user&.gitea_token) + next unless result[:status] === :success + total_byte_size = result[:body].values.sum + hash = result[:body].transform_values { |v| + (v * 100.0 / total_byte_size).to_f + } + + hash.each do |key,value| + # Rails.logger.info "key=============#{key}:#{value}" + if languages_hash.has_key?(key) + languages_hash[key] = languages_hash[key] + value + else + languages_hash[key] = value + end + end + end + languages_hash + end end \ No newline at end of file diff --git a/app/models/organization.rb b/app/models/organization.rb index d61dda567..2ec37ec27 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -39,15 +39,18 @@ # business :boolean default("0") # profile_completed :boolean default("0") # laboratory_id :integer -# is_shixun_marker :boolean default("0") -# admin_visitable :boolean default("0") -# collaborator :boolean default("0") +# platform :string(255) default("0") +# gitea_token :string(255) # gitea_uid :integer +# is_shixun_marker :boolean default("0") # is_sync_pwd :boolean default("1") # watchers_count :integer default("0") # devops_step :integer default("0") -# gitea_token :string(255) -# platform :string(255) +# sponsor_certification :integer default("0") +# sponsor_num :integer default("0") +# sponsored_num :integer default("0") +# sponsor_description :text(65535) +# award_time :datetime # # Indexes # @@ -55,9 +58,8 @@ # index_users_on_homepage_engineer (homepage_engineer) # index_users_on_homepage_teacher (homepage_teacher) # index_users_on_laboratory_id (laboratory_id) -# index_users_on_login (login) UNIQUE -# index_users_on_mail (mail) UNIQUE -# index_users_on_phone (phone) UNIQUE +# index_users_on_login (login) +# index_users_on_mail (mail) # index_users_on_type (type) # @@ -71,13 +73,15 @@ class Organization < Owner has_many :teams, dependent: :destroy has_many :organization_users, dependent: :destroy has_many :team_users, dependent: :destroy + has_many :pinned_projects, class_name: 'PinnedProject', foreign_key: :user_id, dependent: :destroy + has_many :is_pinned_projects, through: :pinned_projects, source: :project, validate: false validates :login, presence: true validates_uniqueness_of :login, :if => Proc.new { |user| user.login_changed? && user.login.present? }, case_sensitive: false validates :login, format: { with: NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" } delegate :description, :website, :location, :repo_admin_change_team_access, :recommend, - :visibility, :max_repo_creation, :num_projects, :num_users, :num_teams, to: :organization_extension, allow_nil: true + :visibility, :max_repo_creation, :num_projects, :num_users, :num_teams, :news_banner_id, :news_content, :memo, to: :organization_extension, allow_nil: true scope :with_visibility, ->(visibility) { joins(:organization_extension).where(organization_extensions: {visibility: visibility}) if visibility.present? } diff --git a/app/models/organization_extension.rb b/app/models/organization_extension.rb index 4b0935208..cb216aca1 100644 --- a/app/models/organization_extension.rb +++ b/app/models/organization_extension.rb @@ -16,6 +16,9 @@ # num_users :integer default("0") # num_teams :integer default("0") # recommend :boolean default("0") +# news_banner_id :integer +# news_content :text(65535) +# memo :text(65535) # # Indexes # diff --git a/app/models/owner.rb b/app/models/owner.rb index d348970f0..d325d3bdb 100644 --- a/app/models/owner.rb +++ b/app/models/owner.rb @@ -67,6 +67,7 @@ class Owner < ApplicationRecord has_many :projects, foreign_key: :user_id, dependent: :destroy has_many :repositories, foreign_key: :user_id, dependent: :destroy has_many :applied_transfer_projects, dependent: :destroy + has_many :pinned_projects, foreign_key: :user_id, dependent: :destroy scope :like, lambda { |keywords| # 表情处理 diff --git a/app/models/pinned_project.rb b/app/models/pinned_project.rb index 8e47c9ea4..c87944fa9 100644 --- a/app/models/pinned_project.rb +++ b/app/models/pinned_project.rb @@ -17,6 +17,7 @@ class PinnedProject < ApplicationRecord - belongs_to :user + # belongs_to :user + belongs_to :owner, class_name: 'Owner', foreign_key: :user_id, optional: true belongs_to :project end diff --git a/app/models/project.rb b/app/models/project.rb index f08daae9e..224479bd8 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -3,7 +3,7 @@ # Table name: projects # # id :integer not null, primary key -# name :string(255) default(""), not null +# name :string(255) # description :text(4294967295) # homepage :string(255) default("") # is_public :boolean default("1"), not null @@ -122,7 +122,7 @@ class Project < ApplicationRecord has_many :project_units, dependent: :destroy has_one :applied_transfer_project,-> { order created_at: :desc }, dependent: :destroy has_many :pinned_projects, dependent: :destroy - has_many :has_pinned_users, through: :pinned_projects, source: :user + has_many :has_pinned_users, through: :pinned_projects, source: :owner has_many :webhooks, class_name: "Gitea::Webhook", primary_key: :gpid, foreign_key: :repo_id has_many :user_trace_tasks, dependent: :destroy has_many :project_invite_links, dependent: :destroy diff --git a/app/views/organizations/organizations/_detail.json.jbuilder b/app/views/organizations/organizations/_detail.json.jbuilder index 4a8b512b9..c7614f039 100644 --- a/app/views/organizations/organizations/_detail.json.jbuilder +++ b/app/views/organizations/organizations/_detail.json.jbuilder @@ -11,4 +11,9 @@ json.num_projects organization.num_projects json.num_users organization.num_users json.num_teams organization.num_teams json.avatar_url url_to_avatar(organization) -json.created_at organization.created_on.strftime("%Y-%m-%d") \ No newline at end of file +json.created_at organization.created_on.strftime("%Y-%m-%d") +json.news_banner_id organization.news_banner_id +json.news_content organization.news_content +json.memo organization.memo +json.news_title organization.news_title +json.news_url organization.news_url \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 7ad885c48..dcce71920 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -168,6 +168,17 @@ Rails.application.routes.draw do end end get :recommend, on: :collection + resources :is_pinned_projects, only: [:index, :update] do + collection do + post :pin + end + end + member do + post :update_news + post :update_memo + post :update_other + get :languages + end end end diff --git a/db/migrate/20220727063638_add_organization_extensions_news.rb b/db/migrate/20220727063638_add_organization_extensions_news.rb new file mode 100644 index 000000000..4abd48de0 --- /dev/null +++ b/db/migrate/20220727063638_add_organization_extensions_news.rb @@ -0,0 +1,7 @@ +class AddOrganizationExtensionsNews < ActiveRecord::Migration[5.2] + def change + add_column :organization_extensions, :news_banner_id, :integer + add_column :organization_extensions, :news_content, :text + add_column :organization_extensions, :memo, :text + end +end From 3f20436bd835c04673fdbbec80273e1d487c3f88 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 10 Apr 2023 15:32:47 +0800 Subject: [PATCH 296/438] =?UTF-8?q?=E7=BB=84=E7=BB=87=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E6=94=B9=E7=89=88=EF=BC=8C=E5=A2=9E=E5=8A=A0=E7=B2=BE=E9=80=89?= =?UTF-8?q?=E3=80=81=E6=96=B0=E9=97=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/organization.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/organization.rb b/app/models/organization.rb index 2ec37ec27..aabe20130 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -81,7 +81,8 @@ class Organization < Owner validates :login, format: { with: NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" } delegate :description, :website, :location, :repo_admin_change_team_access, :recommend, - :visibility, :max_repo_creation, :num_projects, :num_users, :num_teams, :news_banner_id, :news_content, :memo, to: :organization_extension, allow_nil: true + :visibility, :max_repo_creation, :num_projects, :num_users, :num_teams, + :news_banner_id, :news_content, :memo, :news_title, :news_url, to: :organization_extension, allow_nil: true scope :with_visibility, ->(visibility) { joins(:organization_extension).where(organization_extensions: {visibility: visibility}) if visibility.present? } From e938ce2e25c2f315b932e7db1ce675f636701d51 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 10 Apr 2023 15:35:10 +0800 Subject: [PATCH 297/438] =?UTF-8?q?=E7=BB=84=E7=BB=87=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E6=94=B9=E7=89=88=EF=BC=8C=E5=A2=9E=E5=8A=A0=E7=B2=BE=E9=80=89?= =?UTF-8?q?=E3=80=81=E6=96=B0=E9=97=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...20220728063123_add_organization_extensions_news_title.rb | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 db/migrate/20220728063123_add_organization_extensions_news_title.rb diff --git a/db/migrate/20220728063123_add_organization_extensions_news_title.rb b/db/migrate/20220728063123_add_organization_extensions_news_title.rb new file mode 100644 index 000000000..bb9f298ff --- /dev/null +++ b/db/migrate/20220728063123_add_organization_extensions_news_title.rb @@ -0,0 +1,6 @@ +class AddOrganizationExtensionsNewsTitle < ActiveRecord::Migration[5.2] + def change + add_column :organization_extensions, :news_title, :string + add_column :organization_extensions, :news_url, :string + end +end From f81772064d68e17a5d1edc7cd3c488ca0ffb4e90 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 10 Apr 2023 15:35:47 +0800 Subject: [PATCH 298/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=88=97=E8=A1=A8=E4=BD=BF=E7=94=A8topic=5Fid?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=97=B6=E5=BA=94=E8=BF=94=E5=9B=9E=E5=AF=B9?= =?UTF-8?q?=E5=BA=94=E7=9A=84=E6=80=BB=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 652e80ec6..71a214062 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -43,6 +43,9 @@ class ProjectsController < ApplicationController # ps = ProjectStatistic.first # ps.common_projects_count + ps.mirror_projects_count unless ps.blank? @projects.total_count + elsif params[:topic_id].present? + topic = ProjectTopic.find_by(id: params[:topic_id]) + topic&.projects_count || 0 else cate = ProjectCategory.find_by(id: category_id) cate&.projects_count || 0 From 98db151c440c34447b290733c5fe8efba3f6f5cc Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 10 Apr 2023 15:43:23 +0800 Subject: [PATCH 299/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 688d13141..3738d19bd 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -39,7 +39,7 @@ class ProjectsController < ApplicationController category_id = params[:category_id] @total_count = - if category_id.blank? && params[:search].blank? + if category_id.blank? && params[:search].blank? && params[:topic_id].blank? # 默认查询时count性能问题处理 ProjectCategory.sum("projects_count") - Project.visible.joins("left join organization_extensions on organization_extensions.organization_id = projects.user_id").where("organization_extensions.visibility =2").count elsif params[:search].present? From 30787db1e7eff73e4f43e42130b0f58aafeedd36 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 10 Apr 2023 15:43:56 +0800 Subject: [PATCH 300/438] =?UTF-8?q?=E7=BB=84=E7=BB=87=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E6=94=B9=E7=89=88=EF=BC=8C=E5=A2=9E=E5=8A=A0=E7=B2=BE=E9=80=89?= =?UTF-8?q?=E3=80=81=E6=96=B0=E9=97=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../organizations/is_pinned_projects/index.json.jbuilder | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 app/views/organizations/is_pinned_projects/index.json.jbuilder diff --git a/app/views/organizations/is_pinned_projects/index.json.jbuilder b/app/views/organizations/is_pinned_projects/index.json.jbuilder new file mode 100644 index 000000000..c4c93dfe6 --- /dev/null +++ b/app/views/organizations/is_pinned_projects/index.json.jbuilder @@ -0,0 +1,7 @@ +json.total_count @is_pinned_projects.total_count +json.projects @is_pinned_projects.each do |project| + json.partial! "projects/project_detail", project: project&.project + json.id project.id + json.position project.position + json.project_id project.project_id +end \ No newline at end of file From 478fec6ce4078b2c59ec7e27f4a213722acecfa8 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 10 Apr 2023 15:47:40 +0800 Subject: [PATCH 301/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 3738d19bd..433a369a5 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -42,11 +42,8 @@ class ProjectsController < ApplicationController if category_id.blank? && params[:search].blank? && params[:topic_id].blank? # 默认查询时count性能问题处理 ProjectCategory.sum("projects_count") - Project.visible.joins("left join organization_extensions on organization_extensions.organization_id = projects.user_id").where("organization_extensions.visibility =2").count - elsif params[:search].present? + elsif params[:search].present? || params[:topic_id].present? @projects.total_count - elsif params[:topic_id].present? - topic = ProjectTopic.find_by(id: params[:topic_id]) - topic&.projects_count || 0 else cate = ProjectCategory.find_by(id: category_id) cate&.projects_count || 0 From d59e99feca70651b3744c5a09f47993fbaec95ea Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 11 Apr 2023 10:12:24 +0800 Subject: [PATCH 302/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E8=AF=B7=E6=B1=82=E6=9B=B4=E6=96=B0=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/issues_controller.rb | 2 +- app/controllers/pull_requests_controller.rb | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/app/controllers/api/v1/issues_controller.rb b/app/controllers/api/v1/issues_controller.rb index 433432048..113c86a8c 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, :updated_on)) else @issues = kaminari_paginate(@object_result[:data]) end diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index d02bb1deb..f5735d194 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -274,15 +274,10 @@ class PullRequestsController < ApplicationController body: params[:body], #内容 head: params[:head], #源分支 base: params[:base], #目标分支 - milestone: 0, #里程碑,未与本地的里程碑关联 + # milestone: 0, #里程碑,未与本地的里程碑关联 } assignee_login = User.find_by_id(params[:assigned_to_id])&.login - @requests_params = @local_params.merge({ - # assignees: ["#{params[:assigned_login].to_s}"], - assignees: ["#{assignee_login.to_s}"], - labels: params[:issue_tag_ids] - # due_date: Time.now - }) + @requests_params = @local_params.merge({assignees: [assignee_login.to_s].reject!(&:empty?)}) @issue_params = { author_id: current_user.id, project_id: @project.id, From 17279c56f4f0be362d44fb84ec00159310587eb2 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 29 Mar 2023 18:49:20 +0800 Subject: [PATCH 303/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Awebhook=20se?= =?UTF-8?q?rvice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/attachment.rb | 88 +++++++++++--------- app/models/gitea/webhook_task.rb | 6 +- app/models/issue.rb | 26 ++++++ app/models/issue_priority.rb | 6 ++ app/models/issue_status.rb | 6 ++ app/models/issue_tag.rb | 7 ++ app/models/project.rb | 55 ++++++++++++ app/models/user.rb | 10 +++ app/models/version.rb | 6 ++ app/services/webhook/client.rb | 92 +++++++++++++++++++++ app/services/webhook/issue_create_client.rb | 53 ++++++++++++ 11 files changed, 311 insertions(+), 44 deletions(-) create mode 100644 app/services/webhook/client.rb create mode 100644 app/services/webhook/issue_create_client.rb diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 3451246af..0cbf6fb0f 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -1,42 +1,42 @@ -# == Schema Information -# -# Table name: attachments -# -# id :integer not null, primary key -# container_id :integer -# container_type :string(30) -# filename :string(255) default(""), not null -# disk_filename :string(255) default(""), not null -# filesize :integer default("0"), not null -# content_type :string(255) default("") -# digest :string(60) default(""), not null -# downloads :integer default("0"), not null -# author_id :integer default("0"), not null -# created_on :datetime -# description :text(65535) -# disk_directory :string(255) -# attachtype :integer default("1") -# is_public :integer default("1") -# copy_from :string(255) -# quotes :integer default("0") -# is_publish :integer default("1") -# publish_time :datetime -# resource_bank_id :integer -# unified_setting :boolean default("1") -# cloud_url :string(255) default("") -# course_second_category_id :integer default("0") -# delay_publish :boolean default("0") -# link :string(255) -# clone_id :integer -# -# Indexes -# -# index_attachments_on_author_id (author_id) -# index_attachments_on_clone_id (clone_id) -# index_attachments_on_container_id_and_container_type (container_id,container_type) -# index_attachments_on_created_on (created_on) -# - +# == Schema Information +# +# Table name: attachments +# +# id :integer not null, primary key +# container_id :integer +# container_type :string(30) +# filename :string(255) default(""), not null +# disk_filename :string(255) default(""), not null +# filesize :integer default("0"), not null +# content_type :string(255) default("") +# digest :string(60) default(""), not null +# downloads :integer default("0"), not null +# author_id :integer default("0"), not null +# created_on :datetime +# description :text(65535) +# disk_directory :string(255) +# attachtype :integer default("1") +# is_public :integer default("1") +# copy_from :string(255) +# quotes :integer default("0") +# is_publish :integer default("1") +# publish_time :datetime +# resource_bank_id :integer +# unified_setting :boolean default("1") +# cloud_url :string(255) default("") +# course_second_category_id :integer default("0") +# delay_publish :boolean default("0") +# link :string(255) +# clone_id :integer +# +# Indexes +# +# index_attachments_on_author_id (author_id) +# index_attachments_on_clone_id (clone_id) +# index_attachments_on_container_id_and_container_type (container_id,container_type) +# index_attachments_on_created_on (created_on) +# + class Attachment < ApplicationRecord @@ -184,4 +184,14 @@ class Attachment < ApplicationRecord is_pdf end + def to_builder + Jbuilder.new do |attachment| + attachment.id self.id + attachment.title self.title + attachment.filesize self.filesize + attachment.is_pdf self.is_pdf? + attachment.created_on self.created_on.strftime("%Y-%m-%d %H:%M") + attachment.content_type self.content_type + end + end end diff --git a/app/models/gitea/webhook_task.rb b/app/models/gitea/webhook_task.rb index 325352c69..7e9bc68a7 100644 --- a/app/models/gitea/webhook_task.rb +++ b/app/models/gitea/webhook_task.rb @@ -1,6 +1,7 @@ class Gitea::WebhookTask < Gitea::Base serialize :payload_content, JSON serialize :request_content, JSON + serialize :response_content, JSON self.inheritance_column = nil @@ -10,9 +11,4 @@ class Gitea::WebhookTask < Gitea::Base enum type: {gogs: 1, slack: 2, gitea: 3, discord: 4, dingtalk: 5, telegram: 6, msteams: 7, feishu: 8, matrix: 9} - def response_content_json - JSON.parse(response_content) - rescue - {} - end end \ No newline at end of file diff --git a/app/models/issue.rb b/app/models/issue.rb index 0d38f7a2a..4ec77025e 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -217,4 +217,30 @@ class Issue < ApplicationRecord SendTemplateMessageJob.perform_later('IssueExpire', self.id) if Site.has_notice_menu? && self.due_date == Date.today + 1.days end + def to_builder + Jbuilder.new do |issue| + issue.(self, :id, :project_issues_index, :subject, :description) + issue.created_at self.created_on.strftime("%Y-%m-%d %H:%M") + issue.updated_at self.updated_on.strftime("%Y-%m-%d %H:%M") + issue.tags self.show_issue_tags.map{|t| t.to_builder} + issue.status self.issue_status.to_builder + if self.priority.present? + issue.priority self.priority.to_builder + else + issue.priority nil + end + if self.version.present? + issue.milestone self.version.to_builder + else + issue.milestone nil + end + issue.author self.user.to_builder + issue.assigners self.show_assigners.map{|t| t.to_builder} + issue.participants self.participants.distinct.map{|t| t.to_builder} + issue.comment_journals_count self.comment_journals.size + issue.operate_journals_count self.operate_journals.size + issue.attachments self.attachments.map{|t| t.to_builder} + end + end + end diff --git a/app/models/issue_priority.rb b/app/models/issue_priority.rb index c8ef73299..5bf70da05 100644 --- a/app/models/issue_priority.rb +++ b/app/models/issue_priority.rb @@ -32,4 +32,10 @@ class IssuePriority < ApplicationRecord end end end + + def to_builder + Jbuilder.new do |priority| + priority.(self, :id, :name) + end + end end diff --git a/app/models/issue_status.rb b/app/models/issue_status.rb index fcce29c32..fde871182 100644 --- a/app/models/issue_status.rb +++ b/app/models/issue_status.rb @@ -44,4 +44,10 @@ class IssueStatus < ApplicationRecord end end end + + def to_builder + Jbuilder.new do |status| + status.(self, :id, :name) + end + end end diff --git a/app/models/issue_tag.rb b/app/models/issue_tag.rb index ad6a82763..0da4ca730 100644 --- a/app/models/issue_tag.rb +++ b/app/models/issue_tag.rb @@ -53,4 +53,11 @@ class IssueTag < ApplicationRecord self.update_column(:pull_requests_count, pull_request_issues.size) end + + def to_builder + Jbuilder.new do |tag| + tag.(self, :id, :name, :description) + end + end + end diff --git a/app/models/project.rb b/app/models/project.rb index f08daae9e..02844c3bc 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -446,4 +446,59 @@ class Project < ApplicationRecord def del_project_issue_cache_delete_count $redis_cache.hdel("issue_cache_delete_count", self.id) end + + def to_builder + Jbuilder.new do |project| + project.id self.id + project.identifier self.identifier + project.name self.name + project.description Nokogiri::HTML(self.description).text + project.visits self.visits + project.praises_count self.praises_count.to_i + project.watchers_count self.watchers_count.to_i + project.issues_count self.issues_count.to_i + project.pull_requests_count self.pull_requests_count.to_i + project.forked_count self.forked_count.to_i + project.is_public self.is_public + project.mirror_url self.repository&.mirror_url + project.type self&.project_type + project.created_at self.created_on.strftime("%Y-%m-%d %H:%M") + project.updated_at self.updated_on.strftime("%Y-%m-%d %H:%M") + project.forked_from_project_id self.forked_from_project_id + project.platform self.platform + project.author do + if self.educoder? + project_educoder = self.project_educoder + project.name project_educoder&.owner + project.type 'Educoder' + project.login project_educoder&.repo_name.split('/')[0] + project.image_url render_educoder_avatar_url(self.project_educoder) + else + user = self.owner + project.name user.try(:show_real_name) + project.type user&.type + project.login user.login + project.image_url user.get_letter_avatar_url + end + end + + project.category do + if self.project_category.blank? + project.nil! + else + project.id self.project_category.id + project.name self.project_category.name + end + end + project.language do + if self.project_language.blank? + project.nil! + else + project.id self.project_language.id + project.name self.project_language.name + end + end + + end + end end diff --git a/app/models/user.rb b/app/models/user.rb index c3c62f9eb..70de1fc64 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -859,6 +859,16 @@ class User < Owner end end + def to_builder + Jbuilder.new do |user| + user.(self, :id, :login) + user.name self.real_name + user.email self.mail + user.image_url self.get_letter_avatar_url + end + end + + protected def validate_password_length # 管理员的初始密码是5位 diff --git a/app/models/version.rb b/app/models/version.rb index 1e14a135c..82474f55e 100644 --- a/app/models/version.rb +++ b/app/models/version.rb @@ -55,6 +55,12 @@ class Version < ApplicationRecord User.select(:login, :lastname,:firstname, :nickname)&.find_by_id(self.user_id) end + def to_builder + Jbuilder.new do |version| + version.(self, :id, :name, :description, :effective_date) + end + end + private def send_create_message_to_notice_system SendTemplateMessageJob.perform_later('ProjectMilestone', self.id, self.user_id) if Site.has_notice_menu? diff --git a/app/services/webhook/client.rb b/app/services/webhook/client.rb new file mode 100644 index 000000000..05e687f13 --- /dev/null +++ b/app/services/webhook/client.rb @@ -0,0 +1,92 @@ +module Webhook::Client + + # uuid SecureRandom.uuid + # hmac = OpenSSL::HMAC.new(secret, OpenSSL::Digest::SHA1.new) + # message = Gitea::WebhookTask.last.read_attribute_before_type_cast("payload_content") + # hmac.update(message) + # sha1 = hmac.digest.unpack('H*').first + + attr_reader :uuid, :event, :http_method, :content_type, :url, :secret, :payload_content + attr_accessor :request_content, :response_content + + def initialize(opts) + @uuid = opts[:uuid] + @event = opts[:event] + @http_method = opts[:http_method] + @content_type = opts[:content_type] + @url = opts[:url] + @secret = opts[:secret] + @payload_content = opts[:payload_content] + @request_content = {} + @response_content = {} + end + + def do_request + headers = {} + headers['Content-Type'] = trans_content_type + headers["X-Gitea-Delivery"] = @uuid + headers["X-Gitea-Event"] = @event + headers["X-Gitea-Event-Type"] = @event + headers["X-Gitea-Signature"] = signatureSHA256 + headers["X-Gogs-Delivery"] = @uuid + headers["X-Gogs-Event"] = @event + headers["X-Gogs-Event-Type"] = @event + headers["X-Gogs-Signature"] = signatureSHA256 + headers["X-Hub-Signature"] = "sha1=" + signatureSHA1 + headers["X-Hub-Signature-256"] = "sha256=" + signatureSHA256 + headers["X-GitHub-Delivery"] = @uuid + headers["X-GitHub-Event"] = @event + headers["X-GitHub-Event-Type"] = @event + @request_content["url"] = @url + @request_content["http_method"] = @http_method + @request_content["headers"] = headers + + response = RestClient::Request.execute(method: trans_http_method, url: @url, headers: headers, payload: payload_content) {|response, request, result| response } + + @response_content["status"] = response.code + @response_content["headers"] = response.headers + @response_content["body"] = response.body.to_json + + return @request_content, @response_content + end + + def request_content + @request_content + end + + def response_content + @response_content + end + + private + def signatureSHA1 + hmac = OpenSSL::HMAC.new(@secret, OpenSSL::Digest::SHA1.new) + message = @payload_content + + hmac.digest.unpack('H*').first + end + + def signatureSHA256 + hmac = OpenSSL::HMAC.new(@secret, OpenSSL::Digest::SHA256.new) + message = @payload_content + + hmac.digest.unpack('H*').first + end + + def trans_content_type + if @content_type == "form" + return "application/x-www-form-urlencoded" + else + return "application/json" + end + end + + def trans_http_method + if @http_method == "GET" + return :get + else + return :post + end + end + +end \ No newline at end of file diff --git a/app/services/webhook/issue_create_client.rb b/app/services/webhook/issue_create_client.rb new file mode 100644 index 000000000..9e8b94bc3 --- /dev/null +++ b/app/services/webhook/issue_create_client.rb @@ -0,0 +1,53 @@ +class Webhook::IssueCreateClient + + include Webhook::Client + + attr_accessor :webhook, :issue, :sender + attr_accessor :webhook_task + + def initialize(webhook, issue, sender) + @webhook = webhook + @issue = issue + @sender = sender + # 创建webhook task + @webhook_task = Gitea::WebhookTask.create( + hook_id: @webhook.id, + uuid: SecureRandom.uuid, + payload_content: payload_content, + event_type: "issues", + is_delivered: true + ) + + # 构建client参数 + super({ + uuid: @webhook_task.uuid, + event: "issues", + http_method: @webhook.http_method, + content_type: @webhook.content_type, + url: @webhook.url, + secret: @webhook.secret, + payload_content: @webhook_task.read_attribute_before_type_cast("payload_content") + }) + end + + def do_request + request_content, response_content = super + @webhook_task.update_attributes({ + delivered: Time.now.to_i * 1000000000, + is_succeed: response_content["status"] < 300, + request_content: request_content, + response_content: response_content + }) + end + + def payload_content + { + "action": "opened", + "number": @issue.project_issues_index, + "issue": JSON.parse(@issue.to_builder.target!), + "project": JSON.parse(@issue.project.to_builder.target!), + "sender": JSON.parse(@sender.to_builder.target!) + } + end + +end \ No newline at end of file From b4672929dc7cc550df041712a7023103a2d942d9 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 30 Mar 2023 10:19:50 +0800 Subject: [PATCH 304/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E8=A7=A6?= =?UTF-8?q?=E5=8F=91webhook=E7=9A=84job?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/touch_webhook_job.rb | 28 ++++++++++ app/services/api/v1/issues/create_service.rb | 3 ++ app/services/api/v1/issues/update_service.rb | 3 ++ app/services/webhook/issue_create_client.rb | 2 + app/services/webhook/issue_update_client.rb | 57 ++++++++++++++++++++ config/sidekiq.yml | 1 + 6 files changed, 94 insertions(+) create mode 100644 app/jobs/touch_webhook_job.rb create mode 100644 app/services/webhook/issue_update_client.rb diff --git a/app/jobs/touch_webhook_job.rb b/app/jobs/touch_webhook_job.rb new file mode 100644 index 000000000..9959d2ebc --- /dev/null +++ b/app/jobs/touch_webhook_job.rb @@ -0,0 +1,28 @@ +class TouchWebhookJob < ApplicationJob + queue_as :webhook + + def perform(source, *args) + case source + when 'IssueCreate' + issue_id, sender_id = args[0], args[1] + issue = Issue.find_by_id issue_id + sender = User.find_by_id sender_id + return if issue.nil? || sender.nil? + issue.project.webhooks.each do |webhook| + next unless webhook.events["events"]["issues"] + @webhook_task = Webhook::IssueCreateClient.new(webhook, issue, sender).do_request + Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}" + end + when 'IssueUpdate' + issue_id, sender_id, changes = args[0], args[1], args[2] + issue = Issue.find_by_id issue_id + sender = User.find_by_id sender_id + return if issue.nil? || sender.nil? || !changes.is_a?(Hash) + issue.project.webhooks.each do |webhook| + next unless webhook.events["events"]["issues"] + @webhook_task = Webhook::IssueUpdateClient.new(webhook, issue, sender, changes.stringify_keys).do_request + Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}" + end + end + end +end \ No newline at end of file diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index 30f4a11ef..7080c3bda 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -67,6 +67,9 @@ class Api::V1::Issues::CreateService < ApplicationService SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @created_issue&.id, assigner_ids) unless assigner_ids.blank? SendTemplateMessageJob.perform_later('ProjectIssue', current_user.id, @created_issue&.id) end + + # 触发webhook + TouchWebhookJob.perform_later('IssueCreate', @created_issue&.id, current_user.id) unlock("Api::V1::Issues::CreateService:#{project.id}") # 结束写数据,解锁 end diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 9aa9d6bb1..21242edc2 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -77,6 +77,9 @@ class Api::V1::Issues::UpdateService < ApplicationService SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id, add_assigner_ids) unless add_assigner_ids.blank? end + # 触发webhook + TouchWebhookJob.perform_later('IssueCreate', @updated_issue&.id, current_user.id, previous_issue_changes) + unlock("Api::V1::Issues::UpdateService:#{project.id}:#{issue.id}") return @updated_issue diff --git a/app/services/webhook/issue_create_client.rb b/app/services/webhook/issue_create_client.rb index 9e8b94bc3..f222291fb 100644 --- a/app/services/webhook/issue_create_client.rb +++ b/app/services/webhook/issue_create_client.rb @@ -38,6 +38,8 @@ class Webhook::IssueCreateClient request_content: request_content, response_content: response_content }) + + @webhook_task end def payload_content diff --git a/app/services/webhook/issue_update_client.rb b/app/services/webhook/issue_update_client.rb new file mode 100644 index 000000000..ff9926006 --- /dev/null +++ b/app/services/webhook/issue_update_client.rb @@ -0,0 +1,57 @@ +class Webhook::IssueUpdateClient + + include Webhook::Client + + attr_accessor :webhook, :issue, :sender, :changes + attr_accessor :webhook_task + + def initialize(webhook, issue, sender, changes={}) + @webhook = webhook + @issue = issue + @sender = sender + @changes = changes + # 创建webhook task + @webhook_task = Gitea::WebhookTask.create( + hook_id: @webhook.id, + uuid: SecureRandom.uuid, + payload_content: payload_content, + event_type: "issues", + is_delivered: true + ) + + # 构建client参数 + super({ + uuid: @webhook_task.uuid, + event: "issues", + http_method: @webhook.http_method, + content_type: @webhook.content_type, + url: @webhook.url, + secret: @webhook.secret, + payload_content: @webhook_task.read_attribute_before_type_cast("payload_content") + }) + end + + def do_request + request_content, response_content = super + @webhook_task.update_attributes({ + delivered: Time.now.to_i * 1000000000, + is_succeed: response_content["status"] < 300, + request_content: request_content, + response_content: response_content + }) + + @webhook_task + end + + def payload_content + { + "action": "edited", + "number": @issue.project_issues_index, + "changes": @changes, + "issue": JSON.parse(@issue.to_builder.target!), + "project": JSON.parse(@issue.project.to_builder.target!), + "sender": JSON.parse(@sender.to_builder.target!) + } + end + +end \ No newline at end of file diff --git a/config/sidekiq.yml b/config/sidekiq.yml index f8981a8b1..0b38a0b8f 100644 --- a/config/sidekiq.yml +++ b/config/sidekiq.yml @@ -9,3 +9,4 @@ - [mailers, 101] - [cache, 10] - [message, 20] + - [webhook, 20] From 91dfc94a7bec3cbfd8483419bd77dcf3ac5b9e93 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 6 Apr 2023 17:13:47 +0800 Subject: [PATCH 305/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=AD=A3=E5=B8=B8=E6=98=BE=E7=A4=BAresponse=5Fcontent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/api/v1/projects/webhooks/hooktasks.json.jbuilder | 2 +- app/views/projects/webhooks/tasks.json.jbuilder | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/api/v1/projects/webhooks/hooktasks.json.jbuilder b/app/views/api/v1/projects/webhooks/hooktasks.json.jbuilder index 618a05515..22070cc68 100644 --- a/app/views/api/v1/projects/webhooks/hooktasks.json.jbuilder +++ b/app/views/api/v1/projects/webhooks/hooktasks.json.jbuilder @@ -1,6 +1,6 @@ json.total_count @hooktasks.total_count json.hooktasks @hooktasks.each do |task| json.(task, :id, :event_type, :type, :uuid, :is_succeed, :is_delivered, :payload_content, :request_content) - json.response_content task.response_content_json + json.response_content task.response_content json.delivered_time Time.at(task.delivered*10**-9).strftime("%Y-%m-%d %H:%M:%S") end \ No newline at end of file diff --git a/app/views/projects/webhooks/tasks.json.jbuilder b/app/views/projects/webhooks/tasks.json.jbuilder index 82b2eae4a..8e1809011 100644 --- a/app/views/projects/webhooks/tasks.json.jbuilder +++ b/app/views/projects/webhooks/tasks.json.jbuilder @@ -1,6 +1,6 @@ json.total_count @tasks.total_count json.tasks @tasks.each do |task| json.(task, :id, :event_type, :type, :uuid, :is_succeed, :is_delivered, :payload_content, :request_content) - json.response_content task.response_content_json - json.delivered_time Time.at(task.delivered*10**-9).strftime("%Y-%m-%d %H:%M:%S") + json.response_content task.response_content + json.delivered_time task.delivered.present? ? Time.at(task.delivered*10**-9).strftime("%Y-%m-%d %H:%M:%S") : nil end \ No newline at end of file From 769c8a019490b34561b624e0819a3d46b56cb953 Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Thu, 6 Apr 2023 17:00:43 +0800 Subject: [PATCH 306/438] webhook for issue --- app/controllers/journals_controller.rb | 1 + app/jobs/touch_webhook_job.rb | 67 ++++++++- app/services/api/v1/issues/create_service.rb | 3 +- .../api/v1/issues/journals/create_service.rb | 2 +- app/services/api/v1/issues/update_service.rb | 3 +- app/services/webhook/event_client .rb | 130 ++++++++++++++++++ 6 files changed, 201 insertions(+), 5 deletions(-) create mode 100644 app/services/webhook/event_client .rb diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rb index 6dc1e29c9..e539ec2cd 100644 --- a/app/controllers/journals_controller.rb +++ b/app/controllers/journals_controller.rb @@ -46,6 +46,7 @@ class JournalsController < ApplicationController end Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}" AtmeService.call(current_user, @atme_receivers, journal) if @atme_receivers.size > 0 + TouchWebhookJob.perform_later('PullRequestComment', @issue&.id, current_user.id, journal.id) # @issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "journal") render :json => { status: 0, message: "评论成功", id: journal.id} # normal_status(0, "评论成功") diff --git a/app/jobs/touch_webhook_job.rb b/app/jobs/touch_webhook_job.rb index 9959d2ebc..91155398e 100644 --- a/app/jobs/touch_webhook_job.rb +++ b/app/jobs/touch_webhook_job.rb @@ -10,7 +10,7 @@ class TouchWebhookJob < ApplicationJob return if issue.nil? || sender.nil? issue.project.webhooks.each do |webhook| next unless webhook.events["events"]["issues"] - @webhook_task = Webhook::IssueCreateClient.new(webhook, issue, sender).do_request + @webhook_task = Webhook::EventClient.new(webhook, issue, sender,"issues","issues").do_request Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}" end when 'IssueUpdate' @@ -20,7 +20,70 @@ class TouchWebhookJob < ApplicationJob return if issue.nil? || sender.nil? || !changes.is_a?(Hash) issue.project.webhooks.each do |webhook| next unless webhook.events["events"]["issues"] - @webhook_task = Webhook::IssueUpdateClient.new(webhook, issue, sender, changes.stringify_keys).do_request + @webhook_task = Webhook::EventClient.new(webhook, issue, sender, "issues", "issues",changes.stringify_keys).do_request + Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}" + end + + when 'IssueAssign' + issue_id, sender_id, assigner_ids = args[0], args[1], args[2] + issue = Issue.find_by_id issue_id + sender = User.find_by_id sender_id + return if issue.nil? || sender.nil? + issue.project.webhooks.each do |webhook| + next unless webhook.events["events"]["issue_assign"] + @webhook_task = Webhook::EventClient.new(webhook, issue, sender, "issues", "issue_assign",{assigner_ids: assigner_ids}).do_request + Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}" + end + + when 'IssueLable' + issue_id, sender_id, issue_tag_ids = args[0], args[1], args[2] + issue = Issue.find_by_id issue_id + sender = User.find_by_id sender_id + return if issue.nil? || sender.nil? + issue.project.webhooks.each do |webhook| + next unless webhook.events["events"]["issue_label"] + @webhook_task = Webhook::EventClient.new(webhook, issue, sender, "issues", "issue_label",{issue_tag_ids: issue_tag_ids}).do_request + Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}" + end + + when 'IssueComment' + issue_id, sender_id, comment_id = args[0], args[1], args[2] + issue = Issue.find_by_id issue_id + comment = issue.comment_journals.find_by_id comment_id + sender = User.find_by_id sender_id + return if issue.nil? || sender.nil? || comment.nil? + + changes = { + id: comment.id, + user: comment.user.to_builder.target!, + body: comment.notes, + created_on: comment.created_on, + updated_on: comment.updated_on, + } + + issue.project.webhooks.each do |webhook| + next unless webhook.events["events"]["issue_comment"] + @webhook_task = Webhook::EventClient.new(webhook, issue, sender, "issue_comment", "issue_comment",changes.stringify_keys).do_request + Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}" + end + + when 'PullRequestComment' + issue_id, sender_id, comment_id = args[0], args[1], args[2] + issue = Issue.find_by_id issue_id + comment = issue.comment_journals.find_by_id comment_id + sender = User.find_by_id sender_id + return if issue.nil? || sender.nil? || comment.nil? + + changes = { + id: comment.id, + user: comment.user.to_builder.target!, + body: comment.notes, + created_on: comment.created_on, + updated_on: comment.updated_on, + } + issue.project.webhooks.each do |webhook| + next unless webhook.events["events"]["pull_request_comment"] + @webhook_task = Webhook::EventClient.new(webhook, issue, sender, "issue_comment", "pull_request_comment",changes.stringify_keys).do_request Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}" end end diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index 7080c3bda..b0b1b05b0 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -70,7 +70,8 @@ class Api::V1::Issues::CreateService < ApplicationService # 触发webhook TouchWebhookJob.perform_later('IssueCreate', @created_issue&.id, current_user.id) - + TouchWebhookJob.perform_later('IssueLable', @created_issue&.id, issue_tag_ids) + TouchWebhookJob.perform_later('IssueAssign', @created_issue&.id, assigner_ids) unlock("Api::V1::Issues::CreateService:#{project.id}") # 结束写数据,解锁 end diff --git a/app/services/api/v1/issues/journals/create_service.rb b/app/services/api/v1/issues/journals/create_service.rb index dce00349b..568deecdd 100644 --- a/app/services/api/v1/issues/journals/create_service.rb +++ b/app/services/api/v1/issues/journals/create_service.rb @@ -41,7 +41,7 @@ class Api::V1::Issues::Journals::CreateService < ApplicationService # @信息发送 AtmeService.call(current_user, @atme_receivers, @created_journal) unless receivers_login.blank? - + TouchWebhookJob.perform_later('IssueComment', @issue&.id, @current_user.id, @created_journal.id) unlock("Api::V1::Issues::Journals::CreateService:#{@issue.id}") @created_journal diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 21242edc2..153ea32e0 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -79,7 +79,8 @@ class Api::V1::Issues::UpdateService < ApplicationService # 触发webhook TouchWebhookJob.perform_later('IssueCreate', @updated_issue&.id, current_user.id, previous_issue_changes) - + TouchWebhookJob.perform_later('IssueLable', @updated_issue&.id, issue_tag_ids) + TouchWebhookJob.perform_later('IssueAssign', @updated_issue&.id, assigner_ids) unlock("Api::V1::Issues::UpdateService:#{project.id}:#{issue.id}") return @updated_issue diff --git a/app/services/webhook/event_client .rb b/app/services/webhook/event_client .rb new file mode 100644 index 000000000..28e473be5 --- /dev/null +++ b/app/services/webhook/event_client .rb @@ -0,0 +1,130 @@ +class Webhook::EventClient + + include Webhook::Client + + attr_accessor :webhook, :issue, :sender + attr_accessor :webhook_task + + def initialize(webhook, issue, sender, event, event_type, changes={}) + @webhook = webhook + @issue = issue + @sender = sender + @event = event + @event_type = event_type + @changes = changes + # 创建webhook task + @webhook_task = Gitea::WebhookTask.create( + hook_id: @webhook.id, + uuid: SecureRandom.uuid, + payload_content: payload_content, + event_type: @event_type, + is_delivered: true + ) + + # 构建client参数 + super({ + uuid: @webhook_task.uuid, + event: @event, + http_method: @webhook.http_method, + content_type: @webhook.content_type, + url: @webhook.url, + secret: @webhook.secret, + payload_content: @webhook_task.read_attribute_before_type_cast("payload_content") + }) + end + + def do_request + request_content, response_content = super + @webhook_task.update_attributes({ + delivered: Time.now.to_i * 1000000000, + is_succeed: response_content["status"] < 300, + request_content: request_content, + response_content: response_content + }) + + @webhook_task + end + + def payload_content + case @event_type + when "issues" + issue_payload_content + when "issue_assign" + issue_assign_payload_content + when "issue_label" + issue_label_payload_content + when "issue_comment" + issue_comment_payload_content + when "pull_request_comment" + pull_request_comment_payload_content + end + end + + def issue_payload_content + if @changes.blank? + { + "action": "opened", + "number": @issue.project_issues_index, + "issue": JSON.parse(@issue.to_builder.target!), + "project": JSON.parse(@issue.project.to_builder.target!), + "sender": JSON.parse(@sender.to_builder.target!) + } + else + { + "action": "edited", + "number": @issue.project_issues_index, + "changes": @changes, + "issue": JSON.parse(@issue.to_builder.target!), + "project": JSON.parse(@issue.project.to_builder.target!), + "sender": JSON.parse(@sender.to_builder.target!) + } + end + end + + def issue_assign_payload_content + { + "action": @changes["assigner_ids"].blank? ? "unassigned" : "assigned", + "number": @issue.project_issues_index, + "issue": JSON.parse(@issue.to_builder.target!), + "assignees": @issue.assignees.map(&:to_builder.target!), + "project": JSON.parse(@issue.project.to_builder.target!), + "sender": JSON.parse(@sender.to_builder.target!) + } + end + + def issue_label_payload_content + { + "action": @changes["issue_tag_ids"].blank? ? "label_cleared" : "label_updated", + "number": @issue.project_issues_index, + "issue": JSON.parse(@issue.to_builder.target!), + "project": JSON.parse(@issue.project.to_builder.target!), + "sender": JSON.parse(@sender.to_builder.target!) + } + end + + def issue_comment_payload_content + { + "action": "created", + "number": @issue.project_issues_index, + "issue": JSON.parse(@issue.to_builder.target!), + "comment": @changes, + "project": JSON.parse(@issue.project.to_builder.target!), + "sender": JSON.parse(@sender.to_builder.target!) + } + end + + def pull_request_comment_payload_content + { + "action": "created", + "number": @issue.project_issues_index, + "issue": JSON.parse(@issue.to_builder.target!), + "comment": @changes, + "project": JSON.parse(@issue.project.to_builder.target!), + "sender": JSON.parse(@sender.to_builder.target!) + } + end + + + + +end \ No newline at end of file From cd489d3b9767b931c1b6437cb131ed7eec0020a8 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 6 Apr 2023 19:19:54 +0800 Subject: [PATCH 307/438] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9A=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/touch_webhook_job.rb | 41 ++---- app/models/journal.rb | 6 +- app/models/pull_request.rb | 14 ++ app/services/webhook/client.rb | 36 +++-- app/services/webhook/event_client .rb | 130 ------------------- app/services/webhook/issue_client.rb | 75 +++++++++++ app/services/webhook/issue_comment_client.rb | 37 ++++++ app/services/webhook/issue_create_client.rb | 55 -------- app/services/webhook/issue_update_client.rb | 57 -------- app/services/webhook/pull_comment_client.rb | 36 +++++ 10 files changed, 208 insertions(+), 279 deletions(-) delete mode 100644 app/services/webhook/event_client .rb create mode 100644 app/services/webhook/issue_client.rb create mode 100644 app/services/webhook/issue_comment_client.rb delete mode 100644 app/services/webhook/issue_create_client.rb delete mode 100644 app/services/webhook/issue_update_client.rb create mode 100644 app/services/webhook/pull_comment_client.rb diff --git a/app/jobs/touch_webhook_job.rb b/app/jobs/touch_webhook_job.rb index 91155398e..77475098b 100644 --- a/app/jobs/touch_webhook_job.rb +++ b/app/jobs/touch_webhook_job.rb @@ -10,7 +10,7 @@ class TouchWebhookJob < ApplicationJob return if issue.nil? || sender.nil? issue.project.webhooks.each do |webhook| next unless webhook.events["events"]["issues"] - @webhook_task = Webhook::EventClient.new(webhook, issue, sender,"issues","issues").do_request + _, _, @webhook_task = Webhook::IssueClient.new(webhook, issue, sender,"issues",).do_request Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}" end when 'IssueUpdate' @@ -20,7 +20,7 @@ class TouchWebhookJob < ApplicationJob return if issue.nil? || sender.nil? || !changes.is_a?(Hash) issue.project.webhooks.each do |webhook| next unless webhook.events["events"]["issues"] - @webhook_task = Webhook::EventClient.new(webhook, issue, sender, "issues", "issues",changes.stringify_keys).do_request + _, _, @webhook_task = Webhook::IssueClient.new(webhook, issue, sender, "issues", changes.stringify_keys).do_request Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}" end @@ -31,18 +31,18 @@ class TouchWebhookJob < ApplicationJob return if issue.nil? || sender.nil? issue.project.webhooks.each do |webhook| next unless webhook.events["events"]["issue_assign"] - @webhook_task = Webhook::EventClient.new(webhook, issue, sender, "issues", "issue_assign",{assigner_ids: assigner_ids}).do_request + _, _, @webhook_task = Webhook::IssueClient.new(webhook, issue, sender, "issue_assign",{assigner_ids: assigner_ids}.stringify_keys).do_request Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}" end - when 'IssueLable' + when 'IssueLabel' issue_id, sender_id, issue_tag_ids = args[0], args[1], args[2] issue = Issue.find_by_id issue_id sender = User.find_by_id sender_id return if issue.nil? || sender.nil? issue.project.webhooks.each do |webhook| next unless webhook.events["events"]["issue_label"] - @webhook_task = Webhook::EventClient.new(webhook, issue, sender, "issues", "issue_label",{issue_tag_ids: issue_tag_ids}).do_request + _, _, @webhook_task = Webhook::IssueClient.new(webhook, issue, sender, "issue_label",{issue_tag_ids: issue_tag_ids}.stringify_keys).do_request Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}" end @@ -53,37 +53,22 @@ class TouchWebhookJob < ApplicationJob sender = User.find_by_id sender_id return if issue.nil? || sender.nil? || comment.nil? - changes = { - id: comment.id, - user: comment.user.to_builder.target!, - body: comment.notes, - created_on: comment.created_on, - updated_on: comment.updated_on, - } - issue.project.webhooks.each do |webhook| next unless webhook.events["events"]["issue_comment"] - @webhook_task = Webhook::EventClient.new(webhook, issue, sender, "issue_comment", "issue_comment",changes.stringify_keys).do_request + _, _, @webhook_task = Webhook::IssueCommentClient.new(webhook, issue, comment, sender, "issue_comment").do_request Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}" end when 'PullRequestComment' - issue_id, sender_id, comment_id = args[0], args[1], args[2] - issue = Issue.find_by_id issue_id - comment = issue.comment_journals.find_by_id comment_id + pull_id, sender_id, comment_id = args[0], args[1], args[2] + pull = PullRequest.find_by_id pull_id + comment = pull.issue.comment_journals.find_by_id comment_id sender = User.find_by_id sender_id - return if issue.nil? || sender.nil? || comment.nil? - - changes = { - id: comment.id, - user: comment.user.to_builder.target!, - body: comment.notes, - created_on: comment.created_on, - updated_on: comment.updated_on, - } - issue.project.webhooks.each do |webhook| + return if pull.nil? || sender.nil? || comment.nil? + + pull.project.webhooks.each do |webhook| next unless webhook.events["events"]["pull_request_comment"] - @webhook_task = Webhook::EventClient.new(webhook, issue, sender, "issue_comment", "pull_request_comment",changes.stringify_keys).do_request + _, _, @webhook_task = Webhook::PullCommentClient.new(webhook, pull, comment, sender, "pull_request_comment").do_request Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}" end end diff --git a/app/models/journal.rb b/app/models/journal.rb index 5f56b6f78..703a21e82 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -272,5 +272,9 @@ class Journal < ApplicationRecord send_details end - + def to_builder + Jbuilder.new do |journal| + journal.(self, :id, :notes, :comments_count) + end + end end diff --git a/app/models/pull_request.rb b/app/models/pull_request.rb index 270e7dc76..78debfe78 100644 --- a/app/models/pull_request.rb +++ b/app/models/pull_request.rb @@ -117,4 +117,18 @@ class PullRequest < ApplicationRecord JSON.parse file_names end + + def to_builder + Jbuilder.new do |pull| + pull.(self, :id, :gitea_number, :title, :body, :base, :head, :is_original, :comments_count) + pull.created_at self.created_at.strftime("%Y-%m-%d %H:%M") + pull.updated_at self.updated_at.strftime("%Y-%m-%d %H:%M") + pull.user self.user.to_builder + if self.fork_project.present? + pull.fork_project self.fork_project.to_builder + else + pull.fork_project nil + end + end + end end diff --git a/app/services/webhook/client.rb b/app/services/webhook/client.rb index 05e687f13..a64753d05 100644 --- a/app/services/webhook/client.rb +++ b/app/services/webhook/client.rb @@ -6,19 +6,27 @@ module Webhook::Client # hmac.update(message) # sha1 = hmac.digest.unpack('H*').first - attr_reader :uuid, :event, :http_method, :content_type, :url, :secret, :payload_content - attr_accessor :request_content, :response_content + attr_reader :uuid, :event, :http_method, :content_type, :url, :secret, :payload_content, :webhook + attr_accessor :request_content, :response_content, :webhook_task def initialize(opts) @uuid = opts[:uuid] @event = opts[:event] - @http_method = opts[:http_method] - @content_type = opts[:content_type] - @url = opts[:url] - @secret = opts[:secret] + @webhook = opts[:webhook] + @http_method = @webhook.http_method + @content_type = @webhook.content_type + @url = @webhook.url + @secret = @webhook.secret @payload_content = opts[:payload_content] @request_content = {} @response_content = {} + @webhook_task = Gitea::WebhookTask.create( + hook_id: @webhook.id, + uuid: @uuid, + payload_content: @payload_content, + event_type: @event, + is_delivered: true + ) end def do_request @@ -41,13 +49,21 @@ module Webhook::Client @request_content["http_method"] = @http_method @request_content["headers"] = headers - response = RestClient::Request.execute(method: trans_http_method, url: @url, headers: headers, payload: payload_content) {|response, request, result| response } + response = RestClient::Request.execute(method: trans_http_method, url: @url, headers: headers, payload: @webhook_task.read_attribute_before_type_cast("payload_content")) {|response, request, result| response } @response_content["status"] = response.code @response_content["headers"] = response.headers @response_content["body"] = response.body.to_json - return @request_content, @response_content + @webhook_task.update_attributes({ + delivered: Time.now.to_i * 1000000000, + is_succeed: @response_content["status"] < 300, + request_content: @request_content, + response_content: @response_content + }) + + + return @request_content, @response_content, @webhook_task end def request_content @@ -58,6 +74,10 @@ module Webhook::Client @response_content end + def webhook_task + @webhook_task + end + private def signatureSHA1 hmac = OpenSSL::HMAC.new(@secret, OpenSSL::Digest::SHA1.new) diff --git a/app/services/webhook/event_client .rb b/app/services/webhook/event_client .rb deleted file mode 100644 index 28e473be5..000000000 --- a/app/services/webhook/event_client .rb +++ /dev/null @@ -1,130 +0,0 @@ -class Webhook::EventClient - - include Webhook::Client - - attr_accessor :webhook, :issue, :sender - attr_accessor :webhook_task - - def initialize(webhook, issue, sender, event, event_type, changes={}) - @webhook = webhook - @issue = issue - @sender = sender - @event = event - @event_type = event_type - @changes = changes - # 创建webhook task - @webhook_task = Gitea::WebhookTask.create( - hook_id: @webhook.id, - uuid: SecureRandom.uuid, - payload_content: payload_content, - event_type: @event_type, - is_delivered: true - ) - - # 构建client参数 - super({ - uuid: @webhook_task.uuid, - event: @event, - http_method: @webhook.http_method, - content_type: @webhook.content_type, - url: @webhook.url, - secret: @webhook.secret, - payload_content: @webhook_task.read_attribute_before_type_cast("payload_content") - }) - end - - def do_request - request_content, response_content = super - @webhook_task.update_attributes({ - delivered: Time.now.to_i * 1000000000, - is_succeed: response_content["status"] < 300, - request_content: request_content, - response_content: response_content - }) - - @webhook_task - end - - def payload_content - case @event_type - when "issues" - issue_payload_content - when "issue_assign" - issue_assign_payload_content - when "issue_label" - issue_label_payload_content - when "issue_comment" - issue_comment_payload_content - when "pull_request_comment" - pull_request_comment_payload_content - end - end - - def issue_payload_content - if @changes.blank? - { - "action": "opened", - "number": @issue.project_issues_index, - "issue": JSON.parse(@issue.to_builder.target!), - "project": JSON.parse(@issue.project.to_builder.target!), - "sender": JSON.parse(@sender.to_builder.target!) - } - else - { - "action": "edited", - "number": @issue.project_issues_index, - "changes": @changes, - "issue": JSON.parse(@issue.to_builder.target!), - "project": JSON.parse(@issue.project.to_builder.target!), - "sender": JSON.parse(@sender.to_builder.target!) - } - end - end - - def issue_assign_payload_content - { - "action": @changes["assigner_ids"].blank? ? "unassigned" : "assigned", - "number": @issue.project_issues_index, - "issue": JSON.parse(@issue.to_builder.target!), - "assignees": @issue.assignees.map(&:to_builder.target!), - "project": JSON.parse(@issue.project.to_builder.target!), - "sender": JSON.parse(@sender.to_builder.target!) - } - end - - def issue_label_payload_content - { - "action": @changes["issue_tag_ids"].blank? ? "label_cleared" : "label_updated", - "number": @issue.project_issues_index, - "issue": JSON.parse(@issue.to_builder.target!), - "project": JSON.parse(@issue.project.to_builder.target!), - "sender": JSON.parse(@sender.to_builder.target!) - } - end - - def issue_comment_payload_content - { - "action": "created", - "number": @issue.project_issues_index, - "issue": JSON.parse(@issue.to_builder.target!), - "comment": @changes, - "project": JSON.parse(@issue.project.to_builder.target!), - "sender": JSON.parse(@sender.to_builder.target!) - } - end - - def pull_request_comment_payload_content - { - "action": "created", - "number": @issue.project_issues_index, - "issue": JSON.parse(@issue.to_builder.target!), - "comment": @changes, - "project": JSON.parse(@issue.project.to_builder.target!), - "sender": JSON.parse(@sender.to_builder.target!) - } - end - - - - -end \ No newline at end of file diff --git a/app/services/webhook/issue_client.rb b/app/services/webhook/issue_client.rb new file mode 100644 index 000000000..92c85d32e --- /dev/null +++ b/app/services/webhook/issue_client.rb @@ -0,0 +1,75 @@ +class Webhook::IssueClient + + include Webhook::Client + + attr_accessor :webhook, :issue, :sender, :event, :changes + attr_accessor :webhook_task + + def initialize(webhook, issue, sender, event, changes={}) + @webhook = webhook + @issue = issue + @sender = sender + @event = event + @changes = changes + + # 构建client参数 + super({ + uuid: SecureRandom.uuid, + event: @event, + webhook: @webhook, + payload_content: payload_content + }) + end + + def payload_content + case @event + when "issues" + issue_payload_content + when "issue_assign" + issue_assign_payload_content + when "issue_label" + issue_label_payload_content + end + end + + def issue_payload_content + if @changes.blank? + { + "action": "opened", + "number": @issue.project_issues_index, + "issue": JSON.parse(@issue.to_builder.target!), + "project": JSON.parse(@issue.project.to_builder.target!), + "sender": JSON.parse(@sender.to_builder.target!) + } + else + { + "action": "edited", + "number": @issue.project_issues_index, + "changes": @changes, + "issue": JSON.parse(@issue.to_builder.target!), + "project": JSON.parse(@issue.project.to_builder.target!), + "sender": JSON.parse(@sender.to_builder.target!) + } + end + end + + def issue_assign_payload_content + { + "action": @changes["assigner_ids"].blank? ? "unassigned" : "assigned", + "number": @issue.project_issues_index, + "issue": JSON.parse(@issue.to_builder.target!), + "project": JSON.parse(@issue.project.to_builder.target!), + "sender": JSON.parse(@sender.to_builder.target!) + } + end + + def issue_label_payload_content + { + "action": @changes["issue_tag_ids"].blank? ? "label_cleared" : "label_updated", + "number": @issue.project_issues_index, + "issue": JSON.parse(@issue.to_builder.target!), + "project": JSON.parse(@issue.project.to_builder.target!), + "sender": JSON.parse(@sender.to_builder.target!) + } + end +end \ No newline at end of file diff --git a/app/services/webhook/issue_comment_client.rb b/app/services/webhook/issue_comment_client.rb new file mode 100644 index 000000000..a00953a1d --- /dev/null +++ b/app/services/webhook/issue_comment_client.rb @@ -0,0 +1,37 @@ +class Webhook::IssueCommentClient + + include Webhook::Client + + attr_accessor :webhook, :issue, :journal, :sender, :event + + def initialize(webhook, issue, journal, sender, event) + @webhook = webhook + @issue = issue + @journal = journal + @sender = sender + @event = event + + # 构建client参数 + super({ + uuid: SecureRandom.uuid, + event: @event, + webhook: @webhook, + payload_content: payload_content + }) + end + + + + private + + def payload_content + { + "action": "created", + "issue": JSON.parse(@issue.to_builder.target!), + "journal": JSON.parse(@journal.to_builder.target!), + "project": JSON.parse(@issue.project.to_builder.target!), + "sender": JSON.parse(@sender.to_builder.target!), + "is_pull": false + } + end +end \ No newline at end of file diff --git a/app/services/webhook/issue_create_client.rb b/app/services/webhook/issue_create_client.rb deleted file mode 100644 index f222291fb..000000000 --- a/app/services/webhook/issue_create_client.rb +++ /dev/null @@ -1,55 +0,0 @@ -class Webhook::IssueCreateClient - - include Webhook::Client - - attr_accessor :webhook, :issue, :sender - attr_accessor :webhook_task - - def initialize(webhook, issue, sender) - @webhook = webhook - @issue = issue - @sender = sender - # 创建webhook task - @webhook_task = Gitea::WebhookTask.create( - hook_id: @webhook.id, - uuid: SecureRandom.uuid, - payload_content: payload_content, - event_type: "issues", - is_delivered: true - ) - - # 构建client参数 - super({ - uuid: @webhook_task.uuid, - event: "issues", - http_method: @webhook.http_method, - content_type: @webhook.content_type, - url: @webhook.url, - secret: @webhook.secret, - payload_content: @webhook_task.read_attribute_before_type_cast("payload_content") - }) - end - - def do_request - request_content, response_content = super - @webhook_task.update_attributes({ - delivered: Time.now.to_i * 1000000000, - is_succeed: response_content["status"] < 300, - request_content: request_content, - response_content: response_content - }) - - @webhook_task - end - - def payload_content - { - "action": "opened", - "number": @issue.project_issues_index, - "issue": JSON.parse(@issue.to_builder.target!), - "project": JSON.parse(@issue.project.to_builder.target!), - "sender": JSON.parse(@sender.to_builder.target!) - } - end - -end \ No newline at end of file diff --git a/app/services/webhook/issue_update_client.rb b/app/services/webhook/issue_update_client.rb deleted file mode 100644 index ff9926006..000000000 --- a/app/services/webhook/issue_update_client.rb +++ /dev/null @@ -1,57 +0,0 @@ -class Webhook::IssueUpdateClient - - include Webhook::Client - - attr_accessor :webhook, :issue, :sender, :changes - attr_accessor :webhook_task - - def initialize(webhook, issue, sender, changes={}) - @webhook = webhook - @issue = issue - @sender = sender - @changes = changes - # 创建webhook task - @webhook_task = Gitea::WebhookTask.create( - hook_id: @webhook.id, - uuid: SecureRandom.uuid, - payload_content: payload_content, - event_type: "issues", - is_delivered: true - ) - - # 构建client参数 - super({ - uuid: @webhook_task.uuid, - event: "issues", - http_method: @webhook.http_method, - content_type: @webhook.content_type, - url: @webhook.url, - secret: @webhook.secret, - payload_content: @webhook_task.read_attribute_before_type_cast("payload_content") - }) - end - - def do_request - request_content, response_content = super - @webhook_task.update_attributes({ - delivered: Time.now.to_i * 1000000000, - is_succeed: response_content["status"] < 300, - request_content: request_content, - response_content: response_content - }) - - @webhook_task - end - - def payload_content - { - "action": "edited", - "number": @issue.project_issues_index, - "changes": @changes, - "issue": JSON.parse(@issue.to_builder.target!), - "project": JSON.parse(@issue.project.to_builder.target!), - "sender": JSON.parse(@sender.to_builder.target!) - } - end - -end \ No newline at end of file diff --git a/app/services/webhook/pull_comment_client.rb b/app/services/webhook/pull_comment_client.rb new file mode 100644 index 000000000..cb6c144f1 --- /dev/null +++ b/app/services/webhook/pull_comment_client.rb @@ -0,0 +1,36 @@ +class Webhook::PullCommentClient + include Webhook::Client + + attr_accessor :webhook, :pull, :journal, :sender, :event + + def initialize(webhook, pull, journal, sender, event) + @webhook = webhook + @pull = pull + @journal = journal + @sender = sender + @event = event + + # 构建client参数 + super({ + uuid: SecureRandom.uuid, + event: @event, + webhook: @webhook, + payload_content: payload_content + }) + end + + private + + def payload_content + { + "action": "created", + "number": @pull.gitea_number, + "pull_request": JSON.parse(@pull.to_builder.target!), + "comment": JSON.parse(@journal.to_builder.target!), + "project": JSON.parse(@pull.project.to_builder.target!), + "sender": JSON.parse(@sender.to_builder.target!), + "is_pull": true + } + end + +end \ No newline at end of file From 39c2166c12ede068700b3dff33e11196832e6b28 Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Fri, 7 Apr 2023 09:50:35 +0800 Subject: [PATCH 308/438] update pr model and webhook --- app/jobs/touch_webhook_job.rb | 4 ++-- app/models/pull_request.rb | 25 ++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/jobs/touch_webhook_job.rb b/app/jobs/touch_webhook_job.rb index 77475098b..cff8e3aa5 100644 --- a/app/jobs/touch_webhook_job.rb +++ b/app/jobs/touch_webhook_job.rb @@ -60,8 +60,8 @@ class TouchWebhookJob < ApplicationJob end when 'PullRequestComment' - pull_id, sender_id, comment_id = args[0], args[1], args[2] - pull = PullRequest.find_by_id pull_id + issue_id, sender_id, comment_id = args[0], args[1], args[2] + pull = Issue.find_by_id(issue_id).try(:pull_request) comment = pull.issue.comment_journals.find_by_id comment_id sender = User.find_by_id sender_id return if pull.nil? || sender.nil? || comment.nil? diff --git a/app/models/pull_request.rb b/app/models/pull_request.rb index 78debfe78..f033844cd 100644 --- a/app/models/pull_request.rb +++ b/app/models/pull_request.rb @@ -119,16 +119,35 @@ class PullRequest < ApplicationRecord end def to_builder - Jbuilder.new do |pull| + Jbuilder.new do |pull| pull.(self, :id, :gitea_number, :title, :body, :base, :head, :is_original, :comments_count) - pull.created_at self.created_at.strftime("%Y-%m-%d %H:%M") - pull.updated_at self.updated_at.strftime("%Y-%m-%d %H:%M") pull.user self.user.to_builder if self.fork_project.present? pull.fork_project self.fork_project.to_builder else pull.fork_project nil end + pull.created_at self.created_at.strftime("%Y-%m-%d %H:%M") + pull.updated_at self.updated_at.strftime("%Y-%m-%d %H:%M") + pull.status self.pr_status + pull.url self.pr_url + end + end + + def pr_url + return nil if self.project.nil? + "#{Rails.application.config_for(:configuration)['platform_url']}/#{self.project.owner.login}/#{self.project.name}/pulls/#{self.id}" + end + + def pr_status + case status + when 0 + "OPEN" + when 1 + "MERGED" + when 2 + "CLOSED" end end + end From 661d1c2c06b2e22d457df1e44f70b4e3b9dfe629 Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Fri, 7 Apr 2023 09:56:33 +0800 Subject: [PATCH 309/438] update touch webhook --- app/jobs/touch_webhook_job.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/jobs/touch_webhook_job.rb b/app/jobs/touch_webhook_job.rb index cff8e3aa5..d0d9ad9e3 100644 --- a/app/jobs/touch_webhook_job.rb +++ b/app/jobs/touch_webhook_job.rb @@ -61,9 +61,10 @@ class TouchWebhookJob < ApplicationJob when 'PullRequestComment' issue_id, sender_id, comment_id = args[0], args[1], args[2] - pull = Issue.find_by_id(issue_id).try(:pull_request) - comment = pull.issue.comment_journals.find_by_id comment_id + issue = Issue.find_by_id(issue_id) + comment = issue.comment_journals.find_by_id comment_id sender = User.find_by_id sender_id + pull = issue.try(:pull_request) return if pull.nil? || sender.nil? || comment.nil? pull.project.webhooks.each do |webhook| From ee2082463943a79cdcbd9fb108c279a0397b177b Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 7 Apr 2023 11:44:30 +0800 Subject: [PATCH 310/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=9C=AA?= =?UTF-8?q?=E4=BC=A0=E5=BD=93=E5=89=8D=E7=94=A8=E6=88=B7id?= 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/update_service.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index b0b1b05b0..5304c5026 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -70,8 +70,8 @@ class Api::V1::Issues::CreateService < ApplicationService # 触发webhook TouchWebhookJob.perform_later('IssueCreate', @created_issue&.id, current_user.id) - TouchWebhookJob.perform_later('IssueLable', @created_issue&.id, issue_tag_ids) - TouchWebhookJob.perform_later('IssueAssign', @created_issue&.id, assigner_ids) + TouchWebhookJob.perform_later('IssueLabel', @created_issue&.id, current_user.id, issue_tag_ids) + TouchWebhookJob.perform_later('IssueAssign', @created_issue&.id, current_user.id, assigner_ids) unlock("Api::V1::Issues::CreateService:#{project.id}") # 结束写数据,解锁 end diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 153ea32e0..758dc9e43 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -79,8 +79,8 @@ class Api::V1::Issues::UpdateService < ApplicationService # 触发webhook TouchWebhookJob.perform_later('IssueCreate', @updated_issue&.id, current_user.id, previous_issue_changes) - TouchWebhookJob.perform_later('IssueLable', @updated_issue&.id, issue_tag_ids) - TouchWebhookJob.perform_later('IssueAssign', @updated_issue&.id, assigner_ids) + TouchWebhookJob.perform_later('IssueLabel', @updated_issue&.id, current_user.id, issue_tag_ids) + TouchWebhookJob.perform_later('IssueAssign', @updated_issue&.id, current_user.id, assigner_ids) unlock("Api::V1::Issues::UpdateService:#{project.id}:#{issue.id}") return @updated_issue From 1a3a7967fd619b654cc5e75bd98f9f18857719bd Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 7 Apr 2023 14:28:21 +0800 Subject: [PATCH 311/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Apayload?= =?UTF-8?q?=E4=B8=AD=E8=BF=87=E6=BB=A4emoji?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/project.rb | 2 +- app/models/user.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index 02844c3bc..1ac3744bd 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -451,7 +451,7 @@ class Project < ApplicationRecord Jbuilder.new do |project| project.id self.id project.identifier self.identifier - project.name self.name + project.name self.name.to_s.each_char.select { |c| c.bytes.first < 240 }.join('') project.description Nokogiri::HTML(self.description).text project.visits self.visits project.praises_count self.praises_count.to_i diff --git a/app/models/user.rb b/app/models/user.rb index 70de1fc64..874da712a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -862,7 +862,7 @@ class User < Owner def to_builder Jbuilder.new do |user| user.(self, :id, :login) - user.name self.real_name + user.name self.real_name.to_s.each_char.select { |c| c.bytes.first < 240 }.join('') user.email self.mail user.image_url self.get_letter_avatar_url end From 7f0989f69d99b3ed50fbd262c2634f7adb4afd3b Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 7 Apr 2023 14:54:06 +0800 Subject: [PATCH 312/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Apayload?= =?UTF-8?q?=E4=B8=AD=E8=BF=87=E6=BB=A4emoji?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/project.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 1ac3744bd..52b729a85 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -475,7 +475,7 @@ class Project < ApplicationRecord project.image_url render_educoder_avatar_url(self.project_educoder) else user = self.owner - project.name user.try(:show_real_name) + project.name user.try(:show_real_name).to_s.each_char.select { |c| c.bytes.first < 240 }.join('') project.type user&.type project.login user.login project.image_url user.get_letter_avatar_url From afa1cdf8429df2eace5cf3dfcc1e9cbab236428d Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 11 Apr 2023 11:52:03 +0800 Subject: [PATCH 313/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E8=AF=84?= =?UTF-8?q?=E8=AE=BA=E4=B8=B0=E5=AF=8C=E6=9B=B4=E6=96=B0=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=EF=BC=8Cissue=E4=BA=8B=E4=BB=B6=E7=B2=92?= =?UTF-8?q?=E5=BA=A6=E6=9B=B4=E7=BB=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/issues/journals_controller.rb | 1 + app/controllers/journals_controller.rb | 3 ++- app/jobs/touch_webhook_job.rb | 16 ++++++++-------- app/models/journal.rb | 6 ++++++ app/services/api/v1/issues/create_service.rb | 4 ++-- .../api/v1/issues/journals/create_service.rb | 2 +- .../api/v1/issues/journals/update_service.rb | 1 + app/services/api/v1/issues/update_service.rb | 6 +++--- app/services/webhook/issue_comment_client.rb | 18 +++++++++++++----- app/services/webhook/pull_comment_client.rb | 19 +++++++++++++------ 10 files changed, 50 insertions(+), 26 deletions(-) diff --git a/app/controllers/api/v1/issues/journals_controller.rb b/app/controllers/api/v1/issues/journals_controller.rb index cee2b81e8..af23aa686 100644 --- a/app/controllers/api/v1/issues/journals_controller.rb +++ b/app/controllers/api/v1/issues/journals_controller.rb @@ -27,6 +27,7 @@ class Api::V1::Issues::JournalsController < Api::V1::BaseController end def destroy + TouchWebhookJob.perform_later('IssueComment', @issue&.id, current_user.id, @journal.id, 'deleted', JSON.parse(@journal.to_builder.target!)) if @journal.destroy! render_ok else diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rb index e539ec2cd..7bade2797 100644 --- a/app/controllers/journals_controller.rb +++ b/app/controllers/journals_controller.rb @@ -46,7 +46,7 @@ class JournalsController < ApplicationController end Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}" AtmeService.call(current_user, @atme_receivers, journal) if @atme_receivers.size > 0 - TouchWebhookJob.perform_later('PullRequestComment', @issue&.id, current_user.id, journal.id) + TouchWebhookJob.perform_later('PullRequestComment', @issue&.id, current_user.id, journal.id, 'created', {}) # @issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "journal") render :json => { status: 0, message: "评论成功", id: journal.id} # normal_status(0, "评论成功") @@ -62,6 +62,7 @@ class JournalsController < ApplicationController def destroy if @journal.destroy #如果有子评论,子评论删除吗? + TouchWebhookJob.perform_later('PullRequestComment', @issue&.id, current_user.id, @journal.id, 'deleted', JSON.parse(@journal.to_builder.target!)) Journal.children_journals(@journal.id).destroy_all normal_status(0, "评论删除成功") else diff --git a/app/jobs/touch_webhook_job.rb b/app/jobs/touch_webhook_job.rb index d0d9ad9e3..061d5ece7 100644 --- a/app/jobs/touch_webhook_job.rb +++ b/app/jobs/touch_webhook_job.rb @@ -10,14 +10,14 @@ class TouchWebhookJob < ApplicationJob return if issue.nil? || sender.nil? issue.project.webhooks.each do |webhook| next unless webhook.events["events"]["issues"] - _, _, @webhook_task = Webhook::IssueClient.new(webhook, issue, sender,"issues",).do_request + _, _, @webhook_task = Webhook::IssueClient.new(webhook, issue, sender,"issues").do_request Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}" end when 'IssueUpdate' issue_id, sender_id, changes = args[0], args[1], args[2] issue = Issue.find_by_id issue_id sender = User.find_by_id sender_id - return if issue.nil? || sender.nil? || !changes.is_a?(Hash) + return if issue.nil? || sender.nil? || !changes.is_a?(Hash) || changes.blank? issue.project.webhooks.each do |webhook| next unless webhook.events["events"]["issues"] _, _, @webhook_task = Webhook::IssueClient.new(webhook, issue, sender, "issues", changes.stringify_keys).do_request @@ -47,29 +47,29 @@ class TouchWebhookJob < ApplicationJob end when 'IssueComment' - issue_id, sender_id, comment_id = args[0], args[1], args[2] + issue_id, sender_id, comment_id, action_type, comment_json = args[0], args[1], args[2], args[3], args[4] issue = Issue.find_by_id issue_id comment = issue.comment_journals.find_by_id comment_id sender = User.find_by_id sender_id - return if issue.nil? || sender.nil? || comment.nil? + return if issue.nil? || sender.nil? issue.project.webhooks.each do |webhook| next unless webhook.events["events"]["issue_comment"] - _, _, @webhook_task = Webhook::IssueCommentClient.new(webhook, issue, comment, sender, "issue_comment").do_request + _, _, @webhook_task = Webhook::IssueCommentClient.new(webhook, issue, comment, sender, "issue_comment", action_type, comment_json).do_request Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}" end when 'PullRequestComment' - issue_id, sender_id, comment_id = args[0], args[1], args[2] + issue_id, sender_id, comment_id, action_type, comment_json = args[0], args[1], args[2], args[3], args[4] issue = Issue.find_by_id(issue_id) comment = issue.comment_journals.find_by_id comment_id sender = User.find_by_id sender_id pull = issue.try(:pull_request) - return if pull.nil? || sender.nil? || comment.nil? + return if pull.nil? || sender.nil? pull.project.webhooks.each do |webhook| next unless webhook.events["events"]["pull_request_comment"] - _, _, @webhook_task = Webhook::PullCommentClient.new(webhook, pull, comment, sender, "pull_request_comment").do_request + _, _, @webhook_task = Webhook::PullCommentClient.new(webhook, pull, comment, sender, "pull_request_comment", action_type, comment_json).do_request Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}" end end diff --git a/app/models/journal.rb b/app/models/journal.rb index 703a21e82..ce69c1f3a 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -275,6 +275,12 @@ class Journal < ApplicationRecord def to_builder Jbuilder.new do |journal| journal.(self, :id, :notes, :comments_count) + if self.parent_journal.present? + journal.parent_journal self.parent_journal.to_builder + end + if self.reply_journal.present? + journal.reply_journal self.reply_journal.to_builder + end end end end diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index 5304c5026..ce24c8b49 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -70,8 +70,8 @@ class Api::V1::Issues::CreateService < ApplicationService # 触发webhook TouchWebhookJob.perform_later('IssueCreate', @created_issue&.id, current_user.id) - TouchWebhookJob.perform_later('IssueLabel', @created_issue&.id, current_user.id, issue_tag_ids) - TouchWebhookJob.perform_later('IssueAssign', @created_issue&.id, current_user.id, assigner_ids) + TouchWebhookJob.perform_later('IssueLabel', @created_issue&.id, current_user.id, issue_tag_ids) unless issue_tag_ids.blank? + TouchWebhookJob.perform_later('IssueAssign', @created_issue&.id, current_user.id, assigner_ids) unless assigner_ids.blank? unlock("Api::V1::Issues::CreateService:#{project.id}") # 结束写数据,解锁 end diff --git a/app/services/api/v1/issues/journals/create_service.rb b/app/services/api/v1/issues/journals/create_service.rb index 568deecdd..3121a635d 100644 --- a/app/services/api/v1/issues/journals/create_service.rb +++ b/app/services/api/v1/issues/journals/create_service.rb @@ -41,7 +41,7 @@ class Api::V1::Issues::Journals::CreateService < ApplicationService # @信息发送 AtmeService.call(current_user, @atme_receivers, @created_journal) unless receivers_login.blank? - TouchWebhookJob.perform_later('IssueComment', @issue&.id, @current_user.id, @created_journal.id) + TouchWebhookJob.perform_later('IssueComment', @issue&.id, @current_user.id, @created_journal.id, 'created', {}) unlock("Api::V1::Issues::Journals::CreateService:#{@issue.id}") @created_journal diff --git a/app/services/api/v1/issues/journals/update_service.rb b/app/services/api/v1/issues/journals/update_service.rb index e5031aafe..0b56dd303 100644 --- a/app/services/api/v1/issues/journals/update_service.rb +++ b/app/services/api/v1/issues/journals/update_service.rb @@ -38,6 +38,7 @@ class Api::V1::Issues::Journals::UpdateService < ApplicationService # @信息发送 AtmeService.call(current_user, @atme_receivers, @created_journal) unless receivers_login.blank? + TouchWebhookJob.perform_later('IssueComment', @issue&.id, @current_user.id, @updated_journal.id, 'edited', @updated_journal.previous_changes.stringify_keys) unlock("Api::V1::Issues::Journals::UpdateService:#{@issue.id}:#{@journal.id}") diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 758dc9e43..9dfaaa447 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -78,9 +78,9 @@ class Api::V1::Issues::UpdateService < ApplicationService end # 触发webhook - TouchWebhookJob.perform_later('IssueCreate', @updated_issue&.id, current_user.id, previous_issue_changes) - TouchWebhookJob.perform_later('IssueLabel', @updated_issue&.id, current_user.id, issue_tag_ids) - TouchWebhookJob.perform_later('IssueAssign', @updated_issue&.id, current_user.id, assigner_ids) + TouchWebhookJob.perform_later('IssueUpdate', @updated_issue&.id, current_user.id, previous_issue_changes.except(:issue_tags_value, :assigned_to_id)) + TouchWebhookJob.perform_later('IssueLabel', @updated_issue&.id, current_user.id, issue_tag_ids) unless issue_tag_ids.nil? + TouchWebhookJob.perform_later('IssueAssign', @updated_issue&.id, current_user.id, assigner_ids) unless assigner_ids.nil? unlock("Api::V1::Issues::UpdateService:#{project.id}:#{issue.id}") return @updated_issue diff --git a/app/services/webhook/issue_comment_client.rb b/app/services/webhook/issue_comment_client.rb index a00953a1d..1881217ec 100644 --- a/app/services/webhook/issue_comment_client.rb +++ b/app/services/webhook/issue_comment_client.rb @@ -2,14 +2,16 @@ class Webhook::IssueCommentClient include Webhook::Client - attr_accessor :webhook, :issue, :journal, :sender, :event + attr_accessor :webhook, :issue, :journal, :sender, :event, :action_type, :comment_json - def initialize(webhook, issue, journal, sender, event) + def initialize(webhook, issue, journal, sender, event, action_type, comment_json={}) @webhook = webhook @issue = issue @journal = journal @sender = sender @event = event + @action_type = action_type + @comment_json = comment_json # 构建client参数 super({ @@ -25,13 +27,19 @@ class Webhook::IssueCommentClient private def payload_content - { - "action": "created", + payload_content = { + "action": @action_type, "issue": JSON.parse(@issue.to_builder.target!), - "journal": JSON.parse(@journal.to_builder.target!), + "journal": @journal.present? ? JSON.parse(@journal.to_builder.target!) : @comment_json, "project": JSON.parse(@issue.project.to_builder.target!), "sender": JSON.parse(@sender.to_builder.target!), "is_pull": false } + + payload_content.merge!({ + "changes": @comment_json, + }) if @action_type == "edited" + + payload_content end end \ No newline at end of file diff --git a/app/services/webhook/pull_comment_client.rb b/app/services/webhook/pull_comment_client.rb index cb6c144f1..dde9d983f 100644 --- a/app/services/webhook/pull_comment_client.rb +++ b/app/services/webhook/pull_comment_client.rb @@ -1,15 +1,16 @@ class Webhook::PullCommentClient include Webhook::Client - attr_accessor :webhook, :pull, :journal, :sender, :event + attr_accessor :webhook, :pull, :journal, :sender, :event, :action_type, :comment_json - def initialize(webhook, pull, journal, sender, event) + def initialize(webhook, pull, journal, sender, event, action_type='created', comment_json={}) @webhook = webhook @pull = pull @journal = journal @sender = sender @event = event - + @action_type = action_type + @comment_json = comment_json # 构建client参数 super({ uuid: SecureRandom.uuid, @@ -22,15 +23,21 @@ class Webhook::PullCommentClient private def payload_content - { - "action": "created", + payload_content = { + "action": @action_type, "number": @pull.gitea_number, "pull_request": JSON.parse(@pull.to_builder.target!), - "comment": JSON.parse(@journal.to_builder.target!), + "comment": @journal.present? ? JSON.parse(@journal.to_builder.target!) : @comment_json, "project": JSON.parse(@pull.project.to_builder.target!), "sender": JSON.parse(@sender.to_builder.target!), "is_pull": true } + + payload_content.merge!({ + "changes": @comment_json + }) if @action_type == "edited" + + payload_content end end \ No newline at end of file From bea2831149b7f5f80894fd7c4c1147af0689050b Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 11 Apr 2023 13:55:25 +0800 Subject: [PATCH 314/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=9B=B4?= =?UTF-8?q?=E6=94=B9issue=E8=AF=84=E8=AE=BA=E4=BA=8B=E4=BB=B6=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/touch_webhook_job.rb | 2 ++ app/services/api/v1/issues/journals/update_service.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/jobs/touch_webhook_job.rb b/app/jobs/touch_webhook_job.rb index 061d5ece7..8319a9d66 100644 --- a/app/jobs/touch_webhook_job.rb +++ b/app/jobs/touch_webhook_job.rb @@ -52,6 +52,7 @@ class TouchWebhookJob < ApplicationJob comment = issue.comment_journals.find_by_id comment_id sender = User.find_by_id sender_id return if issue.nil? || sender.nil? + return if action_type == 'edited' && comment_json.blank? issue.project.webhooks.each do |webhook| next unless webhook.events["events"]["issue_comment"] @@ -66,6 +67,7 @@ class TouchWebhookJob < ApplicationJob sender = User.find_by_id sender_id pull = issue.try(:pull_request) return if pull.nil? || sender.nil? + return if action_type == 'edited' && comment_json.blank? pull.project.webhooks.each do |webhook| next unless webhook.events["events"]["pull_request_comment"] diff --git a/app/services/api/v1/issues/journals/update_service.rb b/app/services/api/v1/issues/journals/update_service.rb index 0b56dd303..2e27d53ea 100644 --- a/app/services/api/v1/issues/journals/update_service.rb +++ b/app/services/api/v1/issues/journals/update_service.rb @@ -38,7 +38,7 @@ class Api::V1::Issues::Journals::UpdateService < ApplicationService # @信息发送 AtmeService.call(current_user, @atme_receivers, @created_journal) unless receivers_login.blank? - TouchWebhookJob.perform_later('IssueComment', @issue&.id, @current_user.id, @updated_journal.id, 'edited', @updated_journal.previous_changes.stringify_keys) + TouchWebhookJob.perform_later('IssueComment', @issue&.id, @current_user.id, @updated_journal.id, 'edited', @updated_journal.previous_changes.slice(:notes).stringify_keys) unlock("Api::V1::Issues::Journals::UpdateService:#{@issue.id}:#{@journal.id}") From ef101553875ba9319510c28d0cca2b1d205bd798 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 11 Apr 2023 13:58:42 +0800 Subject: [PATCH 315/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Aevents?= =?UTF-8?q?=E5=9B=9E=E5=88=B0=E5=8E=9F=E6=9D=A5=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../projects/webhooks/_simple_gitea_detail.json.jbuilder | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/app/views/api/v1/projects/webhooks/_simple_gitea_detail.json.jbuilder b/app/views/api/v1/projects/webhooks/_simple_gitea_detail.json.jbuilder index 09f9565a4..43d602d1f 100644 --- a/app/views/api/v1/projects/webhooks/_simple_gitea_detail.json.jbuilder +++ b/app/views/api/v1/projects/webhooks/_simple_gitea_detail.json.jbuilder @@ -3,12 +3,7 @@ json.type webhook["type"] json.content_type webhook['config']['content_type'] json.http_method webhook['config']['http_method'] json.url webhook['config']['url'] -event = webhook.events -if event["send_everything"] - json.events event["events"].keys.collect{|i| %w(pull_request issues).include?(i) ? i + "_only" : i} -else - json.events event["events"].select{|k, v| v}.keys.collect{|i| %w(pull_request issues).include?(i) ? i + "_only" : i} -end +json.events webhook["events"] json.active webhook['active'] json.branch_filter webhook['branch_filter'] json.created_at format_time(webhook['created_at'].to_time) \ No newline at end of file From 8663efc73bf9bc38b21813641e9b03e5aa8d621b Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 11 Apr 2023 14:10:24 +0800 Subject: [PATCH 316/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E6=95=B0=E6=8D=AE=E5=BB=B6=E8=BF=9F5=E7=A7=92?= =?UTF-8?q?=E8=A7=A6=E5=8F=91webhook?= 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/journals/create_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 ce24c8b49..b930a91b1 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -69,7 +69,7 @@ class Api::V1::Issues::CreateService < ApplicationService end # 触发webhook - TouchWebhookJob.perform_later('IssueCreate', @created_issue&.id, current_user.id) + TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueCreate', @created_issue&.id, current_user.id) TouchWebhookJob.perform_later('IssueLabel', @created_issue&.id, current_user.id, issue_tag_ids) unless issue_tag_ids.blank? TouchWebhookJob.perform_later('IssueAssign', @created_issue&.id, current_user.id, assigner_ids) unless assigner_ids.blank? unlock("Api::V1::Issues::CreateService:#{project.id}") # 结束写数据,解锁 diff --git a/app/services/api/v1/issues/journals/create_service.rb b/app/services/api/v1/issues/journals/create_service.rb index 3121a635d..e60acb8b3 100644 --- a/app/services/api/v1/issues/journals/create_service.rb +++ b/app/services/api/v1/issues/journals/create_service.rb @@ -41,7 +41,7 @@ class Api::V1::Issues::Journals::CreateService < ApplicationService # @信息发送 AtmeService.call(current_user, @atme_receivers, @created_journal) unless receivers_login.blank? - TouchWebhookJob.perform_later('IssueComment', @issue&.id, @current_user.id, @created_journal.id, 'created', {}) + TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueComment', @issue&.id, @current_user.id, @created_journal.id, 'created', {}) unlock("Api::V1::Issues::Journals::CreateService:#{@issue.id}") @created_journal From f64afb8f55d2ce9ef00a2c0011c237fedaa4b41b Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 11 Apr 2023 14:11:17 +0800 Subject: [PATCH 317/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E6=95=B0=E6=8D=AE=E5=BB=B6=E8=BF=9F5=E7=A7=92?= =?UTF-8?q?=E8=A7=A6=E5=8F=91webhook?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/journals_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rb index 7bade2797..ff214774a 100644 --- a/app/controllers/journals_controller.rb +++ b/app/controllers/journals_controller.rb @@ -46,7 +46,7 @@ class JournalsController < ApplicationController end Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}" AtmeService.call(current_user, @atme_receivers, journal) if @atme_receivers.size > 0 - TouchWebhookJob.perform_later('PullRequestComment', @issue&.id, current_user.id, journal.id, 'created', {}) + TouchWebhookJob.set(wait: 5.seconds).perform_later('PullRequestComment', @issue&.id, current_user.id, journal.id, 'created', {}) # @issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "journal") render :json => { status: 0, message: "评论成功", id: journal.id} # normal_status(0, "评论成功") From ccede16716d98a0ac01fb05fbae74fb0cf8b64ef Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 11 Apr 2023 14:41:12 +0800 Subject: [PATCH 318/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Aevents?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E6=95=B0=E6=8D=AE=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/webhooks/_simple_gitea_detail.json.jbuilder | 2 +- app/views/projects/webhooks/create.json.jbuilder | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/api/v1/projects/webhooks/_simple_gitea_detail.json.jbuilder b/app/views/api/v1/projects/webhooks/_simple_gitea_detail.json.jbuilder index 43d602d1f..1eab68518 100644 --- a/app/views/api/v1/projects/webhooks/_simple_gitea_detail.json.jbuilder +++ b/app/views/api/v1/projects/webhooks/_simple_gitea_detail.json.jbuilder @@ -3,7 +3,7 @@ json.type webhook["type"] json.content_type webhook['config']['content_type'] json.http_method webhook['config']['http_method'] json.url webhook['config']['url'] -json.events webhook["events"] +json.events webhook["events"].collect{|i| %w(pull_request issues).include?(i) ? i + "_only" : i} json.active webhook['active'] json.branch_filter webhook['branch_filter'] json.created_at format_time(webhook['created_at'].to_time) \ No newline at end of file diff --git a/app/views/projects/webhooks/create.json.jbuilder b/app/views/projects/webhooks/create.json.jbuilder index 6d6dde31f..26ccd52fa 100644 --- a/app/views/projects/webhooks/create.json.jbuilder +++ b/app/views/projects/webhooks/create.json.jbuilder @@ -2,6 +2,6 @@ json.id @webhook["id"] json.type @webhook["type"] json.content_type @webhook["config"]["content_type"] json.url @webhook["config"]["url"] -json.events @webhook["events"] +json.events @webhook["events"].collect{|i| %w(pull_request issues).include?(i) ? i + "_only" : i} json.active @webhook["active"] json.create_time @webhook["created_at"].to_time.strftime("%Y-%m-%d %H:%M:%S") \ No newline at end of file From 083085051850d6a6e656ca7c010b58230c3cae4d Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 12 Apr 2023 14:51:27 +0800 Subject: [PATCH 319/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E6=96=87=E4=BB=B6=E4=BB=A5=E5=8F=8A=E6=9F=A5=E7=9C=8B?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 11 +++++++---- app/controllers/repositories_controller.rb | 2 +- app/helpers/projects_helper.rb | 2 +- .../repositories/_simple_entry.json.jbuilder | 17 +++++++++-------- config/routes.rb | 2 +- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 941dcf35f..0cdba3847 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -31,14 +31,17 @@ class AttachmentsController < ApplicationController def get_file normal_status(-1, "参数缺失") if params[:download_url].blank? - url = base_url.starts_with?("https:") ? URI.encode(params[:download_url].to_s.gsub("http:", "https:")) : URI.encode(params[:download_url].to_s) + url = base_url.starts_with?("https:") ? params[:download_url].to_s.gsub("http:", "https:") : params[:download_url].to_s if url.starts_with?(base_url) && !url.starts_with?("#{base_url}/repo") domain = GiteaService.gitea_config[:domain] api_url = GiteaService.gitea_config[:base_url] - url = ("/repos"+url.split(base_url + "/api")[1]).gsub('?filepath=', '/').gsub('&', '?') - request_url = [domain, api_url, url, "?ref=#{params[:ref]}&access_token=#{User.where(admin: true).take&.gitea_token}"].join + url = ("/repos"+url.split(base_url + "/api")[1]) + filepath, ref = url.split("/")[-1].split("?") + url.gsub!(url.split("/")[-1], '') + puts filepath + request_url = [domain, api_url, url, CGI.escape(filepath), "?ref=#{CGI.escape(ref.split('ref=')[1])}&access_token=#{User.where(admin: true).take&.gitea_token}"].join response = Faraday.get(request_url) - filename = url.to_s.split("/").pop() + filename = filepath else response = Faraday.get(url) filename = params[:download_url].to_s.split("/").pop() diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 5d8745397..f80e00b6f 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -273,7 +273,7 @@ class RepositoriesController < ApplicationController domain = GiteaService.gitea_config[:domain] api_url = GiteaService.gitea_config[:base_url] - url = "/repos/#{@owner.login}/#{@repository.identifier}/raw/#{Addressable::URI.escape(params[:filepath])}?ref=#{Addressable::URI.escape(params[:ref])}" + url = "/repos/#{@owner.login}/#{@repository.identifier}/raw/#{CGI.escape(params[:filepath])}?ref=#{CGI.escape(params[:ref])}" file_path = [domain, api_url, url].join file_path = [file_path, "access_token=#{@owner&.gitea_token}"].join("&") diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 5ed680ba3..aa905ebc9 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -22,7 +22,7 @@ module ProjectsHelper end def render_download_file_url(owner, repository, filepath, ref) - [base_url, "/api/#{owner&.login}/#{repository.identifier}/raw?filepath=#{filepath}&ref=#{ref}"].join + [base_url, "/api/#{owner&.login}/#{repository.identifier}/raw/#{CGI.escape(filepath)}?ref=#{CGI.escape(ref)}"].join end def render_http_url(project) diff --git a/app/views/repositories/_simple_entry.json.jbuilder b/app/views/repositories/_simple_entry.json.jbuilder index 42342f07b..9ad5e3fc2 100644 --- a/app/views/repositories/_simple_entry.json.jbuilder +++ b/app/views/repositories/_simple_entry.json.jbuilder @@ -17,14 +17,15 @@ if @project.forge? json.content (direct_download || image_type || is_dir) ? nil : decode64_content(entry, @owner, @repository, @ref, @path) json.target entry['target'] - download_url = - if image_type - dir_path = [@owner.login, @repository.identifier, "raw/branch", @ref].join('/') - is_dir ? "" : render_download_image_url(dir_path, entry['path'], decode64_content(entry, @owner, @repository, @ref)) - else - # entry['download_url'] - is_dir ? "" : render_download_file_url(@owner, @repository, entry['path'].to_s, @ref) - end + download_url = is_dir ? "" : render_download_file_url(@owner, @repository, entry['path'].to_s, @ref) + # if image_type + # # dir_path = [@owner.login, @repository.identifier, "raw/branch", @ref].join('/') + # # is_dir ? "" : render_download_image_url(dir_path, entry['path'], decode64_content(entry, @owner, @repository, @ref)) + # is_dir ? "" : render_gitea_raw_url(entry['download_url']) + # else + # # entry['download_url'] + # is_dir ? "" : render_download_file_url(@owner, @repository, entry['path'].to_s, @ref) + # end json.download_url download_url json.direct_download direct_download diff --git a/config/routes.rb b/config/routes.rb index 7e69c2e38..0123654cd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -507,7 +507,7 @@ Rails.application.routes.draw do get 'readme' get 'languages' get 'archive/:archive', to: 'repositories#archive', as: "archive", constraints: { archive: /.+/, format: /(zip|gzip)/ } - get 'raw', to: 'repositories#raw', as: "raw" + get 'raw/*filepath', to: 'repositories#raw', as: "raw", constraints: { filepath: /.+/} end end From 3769e13c1c127831ecd240ecf171f9aa3c7c0083 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 12 Apr 2023 16:12:52 +0800 Subject: [PATCH 320/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Aselect?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=A2=9E=E5=8A=A0created=5Fon?= 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 113c86a8c..3b3607c14 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, :updated_on)) + @issues = kaminary_select_paginate(@object_result[:data].select(:id, :subject, :project_issues_index, :updated_on, :created_on)) else @issues = kaminari_paginate(@object_result[:data]) end From 09d9f9a94e2561208cee7aeefb7dbba786625078 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 12 Apr 2023 16:17:46 +0800 Subject: [PATCH 321/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Aselect?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=A2=9E=E5=8A=A0created=5Fon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/issues/list_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index 4fbc4599f..c445df2d3 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -90,7 +90,7 @@ class Api::V1::Issues::ListService < ApplicationService end if only_name.present? - scope = issues.select(:id, :subject, :project_issues_index) + scope = issues.select(:id, :subject, :project_issues_index, :updated_on, :created_on) scope = scope.reorder("project_issues_index asc").distinct else scope = issues.includes(:priority, :issue_status, :user, :show_assigners, :show_issue_tags, :version, :comment_journals) From 61c23b137f427c2af756d0e93b384b59e0cbcd8b Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 12 Apr 2023 16:18:28 +0800 Subject: [PATCH 322/438] fix --- app/services/api/v1/issues/list_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index c445df2d3..5a3f97e98 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -91,7 +91,7 @@ class Api::V1::Issues::ListService < ApplicationService if only_name.present? scope = issues.select(:id, :subject, :project_issues_index, :updated_on, :created_on) - scope = scope.reorder("project_issues_index asc").distinct + scope = scope.reorder("#{sort_by} #{sort_direction}").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 From 4bd60d458e36c9b63bd314147a6a69357b59959b Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 12 Apr 2023 18:34:49 +0800 Subject: [PATCH 323/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Awebhook?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=BF=94=E5=9B=9E=E7=BB=93=E6=9E=84=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/issues/journals_controller.rb | 2 +- app/controllers/journals_controller.rb | 2 +- app/jobs/touch_webhook_job.rb | 8 ++-- app/services/api/v1/issues/create_service.rb | 4 +- .../api/v1/issues/journals/update_service.rb | 2 +- app/services/api/v1/issues/update_service.rb | 11 +++-- app/services/webhook/issue_client.rb | 45 ++++++++++++++++++- 7 files changed, 59 insertions(+), 15 deletions(-) diff --git a/app/controllers/api/v1/issues/journals_controller.rb b/app/controllers/api/v1/issues/journals_controller.rb index af23aa686..4a88c1b0f 100644 --- a/app/controllers/api/v1/issues/journals_controller.rb +++ b/app/controllers/api/v1/issues/journals_controller.rb @@ -27,7 +27,7 @@ class Api::V1::Issues::JournalsController < Api::V1::BaseController end def destroy - TouchWebhookJob.perform_later('IssueComment', @issue&.id, current_user.id, @journal.id, 'deleted', JSON.parse(@journal.to_builder.target!)) + TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueComment', @issue&.id, current_user.id, @journal.id, 'deleted', JSON.parse(@journal.to_builder.target!)) if @journal.destroy! render_ok else diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rb index ff214774a..a6c6c8080 100644 --- a/app/controllers/journals_controller.rb +++ b/app/controllers/journals_controller.rb @@ -62,7 +62,7 @@ class JournalsController < ApplicationController def destroy if @journal.destroy #如果有子评论,子评论删除吗? - TouchWebhookJob.perform_later('PullRequestComment', @issue&.id, current_user.id, @journal.id, 'deleted', JSON.parse(@journal.to_builder.target!)) + TouchWebhookJob.set(wait: 5.seconds).perform_later('PullRequestComment', @issue&.id, current_user.id, @journal.id, 'deleted', JSON.parse(@journal.to_builder.target!)) Journal.children_journals(@journal.id).destroy_all normal_status(0, "评论删除成功") else diff --git a/app/jobs/touch_webhook_job.rb b/app/jobs/touch_webhook_job.rb index 8319a9d66..0a8c03e9f 100644 --- a/app/jobs/touch_webhook_job.rb +++ b/app/jobs/touch_webhook_job.rb @@ -25,24 +25,24 @@ class TouchWebhookJob < ApplicationJob end when 'IssueAssign' - issue_id, sender_id, assigner_ids = args[0], args[1], args[2] + issue_id, sender_id, changes = args[0], args[1], args[2] issue = Issue.find_by_id issue_id sender = User.find_by_id sender_id return if issue.nil? || sender.nil? issue.project.webhooks.each do |webhook| next unless webhook.events["events"]["issue_assign"] - _, _, @webhook_task = Webhook::IssueClient.new(webhook, issue, sender, "issue_assign",{assigner_ids: assigner_ids}.stringify_keys).do_request + _, _, @webhook_task = Webhook::IssueClient.new(webhook, issue, sender, "issue_assign", changes.stringify_keys).do_request Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}" end when 'IssueLabel' - issue_id, sender_id, issue_tag_ids = args[0], args[1], args[2] + issue_id, sender_id, changes = args[0], args[1], args[2] issue = Issue.find_by_id issue_id sender = User.find_by_id sender_id return if issue.nil? || sender.nil? issue.project.webhooks.each do |webhook| next unless webhook.events["events"]["issue_label"] - _, _, @webhook_task = Webhook::IssueClient.new(webhook, issue, sender, "issue_label",{issue_tag_ids: issue_tag_ids}.stringify_keys).do_request + _, _, @webhook_task = Webhook::IssueClient.new(webhook, issue, sender, "issue_label", changes.stringify_keys).do_request Rails.logger.info "Touch Webhook Response result: #{@webhook_task.response_content}" end diff --git a/app/services/api/v1/issues/create_service.rb b/app/services/api/v1/issues/create_service.rb index b930a91b1..e81f65e19 100644 --- a/app/services/api/v1/issues/create_service.rb +++ b/app/services/api/v1/issues/create_service.rb @@ -70,8 +70,8 @@ class Api::V1::Issues::CreateService < ApplicationService # 触发webhook TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueCreate', @created_issue&.id, current_user.id) - TouchWebhookJob.perform_later('IssueLabel', @created_issue&.id, current_user.id, issue_tag_ids) unless issue_tag_ids.blank? - TouchWebhookJob.perform_later('IssueAssign', @created_issue&.id, current_user.id, assigner_ids) unless assigner_ids.blank? + TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueLabel', @created_issue&.id, current_user.id, {issue_tag_ids: [[], issue_tag_ids]}) unless issue_tag_ids.blank? + TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueAssign', @created_issue&.id, current_user.id, {assigner_ids: [[], assigner_ids]}) unless assigner_ids.blank? unlock("Api::V1::Issues::CreateService:#{project.id}") # 结束写数据,解锁 end diff --git a/app/services/api/v1/issues/journals/update_service.rb b/app/services/api/v1/issues/journals/update_service.rb index 2e27d53ea..c771d5c1a 100644 --- a/app/services/api/v1/issues/journals/update_service.rb +++ b/app/services/api/v1/issues/journals/update_service.rb @@ -38,7 +38,7 @@ class Api::V1::Issues::Journals::UpdateService < ApplicationService # @信息发送 AtmeService.call(current_user, @atme_receivers, @created_journal) unless receivers_login.blank? - TouchWebhookJob.perform_later('IssueComment', @issue&.id, @current_user.id, @updated_journal.id, 'edited', @updated_journal.previous_changes.slice(:notes).stringify_keys) + TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueComment', @issue&.id, @current_user.id, @updated_journal.id, 'edited', @updated_journal.previous_changes.slice(:notes).stringify_keys) unlock("Api::V1::Issues::Journals::UpdateService:#{@issue.id}:#{@journal.id}") diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index 9dfaaa447..fc7eabea6 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -5,7 +5,7 @@ class Api::V1::Issues::UpdateService < ApplicationService attr_reader :project, :issue, :current_user attr_reader :status_id, :priority_id, :milestone_id, :branch_name, :start_date, :due_date, :subject, :description - attr_reader :issue_tag_ids, :assigner_ids, :attachment_ids, :receivers_login + attr_reader :issue_tag_ids, :assigner_ids, :attachment_ids, :receivers_login, :before_issue_tag_ids, :before_assigner_ids attr_accessor :add_assigner_ids, :previous_issue_changes, :updated_issue, :atme_receivers validates :project, :issue, :current_user, presence: true @@ -24,6 +24,8 @@ class Api::V1::Issues::UpdateService < ApplicationService @description = params[:description] @issue_tag_ids = params[:issue_tag_ids] @assigner_ids = params[:assigner_ids] + @before_issue_tag_ids = issue.issue_tags.pluck(:id) + @before_assigner_ids = issue.assigners.pluck(:id) @attachment_ids = params[:attachment_ids] @receivers_login = params[:receivers_login] @add_assigner_ids = [] @@ -78,9 +80,10 @@ class Api::V1::Issues::UpdateService < ApplicationService end # 触发webhook - TouchWebhookJob.perform_later('IssueUpdate', @updated_issue&.id, current_user.id, previous_issue_changes.except(:issue_tags_value, :assigned_to_id)) - TouchWebhookJob.perform_later('IssueLabel', @updated_issue&.id, current_user.id, issue_tag_ids) unless issue_tag_ids.nil? - TouchWebhookJob.perform_later('IssueAssign', @updated_issue&.id, current_user.id, assigner_ids) unless assigner_ids.nil? + TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueUpdate', @updated_issue&.id, current_user.id, previous_issue_changes.except(:issue_tags_value, :assigned_to_id)) + TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueLabel', @issue&.id, current_user.id, {issue_tag_ids: [before_issue_tag_ids, issue_tag_ids]}) unless issue_tag_ids.nil? + TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueAssign', @issue&.id, current_user.id, {assigner_ids: [before_assigner_ids, assigner_ids]}) unless assigner_ids.nil? + unlock("Api::V1::Issues::UpdateService:#{project.id}:#{issue.id}") return @updated_issue diff --git a/app/services/webhook/issue_client.rb b/app/services/webhook/issue_client.rb index 92c85d32e..b829f9740 100644 --- a/app/services/webhook/issue_client.rb +++ b/app/services/webhook/issue_client.rb @@ -42,6 +42,30 @@ class Webhook::IssueClient "sender": JSON.parse(@sender.to_builder.target!) } else + if @changes.has_key?("status_id") + before_status = IssueStatus.find_by_id(@changes["status_id"][0]) + after_status = IssueStatus.find_by_id(@changes["status_id"][1]) + @changes["status"] = [] + @changes["status"].append(before_status.present? ? JSON.parse(before_status.to_builder.target!) : {}) + @changes["status"].append(after_status.present? ? JSON.parse(after_status.to_builder.target!) : {}) + @changes.delete("status_id") + end + if @changes.has_key?("fixed_version_id") + before_milestone = Version.find_by_id(@changes["fixed_version_id"][0]) + after_milestone = Version.find_by_id(@changes["fixed_version_id"][1]) + @changes["milestone"] = [] + @changes["milestone"].append(before_milestone.present? ? JSON.parse(before_milestone.to_builder.target!) : {}) + @changes["milestone"].append(after_milestone.present? ? JSON.parse(after_milestone.to_builder.target!) : {}) + @changes.delete("fixed_version_id") + end + if @changes.has_key?("priority_id") + before_priority = IssuePriority.find_by_id(@changes["priority_id"][0]) + after_priority = IssuePriority.find_by_id(@changes["priority_id"][1]) + @changes["priority"] = [] + @changes["priority"].append(before_priority.present? ? JSON.parse(before_priority.to_builder.target!) : {}) + @changes["priority"].append(after_priority.present? ? JSON.parse(after_priority.to_builder.target!) : {}) + @changes.delete("priority_id") + end { "action": "edited", "number": @issue.project_issues_index, @@ -54,8 +78,16 @@ class Webhook::IssueClient end def issue_assign_payload_content + if @changes.has_key?("assigner_ids") + before_assigners = User.where(id: @changes["assigner_ids"][0]) + after_assigners = User.where(id: @changes["assigner_ids"][1]) + @changes["assigners"] = [] + @changes["assigners"].append(before_assigners.blank? ? [] : before_assigners.map{|a|JSON.parse(a.to_buidler.target!)}) + @changes["assigners"].append(after_assigners.blank? ? [] : after_assigners.map{|a|JSON.parse(a.to_builder.target!)}) + @changes.delete("assigner_ids") + end { - "action": @changes["assigner_ids"].blank? ? "unassigned" : "assigned", + "action": @changes["assigners"].blank? ? "unassigned" : "assigned", "number": @issue.project_issues_index, "issue": JSON.parse(@issue.to_builder.target!), "project": JSON.parse(@issue.project.to_builder.target!), @@ -64,8 +96,17 @@ class Webhook::IssueClient end def issue_label_payload_content + if @changes.has_key?("issue_tag_ids") + before_issue_tags = IssueTag.where(id: @changes["issue_tag_ids"][0]) + after_issue_tags = IssueTag.where(id: @changes["issue_tag_ids"][1]) + @changes["issue_tags"] = [] + @changes["issue_tags"].append(before_issue_tags.blank? ? [] : before_issue_tags.map{|t|JSON.parse(t.to_builder.target!)}) + @changes["issue_tags"].append(after_issue_tags.blank? ? [] : after_issue_tags.map{|t|JSON.parse(t.to_builder.target!)}) + @changes.delete("issue_tag_ids") + end { - "action": @changes["issue_tag_ids"].blank? ? "label_cleared" : "label_updated", + "action": @changes["issue_tags"].blank? ? "label_cleared" : "label_updated", + "changes": @changes, "number": @issue.project_issues_index, "issue": JSON.parse(@issue.to_builder.target!), "project": JSON.parse(@issue.project.to_builder.target!), From 1e3ad9e98881625d4ecdb24dc3c21573369d4a2d Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 13 Apr 2023 09:30:00 +0800 Subject: [PATCH 324/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/webhook/client.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/services/webhook/client.rb b/app/services/webhook/client.rb index a64753d05..ac7cfcf35 100644 --- a/app/services/webhook/client.rb +++ b/app/services/webhook/client.rb @@ -49,11 +49,19 @@ module Webhook::Client @request_content["http_method"] = @http_method @request_content["headers"] = headers - response = RestClient::Request.execute(method: trans_http_method, url: @url, headers: headers, payload: @webhook_task.read_attribute_before_type_cast("payload_content")) {|response, request, result| response } + begin - @response_content["status"] = response.code - @response_content["headers"] = response.headers - @response_content["body"] = response.body.to_json + response = RestClient::Request.execute(method: trans_http_method, url: @url, headers: headers, payload: @webhook_task.read_attribute_before_type_cast("payload_content")) {|response, request, result| response } + + @response_content["status"] = response.code + @response_content["headers"] = response.headers + @response_content["body"] = response.body.to_json + + rescue => e + @response_content["status"] = 500 + @response_content["headers"] = {} + @response_content["body"] = e.message + end @webhook_task.update_attributes({ delivered: Time.now.to_i * 1000000000, From a69e4e50143b43e5c1aecacd25eea8b3ec32622c Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 13 Apr 2023 09:42:12 +0800 Subject: [PATCH 325/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Awebhook=20cl?= =?UTF-8?q?ient=E9=87=8C=E6=95=B0=E6=8D=AEreload?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/webhook/issue_client.rb | 4 ++-- app/services/webhook/issue_comment_client.rb | 6 +++--- app/services/webhook/pull_comment_client.rb | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/services/webhook/issue_client.rb b/app/services/webhook/issue_client.rb index b829f9740..cb6cca843 100644 --- a/app/services/webhook/issue_client.rb +++ b/app/services/webhook/issue_client.rb @@ -7,8 +7,8 @@ class Webhook::IssueClient def initialize(webhook, issue, sender, event, changes={}) @webhook = webhook - @issue = issue - @sender = sender + @issue = issue.reload + @sender = sender.reload @event = event @changes = changes diff --git a/app/services/webhook/issue_comment_client.rb b/app/services/webhook/issue_comment_client.rb index 1881217ec..4d74aa7ca 100644 --- a/app/services/webhook/issue_comment_client.rb +++ b/app/services/webhook/issue_comment_client.rb @@ -6,9 +6,9 @@ class Webhook::IssueCommentClient def initialize(webhook, issue, journal, sender, event, action_type, comment_json={}) @webhook = webhook - @issue = issue - @journal = journal - @sender = sender + @issue = issue.reload + @journal = journal.reload + @sender = sender.reload @event = event @action_type = action_type @comment_json = comment_json diff --git a/app/services/webhook/pull_comment_client.rb b/app/services/webhook/pull_comment_client.rb index dde9d983f..d7be63e8b 100644 --- a/app/services/webhook/pull_comment_client.rb +++ b/app/services/webhook/pull_comment_client.rb @@ -5,9 +5,9 @@ class Webhook::PullCommentClient def initialize(webhook, pull, journal, sender, event, action_type='created', comment_json={}) @webhook = webhook - @pull = pull - @journal = journal - @sender = sender + @pull = pull.reload + @journal = journal.reload + @sender = sender.reload @event = event @action_type = action_type @comment_json = comment_json From e7598642fd243d7605eebd4092fa2e443aa3ae18 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 13 Apr 2023 11:06:58 +0800 Subject: [PATCH 326/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=A0=87=E8=AF=86=E4=B8=8D=E8=83=BD=E4=BB=A5.?= =?UTF-8?q?=E7=BB=93=E5=B0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/libs/custom_regexp.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/libs/custom_regexp.rb b/app/libs/custom_regexp.rb index 1bfeb4b71..26608c0ea 100644 --- a/app/libs/custom_regexp.rb +++ b/app/libs/custom_regexp.rb @@ -10,6 +10,6 @@ module CustomRegexp IP = /^((\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3}(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])$/ URL_REGEX = /\A(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?\z/i - REPOSITORY_NAME_REGEX = /^[a-zA-Z0-9][a-zA-Z0-9\-\_\.]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾 + REPOSITORY_NAME_REGEX = /^[a-zA-Z0-9][a-zA-Z0-9\-\_\.]+[a-zA-Z0-9\-\_]$/ #只含有数字、字母、下划线不能以下划线开头和结尾 MD_REGEX = /^.+(\.[m|M][d|D])$/ end From 64f34cc868f95f61f64318bb17018094dfd6ee53 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 13 Apr 2023 11:12:27 +0800 Subject: [PATCH 327/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=A0=87=E8=AF=86=E6=8F=90=E7=A4=BA=E8=AF=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/forms/projects/create_form.rb | 2 +- app/forms/projects/migrate_form.rb | 2 +- app/libs/custom_regexp.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/forms/projects/create_form.rb b/app/forms/projects/create_form.rb index 28cb296c0..6b86362c8 100644 --- a/app/forms/projects/create_form.rb +++ b/app/forms/projects/create_form.rb @@ -3,7 +3,7 @@ class Projects::CreateForm < BaseForm :project_language_id, :ignore_id, :license_id, :private, :owner validates :user_id, :name, :repository_name, presence: true - validates :repository_name, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "项目标识只能包含数字,字母,下划线(_),中划线(-),英文句号(.),必须以数字和字母开头,不能以下划线/中划线开头和结尾" } + validates :repository_name, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "项目标识只能包含数字,字母,下划线(_),中划线(-),英文句号(.),必须以数字和字母开头,不能以下划线/中划线/英文句号开头和结尾" } validates :name, length: { maximum: 50 } validates :repository_name, length: { maximum: 100 } diff --git a/app/forms/projects/migrate_form.rb b/app/forms/projects/migrate_form.rb index c3684c2ef..1cb9b462e 100644 --- a/app/forms/projects/migrate_form.rb +++ b/app/forms/projects/migrate_form.rb @@ -3,7 +3,7 @@ class Projects::MigrateForm < BaseForm :project_language_id, :clone_addr, :private, :is_mirror, :auth_username, :auth_password, :owner validates :user_id, :name, :repository_name, :clone_addr, presence: true - validates :repository_name, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "项目标识只能包含数字,字母,下划线(_),中划线(-),英文句号(.),必须以数字和字母开头,不能以下划线/中划线开头和结尾" } + validates :repository_name, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "项目标识只能包含数字,字母,下划线(_),中划线(-),英文句号(.),必须以数字和字母开头,不能以下划线/中划线/英文句号开头和结尾" } validates :clone_addr, format: { with: CustomRegexp::URL_REGEX, multiline: true, message: "地址格式不正确" } validates :name, length: { maximum: 50 } validates :repository_name, length: { maximum: 100 } diff --git a/app/libs/custom_regexp.rb b/app/libs/custom_regexp.rb index 26608c0ea..6012382b2 100644 --- a/app/libs/custom_regexp.rb +++ b/app/libs/custom_regexp.rb @@ -10,6 +10,6 @@ module CustomRegexp IP = /^((\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3}(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])$/ URL_REGEX = /\A(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?\z/i - REPOSITORY_NAME_REGEX = /^[a-zA-Z0-9][a-zA-Z0-9\-\_\.]+[a-zA-Z0-9\-\_]$/ #只含有数字、字母、下划线不能以下划线开头和结尾 + REPOSITORY_NAME_REGEX = /^[a-zA-Z0-9][a-zA-Z0-9\-\_\.]+[a-zA-Z0-9]$/ #只含有数字、字母、下划线不能以下划线开头和结尾 MD_REGEX = /^.+(\.[m|M][d|D])$/ end From 6eea21821f40689184c210d207d2c2c1d0b34699 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 13 Apr 2023 11:17:46 +0800 Subject: [PATCH 328/438] =?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/projects/update_form.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/forms/projects/update_form.rb b/app/forms/projects/update_form.rb index 2490fbed6..1a04b7fe4 100644 --- a/app/forms/projects/update_form.rb +++ b/app/forms/projects/update_form.rb @@ -3,7 +3,7 @@ class Projects::UpdateForm < BaseForm validates :name, presence: true validates :name, length: { maximum: 50 } validates :description, length: { maximum: 200 } - validates :identifier, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: '项目标识只能包含数字,字母,下划线(_),中划线(-),英文句号(.),必须以数字和字母开头,不能以下划线/中划线开头和结尾' } + validates :identifier, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: '项目标识只能包含数字,字母,下划线(_),中划线(-),英文句号(.),必须以数字和字母开头,不能以下划线/中划线/英文句号开头和结尾' } validate do check_project_category(project_category_id) From c01c3de2fddaea2f2ab486db3418ac4f799b8ad7 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 13 Apr 2023 17:07:41 +0800 Subject: [PATCH 329/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E9=A1=B9=E7=9B=AE=E6=90=9C=E7=B4=A2=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/init_project_topic.rake | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 lib/tasks/init_project_topic.rake diff --git a/lib/tasks/init_project_topic.rake b/lib/tasks/init_project_topic.rake new file mode 100644 index 000000000..9d96a473f --- /dev/null +++ b/lib/tasks/init_project_topic.rake @@ -0,0 +1,21 @@ +# 执行示例 bundle exec rake init_project_topic:project +# RAILS_ENV=production bundle exec rake init_project_topic:project + +namespace :init_project_topic do + desc "Init Project Topic for Project" + task project: :environment do + Project.find_each do |p| + next if p.project_topics.size >= 3 + languages = $gitea_client.get_repos_languages_by_owner_repo(p.owner.login, p.identifier) + topic_count = p.project_topics.size + languages.each do |k, _| + next if topic_count >= 3 + project_topic = ProjectTopic.find_or_create_by!(name: k.downcase) + project_topic_ralate = project_topic.project_topic_ralates.find_or_create_by!(project_id: p.id) + if project_topic.present? && project_topic_ralate.present? + topic_count +=1 + end + end + end + end +end \ No newline at end of file From 33589a028d5f45e7cfc373c1c696535b13b61108 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 13 Apr 2023 17:10:36 +0800 Subject: [PATCH 330/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E6=97=B6=E9=97=B4=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/init_project_topic.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/init_project_topic.rake b/lib/tasks/init_project_topic.rake index 9d96a473f..ded67fa34 100644 --- a/lib/tasks/init_project_topic.rake +++ b/lib/tasks/init_project_topic.rake @@ -4,7 +4,7 @@ namespace :init_project_topic do desc "Init Project Topic for Project" task project: :environment do - Project.find_each do |p| + Project.order_by(created_at: :desc).find_each do |p| next if p.project_topics.size >= 3 languages = $gitea_client.get_repos_languages_by_owner_repo(p.owner.login, p.identifier) topic_count = p.project_topics.size From fa6cd1b75944c227ba92db2931d918dce02292af Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 13 Apr 2023 17:12:37 +0800 Subject: [PATCH 331/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E6=97=B6=E9=97=B4=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/init_project_topic.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/init_project_topic.rake b/lib/tasks/init_project_topic.rake index ded67fa34..68bbefdfd 100644 --- a/lib/tasks/init_project_topic.rake +++ b/lib/tasks/init_project_topic.rake @@ -4,7 +4,7 @@ namespace :init_project_topic do desc "Init Project Topic for Project" task project: :environment do - Project.order_by(created_at: :desc).find_each do |p| + Project.order(created_at: :desc).find_each do |p| next if p.project_topics.size >= 3 languages = $gitea_client.get_repos_languages_by_owner_repo(p.owner.login, p.identifier) topic_count = p.project_topics.size From 98c810cc80e5117624e32f7ee156c695ab1805c9 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 13 Apr 2023 17:14:57 +0800 Subject: [PATCH 332/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E9=A1=B9=E7=9B=AE=E6=8B=A5=E6=9C=89=E8=80=85=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA=E7=9B=B4=E6=8E=A5=E8=B7=B3=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/init_project_topic.rake | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/tasks/init_project_topic.rake b/lib/tasks/init_project_topic.rake index 68bbefdfd..df4714d14 100644 --- a/lib/tasks/init_project_topic.rake +++ b/lib/tasks/init_project_topic.rake @@ -5,6 +5,7 @@ namespace :init_project_topic do desc "Init Project Topic for Project" task project: :environment do Project.order(created_at: :desc).find_each do |p| + next unless p.owner.present? next if p.project_topics.size >= 3 languages = $gitea_client.get_repos_languages_by_owner_repo(p.owner.login, p.identifier) topic_count = p.project_topics.size From 4ac33e9e6dbb58797c5345390f7a231ce6b8ce7a Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 13 Apr 2023 17:18:01 +0800 Subject: [PATCH 333/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=BC=82=E5=B8=B8=E6=8D=95=E8=8E=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/init_project_topic.rake | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/tasks/init_project_topic.rake b/lib/tasks/init_project_topic.rake index df4714d14..f6fcd4b96 100644 --- a/lib/tasks/init_project_topic.rake +++ b/lib/tasks/init_project_topic.rake @@ -7,15 +7,19 @@ namespace :init_project_topic do Project.order(created_at: :desc).find_each do |p| next unless p.owner.present? next if p.project_topics.size >= 3 - languages = $gitea_client.get_repos_languages_by_owner_repo(p.owner.login, p.identifier) - topic_count = p.project_topics.size - languages.each do |k, _| - next if topic_count >= 3 - project_topic = ProjectTopic.find_or_create_by!(name: k.downcase) - project_topic_ralate = project_topic.project_topic_ralates.find_or_create_by!(project_id: p.id) - if project_topic.present? && project_topic_ralate.present? - topic_count +=1 + begin + languages = $gitea_client.get_repos_languages_by_owner_repo(p.owner.login, p.identifier) + topic_count = p.project_topics.size + languages.each do |k, _| + next if topic_count >= 3 + project_topic = ProjectTopic.find_or_create_by!(name: k.downcase) + project_topic_ralate = project_topic.project_topic_ralates.find_or_create_by!(project_id: p.id) + if project_topic.present? && project_topic_ralate.present? + topic_count +=1 + end end + rescue + next end end end From 1e7cffd716284b2560e4603a14f5d3253ecb6b51 Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Thu, 13 Apr 2023 17:21:09 +0800 Subject: [PATCH 334/438] fix issue webhook error --- Gemfile | 3 ++ Gemfile.lock | 52 ++++++++++++++++++- app/models/issue.rb | 8 +-- app/services/api/v1/issues/update_service.rb | 4 +- app/services/webhook/issue_client.rb | 2 +- .../projects/webhooks/tasks.json.jbuilder | 2 +- 6 files changed, 62 insertions(+), 9 deletions(-) diff --git a/Gemfile b/Gemfile index abe202581..947543c5f 100644 --- a/Gemfile +++ b/Gemfile @@ -70,6 +70,9 @@ group :development do gem 'web-console', '>= 3.3.0' gem 'listen', '>= 3.0.5', '< 3.2' gem 'spring' + gem 'pry-rails' + gem 'pry-remote' + gem 'byebug', platforms: [:mri,:mingw,:x64_mingw] gem 'spring-watcher-listen', '~> 2.0.0' gem "annotate", "~> 2.6.0" end diff --git a/Gemfile.lock b/Gemfile.lock index e27c504aa..7773ecad8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,5 +1,5 @@ GEM - remote: https://gems.ruby-china.com/ + remote: https://mirrors.cloud.tencent.com/rubygems/ specs: aasm (5.0.6) concurrent-ruby (~> 1.0) @@ -84,6 +84,7 @@ GEM builder (3.2.4) bulk_insert (1.7.0) activerecord (>= 3.2.0) + byebug (11.1.3) capybara (3.15.1) addressable mini_mime (>= 0.1.3) @@ -99,6 +100,7 @@ GEM archive-zip (~> 0.10) nokogiri (~> 1.8) chunky_png (1.3.11) + coderay (1.1.3) concurrent-ruby (1.1.6) connection_pool (2.2.2) crass (1.0.6) @@ -106,6 +108,8 @@ GEM activerecord (>= 3.1.0, < 7) diff-lcs (1.3) diffy (3.3.0) + domain_name (0.5.20190701) + unf (>= 0.0.5, < 1.0.0) doorkeeper (5.5.1) railties (>= 5) doorkeeper-jwt (0.4.1) @@ -133,6 +137,8 @@ GEM fugit (1.4.1) et-orbi (~> 1.1, >= 1.1.8) raabro (~> 1.4) + gitea-client (1.4.1) + rest-client (~> 2.1.0) globalid (0.4.2) activesupport (>= 4.2.0) grape-entity (0.7.1) @@ -143,6 +149,9 @@ GEM harmonious_dictionary (0.0.1) hashie (3.6.0) htmlentities (4.3.4) + http-accept (1.7.0) + http-cookie (1.0.5) + domain_name (~> 0.5) i18n (1.8.2) concurrent-ruby (~> 1.0) io-like (0.3.1) @@ -180,6 +189,9 @@ GEM mimemagic (~> 0.3.2) maruku (0.7.3) method_source (0.9.2) + mime-types (3.4.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2023.0218.1) mimemagic (0.3.10) nokogiri (~> 1) rake @@ -193,6 +205,7 @@ GEM mustermann (1.1.1) ruby2_keywords (~> 0.0.1) mysql2 (0.5.3) + netrc (0.11.0) nio4r (2.5.2) nokogiri (1.10.8) mini_portile2 (~> 2.4.0) @@ -209,9 +222,21 @@ GEM addressable (~> 2.3) nokogiri (~> 1.5) omniauth (~> 1.2) + omniauth-gitee (1.0.0) + omniauth (>= 1.5, < 3.0) + omniauth-oauth2 (>= 1.4.0, < 2.0) + omniauth-github (1.4.0) + omniauth (~> 1.5) + omniauth-oauth2 (>= 1.4.0, < 2.0) omniauth-oauth2 (1.6.0) oauth2 (~> 1.1) omniauth (~> 1.9) + omniauth-rails_csrf_protection (0.1.2) + actionpack (>= 4.2) + omniauth (>= 1.3.1) + omniauth-wechat-oauth2 (0.2.2) + omniauth (>= 1.3.2) + omniauth-oauth2 (>= 1.1.1) parallel (1.19.1) parser (2.7.1.1) ast (~> 2.4.0) @@ -221,6 +246,14 @@ GEM popper_js (1.16.0) powerpack (0.1.2) prettier (0.18.2) + pry (0.12.2) + coderay (~> 1.1.0) + method_source (~> 0.9.0) + pry-rails (0.3.9) + pry (>= 0.10.4) + pry-remote (0.1.8) + pry (~> 0.9) + slop (~> 3.0) public_suffix (4.0.3) puma (3.12.2) raabro (1.4.0) @@ -292,6 +325,11 @@ GEM regexp_parser (1.7.0) request_store (1.5.0) rack (>= 1.4) + rest-client (2.1.0) + http-accept (>= 1.7.0, < 2.0) + http-cookie (>= 1.0.2, < 2.0) + mime-types (>= 1.16, < 4.0) + netrc (~> 0.8) reverse_markdown (1.4.0) nokogiri roo (2.8.3) @@ -380,6 +418,7 @@ GEM rack (~> 2.0) rack-protection (= 2.0.8.1) tilt (~> 2.0) + slop (3.6.0) solargraph (0.38.6) backport (~> 1.1) benchmark @@ -418,6 +457,9 @@ GEM thread_safe (~> 0.1) uglifier (4.2.0) execjs (>= 0.3.0, < 3) + unf (0.1.4) + unf_ext + unf_ext (0.0.8.2) unicode-display_width (1.6.1) web-console (3.7.0) actionview (>= 5.0) @@ -448,6 +490,7 @@ DEPENDENCIES bootsnap (>= 1.1.0) bootstrap (~> 4.3.1) bulk_insert + byebug capybara (>= 2.15, < 4.0) chartkick chinese_pinyin @@ -459,6 +502,7 @@ DEPENDENCIES enumerize faraday (~> 0.15.4) font-awesome-sass (= 4.7.0) + gitea-client (~> 1.4.1) grape-entity (~> 0.7.1) groupdate (~> 4.1.0) harmonious_dictionary (~> 0.0.1) @@ -472,10 +516,16 @@ DEPENDENCIES oauth2 omniauth (~> 1.9.0) omniauth-cas + omniauth-gitee (~> 1.0.0) + omniauth-github omniauth-oauth2 (~> 1.6.0) + omniauth-rails_csrf_protection + omniauth-wechat-oauth2 parallel (~> 1.19, >= 1.19.1) pdfkit prettier + pry-rails + pry-remote puma (~> 3.11) rack-cors rack-mini-profiler diff --git a/app/models/issue.rb b/app/models/issue.rb index 4ec77025e..555332852 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -222,7 +222,7 @@ class Issue < ApplicationRecord issue.(self, :id, :project_issues_index, :subject, :description) issue.created_at self.created_on.strftime("%Y-%m-%d %H:%M") issue.updated_at self.updated_on.strftime("%Y-%m-%d %H:%M") - issue.tags self.show_issue_tags.map{|t| t.to_builder} + issue.tags self.show_issue_tags.map{|t| JSON.parse(t.to_builder.target!)} issue.status self.issue_status.to_builder if self.priority.present? issue.priority self.priority.to_builder @@ -235,11 +235,11 @@ class Issue < ApplicationRecord issue.milestone nil end issue.author self.user.to_builder - issue.assigners self.show_assigners.map{|t| t.to_builder} - issue.participants self.participants.distinct.map{|t| t.to_builder} + issue.assigners self.show_assigners.map{|t| JSON.parse(t.to_builder.target!)} + issue.participants self.participants.distinct.map{|t| JSON.parse(t.to_builder.target!)} issue.comment_journals_count self.comment_journals.size issue.operate_journals_count self.operate_journals.size - issue.attachments self.attachments.map{|t| t.to_builder} + issue.attachments self.attachments.map{|t| JSON.parse(t.to_builder.target!)} end end diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index fc7eabea6..d72a1693b 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -79,13 +79,13 @@ class Api::V1::Issues::UpdateService < ApplicationService SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id, add_assigner_ids) unless add_assigner_ids.blank? end + unlock("Api::V1::Issues::UpdateService:#{project.id}:#{issue.id}") # 触发webhook + Rails.logger.info "################### 触发webhook" TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueUpdate', @updated_issue&.id, current_user.id, previous_issue_changes.except(:issue_tags_value, :assigned_to_id)) TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueLabel', @issue&.id, current_user.id, {issue_tag_ids: [before_issue_tag_ids, issue_tag_ids]}) unless issue_tag_ids.nil? TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueAssign', @issue&.id, current_user.id, {assigner_ids: [before_assigner_ids, assigner_ids]}) unless assigner_ids.nil? - unlock("Api::V1::Issues::UpdateService:#{project.id}:#{issue.id}") - return @updated_issue end end diff --git a/app/services/webhook/issue_client.rb b/app/services/webhook/issue_client.rb index cb6cca843..abd84d030 100644 --- a/app/services/webhook/issue_client.rb +++ b/app/services/webhook/issue_client.rb @@ -82,7 +82,7 @@ class Webhook::IssueClient before_assigners = User.where(id: @changes["assigner_ids"][0]) after_assigners = User.where(id: @changes["assigner_ids"][1]) @changes["assigners"] = [] - @changes["assigners"].append(before_assigners.blank? ? [] : before_assigners.map{|a|JSON.parse(a.to_buidler.target!)}) + @changes["assigners"].append(before_assigners.blank? ? [] : before_assigners.map{|a|JSON.parse(a.to_builder.target!)}) @changes["assigners"].append(after_assigners.blank? ? [] : after_assigners.map{|a|JSON.parse(a.to_builder.target!)}) @changes.delete("assigner_ids") end diff --git a/app/views/projects/webhooks/tasks.json.jbuilder b/app/views/projects/webhooks/tasks.json.jbuilder index 8e1809011..115a59bcc 100644 --- a/app/views/projects/webhooks/tasks.json.jbuilder +++ b/app/views/projects/webhooks/tasks.json.jbuilder @@ -1,6 +1,6 @@ json.total_count @tasks.total_count json.tasks @tasks.each do |task| - json.(task, :id, :event_type, :type, :uuid, :is_succeed, :is_delivered, :payload_content, :request_content) + json.(task, :id, :event_type, :uuid, :is_succeed, :is_delivered, :payload_content, :request_content) json.response_content task.response_content json.delivered_time task.delivered.present? ? Time.at(task.delivered*10**-9).strftime("%Y-%m-%d %H:%M:%S") : nil end \ No newline at end of file From 16dbb87526af432a61a9e54ea910145a8738ecb3 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 13 Apr 2023 19:56:43 +0800 Subject: [PATCH 335/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E9=83=A8?= =?UTF-8?q?=E5=88=86issue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/issue.rb | 2 +- app/services/api/v1/issues/update_service.rb | 2 +- app/services/webhook/client.rb | 2 +- app/services/webhook/issue_client.rb | 1 + app/services/webhook/issue_comment_client.rb | 2 +- app/services/webhook/pull_comment_client.rb | 2 +- 6 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 555332852..9076551c4 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -219,7 +219,7 @@ class Issue < ApplicationRecord def to_builder Jbuilder.new do |issue| - issue.(self, :id, :project_issues_index, :subject, :description) + issue.(self, :id, :project_issues_index, :subject, :description, :branch_name, :start_date, :due_date) issue.created_at self.created_on.strftime("%Y-%m-%d %H:%M") issue.updated_at self.updated_on.strftime("%Y-%m-%d %H:%M") issue.tags self.show_issue_tags.map{|t| JSON.parse(t.to_builder.target!)} diff --git a/app/services/api/v1/issues/update_service.rb b/app/services/api/v1/issues/update_service.rb index d72a1693b..9c1b3ebfc 100644 --- a/app/services/api/v1/issues/update_service.rb +++ b/app/services/api/v1/issues/update_service.rb @@ -128,7 +128,7 @@ class Api::V1::Issues::UpdateService < ApplicationService end def build_previous_issue_changes - @previous_issue_changes.merge!(@updated_issue.previous_changes.slice("status_id", "priority_id", "fixed_version_id", "issue_tags_value", "branch_name").symbolize_keys) + @previous_issue_changes.merge!(@updated_issue.previous_changes.slice("status_id", "priority_id", "fixed_version_id", "issue_tags_value", "branch_name", "subject", "description").symbolize_keys) if @updated_issue.previous_changes[:start_date].present? @previous_issue_changes.merge!(start_date: [@updated_issue.previous_changes[:start_date][0].to_s, @updated_issue.previous_changes[:start_date][1].to_s]) end diff --git a/app/services/webhook/client.rb b/app/services/webhook/client.rb index ac7cfcf35..cb1cac61c 100644 --- a/app/services/webhook/client.rb +++ b/app/services/webhook/client.rb @@ -55,7 +55,7 @@ module Webhook::Client @response_content["status"] = response.code @response_content["headers"] = response.headers - @response_content["body"] = response.body.to_json + @response_content["body"] = response.body rescue => e @response_content["status"] = 500 diff --git a/app/services/webhook/issue_client.rb b/app/services/webhook/issue_client.rb index abd84d030..535330896 100644 --- a/app/services/webhook/issue_client.rb +++ b/app/services/webhook/issue_client.rb @@ -89,6 +89,7 @@ class Webhook::IssueClient { "action": @changes["assigners"].blank? ? "unassigned" : "assigned", "number": @issue.project_issues_index, + "changes": @changes, "issue": JSON.parse(@issue.to_builder.target!), "project": JSON.parse(@issue.project.to_builder.target!), "sender": JSON.parse(@sender.to_builder.target!) diff --git a/app/services/webhook/issue_comment_client.rb b/app/services/webhook/issue_comment_client.rb index 4d74aa7ca..322041493 100644 --- a/app/services/webhook/issue_comment_client.rb +++ b/app/services/webhook/issue_comment_client.rb @@ -7,7 +7,7 @@ class Webhook::IssueCommentClient def initialize(webhook, issue, journal, sender, event, action_type, comment_json={}) @webhook = webhook @issue = issue.reload - @journal = journal.reload + @journal = journal.present? ? journal.reload : nil @sender = sender.reload @event = event @action_type = action_type diff --git a/app/services/webhook/pull_comment_client.rb b/app/services/webhook/pull_comment_client.rb index d7be63e8b..a4d6cab4b 100644 --- a/app/services/webhook/pull_comment_client.rb +++ b/app/services/webhook/pull_comment_client.rb @@ -6,7 +6,7 @@ class Webhook::PullCommentClient def initialize(webhook, pull, journal, sender, event, action_type='created', comment_json={}) @webhook = webhook @pull = pull.reload - @journal = journal.reload + @journal = journal.present? ? journal.reload : nil @sender = sender.reload @event = event @action_type = action_type From 8ac7b6a7e7cb94e028c3b49ddb2e3dd75546a3cd Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 13 Apr 2023 20:17:47 +0800 Subject: [PATCH 336/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Awebhook?= =?UTF-8?q?=E5=8E=86=E5=8F=B2=E8=AE=B0=E5=BD=95=E9=83=A8=E5=88=86=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E7=BC=96=E7=A0=81=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/project.rb | 4 ++-- app/models/user.rb | 2 +- .../20230413121129_change_webhook_task_field_character.rb | 7 +++++++ 3 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20230413121129_change_webhook_task_field_character.rb diff --git a/app/models/project.rb b/app/models/project.rb index 52b729a85..02844c3bc 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -451,7 +451,7 @@ class Project < ApplicationRecord Jbuilder.new do |project| project.id self.id project.identifier self.identifier - project.name self.name.to_s.each_char.select { |c| c.bytes.first < 240 }.join('') + project.name self.name project.description Nokogiri::HTML(self.description).text project.visits self.visits project.praises_count self.praises_count.to_i @@ -475,7 +475,7 @@ class Project < ApplicationRecord project.image_url render_educoder_avatar_url(self.project_educoder) else user = self.owner - project.name user.try(:show_real_name).to_s.each_char.select { |c| c.bytes.first < 240 }.join('') + project.name user.try(:show_real_name) project.type user&.type project.login user.login project.image_url user.get_letter_avatar_url diff --git a/app/models/user.rb b/app/models/user.rb index 874da712a..70de1fc64 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -862,7 +862,7 @@ class User < Owner def to_builder Jbuilder.new do |user| user.(self, :id, :login) - user.name self.real_name.to_s.each_char.select { |c| c.bytes.first < 240 }.join('') + user.name self.real_name user.email self.mail user.image_url self.get_letter_avatar_url end diff --git a/db/migrate/20230413121129_change_webhook_task_field_character.rb b/db/migrate/20230413121129_change_webhook_task_field_character.rb new file mode 100644 index 000000000..04c86716d --- /dev/null +++ b/db/migrate/20230413121129_change_webhook_task_field_character.rb @@ -0,0 +1,7 @@ +class ChangeWebhookTaskFieldCharacter < ActiveRecord::Migration[5.2] + def change + Gitea::Base.connection.execute("ALTER TABLE `hook_task` MODIFY `payload_content` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;") + Gitea::Base.connection.execute("ALTER TABLE `hook_task` MODIFY `request_content` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;") + Gitea::Base.connection.execute("ALTER TABLE `hook_task` MODIFY `response_content` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;") + end +end From 71bf2137acbca25b31e1717a6055b52b8ad2f0be Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 14 Apr 2023 11:19:23 +0800 Subject: [PATCH 337/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=A0=87=E8=AE=B0=E4=B8=8D=E8=83=BD=E6=B8=85=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 71a214062..ca6b38360 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -132,7 +132,7 @@ class ProjectsController < ApplicationController # TODO: # 临时特殊处理修改website、lesson_url操作方法 if project_params.has_key?("website") - if params[:project_topic_names].present? && params[:project_topic_names].is_a?(Array) + if params[:project_topic_names].is_a?(Array) ProjectTopicRalate.where(project: @project).destroy_all params[:project_topic_names].each do |name| project_topic = ProjectTopic.find_or_create_by!(name: name.downcase) From b4bca892b50c25a8e2ccb91b2b75333376b36204 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Sat, 15 Apr 2023 15:00:25 +0800 Subject: [PATCH 338/438] =?UTF-8?q?top=E7=94=A8=E6=88=B7=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=8E=92=E8=A1=8C=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/project_rank_controller.rb | 7 +++-- app/controllers/user_rank_controller.rb | 7 +++-- app/views/project_rank/_detail.json.jbuilder | 3 +- app/views/user_rank/_detail.json.jbuilder | 29 +++++++++++++++++++- 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/app/controllers/project_rank_controller.rb b/app/controllers/project_rank_controller.rb index 5cea074fb..424f3ced5 100644 --- a/app/controllers/project_rank_controller.rb +++ b/app/controllers/project_rank_controller.rb @@ -1,10 +1,13 @@ class ProjectRankController < ApplicationController # 根据时间获取热门项目 - def index + def index + limit = 9 + limit = params[:limit].to_i - 1 if params[:limit].present? + limit = 99 if limit > 99 $redis_cache.zunionstore("recent-days-project-rank-#{time}", get_timeable_key_names) deleted_data = $redis_cache.smembers("v2-project-rank-deleted") $redis_cache.zrem("recent-days-project-rank-#{time}", deleted_data) unless deleted_data.blank? - @project_rank = $redis_cache.zrevrange("recent-days-project-rank-#{time}", 0, 9, withscores: true) + @project_rank = $redis_cache.zrevrange("recent-days-project-rank-#{time}", 0, limit, withscores: true) rescue Exception => e @project_rank = [] end diff --git a/app/controllers/user_rank_controller.rb b/app/controllers/user_rank_controller.rb index dddca485c..1d1a7b4f3 100644 --- a/app/controllers/user_rank_controller.rb +++ b/app/controllers/user_rank_controller.rb @@ -1,8 +1,11 @@ class UserRankController < ApplicationController # 根据时间获取热门开发者 - def index + def index + limit = 3 + limit = params[:limit].to_i - 1 if params[:limit].present? + limit = 99 if limit > 99 $redis_cache.zunionstore("recent-days-user-rank", get_timeable_key_names) - @user_rank = $redis_cache.zrevrange("recent-days-user-rank", 0, 3, withscores: true) + @user_rank = $redis_cache.zrevrange("recent-days-user-rank", 0, limit, withscores: true) rescue Exception => e @user_rank = [] end diff --git a/app/views/project_rank/_detail.json.jbuilder b/app/views/project_rank/_detail.json.jbuilder index 5e45f518e..f3305649b 100644 --- a/app/views/project_rank/_detail.json.jbuilder +++ b/app/views/project_rank/_detail.json.jbuilder @@ -28,4 +28,5 @@ json.forks project_common["forks"] json.watchers project_common["watchers"] json.praises project_common["praises"] json.issues project_common["issues"] -json.pulls project_common["pullrequests"] \ No newline at end of file +json.pulls project_common["pullrequests"] +json.commits project_common["commits"] \ No newline at end of file diff --git a/app/views/user_rank/_detail.json.jbuilder b/app/views/user_rank/_detail.json.jbuilder index 7632c408b..9733a4632 100644 --- a/app/views/user_rank/_detail.json.jbuilder +++ b/app/views/user_rank/_detail.json.jbuilder @@ -18,4 +18,31 @@ else json.identifier popular_project_common["identifier"] json.description popular_project_common["description"] end -end \ No newline at end of file +end + +ids = $redis_cache.zrevrange("v2-user-project-rank:#{item[0]}", 0, 999, withscores: true).map{|a|a[0]} +visits = 0 +forks = 0 +watchers = 0 +praises = 0 +issues = 0 +pulls = 0 +commits = 0 +ids.each do |pid| + project_common = $redis_cache.hgetall("v2-project-common:#{pid}") + visits = visits + project_common["visits"] + forks = forks + project_common["forks"] + watchers = watchers + project_common["watchers"] + praises = praises + project_common["praises"] + issues = issues + project_common["issues"] + pulls = pulls + project_common["pullrequests"] + commits = commits + project_common["commits"] +end + +json.visits visits +json.forks forks +json.watchers watchers +json.praises praises +json.issues issues +json.pulls pulls +json.commits commits \ No newline at end of file From 9200a9e527cdb6278a686a4f243091083cd04e49 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Sat, 15 Apr 2023 15:02:40 +0800 Subject: [PATCH 339/438] =?UTF-8?q?top=E7=94=A8=E6=88=B7=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=8E=92=E8=A1=8C=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/user_rank/_detail.json.jbuilder | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/views/user_rank/_detail.json.jbuilder b/app/views/user_rank/_detail.json.jbuilder index 9733a4632..d94ef342e 100644 --- a/app/views/user_rank/_detail.json.jbuilder +++ b/app/views/user_rank/_detail.json.jbuilder @@ -30,13 +30,13 @@ pulls = 0 commits = 0 ids.each do |pid| project_common = $redis_cache.hgetall("v2-project-common:#{pid}") - visits = visits + project_common["visits"] - forks = forks + project_common["forks"] - watchers = watchers + project_common["watchers"] - praises = praises + project_common["praises"] - issues = issues + project_common["issues"] - pulls = pulls + project_common["pullrequests"] - commits = commits + project_common["commits"] + visits = visits + project_common["visits"].to_i + forks = forks + project_common["forks"].to_i + watchers = watchers + project_common["watchers"].to_i + praises = praises + project_common["praises"].to_i + issues = issues + project_common["issues"].to_i + pulls = pulls + project_common["pullrequests"].to_i + commits = commits + project_common["commits"].to_i end json.visits visits From 2dea54481c1a8236517e589ae685b1ae0b871478 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Sat, 15 Apr 2023 15:12:44 +0800 Subject: [PATCH 340/438] =?UTF-8?q?top=E7=94=A8=E6=88=B7=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=8E=92=E8=A1=8C=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/project_rank_controller.rb | 7 +++-- app/controllers/user_rank_controller.rb | 7 +++-- app/views/project_rank/_detail.json.jbuilder | 3 +- app/views/user_rank/_detail.json.jbuilder | 29 +++++++++++++++++++- 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/app/controllers/project_rank_controller.rb b/app/controllers/project_rank_controller.rb index 5cea074fb..424f3ced5 100644 --- a/app/controllers/project_rank_controller.rb +++ b/app/controllers/project_rank_controller.rb @@ -1,10 +1,13 @@ class ProjectRankController < ApplicationController # 根据时间获取热门项目 - def index + def index + limit = 9 + limit = params[:limit].to_i - 1 if params[:limit].present? + limit = 99 if limit > 99 $redis_cache.zunionstore("recent-days-project-rank-#{time}", get_timeable_key_names) deleted_data = $redis_cache.smembers("v2-project-rank-deleted") $redis_cache.zrem("recent-days-project-rank-#{time}", deleted_data) unless deleted_data.blank? - @project_rank = $redis_cache.zrevrange("recent-days-project-rank-#{time}", 0, 9, withscores: true) + @project_rank = $redis_cache.zrevrange("recent-days-project-rank-#{time}", 0, limit, withscores: true) rescue Exception => e @project_rank = [] end diff --git a/app/controllers/user_rank_controller.rb b/app/controllers/user_rank_controller.rb index dddca485c..1d1a7b4f3 100644 --- a/app/controllers/user_rank_controller.rb +++ b/app/controllers/user_rank_controller.rb @@ -1,8 +1,11 @@ class UserRankController < ApplicationController # 根据时间获取热门开发者 - def index + def index + limit = 3 + limit = params[:limit].to_i - 1 if params[:limit].present? + limit = 99 if limit > 99 $redis_cache.zunionstore("recent-days-user-rank", get_timeable_key_names) - @user_rank = $redis_cache.zrevrange("recent-days-user-rank", 0, 3, withscores: true) + @user_rank = $redis_cache.zrevrange("recent-days-user-rank", 0, limit, withscores: true) rescue Exception => e @user_rank = [] end diff --git a/app/views/project_rank/_detail.json.jbuilder b/app/views/project_rank/_detail.json.jbuilder index 5e45f518e..f3305649b 100644 --- a/app/views/project_rank/_detail.json.jbuilder +++ b/app/views/project_rank/_detail.json.jbuilder @@ -28,4 +28,5 @@ json.forks project_common["forks"] json.watchers project_common["watchers"] json.praises project_common["praises"] json.issues project_common["issues"] -json.pulls project_common["pullrequests"] \ No newline at end of file +json.pulls project_common["pullrequests"] +json.commits project_common["commits"] \ No newline at end of file diff --git a/app/views/user_rank/_detail.json.jbuilder b/app/views/user_rank/_detail.json.jbuilder index 7632c408b..d94ef342e 100644 --- a/app/views/user_rank/_detail.json.jbuilder +++ b/app/views/user_rank/_detail.json.jbuilder @@ -18,4 +18,31 @@ else json.identifier popular_project_common["identifier"] json.description popular_project_common["description"] end -end \ No newline at end of file +end + +ids = $redis_cache.zrevrange("v2-user-project-rank:#{item[0]}", 0, 999, withscores: true).map{|a|a[0]} +visits = 0 +forks = 0 +watchers = 0 +praises = 0 +issues = 0 +pulls = 0 +commits = 0 +ids.each do |pid| + project_common = $redis_cache.hgetall("v2-project-common:#{pid}") + visits = visits + project_common["visits"].to_i + forks = forks + project_common["forks"].to_i + watchers = watchers + project_common["watchers"].to_i + praises = praises + project_common["praises"].to_i + issues = issues + project_common["issues"].to_i + pulls = pulls + project_common["pullrequests"].to_i + commits = commits + project_common["commits"].to_i +end + +json.visits visits +json.forks forks +json.watchers watchers +json.praises praises +json.issues issues +json.pulls pulls +json.commits commits \ No newline at end of file From d2b4b500b6dee498203f71363af9d4c4c9f82ccd Mon Sep 17 00:00:00 2001 From: xxq250 Date: Sat, 15 Apr 2023 22:18:34 +0800 Subject: [PATCH 341/438] =?UTF-8?q?top=E7=94=A8=E6=88=B7=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=8E=92=E8=A1=8C=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/project_rank/_detail.json.jbuilder | 3 ++- app/views/user_rank/_detail.json.jbuilder | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/views/project_rank/_detail.json.jbuilder b/app/views/project_rank/_detail.json.jbuilder index f3305649b..d5b4b016b 100644 --- a/app/views/project_rank/_detail.json.jbuilder +++ b/app/views/project_rank/_detail.json.jbuilder @@ -29,4 +29,5 @@ json.watchers project_common["watchers"] json.praises project_common["praises"] json.issues project_common["issues"] json.pulls project_common["pullrequests"] -json.commits project_common["commits"] \ No newline at end of file +json.commits project_common["commits"] +json.issues project_common["issues"] \ No newline at end of file diff --git a/app/views/user_rank/_detail.json.jbuilder b/app/views/user_rank/_detail.json.jbuilder index d94ef342e..e3f8ce5d0 100644 --- a/app/views/user_rank/_detail.json.jbuilder +++ b/app/views/user_rank/_detail.json.jbuilder @@ -28,6 +28,7 @@ praises = 0 issues = 0 pulls = 0 commits = 0 +issues = 0 ids.each do |pid| project_common = $redis_cache.hgetall("v2-project-common:#{pid}") visits = visits + project_common["visits"].to_i @@ -37,6 +38,7 @@ ids.each do |pid| issues = issues + project_common["issues"].to_i pulls = pulls + project_common["pullrequests"].to_i commits = commits + project_common["commits"].to_i + issues = issues + project_common["issues"].to_i end json.visits visits @@ -45,4 +47,5 @@ json.watchers watchers json.praises praises json.issues issues json.pulls pulls -json.commits commits \ No newline at end of file +json.commits commits +json.issues issues \ No newline at end of file From 6a1abd36cf075f215406406e38a0e61d121731a9 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Sat, 15 Apr 2023 22:19:26 +0800 Subject: [PATCH 342/438] =?UTF-8?q?top=E7=94=A8=E6=88=B7=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=8E=92=E8=A1=8C=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/project_rank/_detail.json.jbuilder | 3 ++- app/views/user_rank/_detail.json.jbuilder | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/views/project_rank/_detail.json.jbuilder b/app/views/project_rank/_detail.json.jbuilder index f3305649b..d5b4b016b 100644 --- a/app/views/project_rank/_detail.json.jbuilder +++ b/app/views/project_rank/_detail.json.jbuilder @@ -29,4 +29,5 @@ json.watchers project_common["watchers"] json.praises project_common["praises"] json.issues project_common["issues"] json.pulls project_common["pullrequests"] -json.commits project_common["commits"] \ No newline at end of file +json.commits project_common["commits"] +json.issues project_common["issues"] \ No newline at end of file diff --git a/app/views/user_rank/_detail.json.jbuilder b/app/views/user_rank/_detail.json.jbuilder index d94ef342e..e3f8ce5d0 100644 --- a/app/views/user_rank/_detail.json.jbuilder +++ b/app/views/user_rank/_detail.json.jbuilder @@ -28,6 +28,7 @@ praises = 0 issues = 0 pulls = 0 commits = 0 +issues = 0 ids.each do |pid| project_common = $redis_cache.hgetall("v2-project-common:#{pid}") visits = visits + project_common["visits"].to_i @@ -37,6 +38,7 @@ ids.each do |pid| issues = issues + project_common["issues"].to_i pulls = pulls + project_common["pullrequests"].to_i commits = commits + project_common["commits"].to_i + issues = issues + project_common["issues"].to_i end json.visits visits @@ -45,4 +47,5 @@ json.watchers watchers json.praises praises json.issues issues json.pulls pulls -json.commits commits \ No newline at end of file +json.commits commits +json.issues issues \ No newline at end of file From 5c563db6e4573231cd006f0f5b8e51116a90153d Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Apr 2023 10:13:23 +0800 Subject: [PATCH 343/438] =?UTF-8?q?commit=E5=8A=A0=E5=85=A5=E5=88=B0?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=8A=A8=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/commit_logs_controller.rb | 12 +++++++++++- app/models/commit_log.rb | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/controllers/commit_logs_controller.rb b/app/controllers/commit_logs_controller.rb index cc071340e..7c0828b6b 100644 --- a/app/controllers/commit_logs_controller.rb +++ b/app/controllers/commit_logs_controller.rb @@ -19,12 +19,22 @@ class CommitLogsController < ApplicationController params[:commits].each do |commit| commit_id = commit[:id] message = commit[:message] - CommitLog.create(user: user, project: project, repository_id: repository_id, + commit_log = CommitLog.create(user: user, project: project, repository_id: repository_id, name: repository_name, full_name: repository_full_name, ref: ref, commit_id: commit_id, message: message) + commit_log.project_trends.create(user_id: user.id, project_id: project&.id, action_type: "create") # 统计数据新增 CacheAsyncSetJob.perform_later("project_common_service", {commits: 1}, project.id) end end + + def activity + commit_sql = CommitLog.select("user_id,project_id, '' as ref").order(id: :desc).limit(10).to_sql + project_sql = Project.select("user_id,id as project_id, '' as ref").order(id: :desc).limit(10).to_sql + project_sql = Issue.select("user_id,project_id, '' as ref").order(id: :desc).limit(10).to_sql + project_sql = Issue.select("user_id,project_id, '' as ref").order(id: :desc).limit(10).to_sql + privacy_organizations_sql = Project.with_visibility("privacy").joins(:organization_users).where(organization_users: {user_id: current_user.id}).to_sql + @organizations = Organization.from("( #{ logged_organizations_sql } UNION #{ privacy_organizations_sql } ) AS users") + end end diff --git a/app/models/commit_log.rb b/app/models/commit_log.rb index 9b51b0631..22cdb1e18 100644 --- a/app/models/commit_log.rb +++ b/app/models/commit_log.rb @@ -3,4 +3,6 @@ class CommitLog < ApplicationRecord belongs_to :project belongs_to :repository + has_many :project_trends, as: :trend, dependent: :destroy + end From 08d2ccada2e836e6864f8893d689840d09b6e468 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Apr 2023 10:13:30 +0800 Subject: [PATCH 344/438] =?UTF-8?q?commit=E5=8A=A0=E5=85=A5=E5=88=B0?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=8A=A8=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20230417032154_update_commit_log_utf8.rb | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 db/migrate/20230417032154_update_commit_log_utf8.rb diff --git a/db/migrate/20230417032154_update_commit_log_utf8.rb b/db/migrate/20230417032154_update_commit_log_utf8.rb new file mode 100644 index 000000000..fa8ac44d7 --- /dev/null +++ b/db/migrate/20230417032154_update_commit_log_utf8.rb @@ -0,0 +1,6 @@ +class UpdateCommitLogUtf8 < ActiveRecord::Migration[5.2] + def change + execute("ALTER TABLE `commit_logs` MODIFY `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;") + execute("ALTER TABLE `commit_logs` MODIFY `full_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;") + end +end From 71c1a0f436316b5c99647cbb0d7cebdd8ea56193 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Apr 2023 10:15:57 +0800 Subject: [PATCH 345/438] =?UTF-8?q?commit=E5=8A=A0=E5=85=A5=E5=88=B0?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=8A=A8=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/commit_log.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/commit_log.rb b/app/models/commit_log.rb index 22cdb1e18..def2846fa 100644 --- a/app/models/commit_log.rb +++ b/app/models/commit_log.rb @@ -5,4 +5,8 @@ class CommitLog < ApplicationRecord has_many :project_trends, as: :trend, dependent: :destroy + def title + self.message + end + end From 2175e798e11806a2189261290b9669b1d58b7c98 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Apr 2023 10:27:28 +0800 Subject: [PATCH 346/438] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/project_trends_controller.rb | 12 ++++++++++-- app/views/project_trends/last.json.jbuilder | 8 ++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 app/views/project_trends/last.json.jbuilder diff --git a/app/controllers/project_trends_controller.rb b/app/controllers/project_trends_controller.rb index f283d05f7..4c0b2348f 100644 --- a/app/controllers/project_trends_controller.rb +++ b/app/controllers/project_trends_controller.rb @@ -1,6 +1,6 @@ class ProjectTrendsController < ApplicationController - before_action :load_repository - before_action :check_project_public + before_action :load_repository, except: [:last] + before_action :check_project_public, except: [:last] def index project_trends = @project.project_trends.preload(:user, trend: :user, project: :owner) @@ -42,6 +42,14 @@ class ProjectTrendsController < ApplicationController @project_trends = project_trends.page(@page).per(@limit) end + def last + project_trends = ProjectTrend.preload(:user, trend: :user, project: :owner).order("id desc") + @page = params[:page] || 1 + @limit = params[:limit] || 20 + @project_trends_count = project_trends.count + @project_trends = project_trends.page(@page).per(@limit) + end + private def check_project_public diff --git a/app/views/project_trends/last.json.jbuilder b/app/views/project_trends/last.json.jbuilder new file mode 100644 index 000000000..04edf97a9 --- /dev/null +++ b/app/views/project_trends/last.json.jbuilder @@ -0,0 +1,8 @@ +json.partial! "commons/success" +json.total_count @project_trends_count +json.project_trends do + json.array! @project_trends.to_a.each do |trend| + json.partial! "detail", trend: trend + end +end + From cba729f48210a63482526568e4cf24ecb07817fd Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Apr 2023 10:27:50 +0800 Subject: [PATCH 347/438] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/commit_logs_controller.rb | 9 --------- config/routes.rb | 1 + 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/app/controllers/commit_logs_controller.rb b/app/controllers/commit_logs_controller.rb index 7c0828b6b..b034f673c 100644 --- a/app/controllers/commit_logs_controller.rb +++ b/app/controllers/commit_logs_controller.rb @@ -28,13 +28,4 @@ class CommitLogsController < ApplicationController end end - - def activity - commit_sql = CommitLog.select("user_id,project_id, '' as ref").order(id: :desc).limit(10).to_sql - project_sql = Project.select("user_id,id as project_id, '' as ref").order(id: :desc).limit(10).to_sql - project_sql = Issue.select("user_id,project_id, '' as ref").order(id: :desc).limit(10).to_sql - project_sql = Issue.select("user_id,project_id, '' as ref").order(id: :desc).limit(10).to_sql - privacy_organizations_sql = Project.with_visibility("privacy").joins(:organization_users).where(organization_users: {user_id: current_user.id}).to_sql - @organizations = Organization.from("( #{ logged_organizations_sql } UNION #{ privacy_organizations_sql } ) AS users") - end end diff --git a/config/routes.rb b/config/routes.rb index 8b943f543..36f056c2a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1074,6 +1074,7 @@ Rails.application.routes.draw do get 'oauth/get_token_callback', to: 'oauth#get_token_callback' resources :commit_logs, :only => [:create] + get 'activity/last', to: 'project_trends#last' scope '/app' do get '/', to: 'installations#app' From 0a693a77b89b6d564fb6085d3273162e9ecb58e6 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Apr 2023 10:38:10 +0800 Subject: [PATCH 348/438] =?UTF-8?q?commit=E5=8A=A0=E5=85=A5=E5=88=B0?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=8A=A8=E6=80=81=EF=BC=8C=E5=B9=B6=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project_trends/_detail.json.jbuilder | 7 + config/locales/zh-CN.yml | 479 +++++++++--------- 2 files changed, 247 insertions(+), 239 deletions(-) diff --git a/app/views/project_trends/_detail.json.jbuilder b/app/views/project_trends/_detail.json.jbuilder index 04de10f6a..29609bd28 100644 --- a/app/views/project_trends/_detail.json.jbuilder +++ b/app/views/project_trends/_detail.json.jbuilder @@ -18,6 +18,13 @@ if trend.trend_type == "Issue" json.partial! "issues/simple_issue_item", locals: {issue: trend.trend} elsif trend.trend_type == "VersionRelease" json.partial! "version_releases/simple_version_release", locals: {version: trend.trend} +elsif trend.trend_type == "CommitLog" + commit_log = trend.trend + json.user do + json.partial! 'users/user_simple', locals: {user: commit_log.user} + end + json.ref commit_log.ref.to_s.gsub("refs/heads/", "") + json.extract! commit_log, :id,:name,:full_name,:message, :commit_id,:created_at,:updated_at else json.name trend.trend&.title json.created_at format_time(trend.trend&.created_at) diff --git a/config/locales/zh-CN.yml b/config/locales/zh-CN.yml index e7c586417..d5c68d448 100644 --- a/config/locales/zh-CN.yml +++ b/config/locales/zh-CN.yml @@ -1,240 +1,241 @@ -zh-CN: - error: - record_not_found: 您访问的页面不存在或已被删除 - forbidden: 您没有权限进行该操作 - unauthorized: 未登录 - - button_test: 测试 - button_edit: 编辑 - button_delete: 删除 - - admins_apply_status: - status: - 'pending': '待审批' - 'processed': '已审批' - 'refused': '已拒绝' - 'agreed': '已同意' - trend: - Issue: 疑修(Issue) - PullRequest: 合并请求(PR) - VersionRelease: 版本发布 - create: 创建了 - journal: 回复了 - close: 关闭了 - merge: 合并了 - push: 发布了 - - version: - draft: 草稿 - - journal_detail: - branch_name: 分支 - close_pr: 合并 - merge: 合并 - issue_tags_value: 标记 - lock_issue: 锁定工单 - unlock_issue: 解锁工单 - destroy_issue_depend: 删除依赖 - issue_depend: 增加依赖 - work_time: 开始工作 - cancel_time: 取消时间跟踪 - end_time: 停止工作 - subject: 主题 - description: 描述 - is_private: 私有 - assigned_to_id: 指派给 - tracker_id: 类型 - status_id: 状态 - priority_id: 优先级 - fixed_version_id: 里程碑 - start_date: 开始日期 - due_date: 结束日期 - estimated_hours: 添加耗时 - done_ratio: 完成度 - t: 是 - f: 否 - true: 是 - false: 否 - issue_tag_ids: 标记 - issue_type: 分类 - token: 悬赏金额 - close_issue: 工单 - activerecord: - attributes: - organization: - login: '组织名称' - user: - login: '登录名' - lastname: '姓名' - nickname: '昵称' - discuss: - content: '内容' - journals_for_message: - notes: '内容' - subject: - name: '课程名称' - description: '课程简介' - learning_notes: '学习须知' - stage: - name: '章节名称' - description: '章节描述' - shixun_info: - description: '简介' - fork_reason: 'fork原因' - challenge: - task_pass: '过关任务' - test_set: - input: '输入' - output: '输出' - challenge_question: - option_name: '选项' - challenge_choose: - subject: '题干' - challenge_answer: - contents: '答案内容' - memo: - content: '帖子内容' - course: - name: '课堂名称' - course_group: - name: '分班名称' - course_module: - module_name: '目录名称' - course_second_category: - name: '目录名称' - inform: - name: '标题' - description: '内容' - course_stage: - name: '章节名称' - description: '章节描述' - attachment: - description: '资源描述' - message: - subject: '标题' - message_detail: - content: '内容' - homework_common: - name: '标题' - description: '内容' - explanation: '内容' - reference_answer: '参考答案' - student_work: - description: '内容' - student_works_score: - comment: '评语' - challenge_work_score: - comment: '评语' - shixun_work_comment: - comment: '评语' - hidden_comment: '隐藏评语' - graduation_topic: - name: '选题名称' - description: '选题简介' - graduation_task: - name: '任务标题' - description: '内容' - graduation_work: - description: '作品内容' - graduation_work_score: - comment: '评语' - poll: - polls_name: '问卷标题' - polls_description: '问卷须知' - poll_question: - question_title: '题干' - poll_answer: - answer_text: '选项' - poll_vote: - vote_text: '内容' - exercise: - exercise_name: '试卷标题' - exercise_description: '试卷须知' - exercise_question: - question_title: '题干' - exercise_choice: - choice_text: '选项' - exercise_answer: - answer_text: '答案' - exercise_standard_answer: - answer_text: '参考答案' - exercise_answer_comment: - comment: '评语' - homework_bank: - name: '标题' - description: '内容' - reference_answer: '参考答案' - gtask_bank: - name: '任务标题' - description: '内容' - gtopic_bank: - name: '选题名称' - description: '选题简介' - exercise_bank: - name: '试卷标题' - description: '试卷须知' - exercise_bank_question: - question_title: '题干' - exerise_bank_choice: - choice_text: '选项' - exercise_bank_standard_answer: - answer_text: '参考答案' - library: - title: '标题' - content: '内容' - author_name: '作者姓名' - author_school_name: '作者单位名称' - competition: - introduction: '简介' - competition_module_md_content: - content: '内容' - chart_rule: - content: '内容' - project_package: - title: '标题' - examination_bank: - name: '试卷名称' - item_bank: - name: '题干' - item_analysis: - analysis: '解析' - item_choice: - choice_text: '选项' - hack: - name: '任务名称' - description: '描述' - hack_set: - input: '测试集输入' - output: '测试集输出' - hack_user_lastest_code: - notes: '笔记' - trustie_hack: - description: '描述' - discipline: - name: '名称' - sub_discipline: - name: '名称' - tag_discipline: - name: '名称' - live_link: - description: '说明' - url: '链接' - course_name: '课程名称' - platform: '直播平台' - live_time: '开播时间' - duration: '直播时长' - project_language: - name: '项目语言' - license: - name: '许可证名称' - content: '许可证内容' - ignore: - name: 'git忽略文件名称' - content: 'git忽略文件内容' - feedback_message_history: - title: '' - close_pr: 合并请求 - roles: - Developer: 开发者 - Reporter: 报告者 +zh-CN: + error: + record_not_found: 您访问的页面不存在或已被删除 + forbidden: 您没有权限进行该操作 + unauthorized: 未登录 + + button_test: 测试 + button_edit: 编辑 + button_delete: 删除 + + admins_apply_status: + status: + 'pending': '待审批' + 'processed': '已审批' + 'refused': '已拒绝' + 'agreed': '已同意' + trend: + Issue: 疑修(Issue) + PullRequest: 合并请求(PR) + VersionRelease: 版本发布 + CommitLog: 代码(Commit) + create: 创建了 + journal: 回复了 + close: 关闭了 + merge: 合并了 + push: 发布了 + + version: + draft: 草稿 + + journal_detail: + branch_name: 分支 + close_pr: 合并 + merge: 合并 + issue_tags_value: 标记 + lock_issue: 锁定工单 + unlock_issue: 解锁工单 + destroy_issue_depend: 删除依赖 + issue_depend: 增加依赖 + work_time: 开始工作 + cancel_time: 取消时间跟踪 + end_time: 停止工作 + subject: 主题 + description: 描述 + is_private: 私有 + assigned_to_id: 指派给 + tracker_id: 类型 + status_id: 状态 + priority_id: 优先级 + fixed_version_id: 里程碑 + start_date: 开始日期 + due_date: 结束日期 + estimated_hours: 添加耗时 + done_ratio: 完成度 + t: 是 + f: 否 + true: 是 + false: 否 + issue_tag_ids: 标记 + issue_type: 分类 + token: 悬赏金额 + close_issue: 工单 + activerecord: + attributes: + organization: + login: '组织名称' + user: + login: '登录名' + lastname: '姓名' + nickname: '昵称' + discuss: + content: '内容' + journals_for_message: + notes: '内容' + subject: + name: '课程名称' + description: '课程简介' + learning_notes: '学习须知' + stage: + name: '章节名称' + description: '章节描述' + shixun_info: + description: '简介' + fork_reason: 'fork原因' + challenge: + task_pass: '过关任务' + test_set: + input: '输入' + output: '输出' + challenge_question: + option_name: '选项' + challenge_choose: + subject: '题干' + challenge_answer: + contents: '答案内容' + memo: + content: '帖子内容' + course: + name: '课堂名称' + course_group: + name: '分班名称' + course_module: + module_name: '目录名称' + course_second_category: + name: '目录名称' + inform: + name: '标题' + description: '内容' + course_stage: + name: '章节名称' + description: '章节描述' + attachment: + description: '资源描述' + message: + subject: '标题' + message_detail: + content: '内容' + homework_common: + name: '标题' + description: '内容' + explanation: '内容' + reference_answer: '参考答案' + student_work: + description: '内容' + student_works_score: + comment: '评语' + challenge_work_score: + comment: '评语' + shixun_work_comment: + comment: '评语' + hidden_comment: '隐藏评语' + graduation_topic: + name: '选题名称' + description: '选题简介' + graduation_task: + name: '任务标题' + description: '内容' + graduation_work: + description: '作品内容' + graduation_work_score: + comment: '评语' + poll: + polls_name: '问卷标题' + polls_description: '问卷须知' + poll_question: + question_title: '题干' + poll_answer: + answer_text: '选项' + poll_vote: + vote_text: '内容' + exercise: + exercise_name: '试卷标题' + exercise_description: '试卷须知' + exercise_question: + question_title: '题干' + exercise_choice: + choice_text: '选项' + exercise_answer: + answer_text: '答案' + exercise_standard_answer: + answer_text: '参考答案' + exercise_answer_comment: + comment: '评语' + homework_bank: + name: '标题' + description: '内容' + reference_answer: '参考答案' + gtask_bank: + name: '任务标题' + description: '内容' + gtopic_bank: + name: '选题名称' + description: '选题简介' + exercise_bank: + name: '试卷标题' + description: '试卷须知' + exercise_bank_question: + question_title: '题干' + exerise_bank_choice: + choice_text: '选项' + exercise_bank_standard_answer: + answer_text: '参考答案' + library: + title: '标题' + content: '内容' + author_name: '作者姓名' + author_school_name: '作者单位名称' + competition: + introduction: '简介' + competition_module_md_content: + content: '内容' + chart_rule: + content: '内容' + project_package: + title: '标题' + examination_bank: + name: '试卷名称' + item_bank: + name: '题干' + item_analysis: + analysis: '解析' + item_choice: + choice_text: '选项' + hack: + name: '任务名称' + description: '描述' + hack_set: + input: '测试集输入' + output: '测试集输出' + hack_user_lastest_code: + notes: '笔记' + trustie_hack: + description: '描述' + discipline: + name: '名称' + sub_discipline: + name: '名称' + tag_discipline: + name: '名称' + live_link: + description: '说明' + url: '链接' + course_name: '课程名称' + platform: '直播平台' + live_time: '开播时间' + duration: '直播时长' + project_language: + name: '项目语言' + license: + name: '许可证名称' + content: '许可证内容' + ignore: + name: 'git忽略文件名称' + content: 'git忽略文件内容' + feedback_message_history: + title: '' + close_pr: 合并请求 + roles: + Developer: 开发者 + Reporter: 报告者 Manager: 管理员 \ No newline at end of file From 5922c8800fde43e597c8eca7d11085596f8cd738 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Apr 2023 10:40:58 +0800 Subject: [PATCH 349/438] =?UTF-8?q?commit=E5=8A=A0=E5=85=A5=E5=88=B0?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=8A=A8=E6=80=81=EF=BC=8C=E5=B9=B6=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/project_trends/_detail.json.jbuilder | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/views/project_trends/_detail.json.jbuilder b/app/views/project_trends/_detail.json.jbuilder index 29609bd28..f8d1006dd 100644 --- a/app/views/project_trends/_detail.json.jbuilder +++ b/app/views/project_trends/_detail.json.jbuilder @@ -19,12 +19,14 @@ if trend.trend_type == "Issue" elsif trend.trend_type == "VersionRelease" json.partial! "version_releases/simple_version_release", locals: {version: trend.trend} elsif trend.trend_type == "CommitLog" - commit_log = trend.trend - json.user do - json.partial! 'users/user_simple', locals: {user: commit_log.user} + json.commit_log do + commit_log = trend.trend + json.user do + json.partial! 'users/user_simple', locals: {user: commit_log.user} + end + json.ref commit_log.ref.to_s.gsub("refs/heads/", "") + json.extract! commit_log, :id,:name,:full_name,:message, :commit_id,:created_at,:updated_at end - json.ref commit_log.ref.to_s.gsub("refs/heads/", "") - json.extract! commit_log, :id,:name,:full_name,:message, :commit_id,:created_at,:updated_at else json.name trend.trend&.title json.created_at format_time(trend.trend&.created_at) From 1baee3efb6c8b73628cc60ccf19c1d9b2bd5f19b Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Apr 2023 10:44:50 +0800 Subject: [PATCH 350/438] =?UTF-8?q?commit=E5=8A=A0=E5=85=A5=E5=88=B0?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=8A=A8=E6=80=81=EF=BC=8C=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/routes.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 36f056c2a..517614efd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -763,6 +763,8 @@ Rails.application.routes.draw do end end end + + get 'activity/last', to: 'project_trends#last' # Project Area END scope module: :helps do @@ -1074,7 +1076,6 @@ Rails.application.routes.draw do get 'oauth/get_token_callback', to: 'oauth#get_token_callback' resources :commit_logs, :only => [:create] - get 'activity/last', to: 'project_trends#last' scope '/app' do get '/', to: 'installations#app' From 0a50da33a9badb89b1c69dab2bc79db04f00cffc Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Apr 2023 10:49:17 +0800 Subject: [PATCH 351/438] =?UTF-8?q?commit=E5=8A=A0=E5=85=A5=E5=88=B0?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=8A=A8=E6=80=81=EF=BC=8C=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/routes.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/routes.rb b/config/routes.rb index 517614efd..0c04bf1db 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -117,6 +117,7 @@ Rails.application.routes.draw do get 'home/index' get 'home/search' get 'main/first_stamp' + get 'activity/last', to: 'project_trends#last' get 'search', to: 'searchs#index' put 'commons/hidden', to: 'commons#hidden' From 1be61f97cfdb59538853c6f51591959f9e8db2e4 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Apr 2023 10:49:30 +0800 Subject: [PATCH 352/438] =?UTF-8?q?commit=E5=8A=A0=E5=85=A5=E5=88=B0?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=8A=A8=E6=80=81=EF=BC=8C=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/routes.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 0c04bf1db..0e760fbe9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -765,7 +765,6 @@ Rails.application.routes.draw do end end - get 'activity/last', to: 'project_trends#last' # Project Area END scope module: :helps do From 578acd7845afd15a97010f64d51898810bc4f866 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 17 Apr 2023 11:35:28 +0800 Subject: [PATCH 353/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E8=80=85=E4=BB=A3=E7=A0=81=E8=A1=8C=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 +- .../v1/projects/contributors_controller.rb | 11 ++++++ .../v1/projects/contributors/stat_service.rb | 38 +++++++++++++++++++ .../projects/contributors/stat.json.jbuilder | 26 +++++++++++++ config/routes/api.rb | 5 +++ 5 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 app/controllers/api/v1/projects/contributors_controller.rb create mode 100644 app/services/api/v1/projects/contributors/stat_service.rb create mode 100644 app/views/api/v1/projects/contributors/stat.json.jbuilder diff --git a/Gemfile b/Gemfile index 947543c5f..8051448e4 100644 --- a/Gemfile +++ b/Gemfile @@ -143,4 +143,4 @@ gem 'doorkeeper' gem 'doorkeeper-jwt' -gem 'gitea-client', '~> 1.4.1' +gem 'gitea-client', '~> 1.4.2' diff --git a/app/controllers/api/v1/projects/contributors_controller.rb b/app/controllers/api/v1/projects/contributors_controller.rb new file mode 100644 index 000000000..abb5827c5 --- /dev/null +++ b/app/controllers/api/v1/projects/contributors_controller.rb @@ -0,0 +1,11 @@ +class Api::V1::Projects::ContributorsController < Api::V1::BaseController + before_action :require_public_and_member_above, only: [:index, :stat] + + # todo + def index + end + + def stat + @result_object = Api::V1::Projects::Contributors::StatService.call(@project, {branch: params[:branch], pass_year: params[:pass_year], page: page, limit: limit}, current_user&.gitea_token) + end +end \ No newline at end of file diff --git a/app/services/api/v1/projects/contributors/stat_service.rb b/app/services/api/v1/projects/contributors/stat_service.rb new file mode 100644 index 000000000..d264a109b --- /dev/null +++ b/app/services/api/v1/projects/contributors/stat_service.rb @@ -0,0 +1,38 @@ +class Api::V1::Projects::Contributors::StatService < ApplicationService + + attr_reader :project, :branch, :pass_year, :owner, :repo, :token, :page, :limit + attr_accessor :gitea_data + + def initialize(project, params, token=nil) + @project = project + @branch = params[:branch] + @pass_year = params[:pass_year] + @page = params[:page] || 1 + @limit = params[:limit] || 15 + @owner = project&.owner.login + @repo = project&.identifier + @token = token + end + + def call + load_gitea_data + + gitea_data + end + + private + def request_params + param = { + access_token: token + } + param.merge!(branch: branch) if branch.present? + param.merge!(pass_year: pass_year) if pass_year.present? + + param + end + + def load_gitea_data + @gitea_data = $gitea_hat_client.get_repos_contributors_stat_by_owner_repo(owner, repo, {query: request_params}) rescue nil + raise Error, '获取贡献者(代码行)失败!' unless @gitea_data.is_a?(Hash) + end +end \ No newline at end of file diff --git a/app/views/api/v1/projects/contributors/stat.json.jbuilder b/app/views/api/v1/projects/contributors/stat.json.jbuilder new file mode 100644 index 000000000..a01ad81a5 --- /dev/null +++ b/app/views/api/v1/projects/contributors/stat.json.jbuilder @@ -0,0 +1,26 @@ +json.total_count @result_object[:total_data].to_i +json.contributors @result_object[:data].each do |contributor| + user = $redis_cache.hgetall("v2-owner-common:#{contributor["name"]}-#{contributor["email"]}") + if user.blank? + json.contributions contributor["commits"] + json.additions contributor["additions"] + json.deletions contributor["deletions"] + # json.id contributor["id"] + json.login contributor["name"] + json.email contributor["email"] + json.type nil + json.name contributor["name"] + json.image_url User::Avatar.get_letter_avatar_url(contributor["name"]) + else + json.contributions contributor["commits"] + json.additions contributor["additions"] + json.deletions contributor["deletions"] + json.id user["id"] + json.login user["login"] + json.email user["email"] + json.name user["name"] + json.type user["type"] + json.name user["name"] + json.image_url user["avatar_url"] + end +end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index 0a02065e2..62d49caf2 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -82,6 +82,11 @@ defaults format: :json do resources :commits, only: [:index] resources :code_stats, only: [:index] + resources :contributors, only: [:index] do + collection do + get :stat + end + end get '/commits/:sha/diff', to: 'commits#diff' get '/git/blobs/:sha', to: 'git#blobs' get '/git/trees/:sha', to: 'git#trees' From c2484119f93cf70c8535d16a4278a6b5937c63be Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Apr 2023 13:53:02 +0800 Subject: [PATCH 354/438] rake commit_log_to_db --- lib/tasks/commit_log_to_db.rake | 76 +++++++++++++++++++++++++++++++ lib/tasks/total_commit_to_db.rake | 65 ++++++++++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 lib/tasks/commit_log_to_db.rake create mode 100644 lib/tasks/total_commit_to_db.rake diff --git a/lib/tasks/commit_log_to_db.rake b/lib/tasks/commit_log_to_db.rake new file mode 100644 index 000000000..5cb0003f3 --- /dev/null +++ b/lib/tasks/commit_log_to_db.rake @@ -0,0 +1,76 @@ +namespace :commit_log_to_db do + desc "commit_log_to_db" + task done: :environment do + puts "project_id=================#{ENV['project_id']}" + return if ENV['project_id'].blank? + projects = Project.where(id: ENV['project_id']) + projects.each_with_index do |project, index| + result = Gitea::Repository::Commits::ListService.call(project.owner.login,project.identifier,sha: "", page: 1, limit: 200, token: project.owner.gitea_token) + next if result.blank? || result[:total_count].blank? + total_count = result[:total_count] + # next if total_count > 2000 + puts "#{index} total_count==========#{total_count}" + if total_count > 200 + total_page = (total_count / 200) + 1 + total_page.times do |i| + add_commit_by_page(project, i + 1) + end + else + # add_commit_to_index(project, 1) + data = "" + result[:body].each do |commit| + # puts "commit==========#{commit}" + commiter = commit['commit']['committer'] + # "luoyuan " + commit_author = "#{commiter['name']} <#{commiter['email']}>" + commit_sha = commit['sha'] + ref = "master" + commit_message = commit['commit']['message'] + user = User.find_by(mail: commiter['email']) + commit_date = Time.parse(commit['commit']['author']['date']) + commit_date_str = commit_date.strftime("%a %b %d %H:%M:%S") + + data += "(#{user&.id},#{project.id},#{project.repository&.id},'#{project.identifier}','#{project.owner.name}/#{project.identifier}','#{commit_sha}','#{ref}','#{commit_message}','#{commit_date_str}','#{commit_date_str}')," + end + data = data[0,data.length-1] + sql_connection = ActiveRecord::Base.connection + sql_connection.begin_db_transaction + sql = "INSERT INTO commit_logs (`user_id`, `project_id`, `repository_id`, `name`, `full_name`, `commit_id`, `ref`, `message`, `created_at`, `updated_at`) VALUES #{data}" + sql_connection.execute(sql) + end + end + + # Time.now + # Wed Mar 15 14:12:09 2023 +0800 + # Time.now.strftime("%a %b %d %H:%M:%S %Y") + # Time.now.strftime("%a %b %d %H:%M:%S %Y +0800") + Time.parse("2023-03-15 14:12:09").strftime("%a %b %d %H:%M:%S %Y +0800") + + end + + def add_commit_by_page(project, page) + # Gitea::Repository::Commits::ListSliceService.call(project.owner.login,project.identifier,sha: "", page: 1, limit: 1000, token: "a9244ecac647dd33fee3b480c5898baab1d3fe7d") + result = Gitea::Repository::Commits::ListService.call(project.owner.login,project.identifier,sha: "", page: page, limit: 200, token: project.owner.gitea_token) + data = "" + result[:body].each do |commit| + # puts "commit==========#{commit}" + commiter = commit['commit']['committer'] + # "luoyuan " + commit_author = "#{commiter['name']} <#{commiter['email']}>" + commit_sha = commit['sha'] + ref = "master" + commit_message = commit['commit']['message'] + user = User.find_by(mail: commiter['email']) + commit_date = Time.parse(commit['commit']['author']['date']) + commit_date_str = commit_date.strftime("%a %b %d %H:%M:%S") + + data += "(#{user&.id},#{project.id},#{project.repository&.id},'#{project.identifier}','#{project.owner.name}/#{project.identifier}','#{commit_sha}','#{ref}','#{commit_message}','#{commit_date_str}','#{commit_date_str}')," + end + data = data[0,data.length-1] + sql_connection = ActiveRecord::Base.connection + sql_connection.begin_db_transaction + sql = "INSERT INTO commit_logs (`user_id`, `project_id`, `repository_id`, `name`, `full_name`, `commit_id`, `ref`, `message`, `created_at`, `updated_at`) VALUES #{data}" + sql_connection.execute(sql) + end + +end \ No newline at end of file diff --git a/lib/tasks/total_commit_to_db.rake b/lib/tasks/total_commit_to_db.rake new file mode 100644 index 000000000..cdb29e108 --- /dev/null +++ b/lib/tasks/total_commit_to_db.rake @@ -0,0 +1,65 @@ +namespace :total_commit_to_db do + desc "total_commit_to_db" + task done: :environment do + project_name = ENV['name'] || "mindspore" + puts "project_id=================#{project_name}" + projects = Project.where(identifier: ['MindSpore-first-experience', ' MindSpore-install', 'MindSpore-Application-practice', 'MindSpore-Model-Development', 'MindSpore-Data-preprocessing', 'Mindspore-Data-storage-use', 'MindSpore-Data-storage-kunpeng', 'MindSpore-LeNet-jzx3', 'MindSpore-competition'] ) + + projects.each_with_index do |project, index| + result = Gitea::Repository::Commits::ListService.call(project.owner.login,project.identifier,sha: "", page: 1, limit: 5, token: project.owner.gitea_token) + next if result.blank? || result[:total_count].blank? + total_count = result[:total_count] + # next if total_count > 2000 + puts "#{index} total_count==========#{total_count}" + if total_count > 200 + total_page = (total_count / 200) + 1 + total_page.times do |i| + add_commit_to_index(project, i + 1) + end + else + # add_commit_to_index(project, 1) + data = "" + result[:body].each do |commit| + commit_date = Time.parse(commit['commit']['author']['date']) + commit_date_str = commit_date.strftime("%Y-%m-%d") + data += "(\"#{commit_date_str}\",1)," + end + data = data[0,data.length-1] + sql_connection = ActiveRecord::Base.connection + sql_connection.begin_db_transaction + sql = "insert into mindspore_commit(week_date,num) values #{data}" + sql_connection.execute(sql) + end + puts "#{index} date_count_hash===========#{@date_count_hash.to_json}" + + end + puts "@date_count_hash===========#{@date_count_hash.to_json}" + + + + + # Time.now + # Wed Mar 15 14:12:09 2023 +0800 + # Time.now.strftime("%a %b %d %H:%M:%S %Y") + # Time.now.strftime("%a %b %d %H:%M:%S %Y +0800") + Time.parse("2023-03-15 14:12:09").strftime("%a %b %d %H:%M:%S %Y +0800") + + end + + def add_commit_to_index(project, page) + # Gitea::Repository::Commits::ListSliceService.call(project.owner.login,project.identifier,sha: "", page: 1, limit: 1000, token: "a9244ecac647dd33fee3b480c5898baab1d3fe7d") + result = Gitea::Repository::Commits::ListService.call(project.owner.login,project.identifier,sha: "", page: page, limit: 200, token: project.owner.gitea_token) + data = "" + result[:body].each do |commit| + commit_date = Time.parse(commit['commit']['author']['date']) + commit_date_str = commit_date.strftime("%Y-%m-%d") + data += "(\"#{commit_date_str}\",1)," + end + data = data[0,data.length-1] + sql_connection = ActiveRecord::Base.connection + sql_connection.begin_db_transaction + sql = "insert into mindspore_commit(week_date,num) values #{data}" + sql_connection.execute(sql) + end + +end \ No newline at end of file From 0fa0cc492e8d34ee9ad6170333dc47528932e2ab Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Apr 2023 13:59:09 +0800 Subject: [PATCH 355/438] =?UTF-8?q?rake=20commit=5Flog=5Fto=5Fdb=20?= =?UTF-8?q?=E6=97=A5=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/commit_log_to_db.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/commit_log_to_db.rake b/lib/tasks/commit_log_to_db.rake index 5cb0003f3..bde59a337 100644 --- a/lib/tasks/commit_log_to_db.rake +++ b/lib/tasks/commit_log_to_db.rake @@ -62,7 +62,7 @@ namespace :commit_log_to_db do commit_message = commit['commit']['message'] user = User.find_by(mail: commiter['email']) commit_date = Time.parse(commit['commit']['author']['date']) - commit_date_str = commit_date.strftime("%a %b %d %H:%M:%S") + commit_date_str = commit_date.strftime("%Y-%m-%d %H:%M:%S") data += "(#{user&.id},#{project.id},#{project.repository&.id},'#{project.identifier}','#{project.owner.name}/#{project.identifier}','#{commit_sha}','#{ref}','#{commit_message}','#{commit_date_str}','#{commit_date_str}')," end From 15100689c3f8a592d5c7c0e359dabf67276dcad8 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Apr 2023 14:01:48 +0800 Subject: [PATCH 356/438] =?UTF-8?q?rake=20commit=5Flog=5Fto=5Fdb=20sql?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/commit_log_to_db.rake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tasks/commit_log_to_db.rake b/lib/tasks/commit_log_to_db.rake index bde59a337..bd45d91ce 100644 --- a/lib/tasks/commit_log_to_db.rake +++ b/lib/tasks/commit_log_to_db.rake @@ -30,7 +30,7 @@ namespace :commit_log_to_db do commit_date = Time.parse(commit['commit']['author']['date']) commit_date_str = commit_date.strftime("%a %b %d %H:%M:%S") - data += "(#{user&.id},#{project.id},#{project.repository&.id},'#{project.identifier}','#{project.owner.name}/#{project.identifier}','#{commit_sha}','#{ref}','#{commit_message}','#{commit_date_str}','#{commit_date_str}')," + data += "(#{user&.id},#{project.id},#{project.repository&.id},'#{project.identifier}','#{project.owner.name}/#{project.identifier}','#{commit_sha}','#{ref}',\"#{commit_message}\",'#{commit_date_str}','#{commit_date_str}')," end data = data[0,data.length-1] sql_connection = ActiveRecord::Base.connection @@ -64,7 +64,7 @@ namespace :commit_log_to_db do commit_date = Time.parse(commit['commit']['author']['date']) commit_date_str = commit_date.strftime("%Y-%m-%d %H:%M:%S") - data += "(#{user&.id},#{project.id},#{project.repository&.id},'#{project.identifier}','#{project.owner.name}/#{project.identifier}','#{commit_sha}','#{ref}','#{commit_message}','#{commit_date_str}','#{commit_date_str}')," + data += "(#{user&.id},#{project.id},#{project.repository&.id},'#{project.identifier}','#{project.owner.name}/#{project.identifier}','#{commit_sha}','#{ref}',\"#{commit_message}\",'#{commit_date_str}','#{commit_date_str}')," end data = data[0,data.length-1] sql_connection = ActiveRecord::Base.connection From ffea28596222b13e926588a2e7cd432ebe6db835 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Apr 2023 14:08:20 +0800 Subject: [PATCH 357/438] =?UTF-8?q?rake=20commit=5Flog=5Fto=5Fdb=20?= =?UTF-8?q?=E6=94=BE=E8=A1=8C=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/commit_log_to_db.rake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tasks/commit_log_to_db.rake b/lib/tasks/commit_log_to_db.rake index bd45d91ce..a85084c74 100644 --- a/lib/tasks/commit_log_to_db.rake +++ b/lib/tasks/commit_log_to_db.rake @@ -25,7 +25,7 @@ namespace :commit_log_to_db do commit_author = "#{commiter['name']} <#{commiter['email']}>" commit_sha = commit['sha'] ref = "master" - commit_message = commit['commit']['message'] + commit_message = commit['commit']['message'].to_s.gsub("/n","") user = User.find_by(mail: commiter['email']) commit_date = Time.parse(commit['commit']['author']['date']) commit_date_str = commit_date.strftime("%a %b %d %H:%M:%S") @@ -59,7 +59,7 @@ namespace :commit_log_to_db do commit_author = "#{commiter['name']} <#{commiter['email']}>" commit_sha = commit['sha'] ref = "master" - commit_message = commit['commit']['message'] + commit_message = commit['commit']['message'].to_s.gsub("/n","") user = User.find_by(mail: commiter['email']) commit_date = Time.parse(commit['commit']['author']['date']) commit_date_str = commit_date.strftime("%Y-%m-%d %H:%M:%S") From b8e31b8d0bce624f0814722b4171a17fa48e05ae Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Apr 2023 14:15:45 +0800 Subject: [PATCH 358/438] =?UTF-8?q?rake=20commit=5Flog=5Fto=5Fdb=20?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=B8=8D=E5=AD=98=E5=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/commit_log_to_db.rake | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/tasks/commit_log_to_db.rake b/lib/tasks/commit_log_to_db.rake index a85084c74..6d1c854ea 100644 --- a/lib/tasks/commit_log_to_db.rake +++ b/lib/tasks/commit_log_to_db.rake @@ -27,10 +27,11 @@ namespace :commit_log_to_db do ref = "master" commit_message = commit['commit']['message'].to_s.gsub("/n","") user = User.find_by(mail: commiter['email']) + user_id = user&.id || 1 commit_date = Time.parse(commit['commit']['author']['date']) commit_date_str = commit_date.strftime("%a %b %d %H:%M:%S") - data += "(#{user&.id},#{project.id},#{project.repository&.id},'#{project.identifier}','#{project.owner.name}/#{project.identifier}','#{commit_sha}','#{ref}',\"#{commit_message}\",'#{commit_date_str}','#{commit_date_str}')," + data += "(#{user_id},#{project.id},#{project.repository&.id},'#{project.identifier}','#{project.owner.name}/#{project.identifier}','#{commit_sha}','#{ref}',\"#{commit_message}\",'#{commit_date_str}','#{commit_date_str}')," end data = data[0,data.length-1] sql_connection = ActiveRecord::Base.connection @@ -61,10 +62,11 @@ namespace :commit_log_to_db do ref = "master" commit_message = commit['commit']['message'].to_s.gsub("/n","") user = User.find_by(mail: commiter['email']) + user_id = user&.id || 1 commit_date = Time.parse(commit['commit']['author']['date']) commit_date_str = commit_date.strftime("%Y-%m-%d %H:%M:%S") - data += "(#{user&.id},#{project.id},#{project.repository&.id},'#{project.identifier}','#{project.owner.name}/#{project.identifier}','#{commit_sha}','#{ref}',\"#{commit_message}\",'#{commit_date_str}','#{commit_date_str}')," + data += "(#{user_id},#{project.id},#{project.repository&.id},'#{project.identifier}','#{project.owner.name}/#{project.identifier}','#{commit_sha}','#{ref}',\"#{commit_message}\",'#{commit_date_str}','#{commit_date_str}')," end data = data[0,data.length-1] sql_connection = ActiveRecord::Base.connection From cb848c5b45e40c50cda961df29a7834cdc92840b Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Apr 2023 14:21:12 +0800 Subject: [PATCH 359/438] =?UTF-8?q?=E4=BF=AE=E6=94=B9commit=5Flog=20messag?= =?UTF-8?q?e=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20230417141788_update_commit_log_utf8.rb | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 db/migrate/20230417141788_update_commit_log_utf8.rb diff --git a/db/migrate/20230417141788_update_commit_log_utf8.rb b/db/migrate/20230417141788_update_commit_log_utf8.rb new file mode 100644 index 000000000..8e3af9528 --- /dev/null +++ b/db/migrate/20230417141788_update_commit_log_utf8.rb @@ -0,0 +1,5 @@ +class UpdateCommitLogUtf8 < ActiveRecord::Migration[5.2] + def change + execute("ALTER TABLE `commit_logs` MODIFY `message` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;") + end +end From aaf3b381fbfaba53d13176ca3b156a86afd3ebc1 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Apr 2023 14:22:15 +0800 Subject: [PATCH 360/438] =?UTF-8?q?=E4=BF=AE=E6=94=B9commit=5Flog=20messag?= =?UTF-8?q?e=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ..._log_utf8.rb => 20230417141788_update_commit_log_message.rb} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename db/migrate/{20230417141788_update_commit_log_utf8.rb => 20230417141788_update_commit_log_message.rb} (69%) diff --git a/db/migrate/20230417141788_update_commit_log_utf8.rb b/db/migrate/20230417141788_update_commit_log_message.rb similarity index 69% rename from db/migrate/20230417141788_update_commit_log_utf8.rb rename to db/migrate/20230417141788_update_commit_log_message.rb index 8e3af9528..ee5d1f1c4 100644 --- a/db/migrate/20230417141788_update_commit_log_utf8.rb +++ b/db/migrate/20230417141788_update_commit_log_message.rb @@ -1,4 +1,4 @@ -class UpdateCommitLogUtf8 < ActiveRecord::Migration[5.2] +class UpdateCommitLogMessage < ActiveRecord::Migration[5.2] def change execute("ALTER TABLE `commit_logs` MODIFY `message` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;") end From f370e1906e35f2356757f73be5365e4e577d9cc5 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Apr 2023 14:28:58 +0800 Subject: [PATCH 361/438] =?UTF-8?q?rake=20commit=5Flog=5Fto=5Fdb=20?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=B8=8D=E5=AD=98=E5=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/commit_log_to_db.rake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/tasks/commit_log_to_db.rake b/lib/tasks/commit_log_to_db.rake index 6d1c854ea..ae80f9424 100644 --- a/lib/tasks/commit_log_to_db.rake +++ b/lib/tasks/commit_log_to_db.rake @@ -25,9 +25,9 @@ namespace :commit_log_to_db do commit_author = "#{commiter['name']} <#{commiter['email']}>" commit_sha = commit['sha'] ref = "master" - commit_message = commit['commit']['message'].to_s.gsub("/n","") + commit_message = commit['commit']['message'].to_s.gsub("\"","") user = User.find_by(mail: commiter['email']) - user_id = user&.id || 1 + user_id = user&.id || project.user_id commit_date = Time.parse(commit['commit']['author']['date']) commit_date_str = commit_date.strftime("%a %b %d %H:%M:%S") @@ -60,9 +60,9 @@ namespace :commit_log_to_db do commit_author = "#{commiter['name']} <#{commiter['email']}>" commit_sha = commit['sha'] ref = "master" - commit_message = commit['commit']['message'].to_s.gsub("/n","") + commit_message = commit['commit']['message'].to_s.gsub("/n","").gsub("\"","") user = User.find_by(mail: commiter['email']) - user_id = user&.id || 1 + user_id = user&.id || project.user_id commit_date = Time.parse(commit['commit']['author']['date']) commit_date_str = commit_date.strftime("%Y-%m-%d %H:%M:%S") From 70ee0f82a80d4edd3ccdf44f91a028244cc5fc51 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Apr 2023 15:20:31 +0800 Subject: [PATCH 362/438] token --- lib/tasks/batch_add_issues.rake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tasks/batch_add_issues.rake b/lib/tasks/batch_add_issues.rake index 82beaf01d..763675e59 100644 --- a/lib/tasks/batch_add_issues.rake +++ b/lib/tasks/batch_add_issues.rake @@ -26,7 +26,7 @@ namespace :batch_add_issues do def add_issues_to_project(project,page) # curl -X GET --header 'Content-Type: application/json;charset=UTF-8' 'https://gitee.com/api/v5/repos/mindspore/mindspore/issues?access_token=5ccebd935915fb6cfcae634b161047a2&state=open&sort=created&direction=desc&page=1&per_page=10' - api_url = "https://gitee.com/api/v5/repos/mindspore/mindspore/issues?access_token=5ccebd935915fb6cfcae634b161047a2&state=all&sort=created&direction=desc&page=#{page}&per_page=100" + api_url = "https://gitee.com/api/v5/repos/mindspore/mindspore/issues?access_token=96a637aa055f15056e77e3cf11a67525&state=all&sort=created&direction=desc&page=#{page}&per_page=100" uri = URI.parse(api_url) response = Net::HTTP.get_response(uri) puts "gitee api response.code ===== #{response.code}" @@ -127,4 +127,4 @@ namespace :batch_add_issues do end end end -end \ No newline at end of file +end From fec8db6959c5f1a6392b4ddf5de4371f4c2c1a2d Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Apr 2023 15:23:04 +0800 Subject: [PATCH 363/438] token update --- lib/tasks/batch_add_issues.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/batch_add_issues.rake b/lib/tasks/batch_add_issues.rake index 763675e59..32d3e6ebd 100644 --- a/lib/tasks/batch_add_issues.rake +++ b/lib/tasks/batch_add_issues.rake @@ -89,7 +89,7 @@ namespace :batch_add_issues do end issue_number = issue['number'] - comment_api_url = "https://gitee.com/api/v5/repos/mindspore/mindspore/issues/#{issue_number}/comments?access_token=5ccebd935915fb6cfcae634b161047a2&page=1&per_page=100&order=asc" + comment_api_url = "https://gitee.com/api/v5/repos/mindspore/mindspore/issues/#{issue_number}/comments?access_token=96a637aa055f15056e77e3cf11a67525&page=1&per_page=100&order=asc" comment_uri = URI.parse(comment_api_url) comment_response = Net::HTTP.get_response(comment_uri) comment_lists = JSON.parse(comment_response.body) From 117f9bafb96776a3ac6e51285476bcbf4d2bc5f1 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 17 Apr 2023 15:32:10 +0800 Subject: [PATCH 364/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E8=80=85=E4=BB=A3=E7=A0=81=E8=A1=8Cscore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/project.rb | 1 + app/models/user.rb | 23 +++++++++++++++++++ .../projects/contributors/stat.json.jbuilder | 2 ++ app/views/user_rank/_detail.json.jbuilder | 13 +++++++++++ 4 files changed, 39 insertions(+) diff --git a/app/models/project.rb b/app/models/project.rb index 208d6b7be..ce4a14dab 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -128,6 +128,7 @@ class Project < ApplicationRecord has_many :project_invite_links, dependent: :destroy has_many :project_topic_ralates, dependent: :destroy has_many :project_topics, through: :project_topic_ralates + has_many :commit_logs, dependent: :destroy after_create :incre_user_statistic, :incre_platform_statistic after_save :check_project_members before_save :set_invite_code, :reset_unmember_followed, :set_recommend_and_is_pinned, :reset_cache_data diff --git a/app/models/user.rb b/app/models/user.rb index 268cb01f1..c67858032 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -877,6 +877,29 @@ class User < Owner end end + def self.develop_score(user_id=User.current.id) + user_date_statistic_key = "v2-user-statistic:#{user_id}" + follow_count = $redis_cache.hget(user_date_statistic_key, "follow-count") || 0 + pullrequest_count = $redis_cache.hget(user_date_statistic_key, "pullrequest-count") || 0 + issues_count = $redis_cache.hget(user_date_statistic_key, "issue-count") || 0 + project_count = $redis_cache.hget(user_date_statistic_key, "project-count") || 0 + fork_count = $redis_cache.hget(user_date_statistic_key, "fork-count") || 0 + project_watchers_count = $redis_cache.hget(user_date_statistic_key, "project-watcher-count") || 0 + project_praises_count = $redis_cache.hget(user_date_statistic_key, "project-praise-count") || 0 + project_language = $redis_cache.hget(user_date_statistic_key, "project-language") + project_languages_count = project_language.nil? || project_language == "{}" ? 0 : JSON.parse(project_language).length + + influence = (60.0 + follow_count.to_i / (follow_count.to_i + 20.0) * 40.0).to_i + contribution = (60.0 + pullrequest_count.to_i / (pullrequest_count.to_i + 20.0) * 40.0).to_i + activity = (60.0 + issues_count.to_i / (issues_count.to_i + 80.0) * 40.0).to_i + experience = 10 * project_count.to_i + 5 * fork_count.to_i + project_watchers_count.to_i + project_praises_count.to_i + experience = (60.0 + experience / (experience + 100.0) * 40.0).to_i + language = (60.0 + project_languages_count.to_i / (project_languages_count.to_i + 5.0) * 40.0).to_i + score = influence+ contribution + activity + experience + language + + score + end + protected def validate_password_length diff --git a/app/views/api/v1/projects/contributors/stat.json.jbuilder b/app/views/api/v1/projects/contributors/stat.json.jbuilder index a01ad81a5..44bdbbeae 100644 --- a/app/views/api/v1/projects/contributors/stat.json.jbuilder +++ b/app/views/api/v1/projects/contributors/stat.json.jbuilder @@ -2,6 +2,7 @@ json.total_count @result_object[:total_data].to_i json.contributors @result_object[:data].each do |contributor| user = $redis_cache.hgetall("v2-owner-common:#{contributor["name"]}-#{contributor["email"]}") if user.blank? + json.score 300 json.contributions contributor["commits"] json.additions contributor["additions"] json.deletions contributor["deletions"] @@ -12,6 +13,7 @@ json.contributors @result_object[:data].each do |contributor| json.name contributor["name"] json.image_url User::Avatar.get_letter_avatar_url(contributor["name"]) else + json.score User.develop_score(user["id"]) json.contributions contributor["commits"] json.additions contributor["additions"] json.deletions contributor["deletions"] diff --git a/app/views/user_rank/_detail.json.jbuilder b/app/views/user_rank/_detail.json.jbuilder index e3f8ce5d0..d6c5c23ae 100644 --- a/app/views/user_rank/_detail.json.jbuilder +++ b/app/views/user_rank/_detail.json.jbuilder @@ -7,6 +7,19 @@ json.score item[1] json.name owner_common["name"] json.type owner_common["type"] json.login owner_common["login"] +if owner_common["tmp_projects"].nil? + normal_projects = Project.members_projects(item[0]).to_sql + org_projects = Project.joins(team_projects: [team: :team_users]).where(team_users: {user_id: item[0]}).to_sql + issue_project = Project.joins(:issues).where(issues: {author_id: item[0]}).to_sql + pull_project = Project.joins(:pull_requests).where(pull_requests: {user_id: item[0]}).to_sql + commit_project = Project.joins(:commit_logs).where(commit_logs: {user_id: item[0]}).to_sql + project_count = Project.from("( #{normal_projects} UNION #{org_projects} UNION #{issue_project} UNION #{pull_project} UNION #{issue_project} ) AS projects").distinct.size + + $redis_cache.hset("v2-owner-common:#{item[0]}", 'tmp_projects', project_count) + json.projects_count project_count +else + json.projects_count owner_common["tmp_projects"] +end json.avatar_url owner_common["avatar_url"] if popular_project.blank? json.project nil From 5b14252ecdd271f1e8baa0548198b44456a1a5b3 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 17 Apr 2023 16:56:04 +0800 Subject: [PATCH 365/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E8=80=85=E4=BB=A3=E7=A0=81=E8=A1=8C=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?score=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/user.rb | 6 +++--- app/views/api/v1/projects/contributors/stat.json.jbuilder | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index c67858032..3f74df9f4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -877,10 +877,10 @@ class User < Owner end end - def self.develop_score(user_id=User.current.id) + def self.develop_score(commit_count, user_id=User.current.id) user_date_statistic_key = "v2-user-statistic:#{user_id}" follow_count = $redis_cache.hget(user_date_statistic_key, "follow-count") || 0 - pullrequest_count = $redis_cache.hget(user_date_statistic_key, "pullrequest-count") || 0 + pullrequest_count = $redis_cache.hget(user_date_statistic_key, "pullrequest-count").to_i || 0 issues_count = $redis_cache.hget(user_date_statistic_key, "issue-count") || 0 project_count = $redis_cache.hget(user_date_statistic_key, "project-count") || 0 fork_count = $redis_cache.hget(user_date_statistic_key, "fork-count") || 0 @@ -888,7 +888,7 @@ class User < Owner project_praises_count = $redis_cache.hget(user_date_statistic_key, "project-praise-count") || 0 project_language = $redis_cache.hget(user_date_statistic_key, "project-language") project_languages_count = project_language.nil? || project_language == "{}" ? 0 : JSON.parse(project_language).length - + pullrequest_count += commit_count influence = (60.0 + follow_count.to_i / (follow_count.to_i + 20.0) * 40.0).to_i contribution = (60.0 + pullrequest_count.to_i / (pullrequest_count.to_i + 20.0) * 40.0).to_i activity = (60.0 + issues_count.to_i / (issues_count.to_i + 80.0) * 40.0).to_i diff --git a/app/views/api/v1/projects/contributors/stat.json.jbuilder b/app/views/api/v1/projects/contributors/stat.json.jbuilder index 44bdbbeae..f0e91225a 100644 --- a/app/views/api/v1/projects/contributors/stat.json.jbuilder +++ b/app/views/api/v1/projects/contributors/stat.json.jbuilder @@ -1,8 +1,10 @@ json.total_count @result_object[:total_data].to_i -json.contributors @result_object[:data].each do |contributor| +result_arr = @result_object[:data] +result_arr = result_arr.sort_by!{|c| User.develop_score(c["commits"])}.reverse +json.contributors result_arr.each do |contributor| user = $redis_cache.hgetall("v2-owner-common:#{contributor["name"]}-#{contributor["email"]}") if user.blank? - json.score 300 + json.score User.develop_score(contributor["commits"]) json.contributions contributor["commits"] json.additions contributor["additions"] json.deletions contributor["deletions"] @@ -13,7 +15,7 @@ json.contributors @result_object[:data].each do |contributor| json.name contributor["name"] json.image_url User::Avatar.get_letter_avatar_url(contributor["name"]) else - json.score User.develop_score(user["id"]) + json.score User.develop_score(contributor["commits"]) json.contributions contributor["commits"] json.additions contributor["additions"] json.deletions contributor["deletions"] From bf0af3c9463f5a9a38cae5c5766dd391c3bf14df Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 17 Apr 2023 17:12:48 +0800 Subject: [PATCH 366/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Ascore?= =?UTF-8?q?=E8=AE=B0=E5=88=86=E5=8A=A0=E5=85=A5=E4=BB=A3=E7=A0=81=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/user.rb | 5 +++-- app/views/api/v1/projects/contributors/stat.json.jbuilder | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 3f74df9f4..ba8afffa4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -877,11 +877,11 @@ class User < Owner end end - def self.develop_score(commit_count, user_id=User.current.id) + def self.develop_score(commit_count, code_line, user_id=User.current.id) user_date_statistic_key = "v2-user-statistic:#{user_id}" follow_count = $redis_cache.hget(user_date_statistic_key, "follow-count") || 0 pullrequest_count = $redis_cache.hget(user_date_statistic_key, "pullrequest-count").to_i || 0 - issues_count = $redis_cache.hget(user_date_statistic_key, "issue-count") || 0 + issues_count = $redis_cache.hget(user_date_statistic_key, "issue-count").to_i || 0 project_count = $redis_cache.hget(user_date_statistic_key, "project-count") || 0 fork_count = $redis_cache.hget(user_date_statistic_key, "fork-count") || 0 project_watchers_count = $redis_cache.hget(user_date_statistic_key, "project-watcher-count") || 0 @@ -889,6 +889,7 @@ class User < Owner project_language = $redis_cache.hget(user_date_statistic_key, "project-language") project_languages_count = project_language.nil? || project_language == "{}" ? 0 : JSON.parse(project_language).length pullrequest_count += commit_count + issues_count += code_line influence = (60.0 + follow_count.to_i / (follow_count.to_i + 20.0) * 40.0).to_i contribution = (60.0 + pullrequest_count.to_i / (pullrequest_count.to_i + 20.0) * 40.0).to_i activity = (60.0 + issues_count.to_i / (issues_count.to_i + 80.0) * 40.0).to_i diff --git a/app/views/api/v1/projects/contributors/stat.json.jbuilder b/app/views/api/v1/projects/contributors/stat.json.jbuilder index f0e91225a..456c37bce 100644 --- a/app/views/api/v1/projects/contributors/stat.json.jbuilder +++ b/app/views/api/v1/projects/contributors/stat.json.jbuilder @@ -1,10 +1,10 @@ json.total_count @result_object[:total_data].to_i result_arr = @result_object[:data] -result_arr = result_arr.sort_by!{|c| User.develop_score(c["commits"])}.reverse +result_arr = result_arr.sort_by!{|c| User.develop_score(c["commits"],c["additions"]+c["deletions"])}.reverse json.contributors result_arr.each do |contributor| user = $redis_cache.hgetall("v2-owner-common:#{contributor["name"]}-#{contributor["email"]}") if user.blank? - json.score User.develop_score(contributor["commits"]) + json.score User.develop_score(contributor["commits"],contributor["additions"]+contributor["deletions"] )-300 json.contributions contributor["commits"] json.additions contributor["additions"] json.deletions contributor["deletions"] @@ -15,7 +15,7 @@ json.contributors result_arr.each do |contributor| json.name contributor["name"] json.image_url User::Avatar.get_letter_avatar_url(contributor["name"]) else - json.score User.develop_score(contributor["commits"]) + json.score User.develop_score(contributor["commits"],contributor["additions"]+contributor["deletions"])-300 json.contributions contributor["commits"] json.additions contributor["additions"] json.deletions contributor["deletions"] From e140fb536c12f44cd9389e8e1040efe0bc996fc9 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Apr 2023 18:38:27 +0800 Subject: [PATCH 367/438] =?UTF-8?q?=E6=96=87=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/locales/zh-CN.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/zh-CN.yml b/config/locales/zh-CN.yml index d5c68d448..b9000c1ee 100644 --- a/config/locales/zh-CN.yml +++ b/config/locales/zh-CN.yml @@ -18,7 +18,7 @@ zh-CN: Issue: 疑修(Issue) PullRequest: 合并请求(PR) VersionRelease: 版本发布 - CommitLog: 代码(Commit) + CommitLog: 代码提交(Commit) create: 创建了 journal: 回复了 close: 关闭了 From f078c59cf4e2067695d9f609a30f752415c7f0c5 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 18 Apr 2023 09:44:34 +0800 Subject: [PATCH 368/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=A0=87=E8=AE=B0=E5=B7=B2=E5=AD=98=E5=9C=A8validate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/issue_tag.rb | 2 ++ config/locales/zh-CN.yml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/app/models/issue_tag.rb b/app/models/issue_tag.rb index 0da4ca730..98e0f9072 100644 --- a/app/models/issue_tag.rb +++ b/app/models/issue_tag.rb @@ -28,6 +28,8 @@ class IssueTag < ApplicationRecord belongs_to :project, optional: true, counter_cache: true belongs_to :user, optional: true + validates :name, uniqueness: { message: "已存在" } + def self.init_data(project_id) data = [ ["缺陷", "表示存在意外问题或错误", "#d92d4c"], diff --git a/config/locales/zh-CN.yml b/config/locales/zh-CN.yml index e7c586417..b09b55f45 100644 --- a/config/locales/zh-CN.yml +++ b/config/locales/zh-CN.yml @@ -233,6 +233,8 @@ zh-CN: content: 'git忽略文件内容' feedback_message_history: title: '' + issue_tag: + name: '项目标记' close_pr: 合并请求 roles: Developer: 开发者 From 827e265fc51edef8ef6c08b0d213f09cbb8c5a01 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 18 Apr 2023 09:56:25 +0800 Subject: [PATCH 369/438] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8F=90=E4=BA=A4=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/project_trends/_detail.json.jbuilder | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/project_trends/_detail.json.jbuilder b/app/views/project_trends/_detail.json.jbuilder index f8d1006dd..e7c590b8f 100644 --- a/app/views/project_trends/_detail.json.jbuilder +++ b/app/views/project_trends/_detail.json.jbuilder @@ -19,8 +19,10 @@ if trend.trend_type == "Issue" elsif trend.trend_type == "VersionRelease" json.partial! "version_releases/simple_version_release", locals: {version: trend.trend} elsif trend.trend_type == "CommitLog" + commit_log = trend.trend + json.name commit_log.message + json.created_at format_time(commit_log.created_at) json.commit_log do - commit_log = trend.trend json.user do json.partial! 'users/user_simple', locals: {user: commit_log.user} end From 031f2769835c1e18d00f8a707ea5cb0c8f8e1e09 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 18 Apr 2023 10:08:17 +0800 Subject: [PATCH 370/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E6=A0=A1?= =?UTF-8?q?=E9=AA=8Cscope=E6=96=B0=E5=A2=9Eproject=5Fid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/issue_tag.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/issue_tag.rb b/app/models/issue_tag.rb index 98e0f9072..b4ee673f7 100644 --- a/app/models/issue_tag.rb +++ b/app/models/issue_tag.rb @@ -28,7 +28,7 @@ class IssueTag < ApplicationRecord belongs_to :project, optional: true, counter_cache: true belongs_to :user, optional: true - validates :name, uniqueness: { message: "已存在" } + validates :name, uniqueness: {scope: :project_id, message: "已存在" } def self.init_data(project_id) data = [ From ee0b5e30c47ea84deba067a4ce1b0d0e401625ff Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 18 Apr 2023 14:08:31 +0800 Subject: [PATCH 371/438] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8F=90=E4=BA=A4=E6=97=A5=E5=BF=97,?= =?UTF-8?q?=E5=8E=BB=E6=8E=89=E4=B8=8D=E5=AE=9E=E5=88=AB=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/commit_logs_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/commit_logs_controller.rb b/app/controllers/commit_logs_controller.rb index b034f673c..c3bbf9c16 100644 --- a/app/controllers/commit_logs_controller.rb +++ b/app/controllers/commit_logs_controller.rb @@ -22,7 +22,7 @@ class CommitLogsController < ApplicationController commit_log = CommitLog.create(user: user, project: project, repository_id: repository_id, name: repository_name, full_name: repository_full_name, ref: ref, commit_id: commit_id, message: message) - commit_log.project_trends.create(user_id: user.id, project_id: project&.id, action_type: "create") + commit_log.project_trends.create(user_id: user.id, project_id: project&.id, action_type: "create") if user.id !=2 # 统计数据新增 CacheAsyncSetJob.perform_later("project_common_service", {commits: 1}, project.id) end From 97cdcdd6dee7cc37130a551e8211426f2126b6bc Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 18 Apr 2023 16:41:56 +0800 Subject: [PATCH 372/438] =?UTF-8?q?=E8=AE=A1=E5=9B=BEcommit=E8=A1=A5?= =?UTF-8?q?=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/commit_log_to_db.rake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/tasks/commit_log_to_db.rake b/lib/tasks/commit_log_to_db.rake index ae80f9424..b434583f2 100644 --- a/lib/tasks/commit_log_to_db.rake +++ b/lib/tasks/commit_log_to_db.rake @@ -4,6 +4,9 @@ namespace :commit_log_to_db do puts "project_id=================#{ENV['project_id']}" return if ENV['project_id'].blank? projects = Project.where(id: ENV['project_id']) + if ENV['project_name'] == "jittor" + projects = Project.where(id: [1403791,1404837,1404087,1403854,1403883,1403886,1403894,1404027,1404187,1404234,1404291,1404522,1404238,1404632,1404003,1403975,1404285,1404525,1404017,1403843,1403867,1403874,1403878,1403881,1403887,1403898,1403916,1403937,1403954,1403961,1403963,1403965,1403967,1403972,1403974,1403976,1403977,1403978,1404007,1404012,1404020,1404023,1404032,1404042,1404058,1404065,1404069,1404071,1404072,1404078,1404094,1404104,1404143,1404146,1404167,1404173,1404174,1404175,1404210,1404216,1404226,1404229,1404240,1404242,1404244,1404247,1404248,1404250,1404261,1404272,1404276,1404290,1404327,1404333,1404360,1404450,1404460,1404466,1404485,1404489,1404491,1404496,1404500,1404502,1404507,1404519,1404521,1404523,1404527,1404530,1404532,1404537,1404540,1404541,1404710,1404328,1404211,1404241,1404107,1403880,1404271,1404268,1404745,1404101,1404051,1404047,1404052,1406706,1403852,1403931,1404165,1404607,1404498,1404014,1404045,1404043,1403739,1403801,1403815,1403821,1403822,1403824,1403836,1403853,1403872,1403904,1403906,1403909,1403915,1403919,1403921,1403943,1403945,1403971,1403981,1404022,1404026,1404030,1404037,1404091,1404133,1404163,1404184,1404209,1404212,1404220,1404246,1404249,1404263,1404265,1404287,1404299,1404311,1404497,1404506,1404546,1404558,1404577,1404582,1404591,1404592,1404594,1404595,1404596,1404597,1404605,1404606,1404609,1404639,1404641,1404659,1404671,1404681,1404702,1404748,1404754,1404759,1404785,1404879,1404955,1405169,1405205,1405265,1405374,1407368,1407446,1407671,1407673,1404956,1404079,1404080,1403889,1404665,1404801,1404224,1404931,1404544,1403844,1404036,1404067,1404587,1404696,1404732,1404598,1405192,1404162,1403920,1403903,1405248,1403792,1403817,1403962,1403841,1404188,1404185,1405273,1404575,1404550,1404834,1405420,1404141,1405256,1404633,1405277,1404590,1404796,1405230,1405189,1404584,1405257,1405198,1403925,1404692,1405253,1403809,1405118,1404756,1404962,1404864,1405190,1405258,1405274,1404642,1404924,1404453,1404926,1404649,1404237,1404233,1404600,1404758,1405259,1404157,1404444,1404451,1404920,1404919,1404927,1403830,1404658,1405145,1405185,1403842,1403807,1403895,1404549,1404593,1404750,1404798,1404551,1404701,1405156,1404579,1404655,1405267,1404957,1404556,1404651,1404456,1405430,1403955,1404063,1404214,1403942,1404040,1404804,1428732,1403939,1404208,1404245,1405278,1404139,1403850,1404192,1404293,1404297,1404370,1404492,1404693,1404757,1404329,1404512,1404228,1404314,1404016,1404652,1405275,1404832,1404561,1404653,1404704,1404892,1404589,1404953,1405269,1404881,1404221,1404230,1404793,1403953,1404933,1404035,1404599,1403924,1404119,1404526,1404581,1404705,1404709,1404073,1403808,1403892,1404574,1403849,1404251,1404792,1403865,1404640,1404783,1404048,1406707,1404708,1404053,1404295,1404050,1404049,1404044,1404274,1404046,1404636]) + end projects.each_with_index do |project, index| result = Gitea::Repository::Commits::ListService.call(project.owner.login,project.identifier,sha: "", page: 1, limit: 200, token: project.owner.gitea_token) next if result.blank? || result[:total_count].blank? @@ -24,6 +27,7 @@ namespace :commit_log_to_db do # "luoyuan " commit_author = "#{commiter['name']} <#{commiter['email']}>" commit_sha = commit['sha'] + next if CommitLog.find_by(commit_id: commit_sha).present? ref = "master" commit_message = commit['commit']['message'].to_s.gsub("\"","") user = User.find_by(mail: commiter['email']) From 3a2395d58a636b280b3f9894d6f9e2764ea3bb5b Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 18 Apr 2023 16:42:17 +0800 Subject: [PATCH 373/438] =?UTF-8?q?=E8=AE=A1=E5=9B=BEcommit=E8=A1=A5?= =?UTF-8?q?=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/commit_log_to_db.rake | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/tasks/commit_log_to_db.rake b/lib/tasks/commit_log_to_db.rake index b434583f2..359a844fc 100644 --- a/lib/tasks/commit_log_to_db.rake +++ b/lib/tasks/commit_log_to_db.rake @@ -63,6 +63,7 @@ namespace :commit_log_to_db do # "luoyuan " commit_author = "#{commiter['name']} <#{commiter['email']}>" commit_sha = commit['sha'] + next if CommitLog.find_by(commit_id: commit_sha).present? ref = "master" commit_message = commit['commit']['message'].to_s.gsub("/n","").gsub("\"","") user = User.find_by(mail: commiter['email']) From 17385de87073bf6518d6d3376090a14492ebc993 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 18 Apr 2023 16:52:40 +0800 Subject: [PATCH 374/438] =?UTF-8?q?=E8=AE=A1=E5=9B=BEcommit=E8=A1=A5?= =?UTF-8?q?=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/commit_log_to_db.rake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tasks/commit_log_to_db.rake b/lib/tasks/commit_log_to_db.rake index 359a844fc..2f29bee8f 100644 --- a/lib/tasks/commit_log_to_db.rake +++ b/lib/tasks/commit_log_to_db.rake @@ -29,7 +29,7 @@ namespace :commit_log_to_db do commit_sha = commit['sha'] next if CommitLog.find_by(commit_id: commit_sha).present? ref = "master" - commit_message = commit['commit']['message'].to_s.gsub("\"","") + commit_message = commit['commit']['message'].to_s.size > 2000 ? "Message Data too long" : commit['commit']['message'].to_s.gsub("/n","").gsub("\"","") user = User.find_by(mail: commiter['email']) user_id = user&.id || project.user_id commit_date = Time.parse(commit['commit']['author']['date']) @@ -65,7 +65,7 @@ namespace :commit_log_to_db do commit_sha = commit['sha'] next if CommitLog.find_by(commit_id: commit_sha).present? ref = "master" - commit_message = commit['commit']['message'].to_s.gsub("/n","").gsub("\"","") + commit_message = commit['commit']['message'].to_s.size > 2000 ? "Message Data too long" : commit['commit']['message'].to_s.gsub("/n","").gsub("\"","") user = User.find_by(mail: commiter['email']) user_id = user&.id || project.user_id commit_date = Time.parse(commit['commit']['author']['date']) From 03a53f56fd5904f6e64f140f5f65ea01b4db9ae8 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 18 Apr 2023 16:56:12 +0800 Subject: [PATCH 375/438] =?UTF-8?q?=E8=AE=A1=E5=9B=BEcommit=E8=A1=A5?= =?UTF-8?q?=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/commit_log_to_db.rake | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/tasks/commit_log_to_db.rake b/lib/tasks/commit_log_to_db.rake index 2f29bee8f..cfde9bd05 100644 --- a/lib/tasks/commit_log_to_db.rake +++ b/lib/tasks/commit_log_to_db.rake @@ -38,10 +38,12 @@ namespace :commit_log_to_db do data += "(#{user_id},#{project.id},#{project.repository&.id},'#{project.identifier}','#{project.owner.name}/#{project.identifier}','#{commit_sha}','#{ref}',\"#{commit_message}\",'#{commit_date_str}','#{commit_date_str}')," end data = data[0,data.length-1] - sql_connection = ActiveRecord::Base.connection - sql_connection.begin_db_transaction - sql = "INSERT INTO commit_logs (`user_id`, `project_id`, `repository_id`, `name`, `full_name`, `commit_id`, `ref`, `message`, `created_at`, `updated_at`) VALUES #{data}" - sql_connection.execute(sql) + if data.present? + sql_connection = ActiveRecord::Base.connection + sql_connection.begin_db_transaction + sql = "INSERT INTO commit_logs (`user_id`, `project_id`, `repository_id`, `name`, `full_name`, `commit_id`, `ref`, `message`, `created_at`, `updated_at`) VALUES #{data}" + sql_connection.execute(sql) + end end end @@ -74,10 +76,12 @@ namespace :commit_log_to_db do data += "(#{user_id},#{project.id},#{project.repository&.id},'#{project.identifier}','#{project.owner.name}/#{project.identifier}','#{commit_sha}','#{ref}',\"#{commit_message}\",'#{commit_date_str}','#{commit_date_str}')," end data = data[0,data.length-1] - sql_connection = ActiveRecord::Base.connection - sql_connection.begin_db_transaction - sql = "INSERT INTO commit_logs (`user_id`, `project_id`, `repository_id`, `name`, `full_name`, `commit_id`, `ref`, `message`, `created_at`, `updated_at`) VALUES #{data}" - sql_connection.execute(sql) + if data.present? + sql_connection = ActiveRecord::Base.connection + sql_connection.begin_db_transaction + sql = "INSERT INTO commit_logs (`user_id`, `project_id`, `repository_id`, `name`, `full_name`, `commit_id`, `ref`, `message`, `created_at`, `updated_at`) VALUES #{data}" + sql_connection.execute(sql) + end end end \ No newline at end of file From 3d24ed3780dffd0f4aac7a77db2faa62bc68b766 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 18 Apr 2023 17:02:37 +0800 Subject: [PATCH 376/438] =?UTF-8?q?=E8=AE=A1=E5=9B=BEcommit=E8=A1=A5?= =?UTF-8?q?=E5=85=85,message=E9=95=BF=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/commit_log_to_db.rake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tasks/commit_log_to_db.rake b/lib/tasks/commit_log_to_db.rake index cfde9bd05..cc6cdcd23 100644 --- a/lib/tasks/commit_log_to_db.rake +++ b/lib/tasks/commit_log_to_db.rake @@ -29,7 +29,7 @@ namespace :commit_log_to_db do commit_sha = commit['sha'] next if CommitLog.find_by(commit_id: commit_sha).present? ref = "master" - commit_message = commit['commit']['message'].to_s.size > 2000 ? "Message Data too long" : commit['commit']['message'].to_s.gsub("/n","").gsub("\"","") + commit_message = commit['commit']['message'].to_s.size > 1000 ? "Message Data too long" : commit['commit']['message'].to_s.gsub("/n","").gsub("\"","") user = User.find_by(mail: commiter['email']) user_id = user&.id || project.user_id commit_date = Time.parse(commit['commit']['author']['date']) @@ -67,7 +67,7 @@ namespace :commit_log_to_db do commit_sha = commit['sha'] next if CommitLog.find_by(commit_id: commit_sha).present? ref = "master" - commit_message = commit['commit']['message'].to_s.size > 2000 ? "Message Data too long" : commit['commit']['message'].to_s.gsub("/n","").gsub("\"","") + commit_message = commit['commit']['message'].to_s.size > 1000 ? "Message Data too long" : commit['commit']['message'].to_s.gsub("/n","").gsub("\"","") user = User.find_by(mail: commiter['email']) user_id = user&.id || project.user_id commit_date = Time.parse(commit['commit']['author']['date']) From 6608c799f07db922cadfbe1f92a0d17b02291ef1 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 18 Apr 2023 21:36:26 +0800 Subject: [PATCH 377/438] =?UTF-8?q?=E8=AE=A1=E5=9B=BEcommit=E8=A1=A5?= =?UTF-8?q?=E5=85=85,message=E9=95=BF=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/commit_log_to_db.rake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tasks/commit_log_to_db.rake b/lib/tasks/commit_log_to_db.rake index cc6cdcd23..6365c485f 100644 --- a/lib/tasks/commit_log_to_db.rake +++ b/lib/tasks/commit_log_to_db.rake @@ -29,7 +29,7 @@ namespace :commit_log_to_db do commit_sha = commit['sha'] next if CommitLog.find_by(commit_id: commit_sha).present? ref = "master" - commit_message = commit['commit']['message'].to_s.size > 1000 ? "Message Data too long" : commit['commit']['message'].to_s.gsub("/n","").gsub("\"","") + commit_message = commit['commit']['message'].to_s.size > 200 ? "Message Data too long" : commit['commit']['message'].to_s.gsub("/n","").gsub("\"","") user = User.find_by(mail: commiter['email']) user_id = user&.id || project.user_id commit_date = Time.parse(commit['commit']['author']['date']) @@ -67,7 +67,7 @@ namespace :commit_log_to_db do commit_sha = commit['sha'] next if CommitLog.find_by(commit_id: commit_sha).present? ref = "master" - commit_message = commit['commit']['message'].to_s.size > 1000 ? "Message Data too long" : commit['commit']['message'].to_s.gsub("/n","").gsub("\"","") + commit_message = commit['commit']['message'].to_s.size > 200 ? "Message Data too long" : commit['commit']['message'].to_s.gsub("/n","").gsub("\"","") user = User.find_by(mail: commiter['email']) user_id = user&.id || project.user_id commit_date = Time.parse(commit['commit']['author']['date']) From 11d22d5d5a0556b639fc22af0dd990491cc25c48 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 18 Apr 2023 21:41:55 +0800 Subject: [PATCH 378/438] =?UTF-8?q?=E8=AE=A1=E5=9B=BEcommit=E8=A1=A5?= =?UTF-8?q?=E5=85=85commit=5Fdb=5Ftransaction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/commit_log_to_db.rake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/tasks/commit_log_to_db.rake b/lib/tasks/commit_log_to_db.rake index 6365c485f..b5505beda 100644 --- a/lib/tasks/commit_log_to_db.rake +++ b/lib/tasks/commit_log_to_db.rake @@ -43,6 +43,7 @@ namespace :commit_log_to_db do sql_connection.begin_db_transaction sql = "INSERT INTO commit_logs (`user_id`, `project_id`, `repository_id`, `name`, `full_name`, `commit_id`, `ref`, `message`, `created_at`, `updated_at`) VALUES #{data}" sql_connection.execute(sql) + sql_connection.commit_db_transaction end end end @@ -81,6 +82,7 @@ namespace :commit_log_to_db do sql_connection.begin_db_transaction sql = "INSERT INTO commit_logs (`user_id`, `project_id`, `repository_id`, `name`, `full_name`, `commit_id`, `ref`, `message`, `created_at`, `updated_at`) VALUES #{data}" sql_connection.execute(sql) + sql_connection.commit_db_transaction end end From 6cc03b1ab4cb9e3550d9a193c845d9378043db2a Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 18 Apr 2023 22:00:01 +0800 Subject: [PATCH 379/438] =?UTF-8?q?=E8=AE=A1=E5=9B=BEcommit=E8=A1=A5?= =?UTF-8?q?=E5=85=85=E6=97=A5=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/commit_log_to_db.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/commit_log_to_db.rake b/lib/tasks/commit_log_to_db.rake index b5505beda..fdb7ac1a3 100644 --- a/lib/tasks/commit_log_to_db.rake +++ b/lib/tasks/commit_log_to_db.rake @@ -33,7 +33,7 @@ namespace :commit_log_to_db do user = User.find_by(mail: commiter['email']) user_id = user&.id || project.user_id commit_date = Time.parse(commit['commit']['author']['date']) - commit_date_str = commit_date.strftime("%a %b %d %H:%M:%S") + commit_date_str = commit_date.strftime("%Y-%m-%d %H:%M:%S") data += "(#{user_id},#{project.id},#{project.repository&.id},'#{project.identifier}','#{project.owner.name}/#{project.identifier}','#{commit_sha}','#{ref}',\"#{commit_message}\",'#{commit_date_str}','#{commit_date_str}')," end From 82ba843d7dd939954ce35074ee3d2617826b5300 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 19 Apr 2023 10:15:07 +0800 Subject: [PATCH 380/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=8F=91?= =?UTF-8?q?=E9=80=81=E9=82=AE=E4=BB=B6=E5=8F=8A=E7=9F=AD=E4=BF=A1=E6=AC=A1?= =?UTF-8?q?=E6=95=B0=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/accounts_controller.rb | 2 + app/controllers/api/v1/users_controller.rb | 15 +++-- app/controllers/application_controller.rb | 14 ++-- app/services/info_risk_control_service.rb | 77 ++++++++++++++++++++++ 4 files changed, 95 insertions(+), 13 deletions(-) create mode 100644 app/services/info_risk_control_service.rb diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 2046dfa20..0b713bdb3 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -324,6 +324,8 @@ class AccountsController < ApplicationController send_type = verify_type(login_type, type) verification_code = code.sample(6).join + status, message = InfoRiskControlService.call(value, request.remote_ip) + tip_exception(420, message) if status == 0 sign = Digest::MD5.hexdigest("#{OPENKEY}#{value}") tip_exception(501, "请求不合理") if sign != params[:smscode] diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index 3a750b519..f5ea37a90 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -9,21 +9,24 @@ class Api::V1::UsersController < Api::V1::BaseController mail = params[:email] code_type = params[:code_type] + status, message = InfoRiskControlService.call(0, request.remote_ip) + tip_exception(420, message) if status == 0 + sign = Digest::MD5.hexdigest("#{OPENKEY}#{mail}") Rails.logger.info sign tip_exception(501, "请求不合理") if sign != params[:smscode] # 60s内不能重复发送 - send_email_limit_cache_key = "send_email_60_second_limit:#{mail}" - tip_exception(-2, '请勿频繁操作') if Rails.cache.exist?(send_email_limit_cache_key) - send_email_control = LimitForbidControl::SendEmailCode.new(mail) - tip_exception(-2, '邮件发送太频繁,请稍后再试') if send_email_control.forbid? + # send_email_limit_cache_key = "send_email_60_second_limit:#{mail}" + # tip_exception(-2, '请勿频繁操作') if Rails.cache.exist?(send_email_limit_cache_key) + # send_email_control = LimitForbidControl::SendEmailCode.new(mail) + # tip_exception(-2, '邮件发送太频繁,请稍后再试') if send_email_control.forbid? begin UserMailer.update_email(mail, verification_code).deliver_now - Rails.cache.write(send_email_limit_cache_key, 1, expires_in: 1.minute) - send_email_control.increment! + # Rails.cache.write(send_email_limit_cache_key, 1, expires_in: 1.minute) + # send_email_control.increment! rescue Exception => e logger_error(e) tip_exception(-2,"邮件发送失败,请稍后重试") diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 517e1b2df..61541d09b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -112,12 +112,12 @@ class ApplicationController < ActionController::Base # 邮箱类型的发送 sigle_para = {email: value} # 60s内不能重复发送 - send_email_limit_cache_key = "send_email_60_second_limit:#{value}" - tip_exception(-1, '请勿频繁操作') if Rails.cache.exist?(send_email_limit_cache_key) + # send_email_limit_cache_key = "send_email_60_second_limit:#{value}" + # tip_exception(-1, '请勿频繁操作') if Rails.cache.exist?(send_email_limit_cache_key) - # 短时间内不能大量发送 - send_email_control = LimitForbidControl::SendEmailCode.new(value) - tip_exception(-1, '邮件发送太频繁,请稍后再试') if send_email_control.forbid? + # # 短时间内不能大量发送 + # send_email_control = LimitForbidControl::SendEmailCode.new(value) + # tip_exception(-1, '邮件发送太频繁,请稍后再试') if send_email_control.forbid? begin if send_type == 3 UserMailer.find_password(value, code).deliver_now @@ -126,8 +126,8 @@ class ApplicationController < ActionController::Base else UserMailer.register_email(value, code).deliver_now end - Rails.cache.write(send_email_limit_cache_key, 1, expires_in: 1.minute) - send_email_control.increment! + # Rails.cache.write(send_email_limit_cache_key, 1, expires_in: 1.minute) + # send_email_control.increment! # Mailer.run.email_register(code, value) rescue Exception => e logger_error(e) diff --git a/app/services/info_risk_control_service.rb b/app/services/info_risk_control_service.rb new file mode 100644 index 000000000..f07b30c48 --- /dev/null +++ b/app/services/info_risk_control_service.rb @@ -0,0 +1,77 @@ +class InfoRiskControlService < ApplicationService + + attr_reader :receiver, :remote_ip + attr_accessor :status, :message + + + def initialize(receiver="", remote_ip="0.0.0.0") + @receiver = receiver + @remote_ip = remote_ip + @status = 1 + @message = "" + end + + def call + if receiver == "" + remote_ip_minute_risk_control + remote_ip_risk_control if @status = 1 + else + remote_ip_minute_risk_control + remote_ip_risk_control if @status = 1 + minute_risk_control + day_risk_control if @status = 1 + end + + return @status, @message + end + + private + def remote_ip_minute_risk_control + result = Rails.cache.read("InfoRiskControlService-RemoteIp-Minute-#{remote_ip}") + if result.present? + @status = 0 + @message = "您的请求过于频繁,请稍后再试" + else + Rails.cache.write("InfoRiskControlService-RemoteIp-Minute-#{remote_ip}", 1, expires_in: 1.minute) + end + end + + def remote_ip_risk_control + result = Rails.cache.read("InfoRiskControlService-RemoteIp-#{remote_ip}") + if result.present? + if result.to_i > 20 + @status = 0 + @message = "暂时无法请求,请稍后再试" + else + Rails.cache.write("InfoRiskControlService-RemoteIp-#{remote_ip}", result.to_i + 1) + end + else + Rails.cache.write("InfoRiskControlService-RemoteIp-#{remote_ip}", 1, expires_in: 1.day) + end + end + + def minute_risk_control + result = Rails.cache.read("InfoRiskControlService-Minute-#{receiver}") + if result.present? + @status = 0 + @message = "您的请求过于频繁,请稍后再试" + else + Rails.cache.write("InfoRiskControlService-Minute-#{receiver}", 1, expires_in: 1.minute) + end + end + + def day_risk_control + result = Rails.cache.read("InfoRiskControlService-Day-#{receiver}") + if result.present? + if result.to_i > 10 + @status = 0 + @message = "您的请求过于频繁,请稍后再试" + else + Rails.cache.write("InfoRiskControlService-Day-#{receiver}", result.to_i + 1) + end + else + Rails.cache.write("InfoRiskControlService-Day-#{receiver}", 1, expires_in: 1.days) + end + end + +end \ No newline at end of file From 71862ba6d6fe964a11b0da3de8270a7514b0942f Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 19 Apr 2023 10:26:07 +0800 Subject: [PATCH 381/438] =?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/users_controller.rb | 2 +- app/services/info_risk_control_service.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index f5ea37a90..a37db2524 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -9,7 +9,7 @@ class Api::V1::UsersController < Api::V1::BaseController mail = params[:email] code_type = params[:code_type] - status, message = InfoRiskControlService.call(0, request.remote_ip) + status, message = InfoRiskControlService.call(mail, request.remote_ip) tip_exception(420, message) if status == 0 sign = Digest::MD5.hexdigest("#{OPENKEY}#{mail}") diff --git a/app/services/info_risk_control_service.rb b/app/services/info_risk_control_service.rb index f07b30c48..f8bd993b5 100644 --- a/app/services/info_risk_control_service.rb +++ b/app/services/info_risk_control_service.rb @@ -14,12 +14,12 @@ class InfoRiskControlService < ApplicationService def call if receiver == "" remote_ip_minute_risk_control - remote_ip_risk_control if @status = 1 + remote_ip_risk_control if @status == 1 else remote_ip_minute_risk_control - remote_ip_risk_control if @status = 1 - minute_risk_control - day_risk_control if @status = 1 + remote_ip_risk_control if @status == 1 + minute_risk_control + day_risk_control if @status == 1 end return @status, @message From a13fc2a96f3196a5a0df8075e33528c69961811e Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 19 Apr 2023 15:18:12 +0800 Subject: [PATCH 382/438] =?UTF-8?q?mindspore=20=E5=AD=90=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=95=B0=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/commit_log_to_db.rake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/tasks/commit_log_to_db.rake b/lib/tasks/commit_log_to_db.rake index fdb7ac1a3..87d7649e9 100644 --- a/lib/tasks/commit_log_to_db.rake +++ b/lib/tasks/commit_log_to_db.rake @@ -7,6 +7,9 @@ namespace :commit_log_to_db do if ENV['project_name'] == "jittor" projects = Project.where(id: [1403791,1404837,1404087,1403854,1403883,1403886,1403894,1404027,1404187,1404234,1404291,1404522,1404238,1404632,1404003,1403975,1404285,1404525,1404017,1403843,1403867,1403874,1403878,1403881,1403887,1403898,1403916,1403937,1403954,1403961,1403963,1403965,1403967,1403972,1403974,1403976,1403977,1403978,1404007,1404012,1404020,1404023,1404032,1404042,1404058,1404065,1404069,1404071,1404072,1404078,1404094,1404104,1404143,1404146,1404167,1404173,1404174,1404175,1404210,1404216,1404226,1404229,1404240,1404242,1404244,1404247,1404248,1404250,1404261,1404272,1404276,1404290,1404327,1404333,1404360,1404450,1404460,1404466,1404485,1404489,1404491,1404496,1404500,1404502,1404507,1404519,1404521,1404523,1404527,1404530,1404532,1404537,1404540,1404541,1404710,1404328,1404211,1404241,1404107,1403880,1404271,1404268,1404745,1404101,1404051,1404047,1404052,1406706,1403852,1403931,1404165,1404607,1404498,1404014,1404045,1404043,1403739,1403801,1403815,1403821,1403822,1403824,1403836,1403853,1403872,1403904,1403906,1403909,1403915,1403919,1403921,1403943,1403945,1403971,1403981,1404022,1404026,1404030,1404037,1404091,1404133,1404163,1404184,1404209,1404212,1404220,1404246,1404249,1404263,1404265,1404287,1404299,1404311,1404497,1404506,1404546,1404558,1404577,1404582,1404591,1404592,1404594,1404595,1404596,1404597,1404605,1404606,1404609,1404639,1404641,1404659,1404671,1404681,1404702,1404748,1404754,1404759,1404785,1404879,1404955,1405169,1405205,1405265,1405374,1407368,1407446,1407671,1407673,1404956,1404079,1404080,1403889,1404665,1404801,1404224,1404931,1404544,1403844,1404036,1404067,1404587,1404696,1404732,1404598,1405192,1404162,1403920,1403903,1405248,1403792,1403817,1403962,1403841,1404188,1404185,1405273,1404575,1404550,1404834,1405420,1404141,1405256,1404633,1405277,1404590,1404796,1405230,1405189,1404584,1405257,1405198,1403925,1404692,1405253,1403809,1405118,1404756,1404962,1404864,1405190,1405258,1405274,1404642,1404924,1404453,1404926,1404649,1404237,1404233,1404600,1404758,1405259,1404157,1404444,1404451,1404920,1404919,1404927,1403830,1404658,1405145,1405185,1403842,1403807,1403895,1404549,1404593,1404750,1404798,1404551,1404701,1405156,1404579,1404655,1405267,1404957,1404556,1404651,1404456,1405430,1403955,1404063,1404214,1403942,1404040,1404804,1428732,1403939,1404208,1404245,1405278,1404139,1403850,1404192,1404293,1404297,1404370,1404492,1404693,1404757,1404329,1404512,1404228,1404314,1404016,1404652,1405275,1404832,1404561,1404653,1404704,1404892,1404589,1404953,1405269,1404881,1404221,1404230,1404793,1403953,1404933,1404035,1404599,1403924,1404119,1404526,1404581,1404705,1404709,1404073,1403808,1403892,1404574,1403849,1404251,1404792,1403865,1404640,1404783,1404048,1406707,1404708,1404053,1404295,1404050,1404049,1404044,1404274,1404046,1404636]) end + if ENV['project_name'] == "mindspore" + projects = Project.where(identifier: ['MindSpore-first-experience', ' MindSpore-install', 'MindSpore-Application-practice', 'MindSpore-Model-Development', 'MindSpore-Data-preprocessing', 'Mindspore-Data-storage-use', 'MindSpore-Data-storage-kunpeng', 'MindSpore-LeNet-jzx3', 'MindSpore-competition'] ) + end projects.each_with_index do |project, index| result = Gitea::Repository::Commits::ListService.call(project.owner.login,project.identifier,sha: "", page: 1, limit: 200, token: project.owner.gitea_token) next if result.blank? || result[:total_count].blank? From 48207de001282dc4ae639bc3b84f24c15c58397f Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 19 Apr 2023 15:52:33 +0800 Subject: [PATCH 383/438] =?UTF-8?q?mindspore=20=E6=9C=80=E8=BF=91=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=E6=95=B0=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_add_commits.rake | 60 ++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 lib/tasks/batch_add_commits.rake diff --git a/lib/tasks/batch_add_commits.rake b/lib/tasks/batch_add_commits.rake new file mode 100644 index 000000000..2f8790ffe --- /dev/null +++ b/lib/tasks/batch_add_commits.rake @@ -0,0 +1,60 @@ +namespace :batch_add_issues do + desc "batch_add_issues" + task gitee: :environment do + project_id = ENV['project_id'] + puts "project_id=================#{project_id}" + next if project_id.blank? + project = Project.find project_id + count = 0 + if ENV['count'].present? + count = ENV['count'].to_i + end + + total_count = 3000 + puts "total_count==========#{total_count}" + if total_count > 100 + total_page = (total_count / 100) + 1 + total_page.times do |i| + add_commits_to_project(project, i + 1 + count) + end + else + add_commits_to_project(project, 1) + end + + + end + + def add_commits_to_project(project,page) + # curl -X GET --header 'Content-Type: application/json;charset=UTF-8' 'https://gitee.com/api/v5/repos/mindspore/mindspore/issues?access_token=5ccebd935915fb6cfcae634b161047a2&state=open&sort=created&direction=desc&page=1&per_page=10' + api_url = "https://gitee.com/api/v5/repos/mindspore/mindspore/commits?access_token=96a637aa055f15056e77e3cf11a67525&state=all&sort=created&direction=desc&page=#{page}&per_page=100" + uri = URI.parse(api_url) + response = Net::HTTP.get_response(uri) + puts "gitee api response.code ===== #{response.code}" + lists = JSON.parse(response.body) + puts "lists.size =====#{lists.size}" + + data = "" + lists.each do |commit| + # puts "commit==========#{commit}" + commiter = commit['commit']['author'] + commit_sha = commit['sha'] + next if CommitLog.find_by(commit_id: commit_sha).present? + ref = "master" + commit_message = commit['commit']['message'].to_s.size > 200 ? "Message Data too long" : commit['commit']['message'].to_s.gsub("/n","").gsub("\"","") + user = User.find_by(mail: commiter['email']) + user_id = user&.id || project.user_id + commit_date = Time.parse(commit['commit']['author']['date']) + commit_date_str = commit_date.strftime("%Y-%m-%d %H:%M:%S") + + data += "(#{user_id},#{project.id},#{project.repository&.id},'#{project.identifier}','#{project.owner.name}/#{project.identifier}','#{commit_sha}','#{ref}',\"#{commit_message}\",'#{commit_date_str}','#{commit_date_str}')," + end + data = data[0,data.length-1] + if data.present? + sql_connection = ActiveRecord::Base.connection + sql_connection.begin_db_transaction + sql = "INSERT INTO commit_logs (`user_id`, `project_id`, `repository_id`, `name`, `full_name`, `commit_id`, `ref`, `message`, `created_at`, `updated_at`) VALUES #{data}" + sql_connection.execute(sql) + sql_connection.commit_db_transaction + end + end +end From 8bcc6517ce92f15e50e016485ea7bcfd311b3d90 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 19 Apr 2023 15:54:04 +0800 Subject: [PATCH 384/438] =?UTF-8?q?mindspore=20=E6=9C=80=E8=BF=91=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=E6=95=B0=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_add_commits.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/batch_add_commits.rake b/lib/tasks/batch_add_commits.rake index 2f8790ffe..96efc221b 100644 --- a/lib/tasks/batch_add_commits.rake +++ b/lib/tasks/batch_add_commits.rake @@ -1,4 +1,4 @@ -namespace :batch_add_issues do +namespace :batch_add_commits do desc "batch_add_issues" task gitee: :environment do project_id = ENV['project_id'] From 1508013abb8950b0c1ac178dfef0b9c58c416a1c Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 19 Apr 2023 16:20:59 +0800 Subject: [PATCH 385/438] =?UTF-8?q?mindspore=20=E6=9C=80=E8=BF=91=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=E6=95=B0=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_add_commits.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/batch_add_commits.rake b/lib/tasks/batch_add_commits.rake index 96efc221b..00abae370 100644 --- a/lib/tasks/batch_add_commits.rake +++ b/lib/tasks/batch_add_commits.rake @@ -10,7 +10,7 @@ namespace :batch_add_commits do count = ENV['count'].to_i end - total_count = 3000 + total_count = 65669 puts "total_count==========#{total_count}" if total_count > 100 total_page = (total_count / 100) + 1 From 0dffec890206165026ed79264f1c54fe59029d9c Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 19 Apr 2023 16:38:42 +0800 Subject: [PATCH 386/438] =?UTF-8?q?mindspore=20=E6=9C=80=E8=BF=91=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=E6=95=B0=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_add_commits.rake | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/tasks/batch_add_commits.rake b/lib/tasks/batch_add_commits.rake index 00abae370..e2a72e61a 100644 --- a/lib/tasks/batch_add_commits.rake +++ b/lib/tasks/batch_add_commits.rake @@ -25,6 +25,7 @@ namespace :batch_add_commits do end def add_commits_to_project(project,page) + puts "page==========#{page}" # curl -X GET --header 'Content-Type: application/json;charset=UTF-8' 'https://gitee.com/api/v5/repos/mindspore/mindspore/issues?access_token=5ccebd935915fb6cfcae634b161047a2&state=open&sort=created&direction=desc&page=1&per_page=10' api_url = "https://gitee.com/api/v5/repos/mindspore/mindspore/commits?access_token=96a637aa055f15056e77e3cf11a67525&state=all&sort=created&direction=desc&page=#{page}&per_page=100" uri = URI.parse(api_url) From a38ebeaca2c8c7348e4566bd05fa34c4a72ecc54 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 19 Apr 2023 16:45:10 +0800 Subject: [PATCH 387/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E7=94=A8=E6=88=B7id=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/users_controller.rb | 6 ++++++ config/routes/api.rb | 1 + 2 files changed, 7 insertions(+) diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index a37db2524..807efd5f3 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -42,6 +42,12 @@ class Api::V1::UsersController < Api::V1::BaseController end end + def check_user_id + id = params[:user_id] + return tip_exception(-1, "用户ID不存在") unless User.exists?(id: id) + render_ok + end + def check_password password = params[:password] return tip_exception(-5, "8~16位密码,支持字母数字和符号") unless password =~ CustomRegexp::PASSWORD diff --git a/config/routes/api.rb b/config/routes/api.rb index 62d49caf2..92b5868f5 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -5,6 +5,7 @@ defaults format: :json do resource :users, path: '/', only: [:update, :edit, :destroy] do collection do get :send_email_vefify_code + post :check_user_id post :check_password post :check_email post :check_email_verify_code From 421a64e8ca3e16c0f993eada70baf281b09370bd Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 19 Apr 2023 16:56:09 +0800 Subject: [PATCH 388/438] =?UTF-8?q?=E7=A7=BB=E9=99=A4=EF=BC=9Aproject=5Fto?= =?UTF-8?q?pics=E6=8E=A5=E5=8F=A3=E7=9A=84includes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/project_topics_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/v1/project_topics_controller.rb b/app/controllers/api/v1/project_topics_controller.rb index 5d353fbf4..46ae4cee0 100644 --- a/app/controllers/api/v1/project_topics_controller.rb +++ b/app/controllers/api/v1/project_topics_controller.rb @@ -3,7 +3,7 @@ class Api::V1::ProjectTopicsController < Api::V1::BaseController def index @project_topics = ProjectTopic @project_topics = @project_topics.ransack(name_cont: params[:keyword]) if params[:keyword].present? - @project_topics = @project_topics.includes(:projects) + # @project_topics = @project_topics.includes(:projects) @project_topics = kaminary_select_paginate(@project_topics) end From a578b7277a48f1b56f16711c42531e0922412533 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 19 Apr 2023 17:32:27 +0800 Subject: [PATCH 389/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E7=94=A8=E6=88=B7id=E4=B8=8D=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/users_controller.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index 807efd5f3..f63400b03 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -1,5 +1,11 @@ class Api::V1::UsersController < Api::V1::BaseController + def check_user_id + id = params[:user_id] + return tip_exception(-1, "用户ID不存在") unless User.exists?(id: id) + render_ok + end + before_action :load_observe_user before_action :check_auth_for_observe_user @@ -42,12 +48,6 @@ class Api::V1::UsersController < Api::V1::BaseController end end - def check_user_id - id = params[:user_id] - return tip_exception(-1, "用户ID不存在") unless User.exists?(id: id) - render_ok - end - def check_password password = params[:password] return tip_exception(-5, "8~16位密码,支持字母数字和符号") unless password =~ CustomRegexp::PASSWORD From e815b0a8accbb2f04557b335d27a01640498a60d Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 19 Apr 2023 18:11:11 +0800 Subject: [PATCH 390/438] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E7=94=A8=E6=88=B7id=E7=9A=84=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/users_controller.rb | 9 ++++----- config/routes/api.rb | 8 +++++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index f63400b03..3f7b49f99 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -1,14 +1,13 @@ class Api::V1::UsersController < Api::V1::BaseController + before_action :load_observe_user, except: [:check_user_id] + before_action :check_auth_for_observe_user, except: [:check_user_id] + def check_user_id - id = params[:user_id] - return tip_exception(-1, "用户ID不存在") unless User.exists?(id: id) + return tip_exception(-1, "用户ID不存在") unless params[:user_id].present? && User.exists?(id: params[:user_id]) render_ok end - before_action :load_observe_user - before_action :check_auth_for_observe_user - def send_email_vefify_code code = %W(0 1 2 3 4 5 6 7 8 9) verification_code = code.sample(6).join diff --git a/config/routes/api.rb b/config/routes/api.rb index 92b5868f5..77ff5d03b 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -1,11 +1,17 @@ defaults format: :json do namespace :api do namespace :v1 do + + resources :users, only: [:index] do + collection do + post :check_user_id + end + end + scope ':owner' do resource :users, path: '/', only: [:update, :edit, :destroy] do collection do get :send_email_vefify_code - post :check_user_id post :check_password post :check_email post :check_email_verify_code From 9fdf6226a5198214320bc3d53825f87d3529bddb Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 19 Apr 2023 20:09:50 +0800 Subject: [PATCH 391/438] =?UTF-8?q?commit=E6=8F=90=E5=8F=96=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E8=80=85=E5=88=9B=E5=BB=BA=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_add_contributors.rake | 115 ++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 lib/tasks/batch_add_contributors.rake diff --git a/lib/tasks/batch_add_contributors.rake b/lib/tasks/batch_add_contributors.rake new file mode 100644 index 000000000..4da743434 --- /dev/null +++ b/lib/tasks/batch_add_contributors.rake @@ -0,0 +1,115 @@ +namespace :batch_add_contributors do + desc "commit_log_to_db" + task done: :environment do + puts "project_id=================#{ENV['project_id']}" + return if ENV['project_id'].blank? + projects = Project.where(id: ENV['project_id']) + if ENV['project_name'] == "jittor" + projects = Project.where(id: [1403791,1404837,1404087,1403854,1403883,1403886,1403894,1404027,1404187,1404234,1404291,1404522,1404238,1404632,1404003,1403975,1404285,1404525,1404017,1403843,1403867,1403874,1403878,1403881,1403887,1403898,1403916,1403937,1403954,1403961,1403963,1403965,1403967,1403972,1403974,1403976,1403977,1403978,1404007,1404012,1404020,1404023,1404032,1404042,1404058,1404065,1404069,1404071,1404072,1404078,1404094,1404104,1404143,1404146,1404167,1404173,1404174,1404175,1404210,1404216,1404226,1404229,1404240,1404242,1404244,1404247,1404248,1404250,1404261,1404272,1404276,1404290,1404327,1404333,1404360,1404450,1404460,1404466,1404485,1404489,1404491,1404496,1404500,1404502,1404507,1404519,1404521,1404523,1404527,1404530,1404532,1404537,1404540,1404541,1404710,1404328,1404211,1404241,1404107,1403880,1404271,1404268,1404745,1404101,1404051,1404047,1404052,1406706,1403852,1403931,1404165,1404607,1404498,1404014,1404045,1404043,1403739,1403801,1403815,1403821,1403822,1403824,1403836,1403853,1403872,1403904,1403906,1403909,1403915,1403919,1403921,1403943,1403945,1403971,1403981,1404022,1404026,1404030,1404037,1404091,1404133,1404163,1404184,1404209,1404212,1404220,1404246,1404249,1404263,1404265,1404287,1404299,1404311,1404497,1404506,1404546,1404558,1404577,1404582,1404591,1404592,1404594,1404595,1404596,1404597,1404605,1404606,1404609,1404639,1404641,1404659,1404671,1404681,1404702,1404748,1404754,1404759,1404785,1404879,1404955,1405169,1405205,1405265,1405374,1407368,1407446,1407671,1407673,1404956,1404079,1404080,1403889,1404665,1404801,1404224,1404931,1404544,1403844,1404036,1404067,1404587,1404696,1404732,1404598,1405192,1404162,1403920,1403903,1405248,1403792,1403817,1403962,1403841,1404188,1404185,1405273,1404575,1404550,1404834,1405420,1404141,1405256,1404633,1405277,1404590,1404796,1405230,1405189,1404584,1405257,1405198,1403925,1404692,1405253,1403809,1405118,1404756,1404962,1404864,1405190,1405258,1405274,1404642,1404924,1404453,1404926,1404649,1404237,1404233,1404600,1404758,1405259,1404157,1404444,1404451,1404920,1404919,1404927,1403830,1404658,1405145,1405185,1403842,1403807,1403895,1404549,1404593,1404750,1404798,1404551,1404701,1405156,1404579,1404655,1405267,1404957,1404556,1404651,1404456,1405430,1403955,1404063,1404214,1403942,1404040,1404804,1428732,1403939,1404208,1404245,1405278,1404139,1403850,1404192,1404293,1404297,1404370,1404492,1404693,1404757,1404329,1404512,1404228,1404314,1404016,1404652,1405275,1404832,1404561,1404653,1404704,1404892,1404589,1404953,1405269,1404881,1404221,1404230,1404793,1403953,1404933,1404035,1404599,1403924,1404119,1404526,1404581,1404705,1404709,1404073,1403808,1403892,1404574,1403849,1404251,1404792,1403865,1404640,1404783,1404048,1406707,1404708,1404053,1404295,1404050,1404049,1404044,1404274,1404046,1404636]) + end + if ENV['project_name'] == "mindspore" + projects = Project.where(identifier: ['MindSpore-first-experience', ' MindSpore-install', 'MindSpore-Application-practice', 'MindSpore-Model-Development', 'MindSpore-Data-preprocessing', 'Mindspore-Data-storage-use', 'MindSpore-Data-storage-kunpeng', 'MindSpore-LeNet-jzx3', 'MindSpore-competition'] ) + end + projects.each_with_index do |project, index| + result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier, {page: params[:page], limit: params[:limit]}) + # @total_count = result[:total_count] + # @contributors = result.is_a?(Hash) ? result[:body] : [] + next if result.blank? || result[:total_count].blank? + total_count = result[:total_count] + # next if total_count > 2000 + puts "#{index} total_count==========#{total_count}" + if total_count > 200 + total_page = (total_count / 200) + 1 + total_page.times do |i| + add_data_by_page(project, i + 1) + end + else + # add_commit_to_index(project, 1) + data = "" + result[:body].each do |commit| + # puts "commit==========#{commit}" + commiter = commit['commit']['author'] + # "luoyuan " + commit_author = "#{commiter['name']} <#{commiter['email']}>" + commit_sha = commit['sha'] + next if CommitLog.find_by(commit_id: commit_sha).present? + ref = "master" + commit_message = commit['commit']['message'].to_s.size > 200 ? "Message Data too long" : commit['commit']['message'].to_s.gsub("/n","").gsub("\"","") + # user = User.find_by(mail: commiter['email']) + # user_id = user&.id || project.user_id + commit_date = Time.parse(commit['commit']['author']['date']) + commit_date_str = commit_date.strftime("%Y-%m-%d %H:%M:%S") + sql_connection = ActiveRecord::Base.connection + sql_connection.begin_db_transaction + if Issue.find_by_sql("select id from commit_contributors where name='#{commiter['email']}'").present? + sql = "update commit_contributors set created_at ='#{}' where name='#{commiter['email']}'" + else + sql = "INSERT INTO commit_contributors (`created_at`, `count`, `name`) VALUES ('#{commit_date_str}',1,'#{commiter['email']}')" + end + + sql_connection.execute(sql) + sql_connection.commit_db_transaction + + # data += "(#{user_id},#{project.id},#{project.repository&.id},'#{project.identifier}','#{project.owner.name}/#{project.identifier}','#{commit_sha}','#{ref}',\"#{commit_message}\",'#{commit_date_str}','#{commit_date_str}')," + end + # data = data[0,data.length-1] + # if data.present? + # sql_connection = ActiveRecord::Base.connection + # sql_connection.begin_db_transaction + # sql = "INSERT INTO commit_contributors (`created_at`, `count`, `name`) VALUES #{data}" + # sql_connection.execute(sql) + # sql_connection.commit_db_transaction + # end + end + end + + # Time.now + # Wed Mar 15 14:12:09 2023 +0800 + # Time.now.strftime("%a %b %d %H:%M:%S %Y") + # Time.now.strftime("%a %b %d %H:%M:%S %Y +0800") + Time.parse("2023-03-15 14:12:09").strftime("%a %b %d %H:%M:%S %Y +0800") + + end + + def add_data_by_page(project, page) + # Gitea::Repository::Commits::ListSliceService.call(project.owner.login,project.identifier,sha: "", page: 1, limit: 1000, token: "a9244ecac647dd33fee3b480c5898baab1d3fe7d") + result = Gitea::Repository::Commits::ListService.call(project.owner.login,project.identifier,sha: "", page: page, limit: 200, token: project.owner.gitea_token) + data = "" + result[:body].each do |commit| + # puts "commit==========#{commit}" + commiter = commit['commit']['author'] + # "luoyuan " + commit_author = "#{commiter['name']} <#{commiter['email']}>" + commit_sha = commit['sha'] + next if CommitLog.find_by(commit_id: commit_sha).present? + ref = "master" + commit_message = commit['commit']['message'].to_s.size > 200 ? "Message Data too long" : commit['commit']['message'].to_s.gsub("/n","").gsub("\"","") + user = User.find_by(mail: commiter['email']) + user_id = user&.id || project.user_id + commit_date = Time.parse(commit['commit']['author']['date']) + commit_date_str = commit_date.strftime("%Y-%m-%d %H:%M:%S") + + sql_connection = ActiveRecord::Base.connection + sql_connection.begin_db_transaction + if Issue.find_by_sql("select id from commit_contributors where name='#{commiter['email']}'").present? + sql = "update commit_contributors set created_at ='#{}' where name='#{commiter['email']}'" + else + sql = "INSERT INTO commit_contributors (`created_at`, `count`, `name`) VALUES ('#{commit_date_str}',1,'#{commiter['email']}')" + end + + sql_connection.execute(sql) + sql_connection.commit_db_transaction + + # data += "(#{user_id},#{project.id},#{project.repository&.id},'#{project.identifier}','#{project.owner.name}/#{project.identifier}','#{commit_sha}','#{ref}',\"#{commit_message}\",'#{commit_date_str}','#{commit_date_str}')," + end + # data = data[0,data.length-1] + # if data.present? + # sql_connection = ActiveRecord::Base.connection + # sql_connection.begin_db_transaction + # sql = "INSERT INTO commit_logs (`user_id`, `project_id`, `repository_id`, `name`, `full_name`, `commit_id`, `ref`, `message`, `created_at`, `updated_at`) VALUES #{data}" + # sql_connection.execute(sql) + # sql_connection.commit_db_transaction + # end + end + +end \ No newline at end of file From d890e01aed72130a6d67aa99a257f3c22035a9e1 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 19 Apr 2023 20:12:29 +0800 Subject: [PATCH 392/438] =?UTF-8?q?commit=E6=8F=90=E5=8F=96=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E8=80=85=E5=88=9B=E5=BB=BA=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_add_contributors.rake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/tasks/batch_add_contributors.rake b/lib/tasks/batch_add_contributors.rake index 4da743434..e1a5c44e6 100644 --- a/lib/tasks/batch_add_contributors.rake +++ b/lib/tasks/batch_add_contributors.rake @@ -1,5 +1,5 @@ namespace :batch_add_contributors do - desc "commit_log_to_db" + desc "batch_add_contributors" task done: :environment do puts "project_id=================#{ENV['project_id']}" return if ENV['project_id'].blank? @@ -42,7 +42,7 @@ namespace :batch_add_contributors do sql_connection = ActiveRecord::Base.connection sql_connection.begin_db_transaction if Issue.find_by_sql("select id from commit_contributors where name='#{commiter['email']}'").present? - sql = "update commit_contributors set created_at ='#{}' where name='#{commiter['email']}'" + sql = "update commit_contributors set created_at ='#{commit_date_str}' where name='#{commiter['email']}'" else sql = "INSERT INTO commit_contributors (`created_at`, `count`, `name`) VALUES ('#{commit_date_str}',1,'#{commiter['email']}')" end @@ -92,7 +92,7 @@ namespace :batch_add_contributors do sql_connection = ActiveRecord::Base.connection sql_connection.begin_db_transaction if Issue.find_by_sql("select id from commit_contributors where name='#{commiter['email']}'").present? - sql = "update commit_contributors set created_at ='#{}' where name='#{commiter['email']}'" + sql = "update commit_contributors set created_at ='#{commit_date_str}' where name='#{commiter['email']}'" else sql = "INSERT INTO commit_contributors (`created_at`, `count`, `name`) VALUES ('#{commit_date_str}',1,'#{commiter['email']}')" end From 77b4b51c427dfdd3361859513fb0fc284d532683 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 19 Apr 2023 20:14:20 +0800 Subject: [PATCH 393/438] =?UTF-8?q?commit=E6=8F=90=E5=8F=96=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E8=80=85=E5=88=9B=E5=BB=BA=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_add_contributors.rake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/tasks/batch_add_contributors.rake b/lib/tasks/batch_add_contributors.rake index e1a5c44e6..98e53983a 100644 --- a/lib/tasks/batch_add_contributors.rake +++ b/lib/tasks/batch_add_contributors.rake @@ -11,7 +11,8 @@ namespace :batch_add_contributors do projects = Project.where(identifier: ['MindSpore-first-experience', ' MindSpore-install', 'MindSpore-Application-practice', 'MindSpore-Model-Development', 'MindSpore-Data-preprocessing', 'Mindspore-Data-storage-use', 'MindSpore-Data-storage-kunpeng', 'MindSpore-LeNet-jzx3', 'MindSpore-competition'] ) end projects.each_with_index do |project, index| - result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier, {page: params[:page], limit: params[:limit]}) + # result = Gitea::Repository::Contributors::GetService.call(project.owner, project.repository.identifier, {page: params[:page], limit: params[:limit]}) + result = Gitea::Repository::Commits::ListService.call(project.owner.login,project.identifier,sha: "", page: 1, limit: 200, token: project.owner.gitea_token) # @total_count = result[:total_count] # @contributors = result.is_a?(Hash) ? result[:body] : [] next if result.blank? || result[:total_count].blank? From 0b9ebbda4b83e45b510b63e6a9ca7a759704aac6 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 19 Apr 2023 20:16:28 +0800 Subject: [PATCH 394/438] =?UTF-8?q?commit=E6=8F=90=E5=8F=96=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E8=80=85=E5=88=9B=E5=BB=BA=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_add_contributors.rake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/tasks/batch_add_contributors.rake b/lib/tasks/batch_add_contributors.rake index 98e53983a..2649fa671 100644 --- a/lib/tasks/batch_add_contributors.rake +++ b/lib/tasks/batch_add_contributors.rake @@ -47,6 +47,7 @@ namespace :batch_add_contributors do else sql = "INSERT INTO commit_contributors (`created_at`, `count`, `name`) VALUES ('#{commit_date_str}',1,'#{commiter['email']}')" end + puts "sql====#{sql}" sql_connection.execute(sql) sql_connection.commit_db_transaction @@ -97,6 +98,7 @@ namespace :batch_add_contributors do else sql = "INSERT INTO commit_contributors (`created_at`, `count`, `name`) VALUES ('#{commit_date_str}',1,'#{commiter['email']}')" end + puts "sql====#{sql}" sql_connection.execute(sql) sql_connection.commit_db_transaction From 7d51829e3c40a1a161cd8c904a6203a862a62ffb Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 19 Apr 2023 20:17:46 +0800 Subject: [PATCH 395/438] =?UTF-8?q?commit=E6=8F=90=E5=8F=96=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E8=80=85=E5=88=9B=E5=BB=BA=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_add_contributors.rake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/tasks/batch_add_contributors.rake b/lib/tasks/batch_add_contributors.rake index 2649fa671..f6feb332f 100644 --- a/lib/tasks/batch_add_contributors.rake +++ b/lib/tasks/batch_add_contributors.rake @@ -33,7 +33,7 @@ namespace :batch_add_contributors do # "luoyuan " commit_author = "#{commiter['name']} <#{commiter['email']}>" commit_sha = commit['sha'] - next if CommitLog.find_by(commit_id: commit_sha).present? + # next if CommitLog.find_by(commit_id: commit_sha).present? ref = "master" commit_message = commit['commit']['message'].to_s.size > 200 ? "Message Data too long" : commit['commit']['message'].to_s.gsub("/n","").gsub("\"","") # user = User.find_by(mail: commiter['email']) @@ -83,11 +83,11 @@ namespace :batch_add_contributors do # "luoyuan " commit_author = "#{commiter['name']} <#{commiter['email']}>" commit_sha = commit['sha'] - next if CommitLog.find_by(commit_id: commit_sha).present? + # next if CommitLog.find_by(commit_id: commit_sha).present? ref = "master" commit_message = commit['commit']['message'].to_s.size > 200 ? "Message Data too long" : commit['commit']['message'].to_s.gsub("/n","").gsub("\"","") - user = User.find_by(mail: commiter['email']) - user_id = user&.id || project.user_id + # user = User.find_by(mail: commiter['email']) + # user_id = user&.id || project.user_id commit_date = Time.parse(commit['commit']['author']['date']) commit_date_str = commit_date.strftime("%Y-%m-%d %H:%M:%S") From 5bfa14e01adee7af509f7b4b959c9789eed5f3a2 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 19 Apr 2023 20:22:13 +0800 Subject: [PATCH 396/438] =?UTF-8?q?commit=E6=8F=90=E5=8F=96=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E8=80=85=E5=88=9B=E5=BB=BA=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_add_contributors.rake | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/tasks/batch_add_contributors.rake b/lib/tasks/batch_add_contributors.rake index f6feb332f..719b271bf 100644 --- a/lib/tasks/batch_add_contributors.rake +++ b/lib/tasks/batch_add_contributors.rake @@ -93,12 +93,16 @@ namespace :batch_add_contributors do sql_connection = ActiveRecord::Base.connection sql_connection.begin_db_transaction - if Issue.find_by_sql("select id from commit_contributors where name='#{commiter['email']}'").present? - sql = "update commit_contributors set created_at ='#{commit_date_str}' where name='#{commiter['email']}'" + site = Site.find_by_sql("select id, created_at from commit_contributors where name='#{commiter['email']}'") + if site.present? + puts "commit_date====#{commit_date},created_at======#{site.created_at}" + if commit_date.to_i < site.created_at.to_i + sql = "update commit_contributors set created_at ='#{commit_date_str}' where name='#{commiter['email']}'" + end else sql = "INSERT INTO commit_contributors (`created_at`, `count`, `name`) VALUES ('#{commit_date_str}',1,'#{commiter['email']}')" end - puts "sql====#{sql}" + # puts "sql====#{sql}" sql_connection.execute(sql) sql_connection.commit_db_transaction From b55137f87487f49d542ac14ba432f1986f8c7248 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 19 Apr 2023 20:22:28 +0800 Subject: [PATCH 397/438] =?UTF-8?q?commit=E6=8F=90=E5=8F=96=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E8=80=85=E5=88=9B=E5=BB=BA=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_add_contributors.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/batch_add_contributors.rake b/lib/tasks/batch_add_contributors.rake index 719b271bf..de42e1beb 100644 --- a/lib/tasks/batch_add_contributors.rake +++ b/lib/tasks/batch_add_contributors.rake @@ -102,7 +102,7 @@ namespace :batch_add_contributors do else sql = "INSERT INTO commit_contributors (`created_at`, `count`, `name`) VALUES ('#{commit_date_str}',1,'#{commiter['email']}')" end - # puts "sql====#{sql}" + puts "sql====#{sql}" sql_connection.execute(sql) sql_connection.commit_db_transaction From 68a457547668a64deedb4de13280dd35ebb32c65 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 19 Apr 2023 20:25:07 +0800 Subject: [PATCH 398/438] =?UTF-8?q?commit=E6=8F=90=E5=8F=96=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E8=80=85=E5=88=9B=E5=BB=BA=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_add_contributors.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/batch_add_contributors.rake b/lib/tasks/batch_add_contributors.rake index de42e1beb..1e9e5c57a 100644 --- a/lib/tasks/batch_add_contributors.rake +++ b/lib/tasks/batch_add_contributors.rake @@ -95,7 +95,7 @@ namespace :batch_add_contributors do sql_connection.begin_db_transaction site = Site.find_by_sql("select id, created_at from commit_contributors where name='#{commiter['email']}'") if site.present? - puts "commit_date====#{commit_date},created_at======#{site.created_at}" + puts "commit_date====#{commit_date},created_at======#{site.first&.created_at}" if commit_date.to_i < site.created_at.to_i sql = "update commit_contributors set created_at ='#{commit_date_str}' where name='#{commiter['email']}'" end From 0aee41c7eaea3f86555f5bc94b2e941db6f7496b Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 19 Apr 2023 20:27:18 +0800 Subject: [PATCH 399/438] =?UTF-8?q?commit=E6=8F=90=E5=8F=96=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E8=80=85=E5=88=9B=E5=BB=BA=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_add_contributors.rake | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/tasks/batch_add_contributors.rake b/lib/tasks/batch_add_contributors.rake index 1e9e5c57a..633ee869e 100644 --- a/lib/tasks/batch_add_contributors.rake +++ b/lib/tasks/batch_add_contributors.rake @@ -40,15 +40,19 @@ namespace :batch_add_contributors do # user_id = user&.id || project.user_id commit_date = Time.parse(commit['commit']['author']['date']) commit_date_str = commit_date.strftime("%Y-%m-%d %H:%M:%S") - sql_connection = ActiveRecord::Base.connection - sql_connection.begin_db_transaction - if Issue.find_by_sql("select id from commit_contributors where name='#{commiter['email']}'").present? - sql = "update commit_contributors set created_at ='#{commit_date_str}' where name='#{commiter['email']}'" + site = Site.find_by_sql("select id, created_at from commit_contributors where name='#{commiter['email']}'") + if site.present? + puts "commit_date====#{commit_date},created_at======#{site.first&.created_at}" + if commit_date.to_i < site.created_at.to_i + sql = "update commit_contributors set created_at ='#{commit_date_str}' where name='#{commiter['email']}'" + end else sql = "INSERT INTO commit_contributors (`created_at`, `count`, `name`) VALUES ('#{commit_date_str}',1,'#{commiter['email']}')" end puts "sql====#{sql}" + sql_connection = ActiveRecord::Base.connection + sql_connection.begin_db_transaction sql_connection.execute(sql) sql_connection.commit_db_transaction @@ -90,10 +94,8 @@ namespace :batch_add_contributors do # user_id = user&.id || project.user_id commit_date = Time.parse(commit['commit']['author']['date']) commit_date_str = commit_date.strftime("%Y-%m-%d %H:%M:%S") - - sql_connection = ActiveRecord::Base.connection - sql_connection.begin_db_transaction site = Site.find_by_sql("select id, created_at from commit_contributors where name='#{commiter['email']}'") + if site.present? puts "commit_date====#{commit_date},created_at======#{site.first&.created_at}" if commit_date.to_i < site.created_at.to_i @@ -104,6 +106,8 @@ namespace :batch_add_contributors do end puts "sql====#{sql}" + sql_connection = ActiveRecord::Base.connection + sql_connection.begin_db_transaction sql_connection.execute(sql) sql_connection.commit_db_transaction From fe294e6fed80da64ab81804e3deaaaee28796fd8 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 19 Apr 2023 20:28:25 +0800 Subject: [PATCH 400/438] =?UTF-8?q?commit=E6=8F=90=E5=8F=96=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E8=80=85=E5=88=9B=E5=BB=BA=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_add_contributors.rake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tasks/batch_add_contributors.rake b/lib/tasks/batch_add_contributors.rake index 633ee869e..806c132c6 100644 --- a/lib/tasks/batch_add_contributors.rake +++ b/lib/tasks/batch_add_contributors.rake @@ -43,7 +43,7 @@ namespace :batch_add_contributors do site = Site.find_by_sql("select id, created_at from commit_contributors where name='#{commiter['email']}'") if site.present? puts "commit_date====#{commit_date},created_at======#{site.first&.created_at}" - if commit_date.to_i < site.created_at.to_i + if commit_date.to_i < site.first&.created_at.to_i sql = "update commit_contributors set created_at ='#{commit_date_str}' where name='#{commiter['email']}'" end else @@ -98,7 +98,7 @@ namespace :batch_add_contributors do if site.present? puts "commit_date====#{commit_date},created_at======#{site.first&.created_at}" - if commit_date.to_i < site.created_at.to_i + if commit_date.to_i < site.first&.created_at.to_i sql = "update commit_contributors set created_at ='#{commit_date_str}' where name='#{commiter['email']}'" end else From d61622f31b19a411c04021149240ff4332fc2cc9 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 19 Apr 2023 20:29:51 +0800 Subject: [PATCH 401/438] =?UTF-8?q?commit=E6=8F=90=E5=8F=96=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E8=80=85=E5=88=9B=E5=BB=BA=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_add_contributors.rake | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/tasks/batch_add_contributors.rake b/lib/tasks/batch_add_contributors.rake index 806c132c6..3a13d2225 100644 --- a/lib/tasks/batch_add_contributors.rake +++ b/lib/tasks/batch_add_contributors.rake @@ -41,6 +41,7 @@ namespace :batch_add_contributors do commit_date = Time.parse(commit['commit']['author']['date']) commit_date_str = commit_date.strftime("%Y-%m-%d %H:%M:%S") site = Site.find_by_sql("select id, created_at from commit_contributors where name='#{commiter['email']}'") + sql ="" if site.present? puts "commit_date====#{commit_date},created_at======#{site.first&.created_at}" if commit_date.to_i < site.first&.created_at.to_i @@ -50,6 +51,7 @@ namespace :batch_add_contributors do sql = "INSERT INTO commit_contributors (`created_at`, `count`, `name`) VALUES ('#{commit_date_str}',1,'#{commiter['email']}')" end puts "sql====#{sql}" + next if sql.blank? sql_connection = ActiveRecord::Base.connection sql_connection.begin_db_transaction @@ -95,7 +97,7 @@ namespace :batch_add_contributors do commit_date = Time.parse(commit['commit']['author']['date']) commit_date_str = commit_date.strftime("%Y-%m-%d %H:%M:%S") site = Site.find_by_sql("select id, created_at from commit_contributors where name='#{commiter['email']}'") - + sql= "" if site.present? puts "commit_date====#{commit_date},created_at======#{site.first&.created_at}" if commit_date.to_i < site.first&.created_at.to_i @@ -105,6 +107,7 @@ namespace :batch_add_contributors do sql = "INSERT INTO commit_contributors (`created_at`, `count`, `name`) VALUES ('#{commit_date_str}',1,'#{commiter['email']}')" end puts "sql====#{sql}" + next if sql.blank? sql_connection = ActiveRecord::Base.connection sql_connection.begin_db_transaction From 881acd24804aeabdf8ec599e9cd777804e3fb936 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 20 Apr 2023 11:31:34 +0800 Subject: [PATCH 402/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=AD=BE=E7=BD=B2cla=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/users_controller.rb | 5 +++++ config/routes/api.rb | 1 + db/migrate/20230420031926_add_sign_cla_to_users.rb | 5 +++++ 3 files changed, 11 insertions(+) create mode 100644 db/migrate/20230420031926_add_sign_cla_to_users.rb diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index 3f7b49f99..2204ff89f 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -8,6 +8,11 @@ class Api::V1::UsersController < Api::V1::BaseController render_ok end + def check_user_login + return tip_exception(-1, "用户标识不存在") unless params[:login].present? && User.exists?(login: params[:login]) + render_ok + end + def send_email_vefify_code code = %W(0 1 2 3 4 5 6 7 8 9) verification_code = code.sample(6).join diff --git a/config/routes/api.rb b/config/routes/api.rb index 77ff5d03b..20c56138c 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -5,6 +5,7 @@ defaults format: :json do resources :users, only: [:index] do collection do post :check_user_id + post :check_user_login end end diff --git a/db/migrate/20230420031926_add_sign_cla_to_users.rb b/db/migrate/20230420031926_add_sign_cla_to_users.rb new file mode 100644 index 000000000..36a849bfb --- /dev/null +++ b/db/migrate/20230420031926_add_sign_cla_to_users.rb @@ -0,0 +1,5 @@ +class AddSignClaToUsers < ActiveRecord::Migration[5.2] + def change + add_column :users, :sign_cla, :boolean, default: false + end +end From c91b986bec8f30af56c5c962b631e78adc503e90 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 20 Apr 2023 11:39:42 +0800 Subject: [PATCH 403/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=AD=BE=E7=BD=B2cla=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/get_user_info.json.jbuilder | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/users/get_user_info.json.jbuilder b/app/views/users/get_user_info.json.jbuilder index 68bfa6589..a1d689f44 100644 --- a/app/views/users/get_user_info.json.jbuilder +++ b/app/views/users/get_user_info.json.jbuilder @@ -28,3 +28,4 @@ json.message_unread_total @message_unread_total json.has_trace_user @user.trace_user.present? json.is_new @user.login.present? && params[:login].to_s.include?("#{@user.login}") json.nps EduSetting.get("nps-on-off-switch").to_s == 'true' && UserNp.where(user_id: current_user.id).where("created_at >= ?", (Time.now - 30.days).beginning_of_day ).blank? +json.sign_cla @user.sign_cla \ No newline at end of file From e9da21bccfd389d19ea978a4d158a3eabc292f76 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 21 Apr 2023 09:23:30 +0800 Subject: [PATCH 404/438] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Aopenkylin=5F?= =?UTF-8?q?sign=20=E7=AD=BE=E7=BD=B2=E5=8D=8F=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/users/openkylin_sign_controller.rb | 23 ++++++++++ app/controllers/api/v1/users_controller.rb | 4 +- app/models/openkylin_sign_detail.rb | 24 ++++++++++ .../v1/users/openkylin_sign/create_service.rb | 45 +++++++++++++++++++ config/routes/api.rb | 5 +++ ...420092835_create_openkylin_sign_details.rb | 14 ++++++ 6 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 app/controllers/api/v1/users/openkylin_sign_controller.rb create mode 100644 app/models/openkylin_sign_detail.rb create mode 100644 app/services/api/v1/users/openkylin_sign/create_service.rb create mode 100644 db/migrate/20230420092835_create_openkylin_sign_details.rb diff --git a/app/controllers/api/v1/users/openkylin_sign_controller.rb b/app/controllers/api/v1/users/openkylin_sign_controller.rb new file mode 100644 index 000000000..d37e76363 --- /dev/null +++ b/app/controllers/api/v1/users/openkylin_sign_controller.rb @@ -0,0 +1,23 @@ +class Api::V1::Users::OpenkylinSignController < Api::V1::BaseController + + before_action :load_observe_user + + def competitions + @competition_ids = EduSetting.get("openkylin_sign_competitions").split(",") rescue [] + render :json => {data: @competition_ids} + end + + def create + @object_result = Api::V1::Users::OpenkylinSign::CreateService.call(@observe_user, create_params) + if @result_object + return render_ok + else + return render_error('签署失败!') + end + end + + private + def create_params + params.permit(:login, :email, :nickname, :phone, :address) + end +end \ No newline at end of file diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index 2204ff89f..47087c523 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -1,7 +1,7 @@ class Api::V1::UsersController < Api::V1::BaseController - before_action :load_observe_user, except: [:check_user_id] - before_action :check_auth_for_observe_user, except: [:check_user_id] + before_action :load_observe_user, except: [:check_user_id, :check_user_login] + before_action :check_auth_for_observe_user, except: [:check_user_id, :check_user_login] def check_user_id return tip_exception(-1, "用户ID不存在") unless params[:user_id].present? && User.exists?(id: params[:user_id]) diff --git a/app/models/openkylin_sign_detail.rb b/app/models/openkylin_sign_detail.rb new file mode 100644 index 000000000..7f9000cf5 --- /dev/null +++ b/app/models/openkylin_sign_detail.rb @@ -0,0 +1,24 @@ +# == Schema Information +# +# Table name: openkylin_sign_details +# +# id :integer not null, primary key +# user_id :integer +# login :string(255) +# email :string(255) +# nickname :string(255) +# phone :string(255) +# address :string(255) +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_openkylin_sign_details_on_user_id (user_id) +# + +class OpenkylinSignDetail < ApplicationRecord + + belongs_to :user + +end diff --git a/app/services/api/v1/users/openkylin_sign/create_service.rb b/app/services/api/v1/users/openkylin_sign/create_service.rb new file mode 100644 index 000000000..e9703d9dc --- /dev/null +++ b/app/services/api/v1/users/openkylin_sign/create_service.rb @@ -0,0 +1,45 @@ +class Api::V1::Users::OpenkylinSign::CreateService < ApplicationService + include ActiveModel::Model + + attr_reader :observe_user, :login, :email, :nickname, :phone, :address + + # validates :login, format: {with: CustomRegexp::LOGIN} + validates :email, format: {with: CustomRegexp::EMAIL} + validates :nickname, length: { maximum: 32 } + validates :phone, format: {with: CustomRegexp::PHONE} + validates :address, length: { maximum: 100 } + + def initialize(observe_user, params={}) + @observe_user = observe_user + @login = observe_user.login + @email = params[:email] + @nickname = params[:nickname] + @phone = params[:phone] + @address = params[:address] + end + + def call + raise Error, errors.full_messages.join(",") unless valid? + raise Error, '用户已经签署CLA协议!' if @observe_user.sign_cla + begin + ActiveRecord::Base.transaction do + create_openkylin_sign_detail + update_user_sign_cla + end + + return true + rescue + raise Error, "服务器错误,请联系系统管理员!" + end + end + + private + def create_openkylin_sign_detail + OpenkylinSignDetail.create!(user_id: @observe_user.id, login: @login, email: @email, nickname: @nickname, phone: @phone, address: @address) + end + + def update_user_sign_cla + @observe_user.update_attributes!(sign_cla: true) + end + +end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index 20c56138c..4d5547683 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -24,6 +24,11 @@ defaults format: :json do scope module: :users do resources :projects, only: [:index] resources :feedbacks, only: [:create] + resources :openkylin_sign, only: [:create] do + collection do + get :competitions + end + end end scope ':repo', constraints: { repo: /[^\/]+/ } do diff --git a/db/migrate/20230420092835_create_openkylin_sign_details.rb b/db/migrate/20230420092835_create_openkylin_sign_details.rb new file mode 100644 index 000000000..e282a5f43 --- /dev/null +++ b/db/migrate/20230420092835_create_openkylin_sign_details.rb @@ -0,0 +1,14 @@ +class CreateOpenkylinSignDetails < ActiveRecord::Migration[5.2] + def change + create_table :openkylin_sign_details do |t| + t.references :user + t.string :login + t.string :email + t.string :nickname + t.string :phone + t.string :address + + t.timestamps + end + end +end From 1387e1d17ec31005cae13b9f3a55b8120bfec683 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 21 Apr 2023 14:07:31 +0800 Subject: [PATCH 405/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Areadme?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E4=B8=8D=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/repositories_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index afde12d2c..010197a70 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -88,7 +88,7 @@ module RepositoriesHelper unless r_content.include?("http://") || r_content.include?("https://") || r_content.include?("mailto:") # new_r_content = "#{path}" + new_r_content - new_r_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw?filepath=#{path_current}/#{path_last}&ref=#{ref}"].join + new_r_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw/#{path_current}/#{path_last}&ref=#{ref}"].join end content = content.gsub(/src=\"#{r_content}\"/, "src=\"#{new_r_content}\"").gsub(/src='#{r_content}'/, "src=\"#{new_r_content}\"") rescue @@ -132,7 +132,7 @@ module RepositoriesHelper s_content = File.expand_path(s_content, file_path) s_content = s_content.split("#{Rails.root}/")[1] # content = content.gsub(s[0], "/#{s_content}") - s_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw?filepath=#{s_content}&ref=#{ref}"].join + s_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw/#{s_content}&ref=#{ref}"].join case k.to_s when 'ss_src' content = content.gsub("src=\"#{s[0]}\"", "src=\"#{s_content}\"") From 6c26450924e9b4763559cc445be08ee5511b636c Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 21 Apr 2023 14:07:31 +0800 Subject: [PATCH 406/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Areadme?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E4=B8=8D=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/repositories_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index afde12d2c..010197a70 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -88,7 +88,7 @@ module RepositoriesHelper unless r_content.include?("http://") || r_content.include?("https://") || r_content.include?("mailto:") # new_r_content = "#{path}" + new_r_content - new_r_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw?filepath=#{path_current}/#{path_last}&ref=#{ref}"].join + new_r_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw/#{path_current}/#{path_last}&ref=#{ref}"].join end content = content.gsub(/src=\"#{r_content}\"/, "src=\"#{new_r_content}\"").gsub(/src='#{r_content}'/, "src=\"#{new_r_content}\"") rescue @@ -132,7 +132,7 @@ module RepositoriesHelper s_content = File.expand_path(s_content, file_path) s_content = s_content.split("#{Rails.root}/")[1] # content = content.gsub(s[0], "/#{s_content}") - s_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw?filepath=#{s_content}&ref=#{ref}"].join + s_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw/#{s_content}&ref=#{ref}"].join case k.to_s when 'ss_src' content = content.gsub("src=\"#{s[0]}\"", "src=\"#{s_content}\"") From 67d7d11c6236860353fd4c1413180a9e0e725739 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 21 Apr 2023 14:22:38 +0800 Subject: [PATCH 407/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A&to=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/repositories_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 010197a70..c9be515d2 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -88,7 +88,7 @@ module RepositoriesHelper unless r_content.include?("http://") || r_content.include?("https://") || r_content.include?("mailto:") # new_r_content = "#{path}" + new_r_content - new_r_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw/#{path_current}/#{path_last}&ref=#{ref}"].join + new_r_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw/#{path_current}/#{path_last}?ref=#{ref}"].join end content = content.gsub(/src=\"#{r_content}\"/, "src=\"#{new_r_content}\"").gsub(/src='#{r_content}'/, "src=\"#{new_r_content}\"") rescue @@ -132,7 +132,7 @@ module RepositoriesHelper s_content = File.expand_path(s_content, file_path) s_content = s_content.split("#{Rails.root}/")[1] # content = content.gsub(s[0], "/#{s_content}") - s_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw/#{s_content}&ref=#{ref}"].join + s_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw/#{s_content}?ref=#{ref}"].join case k.to_s when 'ss_src' content = content.gsub("src=\"#{s[0]}\"", "src=\"#{s_content}\"") From d523ab328e11b7d850b6244107b88f58259be684 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 21 Apr 2023 17:55:10 +0800 Subject: [PATCH 408/438] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Acla=E5=8D=8F?= =?UTF-8?q?=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/users/openkylin_sign_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/v1/users/openkylin_sign_controller.rb b/app/controllers/api/v1/users/openkylin_sign_controller.rb index d37e76363..df36e7867 100644 --- a/app/controllers/api/v1/users/openkylin_sign_controller.rb +++ b/app/controllers/api/v1/users/openkylin_sign_controller.rb @@ -9,7 +9,7 @@ class Api::V1::Users::OpenkylinSignController < Api::V1::BaseController def create @object_result = Api::V1::Users::OpenkylinSign::CreateService.call(@observe_user, create_params) - if @result_object + if @object_result return render_ok else return render_error('签署失败!') From fb745453c21a49384c20ca626e7f0e6ae7253da3 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 25 Apr 2023 17:22:25 +0800 Subject: [PATCH 409/438] =?UTF-8?q?=E5=A2=9E=E5=8A=A0sidekiq=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/sidekiq.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/config/sidekiq.yml b/config/sidekiq.yml index 0b38a0b8f..81915d50e 100644 --- a/config/sidekiq.yml +++ b/config/sidekiq.yml @@ -1,12 +1,12 @@ -:concurrency: <%= ENV["sidekiq_threads"] || 20 %> -:pidfile: tmp/pids/sidekiq.pid -:logfile: log/sidekiq.log -:timeout: 30 -:queues: - - [default, 3] - - [searchkick, 10] - - [notify, 100] - - [mailers, 101] - - [cache, 10] - - [message, 20] - - [webhook, 20] +:concurrency: <%= ENV["sidekiq_threads"] || 40 %> +:pidfile: tmp/pids/sidekiq.pid +:logfile: log/sidekiq.log +:timeout: 30 +:queues: + - [default, 3] + - [searchkick, 10] + - [notify, 100] + - [mailers, 101] + - [cache, 10] + - [message, 20] + - [webhook, 20] From d2ced0bc6cd067164f1c59cf42394ebdd6d56b5d Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 25 Apr 2023 18:01:45 +0800 Subject: [PATCH 410/438] =?UTF-8?q?=E5=A2=9E=E5=8A=A0sidekiq=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/users/openkylin_sign_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/api/v1/users/openkylin_sign_controller.rb b/app/controllers/api/v1/users/openkylin_sign_controller.rb index df36e7867..6c76c5b3e 100644 --- a/app/controllers/api/v1/users/openkylin_sign_controller.rb +++ b/app/controllers/api/v1/users/openkylin_sign_controller.rb @@ -9,6 +9,7 @@ class Api::V1::Users::OpenkylinSignController < Api::V1::BaseController def create @object_result = Api::V1::Users::OpenkylinSign::CreateService.call(@observe_user, create_params) + Rails.logger.info "OpenkylinSignController=====#{@object_result}" if @object_result return render_ok else From 1fb3865865f7d19bc4097e2df9bb02448878d501 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 25 Apr 2023 18:02:31 +0800 Subject: [PATCH 411/438] =?UTF-8?q?=E5=A2=9E=E5=8A=A0sidekiq=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/users/openkylin_sign_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/api/v1/users/openkylin_sign_controller.rb b/app/controllers/api/v1/users/openkylin_sign_controller.rb index df36e7867..6c76c5b3e 100644 --- a/app/controllers/api/v1/users/openkylin_sign_controller.rb +++ b/app/controllers/api/v1/users/openkylin_sign_controller.rb @@ -9,6 +9,7 @@ class Api::V1::Users::OpenkylinSignController < Api::V1::BaseController def create @object_result = Api::V1::Users::OpenkylinSign::CreateService.call(@observe_user, create_params) + Rails.logger.info "OpenkylinSignController=====#{@object_result}" if @object_result return render_ok else From c90fc3d48734d92753abef008e93bb2912ce9663 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 26 Apr 2023 15:55:29 +0800 Subject: [PATCH 412/438] =?UTF-8?q?=E5=AE=B9=E9=94=99=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/repositories/_contributor.json.jbuilder | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/repositories/_contributor.json.jbuilder b/app/views/repositories/_contributor.json.jbuilder index ea8a5ae30..5d1c093bd 100644 --- a/app/views/repositories/_contributor.json.jbuilder +++ b/app/views/repositories/_contributor.json.jbuilder @@ -3,7 +3,7 @@ if user.blank? json.contributions contributor["commits"] json.login nil json.type nil - json.name contributor["name"].downcase + json.name contributor["name"].to_s.downcase json.email contributor["email"] json.image_url User::Avatar.get_letter_avatar_url(contributor["name"]) json.contribution_perc User.new(login: contributor["name"], mail: contributor["email"]).simple_contribution_perc(project, contributor["contribution_perc"]) @@ -13,7 +13,7 @@ else json.login user["login"] json.email user["email"] json.type user["type"] - json.name user["name"].downcase + json.name user["name"].to_s.downcase json.image_url user["avatar_url"] db_user = User.find_by_id(user["id"]) json.contribution_perc db_user.simple_contribution_perc(project, contributor["contribution_perc"]) if db_user.present? From 9f4e201360a4fc52e0ea898aa0f5ab4429be858f Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 26 Apr 2023 16:03:06 +0800 Subject: [PATCH 413/438] =?UTF-8?q?=E5=AE=B9=E9=94=99=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/repositories/_contributor.json.jbuilder | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/repositories/_contributor.json.jbuilder b/app/views/repositories/_contributor.json.jbuilder index 5d1c093bd..0c4ddfb51 100644 --- a/app/views/repositories/_contributor.json.jbuilder +++ b/app/views/repositories/_contributor.json.jbuilder @@ -1,11 +1,11 @@ -user = $redis_cache.hgetall("v2-owner-common:#{contributor["name"]}-#{contributor["email"]}") +user = $redis_cache.hgetall("v2-owner-common:#{contributor["name"] || contributor["login"]}-#{contributor["email"]}") if user.blank? json.contributions contributor["commits"] - json.login nil + json.login contributor["name"].to_s.downcase || contributor["login"].to_s.downcase json.type nil - json.name contributor["name"].to_s.downcase + json.name contributor["name"].to_s.downcase || contributor["login"].to_s.downcase json.email contributor["email"] - json.image_url User::Avatar.get_letter_avatar_url(contributor["name"]) + json.image_url User::Avatar.get_letter_avatar_url(contributor["name"] || contributor["login"]) json.contribution_perc User.new(login: contributor["name"], mail: contributor["email"]).simple_contribution_perc(project, contributor["contribution_perc"]) else json.contributions contributor["commits"] From 67760fd1a97b3913dca059db37e5bd2d1d8c1ae7 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 26 Apr 2023 16:07:40 +0800 Subject: [PATCH 414/438] =?UTF-8?q?=E8=B4=A1=E7=8C=AE=E8=80=85=E5=AE=B9?= =?UTF-8?q?=E9=94=99=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/repositories/_contributor.json.jbuilder | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/repositories/_contributor.json.jbuilder b/app/views/repositories/_contributor.json.jbuilder index 0c4ddfb51..da2ae37dc 100644 --- a/app/views/repositories/_contributor.json.jbuilder +++ b/app/views/repositories/_contributor.json.jbuilder @@ -1,6 +1,6 @@ user = $redis_cache.hgetall("v2-owner-common:#{contributor["name"] || contributor["login"]}-#{contributor["email"]}") if user.blank? - json.contributions contributor["commits"] + json.contributions contributor["commits"] || contributor["contributions"] json.login contributor["name"].to_s.downcase || contributor["login"].to_s.downcase json.type nil json.name contributor["name"].to_s.downcase || contributor["login"].to_s.downcase @@ -8,12 +8,12 @@ if user.blank? json.image_url User::Avatar.get_letter_avatar_url(contributor["name"] || contributor["login"]) json.contribution_perc User.new(login: contributor["name"], mail: contributor["email"]).simple_contribution_perc(project, contributor["contribution_perc"]) else - json.contributions contributor["commits"] + json.contributions contributor["commits"] || contributor["contributions"] json.id user["id"] - json.login user["login"] + json.login user["login"] || contributor["name"].to_s.downcase || contributor["login"].to_s.downcase json.email user["email"] json.type user["type"] - json.name user["name"].to_s.downcase + json.name user["name"].to_s.downcase || contributor["name"].to_s.downcase || contributor["login"].to_s.downcase json.image_url user["avatar_url"] db_user = User.find_by_id(user["id"]) json.contribution_perc db_user.simple_contribution_perc(project, contributor["contribution_perc"]) if db_user.present? From 8b28c84a8e8154d31dcb467425316e7d3b6d6379 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 26 Apr 2023 16:08:22 +0800 Subject: [PATCH 415/438] =?UTF-8?q?=E8=B4=A1=E7=8C=AE=E8=80=85=E5=AE=B9?= =?UTF-8?q?=E9=94=99=E5=A4=84=E7=90=86?= 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 da2ae37dc..dddf04398 100644 --- a/app/views/repositories/_contributor.json.jbuilder +++ b/app/views/repositories/_contributor.json.jbuilder @@ -6,7 +6,7 @@ if user.blank? json.name contributor["name"].to_s.downcase || contributor["login"].to_s.downcase json.email contributor["email"] json.image_url User::Avatar.get_letter_avatar_url(contributor["name"] || contributor["login"]) - json.contribution_perc User.new(login: contributor["name"], mail: contributor["email"]).simple_contribution_perc(project, contributor["contribution_perc"]) + json.contribution_perc User.new(login: (contributor["name"] || contributor["login"]), mail: contributor["email"]).simple_contribution_perc(project, contributor["contribution_perc"]) else json.contributions contributor["commits"] || contributor["contributions"] json.id user["id"] From c4ae40ee5297f4dd84a37dfdf6ee5688470e0c74 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 26 Apr 2023 16:15:23 +0800 Subject: [PATCH 416/438] =?UTF-8?q?=E8=B4=A1=E7=8C=AE=E8=80=85=E5=AE=B9?= =?UTF-8?q?=E9=94=99=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/repositories/_contributor.json.jbuilder | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/repositories/_contributor.json.jbuilder b/app/views/repositories/_contributor.json.jbuilder index dddf04398..001ddd8b1 100644 --- a/app/views/repositories/_contributor.json.jbuilder +++ b/app/views/repositories/_contributor.json.jbuilder @@ -1,19 +1,19 @@ user = $redis_cache.hgetall("v2-owner-common:#{contributor["name"] || contributor["login"]}-#{contributor["email"]}") if user.blank? json.contributions contributor["commits"] || contributor["contributions"] - json.login contributor["name"].to_s.downcase || contributor["login"].to_s.downcase + json.login (contributor["name"] || contributor["login"]).to_s.downcase json.type nil - json.name contributor["name"].to_s.downcase || contributor["login"].to_s.downcase + json.name (contributor["name"] || contributor["login"]).to_s.downcase json.email contributor["email"] json.image_url User::Avatar.get_letter_avatar_url(contributor["name"] || contributor["login"]) json.contribution_perc User.new(login: (contributor["name"] || contributor["login"]), mail: contributor["email"]).simple_contribution_perc(project, contributor["contribution_perc"]) else json.contributions contributor["commits"] || contributor["contributions"] json.id user["id"] - json.login user["login"] || contributor["name"].to_s.downcase || contributor["login"].to_s.downcase + json.login (user["login"] || contributor["name"] || contributor["login"]).to_s.downcase json.email user["email"] json.type user["type"] - json.name user["name"].to_s.downcase || contributor["name"].to_s.downcase || contributor["login"].to_s.downcase + json.name (user["name"] || contributor["name"] || contributor["login"]).to_s.downcase json.image_url user["avatar_url"] db_user = User.find_by_id(user["id"]) json.contribution_perc db_user.simple_contribution_perc(project, contributor["contribution_perc"]) if db_user.present? From 6b716855a90e427ac38449047832d59fd05a7036 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 26 Apr 2023 16:17:58 +0800 Subject: [PATCH 417/438] =?UTF-8?q?=E8=B4=A1=E7=8C=AE=E8=80=85=E5=AE=B9?= =?UTF-8?q?=E9=94=99=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/repositories/_contributor.json.jbuilder | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/repositories/_contributor.json.jbuilder b/app/views/repositories/_contributor.json.jbuilder index 001ddd8b1..b0547eba3 100644 --- a/app/views/repositories/_contributor.json.jbuilder +++ b/app/views/repositories/_contributor.json.jbuilder @@ -1,7 +1,7 @@ user = $redis_cache.hgetall("v2-owner-common:#{contributor["name"] || contributor["login"]}-#{contributor["email"]}") if user.blank? json.contributions contributor["commits"] || contributor["contributions"] - json.login (contributor["name"] || contributor["login"]).to_s.downcase + json.login nil json.type nil json.name (contributor["name"] || contributor["login"]).to_s.downcase json.email contributor["email"] @@ -10,7 +10,7 @@ if user.blank? else json.contributions contributor["commits"] || contributor["contributions"] json.id user["id"] - json.login (user["login"] || contributor["name"] || contributor["login"]).to_s.downcase + json.login user["login"] json.email user["email"] json.type user["type"] json.name (user["name"] || contributor["name"] || contributor["login"]).to_s.downcase From 1bfaa44af570b5829c4a398dd0b3b5fe05f6e1bd Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 27 Apr 2023 09:29:13 +0800 Subject: [PATCH 418/438] =?UTF-8?q?=E4=BB=93=E5=BA=93=E8=AF=AD=E8=A8=80?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E9=9A=8F=E7=9D=80=E9=A1=B9=E7=9B=AE=E6=95=B0?= =?UTF-8?q?=E5=8F=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/organizations/organizations_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/organizations/organizations_controller.rb b/app/controllers/organizations/organizations_controller.rb index 0abd8d1ca..c2e670f55 100644 --- a/app/controllers/organizations/organizations_controller.rb +++ b/app/controllers/organizations/organizations_controller.rb @@ -88,7 +88,7 @@ class Organizations::OrganizationsController < Organizations::BaseController projects = @organization.projects projects_count = @organization.projects.count - languages_hash = Rails.cache.fetch("query/organizations/languages/#{@organization.id}", :expires_in => 1.days) do + languages_hash = Rails.cache.fetch("query/organizations/languages/#{@organization.id}/#{projects_count}", :expires_in => 1.days) do total_languages(projects) end From ba344e76ba033cc7abb82376a9a4dcceba23b213 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 27 Apr 2023 09:29:13 +0800 Subject: [PATCH 419/438] =?UTF-8?q?=E4=BB=93=E5=BA=93=E8=AF=AD=E8=A8=80?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E9=9A=8F=E7=9D=80=E9=A1=B9=E7=9B=AE=E6=95=B0?= =?UTF-8?q?=E5=8F=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/organizations/organizations_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/organizations/organizations_controller.rb b/app/controllers/organizations/organizations_controller.rb index 0abd8d1ca..c2e670f55 100644 --- a/app/controllers/organizations/organizations_controller.rb +++ b/app/controllers/organizations/organizations_controller.rb @@ -88,7 +88,7 @@ class Organizations::OrganizationsController < Organizations::BaseController projects = @organization.projects projects_count = @organization.projects.count - languages_hash = Rails.cache.fetch("query/organizations/languages/#{@organization.id}", :expires_in => 1.days) do + languages_hash = Rails.cache.fetch("query/organizations/languages/#{@organization.id}/#{projects_count}", :expires_in => 1.days) do total_languages(projects) end From 9630fbfec55a40ef06eddc2d0972bf5eb40e179a Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 27 Apr 2023 18:07:43 +0800 Subject: [PATCH 420/438] =?UTF-8?q?=E4=BB=93=E5=BA=93=E8=AF=AD=E8=A8=80?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E9=9A=8F=E7=9D=80=E9=A1=B9=E7=9B=AE=E6=95=B0?= =?UTF-8?q?=E5=8F=98=E5=8C=96=EF=BC=8C=E8=AE=A1=E7=AE=97=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/organizations/organizations_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/organizations/organizations_controller.rb b/app/controllers/organizations/organizations_controller.rb index c2e670f55..31300f1ea 100644 --- a/app/controllers/organizations/organizations_controller.rb +++ b/app/controllers/organizations/organizations_controller.rb @@ -94,9 +94,10 @@ class Organizations::OrganizationsController < Organizations::BaseController languages_hash = languages_hash.sort { |x, y| y[1] <=> x[1] } sort_hash = Hash[*languages_hash.flatten] + total_byte_size = sort_hash.values.sum # Rails.logger.info "languages_hash=============#{sort_hash}" sort_hash= sort_hash.transform_values { |v| - ActionController::Base.helpers.number_to_percentage((v / projects_count), precision: 1) + ActionController::Base.helpers.number_to_percentage((v / total_byte_size), precision: 1) }.select { |k, v| v != "0.0%" } render json: sort_hash end From e50d4bdf34c8a56ee95d1d6bec843bb24535e7b5 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 27 Apr 2023 18:10:35 +0800 Subject: [PATCH 421/438] =?UTF-8?q?=E4=BB=93=E5=BA=93=E8=AF=AD=E8=A8=80?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E9=9A=8F=E7=9D=80=E9=A1=B9=E7=9B=AE=E6=95=B0?= =?UTF-8?q?=E5=8F=98=E5=8C=96=EF=BC=8C=E8=AE=A1=E7=AE=97=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/organizations/organizations_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/organizations/organizations_controller.rb b/app/controllers/organizations/organizations_controller.rb index 31300f1ea..3c4e64780 100644 --- a/app/controllers/organizations/organizations_controller.rb +++ b/app/controllers/organizations/organizations_controller.rb @@ -88,7 +88,7 @@ class Organizations::OrganizationsController < Organizations::BaseController projects = @organization.projects projects_count = @organization.projects.count - languages_hash = Rails.cache.fetch("query/organizations/languages/#{@organization.id}/#{projects_count}", :expires_in => 1.days) do + languages_hash = Rails.cache.fetch("query/organizations/languages/#{@organization.id}/#{projects_count}/2023", :expires_in => 1.days) do total_languages(projects) end @@ -97,7 +97,7 @@ class Organizations::OrganizationsController < Organizations::BaseController total_byte_size = sort_hash.values.sum # Rails.logger.info "languages_hash=============#{sort_hash}" sort_hash= sort_hash.transform_values { |v| - ActionController::Base.helpers.number_to_percentage((v / total_byte_size), precision: 1) + ActionController::Base.helpers.number_to_percentage((v * 100 / total_byte_size), precision: 1) }.select { |k, v| v != "0.0%" } render json: sort_hash end From 8198b347e70393fcf86246d6e4809761f07388bc Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 27 Apr 2023 18:11:00 +0800 Subject: [PATCH 422/438] =?UTF-8?q?=E4=BB=93=E5=BA=93=E8=AF=AD=E8=A8=80?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E9=9A=8F=E7=9D=80=E9=A1=B9=E7=9B=AE=E6=95=B0?= =?UTF-8?q?=E5=8F=98=E5=8C=96=EF=BC=8C=E8=AE=A1=E7=AE=97=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/organizations/organizations_controller.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/organizations/organizations_controller.rb b/app/controllers/organizations/organizations_controller.rb index c2e670f55..3c4e64780 100644 --- a/app/controllers/organizations/organizations_controller.rb +++ b/app/controllers/organizations/organizations_controller.rb @@ -88,15 +88,16 @@ class Organizations::OrganizationsController < Organizations::BaseController projects = @organization.projects projects_count = @organization.projects.count - languages_hash = Rails.cache.fetch("query/organizations/languages/#{@organization.id}/#{projects_count}", :expires_in => 1.days) do + languages_hash = Rails.cache.fetch("query/organizations/languages/#{@organization.id}/#{projects_count}/2023", :expires_in => 1.days) do total_languages(projects) end languages_hash = languages_hash.sort { |x, y| y[1] <=> x[1] } sort_hash = Hash[*languages_hash.flatten] + total_byte_size = sort_hash.values.sum # Rails.logger.info "languages_hash=============#{sort_hash}" sort_hash= sort_hash.transform_values { |v| - ActionController::Base.helpers.number_to_percentage((v / projects_count), precision: 1) + ActionController::Base.helpers.number_to_percentage((v * 100 / total_byte_size), precision: 1) }.select { |k, v| v != "0.0%" } render json: sort_hash end From d633550a4f194f1a32fff4dd7e11997602ee6cc2 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 4 May 2023 20:52:56 +0800 Subject: [PATCH 423/438] =?UTF-8?q?file=5Fcommits=20hat=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=80=A7=E8=83=BD=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/gitea/repository/commits/file_list_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/gitea/repository/commits/file_list_service.rb b/app/services/gitea/repository/commits/file_list_service.rb index 77a193475..4a0bbe2cd 100644 --- a/app/services/gitea/repository/commits/file_list_service.rb +++ b/app/services/gitea/repository/commits/file_list_service.rb @@ -14,7 +14,7 @@ class Gitea::Repository::Commits::FileListService < Gitea::ClientService end def call - response = get(url, params, true) + response = get(url, params, false) render_result(response) end From e4040bbe56ce99e51533812db234afb6fa294d90 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 4 May 2023 20:53:52 +0800 Subject: [PATCH 424/438] =?UTF-8?q?file=5Fcommits=20hat=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=80=A7=E8=83=BD=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/gitea/repository/commits/file_list_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/gitea/repository/commits/file_list_service.rb b/app/services/gitea/repository/commits/file_list_service.rb index 77a193475..4a0bbe2cd 100644 --- a/app/services/gitea/repository/commits/file_list_service.rb +++ b/app/services/gitea/repository/commits/file_list_service.rb @@ -14,7 +14,7 @@ class Gitea::Repository::Commits::FileListService < Gitea::ClientService end def call - response = get(url, params, true) + response = get(url, params, false) render_result(response) end From d9b4c30f60d070b0c490418c547ab07af7ddcb9c Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 4 May 2023 21:20:33 +0800 Subject: [PATCH 425/438] =?UTF-8?q?file=5Fcommits=20hat=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=80=A7=E8=83=BD=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/gitea/repository/commits/file_list_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/gitea/repository/commits/file_list_service.rb b/app/services/gitea/repository/commits/file_list_service.rb index 4a0bbe2cd..77a193475 100644 --- a/app/services/gitea/repository/commits/file_list_service.rb +++ b/app/services/gitea/repository/commits/file_list_service.rb @@ -14,7 +14,7 @@ class Gitea::Repository::Commits::FileListService < Gitea::ClientService end def call - response = get(url, params, false) + response = get(url, params, true) render_result(response) end From cc89a61892b02b21159635eaa9703a0709994f2b Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 5 May 2023 15:00:21 +0800 Subject: [PATCH 426/438] =?UTF-8?q?file=5Fcommits=20hat=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=80=A7=E8=83=BD=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/gitea/repository/commits/file_list_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/gitea/repository/commits/file_list_service.rb b/app/services/gitea/repository/commits/file_list_service.rb index 4a0bbe2cd..77a193475 100644 --- a/app/services/gitea/repository/commits/file_list_service.rb +++ b/app/services/gitea/repository/commits/file_list_service.rb @@ -14,7 +14,7 @@ class Gitea::Repository::Commits::FileListService < Gitea::ClientService end def call - response = get(url, params, false) + response = get(url, params, true) render_result(response) end From 8a23fc0fbc32b80afeea6c9a987d6abb6816af9c Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 5 May 2023 15:40:18 +0800 Subject: [PATCH 427/438] =?UTF-8?q?file=5Fcommits=20hat=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=80=A7=E8=83=BD=E9=97=AE=E9=A2=98=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=8F=82=E6=95=B0stat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/gitea/repository/commits/file_list_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/gitea/repository/commits/file_list_service.rb b/app/services/gitea/repository/commits/file_list_service.rb index 77a193475..14c873fd3 100644 --- a/app/services/gitea/repository/commits/file_list_service.rb +++ b/app/services/gitea/repository/commits/file_list_service.rb @@ -20,7 +20,7 @@ class Gitea::Repository::Commits::FileListService < Gitea::ClientService private def params - {sha: args[:sha] || 'master', page: args[:page] || PAGINATE_DEFAULT_PAGE, limit: args[:limit] || PAGINATE_DEFAULT_LIMIT, token: args[:token] || "" } + {sha: args[:sha] || 'master', page: args[:page] || PAGINATE_DEFAULT_PAGE, limit: args[:limit] || PAGINATE_DEFAULT_LIMIT, token: args[:token] || "", stat: args[:page].to_i != 1 } end def url From 769f888f3ea404c7d2e436691c6ec4c983447f1d Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Sat, 6 May 2023 01:15:00 +0800 Subject: [PATCH 428/438] replace_file --- app/controllers/repositories_controller.rb | 14 ++++++++++++++ config/routes.rb | 1 + 2 files changed, 15 insertions(+) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 5d8745397..6cdf3753c 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -211,6 +211,20 @@ class RepositoriesController < ApplicationController end end + def replace_file + #删除 + delete_interactor = Gitea::DeleteFileInteractor.call(current_user.gitea_token, @owner.login, params[:delete_file].merge(identifier: @project.identifier)) + return render_error(delete_interactor.error) unless delete_interactor.success? + #新建 + interactor = Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params) + if interactor.success? + @file = interactor.result + else + render_error(interactor.error) + end + + end + def delete_file interactor = Gitea::DeleteFileInteractor.call(current_user.gitea_token, @owner.login, params.merge(identifier: @project.identifier)) if interactor.success? diff --git a/config/routes.rb b/config/routes.rb index 7e69c2e38..da3cdd979 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -498,6 +498,7 @@ Rails.application.routes.draw do get :tags get :contributors post :create_file + post :replace_file put :update_file delete :delete_file post :repo_hook From 4c1bcd87a21922f8fa892f067031ca7eeec1e0d8 Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Sat, 6 May 2023 14:42:11 +0800 Subject: [PATCH 429/438] add repositories replace_file json --- app/views/repositories/replace_file.json.jbuilder | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 app/views/repositories/replace_file.json.jbuilder diff --git a/app/views/repositories/replace_file.json.jbuilder b/app/views/repositories/replace_file.json.jbuilder new file mode 100644 index 000000000..5687ee731 --- /dev/null +++ b/app/views/repositories/replace_file.json.jbuilder @@ -0,0 +1,11 @@ +json.name @file['content']['name'] +json.sha @file['content']['sha'] +json.size @file['content']['size'] +json.content @file['content']['content'] +json.encoding @file['content']['encoding'] +json.pr_id @pull_issue.try(:id) +json.commit do + json.message @file['commit']['message'] + json.author @file['commit']['author'] + json.committer @file['commit']['committer'] +end From b86ea02dc9b7f8d97df9b2069c97b4bfd60e85a6 Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Sat, 6 May 2023 15:00:06 +0800 Subject: [PATCH 430/438] change response for replace file --- app/controllers/repositories_controller.rb | 1 + app/views/repositories/replace_file.json.jbuilder | 11 ----------- 2 files changed, 1 insertion(+), 11 deletions(-) delete mode 100644 app/views/repositories/replace_file.json.jbuilder diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index f729ab394..66b30eef8 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -219,6 +219,7 @@ class RepositoriesController < ApplicationController interactor = Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params) if interactor.success? @file = interactor.result + render_result(0, "替换成功") else render_error(interactor.error) end diff --git a/app/views/repositories/replace_file.json.jbuilder b/app/views/repositories/replace_file.json.jbuilder deleted file mode 100644 index 5687ee731..000000000 --- a/app/views/repositories/replace_file.json.jbuilder +++ /dev/null @@ -1,11 +0,0 @@ -json.name @file['content']['name'] -json.sha @file['content']['sha'] -json.size @file['content']['size'] -json.content @file['content']['content'] -json.encoding @file['content']['encoding'] -json.pr_id @pull_issue.try(:id) -json.commit do - json.message @file['commit']['message'] - json.author @file['commit']['author'] - json.committer @file['commit']['committer'] -end From bc76324290f408f93c83ada2274aebce39abdfd1 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 8 May 2023 15:36:19 +0800 Subject: [PATCH 431/438] =?UTF-8?q?fixed=20=E9=A1=B9=E7=9B=AE=E6=A0=87?= =?UTF-8?q?=E8=AF=86=E6=A0=A1=E9=AA=8C=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/libs/custom_regexp.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/libs/custom_regexp.rb b/app/libs/custom_regexp.rb index 6012382b2..b735a631b 100644 --- a/app/libs/custom_regexp.rb +++ b/app/libs/custom_regexp.rb @@ -10,6 +10,7 @@ module CustomRegexp IP = /^((\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3}(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])$/ URL_REGEX = /\A(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?\z/i - REPOSITORY_NAME_REGEX = /^[a-zA-Z0-9][a-zA-Z0-9\-\_\.]+[a-zA-Z0-9]$/ #只含有数字、字母、下划线不能以下划线开头和结尾 + # REPOSITORY_NAME_REGEX = /^[a-zA-Z0-9][a-zA-Z0-9\-\_\.]+[a-zA-Z0-9]$/ #只含有数字、字母、下划线不能以下划线开头和结尾 + REPOSITORY_NAME_REGEX = /^[a-zA-Z0-9\-\_\.]+[a-zA-Z0-9]$/ #只含有数字、字母、下划线不能以下划线开头和结尾 MD_REGEX = /^.+(\.[m|M][d|D])$/ end From 5c26a6a877766db0ace166da833f0a088525bbc7 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 8 May 2023 16:33:43 +0800 Subject: [PATCH 432/438] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=A0=87=E8=AF=86?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E6=96=87=E6=A1=88=E7=BB=9F=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/forms/projects/create_form.rb | 2 +- app/forms/projects/migrate_form.rb | 2 +- app/forms/projects/update_form.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/forms/projects/create_form.rb b/app/forms/projects/create_form.rb index 9c7424094..6b08d1f8f 100644 --- a/app/forms/projects/create_form.rb +++ b/app/forms/projects/create_form.rb @@ -4,7 +4,7 @@ class Projects::CreateForm < BaseForm :blockchain, :blockchain_token_all, :blockchain_init_token validates :user_id, :name, :repository_name, presence: true - validates :repository_name, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "项目标识只能包含数字,字母,下划线(_),中划线(-),英文句号(.),必须以数字和字母开头,不能以下划线/中划线/英文句号开头和结尾" } + validates :repository_name, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "项目标识长度为2~100, 只能包含数字,字母,下划线(_),中划线(-),英文句号(.),必须以数字和字母开头,不能以下划线/中划线/英文句号开头和结尾" } validates :name, length: { maximum: 50 } validates :repository_name, length: { maximum: 100 } diff --git a/app/forms/projects/migrate_form.rb b/app/forms/projects/migrate_form.rb index 1cb9b462e..4d81307ca 100644 --- a/app/forms/projects/migrate_form.rb +++ b/app/forms/projects/migrate_form.rb @@ -3,7 +3,7 @@ class Projects::MigrateForm < BaseForm :project_language_id, :clone_addr, :private, :is_mirror, :auth_username, :auth_password, :owner validates :user_id, :name, :repository_name, :clone_addr, presence: true - validates :repository_name, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "项目标识只能包含数字,字母,下划线(_),中划线(-),英文句号(.),必须以数字和字母开头,不能以下划线/中划线/英文句号开头和结尾" } + validates :repository_name, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "项目标识长度为2~100, 只能包含数字,字母,下划线(_),中划线(-),英文句号(.),必须以数字和字母开头,不能以下划线/中划线/英文句号开头和结尾" } validates :clone_addr, format: { with: CustomRegexp::URL_REGEX, multiline: true, message: "地址格式不正确" } validates :name, length: { maximum: 50 } validates :repository_name, length: { maximum: 100 } diff --git a/app/forms/projects/update_form.rb b/app/forms/projects/update_form.rb index 1a04b7fe4..1bd7ad68b 100644 --- a/app/forms/projects/update_form.rb +++ b/app/forms/projects/update_form.rb @@ -3,7 +3,7 @@ class Projects::UpdateForm < BaseForm validates :name, presence: true validates :name, length: { maximum: 50 } validates :description, length: { maximum: 200 } - validates :identifier, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: '项目标识只能包含数字,字母,下划线(_),中划线(-),英文句号(.),必须以数字和字母开头,不能以下划线/中划线/英文句号开头和结尾' } + validates :identifier, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: '项目标识长度为2~100, 只能包含数字,字母,下划线(_),中划线(-),英文句号(.),必须以数字和字母开头,不能以下划线/中划线/英文句号开头和结尾' } validate do check_project_category(project_category_id) From 5343fcf29ee4d4f89a486ba2299b53f5b15d62b1 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 8 May 2023 16:40:57 +0800 Subject: [PATCH 433/438] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=A0=87=E8=AF=86?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E6=96=87=E6=A1=88=E7=BB=9F=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/forms/projects/create_form.rb | 2 +- app/forms/projects/migrate_form.rb | 2 +- app/forms/projects/update_form.rb | 2 +- config/locales/forms/projects_create_form.zh-CN.yml | 4 ++++ 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/forms/projects/create_form.rb b/app/forms/projects/create_form.rb index 6b08d1f8f..c133175c2 100644 --- a/app/forms/projects/create_form.rb +++ b/app/forms/projects/create_form.rb @@ -4,7 +4,7 @@ class Projects::CreateForm < BaseForm :blockchain, :blockchain_token_all, :blockchain_init_token validates :user_id, :name, :repository_name, presence: true - validates :repository_name, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "项目标识长度为2~100, 只能包含数字,字母,下划线(_),中划线(-),英文句号(.),必须以数字和字母开头,不能以下划线/中划线/英文句号开头和结尾" } + validates :repository_name, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "长度为2~100, 只能包含数字,字母,下划线(_),中划线(-),英文句号(.),必须以数字和字母开头,不能以下划线/中划线/英文句号开头和结尾" } validates :name, length: { maximum: 50 } validates :repository_name, length: { maximum: 100 } diff --git a/app/forms/projects/migrate_form.rb b/app/forms/projects/migrate_form.rb index 4d81307ca..12a4ee617 100644 --- a/app/forms/projects/migrate_form.rb +++ b/app/forms/projects/migrate_form.rb @@ -3,7 +3,7 @@ class Projects::MigrateForm < BaseForm :project_language_id, :clone_addr, :private, :is_mirror, :auth_username, :auth_password, :owner validates :user_id, :name, :repository_name, :clone_addr, presence: true - validates :repository_name, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "项目标识长度为2~100, 只能包含数字,字母,下划线(_),中划线(-),英文句号(.),必须以数字和字母开头,不能以下划线/中划线/英文句号开头和结尾" } + validates :repository_name, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "长度为2~100, 只能包含数字,字母,下划线(_),中划线(-),英文句号(.),必须以数字和字母开头,不能以下划线/中划线/英文句号开头和结尾" } validates :clone_addr, format: { with: CustomRegexp::URL_REGEX, multiline: true, message: "地址格式不正确" } validates :name, length: { maximum: 50 } validates :repository_name, length: { maximum: 100 } diff --git a/app/forms/projects/update_form.rb b/app/forms/projects/update_form.rb index 1bd7ad68b..226b2dc59 100644 --- a/app/forms/projects/update_form.rb +++ b/app/forms/projects/update_form.rb @@ -3,7 +3,7 @@ class Projects::UpdateForm < BaseForm validates :name, presence: true validates :name, length: { maximum: 50 } validates :description, length: { maximum: 200 } - validates :identifier, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: '项目标识长度为2~100, 只能包含数字,字母,下划线(_),中划线(-),英文句号(.),必须以数字和字母开头,不能以下划线/中划线/英文句号开头和结尾' } + validates :identifier, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: '长度为2~100, 只能包含数字,字母,下划线(_),中划线(-),英文句号(.),必须以数字和字母开头,不能以下划线/中划线/英文句号开头和结尾' } validate do check_project_category(project_category_id) diff --git a/config/locales/forms/projects_create_form.zh-CN.yml b/config/locales/forms/projects_create_form.zh-CN.yml index 54de8e71a..f319c3cd4 100644 --- a/config/locales/forms/projects_create_form.zh-CN.yml +++ b/config/locales/forms/projects_create_form.zh-CN.yml @@ -2,6 +2,10 @@ activemodel: attributes: projects/create_form: + name: 项目名称 + repository_name: 项目标识 + description: 项目简介 + projects/migrate_form: name: 项目名称 repository_name: 项目标识 description: 项目简介 \ No newline at end of file From 784553d894c50f39ee6a59b2e115f30f362167d6 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 8 May 2023 17:15:19 +0800 Subject: [PATCH 434/438] =?UTF-8?q?fixed=20=E8=AF=AD=E8=A8=80=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/gitea/client_service.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/services/gitea/client_service.rb b/app/services/gitea/client_service.rb index fae4ae27e..b2b0aef11 100644 --- a/app/services/gitea/client_service.rb +++ b/app/services/gitea/client_service.rb @@ -221,6 +221,8 @@ class Gitea::ClientService < ApplicationService end [body, message] + rescue + return [{}, ""] end def json_parse!(body) From 55581be46bd168203eb1f39a8a02ae005f63e036 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 9 May 2023 10:11:43 +0800 Subject: [PATCH 435/438] =?UTF-8?q?fixed=20=E5=A4=B4=E6=AD=8C=E5=BF=AB?= =?UTF-8?q?=E9=80=9F=E7=99=BB=E5=BD=95=E5=9B=9E=E8=B0=83=E9=87=8D=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index f36aaa165..0702b1069 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -431,7 +431,7 @@ Rails.application.routes.draw do get '/auth/qq/callback', to: 'oauth/qq#create' get '/auth/wechat/callback', to: 'oauth/wechat#create' - get '/auth/educoder/callback', to: 'oauth/educoder#create' + # get '/auth/educoder/callback', to: 'oauth/educoder#create' resource :bind_user, only: [:create] resources :hot_keywords, only: [:index] From 0d2d38d53724894c2eb07a9a7ee87abeb15df2c7 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 9 May 2023 10:25:36 +0800 Subject: [PATCH 436/438] =?UTF-8?q?fixed=20=E5=A4=B4=E6=AD=8C=E5=BF=AB?= =?UTF-8?q?=E9=80=9F=E7=99=BB=E5=BD=95=E7=94=A8=E6=88=B7=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/oauth/educoder_controller.rb | 25 ++++++++++++-------- config/routes.rb | 2 +- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/app/controllers/oauth/educoder_controller.rb b/app/controllers/oauth/educoder_controller.rb index 9ca4ae49b..6d479ed0c 100644 --- a/app/controllers/oauth/educoder_controller.rb +++ b/app/controllers/oauth/educoder_controller.rb @@ -49,24 +49,29 @@ class Oauth::EducoderController < Oauth::BaseController open_user = OpenUsers::Educoder.find_by(uid: result['login']) if open_user.present? && open_user.user.present? successful_authentication(open_user.user) + redirect_to root_path(new_user: false) + return else if current_user.blank? || !current_user.logged? new_user = true - login = User.generate_login('E') - reg_result = autologin_register(login,"#{login}@forge.com", "Ec#{login}2021#", 'educoder', true) - if reg_result[:message].blank? - open_user = OpenUsers::Educoder.create!(user_id: reg_result[:user][:id], uid: result['login'], extra: result) - autosync_register_trustie(login, "Ec#{login}2021#", "#{login}@forge.com") - successful_authentication(open_user.user) - else - render_error(reg_result[:message]) - end + session[:unionid] = result['login'] + # login = User.generate_login('E') + # reg_result = autologin_register(login,"#{login}@forge.com", "Ec#{login}2021#", 'educoder', true) + # if reg_result[:message].blank? + # open_user = OpenUsers::Educoder.create!(user_id: reg_result[:user][:id], uid: result['login'], extra: result) + # autosync_register_trustie(login, "Ec#{login}2021#", "#{login}@forge.com") + # successful_authentication(open_user.user) + # else + # render_error(reg_result[:message]) + # end else OpenUsers::Educoder.create!(user: current_user, uid: result['login'], extra: result) end end + Rails.logger.info("[OAuth2] session[:unionid] -> #{session[:unionid]}") + redirect_to "/bindlogin/educoder" - redirect_to root_path(new_user: new_user) + # redirect_to root_path(new_user: new_user) rescue Exception => ex render_error(ex.message) end diff --git a/config/routes.rb b/config/routes.rb index 0702b1069..f36aaa165 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -431,7 +431,7 @@ Rails.application.routes.draw do get '/auth/qq/callback', to: 'oauth/qq#create' get '/auth/wechat/callback', to: 'oauth/wechat#create' - # get '/auth/educoder/callback', to: 'oauth/educoder#create' + get '/auth/educoder/callback', to: 'oauth/educoder#create' resource :bind_user, only: [:create] resources :hot_keywords, only: [:index] From d1352825f132644b0ed59091c2b9d13ad9a720cc Mon Sep 17 00:00:00 2001 From: kingchan Date: Tue, 9 May 2023 15:44:00 +0800 Subject: [PATCH 437/438] sub_entries render -2 --- app/controllers/repositories_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 66b30eef8..8587ab570 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -110,7 +110,8 @@ class RepositoriesController < ApplicationController result = interactor.result @sub_entries = result.is_a?(Array) ? result.sort_by{ |hash| hash['type'] } : result else - render_error(interactor.error) + status = interactor.error == "你访问的文件不存在"? -2 : -1 + render_error(interactor.error,status) end end end From bd0a19586959fc3b62e84b48df650c177ed26d8a Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 10 May 2023 14:30:18 +0800 Subject: [PATCH 438/438] =?UTF-8?q?=E6=95=B4=E7=90=86=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=92=8C=E8=84=9A=E6=9C=AC=E7=BB=86=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/configuration.yml.example | 57 +------- config/database.yml.example | 123 +++++++++--------- ...1124111351_update_pull_request_utf_name.rb | 2 +- 3 files changed, 70 insertions(+), 112 deletions(-) diff --git a/config/configuration.yml.example b/config/configuration.yml.example index c90cea288..be8d59997 100644 --- a/config/configuration.yml.example +++ b/config/configuration.yml.example @@ -1,33 +1,5 @@ default: &default - # 用户登入的时候设置/登出的时候清空 - autologin_cookie_name: 'autologin_gitlink' platform_url: 'http://localhost:3000' - sign_key: '' - - #附件上传路径 - attachment_folder: '/tmp' - - # webssh相关 - tomcat_webssh: 'https://testwebssh.gitlink.org.cn' - webssh_username: '' - webssh_password: '' - - # git服务地址 - git_address_ip: '' - - #新版git服务地址 - git_address_domain: '' - - # git管理员用户名问题, 适用于git客户端的操作 - git_username: '' - git_password: '' - - ucloud: - public_key: '' - private_key: '' - public_bucket: '' - public_bucket_host: '' - public_cdn_host: '' oauth: qq: appid: 'test' @@ -45,10 +17,10 @@ default: &default callback_url: 'callback_url' signature_key: 'test12345678' educoder: - client_id: 'e9ce4d5ba1698d6f7d01d8ee2959776c7a6d743ebe94da2341e288fd2fbf60aa' - client_secret: '6ff84dd75eddd859c5bd0e7a791b58bc5ad1ba4fbb30bc9db37cb0baf9f33012' - base_url: 'https://test-data.educoder.net' - redirect_uri: 'https://testforgeplus.trustie.net/api/auth/educoder/callback' + client_id: 'test' + client_secret: 'test123456' + base_url: 'https://test.a.com' + redirect_uri: 'https://test.a.com/api/auth/educoder/callback' gitea: access_key_id: '' @@ -73,7 +45,8 @@ default: &default trace: domain: '' base_url: '' - + cookie_domain: '.gitlink.org.cn' + view_domain: 'https://cjn.gitlink.org.cn' forum: domain: '' base_url: '/api' @@ -83,26 +56,10 @@ default: &default production: <<: *default - # 中间层地址 - - cloud_bridge: '' - cloud_tomcat_php: '' - bridge_secret_key: '' - cookie_domain: '.gitlink.org.cn' - - attachment_folder: '' - host_name: 'https://testeduplus2.gitlink.org.cn' - old_edu_host: 'http://testbdweb.gitlink.org.cn' development: <<: *default - cloud_bridge: '' - cloud_tomcat_php: '' - host_name: '' - old_edu_host: '' test: <<: *default - cloud_tomcat_php: 'http://10.9.63.225' - host_name: 'https://testeduplus2.gitlink.org.cn' - old_edu_host: 'http://testbdweb.gitlink.org.cn' + diff --git a/config/database.yml.example b/config/database.yml.example index 52f6538e1..157a5ac54 100644 --- a/config/database.yml.example +++ b/config/database.yml.example @@ -1,61 +1,62 @@ -# MySQL. Versions 5.1.10 and up are supported. -# -# Install the MySQL driver -# gem install mysql2 -# -# Ensure the MySQL gem is defined in your Gemfile -# gem 'mysql2' -# -# And be sure to use new-style password hashing: -# https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html -# -default: &default - adapter: mysql2 - host: 127.0.0.1 - encoding: utf8 - pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> - username: root - password: 123456 -# socket: /var/run/mysqld/mysqld.sock - gitea_server: - adapter: mysql2 - database: gitea_development - host: 127.0.0.1 - username: root - password: "123456" - encoding: utf8 - -development: - <<: *default - host: 127.0.0.1 - database: forge_development - -# Warning: The database defined as "test" will be erased and -# re-generated from your development database when you run "rake". -# Do not set this db to the same as development or production. -test: - <<: *default - database: forge_test - -# As with config/secrets.yml, you never want to store sensitive information, -# like your database password, in your source code. If your source code is -# ever seen by anyone, they now have access to your database. -# -# Instead, provide the password as a unix environment variable when you boot -# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database -# for a full rundown on how to provide these environment variables in a -# production deployment. -# -# On Heroku and other platform providers, you may have a full connection URL -# available as an environment variable. For example: -# -# DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase" -# -# You can use this database configuration with: -# -# production: -# url: <%= ENV['DATABASE_URL'] %> -# -production: - <<: *default - database: forge_production +# MySQL. Versions 5.1.10 and up are supported. +# +# Install the MySQL driver +# gem install mysql2 +# +# Ensure the MySQL gem is defined in your Gemfile +# gem 'mysql2' +# +# And be sure to use new-style password hashing: +# https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html +# +default: &default + adapter: mysql2 + host: 127.0.0.1 + encoding: utf8mb4 + reconnect: true + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + username: root + password: 123456 +# socket: /var/run/mysqld/mysqld.sock + gitea_server: + adapter: mysql2 + database: gitea_development + host: 127.0.0.1 + username: root + password: "123456" + encoding: utf8 + +development: + <<: *default + host: 127.0.0.1 + database: forge_development + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: forge_test + +# As with config/secrets.yml, you never want to store sensitive information, +# like your database password, in your source code. If your source code is +# ever seen by anyone, they now have access to your database. +# +# Instead, provide the password as a unix environment variable when you boot +# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database +# for a full rundown on how to provide these environment variables in a +# production deployment. +# +# On Heroku and other platform providers, you may have a full connection URL +# available as an environment variable. For example: +# +# DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase" +# +# You can use this database configuration with: +# +# production: +# url: <%= ENV['DATABASE_URL'] %> +# +production: + <<: *default + database: forge_production diff --git a/db/migrate/20221124111351_update_pull_request_utf_name.rb b/db/migrate/20221124111351_update_pull_request_utf_name.rb index 6d0fd2fec..d0c0ec9fc 100644 --- a/db/migrate/20221124111351_update_pull_request_utf_name.rb +++ b/db/migrate/20221124111351_update_pull_request_utf_name.rb @@ -11,6 +11,6 @@ class UpdatePullRequestUtfName < ActiveRecord::Migration[5.2] execute("ALTER TABLE `versions` MODIFY `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;") execute("ALTER TABLE `issue_tags` MODIFY `name` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;") execute("ALTER TABLE `issue_tags` MODIFY `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;") - execute("ALTER TABLE `projects_activity` MODIFY `project_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;") + # execute("ALTER TABLE `projects_activity` MODIFY `project_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;") end end