From 53b66f6145c6b4bf6fd7b964e5070ef5351f6428 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 30 Aug 2023 16:34:23 +0800 Subject: [PATCH 01/35] =?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 103df6cd4..03ddf4230 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 38cfd98a8..1b729e2c8 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 14b373335..ac27b3afb 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 02/35] =?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 0c89f6012..40f44fea5 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 03/35] =?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 446e4bb31..2045eb7fd 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 312f267da..7694a77c0 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 04/35] 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 319994a28..c3a223a90 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 fe2ecceab..e77b5425f 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 5a7fbc338..3e2a837ee 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 7251e98f2..a3782abaf 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 4d5547683..b6698996f 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 05/35] 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 c3a223a90..2df1288f7 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 e77b5425f..39534c313 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 3e2a837ee..c6495ee26 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 4420ed18e..14876da63 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 b6698996f..41d331168 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 000000000..2c75693fb --- /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 06/35] =?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 4949946c0..cedefd1fe 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 3c8c88d9b..6ea6e0547 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 07/35] 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 cedefd1fe..cfce8b7a7 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 08/35] =?UTF-8?q?fixed=20issue=E6=8F=8F=E8=BF=B0=E9=87=8C?= =?UTF-8?q?=E7=9A=84=E9=99=84=E4=BB=B6=E8=A7=A3=E6=9E=90=E5=85=B3=E8=81=94?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=BC=BA=E9=99=84=E4=BB=B6=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/issues_controller.rb | 3 ++- app/controllers/issues_controller.rb | 1 + app/models/issue.rb | 14 +++++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/issues_controller.rb b/app/controllers/api/v1/issues_controller.rb index 7238254db..ebba95e2b 100644 --- a/app/controllers/api/v1/issues_controller.rb +++ b/app/controllers/api/v1/issues_controller.rb @@ -23,7 +23,8 @@ class Api::V1::IssuesController < Api::V1::BaseController before_action :load_issue, only: [:show, :update, :destroy] before_action :check_issue_operate_permission, only: [:update, :destroy] - def show + def show + @issue.associate_attachment_container @user_permission = current_user.present? && current_user.logged? && (@project.member?(current_user) || current_user.admin? || @issue.user == current_user) end diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 0015b518e..cb7beb402 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -321,6 +321,7 @@ class IssuesController < ApplicationController @issue_user = @issue.user @issue_assign_to = @issue.get_assign_user @join_users = join_users(@issue) + @issue.associate_attachment_container #总耗时 # cost_time(@issue) diff --git a/app/models/issue.rb b/app/models/issue.rb index 14876da63..f568e028c 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -94,7 +94,7 @@ class Issue < ApplicationRecord scope :closed, ->{where(status_id: 5)} scope :opened, ->{where.not(status_id: 5)} after_create :incre_project_common, :incre_user_statistic, :incre_platform_statistic - after_save :change_versions_count, :send_update_message_to_notice_system + after_save :change_versions_count, :send_update_message_to_notice_system, :associate_attachment_container after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic def incre_project_common @@ -222,6 +222,18 @@ class Issue < ApplicationRecord SendTemplateMessageJob.perform_later('IssueExpire', self.id) if Site.has_notice_menu? && self.due_date == Date.today + 1.days end + # 关附件到功能 + def associate_attachment_container + att_ids = [] + # 附件的格式为(/api/attachments/ + 附件id)的形式,提取出id进行附件属性关联,做附件访问权限控制 + att_ids += self.description.to_s.scan(/\(\/api\/attachments\/.+\)/).map{|s|s.match(/\d+/)[0]} + att_ids += self.description.to_s.scan(/\/api\/attachments\/.+\"/).map{|s|s.match(/\d+/)[0]} + att_ids += self.description.to_s.scan(/\/api\/attachments\/\d+/).map{|s|s.match(/\d+/)[0]} + if att_ids.present? + Attachment.where(id: att_ids).where(container_type: nil).update_all(container_id: self.id, container_type: self.class.name) + end + end + def to_builder Jbuilder.new do |issue| issue.(self, :id, :project_issues_index, :subject, :description, :branch_name, :start_date, :due_date) From e8b36f33edbc9c0cacf8a0e9cc953ebfddbac59c Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 18 Oct 2023 15:24:39 +0800 Subject: [PATCH 09/35] =?UTF-8?q?fixed=20issue=E8=AF=84=E8=AE=BA=E9=87=8C?= =?UTF-8?q?=E7=9A=84=E9=99=84=E4=BB=B6=E8=A7=A3=E6=9E=90=E5=85=B3=E8=81=94?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=BC=BA=E9=99=84=E4=BB=B6=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/journal.rb | 14 ++++++++++++++ .../api/v1/issues/journals/index.json.jbuilder | 1 + 2 files changed, 15 insertions(+) diff --git a/app/models/journal.rb b/app/models/journal.rb index ce69c1f3a..3229ae886 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -53,10 +53,24 @@ class Journal < ApplicationRecord enum state: {opened: 0, resolved: 1, disabled: 2} + after_save :associate_attachment_container + def is_journal_detail? self.notes.blank? && self.journal_details.present? end + # 关附件到功能 + def associate_attachment_container + att_ids = [] + # 附件的格式为(/api/attachments/ + 附件id)的形式,提取出id进行附件属性关联,做附件访问权限控制 + att_ids += self.notes.to_s.scan(/\(\/api\/attachments\/.+\)/).map{|s|s.match(/\d+/)[0]} + att_ids += self.notes.to_s.scan(/\/api\/attachments\/.+\"/).map{|s|s.match(/\d+/)[0]} + att_ids += self.notes.to_s.scan(/\/api\/attachments\/\d+/).map{|s|s.match(/\d+/)[0]} + if att_ids.present? + Attachment.where(id: att_ids).where(container_type: nil).update_all(container_id: self.id, container_type: self.class.name) + end + end + def operate_content content = "" detail = self.journal_details.take diff --git a/app/views/api/v1/issues/journals/index.json.jbuilder b/app/views/api/v1/issues/journals/index.json.jbuilder index 49f94aa37..453c39c59 100644 --- a/app/views/api/v1/issues/journals/index.json.jbuilder +++ b/app/views/api/v1/issues/journals/index.json.jbuilder @@ -3,5 +3,6 @@ json.total_operate_journals_count @total_operate_journals_count json.total_comment_journals_count @total_comment_journals_count json.total_count @journals.total_count json.journals @journals do |journal| + journal.associate_attachment_container json.partial! "detail", journal: journal end \ No newline at end of file From 25df7c02d508b704b5976f121f7ae38abeed9f13 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 24 Oct 2023 20:41:02 +0800 Subject: [PATCH 10/35] =?UTF-8?q?fixed=20issue=E5=92=8C=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E9=87=8C=E7=9A=84=E9=99=84=E4=BB=B6=E8=A7=A3=E6=9E=90=E5=85=B3?= =?UTF-8?q?=E8=81=94=EF=BC=8C=E5=A2=9E=E5=BC=BA=E9=99=84=E4=BB=B6=E8=AE=BF?= =?UTF-8?q?=E9=97=AE=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6,=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E5=88=B0=20=E9=A1=B9=E7=9B=AE=E4=BF=9D=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 3 +++ app/models/issue.rb | 2 +- app/models/journal.rb | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index cfce8b7a7..2bbccb495 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -224,6 +224,9 @@ class AttachmentsController < ApplicationController elsif @file.container.is_a?(Journal) project = @file.container.issue.project candown = project.is_public || (current_user.logged? && project.member?(current_user)) + elsif @file.container.is_a?(Project) + project = @file.container + candown = project.is_public || (current_user.logged? && project.member?(current_user)) else project = nil end diff --git a/app/models/issue.rb b/app/models/issue.rb index f568e028c..a5fee95fb 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -230,7 +230,7 @@ class Issue < ApplicationRecord att_ids += self.description.to_s.scan(/\/api\/attachments\/.+\"/).map{|s|s.match(/\d+/)[0]} att_ids += self.description.to_s.scan(/\/api\/attachments\/\d+/).map{|s|s.match(/\d+/)[0]} if att_ids.present? - Attachment.where(id: att_ids).where(container_type: nil).update_all(container_id: self.id, container_type: self.class.name) + Attachment.where(id: att_ids).where("container_type IS NULL OR container_type = 'Issue'").update_all(container_id: self.project_id, container_type: "Project") end end diff --git a/app/models/journal.rb b/app/models/journal.rb index 3229ae886..30cd94143 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -67,7 +67,7 @@ class Journal < ApplicationRecord att_ids += self.notes.to_s.scan(/\/api\/attachments\/.+\"/).map{|s|s.match(/\d+/)[0]} att_ids += self.notes.to_s.scan(/\/api\/attachments\/\d+/).map{|s|s.match(/\d+/)[0]} if att_ids.present? - Attachment.where(id: att_ids).where(container_type: nil).update_all(container_id: self.id, container_type: self.class.name) + Attachment.where(id: att_ids).where("container_type IS NULL OR container_type = 'Journal'").update_all(container_id: self.issue.project_id, container_type: "Project") end end From 9c02b8ba3145eaf2c8d71cde6a00ad0dc03f16e8 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 14 Nov 2023 16:53:29 +0800 Subject: [PATCH 11/35] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Aissue=E5=AD=90?= =?UTF-8?q?=E8=AF=84=E8=AE=BA=E5=85=B3=E8=81=94=E6=9F=A5=E8=AF=A2=E9=94=99?= =?UTF-8?q?=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 30cd94143..e0553ad40 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 486fa5d3f..6d54e3b47 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 12/35] =?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 d5b4b016b..c083033e1 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 13/35] =?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 000000000..2ebca483a --- /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 14/35] =?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 2bbccb495..e5362710c 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 15/35] 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 b6ef11789..8f32cfe6a 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 16/35] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Aissue=20status?= =?UTF-8?q?=E5=92=8Cpriority=E5=88=9D=E5=A7=8B=E5=8C=96=E6=95=B0=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 2df1288f7..f31c92ae3 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 c6495ee26..737f1b38b 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 17/35] 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 8f32cfe6a..820f708e2 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 18/35] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Aissue=20status?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E4=B8=8D=E4=BD=BF=E7=94=A8where.not=E6=96=B9?= =?UTF-8?q?=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 f31c92ae3..2df1288f7 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 737f1b38b..c6495ee26 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 19/35] =?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 69198706e..6e032e9fd 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 20/35] =?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 b87d48429..44fdd9ba0 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 000000000..740f18d07 --- /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 460b56f56..32b384fb5 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 000000000..a0e45fb7e --- /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 20c56138c..f3fa24de8 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 21/35] =?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 8051448e4..3f165215d 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 22/35] =?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 ebba95e2b..76185a16b 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 000000000..55028fc64 --- /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 4478af38f..baa66412e 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 23/35] =?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 e5362710c..bf8c870a0 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -94,6 +94,7 @@ class AttachmentsController < ApplicationController @attachment.author_id = current_user.id @attachment.disk_directory = month_folder @attachment.cloud_url = remote_path + @attachment.uuid = SecureRandom.uuid @attachment.save! else logger.info "文件已存在,id = #{@attachment.id}, filename = #{@attachment.filename}" @@ -147,8 +148,9 @@ class AttachmentsController < ApplicationController if params[:type] == 'history' AttachmentHistory.find params[:id] else - Attachment.find params[:id] + Attachment.find_by(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 936452470..5d5582428 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -299,7 +299,7 @@ module ApplicationHelper end def download_url attachment,options={} - attachment_path(attachment,options) + attachment&.uuid.present? ? attachment_path(attachment.uuid,options) : attachment_path(attachment,options) end # 耗时:天、小时、分、秒 diff --git a/app/models/attachment.rb b/app/models/attachment.rb index f79aca153..defc73662 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -1,44 +1,45 @@ -# == Schema Information -# -# Table name: attachments -# -# id :integer not null, primary key -# container_id :integer -# container_type :string(30) -# filename :string(255) default(""), not null -# disk_filename :string(255) default(""), not null -# filesize :integer default("0"), not null -# content_type :string(255) default("") -# digest :string(60) default(""), not null -# downloads :integer default("0"), not null -# author_id :integer default("0"), not null -# created_on :datetime -# description :text(65535) -# disk_directory :string(255) -# attachtype :integer default("1") -# is_public :integer default("1") -# copy_from :integer -# quotes :integer default("0") -# is_publish :integer default("1") -# publish_time :datetime -# resource_bank_id :integer -# unified_setting :boolean default("1") -# cloud_url :string(255) default("") -# course_second_category_id :integer default("0") -# delay_publish :boolean default("0") -# memo_image :boolean default("0") -# extra_type :integer default("0") -# -# Indexes -# -# index_attachments_on_author_id (author_id) -# index_attachments_on_container_id_and_container_type (container_id,container_type) -# index_attachments_on_course_second_category_id (course_second_category_id) -# index_attachments_on_created_on (created_on) -# index_attachments_on_is_public (is_public) -# index_attachments_on_quotes (quotes) -# - +# == Schema Information +# +# Table name: attachments +# +# id :integer not null, primary key +# container_id :integer +# container_type :string(30) +# filename :string(255) default(""), not null +# disk_filename :string(255) default(""), not null +# filesize :integer default("0"), not null +# content_type :string(255) default("") +# digest :string(60) default(""), not null +# downloads :integer default("0"), not null +# author_id :integer default("0"), not null +# created_on :datetime +# description :text(65535) +# disk_directory :string(255) +# attachtype :integer default("1") +# is_public :integer default("1") +# copy_from :integer +# quotes :integer default("0") +# is_publish :integer default("1") +# publish_time :datetime +# resource_bank_id :integer +# unified_setting :boolean default("1") +# cloud_url :string(255) default("") +# course_second_category_id :integer default("0") +# delay_publish :boolean default("0") +# memo_image :boolean default("0") +# extra_type :integer default("0") +# uuid :string(255) +# +# Indexes +# +# index_attachments_on_author_id (author_id) +# index_attachments_on_container_id_and_container_type (container_id,container_type) +# index_attachments_on_course_second_category_id (course_second_category_id) +# index_attachments_on_created_on (created_on) +# index_attachments_on_is_public (is_public) +# index_attachments_on_quotes (quotes) +# + @@ -97,6 +98,11 @@ class Attachment < ApplicationRecord downloads end + def generate_uuid + self.uuid = uuid || SecureRandom.uuid + save! + end + def quotes_count quotes.nil? ? 0 : quotes end diff --git a/app/models/issue.rb b/app/models/issue.rb index a5fee95fb..93d30b5d5 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 e0553ad40..dad60cd71 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 b19c245ed..58fc6dc6d 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 df30042e0..ffd5ff4a7 100644 --- a/app/services/api/v1/issues/concerns/loadable.rb +++ b/app/services/api/v1/issues/concerns/loadable.rb @@ -9,7 +9,7 @@ module Api::V1::Issues::Concerns::Loadable end def load_attachments(attachment_ids) - @attachments = Attachment.where(id: attachment_ids) + @attachments = Attachment.where(id: attachment_ids).or(Attachment.where(uuid: attachment_ids)) end def load_atme_receivers(receivers_login) diff --git a/app/views/attachments/create.json.jbuilder b/app/views/attachments/create.json.jbuilder index 3c0ef3559..3b12193c9 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 24/35] =?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 740f18d07..bfceab4c2 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 25/35] =?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 000000000..5d0e2ba02 --- /dev/null +++ b/db/migrate/20231121084405_add_uuid_to_attachments.rb @@ -0,0 +1,5 @@ +class AddUuidToAttachments < ActiveRecord::Migration[5.2] + def change + add_column :attachments, :uuid, :string, index: true + end +end From 9a0809e45babd52ed599dfd227aacc554b351654 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 12 Dec 2023 15:33:48 +0800 Subject: [PATCH 26/35] =?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 76a214d0f..62724c12d 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 27/35] =?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 cb7beb402..84219b89b 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 8f7857567..6b9abd5c6 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 62724c12d..ed608873e 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 defc73662..49124a220 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 6ea6e0547..8673a4a6d 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 dad60cd71..2e754c51a 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 58fc6dc6d..7d163ada6 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 ffd5ff4a7..547ff50d7 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 000000000..6a6ac4085 --- /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 28/35] =?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 8673a4a6d..9d7667635 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 29/35] =?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 bf8c870a0..ecc4760b5 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 30/35] =?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 49124a220..810474609 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 9d7667635..fdef74d43 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 7d163ada6..5eef81584 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 31/35] =?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 4cec1be47..c7f4c2767 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 32/35] =?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 c7f4c2767..bfc2cd422 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 33/35] =?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 ac27b3afb..406106744 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 34/35] =?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 34d617f19..d7608ec3d 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 35/35] =?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 bfc2cd422..ba059bf0b 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 f1ac19a2a..9be575a1f 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