From 53b66f6145c6b4bf6fd7b964e5070ef5351f6428 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 30 Aug 2023 16:34:23 +0800 Subject: [PATCH 01/21] =?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/21] =?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 d7976766390747482e535d71fac66a0f3bd77bf7 Mon Sep 17 00:00:00 2001 From: kingchan Date: Fri, 1 Dec 2023 09:52:32 +0800 Subject: [PATCH 03/21] 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 04/21] =?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 05/21] =?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 06/21] =?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 07/21] =?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 08/21] =?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 09/21] =?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 10/21] =?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 11/21] =?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 12/21] =?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 13/21] =?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 14/21] =?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 15/21] =?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 16/21] =?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 17/21] =?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 18/21] =?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 19/21] =?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 20/21] =?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 21/21] =?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