From c4b9ef79d19d83205f3cfb24b9c695c437d1f8ee Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Fri, 18 Sep 2020 17:16:37 +0800 Subject: [PATCH 01/13] Change Issues Clean Routes --- app/controllers/issues_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index f0578d10e..9569b5a77 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -1,6 +1,6 @@ class IssuesController < ApplicationController before_action :require_login, except: [:index, :show, :index_chosen] - before_action :load_project + before_action :load_project, except: :clean before_action :set_user before_action :check_issue_permission before_action :check_project_public, only: [:index ,:show, :copy, :index_chosen, :close_issue] From ee732c0c3a7a9ddb385eebabbf43a7e0c06e27c1 Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Fri, 18 Sep 2020 17:23:47 +0800 Subject: [PATCH 02/13] Change Issues Clean Routes --- app/controllers/issues_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 9569b5a77..f0578d10e 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -1,6 +1,6 @@ class IssuesController < ApplicationController before_action :require_login, except: [:index, :show, :index_chosen] - before_action :load_project, except: :clean + before_action :load_project before_action :set_user before_action :check_issue_permission before_action :check_project_public, only: [:index ,:show, :copy, :index_chosen, :close_issue] From 3829f21da191c68f29e0798fce5b7031268f8635 Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Wed, 23 Sep 2020 16:58:22 +0800 Subject: [PATCH 03/13] FIX load project bug --- app/controllers/application_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index cd317e50f..bcf42ccbc 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -10,7 +10,7 @@ class ApplicationController < ActionController::Base include LoggerHelper include LoginHelper include RegisterHelper - + protect_from_forgery prepend: true, unless: -> { request.format.json? } before_action :check_sign @@ -749,7 +749,7 @@ class ApplicationController < ActionController::Base if @project and current_user.can_read_project?(@project) logger.info "###########: has project and can read project" @project - elsif current_user.is_a?(AnonymousUser) + elsif @project && current_user.is_a?(AnonymousUser) logger.info "###########:This is AnonymousUser" @project = nil if !@project.is_public? render_forbidden and return From b9a3a86b38297e5607b39e9ac978ba3a6de77e48 Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Wed, 23 Sep 2020 17:40:48 +0800 Subject: [PATCH 04/13] Change VersionRelease Default False --- app/controllers/version_releases_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/version_releases_controller.rb b/app/controllers/version_releases_controller.rb index bc6f03037..a9e7fa63a 100644 --- a/app/controllers/version_releases_controller.rb +++ b/app/controllers/version_releases_controller.rb @@ -139,7 +139,7 @@ class VersionReleasesController < ApplicationController body: params[:body], draft: params[:draft] || false, name: params[:name], - prerelease: params[:prerelease], + prerelease: params[:prerelease] || false, tag_name: params[:tag_name], target_commitish: params[:target_commitish] || "master" #分支 } From e698efb14f74335e929ca56c7aa0d3f7302487ab Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Thu, 24 Sep 2020 14:57:36 +0800 Subject: [PATCH 05/13] Add Attachment Video --- app/controllers/application_controller.rb | 2 +- app/views/attachments/_attachment_simple.json.jbuilder | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index bcf42ccbc..5a706e38a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -385,7 +385,7 @@ class ApplicationController < ActionController::Base def current_user if Rails.env.development? - User.current = User.find 36480 + User.current = User.find 1 else User.current end diff --git a/app/views/attachments/_attachment_simple.json.jbuilder b/app/views/attachments/_attachment_simple.json.jbuilder index 6737838d1..46250489f 100644 --- a/app/views/attachments/_attachment_simple.json.jbuilder +++ b/app/views/attachments/_attachment_simple.json.jbuilder @@ -3,6 +3,7 @@ json.title attachment.title json.filesize number_to_human_size attachment.filesize json.description attachment.description json.is_pdf attachment.is_pdf? +json.absolute_path absolute_path(local_path(attachment)) json.url attachment.is_pdf? ? download_url(attachment,disposition:"inline") : download_url(attachment) # json.url download_url(attachment) json.set! :delete, delete.nil? ? true : delete if defined? delete \ No newline at end of file From 09d382ab8f6a8702831c14cbc99e0a98f796585c Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Thu, 24 Sep 2020 15:33:30 +0800 Subject: [PATCH 06/13] Add Attachment Video1 --- app/views/attachments/_attachment_simple.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/attachments/_attachment_simple.json.jbuilder b/app/views/attachments/_attachment_simple.json.jbuilder index 46250489f..0681d6022 100644 --- a/app/views/attachments/_attachment_simple.json.jbuilder +++ b/app/views/attachments/_attachment_simple.json.jbuilder @@ -3,7 +3,7 @@ json.title attachment.title json.filesize number_to_human_size attachment.filesize json.description attachment.description json.is_pdf attachment.is_pdf? -json.absolute_path absolute_path(local_path(attachment)) +json.absolute_path "https://forgeplus.trustie.net/#{absolute_path(local_path(attachment))}" json.url attachment.is_pdf? ? download_url(attachment,disposition:"inline") : download_url(attachment) # json.url download_url(attachment) json.set! :delete, delete.nil? ? true : delete if defined? delete \ No newline at end of file From 1fcf540dfcccef28d7daea72ed7b0390a61ff894 Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Fri, 25 Sep 2020 09:49:42 +0800 Subject: [PATCH 07/13] Add Attachment --- app/controllers/attachments_controller.rb | 22 ++++++++++++++++++- .../_attachment_simple.json.jbuilder | 1 - config/routes.rb | 1 + 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 4f64abbb6..b592bb3f9 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -2,7 +2,7 @@ # # 文件上传 class AttachmentsController < ApplicationController - before_action :require_login, :check_auth, except: [:show] + before_action :require_login, :check_auth, except: [:show, :preview_attachment] before_action :find_file, only: %i[show destroy] before_action :attachment_candown, only: [:show] skip_before_action :check_sign, only: [:show, :create] @@ -98,6 +98,26 @@ class AttachmentsController < ApplicationController end end + # 附件为视频时,点击播放 + def preview_attachment + attachment = Attachment.find_by(id: params[:id]) + dir_path = "#{Rails.root}/public/preview" + Dir.mkdir(dir_path) unless Dir.exist?(dir_path) + if params[:status] == "preview" + if system("cp -r #{absolute_path(local_path(attachment))} #{dir_path}/") + render json: {status: 1, url: "#{dir_path}/#{attachment.disk_filename}"} + else + normal_status(-1, "出现错误,请稍后重试") + end + else + if system("rm -rf #{dir_path}/#{attachment.disk_filename}") + normal_status(1, "操作成功") + else + normal_status(-1, "出现错误,请稍后重试") + end + end + end + private def find_file @file = diff --git a/app/views/attachments/_attachment_simple.json.jbuilder b/app/views/attachments/_attachment_simple.json.jbuilder index 0681d6022..6737838d1 100644 --- a/app/views/attachments/_attachment_simple.json.jbuilder +++ b/app/views/attachments/_attachment_simple.json.jbuilder @@ -3,7 +3,6 @@ json.title attachment.title json.filesize number_to_human_size attachment.filesize json.description attachment.description json.is_pdf attachment.is_pdf? -json.absolute_path "https://forgeplus.trustie.net/#{absolute_path(local_path(attachment))}" json.url attachment.is_pdf? ? download_url(attachment,disposition:"inline") : download_url(attachment) # json.url download_url(attachment) json.set! :delete, delete.nil? ? true : delete if defined? delete \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index f8b4eec71..0af147919 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -33,6 +33,7 @@ Rails.application.routes.draw do resources :attachments do collection do delete :destroy_files + post :preview_attachment end end get 'home/index' From 47c147c263300210ab37c0160e57f0e57687208d Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Fri, 25 Sep 2020 09:50:57 +0800 Subject: [PATCH 08/13] Add Attachment1 --- config/routes.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 0af147919..40d1546ba 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -31,9 +31,11 @@ Rails.application.routes.draw do resources :compose_projects, only: [:create, :destroy] end resources :attachments do + member do + post :preview_attachment + end collection do delete :destroy_files - post :preview_attachment end end get 'home/index' From d9f6750797fa005d93c6cb6c337007645110dfa9 Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Fri, 25 Sep 2020 10:26:51 +0800 Subject: [PATCH 09/13] Add Attachment2 --- 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 b592bb3f9..a79aae425 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -105,7 +105,7 @@ class AttachmentsController < ApplicationController Dir.mkdir(dir_path) unless Dir.exist?(dir_path) if params[:status] == "preview" if system("cp -r #{absolute_path(local_path(attachment))} #{dir_path}/") - render json: {status: 1, url: "#{dir_path}/#{attachment.disk_filename}"} + render json: {status: 1, url: "/preview/#{attachment.disk_filename}"} else normal_status(-1, "出现错误,请稍后重试") end From db6e3b0f383500882d71d3c2e03b2650a0c34bf8 Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Fri, 25 Sep 2020 10:41:32 +0800 Subject: [PATCH 10/13] FIX fork users list api bug --- app/controllers/projects_controller.rb | 2 +- app/models/fork_user.rb | 2 +- app/views/projects/fork_users.json.jbuilder | 7 +++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index f46945f80..b4fd3e3b4 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -94,7 +94,7 @@ class ProjectsController < ApplicationController end def fork_users - fork_users = @project.fork_users.includes(:user, :project).order("fork_users.created_at desc").distinct + fork_users = @project.fork_users.includes(:user, :project, :fork_project).order("fork_users.created_at desc").distinct @forks_count = fork_users.size @fork_users = paginate(fork_users) end diff --git a/app/models/fork_user.rb b/app/models/fork_user.rb index 4a4d5f77e..749f74980 100644 --- a/app/models/fork_user.rb +++ b/app/models/fork_user.rb @@ -1,6 +1,6 @@ class ForkUser < ApplicationRecord belongs_to :project belongs_to :user - belongs_to :fork_project, class_name: 'ForkUser', foreign_key: :fork_project_id + belongs_to :fork_project, class_name: 'Project', foreign_key: :fork_project_id end diff --git a/app/views/projects/fork_users.json.jbuilder b/app/views/projects/fork_users.json.jbuilder index 3feb31edb..a539797e7 100644 --- a/app/views/projects/fork_users.json.jbuilder +++ b/app/views/projects/fork_users.json.jbuilder @@ -2,10 +2,9 @@ json.count @forks_count json.users do json.array! @fork_users.each do |f| user = f.user - fork_project = Project.select(:id,:name, :identifier).find_by(id: f.fork_project_id) - json.id f.fork_project_id - json.identifier fork_project.identifier - json.name "#{user.try(:show_real_name)}/#{fork_project.try(:name)}" + json.id f.fork_project.id + json.identifier f.fork_project.identifier + json.name "#{user.try(:show_real_name)}/#{f.fork_project.try(:name)}" json.login user.try(:login) json.image_url url_to_avatar(user) json.format_time f.created_at.strftime("%Y-%m-%d") From 1d72256098b806c45f7fe98c13785052894ae9f8 Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Sun, 27 Sep 2020 10:47:55 +0800 Subject: [PATCH 11/13] Add License Id and Reset Version issues_count --- app/controllers/issues_controller.rb | 2 +- .../20200927023922_reset_versions_count.rb | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20200927023922_reset_versions_count.rb diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index f0578d10e..78942fda9 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -196,7 +196,7 @@ class IssuesController < ApplicationController if params[:status_id].to_i == 5 @issue.issue_times.update_all(end_time: Time.now) - @issue.update_closed_issues_count_in_project! + # @issue.update_closed_issues_count_in_project! #已经有after_update方法了,这里就不需要了 end @issue.create_journal_detail(change_files, issue_files, issue_file_ids, current_user&.id) diff --git a/db/migrate/20200927023922_reset_versions_count.rb b/db/migrate/20200927023922_reset_versions_count.rb new file mode 100644 index 000000000..2c121e62d --- /dev/null +++ b/db/migrate/20200927023922_reset_versions_count.rb @@ -0,0 +1,17 @@ +class ResetVersionsCount < ActiveRecord::Migration[5.2] + def change + execute "ALTER TABLE licenses MODIFY COLUMN id INT AUTO_INCREMENT;" + versions = Version.includes(:issues).select(:id, :closed_issues_count, :percent,:issues_count) + versions.each do |v| + Version.reset_counters v.id, :issues + closed_issues = Issue.select(:id, :fixed_version_id, :status_id).where(fixed_version_id: v.id, status_id: 5).size + unless v.closed_issues_count.to_i == closed_issues + percent = v.issues_count.to_i <=0 ? 0.0 : (closed_issues.to_f / v.issues_count.to_i) + v.closed_issues_count = closed_issues + v.percent = percent + v.save + end + puts v.id + end + end +end From d24e7b6a1035f18dbbdba1f2ceaf83610dfb29cd Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Tue, 29 Sep 2020 11:45:29 +0800 Subject: [PATCH 12/13] FIX repository create file with token bug --- app/interactors/gitea/create_file_interactor.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/interactors/gitea/create_file_interactor.rb b/app/interactors/gitea/create_file_interactor.rb index 278d5d857..acceeaa97 100644 --- a/app/interactors/gitea/create_file_interactor.rb +++ b/app/interactors/gitea/create_file_interactor.rb @@ -9,7 +9,8 @@ module Gitea attr_reader :error, :result def initialize(token, owner, params) - @owner = owner + @token = token + @owner = owner @params = params end From 3777059e487ebf86bb0626f0698885149b58dd27 Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Tue, 29 Sep 2020 11:46:18 +0800 Subject: [PATCH 13/13] ADD gitea api request url for escape --- app/services/gitea/client_service.rb | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/app/services/gitea/client_service.rb b/app/services/gitea/client_service.rb index 584276378..06cad0e45 100644 --- a/app/services/gitea/client_service.rb +++ b/app/services/gitea/client_service.rb @@ -20,10 +20,6 @@ class Gitea::ClientService < ApplicationService # } def post(url, params={}) puts "[gitea] request params: #{params}" - request_url = [api_url, url].join('').freeze - Rails.logger.info("######_____api____request_url_______###############{request_url}") - Rails.logger.info("######_____api____request_params_______###############{params}") - auth_token = authen_params(params[:token]) response = conn(auth_token).post do |req| req.url "#{request_url}" @@ -35,7 +31,7 @@ class Gitea::ClientService < ApplicationService def get(url, params={}) auth_token = authen_params(params[:token]) conn(auth_token).get do |req| - req.url full_url(url) + req.url full_url(url, 'get') params.except(:token).each_pair do |key, value| req.params["#{key}"] = value end @@ -117,14 +113,15 @@ class Gitea::ClientService < ApplicationService [domain, base_url].join('') end - def full_url(api_rest) - [api_url, api_rest].join('').freeze + def full_url(api_rest, action='post') + url = [api_url, api_rest].join('').freeze + url = action === 'get' ? url : URI.escape(url) + puts "[gitea] request url: #{url}" + return url end def render_status(response) - Rails.logger.info("###############____response__#{response}") - Rails.logger.info("###############____response_status_#{response.status}") - Rails.logger.info("###############____response_body_#{response.body}") + puts "[gitea] response status: #{response.status}" mark = "[gitea] " case response.status when 201, 200, 202