From 53b66f6145c6b4bf6fd7b964e5070ef5351f6428 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 30 Aug 2023 16:34:23 +0800 Subject: [PATCH 001/130] =?UTF-8?q?fixed=20=E6=96=87=E4=BB=B6=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=BC=96=E8=BE=91=E5=88=A0=E9=99=A4=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E6=97=A0=E6=9D=83=E9=99=90=E6=8F=90=E7=A4=BA=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/interactors/gitea/delete_file_interactor.rb | 3 +++ app/interactors/gitea/update_file_interactor.rb | 3 +++ app/services/gitea/repository/entries/create_service.rb | 6 ++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/interactors/gitea/delete_file_interactor.rb b/app/interactors/gitea/delete_file_interactor.rb index 103df6cd..03ddf423 100644 --- a/app/interactors/gitea/delete_file_interactor.rb +++ b/app/interactors/gitea/delete_file_interactor.rb @@ -42,6 +42,9 @@ module Gitea def render_result(response) if response.status == 200 @result = JSON.parse(response.body) + else + Rails.logger.error("Gitea::Repository::Entries::DeleteService error[#{response.status}]======#{response.body}") + @error = "删除失败,请确认该分支是否是保护分支。" end end diff --git a/app/interactors/gitea/update_file_interactor.rb b/app/interactors/gitea/update_file_interactor.rb index 38cfd98a..1b729e2c 100644 --- a/app/interactors/gitea/update_file_interactor.rb +++ b/app/interactors/gitea/update_file_interactor.rb @@ -42,6 +42,9 @@ module Gitea def render_result(response) if response.status == 200 @result = JSON.parse(response.body) + else + Rails.logger.error("Gitea::Repository::Entries::UpdateService error[#{response.status}]======#{response.body}") + @error = "更新失败,请确认该分支是否是保护分支。" end end diff --git a/app/services/gitea/repository/entries/create_service.rb b/app/services/gitea/repository/entries/create_service.rb index 14b37333..ac27b3af 100644 --- a/app/services/gitea/repository/entries/create_service.rb +++ b/app/services/gitea/repository/entries/create_service.rb @@ -53,7 +53,7 @@ class Gitea::Repository::Entries::CreateService < Gitea::ClientService def status_payload(status, body) case status when 201 then success(json_parse!(body)) - when 403 then error("你没有权限操作!") + when 403 then error("你没有权限操作,请确认该分支是否是保护分支。") when 404 then error("你操作的链接不存在!") when 422 if @body[:new_branch].present? && (@body[:new_branch].include?('/') || @body[:new_branch].include?('\'') || @body[:new_branch].include?('^') || @body[:new_branch].include?('*')) @@ -61,7 +61,9 @@ class Gitea::Repository::Entries::CreateService < Gitea::ClientService else error("#{filepath}文件已存在,不能重复创建!") end - else error("系统错误!") + else + Rails.logger.error("Gitea api url==#{url},status:#{status},body=#{body}") + error("系统错误!") end end end From cdf62b4626f0c423f1e480cb53ebc6fe3ccb0277 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 30 Aug 2023 17:42:24 +0800 Subject: [PATCH 002/130] =?UTF-8?q?fixed=20=E5=88=86=E6=94=AF=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=97=B6=E6=9C=89=E5=BC=80=E5=90=AF=E7=9A=84pr?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E4=B8=80=E5=90=8C=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/branches_controller.rb | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/projects/branches_controller.rb b/app/controllers/api/v1/projects/branches_controller.rb index 0c89f601..40f44fea 100644 --- a/app/controllers/api/v1/projects/branches_controller.rb +++ b/app/controllers/api/v1/projects/branches_controller.rb @@ -17,7 +17,16 @@ class Api::V1::Projects::BranchesController < Api::V1::BaseController def destroy @result_object = Api::V1::Projects::Branches::DeleteService.call(@project, params[:name], current_user&.gitea_token) - if @result_object + if @result_object + # 有开启的pr需要一同关闭 + # 1、删除本仓库中存在未关闭的pr,即本仓库分支1->分支2 + # 2、如果是fork仓库,考虑删除主仓库中存在未关闭的pr,即本仓库:分支1->主:分支2,同时分两种删除:1删除本仓库分支1,2删除主仓库分支2 + close_pull_requests_by(@project, params[:name]) + if @project.forked_from_project_id.present? + # fork项目中删除分支 + close_pull_requests_by(@project.fork_project, params[:name]) + end + return render_ok else return render_error('删除分支失败!') @@ -39,4 +48,19 @@ class Api::V1::Projects::BranchesController < Api::V1::BaseController def branch_params params.require(:branch).permit(:new_branch_name, :old_branch_name) end + + def close_pull_requests_by(project, branch_name) + open_pull_requests = project.pull_requests.opening.where(head: branch_name).or(project.pull_requests.opening.where(base: branch_name)) + if open_pull_requests.present? + open_pull_requests.each do |pull_request| + closed = PullRequests::CloseService.call(project.owner, project.repository, pull_request, current_user) + if closed === true + pull_request.project_trends.create!(user: current_user, project: project,action_type: ProjectTrend::CLOSE) + # 合并请求下issue处理为关闭 + pull_request.issue&.update_attributes!({status_id:5}) + SendTemplateMessageJob.perform_later('PullRequestClosed', current_user.id, pull_request.id) if Site.has_notice_menu? + end + end + end + end end \ No newline at end of file From d19c94666a6fffb40257dbce6265e4811bc08734 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Mon, 16 Oct 2023 10:57:37 +0800 Subject: [PATCH 003/130] =?UTF-8?q?=E9=80=9A=E8=BF=87=E4=BB=93=E5=BA=93id?= =?UTF-8?q?=E6=8B=BF=E7=94=A8=E6=88=B7=E6=A0=87=E8=AF=86=E5=92=8C=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 13 +++++++++++-- config/routes.rb | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 446e4bb3..2045eb7f 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -4,9 +4,9 @@ class ProjectsController < ApplicationController include ProjectsHelper include Acceleratorable - before_action :require_login, except: %i[index branches branches_slice group_type_list simple show fork_users praise_users watch_users recommend banner_recommend about menu_list verify_auth_token] + before_action :require_login, except: %i[index branches branches_slice group_type_list simple show mp_show fork_users praise_users watch_users recommend banner_recommend about menu_list verify_auth_token] before_action :require_profile_completed, only: [:create, :migrate,:page_migrate,:verify_auth_token] - before_action :load_repository, except: %i[index group_type_list migrate page_migrate create recommend banner_recommend verify_auth_token] + before_action :load_repository, except: %i[index mp_show group_type_list migrate page_migrate create recommend banner_recommend verify_auth_token] before_action :authorizate_user_can_edit_project!, only: %i[update] before_action :project_public?, only: %i[fork_users praise_users watch_users] before_action :request_limit, only: %i[index] @@ -232,6 +232,15 @@ class ProjectsController < ApplicationController def show end + def mp_show + @project = Project.joins(:owner).find params[:project_id] + data={ + owner:@project.owner.try(:login), + identifier:@project.identifier + } + render_ok(data:data) + end + def destroy if current_user.admin? || @project.manager?(current_user) ActiveRecord::Base.transaction do diff --git a/config/routes.rb b/config/routes.rb index 312f267d..7694a77c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -127,6 +127,7 @@ Rails.application.routes.draw do # blockchain related routes get 'users/blockchain/balance', to: 'users#blockchain_balance' + get 'projects/mp_show', to: 'projects#mp_show' post 'users/blockchain/balance_project', to: 'users#blockchain_balance_one_project' post 'users/blockchain/transfer', to: 'users#blockchain_transfer' post 'users/blockchain/exchange', to: 'users#blockchain_exchange' From 472499e2786c84642f3b03ca60b03a8c22ec4b92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 17 Oct 2023 11:25:25 +0800 Subject: [PATCH 004/130] mp_index for issue_priorities issue_tags issue_statues --- .../v1/issues/issue_priorities_controller.rb | 8 ++++ .../api/v1/issues/issue_tags_controller.rb | 9 +++- .../api/v1/issues/statues_controller.rb | 7 ++++ app/models/issue_tag.rb | 41 +++++++++++++------ config/routes/api.rb | 18 ++++++-- 5 files changed, 66 insertions(+), 17 deletions(-) diff --git a/app/controllers/api/v1/issues/issue_priorities_controller.rb b/app/controllers/api/v1/issues/issue_priorities_controller.rb index 319994a2..c3a223a9 100644 --- a/app/controllers/api/v1/issues/issue_priorities_controller.rb +++ b/app/controllers/api/v1/issues/issue_priorities_controller.rb @@ -7,4 +7,12 @@ class Api::V1::Issues::IssuePrioritiesController < Api::V1::BaseController @priorities = @priorities.ransack(name_cont: params[:keyword]).result if params[:keyword] @priorities = kaminary_select_paginate(@priorities) end + + def mp_index + @priorities = IssuePriority.order(position: :asc) + @priorities = @priorities.ransack(name_cont: params[:keyword]).result if params[:keyword] + @priorities = kaminary_select_paginate(@priorities) + render "index" + end + end \ No newline at end of file diff --git a/app/controllers/api/v1/issues/issue_tags_controller.rb b/app/controllers/api/v1/issues/issue_tags_controller.rb index fe2eccea..e77b5425 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_login, except: [:index, :mp_index] before_action :require_public_and_member_above, only: [:index] before_action :require_operate_above, only: [:create, :update, :destroy] @@ -7,12 +7,17 @@ class Api::V1::Issues::IssueTagsController < Api::V1::BaseController @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)) + @issue_tags = kaminary_select_paginate(@issue_tags.select(:id, :name, :color)) else @issue_tags = kaminari_paginate(@issue_tags.includes(:project, :user, :issue_issues, :pull_request_issues)) end end + def mp_index + @issue_tags = IssueTag.init_mp_issues_tags + render_ok(@issue_tags) + end + def create @issue_tag = @project.issue_tags.new(issue_tag_params) if @issue_tag.save! diff --git a/app/controllers/api/v1/issues/statues_controller.rb b/app/controllers/api/v1/issues/statues_controller.rb index 5a7fbc33..3e2a837e 100644 --- a/app/controllers/api/v1/issues/statues_controller.rb +++ b/app/controllers/api/v1/issues/statues_controller.rb @@ -8,4 +8,11 @@ class Api::V1::Issues::StatuesController < Api::V1::BaseController @statues = @statues.ransack(name_cont: params[:keyword]).result if params[:keyword].present? @statues = kaminary_select_paginate(@statues) end + + def mp_index + @statues = IssueStatus.order("position asc") + @statues = @statues.ransack(name_cont: params[:keyword]).result if params[:keyword].present? + @statues = kaminary_select_paginate(@statues) + render "index" + end end \ No newline at end of file diff --git a/app/models/issue_tag.rb b/app/models/issue_tag.rb index 7251e98f..a3782aba 100644 --- a/app/models/issue_tag.rb +++ b/app/models/issue_tag.rb @@ -32,18 +32,7 @@ class IssueTag < ApplicationRecord validates :name, uniqueness: {scope: :project_id, message: "已存在" } def self.init_data(project_id) - data = [ - ["缺陷", "表示存在意外问题或错误", "#d92d4c"], - ["功能", "表示新功能申请", "#ee955a"], - ["疑问", "表示存在疑惑", "#2d6ddc"], - ["支持", "表示特定功能或特定需求", "#019549"], - ["任务", "表示需要分配的任务", "#c1a30d"], - ["协助", "表示需要社区用户协助", "#2a0dc1"], - ["搁置", "表示此问题暂时不会继续处理", "#892794"], - ["文档", "表示文档材料补充", "#9ed600"], - ["测试", "表示需要测试的需求", "#2897b9"], - ["重复", "表示已存在类似的疑修", "#bb5332"] - ] + data = init_issue_tag_data 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]) @@ -57,6 +46,34 @@ class IssueTag < ApplicationRecord end + def self.init_issue_tag_data + [ + ["缺陷", "表示存在意外问题或错误", "#d92d4c"], + ["功能", "表示新功能申请", "#ee955a"], + ["疑问", "表示存在疑惑", "#2d6ddc"], + ["支持", "表示特定功能或特定需求", "#019549"], + ["任务", "表示需要分配的任务", "#c1a30d"], + ["协助", "表示需要社区用户协助", "#2a0dc1"], + ["搁置", "表示此问题暂时不会继续处理", "#892794"], + ["文档", "表示文档材料补充", "#9ed600"], + ["测试", "表示需要测试的需求", "#2897b9"], + ["重复", "表示已存在类似的疑修", "#bb5332"] + ] + end + + def self.init_mp_issues_tags + data = {"total_count": 10,} + data["issue_tags"] = init_issue_tag_data.map{|item| + { + "name": item[0], + "description": item[1], + "color": item[2], + } + } + data + end + + def to_builder Jbuilder.new do |tag| tag.(self, :id, :name, :description) diff --git a/config/routes/api.rb b/config/routes/api.rb index 4d554768..b6698996 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -55,12 +55,24 @@ defaults format: :json do end end scope module: :issues do - resources :issue_tags, except: [:new, :edit] + resources :issue_tags, except: [:new, :edit] do + collection do + get :mp_index + end + end resources :milestones, except: [:new, :edit] - resources :issue_statues, only: [:index], controller: '/api/v1/issues/statues' + resources :issue_statues, only: [:index], controller: '/api/v1/issues/statues' do + collection do + get :mp_index + end + end 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] + resources :issue_priorities, only: [:index] do + collection do + get :mp_index + end + end end # projects文件夹下的 From 526dac1230ce8c9edb251fdcbe43fb1e351c74cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 18 Oct 2023 13:21:41 +0800 Subject: [PATCH 005/130] change mp to pm --- .../api/v1/issues/issue_priorities_controller.rb | 2 +- app/controllers/api/v1/issues/issue_tags_controller.rb | 4 ++-- app/controllers/api/v1/issues/statues_controller.rb | 2 +- app/models/issue.rb | 2 ++ config/routes/api.rb | 6 +++--- ...18034251_add_pm_project_id_and_pm_sprint_id_to_issues.rb | 6 ++++++ 6 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 db/migrate/20231018034251_add_pm_project_id_and_pm_sprint_id_to_issues.rb diff --git a/app/controllers/api/v1/issues/issue_priorities_controller.rb b/app/controllers/api/v1/issues/issue_priorities_controller.rb index c3a223a9..2df1288f 100644 --- a/app/controllers/api/v1/issues/issue_priorities_controller.rb +++ b/app/controllers/api/v1/issues/issue_priorities_controller.rb @@ -8,7 +8,7 @@ class Api::V1::Issues::IssuePrioritiesController < Api::V1::BaseController @priorities = kaminary_select_paginate(@priorities) end - def mp_index + def pm_index @priorities = IssuePriority.order(position: :asc) @priorities = @priorities.ransack(name_cont: params[:keyword]).result if params[:keyword] @priorities = kaminary_select_paginate(@priorities) diff --git a/app/controllers/api/v1/issues/issue_tags_controller.rb b/app/controllers/api/v1/issues/issue_tags_controller.rb index e77b5425..39534c31 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, :mp_index] + before_action :require_login, except: [:index, :pm_index] before_action :require_public_and_member_above, only: [:index] before_action :require_operate_above, only: [:create, :update, :destroy] @@ -13,7 +13,7 @@ class Api::V1::Issues::IssueTagsController < Api::V1::BaseController end end - def mp_index + def pm_index @issue_tags = IssueTag.init_mp_issues_tags render_ok(@issue_tags) end diff --git a/app/controllers/api/v1/issues/statues_controller.rb b/app/controllers/api/v1/issues/statues_controller.rb index 3e2a837e..c6495ee2 100644 --- a/app/controllers/api/v1/issues/statues_controller.rb +++ b/app/controllers/api/v1/issues/statues_controller.rb @@ -9,7 +9,7 @@ class Api::V1::Issues::StatuesController < Api::V1::BaseController @statues = kaminary_select_paginate(@statues) end - def mp_index + def pm_index @statues = IssueStatus.order("position asc") @statues = @statues.ransack(name_cont: params[:keyword]).result if params[:keyword].present? @statues = kaminary_select_paginate(@statues) diff --git a/app/models/issue.rb b/app/models/issue.rb index 4420ed18..14876da6 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -34,6 +34,8 @@ # ref_name :string(255) # branch_name :string(255) # blockchain_token_num :integer +# pm_project_id :integer +# pm_sprint_id :integer # # Indexes # diff --git a/config/routes/api.rb b/config/routes/api.rb index b6698996..41d33116 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -57,20 +57,20 @@ defaults format: :json do scope module: :issues do resources :issue_tags, except: [:new, :edit] do collection do - get :mp_index + get :pm_index end end resources :milestones, except: [:new, :edit] resources :issue_statues, only: [:index], controller: '/api/v1/issues/statues' do collection do - get :mp_index + get :pm_index end end resources :issue_authors, only: [:index], controller: '/api/v1/issues/authors' resources :issue_assigners, only: [:index], controller: '/api/v1/issues/assigners' resources :issue_priorities, only: [:index] do collection do - get :mp_index + get :pm_index end end end diff --git a/db/migrate/20231018034251_add_pm_project_id_and_pm_sprint_id_to_issues.rb b/db/migrate/20231018034251_add_pm_project_id_and_pm_sprint_id_to_issues.rb new file mode 100644 index 00000000..2c75693f --- /dev/null +++ b/db/migrate/20231018034251_add_pm_project_id_and_pm_sprint_id_to_issues.rb @@ -0,0 +1,6 @@ +class AddPmProjectIdAndPmSprintIdToIssues < ActiveRecord::Migration[5.2] + def change + add_column :issues, :pm_project_id , :integer + add_column :issues, :pm_sprint_id , :integer + end +end From 2c4253b04bbec3bf040dc7b3db5963009865172d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 18 Oct 2023 13:27:09 +0800 Subject: [PATCH 006/130] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E9=9D=9Epublic?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E6=9F=A5=E7=9C=8B=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 1 + app/models/identity_verification.rb | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 4949946c..cedefd1f 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -229,6 +229,7 @@ class AttachmentsController < ApplicationController end tip_exception(403, "您没有权限进入") if project.present? && !candown end + tip_exception(403, "您没有权限查看") if project.present? && !candown if @file.is_public == 0 && author_id != current_user.id end end diff --git a/app/models/identity_verification.rb b/app/models/identity_verification.rb index 3c8c88d9..6ea6e054 100644 --- a/app/models/identity_verification.rb +++ b/app/models/identity_verification.rb @@ -23,7 +23,10 @@ class IdentityVerification < ApplicationRecord belongs_to :user enum state: { "待审核": 0, "已通过": 1, "已拒绝": 2} - + after_create do + Attachment.where(id:[card_front,card_back,hold_card_front,hold_card_back]).update_all(is_public:0) + end + after_save do if state == "已通过" user.update(id_card_verify: true, website_permission: true) From 93dc10b6a5693e89582a8fe074059fd7249851cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 18 Oct 2023 13:38:09 +0800 Subject: [PATCH 007/130] fix attachment_candown --- app/controllers/attachments_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index cedefd1f..cfce8b7a 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -229,7 +229,7 @@ class AttachmentsController < ApplicationController end tip_exception(403, "您没有权限进入") if project.present? && !candown end - tip_exception(403, "您没有权限查看") if project.present? && !candown if @file.is_public == 0 && author_id != current_user.id + tip_exception(403, "您没有权限查看") if @file.is_public == 0 && @file.author_id != current_user.id end end From 467a4f0b94f481ba70a08a995b5c89d1c224c278 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 18 Oct 2023 15:16:14 +0800 Subject: [PATCH 008/130] =?UTF-8?q?fixed=20issue=E6=8F=8F=E8=BF=B0?= =?UTF-8?q?=E9=87=8C=E7=9A=84=E9=99=84=E4=BB=B6=E8=A7=A3=E6=9E=90=E5=85=B3?= =?UTF-8?q?=E8=81=94=EF=BC=8C=E5=A2=9E=E5=BC=BA=E9=99=84=E4=BB=B6=E8=AE=BF?= =?UTF-8?q?=E9=97=AE=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/issues_controller.rb | 3 ++- app/controllers/issues_controller.rb | 1 + app/models/issue.rb | 14 +++++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/issues_controller.rb b/app/controllers/api/v1/issues_controller.rb index 7238254d..ebba95e2 100644 --- a/app/controllers/api/v1/issues_controller.rb +++ b/app/controllers/api/v1/issues_controller.rb @@ -23,7 +23,8 @@ class Api::V1::IssuesController < Api::V1::BaseController before_action :load_issue, only: [:show, :update, :destroy] before_action :check_issue_operate_permission, only: [:update, :destroy] - def show + def show + @issue.associate_attachment_container @user_permission = current_user.present? && current_user.logged? && (@project.member?(current_user) || current_user.admin? || @issue.user == current_user) end diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 0015b518..cb7beb40 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -321,6 +321,7 @@ class IssuesController < ApplicationController @issue_user = @issue.user @issue_assign_to = @issue.get_assign_user @join_users = join_users(@issue) + @issue.associate_attachment_container #总耗时 # cost_time(@issue) diff --git a/app/models/issue.rb b/app/models/issue.rb index 14876da6..f568e028 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -94,7 +94,7 @@ class Issue < ApplicationRecord scope :closed, ->{where(status_id: 5)} scope :opened, ->{where.not(status_id: 5)} after_create :incre_project_common, :incre_user_statistic, :incre_platform_statistic - after_save :change_versions_count, :send_update_message_to_notice_system + after_save :change_versions_count, :send_update_message_to_notice_system, :associate_attachment_container after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic def incre_project_common @@ -222,6 +222,18 @@ class Issue < ApplicationRecord SendTemplateMessageJob.perform_later('IssueExpire', self.id) if Site.has_notice_menu? && self.due_date == Date.today + 1.days end + # 关附件到功能 + def associate_attachment_container + att_ids = [] + # 附件的格式为(/api/attachments/ + 附件id)的形式,提取出id进行附件属性关联,做附件访问权限控制 + att_ids += self.description.to_s.scan(/\(\/api\/attachments\/.+\)/).map{|s|s.match(/\d+/)[0]} + att_ids += self.description.to_s.scan(/\/api\/attachments\/.+\"/).map{|s|s.match(/\d+/)[0]} + att_ids += self.description.to_s.scan(/\/api\/attachments\/\d+/).map{|s|s.match(/\d+/)[0]} + if att_ids.present? + Attachment.where(id: att_ids).where(container_type: nil).update_all(container_id: self.id, container_type: self.class.name) + end + end + def to_builder Jbuilder.new do |issue| issue.(self, :id, :project_issues_index, :subject, :description, :branch_name, :start_date, :due_date) From e8b36f33edbc9c0cacf8a0e9cc953ebfddbac59c Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 18 Oct 2023 15:24:39 +0800 Subject: [PATCH 009/130] =?UTF-8?q?fixed=20issue=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E9=87=8C=E7=9A=84=E9=99=84=E4=BB=B6=E8=A7=A3=E6=9E=90=E5=85=B3?= =?UTF-8?q?=E8=81=94=EF=BC=8C=E5=A2=9E=E5=BC=BA=E9=99=84=E4=BB=B6=E8=AE=BF?= =?UTF-8?q?=E9=97=AE=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/journal.rb | 14 ++++++++++++++ .../api/v1/issues/journals/index.json.jbuilder | 1 + 2 files changed, 15 insertions(+) diff --git a/app/models/journal.rb b/app/models/journal.rb index ce69c1f3..3229ae88 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -53,10 +53,24 @@ class Journal < ApplicationRecord enum state: {opened: 0, resolved: 1, disabled: 2} + after_save :associate_attachment_container + def is_journal_detail? self.notes.blank? && self.journal_details.present? end + # 关附件到功能 + def associate_attachment_container + att_ids = [] + # 附件的格式为(/api/attachments/ + 附件id)的形式,提取出id进行附件属性关联,做附件访问权限控制 + att_ids += self.notes.to_s.scan(/\(\/api\/attachments\/.+\)/).map{|s|s.match(/\d+/)[0]} + att_ids += self.notes.to_s.scan(/\/api\/attachments\/.+\"/).map{|s|s.match(/\d+/)[0]} + att_ids += self.notes.to_s.scan(/\/api\/attachments\/\d+/).map{|s|s.match(/\d+/)[0]} + if att_ids.present? + Attachment.where(id: att_ids).where(container_type: nil).update_all(container_id: self.id, container_type: self.class.name) + end + end + def operate_content content = "" detail = self.journal_details.take diff --git a/app/views/api/v1/issues/journals/index.json.jbuilder b/app/views/api/v1/issues/journals/index.json.jbuilder index 49f94aa3..453c39c5 100644 --- a/app/views/api/v1/issues/journals/index.json.jbuilder +++ b/app/views/api/v1/issues/journals/index.json.jbuilder @@ -3,5 +3,6 @@ json.total_operate_journals_count @total_operate_journals_count json.total_comment_journals_count @total_comment_journals_count json.total_count @journals.total_count json.journals @journals do |journal| + journal.associate_attachment_container json.partial! "detail", journal: journal end \ No newline at end of file From 25df7c02d508b704b5976f121f7ae38abeed9f13 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 24 Oct 2023 20:41:02 +0800 Subject: [PATCH 010/130] =?UTF-8?q?fixed=20issue=E5=92=8C=E8=AF=84?= =?UTF-8?q?=E8=AE=BA=E9=87=8C=E7=9A=84=E9=99=84=E4=BB=B6=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E5=85=B3=E8=81=94=EF=BC=8C=E5=A2=9E=E5=BC=BA=E9=99=84=E4=BB=B6?= =?UTF-8?q?=E8=AE=BF=E9=97=AE=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6,?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E5=88=B0=20=E9=A1=B9=E7=9B=AE=E4=BF=9D?= =?UTF-8?q?=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 3 +++ app/models/issue.rb | 2 +- app/models/journal.rb | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index cfce8b7a..2bbccb49 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -224,6 +224,9 @@ class AttachmentsController < ApplicationController elsif @file.container.is_a?(Journal) project = @file.container.issue.project candown = project.is_public || (current_user.logged? && project.member?(current_user)) + elsif @file.container.is_a?(Project) + project = @file.container + candown = project.is_public || (current_user.logged? && project.member?(current_user)) else project = nil end diff --git a/app/models/issue.rb b/app/models/issue.rb index f568e028..a5fee95f 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -230,7 +230,7 @@ class Issue < ApplicationRecord att_ids += self.description.to_s.scan(/\/api\/attachments\/.+\"/).map{|s|s.match(/\d+/)[0]} att_ids += self.description.to_s.scan(/\/api\/attachments\/\d+/).map{|s|s.match(/\d+/)[0]} if att_ids.present? - Attachment.where(id: att_ids).where(container_type: nil).update_all(container_id: self.id, container_type: self.class.name) + Attachment.where(id: att_ids).where("container_type IS NULL OR container_type = 'Issue'").update_all(container_id: self.project_id, container_type: "Project") end end diff --git a/app/models/journal.rb b/app/models/journal.rb index 3229ae88..30cd9414 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -67,7 +67,7 @@ class Journal < ApplicationRecord att_ids += self.notes.to_s.scan(/\/api\/attachments\/.+\"/).map{|s|s.match(/\d+/)[0]} att_ids += self.notes.to_s.scan(/\/api\/attachments\/\d+/).map{|s|s.match(/\d+/)[0]} if att_ids.present? - Attachment.where(id: att_ids).where(container_type: nil).update_all(container_id: self.id, container_type: self.class.name) + Attachment.where(id: att_ids).where("container_type IS NULL OR container_type = 'Journal'").update_all(container_id: self.issue.project_id, container_type: "Project") end end From 9c02b8ba3145eaf2c8d71cde6a00ad0dc03f16e8 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 14 Nov 2023 16:53:29 +0800 Subject: [PATCH 011/130] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Aissue?= =?UTF-8?q?=E5=AD=90=E8=AF=84=E8=AE=BA=E5=85=B3=E8=81=94=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/journal.rb | 2 +- app/services/api/v1/issues/journals/list_service.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/journal.rb b/app/models/journal.rb index 30cd9414..e0553ad4 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -44,7 +44,7 @@ class Journal < ApplicationRecord 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 :first_ten_children_journals, -> { order(created_on: :asc).limit(20)}, 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)} diff --git a/app/services/api/v1/issues/journals/list_service.rb b/app/services/api/v1/issues/journals/list_service.rb index 486fa5d3..6d54e3b4 100644 --- a/app/services/api/v1/issues/journals/list_service.rb +++ b/app/services/api/v1/issues/journals/list_service.rb @@ -48,7 +48,7 @@ class Api::V1::Issues::Journals::ListService < ApplicationService @queried_journals = @queried_journals.where(notes: nil) end - @queried_journals = @queried_journals.includes(:journal_details, :user, :attachments, first_ten_children_journals: [:parent_journal, :reply_journal]) + @queried_journals = @queried_journals.includes(:journal_details, :user, :attachments, :children_journals) @queried_journals = @queried_journals.reorder("journals.#{sort_by} #{sort_direction}").distinct @queried_journals From 9e91427de093ab0dcce67347d56319c8d2c52e94 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 15 Nov 2023 08:43:00 +0800 Subject: [PATCH 012/130] =?UTF-8?q?fixed=20=E5=AE=B9=E9=94=99=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/project_rank/_detail.json.jbuilder | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/project_rank/_detail.json.jbuilder b/app/views/project_rank/_detail.json.jbuilder index d5b4b016..c083033e 100644 --- a/app/views/project_rank/_detail.json.jbuilder +++ b/app/views/project_rank/_detail.json.jbuilder @@ -3,8 +3,8 @@ owner_common = $redis_cache.hgetall("v2-owner-common:#{project_common["owner_id" json.id item[0] json.score item[1] json.name project_common["name"] -if project_common['identifier'].include?("/") - json.identifier project_common["identifier"].split('/')[1] +if project_common['identifier'].to_s.include?("/") + json.identifier project_common["identifier"].to_s.split('/')[1] json.owner do json.id nil json.type 'User' From 27bfeb5fc862de48da7716f05cf6490e2b71cdaa Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 15 Nov 2023 08:52:23 +0800 Subject: [PATCH 013/130] =?UTF-8?q?fixed=20=E8=AF=84=E8=AE=BA=E5=9B=9E?= =?UTF-8?q?=E5=A4=8D=E5=A2=9E=E5=8A=A0parent=5Fid=E7=B4=A2=E5=BC=95?= =?UTF-8?q?=EF=BC=8C=E8=A7=A3=E5=86=B3=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 --- db/migrate/20231115126452_add_journal_parent_id_index.rb | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 db/migrate/20231115126452_add_journal_parent_id_index.rb diff --git a/db/migrate/20231115126452_add_journal_parent_id_index.rb b/db/migrate/20231115126452_add_journal_parent_id_index.rb new file mode 100644 index 00000000..2ebca483 --- /dev/null +++ b/db/migrate/20231115126452_add_journal_parent_id_index.rb @@ -0,0 +1,5 @@ +class AddJournalParentIdIndex < ActiveRecord::Migration[5.2] + def change + add_index :journals, :parent_id + end +end From 9e4e30a495e5d895cf8b35d524c469e12c349251 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 16 Nov 2023 13:50:49 +0800 Subject: [PATCH 014/130] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Aurl=E8=BD=AC?= =?UTF-8?q?=E4=B9=89=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 2bbccb49..e5362710 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -39,7 +39,8 @@ class AttachmentsController < ApplicationController filepath, ref = url.split("/")[-1].split("?") url.gsub!(url.split("/")[-1], '') Rails.logger.info("url===#{url}") - request_url = [domain, api_url, URI.encode(url), CGI.escape(filepath), "?ref=#{CGI.escape(ref.split('ref=')[1])}&access_token=#{User.where(admin: true).take&.gitea_token}"].join + Rails.logger.info(filepath) + request_url = [domain, api_url, URI.encode(url), URI.escape(filepath), "?ref=#{URI.escape(ref.split('ref=')[1])}&access_token=#{User.where(admin: true).take&.gitea_token}"].join Rails.logger.info("request_url===#{request_url}") response = Faraday.get(request_url) filename = filepath From 3833816a0a0ac7d1deb8989203e24f31131cdbdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 29 Nov 2023 15:11:41 +0800 Subject: [PATCH 015/130] update issue order by --- app/services/api/v1/issues/list_service.rb | 23 ++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index b6ef1178..8f32cfe6 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -6,8 +6,8 @@ class Api::V1::Issues::ListService < ApplicationService 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 - validates :category, inclusion: {in: %w(all opened closed), message: "请输入正确的Category"} - validates :participant_category, inclusion: {in: %w(all aboutme authoredme assignedme atme), message: "请输入正确的ParticipantCategory"} + validates :category, inclusion: {in: %w(all opened closed), message: '请输入正确的Category'} + validates :participant_category, inclusion: {in: %w(all aboutme authoredme assignedme atme), message: '请输入正确的ParticipantCategory'} validates :sort_by, inclusion: {in: ['issues.created_on', 'issues.updated_on', 'issues.blockchain_token_num', 'issue_priorities.position'], message: '请输入正确的SortBy'}, allow_blank: true validates :sort_direction, inclusion: {in: %w(asc desc), message: '请输入正确的SortDirection'}, allow_blank: true validates :current_user, presence: true @@ -19,7 +19,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].present? ? params[:issue_tag_ids].split(",") : [] + @issue_tag_ids = params[:issue_tag_ids].present? ? params[:issue_tag_ids].split(',') : [] @milestone_id = params[:milestone_id] @assigner_id = params[:assigner_id] @status_id = params[:status_id] @@ -31,7 +31,7 @@ class Api::V1::Issues::ListService < ApplicationService end def call - raise Error, errors.full_messages.join(", ") unless valid? + raise Error, errors.full_messages.join(', ') unless valid? # begin issue_query_data @@ -60,7 +60,7 @@ class Api::V1::Issues::ListService < ApplicationService issues = issues.where(author_id: author_id) if author_id.present? # issue_tag_ids - issues = issues.ransack(issue_tags_value_cont: issue_tag_ids.sort!.join(",")).result unless issue_tag_ids.blank? + issues = issues.ransack(issue_tags_value_cont: issue_tag_ids.sort!.join(',')).result unless issue_tag_ids.blank? # milestone_id issues = issues.where(fixed_version_id: milestone_id) if milestone_id.present? @@ -72,14 +72,14 @@ class Api::V1::Issues::ListService < ApplicationService issues = issues.where(status_id: status_id) if status_id.present? && category != 'closed' if begin_date&.present? || end_date&.present? - issues = issues.where("issues.created_on between ? and ?", begin_date&.present? ? begin_date.to_time : Time.now.beginning_of_day, end_date&.present? ? end_date.to_time.end_of_day : Time.now.end_of_day) + issues = issues.where('issues.created_on between ? and ?', begin_date&.present? ? begin_date.to_time : Time.now.beginning_of_day, end_date&.present? ? end_date.to_time.end_of_day : Time.now.end_of_day) end # keyword issues = issues.ransack(id_or_project_issues_index_eq: keyword).result.or(issues.ransack(subject_or_description_cont: keyword).result) if keyword.present? @total_issues_count = issues.distinct.size - @closed_issues_count = issues.closed.distinct.size + @closed_issues_count = issues.closed.distinct.size @opened_issues_count = issues.opened.distinct.size case category @@ -88,13 +88,16 @@ class Api::V1::Issues::ListService < ApplicationService when 'opened' issues = issues.opened end - if only_name.present? scope = issues.select(:id, :subject, :project_issues_index, :updated_on, :created_on) scope = scope.reorder("#{sort_by} #{sort_direction}").distinct - else + else scope = issues.includes(:priority, :issue_status, :user, :show_assigners, :show_issue_tags, :version, :comment_journals) - scope = scope.reorder("#{sort_by} #{sort_direction}").distinct + scope = if sort_by == 'issue_priorities.position' + scope.reorder("issue_priorities.position #{sort_direction}, issues.created_on DESC").distinct + else + scope.reorder("#{sort_by} #{sort_direction}").distinct + end end @queried_issues = scope From 21640fe5e67ef221f6d6277f0ff21724131c2e1e Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 1 Dec 2023 09:48:08 +0800 Subject: [PATCH 016/130] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Aissue=20stat?= =?UTF-8?q?us=E5=92=8Cpriority=E5=88=9D=E5=A7=8B=E5=8C=96=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/issues/issue_priorities_controller.rb | 2 +- app/controllers/api/v1/issues/statues_controller.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/issues/issue_priorities_controller.rb b/app/controllers/api/v1/issues/issue_priorities_controller.rb index 2df1288f..f31c92ae 100644 --- a/app/controllers/api/v1/issues/issue_priorities_controller.rb +++ b/app/controllers/api/v1/issues/issue_priorities_controller.rb @@ -3,7 +3,7 @@ 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 = IssuePriority.where.not(name: '立刻').order(position: :asc) @priorities = @priorities.ransack(name_cont: params[:keyword]).result if params[:keyword] @priorities = kaminary_select_paginate(@priorities) end diff --git a/app/controllers/api/v1/issues/statues_controller.rb b/app/controllers/api/v1/issues/statues_controller.rb index c6495ee2..737f1b38 100644 --- a/app/controllers/api/v1/issues/statues_controller.rb +++ b/app/controllers/api/v1/issues/statues_controller.rb @@ -4,7 +4,7 @@ class Api::V1::Issues::StatuesController < Api::V1::BaseController # 状态列表 def index - @statues = IssueStatus.order("position asc") + @statues = IssueStatus.where.not(name: '反馈').order("position asc") @statues = @statues.ransack(name_cont: params[:keyword]).result if params[:keyword].present? @statues = kaminary_select_paginate(@statues) end From d7976766390747482e535d71fac66a0f3bd77bf7 Mon Sep 17 00:00:00 2001 From: kingchan Date: Fri, 1 Dec 2023 09:52:32 +0800 Subject: [PATCH 017/130] change created on to updated_on for issue list service --- 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 8f32cfe6..820f708e 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -94,7 +94,7 @@ class Api::V1::Issues::ListService < ApplicationService else scope = issues.includes(:priority, :issue_status, :user, :show_assigners, :show_issue_tags, :version, :comment_journals) scope = if sort_by == 'issue_priorities.position' - scope.reorder("issue_priorities.position #{sort_direction}, issues.created_on DESC").distinct + scope.reorder("issue_priorities.position #{sort_direction}, issues.updated_on DESC").distinct else scope.reorder("#{sort_by} #{sort_direction}").distinct end From c63c0cc636515f2735fe1c62ee29d7fe2ab4a5ed Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 1 Dec 2023 14:59:13 +0800 Subject: [PATCH 018/130] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Aissue=20stat?= =?UTF-8?q?us=E6=9F=A5=E8=AF=A2=E4=B8=8D=E4=BD=BF=E7=94=A8where.not?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/issues/issue_priorities_controller.rb | 2 +- app/controllers/api/v1/issues/statues_controller.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/issues/issue_priorities_controller.rb b/app/controllers/api/v1/issues/issue_priorities_controller.rb index f31c92ae..2df1288f 100644 --- a/app/controllers/api/v1/issues/issue_priorities_controller.rb +++ b/app/controllers/api/v1/issues/issue_priorities_controller.rb @@ -3,7 +3,7 @@ class Api::V1::Issues::IssuePrioritiesController < Api::V1::BaseController before_action :require_public_and_member_above, only: [:index] def index - @priorities = IssuePriority.where.not(name: '立刻').order(position: :asc) + @priorities = IssuePriority.order(position: :asc) @priorities = @priorities.ransack(name_cont: params[:keyword]).result if params[:keyword] @priorities = kaminary_select_paginate(@priorities) end diff --git a/app/controllers/api/v1/issues/statues_controller.rb b/app/controllers/api/v1/issues/statues_controller.rb index 737f1b38..c6495ee2 100644 --- a/app/controllers/api/v1/issues/statues_controller.rb +++ b/app/controllers/api/v1/issues/statues_controller.rb @@ -4,7 +4,7 @@ class Api::V1::Issues::StatuesController < Api::V1::BaseController # 状态列表 def index - @statues = IssueStatus.where.not(name: '反馈').order("position asc") + @statues = IssueStatus.order("position asc") @statues = @statues.ransack(name_cont: params[:keyword]).result if params[:keyword].present? @statues = kaminary_select_paginate(@statues) end From 98770ca47e1ff887c96fdab5165b35631fc4a45a Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 1 Dec 2023 17:04:34 +0800 Subject: [PATCH 019/130] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=BA=AF=E6=BA=90=E6=B3=A8=E5=86=8C=E5=90=8E=E9=A1=BB?= =?UTF-8?q?=E9=87=8D=E6=96=B0=E8=B0=83=E7=94=A8=E7=99=BB=E5=BD=95=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/models/trace_user.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/trace_user.rb b/app/models/trace_user.rb index 69198706..6e032e9f 100644 --- a/app/models/trace_user.rb +++ b/app/models/trace_user.rb @@ -43,8 +43,9 @@ class TraceUser < ApplicationRecord def build_token return if username.blank? || password.blank? || unit.blank? || email.blank? || name.blank? - response = Trace::AddUserService.call(username, password, unit, telnumber, email, name) - self.token = response[1]['token'] + response1 = Trace::AddUserService.call(username, password, unit, telnumber, email, name) + response2 = Trace::LoginService.call(username, password) + self.token = response2[1]['token'] self.expired_at = Time.now + 1.hours end From b2250db79aa7fd31328654275bbe496d8d524908 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 7 Dec 2023 09:50:09 +0800 Subject: [PATCH 020/130] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E6=A0=87=E7=AD=BE=E8=AF=A6=E6=83=85api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/tags_controller.rb | 7 ++- .../api/v1/projects/tags/get_service.rb | 54 +++++++++++++++++++ .../_simple_gitea_index_detail.json.jbuilder | 6 ++- .../api/v1/projects/tags/show.json.jbuilder | 1 + config/routes/api.rb | 5 +- 5 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 app/services/api/v1/projects/tags/get_service.rb create mode 100644 app/views/api/v1/projects/tags/show.json.jbuilder diff --git a/app/controllers/api/v1/projects/tags_controller.rb b/app/controllers/api/v1/projects/tags_controller.rb index b87d4842..44fdd9ba 100644 --- a/app/controllers/api/v1/projects/tags_controller.rb +++ b/app/controllers/api/v1/projects/tags_controller.rb @@ -1,10 +1,13 @@ class Api::V1::Projects::TagsController < Api::V1::BaseController - before_action :require_public_and_member_above, only: [:index] + before_action :require_public_and_member_above, only: [:index, :show] 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 + + def show + @result_object = Api::V1::Projects::Tags::GetService.call(@project, params[:name], current_user&.gitea_token) end before_action :require_operate_above, only: [:destroy] diff --git a/app/services/api/v1/projects/tags/get_service.rb b/app/services/api/v1/projects/tags/get_service.rb new file mode 100644 index 00000000..740f18d0 --- /dev/null +++ b/app/services/api/v1/projects/tags/get_service.rb @@ -0,0 +1,54 @@ +class Api::V1::Projects::Tags::GetService < ApplicationService + include ActiveModel::Model + + attr_reader :project, :token, :owner, :repo, :tag_name + attr_accessor :gitea_data + + validates :tag_name, presence: true + + def initialize(project, tag_name, token=nil) + @project = project + @owner = project&.owner&.login + @repo = project&.identifier + @tag_name = tag_name.to_s + @token = token + Rails.logger.info project&.owner&.login + Rails.logger.info project&.identifier + Rails.logger.info tag_name + Rails.logger.info token + end + + def call + + raise Error, errors.full_messages.join(",") unless valid? + + check_tag_exist + + load_gitea_data + + gitea_data + rescue + raise Error, "服务器错误,请联系系统管理员!" + end + + private + def request_params + params = { + access_token: token + } + + params + end + + def load_gitea_data + @gitea_data = $gitea_hat_client.get_repos_tags_by_owner_repo_tag(owner, repo, tag_name, {query: request_params}) rescue nil + raise Error, '获取标签失败!' unless @gitea_data.is_a?(Hash) + end + + def check_tag_exist + 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 +end \ No newline at end of file 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 460b56f5..32b384fb 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 @@ -4,7 +4,11 @@ if tag.present? && tag.is_a?(Hash) json.zipball_url render_zip_url(@owner, @repository, tag['name']) json.tarball_url render_tar_url(@owner, @repository, tag['name']) json.tagger do - json.partial! 'api/v1/users/commit_user', user: render_cache_commit_author(tag['tagger']), name: tag['tagger']['name'] + if tag['tagger'].present? + json.partial! 'api/v1/users/commit_user', user: render_cache_commit_author(tag['tagger']), name: tag['tagger']['name'] + else + json.nil! + end end json.time_ago time_from_now(tag['tagger']['date'].to_time) json.created_at_unix tag['tagger']['date'].to_time.to_i diff --git a/app/views/api/v1/projects/tags/show.json.jbuilder b/app/views/api/v1/projects/tags/show.json.jbuilder new file mode 100644 index 00000000..a0e45fb7 --- /dev/null +++ b/app/views/api/v1/projects/tags/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "api/v1/projects/tags/simple_gitea_index_detail", tag: @result_object diff --git a/config/routes/api.rb b/config/routes/api.rb index 20c56138..f3fa24de 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -85,8 +85,9 @@ defaults format: :json do end match 'branches/*name', to: "branches#destroy", via: :all - resources :tags, param: :name, only: [:index, :destroy] - match 'tags/*name', to: "tags#destroy", via: :all + resources :tags, param: :name, only: [:index, :show, :destroy] + delete 'tags/*name', to: "tags#destroy", via: :all + get 'tags/*name', to: "tags#show", via: :all resources :commits, only: [:index] resources :code_stats, only: [:index] From 9ac061f2a963f38b254fa179229e51e10445fea8 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 11 Dec 2023 09:17:43 +0800 Subject: [PATCH 021/130] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Agemfile?= 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 8051448e..3f165215 100644 --- a/Gemfile +++ b/Gemfile @@ -143,4 +143,4 @@ gem 'doorkeeper' gem 'doorkeeper-jwt' -gem 'gitea-client', '~> 1.4.2' +gem 'gitea-client', '~> 1.4.3' From 0cb38bce4f9229e17782ed18d2b2edc42acdfb6b Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 11 Dec 2023 16:07:24 +0800 Subject: [PATCH 022/130] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=A0=B9?= =?UTF-8?q?=E6=8D=AEid=E6=9F=A5=E8=AF=A2=E7=96=91=E4=BF=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/issues_controller.rb | 17 +++++++++++++++-- .../api/v1/issues/show_by_id.json.jbuilder | 2 ++ config/routes/api.rb | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 app/views/api/v1/issues/show_by_id.json.jbuilder diff --git a/app/controllers/api/v1/issues_controller.rb b/app/controllers/api/v1/issues_controller.rb index ebba95e2..76185a16 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_login, except: [:index, :show] - before_action :require_public_and_member_above, only: [:index, :show, :create, :update, :destroy] + before_action :require_login, except: [:index, :show, :show_by_id] + before_action :require_public_and_member_above, only: [:index, :show, :show_by_id, :create, :update, :destroy] before_action :require_operate_above, only: [:batch_update, :batch_destroy] def index @@ -22,6 +22,12 @@ class Api::V1::IssuesController < Api::V1::BaseController before_action :load_issue, only: [:show, :update, :destroy] before_action :check_issue_operate_permission, only: [:update, :destroy] + before_action :load_issue_by_id, only: [:show_by_id] + + def show_by_id + @issue.associate_attachment_container + @user_permission = current_user.present? && current_user.logged? && (@project.member?(current_user) || current_user.admin? || @issue.user == current_user) + end def show @issue.associate_attachment_container @@ -70,6 +76,13 @@ class Api::V1::IssuesController < Api::V1::BaseController end end + def load_issue_by_id + @issue = Issue.find_by_id(params[:index]) + if @issue.blank? + render_not_found("疑修不存在!") + end + end + def load_issues return render_error("请输入正确的ID数组!") unless params[:ids].is_a?(Array) params[:ids].each do |id| diff --git a/app/views/api/v1/issues/show_by_id.json.jbuilder b/app/views/api/v1/issues/show_by_id.json.jbuilder new file mode 100644 index 00000000..55028fc6 --- /dev/null +++ b/app/views/api/v1/issues/show_by_id.json.jbuilder @@ -0,0 +1,2 @@ +json.partial! "api/v1/issues/detail", locals: {issue: @issue} +json.user_permission @user_permission diff --git a/config/routes/api.rb b/config/routes/api.rb index 4478af38..baa66412 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -47,6 +47,7 @@ defaults format: :json do end member do + get :show_by_id resources :journals, module: :issues, only: [:index, :create, :update, :destroy] do member do get :children_journals From d74901cffa9a5a0a065d6aee6768c4d835c6faec Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 12 Dec 2023 14:31:21 +0800 Subject: [PATCH 023/130] =?UTF-8?q?fixed=20=E8=A7=A3=E5=86=B3=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E9=97=AE=E9=A2=98=E8=AE=BF=E9=97=AE=E9=99=84=E4=BB=B6?= =?UTF-8?q?=EF=BC=8Cid=E6=94=B9=E4=B8=BAuuid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 6 +- app/helpers/application_helper.rb | 2 +- app/models/attachment.rb | 88 ++++++++++--------- app/models/issue.rb | 12 ++- app/models/journal.rb | 10 +++ .../api/v1/issues/concerns/checkable.rb | 2 +- .../api/v1/issues/concerns/loadable.rb | 2 +- app/views/attachments/create.json.jbuilder | 9 +- 8 files changed, 82 insertions(+), 49 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index e5362710..bf8c870a 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -94,6 +94,7 @@ class AttachmentsController < ApplicationController @attachment.author_id = current_user.id @attachment.disk_directory = month_folder @attachment.cloud_url = remote_path + @attachment.uuid = SecureRandom.uuid @attachment.save! else logger.info "文件已存在,id = #{@attachment.id}, filename = #{@attachment.filename}" @@ -147,8 +148,9 @@ class AttachmentsController < ApplicationController if params[:type] == 'history' AttachmentHistory.find params[:id] else - Attachment.find params[:id] + Attachment.find_by(id: params[:id]) || Attachment.find_by(uuid: params[:id]) end + tip_exception(404, "您访问的页面不存在或已被删除") if @file.blank? end def delete_file(file_path) @@ -218,7 +220,7 @@ class AttachmentsController < ApplicationController def attachment_candown unless current_user.admin? || current_user.business? candown = true - if @file.container + if @file.container && @file.uuid.nil? if @file.container.is_a?(Issue) project = @file.container.project candown = project.is_public || (current_user.logged? && project.member?(current_user)) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 93645247..5d558242 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -299,7 +299,7 @@ module ApplicationHelper end def download_url attachment,options={} - attachment_path(attachment,options) + attachment&.uuid.present? ? attachment_path(attachment.uuid,options) : attachment_path(attachment,options) end # 耗时:天、小时、分、秒 diff --git a/app/models/attachment.rb b/app/models/attachment.rb index f79aca15..defc7366 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -1,44 +1,45 @@ -# == Schema Information -# -# Table name: attachments -# -# id :integer not null, primary key -# container_id :integer -# container_type :string(30) -# filename :string(255) default(""), not null -# disk_filename :string(255) default(""), not null -# filesize :integer default("0"), not null -# content_type :string(255) default("") -# digest :string(60) default(""), not null -# downloads :integer default("0"), not null -# author_id :integer default("0"), not null -# created_on :datetime -# description :text(65535) -# disk_directory :string(255) -# attachtype :integer default("1") -# is_public :integer default("1") -# copy_from :integer -# quotes :integer default("0") -# is_publish :integer default("1") -# publish_time :datetime -# resource_bank_id :integer -# unified_setting :boolean default("1") -# cloud_url :string(255) default("") -# course_second_category_id :integer default("0") -# delay_publish :boolean default("0") -# memo_image :boolean default("0") -# extra_type :integer default("0") -# -# Indexes -# -# index_attachments_on_author_id (author_id) -# index_attachments_on_container_id_and_container_type (container_id,container_type) -# index_attachments_on_course_second_category_id (course_second_category_id) -# index_attachments_on_created_on (created_on) -# index_attachments_on_is_public (is_public) -# index_attachments_on_quotes (quotes) -# - +# == Schema Information +# +# Table name: attachments +# +# id :integer not null, primary key +# container_id :integer +# container_type :string(30) +# filename :string(255) default(""), not null +# disk_filename :string(255) default(""), not null +# filesize :integer default("0"), not null +# content_type :string(255) default("") +# digest :string(60) default(""), not null +# downloads :integer default("0"), not null +# author_id :integer default("0"), not null +# created_on :datetime +# description :text(65535) +# disk_directory :string(255) +# attachtype :integer default("1") +# is_public :integer default("1") +# copy_from :integer +# quotes :integer default("0") +# is_publish :integer default("1") +# publish_time :datetime +# resource_bank_id :integer +# unified_setting :boolean default("1") +# cloud_url :string(255) default("") +# course_second_category_id :integer default("0") +# delay_publish :boolean default("0") +# memo_image :boolean default("0") +# extra_type :integer default("0") +# uuid :string(255) +# +# Indexes +# +# index_attachments_on_author_id (author_id) +# index_attachments_on_container_id_and_container_type (container_id,container_type) +# index_attachments_on_course_second_category_id (course_second_category_id) +# index_attachments_on_created_on (created_on) +# index_attachments_on_is_public (is_public) +# index_attachments_on_quotes (quotes) +# + @@ -97,6 +98,11 @@ class Attachment < ApplicationRecord downloads end + def generate_uuid + self.uuid = uuid || SecureRandom.uuid + save! + end + def quotes_count quotes.nil? ? 0 : quotes end diff --git a/app/models/issue.rb b/app/models/issue.rb index a5fee95f..93d30b5d 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -224,13 +224,23 @@ class Issue < ApplicationRecord # 关附件到功能 def associate_attachment_container + return if self.project_id == 0 att_ids = [] # 附件的格式为(/api/attachments/ + 附件id)的形式,提取出id进行附件属性关联,做附件访问权限控制 att_ids += self.description.to_s.scan(/\(\/api\/attachments\/.+\)/).map{|s|s.match(/\d+/)[0]} att_ids += self.description.to_s.scan(/\/api\/attachments\/.+\"/).map{|s|s.match(/\d+/)[0]} att_ids += self.description.to_s.scan(/\/api\/attachments\/\d+/).map{|s|s.match(/\d+/)[0]} if att_ids.present? - Attachment.where(id: att_ids).where("container_type IS NULL OR container_type = 'Issue'").update_all(container_id: self.project_id, container_type: "Project") + Attachment.where(id: att_ids).where("container_type IS NULL OR container_type = 'Issue'").update_all(container_id: self.project_id, container_type: 'Project') + end + + att_ids2 = [] + # uuid_regex= /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/ + # 附件的格式为(/api/attachments/ + uuid)的形式,提取出id进行附件属性关联,做附件访问权限控制 + att_ids2 += self.description.to_s.scan(/\(\/api\/attachments\/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\)/).map{|s|s.match(/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/)[0]} + att_ids2 += self.description.to_s.scan(/\/api\/attachments\/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/).map{|s|s.match(/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/)[0]} + if att_ids2.present? + Attachment.where(uuid: att_ids2).where("container_type IS NULL OR container_type = 'Issue'").update_all(container_id: self.project_id, container_type: 'Project') end end diff --git a/app/models/journal.rb b/app/models/journal.rb index e0553ad4..dad60cd7 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -61,6 +61,7 @@ class Journal < ApplicationRecord # 关附件到功能 def associate_attachment_container + return if self.issue&.project_id.to_i == 0 att_ids = [] # 附件的格式为(/api/attachments/ + 附件id)的形式,提取出id进行附件属性关联,做附件访问权限控制 att_ids += self.notes.to_s.scan(/\(\/api\/attachments\/.+\)/).map{|s|s.match(/\d+/)[0]} @@ -69,6 +70,15 @@ class Journal < ApplicationRecord if att_ids.present? Attachment.where(id: att_ids).where("container_type IS NULL OR container_type = 'Journal'").update_all(container_id: self.issue.project_id, container_type: "Project") end + + att_ids2 = [] + # uuid_regex= /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/ + # 附件的格式为(/api/attachments/ + uuid)的形式,提取出id进行附件属性关联,做附件访问权限控制 + att_ids2 += self.notes.to_s.scan(/\(\/api\/attachments\/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\)/).map{|s|s.match(/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/)[0]} + att_ids2 += self.notes.to_s.scan(/\/api\/attachments\/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/).map{|s|s.match(/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/)[0]} + if att_ids2.present? + Attachment.where(uuid: att_ids).where("container_type IS NULL OR container_type = 'Journal'").update_all(container_id: self.issue.project_id, container_type: "Project") + end end def operate_content diff --git a/app/services/api/v1/issues/concerns/checkable.rb b/app/services/api/v1/issues/concerns/checkable.rb index b19c245e..58fc6dc6 100644 --- a/app/services/api/v1/issues/concerns/checkable.rb +++ b/app/services/api/v1/issues/concerns/checkable.rb @@ -31,7 +31,7 @@ module Api::V1::Issues::Concerns::Checkable def check_attachments (attachment_ids) raise ApplicationService::Error, "请输入正确的附件ID数组!" unless attachment_ids.is_a?(Array) attachment_ids.each do |aid| - raise ApplicationService::Error, "请输入正确的附件ID!" unless Attachment.exists?(id: aid) + raise ApplicationService::Error, "请输入正确的附件ID!" unless Attachment.exists?(id: aid) || Attachment.exists?(uuid: aid) end end diff --git a/app/services/api/v1/issues/concerns/loadable.rb b/app/services/api/v1/issues/concerns/loadable.rb index df30042e..ffd5ff4a 100644 --- a/app/services/api/v1/issues/concerns/loadable.rb +++ b/app/services/api/v1/issues/concerns/loadable.rb @@ -9,7 +9,7 @@ module Api::V1::Issues::Concerns::Loadable end def load_attachments(attachment_ids) - @attachments = Attachment.where(id: attachment_ids) + @attachments = Attachment.where(id: attachment_ids).or(Attachment.where(uuid: attachment_ids)) end def load_atme_receivers(receivers_login) diff --git a/app/views/attachments/create.json.jbuilder b/app/views/attachments/create.json.jbuilder index 3c0ef355..3b12193c 100644 --- a/app/views/attachments/create.json.jbuilder +++ b/app/views/attachments/create.json.jbuilder @@ -1,2 +1,7 @@ -json.id @attachment.id -json.filesize @attachment.filesize +json.id @attachment.uuid +json.title @attachment.title +json.filesize number_to_human_size(@attachment.filesize) +json.is_pdf @attachment.is_pdf? +json.url Rails.application.config_for(:configuration)['platform_url'] + (@attachment.is_pdf? ? download_url(@attachment,disposition:"inline") : download_url(@attachment)).to_s +json.created_on @attachment.created_on.strftime("%Y-%m-%d %H:%M") +json.content_type @attachment.content_type From 852d43017840ad1b85e6bf5f18fa81baab636417 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 12 Dec 2023 15:02:03 +0800 Subject: [PATCH 024/130] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=A0=87=E7=AD=BE=E8=AF=A6=E6=83=85=E7=89=B9=E6=AE=8A?= =?UTF-8?q?=E7=AC=A6=E5=8F=B7=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/projects/tags/get_service.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/app/services/api/v1/projects/tags/get_service.rb b/app/services/api/v1/projects/tags/get_service.rb index 740f18d0..bfceab4c 100644 --- a/app/services/api/v1/projects/tags/get_service.rb +++ b/app/services/api/v1/projects/tags/get_service.rb @@ -12,10 +12,6 @@ class Api::V1::Projects::Tags::GetService < ApplicationService @repo = project&.identifier @tag_name = tag_name.to_s @token = token - Rails.logger.info project&.owner&.login - Rails.logger.info project&.identifier - Rails.logger.info tag_name - Rails.logger.info token end def call @@ -27,8 +23,6 @@ class Api::V1::Projects::Tags::GetService < ApplicationService load_gitea_data gitea_data - rescue - raise Error, "服务器错误,请联系系统管理员!" end private @@ -41,7 +35,7 @@ class Api::V1::Projects::Tags::GetService < ApplicationService end def load_gitea_data - @gitea_data = $gitea_hat_client.get_repos_tags_by_owner_repo_tag(owner, repo, tag_name, {query: request_params}) rescue nil + @gitea_data = $gitea_hat_client.get_repos_tags_by_owner_repo_tag(owner, repo, URI.escape(tag_name), {query: request_params}) rescue nil raise Error, '获取标签失败!' unless @gitea_data.is_a?(Hash) end From 8264717017d6ab875931057e6dbe1c8ac7d76f0d Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 12 Dec 2023 15:20:52 +0800 Subject: [PATCH 025/130] =?UTF-8?q?fixed=20=E8=A7=A3=E5=86=B3=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E9=97=AE=E9=A2=98=E8=AE=BF=E9=97=AE=E9=99=84=E4=BB=B6?= =?UTF-8?q?=EF=BC=8Cid=E6=94=B9=E4=B8=BAuuid,migrate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20231121084405_add_uuid_to_attachments.rb | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 db/migrate/20231121084405_add_uuid_to_attachments.rb diff --git a/db/migrate/20231121084405_add_uuid_to_attachments.rb b/db/migrate/20231121084405_add_uuid_to_attachments.rb new file mode 100644 index 00000000..5d0e2ba0 --- /dev/null +++ b/db/migrate/20231121084405_add_uuid_to_attachments.rb @@ -0,0 +1,5 @@ +class AddUuidToAttachments < ActiveRecord::Migration[5.2] + def change + add_column :attachments, :uuid, :string, index: true + end +end From 9a0809e45babd52ed599dfd227aacc554b351654 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 12 Dec 2023 15:33:48 +0800 Subject: [PATCH 026/130] =?UTF-8?q?fixed=20=E5=8F=91=E8=A1=8C=E7=89=88?= =?UTF-8?q?=E9=99=84=E4=BB=B6=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/version_releases_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/version_releases_controller.rb b/app/controllers/version_releases_controller.rb index 76a214d0..62724c12 100644 --- a/app/controllers/version_releases_controller.rb +++ b/app/controllers/version_releases_controller.rb @@ -152,11 +152,12 @@ class VersionReleasesController < ApplicationController def create_attachments(attachment_ids, target) attachment_ids.each do |id| - attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id) + attachment = Attachment.select(:id, :container_id, :container_type).where(id: id).or(Attachment.where(uuid: id))&.first unless attachment.blank? attachment.container = target attachment.author_id = current_user.id attachment.description = "" + attachment.uuid = SecureRandom.uuid attachment.save end end From de1266ba6c3e3f98ab2a6420128d62c490bea461 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 12 Dec 2023 16:41:02 +0800 Subject: [PATCH 027/130] =?UTF-8?q?fixed=20=E8=A7=A3=E5=86=B3=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E9=97=AE=E9=A2=98=E8=AE=BF=E9=97=AE=E9=99=84=E4=BB=B6?= =?UTF-8?q?=EF=BC=8Cid=E6=94=B9=E4=B8=BAuuid=EF=BC=8C=E5=85=B3=E8=81=94?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/issues_controller.rb | 4 ++-- app/controllers/journals_controller.rb | 2 +- app/controllers/version_releases_controller.rb | 2 +- app/models/attachment.rb | 1 + app/models/identity_verification.rb | 16 ++++++++-------- app/models/journal.rb | 6 +++--- app/services/api/v1/issues/concerns/checkable.rb | 4 ++-- app/services/api/v1/issues/concerns/loadable.rb | 2 +- ...0231212012107_change_identity_verification.rb | 8 ++++++++ 9 files changed, 27 insertions(+), 18 deletions(-) create mode 100644 db/migrate/20231212012107_change_identity_verification.rb diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index cb7beb40..84219b89 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -139,7 +139,7 @@ class IssuesController < ApplicationController SendTemplateMessageJob.perform_later('ProjectIssue', current_user.id, @issue&.id) if Site.has_notice_menu? if params[:attachment_ids].present? params[:attachment_ids].each do |id| - attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id) + attachment = Attachment.where_id_or_uuid(id).select(:id, :container_id, :container_type)&.first unless attachment.blank? attachment.container = @issue attachment.author_id = current_user.id @@ -232,7 +232,7 @@ class IssuesController < ApplicationController if issue_files.present? change_files = true issue_files.each do |id| - attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id) + attachment = Attachment.where_id_or_uuid(id).select(:id, :container_id, :container_type)&.first unless attachment.blank? attachment.container = @issue attachment.author_id = current_user.id diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rb index 8f785756..6b9abd5c 100644 --- a/app/controllers/journals_controller.rb +++ b/app/controllers/journals_controller.rb @@ -35,7 +35,7 @@ class JournalsController < ApplicationController if journal.save if params[:attachment_ids].present? params[:attachment_ids].each do |id| - attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id) + attachment = Attachment.where_id_or_uuid(id).select(:id, :container_id, :container_type)&.first unless attachment.blank? attachment.container = journal attachment.author_id = current_user.id diff --git a/app/controllers/version_releases_controller.rb b/app/controllers/version_releases_controller.rb index 62724c12..ed608873 100644 --- a/app/controllers/version_releases_controller.rb +++ b/app/controllers/version_releases_controller.rb @@ -152,7 +152,7 @@ class VersionReleasesController < ApplicationController def create_attachments(attachment_ids, target) attachment_ids.each do |id| - attachment = Attachment.select(:id, :container_id, :container_type).where(id: id).or(Attachment.where(uuid: id))&.first + attachment = Attachment.where_id_or_uuid(id).select(:id, :container_id, :container_type)&.first unless attachment.blank? attachment.container = target attachment.author_id = current_user.id diff --git a/app/models/attachment.rb b/app/models/attachment.rb index defc7366..49124a22 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -69,6 +69,7 @@ class Attachment < ApplicationRecord scope :simple_columns, -> { select(:id, :filename, :filesize, :created_on, :cloud_url, :author_id, :content_type, :container_type, :container_id) } scope :search_by_container, -> (ids) {where(container_id: ids)} scope :unified_setting, -> {where("unified_setting = ? ", 1)} + scope :where_id_or_uuid, -> (id) { where("id = ? or uuid= ? ", id, id) } validates_length_of :description, maximum: 100, message: "不能超过100个字符" diff --git a/app/models/identity_verification.rb b/app/models/identity_verification.rb index 6ea6e054..8673a4a6 100644 --- a/app/models/identity_verification.rb +++ b/app/models/identity_verification.rb @@ -6,10 +6,10 @@ # user_id :integer not null # number :string(255) not null # name :string(255) not null -# card_front :integer -# card_back :integer -# hold_card_front :integer -# hold_card_back :integer +# card_front :string(255) +# card_back :string(255) +# hold_card_front :string(255) +# hold_card_back :string(255) # state :integer default("0") # description :string(255) # created_at :datetime not null @@ -34,18 +34,18 @@ class IdentityVerification < ApplicationRecord end def card_front_attachment - Attachment.find_by_id card_front + Attachment.where_id_or_uuid.first card_front end def card_back_attachment - Attachment.find_by_id card_back + Attachment.where_id_or_uuid.first card_back end def hold_card_front_attachment - Attachment.find_by_id hold_card_front + Attachment.where_id_or_uuid.first hold_card_front end def hold_card_back_attachment - Attachment.find_by_id hold_card_back + Attachment.where_id_or_uuid hold_card_back end end diff --git a/app/models/journal.rb b/app/models/journal.rb index dad60cd7..2e754c51 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -88,9 +88,9 @@ class Journal < ApplicationRecord 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? + old_value = Attachment.where("id in (?) or uuid in (?)", detail.old_value.to_s.split(","), detail.old_value.to_s.split(",")).pluck(:filename).join("、") + new_value = Attachment.where("id in (?) or uuid in (?)", detail.value.to_s.split(","), detail.value.to_s.split(",")).pluck(:filename).join("、") + if old_value.nil? || old_value.blank? content += "添加了#{new_value}附件" else new_value = "无" if new_value.blank? diff --git a/app/services/api/v1/issues/concerns/checkable.rb b/app/services/api/v1/issues/concerns/checkable.rb index 58fc6dc6..7d163ada 100644 --- a/app/services/api/v1/issues/concerns/checkable.rb +++ b/app/services/api/v1/issues/concerns/checkable.rb @@ -31,8 +31,8 @@ module Api::V1::Issues::Concerns::Checkable def check_attachments (attachment_ids) raise ApplicationService::Error, "请输入正确的附件ID数组!" unless attachment_ids.is_a?(Array) attachment_ids.each do |aid| - raise ApplicationService::Error, "请输入正确的附件ID!" unless Attachment.exists?(id: aid) || Attachment.exists?(uuid: aid) - end + raise ApplicationService::Error, "请输入正确的附件ID!" unless Attachment.where("id=? or uuid=?", aid, aid).exists? + end end def check_atme_receivers(receivers_login) diff --git a/app/services/api/v1/issues/concerns/loadable.rb b/app/services/api/v1/issues/concerns/loadable.rb index ffd5ff4a..547ff50d 100644 --- a/app/services/api/v1/issues/concerns/loadable.rb +++ b/app/services/api/v1/issues/concerns/loadable.rb @@ -9,7 +9,7 @@ module Api::V1::Issues::Concerns::Loadable end def load_attachments(attachment_ids) - @attachments = Attachment.where(id: attachment_ids).or(Attachment.where(uuid: attachment_ids)) + @attachments = Attachment.where("id in (?) or uuid in (?)", attachment_ids, attachment_ids) end def load_atme_receivers(receivers_login) diff --git a/db/migrate/20231212012107_change_identity_verification.rb b/db/migrate/20231212012107_change_identity_verification.rb new file mode 100644 index 00000000..6a6ac408 --- /dev/null +++ b/db/migrate/20231212012107_change_identity_verification.rb @@ -0,0 +1,8 @@ +class ChangeIdentityVerification < ActiveRecord::Migration[5.2] + def change + change_column :identity_verifications, :card_front, :string + change_column :identity_verifications, :card_back, :string + change_column :identity_verifications, :hold_card_front, :string + change_column :identity_verifications, :hold_card_back, :string + end +end From 247c5a60b1864cad12e8606febde28832b4b2e2d Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 12 Dec 2023 16:47:48 +0800 Subject: [PATCH 028/130] =?UTF-8?q?fixed=20=E8=A7=A3=E5=86=B3=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E9=97=AE=E9=A2=98=E8=AE=BF=E9=97=AE=E9=99=84=E4=BB=B6?= =?UTF-8?q?=EF=BC=8Cid=E6=94=B9=E4=B8=BAuuid=EF=BC=8C=E5=85=B3=E8=81=94pag?= =?UTF-8?q?es=E5=8A=9F=E8=83=BD=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/identity_verification.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/identity_verification.rb b/app/models/identity_verification.rb index 8673a4a6..9d766763 100644 --- a/app/models/identity_verification.rb +++ b/app/models/identity_verification.rb @@ -34,18 +34,18 @@ class IdentityVerification < ApplicationRecord end def card_front_attachment - Attachment.where_id_or_uuid.first card_front + Attachment.where_id_or_uuid(card_front).first end def card_back_attachment - Attachment.where_id_or_uuid.first card_back + Attachment.where_id_or_uuid(card_back).first end def hold_card_front_attachment - Attachment.where_id_or_uuid.first hold_card_front + Attachment.where_id_or_uuid(hold_card_front).first end def hold_card_back_attachment - Attachment.where_id_or_uuid hold_card_back + Attachment.where_id_or_uuid(hold_card_back).first end end From 60c8b25075b42d2c4ff31dbfd1072126247bd759 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 12 Dec 2023 16:57:39 +0800 Subject: [PATCH 029/130] =?UTF-8?q?fixed=20=E8=A7=A3=E5=86=B3=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E9=97=AE=E9=A2=98=E8=AE=BF=E9=97=AE=E9=99=84=E4=BB=B6?= =?UTF-8?q?=EF=BC=8Cid=E6=94=B9=E4=B8=BAuuid,=E6=9F=A5=E7=9C=8B=E9=99=84?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index bf8c870a..ecc4760b 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -144,11 +144,12 @@ class AttachmentsController < ApplicationController private def find_file + tip_exception(404, "您访问的页面不存在或已被删除") if params[:id].blank? @file = if params[:type] == 'history' AttachmentHistory.find params[:id] else - Attachment.find_by(id: params[:id]) || Attachment.find_by(uuid: params[:id]) + Attachment.where_id_or_uuid(params[:id]).first end tip_exception(404, "您访问的页面不存在或已被删除") if @file.blank? end From b29e50064576e979097479adceb61de90a8de142 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 13 Dec 2023 09:26:49 +0800 Subject: [PATCH 030/130] =?UTF-8?q?fixed=20=E8=A7=A3=E5=86=B3=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E9=97=AE=E9=A2=98=E8=AE=BF=E9=97=AE=E9=99=84=E4=BB=B6?= =?UTF-8?q?=EF=BC=8Cid=E6=94=B9=E4=B8=BAuuid,id=E6=9F=A5=E8=AF=A2=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/attachment.rb | 2 +- app/models/identity_verification.rb | 2 +- app/services/api/v1/issues/concerns/checkable.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 49124a22..81047460 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -69,7 +69,7 @@ class Attachment < ApplicationRecord scope :simple_columns, -> { select(:id, :filename, :filesize, :created_on, :cloud_url, :author_id, :content_type, :container_type, :container_id) } scope :search_by_container, -> (ids) {where(container_id: ids)} scope :unified_setting, -> {where("unified_setting = ? ", 1)} - scope :where_id_or_uuid, -> (id) { where("id = ? or uuid= ? ", id, id) } + scope :where_id_or_uuid, -> (id) { (Float(id) rescue nil).present? ? where(id: id) : where(uuid: id) } validates_length_of :description, maximum: 100, message: "不能超过100个字符" diff --git a/app/models/identity_verification.rb b/app/models/identity_verification.rb index 9d766763..fdef74d4 100644 --- a/app/models/identity_verification.rb +++ b/app/models/identity_verification.rb @@ -24,7 +24,7 @@ class IdentityVerification < ApplicationRecord belongs_to :user enum state: { "待审核": 0, "已通过": 1, "已拒绝": 2} after_create do - Attachment.where(id:[card_front,card_back,hold_card_front,hold_card_back]).update_all(is_public:0) + Attachment.where(uuid:[card_front,card_back,hold_card_front,hold_card_back]).update_all(is_public:0) end after_save do diff --git a/app/services/api/v1/issues/concerns/checkable.rb b/app/services/api/v1/issues/concerns/checkable.rb index 7d163ada..5eef8158 100644 --- a/app/services/api/v1/issues/concerns/checkable.rb +++ b/app/services/api/v1/issues/concerns/checkable.rb @@ -31,7 +31,7 @@ module Api::V1::Issues::Concerns::Checkable def check_attachments (attachment_ids) raise ApplicationService::Error, "请输入正确的附件ID数组!" unless attachment_ids.is_a?(Array) attachment_ids.each do |aid| - raise ApplicationService::Error, "请输入正确的附件ID!" unless Attachment.where("id=? or uuid=?", aid, aid).exists? + raise ApplicationService::Error, "请输入正确的附件ID!" unless Attachment.where_id_or_uuid(aid).exists? end end From 062e654d4502ff53a340c5f631cfe0ddd5810f19 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 14 Dec 2023 11:43:42 +0800 Subject: [PATCH 031/130] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=9B=B4?= =?UTF-8?q?=E6=94=B9=E5=AF=86=E7=A0=81=E9=A1=BB=E9=AA=8C=E8=AF=81=E4=B8=A4?= =?UTF-8?q?=E6=AC=A1=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/accounts_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 4cec1be4..c7f4c276 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -214,6 +214,7 @@ class AccountsController < ApplicationController end def change_password + return render_error("两次输入的密码不正确") if params[:password].to_s != params[:new_password_repeat].to_s @user = User.find_by(login: params[:login]) return render_error("未找到相关用户!") if @user.blank? return render_error("旧密码不正确") unless @user.check_password?(params[:old_password]) From 129970a52586434d7c8e90dc16b7851b70d7651a Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 14 Dec 2023 11:47:32 +0800 Subject: [PATCH 032/130] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E8=AF=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 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 c7f4c276..bfc2cd42 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -214,7 +214,7 @@ class AccountsController < ApplicationController end def change_password - return render_error("两次输入的密码不正确") if params[:password].to_s != params[:new_password_repeat].to_s + return render_error("两次输入的密码不一致") if params[:password].to_s != params[:new_password_repeat].to_s @user = User.find_by(login: params[:login]) return render_error("未找到相关用户!") if @user.blank? return render_error("旧密码不正确") unless @user.check_password?(params[:old_password]) From c75953d34319ed8ce162a03d1fe502d5442e873b Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 14 Dec 2023 16:45:02 +0800 Subject: [PATCH 033/130] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E5=88=86=E6=94=AF=E5=B7=B2=E5=AD=98=E5=9C=A8=E5=88=86?= =?UTF-8?q?=E6=94=AF=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/gitea/repository/entries/create_service.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/services/gitea/repository/entries/create_service.rb b/app/services/gitea/repository/entries/create_service.rb index ac27b3af..40610674 100644 --- a/app/services/gitea/repository/entries/create_service.rb +++ b/app/services/gitea/repository/entries/create_service.rb @@ -59,7 +59,11 @@ class Gitea::Repository::Entries::CreateService < Gitea::ClientService if @body[:new_branch].present? && (@body[:new_branch].include?('/') || @body[:new_branch].include?('\'') || @body[:new_branch].include?('^') || @body[:new_branch].include?('*')) error("不合法的分支名称!") else - error("#{filepath}文件已存在,不能重复创建!") + if json_parse!(body)["message"].present? && json_parse!(body)["message"].starts_with?("branch already exists") + error("#{@body[:new_branch]}分支已存在!") + else + error("#{filepath}文件已存在,不能重复创建!") + end end else Rails.logger.error("Gitea api url==#{url},status:#{status},body=#{body}") From c972d538eebf16b3421254f51f4cf1eb03ef741f Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 14 Dec 2023 16:45:29 +0800 Subject: [PATCH 034/130] =?UTF-8?q?fixed=20=E7=94=A8=E6=88=B7=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=8C=89=E6=98=B5=E7=A7=B0=E5=92=8C=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E5=80=92=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 34d617f1..d7608ec3 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -22,7 +22,7 @@ class UsersController < ApplicationController end def list - scope = User.active.recent.like(params[:search]).includes(:user_extension) + scope = User.active.like(params[:search]).includes(:user_extension).order(nickname: :desc, last_login_on: :desc) @total_count = scope.size @users = paginate(scope) end From 4b57e96914291f44f71b4fe936221fee5aa34611 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 14 Dec 2023 16:45:29 +0800 Subject: [PATCH 035/130] =?UTF-8?q?fixed=20=E7=94=A8=E6=88=B7=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=8C=89=E6=98=B5=E7=A7=B0=E5=92=8C=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E5=80=92=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 34d617f1..d7608ec3 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -22,7 +22,7 @@ class UsersController < ApplicationController end def list - scope = User.active.recent.like(params[:search]).includes(:user_extension) + scope = User.active.like(params[:search]).includes(:user_extension).order(nickname: :desc, last_login_on: :desc) @total_count = scope.size @users = paginate(scope) end From ad969917308b40089f1e127925713c529ff1734d Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 15 Dec 2023 09:01:11 +0800 Subject: [PATCH 036/130] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E8=AF=AD=E9=80=97=E5=8F=B7=E4=B8=BA=E4=B8=AD=E6=96=87?= =?UTF-8?q?=E9=80=97=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/accounts_controller.rb | 4 ++-- app/controllers/oauth2_controller.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index bfc2cd42..ba059bf0 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -193,12 +193,12 @@ class AccountsController < ApplicationController return normal_status(-2, "违反平台使用规范,账号已被锁定") if @user.locked? login_control = LimitForbidControl::UserLogin.new(@user) - return normal_status(-2, "登录密码出错已达上限,账号已被锁定, 请#{login_control.forbid_expires/60}分钟后重新登录或找回密码") if login_control.forbid? + return normal_status(-2, "登录密码出错已达上限,账号已被锁定,请#{login_control.forbid_expires/60}分钟后重新登录或找回密码") if login_control.forbid? password_ok = @user.check_password?(params[:password].to_s) unless password_ok if login_control.remain_times-1 == 0 - normal_status(-2, "登录密码出错已达上限,账号已被锁定, 请#{login_control.forbid_expires/60}分钟后重新登录或找回密码") + normal_status(-2, "登录密码出错已达上限,账号已被锁定,请#{login_control.forbid_expires/60}分钟后重新登录或找回密码") else normal_status(-2, "你已经输错密码#{login_control.error_times+1}次,还剩余#{login_control.remain_times-1}次机会") end diff --git a/app/controllers/oauth2_controller.rb b/app/controllers/oauth2_controller.rb index f1ac19a2..9be575a1 100644 --- a/app/controllers/oauth2_controller.rb +++ b/app/controllers/oauth2_controller.rb @@ -20,12 +20,12 @@ class Oauth2Controller < ActionController::Base return @error = {msg: '违反平台使用规范,账号已被锁定', id: 'login'} if @user.locked? login_control = LimitForbidControl::UserLogin.new(@user) - return @error = {msg: "登录密码出错已达上限,账号已被锁定, 请#{login_control.forbid_expires/60}分钟后重新登录或找回密码", id: 'account'} if login_control.forbid? + return @error = {msg: "登录密码出错已达上限,账号已被锁定,请#{login_control.forbid_expires/60}分钟后重新登录或找回密码", id: 'account'} if login_control.forbid? password_ok = @user.check_password?(params[:password].to_s) unless password_ok if login_control.remain_times-1 == 0 - @error = {msg: "登录密码出错已达上限,账号已被锁定, 请#{login_control.forbid_expires/60}分钟后重新登录或找回密码", id: 'account'} + @error = {msg: "登录密码出错已达上限,账号已被锁定,请#{login_control.forbid_expires/60}分钟后重新登录或找回密码", id: 'account'} else @error = {msg: "你已经输错密码#{login_control.error_times+1}次,还剩余#{login_control.remain_times-1}次机会", id: 'account'} end From 0b21d4af4172ce8b3110081fb7fab12e35f84329 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 15 Dec 2023 15:36:31 +0800 Subject: [PATCH 037/130] =?UTF-8?q?Github=20issues=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_add_issues.rake | 130 ++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/lib/tasks/batch_add_issues.rake b/lib/tasks/batch_add_issues.rake index 32d3e6eb..3b607395 100644 --- a/lib/tasks/batch_add_issues.rake +++ b/lib/tasks/batch_add_issues.rake @@ -127,4 +127,134 @@ namespace :batch_add_issues do end end end + + + task github: :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_github_issues_to_project(project, i + 1 + count) + end + else + add_github_issues_to_project(project, 1) + end + end + + def add_github_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=96a637aa055f15056e77e3cf11a67525&state=all&sort=created&direction=desc&page=#{page}&per_page=100" + api_url = "https://api.github.com/repos/OpenXiangShan/XiangShan/issues?sort=created&direction=desc&per_page=100&state=all&page=#{page}" + 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| + next if issue['pull_request'].present? + 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'] + 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 = "gh-#{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=96a637aa055f15056e77e3cf11a67525&page=1&per_page=100&order=asc" + comment_api_url = "https://api.github.com/repos/OpenXiangShan/XiangShan/issues/#{issue_number}/comments?page=1&per_page=100" + 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'] + 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) + unless comment_user.present? + username = "gh-#{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 From 1eb18e4036196859fa94b39e234aae508ad098fc Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 15 Dec 2023 15:47:41 +0800 Subject: [PATCH 038/130] =?UTF-8?q?Github=20issues=E8=BF=81=E7=A7=BB,?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=90=8D=E5=A4=84=E7=90=86?= 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 3b607395..b30925f3 100644 --- a/lib/tasks/batch_add_issues.rake +++ b/lib/tasks/batch_add_issues.rake @@ -178,13 +178,13 @@ namespace :batch_add_issues do 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) + username = "gh-#{user_login}" + user = User.find_by(login: username) unless user.present? - username = "gh-#{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) + user = User.new(nickname: username, 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) @@ -230,13 +230,13 @@ namespace :batch_add_issues do 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) + username = "gh-#{user_login}" + comment_user = User.find_by(login: username) unless comment_user.present? - username = "gh-#{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) + comment_user = User.new(nickname: username, 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) From 505d873ea656cd6d28243e1f4b55336cdc963c93 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 15 Dec 2023 15:59:27 +0800 Subject: [PATCH 039/130] =?UTF-8?q?Github=20issues=E8=BF=81=E7=A7=BB,?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=90=8D=E5=A4=84=E7=90=86,=20=E9=99=90?= =?UTF-8?q?=E6=B5=81=E9=9C=80=E8=A6=81=E8=AF=B7=E6=B1=82=E7=AD=89=E5=BE=85?= 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, 2 insertions(+) diff --git a/lib/tasks/batch_add_issues.rake b/lib/tasks/batch_add_issues.rake index b30925f3..6340899d 100644 --- a/lib/tasks/batch_add_issues.rake +++ b/lib/tasks/batch_add_issues.rake @@ -144,6 +144,7 @@ namespace :batch_add_issues do if total_count > 100 total_page = (total_count / 100) + 1 total_page.times do |i| + sleep 30.seconds add_github_issues_to_project(project, i + 1 + count) end else @@ -218,6 +219,7 @@ namespace :batch_add_issues do end issue_number = issue['number'] + sleep 3.seconds # 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_api_url = "https://api.github.com/repos/OpenXiangShan/XiangShan/issues/#{issue_number}/comments?page=1&per_page=100" comment_uri = URI.parse(comment_api_url) From b7597c3fa73388e946b8c0cbecf566bb90dd7344 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 15 Dec 2023 16:47:22 +0800 Subject: [PATCH 040/130] =?UTF-8?q?Github=20issues=E8=BF=81=E7=A7=BB,?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=90=8D=E5=A4=84=E7=90=86,=20=E9=99=90?= =?UTF-8?q?=E6=B5=81=E9=9C=80=E8=A6=81=E8=AF=B7=E6=B1=82=E7=AD=89=E5=BE=85?= =?UTF-8?q?,token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_add_issues.rake | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/tasks/batch_add_issues.rake b/lib/tasks/batch_add_issues.rake index 6340899d..109198f0 100644 --- a/lib/tasks/batch_add_issues.rake +++ b/lib/tasks/batch_add_issues.rake @@ -144,7 +144,7 @@ namespace :batch_add_issues do if total_count > 100 total_page = (total_count / 100) + 1 total_page.times do |i| - sleep 30.seconds + sleep 3.seconds add_github_issues_to_project(project, i + 1 + count) end else @@ -157,7 +157,11 @@ namespace :batch_add_issues do # 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" api_url = "https://api.github.com/repos/OpenXiangShan/XiangShan/issues?sort=created&direction=desc&per_page=100&state=all&page=#{page}" uri = URI.parse(api_url) - response = Net::HTTP.get_response(uri) + # response = Net::HTTP.get_response(uri) + http = Net::HTTP.new(uri.hostname, uri.port) + http.use_ssl = true + comment_response = http.send_request('GET', uri.path, nil, {'Content-Type' => 'application/json','authorization' => "Bearer #{ENV['token']}"}) + puts "gitee api response.code ===== #{response.code}" lists = JSON.parse(response.body) puts "lists.size =====#{lists.size}" @@ -219,11 +223,14 @@ namespace :batch_add_issues do end issue_number = issue['number'] - sleep 3.seconds + sleep 1.seconds # 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_api_url = "https://api.github.com/repos/OpenXiangShan/XiangShan/issues/#{issue_number}/comments?page=1&per_page=100" comment_uri = URI.parse(comment_api_url) - comment_response = Net::HTTP.get_response(comment_uri) + # comment_response = Net::HTTP.get_response(comment_uri) + http = Net::HTTP.new(comment_uri.hostname, comment_uri.port) + http.use_ssl = true + comment_response = http.send_request('GET', comment_uri.path, nil, {'Content-Type' => 'application/json','authorization' => "Bearer #{ENV['token']}"}) comment_lists = JSON.parse(comment_response.body) comment_lists.each do |comment| From de393148d9533a4586504f7aff99f950436ca9a9 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 15 Dec 2023 16:48:33 +0800 Subject: [PATCH 041/130] =?UTF-8?q?Github=20issues=E8=BF=81=E7=A7=BB,?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=90=8D=E5=A4=84=E7=90=86,=20=E9=99=90?= =?UTF-8?q?=E6=B5=81=E9=9C=80=E8=A6=81=E8=AF=B7=E6=B1=82=E7=AD=89=E5=BE=85?= =?UTF-8?q?,token?= 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 109198f0..d6b76dd0 100644 --- a/lib/tasks/batch_add_issues.rake +++ b/lib/tasks/batch_add_issues.rake @@ -160,7 +160,7 @@ namespace :batch_add_issues do # response = Net::HTTP.get_response(uri) http = Net::HTTP.new(uri.hostname, uri.port) http.use_ssl = true - comment_response = http.send_request('GET', uri.path, nil, {'Content-Type' => 'application/json','authorization' => "Bearer #{ENV['token']}"}) + response = http.send_request('GET', uri.path, nil, {'Content-Type' => 'application/json','authorization' => "Bearer #{ENV['token']}"}) puts "gitee api response.code ===== #{response.code}" lists = JSON.parse(response.body) From b80ed537fcf9b05a4311b94fe19c3ddf247ce9f9 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 15 Dec 2023 17:04:53 +0800 Subject: [PATCH 042/130] =?UTF-8?q?Github=20issues=E8=BF=81=E7=A7=BB,?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=90=8D=E5=A4=84=E7=90=86,=20=E9=99=90?= =?UTF-8?q?=E6=B5=81=E9=9C=80=E8=A6=81=E8=AF=B7=E6=B1=82=E7=AD=89=E5=BE=85?= =?UTF-8?q?,token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_add_issues.rake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/tasks/batch_add_issues.rake b/lib/tasks/batch_add_issues.rake index d6b76dd0..198c76ef 100644 --- a/lib/tasks/batch_add_issues.rake +++ b/lib/tasks/batch_add_issues.rake @@ -144,7 +144,7 @@ namespace :batch_add_issues do if total_count > 100 total_page = (total_count / 100) + 1 total_page.times do |i| - sleep 3.seconds + sleep 1.seconds add_github_issues_to_project(project, i + 1 + count) end else @@ -160,7 +160,7 @@ namespace :batch_add_issues do # response = Net::HTTP.get_response(uri) http = Net::HTTP.new(uri.hostname, uri.port) http.use_ssl = true - response = http.send_request('GET', uri.path, nil, {'Content-Type' => 'application/json','authorization' => "Bearer #{ENV['token']}"}) + response = http.send_request('GET', uri, nil, {'Content-Type' => 'application/json','authorization' => "Bearer #{ENV['token']}"}) puts "gitee api response.code ===== #{response.code}" lists = JSON.parse(response.body) @@ -230,7 +230,7 @@ namespace :batch_add_issues do # comment_response = Net::HTTP.get_response(comment_uri) http = Net::HTTP.new(comment_uri.hostname, comment_uri.port) http.use_ssl = true - comment_response = http.send_request('GET', comment_uri.path, nil, {'Content-Type' => 'application/json','authorization' => "Bearer #{ENV['token']}"}) + comment_response = http.send_request('GET', comment_uri, nil, {'Content-Type' => 'application/json','authorization' => "Bearer #{ENV['token']}"}) comment_lists = JSON.parse(comment_response.body) comment_lists.each do |comment| From 9979ae6d3a6862cf0abac7035ba84105119fef06 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 18 Dec 2023 09:49:53 +0800 Subject: [PATCH 043/130] =?UTF-8?q?Github=20issues=E8=BF=81=E7=A7=BB,title?= =?UTF-8?q?=20=E9=95=BF=E5=BA=A6=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_add_issues.rake | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/tasks/batch_add_issues.rake b/lib/tasks/batch_add_issues.rake index 198c76ef..1e5b1af1 100644 --- a/lib/tasks/batch_add_issues.rake +++ b/lib/tasks/batch_add_issues.rake @@ -68,7 +68,8 @@ namespace :batch_add_issues do UserExtension.create!(user_id: user.id) puts "import_user batch success: phone #{phone} email: #{email}" end - + title = issue['title'] + title = title[0..190] if title.size > 190 issue_params = { :status_id => issue_status, :priority_id => priority, @@ -76,7 +77,7 @@ namespace :batch_add_issues do # :branch_name, # :start_date, # :due_date, - :subject => issue['title'], + :subject => title, :description => issue['body'], # :blockchain_token_num, :issue_tag_ids => [], From 7b1d0e21eedc2c715dc2752ee77649e07e69b5f9 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 18 Dec 2023 10:00:01 +0800 Subject: [PATCH 044/130] =?UTF-8?q?Github=20issues=E8=BF=81=E7=A7=BB,title?= =?UTF-8?q?=20=E9=95=BF=E5=BA=A6=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_add_issues.rake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/tasks/batch_add_issues.rake b/lib/tasks/batch_add_issues.rake index 1e5b1af1..49cced50 100644 --- a/lib/tasks/batch_add_issues.rake +++ b/lib/tasks/batch_add_issues.rake @@ -204,6 +204,8 @@ namespace :batch_add_issues do puts "import_user batch success: phone #{phone} email: #{email}" end + title = issue['title'] + title = title[0..190] if title.size > 190 issue_params = { :status_id => issue_status, :priority_id => priority, @@ -211,7 +213,7 @@ namespace :batch_add_issues do # :branch_name, # :start_date, # :due_date, - :subject => issue['title'], + :subject => title, :description => issue['body'], # :blockchain_token_num, :issue_tag_ids => [], From eaf389ecea57796664d5f084803b665ffd9fd804 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 18 Dec 2023 10:33:31 +0800 Subject: [PATCH 045/130] =?UTF-8?q?Github=20issues=E8=BF=81=E7=A7=BB,title?= =?UTF-8?q?=20=E9=95=BF=E5=BA=A6=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_add_issues.rake | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/tasks/batch_add_issues.rake b/lib/tasks/batch_add_issues.rake index 49cced50..96763344 100644 --- a/lib/tasks/batch_add_issues.rake +++ b/lib/tasks/batch_add_issues.rake @@ -203,6 +203,11 @@ namespace :batch_add_issues do UserExtension.create!(user_id: user.id) puts "import_user batch success: phone #{phone} email: #{email}" end + if issue['labels'].present? + issue['labels'].each do |tag| + project.issue_tags.find_or_create_by!(name: tag['name'], description: tag['description'], color: "##{tag['color']}") + end + end title = issue['title'] title = title[0..190] if title.size > 190 From c6a38c06d06e05664e10c6f2c082d812720dee5c Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 18 Dec 2023 10:54:04 +0800 Subject: [PATCH 046/130] =?UTF-8?q?Github=20issues=E8=BF=81=E7=A7=BB,?= =?UTF-8?q?=E6=A0=87=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_add_issues.rake | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/tasks/batch_add_issues.rake b/lib/tasks/batch_add_issues.rake index 96763344..673d6a1a 100644 --- a/lib/tasks/batch_add_issues.rake +++ b/lib/tasks/batch_add_issues.rake @@ -203,12 +203,15 @@ namespace :batch_add_issues do UserExtension.create!(user_id: user.id) puts "import_user batch success: phone #{phone} email: #{email}" end + issue_tags_value = [] if issue['labels'].present? issue['labels'].each do |tag| - project.issue_tags.find_or_create_by!(name: tag['name'], description: tag['description'], color: "##{tag['color']}") + label = project.issue_tags.find_or_create_by!(name: tag['name'], description: tag['description'], color: "##{tag['color']}") + issue_tags_value.push(label.id) end end + title = issue['title'] title = title[0..190] if title.size > 190 issue_params = { @@ -221,7 +224,7 @@ namespace :batch_add_issues do :subject => title, :description => issue['body'], # :blockchain_token_num, - :issue_tag_ids => [], + :issue_tag_ids => issue_tags_value.join(","), :assigner_ids => [], :attachment_ids => [], :receivers_login => [] From 5fe9719cc9b159f51259cb8d23375c95279711a3 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 18 Dec 2023 10:54:47 +0800 Subject: [PATCH 047/130] =?UTF-8?q?Github=20issues=E8=BF=81=E7=A7=BB,?= =?UTF-8?q?=E6=A0=87=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_add_issues.rake | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/tasks/batch_add_issues.rake b/lib/tasks/batch_add_issues.rake index 673d6a1a..40b8fb3c 100644 --- a/lib/tasks/batch_add_issues.rake +++ b/lib/tasks/batch_add_issues.rake @@ -175,7 +175,9 @@ namespace :batch_add_issues do # Issue的状态: open(开启的), progressing(进行中), closed(关闭的), rejected(拒绝的)。 默认: open lists.each do |issue| next if issue['pull_request'].present? - created_issue = Issue.find_by(project_id: project.id, subject: issue['title']) + title = issue['title'] + title = title[0..190] if title.size > 190 + created_issue = Issue.find_by(project_id: project.id, subject: 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']) @@ -211,9 +213,6 @@ namespace :batch_add_issues do end end - - title = issue['title'] - title = title[0..190] if title.size > 190 issue_params = { :status_id => issue_status, :priority_id => priority, From 3806ddaa179d85c411bac7166361960b5e74cc58 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 18 Dec 2023 10:59:24 +0800 Subject: [PATCH 048/130] =?UTF-8?q?Github=20issues=E8=BF=81=E7=A7=BB,?= =?UTF-8?q?=E6=A0=87=E8=AE=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 40b8fb3c..b1df5677 100644 --- a/lib/tasks/batch_add_issues.rake +++ b/lib/tasks/batch_add_issues.rake @@ -223,7 +223,7 @@ namespace :batch_add_issues do :subject => title, :description => issue['body'], # :blockchain_token_num, - :issue_tag_ids => issue_tags_value.join(","), + :issue_tag_ids => issue_tags_value, :assigner_ids => [], :attachment_ids => [], :receivers_login => [] From 326dcc56abfc0264497de707c9c71e4af25587b2 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 18 Dec 2023 11:19:20 +0800 Subject: [PATCH 049/130] =?UTF-8?q?Github=20issues=E8=BF=81=E7=A7=BB,?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=97=B6=E9=97=B4=E5=9B=BA=E5=AE=9A?= 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 b1df5677..e01182d7 100644 --- a/lib/tasks/batch_add_issues.rake +++ b/lib/tasks/batch_add_issues.rake @@ -229,7 +229,6 @@ namespace :batch_add_issues do :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'] @@ -273,6 +272,7 @@ namespace :batch_add_issues do 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) + created_issue.update_columns(created_on: issue_created_at, updated_on: issue_updated_at) end end end From 761021d19100cbc9565e058069adbfcbdb303032 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 18 Dec 2023 11:52:37 +0800 Subject: [PATCH 050/130] =?UTF-8?q?Github=20issues=E8=BF=81=E7=A7=BB,?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=97=B6=E9=97=B4=E5=9B=BA=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 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 e01182d7..9389b95c 100644 --- a/lib/tasks/batch_add_issues.rake +++ b/lib/tasks/batch_add_issues.rake @@ -178,14 +178,14 @@ namespace :batch_add_issues do title = issue['title'] title = title[0..190] if title.size > 190 created_issue = Issue.find_by(project_id: project.id, subject: title) + issue_created_at = issue['created_at'] + issue_updated_at = issue['updated_at'] 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'] user_login = user_login[0..20] if user_login.size > 29 - issue_created_at = issue['created_at'] - issue_updated_at = issue['updated_at'] username = "gh-#{user_login}" user = User.find_by(login: username) unless user.present? From 75fff13550509023bec5eae00d05287bf0487d71 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 18 Dec 2023 15:49:41 +0800 Subject: [PATCH 051/130] =?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=E6=9F=A5=E8=AF=A2=E4=B8=B0?= =?UTF-8?q?=E5=AF=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admins/projects_rank_controller.rb | 75 +++++++++++++++++-- app/views/admins/projects_rank/index.html.erb | 68 ++++------------- app/views/admins/projects_rank/index.js.erb | 1 + .../projects_rank/shared/_data_list.html.erb | 39 ++++++++++ 4 files changed, 121 insertions(+), 62 deletions(-) create mode 100644 app/views/admins/projects_rank/index.js.erb create mode 100644 app/views/admins/projects_rank/shared/_data_list.html.erb diff --git a/app/controllers/admins/projects_rank_controller.rb b/app/controllers/admins/projects_rank_controller.rb index c4f968da..df759872 100644 --- a/app/controllers/admins/projects_rank_controller.rb +++ b/app/controllers/admins/projects_rank_controller.rb @@ -1,16 +1,77 @@ class Admins::ProjectsRankController < Admins::BaseController - + before_action :get_timeable_key_names, only:[:index] def index - @rank_date = rank_date - deleted_data = $redis_cache.smembers("v2-project-rank-deleted") - $redis_cache.zrem("v2-project-rank-#{rank_date}", deleted_data) unless deleted_data.blank? - @date_rank = $redis_cache.zrevrange("v2-project-rank-#{rank_date}", 0, -1, withscores: true) + puts @names_array + unless @names_array.blank? + $redis_cache.zunionstore("admin-days-project-rank", @names_array) + deleted_data = $redis_cache.smembers("v2-project-rank-deleted") + $redis_cache.zrem("admin-days-project-rank", deleted_data) unless deleted_data.blank? + @date_rank = $redis_cache.zrevrange("admin-days-project-rank", 0, -1, withscores: true) + @date_rank = @date_rank.map do |i| + visits = 0 + watchers = 0 + praises = 0 + forks = 0 + issues = 0 + pullrequests = 0 + commits = 0 + (begin_date..end_date).to_a.each do |d| + result = $redis_cache.hgetall("v2-project-statistic:#{i[0]}-#{d}") + visits += result["visits"].to_i + watchers += result["watchers"].to_i + praises += result["praises"].to_i + forks += result["forks"].to_i + issues += result["issues"].to_i + pullrequests += result["pullrequests"].to_i + commits += result["commits"].to_i + end + i + [visits,watchers,praises,forks,issues,pullrequests,commits] + end + case params[:sort_by] + when 'visits' + @date_rank = @date_rank.sort{|i| i[2]} + when 'watchers' + @date_rank = @date_rank.sort{|i| i[3]} + when 'praises' + @date_rank = @date_rank.sort{|i| i[4]} + when 'forks' + @date_rank = @date_rank.sort{|i| i[5]} + when 'issues' + @date_rank = @date_rank.sort{|i| i[6]} + when 'pullrequests' + @date_rank = @date_rank.sort{|i| i[7]} + when 'commits' + @date_rank = @date_rank.sort{|i| i[8]} + else + @date_rank = @date_rank.sort{|i| i[1]} + end + if params[:sort_direction].blank? || params[:sort_direction].to_s.downcase == "desc" + @date_rank = @date_rank.reverse + end + else + @date_rank = [] + end end private - def rank_date - params.fetch(:date, Date.today.to_s) + def begin_date + params.fetch(:begin_date, Date.today.to_s) + end + + def end_date + params.fetch(:end_date, Date.today.to_s) + end + + def get_timeable_key_names + begin + @names_array = [] + (begin_date..end_date).to_a.each do |i| + @names_array << "v2-project-rank-#{i}" + end + rescue + @names_array = [] + end end end \ No newline at end of file diff --git a/app/views/admins/projects_rank/index.html.erb b/app/views/admins/projects_rank/index.html.erb index d3a7926b..3ea7b8ae 100644 --- a/app/views/admins/projects_rank/index.html.erb +++ b/app/views/admins/projects_rank/index.html.erb @@ -6,69 +6,27 @@
<%= form_tag(admins_projects_rank_index_path, method: :get, class: 'form-inline search-form flex-1', id: 'project-rank-date-form') do %>
- + <% dates_array = (0..30).to_a.map { |item| [(Date.today-item.days).to_s, (Date.today-item.days).to_s] } %> - <%= select_tag(:date, options_for_select(dates_array, params[:date]), class:"form-control",id: "project-rank-date-select")%> + <%= select_tag(:begin_date, options_for_select(dates_array, params[:begin_date]), class:"form-control",id: "project-rank-begin-date-select")%> +
+
+ + <% dates_array = (0..30).to_a.map { |item| [(Date.today-item.days).to_s, (Date.today-item.days).to_s] } %> + <%= select_tag(:end_date, options_for_select(dates_array, params[:end_date]), class:"form-control",id: "project-rank-end-date-select")%>
<% end %>
-
- - - - - - - - - - - - - - - - - <% @date_rank.each_with_index do |item, index| %> - - - <% project_common = $redis_cache.hgetall("v2-project-common:#{item[0]}") %> - <% owner_common = $redis_cache.hgetall("v2-owner-common:#{project_common["owner_id"]}")%> - - - - <% project_date_statistic_key = "v2-project-statistic:#{item[0]}-#{@rank_date}"%> - <% if $redis_cache.exists(project_date_statistic_key)%> - <% visits = $redis_cache.hget(project_date_statistic_key, "visits") %> - - <% watchers = $redis_cache.hget(project_date_statistic_key, "watchers") %> - - <% praises = $redis_cache.hget(project_date_statistic_key, "praises") %> - - <% forks = $redis_cache.hget(project_date_statistic_key, "forks") %> - - <% issues = $redis_cache.hget(project_date_statistic_key, "issues") %> - - <% pullrequests = $redis_cache.hget(project_date_statistic_key, "pullrequests") %> - - <% commits = $redis_cache.hget(project_date_statistic_key, "commits") %> - - <% else %> - - <% end %> - - <% end %> - -
排名项目得分访问数关注数点赞数fork数疑修数合并请求数提交数
<%= index + 1%> - /<%= project_common["identifier"]%>"> - <%= "#{owner_common["name"]}/#{project_common["name"]}" %> - - <%= item[1] %><%= visits || 0 %><%= watchers || 0 %><%= praises || 0 %><%= forks || 0 %><%= issues || 0 %><%= pullrequests || 0 %><%= commits || 0 %>暂无数据
+
+ <%= render partial: 'admins/projects_rank/shared/data_list', locals: { date_rank: @date_rank } %>
\ No newline at end of file diff --git a/app/views/admins/projects_rank/index.js.erb b/app/views/admins/projects_rank/index.js.erb new file mode 100644 index 00000000..7e0f0e5f --- /dev/null +++ b/app/views/admins/projects_rank/index.js.erb @@ -0,0 +1 @@ +$('.project-rank-list-container').html("<%= j( render partial: 'admins/projects_rank/shared/data_list', locals: { date_rank: @date_rank } ) %>"); \ No newline at end of file diff --git a/app/views/admins/projects_rank/shared/_data_list.html.erb b/app/views/admins/projects_rank/shared/_data_list.html.erb new file mode 100644 index 00000000..06b41b45 --- /dev/null +++ b/app/views/admins/projects_rank/shared/_data_list.html.erb @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + <% date_rank.each_with_index do |item, index| %> + + + <% project_common = $redis_cache.hgetall("v2-project-common:#{item[0]}") %> + <% owner_common = $redis_cache.hgetall("v2-owner-common:#{project_common["owner_id"]}")%> + + + + + + + + + + + + <% end %> + +
排名项目得分<%= sort_tag('访问数', name: 'visits', path: admins_projects_rank_index_path) %><%= sort_tag('关注数', name: 'watchers', path: admins_projects_rank_index_path) %><%= sort_tag('点赞数', name: 'praises', path: admins_projects_rank_index_path) %><%= sort_tag('fork数', name: 'forks', path: admins_projects_rank_index_path) %><%= sort_tag('疑修数', name: 'issues', path: admins_projects_rank_index_path) %><%= sort_tag('合并请求数', name: 'pullrequests', path: admins_projects_rank_index_path) %><%= sort_tag('提交数', name: 'commits', path: admins_projects_rank_index_path) %>
<%= index + 1%> + /<%= project_common["identifier"]%>"> + <%= "#{owner_common["name"]}/#{project_common["name"]}" %> + + <%= item[1] %><%= item[2] %><%= item[3] %><%= item[4] %><%= item[5] %><%= item[6] %><%= item[7] %><%= item[8] %>
\ No newline at end of file From 016a2f8cf5c3278c3f180a71a5977955c66862c6 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 18 Dec 2023 16:04:14 +0800 Subject: [PATCH 052/130] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E7=AE=A1=E7=90=86sidebar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/admins/shared/_sidebar.html.erb | 52 +++++++++++------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/app/views/admins/shared/_sidebar.html.erb b/app/views/admins/shared/_sidebar.html.erb index 813e2338..4db54507 100644 --- a/app/views/admins/shared/_sidebar.html.erb +++ b/app/views/admins/shared/_sidebar.html.erb @@ -13,13 +13,7 @@
    -
  • <%= sidebar_item(admins_path, '概览', icon: 'dashboard', controller: 'admins-dashboards') %>
  • -
  • - <%= 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 %> - +
  • <%= sidebar_item(admins_path, '数据概览', icon: 'dashboard', controller: 'admins-dashboards') %>
  • <%= sidebar_item_group('#user-submenu', '用户', icon: 'user') do %>
  • <%= sidebar_item(admins_users_path, '用户列表', icon: 'user', controller: 'admins-users') %>
  • @@ -27,15 +21,23 @@ <% end %> -
  • - <%= sidebar_item_group('#pages-submenu', '站点管理', icon: 'cogs') do %> -
  • <%= sidebar_item(admins_identity_verifications_path, '身份审核列表', icon: 'user', controller: 'admins-identity_verifications') %>
  • -
  • <%= sidebar_item(admins_site_pages_path, '用户站点列表', icon: 'sitemap', controller: 'admins-site_pages') %>
  • -
  • <%= sidebar_item(admins_page_themes_path, '站点主题配置', icon: 'cogs', controller: 'admins-page_themes') %>
  • - + <%= sidebar_item_group('#setting-submenu', '用户支持', icon: 'cogs') do %> +
  • <%= sidebar_item(admins_faqs_path, 'FAQ', icon: 'question-circle', controller: 'admins-faqs') %>
  • +
  • <%= sidebar_item(admins_nps_path, 'NPS用户调研', icon: 'question-circle', controller: 'admins-nps') %>
  • +
  • <%= sidebar_item(admins_feedbacks_path, '用户反馈', icon: 'question-circle', controller: 'admins-feedbacks') %>
  • +
  • <%= sidebar_item(admins_system_notifications_path, '系统公告配置', icon: 'bell', controller: 'admins-system_notifications') %>
  • <% end %> +
  • <%= sidebar_item(admins_laboratories_path, '导航栏配置', icon: 'cloud', controller: 'admins-laboratories') %>
  • +
  • + <%= sidebar_item_group('#setting-system', '开发者配置', icon: 'wrench') do %> +
  • <%= sidebar_item(admins_sites_path, 'setting接口配置', icon: 'deaf', controller: 'admins-sites') %>
  • +
  • <%= sidebar_item(admins_edu_settings_path, '全局变量配置', icon: 'pencil-square', controller: 'admins-edu_settings') %>
  • +
  • <%= sidebar_item(admins_message_templates_path, '消息模版配置', icon: 'folder', controller: 'admins-message_templates') %>
  • + <% end %> + +
  • <%= sidebar_item(admins_reversed_keywords_path, '禁用词管理', icon: 'key', controller: 'admins-reversed_keywords') %>
  • <%= sidebar_item_group('#projects-submenu', '开源项目', icon: 'database') do %>
  • <%= sidebar_item(admins_projects_path, '项目列表', icon: 'database', controller: 'admins-projects') %>
  • @@ -45,9 +47,6 @@
  • <%= sidebar_item(admins_project_ignores_path, '忽略文件', icon: 'git', controller: 'admins-project_ignores') %>
  • <% end %> - -
  • <%= sidebar_item(admins_reversed_keywords_path, '系统保留关键词', icon: 'key', controller: 'admins-reversed_keywords') %>
  • -
  • <%= sidebar_item(admins_laboratories_path, '云上实验室', icon: 'cloud', controller: 'admins-laboratories') %>
  • <%= sidebar_item_group('#setting-index', '首页配置', icon: 'file') do %>
  • <%= sidebar_item(admins_topic_banners_path, 'banner管理', icon: 'image', controller: 'admins-topic-banners') %>
  • @@ -71,25 +70,26 @@ <% end %>
  • - <%= sidebar_item_group('#setting-submenu', '网站建设', icon: 'cogs') do %> -
  • <%= sidebar_item(admins_faqs_path, 'FAQ', icon: 'question-circle', controller: 'admins-faqs') %>
  • -
  • <%= sidebar_item(admins_nps_path, 'NPS用户调研', icon: 'question-circle', controller: 'admins-nps') %>
  • -
  • <%= sidebar_item(admins_feedbacks_path, '用户反馈', icon: 'question-circle', controller: 'admins-feedbacks') %>
  • + <%= sidebar_item_group('#pages-submenu', '个人站点管理', icon: 'cogs') do %> +
  • <%= sidebar_item(admins_identity_verifications_path, '身份审核列表', icon: 'user', controller: 'admins-identity_verifications') %>
  • +
  • <%= sidebar_item(admins_site_pages_path, '用户站点列表', icon: 'sitemap', controller: 'admins-site_pages') %>
  • +
  • <%= sidebar_item(admins_page_themes_path, '站点主题配置', icon: 'cogs', controller: 'admins-page_themes') %>
  • + <% end %>
  • - <%= sidebar_item_group('#setting-system', '系统配置', icon: 'wrench') do %> -
  • <%= sidebar_item(admins_sites_path, 'setting接口配置', icon: 'deaf', controller: 'admins-sites') %>
  • -
  • <%= sidebar_item(admins_edu_settings_path, '全局变量配置', icon: 'pencil-square', controller: 'admins-edu_settings') %>
  • -
  • <%= sidebar_item(admins_system_notifications_path, '系统通知配置', icon: 'bell', controller: 'admins-system_notifications') %>
  • -
  • <%= sidebar_item(admins_message_templates_path, '消息模版配置', icon: 'folder', controller: 'admins-message_templates') %>
  • + <%= 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 %> + + <%= render_admin_statistics_item %> +
  • <%= sidebar_item('/admins/sidekiq', '定时任务', icon: 'bell', controller: 'root') %>
  • - <%= render_admin_statistics_item %>
  • <%= sidebar_item('/', '返回主站', icon: 'sign-out', controller: 'root') %>
From 21f559f2547911ada4d73bb8a042d2d5f1ef6235 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 19 Dec 2023 14:57:54 +0800 Subject: [PATCH 053/130] =?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=E4=BD=BF=E7=94=A8=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=AD=98=E5=82=A8=E4=BB=A5=E5=8F=8A=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- .../admins/projects_rank_controller.rb | 96 +++++++------------ app/jobs/daily_project_statistics_job.rb | 32 +++++++ app/models/daily_project_statistic.rb | 28 ++++++ app/views/admins/projects_rank/index.html.erb | 30 +++--- app/views/admins/projects_rank/index.js.erb | 2 +- .../projects_rank/shared/_data_list.html.erb | 24 +++-- config/sidekiq_cron.yml | 5 + ...9020521_create_daily_project_statistics.rb | 19 ++++ 9 files changed, 153 insertions(+), 86 deletions(-) create mode 100644 app/jobs/daily_project_statistics_job.rb create mode 100644 app/models/daily_project_statistic.rb create mode 100644 db/migrate/20231219020521_create_daily_project_statistics.rb diff --git a/.gitignore b/.gitignore index 4a01bd5e..2735825a 100644 --- a/.gitignore +++ b/.gitignore @@ -84,4 +84,5 @@ redis_data/ dump.rdb .tags* ceshi_user.xlsx -public/trace_task_results \ No newline at end of file +public/trace_task_results +public/项目活跃度排行.xls \ No newline at end of file diff --git a/app/controllers/admins/projects_rank_controller.rb b/app/controllers/admins/projects_rank_controller.rb index df759872..c1f9722c 100644 --- a/app/controllers/admins/projects_rank_controller.rb +++ b/app/controllers/admins/projects_rank_controller.rb @@ -1,56 +1,17 @@ class Admins::ProjectsRankController < Admins::BaseController - before_action :get_timeable_key_names, only:[:index] def index - puts @names_array - unless @names_array.blank? - $redis_cache.zunionstore("admin-days-project-rank", @names_array) - deleted_data = $redis_cache.smembers("v2-project-rank-deleted") - $redis_cache.zrem("admin-days-project-rank", deleted_data) unless deleted_data.blank? - @date_rank = $redis_cache.zrevrange("admin-days-project-rank", 0, -1, withscores: true) - @date_rank = @date_rank.map do |i| - visits = 0 - watchers = 0 - praises = 0 - forks = 0 - issues = 0 - pullrequests = 0 - commits = 0 - (begin_date..end_date).to_a.each do |d| - result = $redis_cache.hgetall("v2-project-statistic:#{i[0]}-#{d}") - visits += result["visits"].to_i - watchers += result["watchers"].to_i - praises += result["praises"].to_i - forks += result["forks"].to_i - issues += result["issues"].to_i - pullrequests += result["pullrequests"].to_i - commits += result["commits"].to_i - end - i + [visits,watchers,praises,forks,issues,pullrequests,commits] - end - case params[:sort_by] - when 'visits' - @date_rank = @date_rank.sort{|i| i[2]} - when 'watchers' - @date_rank = @date_rank.sort{|i| i[3]} - when 'praises' - @date_rank = @date_rank.sort{|i| i[4]} - when 'forks' - @date_rank = @date_rank.sort{|i| i[5]} - when 'issues' - @date_rank = @date_rank.sort{|i| i[6]} - when 'pullrequests' - @date_rank = @date_rank.sort{|i| i[7]} - when 'commits' - @date_rank = @date_rank.sort{|i| i[8]} - else - @date_rank = @date_rank.sort{|i| i[1]} - end - if params[:sort_direction].blank? || params[:sort_direction].to_s.downcase == "desc" - @date_rank = @date_rank.reverse - end - else - @date_rank = [] - end + @statistics = DailyProjectStatistic.where("date >= ? AND date <= ?", begin_date, end_date) + @statistics = @statistics.group(:project_id).select("project_id, + sum(score) as score, + sum(visits) as visits, + sum(watchers) as watchers, + sum(praises) as praises, + sum(forks) as forks, + sum(issues) as issues, + sum(pullrequests) as pullrequests, + sum(commits) as commits").includes(:project) + @statistics = @statistics.order("#{sort_by} #{sort_direction}") + export_excel(@statistics.limit(50)) end private @@ -63,15 +24,32 @@ class Admins::ProjectsRankController < Admins::BaseController params.fetch(:end_date, Date.today.to_s) end - def get_timeable_key_names - begin - @names_array = [] - (begin_date..end_date).to_a.each do |i| - @names_array << "v2-project-rank-#{i}" - end - rescue - @names_array = [] + def sort_by + params.fetch(:sort_by, "score") + end + + def sort_direction + params.fetch(:sort_direction, "desc") + end + + def export_excel(data) + book = Spreadsheet::Workbook.new + sheet = book.create_worksheet :name => "项目活跃度排行" + sheet.row(0).concat %w(排名 项目全称 项目地址 得分 访问数 关注数 点赞数 fork数 疑修数 合并请求数 提交数) + data.each_with_index do |d, index| + sheet[index+1,0] = index+1 + sheet[index+1,1] = "#{d&.project&.owner&.nickname}/#{d&.project&.name}" + sheet[index+1,2] = "#{Rails.application.config_for(:configuration)['platform_url']}/#{d&.project&.owner&.login}/#{d&.project&.identifier}" + sheet[index+1,3] = d.score + sheet[index+1,4] = d.visits + sheet[index+1,5] = d.watchers + sheet[index+1,6] = d.praises + sheet[index+1,7] = d.forks + sheet[index+1,8] = d.issues + sheet[index+1,9] = d.pullrequests + sheet[index+1,10] = d.commits end + book.write "#{Rails.root}/public/项目活跃度排行.xls" end end \ No newline at end of file diff --git a/app/jobs/daily_project_statistics_job.rb b/app/jobs/daily_project_statistics_job.rb new file mode 100644 index 00000000..98506748 --- /dev/null +++ b/app/jobs/daily_project_statistics_job.rb @@ -0,0 +1,32 @@ +class DailyProjectStatisticsJob < ApplicationJob + queue_as :cache + + def perform + date = (Date.today - 1.days).to_s + daily_data_keys = $redis_cache.keys("v2-project-statistic:*-#{date}") + daily_data_keys.each do |key| + result = $redis_cache.hgetall(key) + project_id = key.gsub('v2-project-statistic:', '').gsub("-#{date}", '') + visits = result["visits"].to_i + watchers = result["watchers"].to_i + praises = result["praises"].to_i + forks = result["forks"].to_i + issues = result["issues"].to_i + pullrequests = result["pullrequests"].to_i + commits = result["commits"].to_i + score = visits *1 + watchers *5 + praises * 5 + forks * 10 + issues *5 + pullrequests * 10 + commits * 5 + DailyProjectStatistic.create!( + project_id: project_id, + date: date, + score: score , + visits: visits, + watchers: watchers, + praises: praises, + forks: forks, + issues: issues, + pullrequests: pullrequests, + commits: commits + ) + end + end +end \ No newline at end of file diff --git a/app/models/daily_project_statistic.rb b/app/models/daily_project_statistic.rb new file mode 100644 index 00000000..f7fc0aad --- /dev/null +++ b/app/models/daily_project_statistic.rb @@ -0,0 +1,28 @@ +# == Schema Information +# +# Table name: daily_project_statistics +# +# id :integer not null, primary key +# project_id :integer +# date :string(255) +# visits :integer default("0") +# watchers :integer default("0") +# praises :integer default("0") +# forks :integer default("0") +# issues :integer default("0") +# pullrequests :integer default("0") +# commits :integer default("0") +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_daily_project_statistics_on_date (date) +# index_daily_project_statistics_on_project_id (project_id) +# + +class DailyProjectStatistic < ApplicationRecord + + + belongs_to :project +end diff --git a/app/views/admins/projects_rank/index.html.erb b/app/views/admins/projects_rank/index.html.erb index 3ea7b8ae..e9d38afa 100644 --- a/app/views/admins/projects_rank/index.html.erb +++ b/app/views/admins/projects_rank/index.html.erb @@ -5,28 +5,34 @@
<%= form_tag(admins_projects_rank_index_path, method: :get, class: 'form-inline search-form flex-1', id: 'project-rank-date-form') do %> -
- - <% dates_array = (0..30).to_a.map { |item| [(Date.today-item.days).to_s, (Date.today-item.days).to_s] } %> - <%= select_tag(:begin_date, options_for_select(dates_array, params[:begin_date]), class:"form-control",id: "project-rank-begin-date-select")%> +
+ 开始日期 +
-
- - <% dates_array = (0..30).to_a.map { |item| [(Date.today-item.days).to_s, (Date.today-item.days).to_s] } %> - <%= select_tag(:end_date, options_for_select(dates_array, params[:end_date]), class:"form-control",id: "project-rank-end-date-select")%> +
+ 结束日期 +
<% end %> - + <%= link_to '导出', "/项目活跃度排行.xls", class: 'btn btn-primary mr-3' %>
- <%= render partial: 'admins/projects_rank/shared/data_list', locals: { date_rank: @date_rank } %> + <%= render partial: 'admins/projects_rank/shared/data_list', locals: { statistics: @statistics } %>
\ No newline at end of file diff --git a/app/views/admins/projects_rank/index.js.erb b/app/views/admins/projects_rank/index.js.erb index 7e0f0e5f..0d36dd86 100644 --- a/app/views/admins/projects_rank/index.js.erb +++ b/app/views/admins/projects_rank/index.js.erb @@ -1 +1 @@ -$('.project-rank-list-container').html("<%= j( render partial: 'admins/projects_rank/shared/data_list', locals: { date_rank: @date_rank } ) %>"); \ No newline at end of file +$('.project-rank-list-container').html("<%= j( render partial: 'admins/projects_rank/shared/data_list', locals: { statistics: @statistics } ) %>"); \ No newline at end of file diff --git a/app/views/admins/projects_rank/shared/_data_list.html.erb b/app/views/admins/projects_rank/shared/_data_list.html.erb index 06b41b45..bb9f4577 100644 --- a/app/views/admins/projects_rank/shared/_data_list.html.erb +++ b/app/views/admins/projects_rank/shared/_data_list.html.erb @@ -14,25 +14,23 @@ - <% date_rank.each_with_index do |item, index| %> + <% statistics.each_with_index do |item, index| %> <%= index + 1%> - <% project_common = $redis_cache.hgetall("v2-project-common:#{item[0]}") %> - <% owner_common = $redis_cache.hgetall("v2-owner-common:#{project_common["owner_id"]}")%> - /<%= project_common["identifier"]%>"> - <%= "#{owner_common["name"]}/#{project_common["name"]}" %> + "> + <%= "#{item&.project&.owner&.nickname}/#{item&.project&.name}" %> - <%= item[1] %> - <%= item[2] %> - <%= item[3] %> - <%= item[4] %> - <%= item[5] %> - <%= item[6] %> - <%= item[7] %> - <%= item[8] %> + <%= item&.score %> + <%= item&.visits %> + <%= item&.watchers %> + <%= item&.praises %> + <%= item&.forks %> + <%= item&.issues %> + <%= item&.pullrequests %> + <%= item&.commits %> <% end %> diff --git a/config/sidekiq_cron.yml b/config/sidekiq_cron.yml index 448e9c94..0ec8f997 100644 --- a/config/sidekiq_cron.yml +++ b/config/sidekiq_cron.yml @@ -7,3 +7,8 @@ delay_expired_issue: cron: "0 0 * * *" class: "DelayExpiredIssueJob" queue: message + +create_daily_project_statistics: + cron: "0 1 * * *" + class: "DailyProjectStatisticsJob" + queue: cache \ No newline at end of file diff --git a/db/migrate/20231219020521_create_daily_project_statistics.rb b/db/migrate/20231219020521_create_daily_project_statistics.rb new file mode 100644 index 00000000..4465154d --- /dev/null +++ b/db/migrate/20231219020521_create_daily_project_statistics.rb @@ -0,0 +1,19 @@ +class CreateDailyProjectStatistics < ActiveRecord::Migration[5.2] + def change + create_table :daily_project_statistics do |t| + t.references :project + t.date :date + t.index :date + t.integer :score, default: 0 + t.integer :visits, default: 0 + t.integer :watchers, default: 0 + t.integer :praises, default: 0 + t.integer :forks, default: 0 + t.integer :issues, default: 0 + t.integer :pullrequests, default: 0 + t.integer :commits, default: 0 + + t.timestamps + end + end +end From 26461f3a4407838b907c9ef1c1cdf7d5feed5c18 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 19 Dec 2023 15:05:00 +0800 Subject: [PATCH 054/130] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E9=98=B2?= =?UTF-8?q?=E6=AD=A2sql=E6=B3=A8=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admins/projects_rank_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/admins/projects_rank_controller.rb b/app/controllers/admins/projects_rank_controller.rb index c1f9722c..bee024f8 100644 --- a/app/controllers/admins/projects_rank_controller.rb +++ b/app/controllers/admins/projects_rank_controller.rb @@ -25,11 +25,11 @@ class Admins::ProjectsRankController < Admins::BaseController end def sort_by - params.fetch(:sort_by, "score") + DailyProjectStatistic.column_names.include?(params.fetch(:sort_by, "score")) ? params.fetch(:sort_by, "score") : "score" end def sort_direction - params.fetch(:sort_direction, "desc") + %w(desc asc).include?(params.fetch(:sort_direction, "desc")) ? params.fetch(:sort_direction, "desc") : "desc" end def export_excel(data) From 3b5b78faede4a62e7a15f615430c485fee313d46 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 19 Dec 2023 15:36:57 +0800 Subject: [PATCH 055/130] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=95=B0=E6=8D=AE=E5=A4=84=E7=90=86=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?=E6=98=B5=E7=A7=B0=E8=8E=B7=E5=8F=96=E8=A7=84=E5=88=99=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admins/projects_rank_controller.rb | 2 +- app/jobs/daily_project_statistics_job.rb | 1 + app/views/admins/projects_rank/shared/_data_list.html.erb | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/admins/projects_rank_controller.rb b/app/controllers/admins/projects_rank_controller.rb index bee024f8..06a796bd 100644 --- a/app/controllers/admins/projects_rank_controller.rb +++ b/app/controllers/admins/projects_rank_controller.rb @@ -38,7 +38,7 @@ class Admins::ProjectsRankController < Admins::BaseController sheet.row(0).concat %w(排名 项目全称 项目地址 得分 访问数 关注数 点赞数 fork数 疑修数 合并请求数 提交数) data.each_with_index do |d, index| sheet[index+1,0] = index+1 - sheet[index+1,1] = "#{d&.project&.owner&.nickname}/#{d&.project&.name}" + sheet[index+1,1] = "#{d&.project&.owner&.real_name}/#{d&.project&.name}" sheet[index+1,2] = "#{Rails.application.config_for(:configuration)['platform_url']}/#{d&.project&.owner&.login}/#{d&.project&.identifier}" sheet[index+1,3] = d.score sheet[index+1,4] = d.visits diff --git a/app/jobs/daily_project_statistics_job.rb b/app/jobs/daily_project_statistics_job.rb index 98506748..ad606f13 100644 --- a/app/jobs/daily_project_statistics_job.rb +++ b/app/jobs/daily_project_statistics_job.rb @@ -7,6 +7,7 @@ class DailyProjectStatisticsJob < ApplicationJob daily_data_keys.each do |key| result = $redis_cache.hgetall(key) project_id = key.gsub('v2-project-statistic:', '').gsub("-#{date}", '') + next unless Project.find_by_id(project_id).present? visits = result["visits"].to_i watchers = result["watchers"].to_i praises = result["praises"].to_i diff --git a/app/views/admins/projects_rank/shared/_data_list.html.erb b/app/views/admins/projects_rank/shared/_data_list.html.erb index bb9f4577..2dc0fc1e 100644 --- a/app/views/admins/projects_rank/shared/_data_list.html.erb +++ b/app/views/admins/projects_rank/shared/_data_list.html.erb @@ -19,7 +19,7 @@ <%= index + 1%> "> - <%= "#{item&.project&.owner&.nickname}/#{item&.project&.name}" %> + <%= "#{item&.project&.owner&.real_name}/#{item&.project&.name}" %> From 6b8749589e57bd750d72a3c3fea0b18332950ab2 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 19 Dec 2023 15:45:35 +0800 Subject: [PATCH 056/130] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E6=96=87?= =?UTF-8?q?=E6=A1=88=E4=B8=BA=E6=88=AA=E6=AD=A2=E6=97=A5=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/admins/projects_rank/index.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admins/projects_rank/index.html.erb b/app/views/admins/projects_rank/index.html.erb index e9d38afa..4b1d81fe 100644 --- a/app/views/admins/projects_rank/index.html.erb +++ b/app/views/admins/projects_rank/index.html.erb @@ -10,7 +10,7 @@
- 结束日期 + 截止日期
<% end %> From d590e1165ea72a76abf33b5527d9da84a114f56a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 20 Dec 2023 09:22:10 +0800 Subject: [PATCH 057/130] website update --- app/controllers/site_pages_controller.rb | 38 ++++++----- app/models/attachment.rb | 83 ++++++++++++------------ app/models/issue.rb | 5 ++ app/models/issue_tag.rb | 1 + app/models/journal.rb | 1 + app/models/user.rb | 4 +- 6 files changed, 74 insertions(+), 58 deletions(-) diff --git a/app/controllers/site_pages_controller.rb b/app/controllers/site_pages_controller.rb index 903e037d..085f1b02 100644 --- a/app/controllers/site_pages_controller.rb +++ b/app/controllers/site_pages_controller.rb @@ -17,23 +17,31 @@ class SitePagesController < ApplicationController end def create - return normal_status(-1, "你还未开通Page服务,无法进行部署") unless current_user.website_permission - return normal_status(-1, "你已使用了 #{params[:identifier]} 作为page标识") if Page.exists?(identifier: params[:identifier], user: current_user) - return normal_status(-1, "该仓库已开通Page服务") if Page.exists?(project: @project) + return normal_status(-1, '你还未开通Page服务,无法进行部署') unless current_user.website_permission + return normal_status(-1, '你已开通Page服务') if Page.exists?(user: current_user) + return normal_status(-1, '该仓库已开通Page服务') if Page.exists?(project: @project) @page = Page.new(create_params) @page.user = current_user @page.project = @project @page.save end + def update + return normal_status(-1, '你还未开通Page服务') unless current_user.website_permission + return normal_status(-1, '你还未开通Page站点') unless Page.exists?(user: current_user) + @page = Page.find_by(user: current_user) + @page.update(language_frame: params[:language_frame]) + render_ok + end + def build - return normal_status(-1, "你还未开通Page服务,无法进行部署") unless current_user.website_permission - return normal_status(-1, "该仓库还未开通Page服务,无法进行部署") unless Page.exists?(project: @project) + return normal_status(-1, '你还未开通Page服务,无法进行部署') unless current_user.website_permission + return normal_status(-1, '该仓库还未开通Page服务,无法进行部署') unless Page.exists?(project: @project) @page = Page.find params[:id] return normal_status(-1, @page.state_description) unless @page.state response_str = @page.deploy_page(params[:branch]) - data = JSON.parse(response_str)["result"] || data = JSON.parse(response_str)["error"] - if data.to_s.include?("部署成功") + data = JSON.parse(response_str)['result'] || (data = JSON.parse(response_str)['error']) + if data.to_s.include?('部署成功') @page.update(last_build_at: Time.now, build_state: true, last_build_info: data) else @page.update(build_state:false, last_build_info: data) @@ -42,22 +50,22 @@ class SitePagesController < ApplicationController end def softbot_build - branch = params[:ref].split("/").last + branch = params[:ref].split('/').last user = User.find_by_login params[:repository][:owner][:login] - return normal_status(-1, "你还未开通Page服务,无法进行部署") unless user.website_permission + return normal_status(-1, '你还未开通Page服务,无法进行部署') unless user.website_permission project = Project.where(identifier: params[:repository][:name],user_id: user.id) - return normal_status(-1, "你没有权限操作") if project.owner?(user) - return normal_status(-1, "该仓库还未开通Page服务,无法进行部署") if Page.exists?(user: user, project: project) + return normal_status(-1, '你没有权限操作') if project.owner?(user) + return normal_status(-1, '该仓库还未开通Page服务,无法进行部署') if Page.exists?(user: user, project: project) @page = Page.find_by(user: user, project: project) response_str = @page.deploy_page(branch) - data = JSON.parse(response_str)["result"] + data = JSON.parse(response_str)['result'] if data.nil? - data = JSON.parse(response_str)["error"] + data = JSON.parse(response_str)['error'] end - if data.include?("部署成功") + if data.include?('部署成功') @page.update(last_build_at: Time.now, build_state: true, last_build_info: data) else @page.update(build_state:false, last_build_info: data) @@ -85,7 +93,7 @@ class SitePagesController < ApplicationController end def theme_params - params[:language_frame] || "hugo" + params[:language_frame] || 'hugo' end def create_params diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 81047460..9fd858bf 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -1,44 +1,45 @@ -# == Schema Information -# -# Table name: attachments -# -# id :integer not null, primary key -# container_id :integer -# container_type :string(30) -# filename :string(255) default(""), not null -# disk_filename :string(255) default(""), not null -# filesize :integer default("0"), not null -# content_type :string(255) default("") -# digest :string(60) default(""), not null -# downloads :integer default("0"), not null -# author_id :integer default("0"), not null -# created_on :datetime -# description :text(65535) -# disk_directory :string(255) -# attachtype :integer default("1") -# is_public :integer default("1") -# copy_from :integer -# quotes :integer default("0") -# is_publish :integer default("1") -# publish_time :datetime -# resource_bank_id :integer -# unified_setting :boolean default("1") -# cloud_url :string(255) default("") -# course_second_category_id :integer default("0") -# delay_publish :boolean default("0") -# memo_image :boolean default("0") -# extra_type :integer default("0") -# uuid :string(255) -# -# Indexes -# -# index_attachments_on_author_id (author_id) -# index_attachments_on_container_id_and_container_type (container_id,container_type) -# index_attachments_on_course_second_category_id (course_second_category_id) -# index_attachments_on_created_on (created_on) -# index_attachments_on_is_public (is_public) -# index_attachments_on_quotes (quotes) -# +# == Schema Information +# +# Table name: attachments +# +# id :integer not null, primary key +# container_id :integer +# container_type :string(30) +# filename :string(255) default(""), not null +# disk_filename :string(255) default(""), not null +# filesize :integer default("0"), not null +# content_type :string(255) default("") +# digest :string(60) default(""), not null +# downloads :integer default("0"), not null +# author_id :integer default("0"), not null +# created_on :datetime +# description :text(65535) +# disk_directory :string(255) +# attachtype :integer default("1") +# is_public :integer default("1") +# copy_from :integer +# quotes :integer default("0") +# is_publish :integer default("1") +# publish_time :datetime +# resource_bank_id :integer +# unified_setting :boolean default("1") +# cloud_url :string(255) default("") +# course_second_category_id :integer default("0") +# delay_publish :boolean default("0") +# memo_image :boolean default("0") +# extra_type :integer default("0") +# uuid :string(255) +# +# Indexes +# +# index_attachments_on_author_id (author_id) +# index_attachments_on_container_id_and_container_type (container_id,container_type) +# index_attachments_on_course_second_category_id (course_second_category_id) +# index_attachments_on_created_on (created_on) +# index_attachments_on_is_public (is_public) +# index_attachments_on_quotes (quotes) +# + diff --git a/app/models/issue.rb b/app/models/issue.rb index 93d30b5d..f96bac8f 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -36,12 +36,17 @@ # blockchain_token_num :integer # pm_project_id :integer # pm_sprint_id :integer +# pm_issue_type :integer +# time_scale :decimal(10, 2) default("0.00") +# child_count :integer default("0") +# changer_id :integer # # Indexes # # index_issues_on_assigned_to_id (assigned_to_id) # index_issues_on_author_id (author_id) # index_issues_on_category_id (category_id) +# index_issues_on_changer_id (changer_id) # index_issues_on_created_on (created_on) # index_issues_on_fixed_version_id (fixed_version_id) # index_issues_on_priority_id (priority_id) diff --git a/app/models/issue_tag.rb b/app/models/issue_tag.rb index a3782aba..f5f0abbd 100644 --- a/app/models/issue_tag.rb +++ b/app/models/issue_tag.rb @@ -14,6 +14,7 @@ # gid :integer # gitea_url :string(255) # pull_requests_count :integer default("0") +# pm_project_id :integer # # Indexes # diff --git a/app/models/journal.rb b/app/models/journal.rb index 2e754c51..0fdca0f9 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -27,6 +27,7 @@ # # index_journals_on_created_on (created_on) # index_journals_on_journalized_id (journalized_id) +# index_journals_on_parent_id (parent_id) # index_journals_on_review_id (review_id) # index_journals_on_user_id (user_id) # journals_journalized_id (journalized_id,journalized_type) diff --git a/app/models/user.rb b/app/models/user.rb index 8f1e2954..8ffa5b18 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -189,7 +189,7 @@ class User < Owner has_many :user_clas, :dependent => :destroy has_many :clas, through: :user_clas - has_many :pages, :dependent => :destroy + has_one :page, :dependent => :destroy # Groups and active users scope :active, lambda { where(status: [STATUS_ACTIVE, STATUS_EDIT_INFO]) } @@ -773,7 +773,7 @@ class User < Owner def check_website_permission if website_permission_changed? && website_permission == false - self.pages.update_all(state: false, state_description:"因违规使用,现关闭Page服务") + self.page.update(state: false, state_description:"因违规使用,现关闭Page服务") PageService.close_site(self.id) end end From ae8b86ef025d3bce82000cea8da7e52785eb9b00 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 20 Dec 2023 09:43:57 +0800 Subject: [PATCH 058/130] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E7=AE=A1=E7=90=86=E6=A8=A1=E5=9D=97=E6=96=87=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admins/system_notifications_controller.rb | 8 ++++---- app/views/admins/carousels/index.html.erb | 2 +- app/views/admins/laboratories/index.html.erb | 2 +- .../shared/_create_laboratory_modal.html.erb | 2 +- app/views/admins/laboratory_settings/show.html.erb | 2 +- .../admins/reversed_keywords/_form_modal.html.erb | 4 ++-- app/views/admins/reversed_keywords/index.html.erb | 2 +- .../admins/system_notifications/_form.html.erb | 14 +++++++------- .../admins/system_notifications/index.html.erb | 4 ++-- 9 files changed, 20 insertions(+), 20 deletions(-) diff --git a/app/controllers/admins/system_notifications_controller.rb b/app/controllers/admins/system_notifications_controller.rb index e2081f1a..33f3f20f 100644 --- a/app/controllers/admins/system_notifications_controller.rb +++ b/app/controllers/admins/system_notifications_controller.rb @@ -25,7 +25,7 @@ class Admins::SystemNotificationsController < Admins::BaseController @notification = SystemNotification.new(notification_params) if @notification.save redirect_to admins_system_notifications_path - flash[:success] = '系统消息创建成功' + flash[:success] = '系统公告创建成功' else redirect_to admins_system_notifications_path flash[:danger] = @notification.errors.full_messages.join(",") @@ -37,7 +37,7 @@ class Admins::SystemNotificationsController < Admins::BaseController if @notification.update_attributes(notification_params) format.html do redirect_to admins_system_notifications_path - flash[:success] = '系统消息更新成功' + flash[:success] = '系统公告更新成功' end format.js {render_ok} else @@ -53,10 +53,10 @@ class Admins::SystemNotificationsController < Admins::BaseController def destroy if @notification.destroy redirect_to admins_system_notifications_path - flash[:success] = "系统消息删除成功" + flash[:success] = "系统公告删除成功" else redirect_to admins_system_notifications_path - flash[:danger] = "系统消息删除失败" + flash[:danger] = "系统公告删除失败" end end diff --git a/app/views/admins/carousels/index.html.erb b/app/views/admins/carousels/index.html.erb index 299d1dcf..e9529c86 100644 --- a/app/views/admins/carousels/index.html.erb +++ b/app/views/admins/carousels/index.html.erb @@ -1,6 +1,6 @@ <% define_admin_breadcrumbs do - add_admin_breadcrumb('云上实验室', admins_laboratories_path) + add_admin_breadcrumb('导航栏配置', admins_laboratories_path) add_admin_breadcrumb('轮播图') end %> diff --git a/app/views/admins/laboratories/index.html.erb b/app/views/admins/laboratories/index.html.erb index 8811f4ab..adf34d6f 100644 --- a/app/views/admins/laboratories/index.html.erb +++ b/app/views/admins/laboratories/index.html.erb @@ -1,5 +1,5 @@ <% define_admin_breadcrumbs do %> - <% add_admin_breadcrumb('云上实验室') %> + <% add_admin_breadcrumb('导航栏配置') %> <% end %>
diff --git a/app/views/admins/laboratories/shared/_create_laboratory_modal.html.erb b/app/views/admins/laboratories/shared/_create_laboratory_modal.html.erb index 0a77477d..77ec0bd8 100644 --- a/app/views/admins/laboratories/shared/_create_laboratory_modal.html.erb +++ b/app/views/admins/laboratories/shared/_create_laboratory_modal.html.erb @@ -2,7 +2,7 @@