From fd34a320b11b6bf9119f63f1602c76b5b9ed89c6 Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Wed, 18 Mar 2020 09:52:47 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/sync_forge_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/sync_forge_job.rb b/app/jobs/sync_forge_job.rb index bf0a9a4..6339a5e 100644 --- a/app/jobs/sync_forge_job.rb +++ b/app/jobs/sync_forge_job.rb @@ -142,7 +142,7 @@ class SyncForgeJob < ApplicationJob if Project.exists?(identifier: project_identifier) failed_dic = "public/sync_failed_users.dic" File.open(failed_dic,"a") do |file| - file.puts "[\nTime---#{Time.now}\nproject_info---#{project}\n---]\n " + file.puts "[\nTime---#{Time.now}\nproject_info---#{project}\nerrors---exists the same project:#{project_identifier}]\n " end else new_project = Project.new(project&.except!(*keys_to_delete).merge(user_id: new_user.id)) From cf27fe8839822b460ac1f4a5f5cd3e2866ac9a41 Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Wed, 18 Mar 2020 15:32:54 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=B7=A5=E5=8D=95?= =?UTF-8?q?=E7=9A=84=E8=AF=84=E8=AE=BA=E4=BF=AE=E6=94=B9=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E5=90=8E=E6=98=BE=E7=A4=BA=E8=AE=B0=E5=BD=95=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/journal.rb | 238 +++++++++++++++++++++--------------------- 1 file changed, 120 insertions(+), 118 deletions(-) diff --git a/app/models/journal.rb b/app/models/journal.rb index 01c10de..b943bd4 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -19,127 +19,129 @@ class Journal < ApplicationRecord details = self.journal_details.select(:property, :prop_key, :old_value, :value).pluck(:property, :prop_key, :old_value, :value) if details.size > 0 details.each do |de| - if de[0] == "attr" - content = "" - else - content = "附件" - end - old_value = de[2] - value = de[3] - if de[1].to_i > 0 - prop_name = "" - else - prop_name = I18n.t("journal_detail.#{de[1]}") - case de[1] - when "is_private" - old_value = I18n.t("journal_detail.#{de[2]}") - value = I18n.t("journal_detail.#{de[3]}") - when "assigned_to_id" - u = User.select(:id, :login, :lastname, :firstname, :nickname) - old_value = de[2].to_i > 0 ? u.find_by_id(de[2]).try(:show_real_name) : "" - assign_user = de[3].to_i > 0 ? u.find_by_id(de[3]) : "" - if assign_user.present? - value = assign_user.try(:show_real_name) - else - value = "" - end - - when "tracker_id" - t = Tracker.select(:id, :name) - old_value = de[2].to_i > 0 ? t.find_by_id(de[2]).try(:name) : "" - tracker_name = de[3].to_i > 0 ? t.find_by_id(de[3]) : "" - if tracker_name - value = tracker_name.try(:name) - else - value = "" - end - - when "status_id" - t = IssueStatus.select(:id, :name) - old_value = de[2].to_i > 0 ? t.find_by_id(de[2]).try(:name) : "" - type_name = de[3].to_i > 0 ? t.find_by_id(de[3]) : "" - if type_name - value = type_name.try(:name) - else - value = "" - end - when "priority_id" - t = IssuePriority.select(:id, :name) - old_value = de[2].to_i > 0 ? t.find_by_id(de[2]).try(:name): "" - type_name = de[3].to_i > 0 ? t.find_by_id(de[3]) : "" - if type_name - value = type_name.try(:name) - else - value = "" - end - when "issue_tags_value" - t = IssueTag.select(:id, :name) - old_value = de[2].to_i > 0 ? t.where(id: de[2].split(",")).select(:id,:name,:color).as_json : "" - if de[3].present? - value = t.where(id: de[3].split(",")).select(:id,:name,:color).as_json - else - value = "" - end - when "fixed_version_id" - t = Version.select(:id, :name) - old_value = de[2].to_i > 0 ? t.find_by_id(de[2]).try(:name) : "" - type_name = de[3].to_i > 0 ? t.find_by_id(de[3]) : "" - if type_name - value = type_name.try(:name) - else - value = "" - end - when "end_time" - t = IssueTime.select(:id, :start_time, :end_time) - type_name = de[2].to_i > 0 ? t.find_by_id(de[2]) : "" - if type_name.present? - old_value = "停止工作" - d_value = type_name.end_time.to_i - type_name.start_time.to_i - value = "#{Time.at(d_value).utc.strftime('%H h %M min %S s')}" - else - old_value = "停止工作" - value = "" - end - when "issue_depend" - t = Issue.select(:id,:subject ) - type_name = de[3].present? ? t&.find_by_id(de[3]) : "" - if type_name.present? - old_value = "增加依赖" - value = { - id: de[3], - name: type_name.try(:subject) - } - else - old_value = "增加依赖" - value = "" - end - when "destroy_issue_depend" - t = Issue.select(:id,:subject ) - type_name = de[3].present? ? t&.find_by_id(de[3]) : "" - if type_name.present? - old_value = "删除依赖" - value = { - id: de[3], - name: type_name.try(:subject) - } - else - old_value = "删除依赖" - value = "" - end - when "done_ratio" - old_value = "#{de[2]}%" - value = "#{de[3]}%" + unless de[1] == "description" + if de[0] == "attr" + content = "" else - old_value = de[2] - value = de[3] + content = "附件" end + old_value = de[2] + value = de[3] + if de[1].to_i > 0 + prop_name = "" + else + prop_name = I18n.t("journal_detail.#{de[1]}") + case de[1] + when "is_private" + old_value = I18n.t("journal_detail.#{de[2]}") + value = I18n.t("journal_detail.#{de[3]}") + when "assigned_to_id" + u = User.select(:id, :login, :lastname, :firstname, :nickname) + old_value = de[2].to_i > 0 ? u.find_by_id(de[2]).try(:show_real_name) : "" + assign_user = de[3].to_i > 0 ? u.find_by_id(de[3]) : "" + if assign_user.present? + value = assign_user.try(:show_real_name) + else + value = "" + end + + when "tracker_id" + t = Tracker.select(:id, :name) + old_value = de[2].to_i > 0 ? t.find_by_id(de[2]).try(:name) : "" + tracker_name = de[3].to_i > 0 ? t.find_by_id(de[3]) : "" + if tracker_name + value = tracker_name.try(:name) + else + value = "" + end + + when "status_id" + t = IssueStatus.select(:id, :name) + old_value = de[2].to_i > 0 ? t.find_by_id(de[2]).try(:name) : "" + type_name = de[3].to_i > 0 ? t.find_by_id(de[3]) : "" + if type_name + value = type_name.try(:name) + else + value = "" + end + when "priority_id" + t = IssuePriority.select(:id, :name) + old_value = de[2].to_i > 0 ? t.find_by_id(de[2]).try(:name): "" + type_name = de[3].to_i > 0 ? t.find_by_id(de[3]) : "" + if type_name + value = type_name.try(:name) + else + value = "" + end + when "issue_tags_value" + t = IssueTag.select(:id, :name) + old_value = de[2].to_i > 0 ? t.where(id: de[2].split(",")).select(:id,:name,:color).as_json : "" + if de[3].present? + value = t.where(id: de[3].split(",")).select(:id,:name,:color).as_json + else + value = "" + end + when "fixed_version_id" + t = Version.select(:id, :name) + old_value = de[2].to_i > 0 ? t.find_by_id(de[2]).try(:name) : "" + type_name = de[3].to_i > 0 ? t.find_by_id(de[3]) : "" + if type_name + value = type_name.try(:name) + else + value = "" + end + when "end_time" + t = IssueTime.select(:id, :start_time, :end_time) + type_name = de[2].to_i > 0 ? t.find_by_id(de[2]) : "" + if type_name.present? + old_value = "停止工作" + d_value = type_name.end_time.to_i - type_name.start_time.to_i + value = "#{Time.at(d_value).utc.strftime('%H h %M min %S s')}" + else + old_value = "停止工作" + value = "" + end + when "issue_depend" + t = Issue.select(:id,:subject ) + type_name = de[3].present? ? t&.find_by_id(de[3]) : "" + if type_name.present? + old_value = "增加依赖" + value = { + id: de[3], + name: type_name.try(:subject) + } + else + old_value = "增加依赖" + value = "" + end + when "destroy_issue_depend" + t = Issue.select(:id,:subject ) + type_name = de[3].present? ? t&.find_by_id(de[3]) : "" + if type_name.present? + old_value = "删除依赖" + value = { + id: de[3], + name: type_name.try(:subject) + } + else + old_value = "删除依赖" + value = "" + end + when "done_ratio" + old_value = "#{de[2]}%" + value = "#{de[3]}%" + else + old_value = de[2] + value = de[3] + end + end + prop_hash = { + detail: (content + prop_name), + old_value: old_value, + value: value + } + send_details.push(prop_hash) end - prop_hash = { - detail: (content + prop_name), - old_value: old_value, - value: value - } - send_details.push(prop_hash) end end end From fe4aefa3b65cbeced0e5dab4a93c58cc91c4f124 Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Wed, 18 Mar 2020 15:37:05 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/journal.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/journal.rb b/app/models/journal.rb index b943bd4..185cc79 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -19,7 +19,7 @@ class Journal < ApplicationRecord details = self.journal_details.select(:property, :prop_key, :old_value, :value).pluck(:property, :prop_key, :old_value, :value) if details.size > 0 details.each do |de| - unless de[1] == "description" + unless de[1].to_s == "description" if de[0] == "attr" content = "" else From 829a31ded75b4cc697c9911fec7668e7616c0886 Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Wed, 18 Mar 2020 18:38:57 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=99=84=E4=BB=B6?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=8A=A5=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/routes.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index fa910cc..423672d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,6 +13,11 @@ Rails.application.routes.draw do get 'auth/cas/callback', to: 'oauth/cas#create' scope '/api' do + resources :attachments do + collection do + delete :destroy_files + end + end resources :sync_forge, only: [:create] #同步用户 resources :composes do resources :compose_projects, only: [:create, :destroy] @@ -319,12 +324,6 @@ Rails.application.routes.draw do end - resources :attachments do - collection do - delete :destroy_files - end - end - resources :repertoires, only: [:index] scope module: :projects do From 05f0550def9f3b2a9b88237c6af196430651e64f Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Thu, 19 Mar 2020 14:30:39 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=B7=A5=E5=8D=95?= =?UTF-8?q?=E9=87=8C=E7=9A=84=E9=A1=B9=E7=9B=AE=E6=A0=B9=E6=8D=AEid?= =?UTF-8?q?=E5=AF=BB=E6=89=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/issues_controller.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 6660d93..cc4e3dd 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] - before_action :find_project + before_action :find_project_issue before_action :set_project_and_user before_action :check_project_public, only: [:index ,:show, :copy, :index_chosen, :close_issue] before_action :check_issue_permission, except: [:index, :show, :index_chosen] @@ -430,4 +430,10 @@ class IssuesController < ApplicationController end all_branches end + + def find_project_issue + project_id = params[:id] + @project = Project.find_by(id: project_id) + render_not_found("未找到’#{project}’相关的项目") unless @project + end end From 71ad6083dd18bcdeeece864d45bcd6619447b0ff Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Thu, 19 Mar 2020 15:27:18 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9project=E7=9A=84=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/issues_controller.rb | 8 +------- app/controllers/project_trends_controller.rb | 2 +- app/controllers/pull_requests_controller.rb | 2 +- app/controllers/version_releases_controller.rb | 2 +- app/controllers/versions_controller.rb | 2 +- 5 files changed, 5 insertions(+), 11 deletions(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index cc4e3dd..d4c6eee 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] - before_action :find_project_issue + before_action :find_project_with_id before_action :set_project_and_user before_action :check_project_public, only: [:index ,:show, :copy, :index_chosen, :close_issue] before_action :check_issue_permission, except: [:index, :show, :index_chosen] @@ -430,10 +430,4 @@ class IssuesController < ApplicationController end all_branches end - - def find_project_issue - project_id = params[:id] - @project = Project.find_by(id: project_id) - render_not_found("未找到’#{project}’相关的项目") unless @project - end end diff --git a/app/controllers/project_trends_controller.rb b/app/controllers/project_trends_controller.rb index 7bc6bbe..476a571 100644 --- a/app/controllers/project_trends_controller.rb +++ b/app/controllers/project_trends_controller.rb @@ -1,5 +1,5 @@ class ProjectTrendsController < ApplicationController - before_action :find_project + before_action :find_project_with_id before_action :check_project_public def index diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index c432296..ac18a71 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -1,6 +1,6 @@ class PullRequestsController < ApplicationController before_action :require_login - before_action :find_project + before_action :find_project_with_id before_action :set_repository before_action :find_pull_request, except: [:index, :new, :create, :check_can_merge] include TagChosenHelper diff --git a/app/controllers/version_releases_controller.rb b/app/controllers/version_releases_controller.rb index 541c30d..96be489 100644 --- a/app/controllers/version_releases_controller.rb +++ b/app/controllers/version_releases_controller.rb @@ -1,5 +1,5 @@ class VersionReleasesController < ApplicationController - before_action :find_project + before_action :find_project_with_id before_action :set_user_and_project before_action :require_login, except: [:index] before_action :find_version , only: [:edit, :update, :destroy] diff --git a/app/controllers/versions_controller.rb b/app/controllers/versions_controller.rb index ccabd13..77d7668 100644 --- a/app/controllers/versions_controller.rb +++ b/app/controllers/versions_controller.rb @@ -1,6 +1,6 @@ class VersionsController < ApplicationController before_action :require_login - before_action :find_project + before_action :find_project_with_id before_action :check_issue_permission, except: [:show, :index] before_action :set_version, only: [:edit, :update, :destroy, :show,:update_status] From 12463c9c052c8a862a9151632ec973bd92148be6 Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Thu, 19 Mar 2020 16:05:44 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9repository=E7=9A=84?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E9=A1=B9=E7=9B=AE=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index abb891c..e0d65a3 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -1,10 +1,11 @@ class RepositoriesController < ApplicationController include ApplicationHelper - before_action :find_user, :find_repository, :authorizate! + before_action :find_project_identifier + before_action :find_repository_with_project + before_action :find_user, :authorizate! before_action :require_login, only: %i[edit] def show - @project = @repo.project @branches_count = Gitea::Repository::BranchesService.new(@user, @repo.identifier).call&.size @commits_count = Gitea::Repository::Commits::ListService.new(@user, @repo.identifier).call[:total_count] @result = Gitea::Repository::GetService.new(@user, @repo.identifier).call @@ -14,7 +15,7 @@ class RepositoriesController < ApplicationController end def entries - @repo.project.increment!(:visits) + @project.increment!(:visits) @ref = params[:branch] || "master" @entries = Gitea::Repository::Entries::ListService.new(@user, @repo.identifier, ref:@ref).call @entries = @entries.sort_by{ |hash| hash['type'] } @@ -53,4 +54,14 @@ class RepositoriesController < ApplicationController render_forbidden end end + + def find_project_identifier + @project = Project.find_by(id: params[:repo_identifier]) + render_not_found("未找到’#{params[:repo_identifier]}’相关的项目") unless @project + end + + def find_repository_with_project + @repo = @project.repository + render_not_found("未找到’#{params[:repo_identifier]}’相关的仓库") unless @repo + end end