From adce0c962762a82402a58042517ae16c8dc633be Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 3 Apr 2023 09:39:41 +0800 Subject: [PATCH 01/28] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Areadme?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E4=BD=BF=E7=94=A8owner=20token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index f03215ace..5d8745397 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -235,9 +235,9 @@ class RepositoriesController < ApplicationController def readme if params[:filepath].present? - result = Gitea::Repository::Readme::DirService.call(@owner.login, @repository.identifier, params[:filepath], params[:ref], current_user&.gitea_token) + result = Gitea::Repository::Readme::DirService.call(@owner.login, @repository.identifier, params[:filepath], params[:ref], @owner&.gitea_token) else - result = Gitea::Repository::Readme::GetService.call(@owner.login, @repository.identifier, params[:ref], current_user&.gitea_token) + result = Gitea::Repository::Readme::GetService.call(@owner.login, @repository.identifier, params[:ref], @owner&.gitea_token) end @path = GiteaService.gitea_config[:domain]+"/#{@owner.login}/#{@repository.identifier}/raw/branch/#{params[:ref]}/" @readme = result[:status] === :success ? result[:body] : nil From 05b33171527ed3155f974486b64e0a82e7052238 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 3 Apr 2023 17:13:38 +0800 Subject: [PATCH 02/28] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=8F=98=E6=9B=B4=E8=B7=AF=E5=BE=84=E4=BD=BF=E7=94=A8?= =?UTF-8?q?base64?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gitea/create_file_interactor.rb | 12 ++++++++-- .../gitea/delete_file_interactor.rb | 12 ++++++++-- .../gitea/update_file_interactor.rb | 22 ++++++++++++++++--- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/app/interactors/gitea/create_file_interactor.rb b/app/interactors/gitea/create_file_interactor.rb index cf753767c..70e2f6e81 100644 --- a/app/interactors/gitea/create_file_interactor.rb +++ b/app/interactors/gitea/create_file_interactor.rb @@ -25,7 +25,7 @@ module Gitea def run Contents::CreateForm.new(valid_params).validate! result = Gitea::Repository::Entries::CreateService.call(token, - owner, @params[:identifier], @params[:filepath], file_params) + owner, @params[:identifier], file_path, file_params) if result[:status] == :success @result = result[:body] @@ -50,9 +50,17 @@ module Gitea @result = response end + def file_path + if @params[:base64_filepath].present? + Base64.decode64(params[:base64_filepath]) + else + @params[:filepath] + end + end + def valid_params { - filepath: @params[:filepath], + filepath: file_path, branch: @params[:branch], new_branch: @params[:new_branch] } diff --git a/app/interactors/gitea/delete_file_interactor.rb b/app/interactors/gitea/delete_file_interactor.rb index 9a48c9e56..103df6cd4 100644 --- a/app/interactors/gitea/delete_file_interactor.rb +++ b/app/interactors/gitea/delete_file_interactor.rb @@ -24,7 +24,7 @@ module Gitea def run Contents::DeleteForm.new(valid_params).validate! - response = Gitea::Repository::Entries::DeleteService.new(token, owner, @params[:identifier], @params[:filepath], file_params).call + response = Gitea::Repository::Entries::DeleteService.new(token, owner, @params[:identifier], file_path, file_params).call render_result(response) rescue Exception => exception fail!(exception.message) @@ -45,9 +45,17 @@ module Gitea end end + def file_path + if @params[:base64_filepath].present? + Base64.decode64(params[:base64_filepath]) + else + @params[:filepath] + end + end + def valid_params { - filepath: @params[:filepath], + filepath: file_path, sha: @params[:sha] } end diff --git a/app/interactors/gitea/update_file_interactor.rb b/app/interactors/gitea/update_file_interactor.rb index 7dc0c017f..38cfd98a8 100644 --- a/app/interactors/gitea/update_file_interactor.rb +++ b/app/interactors/gitea/update_file_interactor.rb @@ -24,7 +24,7 @@ module Gitea def run Contents::UpdateForm.new(valid_params).validate! - response = Gitea::Repository::Entries::UpdateService.new(token, owner, @params[:identifier], @params[:filepath], file_params).call + response = Gitea::Repository::Entries::UpdateService.new(token, owner, @params[:identifier], file_path, file_params).call render_result(response) rescue Exception => exception fail!(exception.message) @@ -45,9 +45,25 @@ module Gitea end end + def file_path + if @params[:base64_filepath].present? + Base64.decode64(params[:base64_filepath]) + else + @params[:filepath] + end + end + + def from_file_path + if @params[:base64_from_path].present? + Base64.decode64(params[:base64_from_path]) + else + @params[:from_path] + end + end + def valid_params { - filepath: @params[:filepath], + filepath: file_path, branch: @params[:branch], new_branch: @params[:new_branch], sha: @params[:sha] @@ -59,7 +75,7 @@ module Gitea branch: @params[:branch], sha: @params[:sha], new_branch: @params[:new_branch], - from_path: @params[:from_path], + from_path: from_file_path, message: @params[:message], content: Base64.encode64(@params[:content]) ).compact From 1cd2e712a769d475e37a3e8ee9eebcf91b5f9bc0 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 09:38:39 +0800 Subject: [PATCH 03/28] =?UTF-8?q?fixed=20=E4=BB=93=E5=BA=93=E6=A0=91?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E4=B8=8D=E5=8A=A0=E8=BD=BD=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/repositories/entries.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/repositories/entries.json.jbuilder b/app/views/repositories/entries.json.jbuilder index c86219785..aa8ea76cd 100644 --- a/app/views/repositories/entries.json.jbuilder +++ b/app/views/repositories/entries.json.jbuilder @@ -54,7 +54,7 @@ if @project.forge? json.submodule_git_url entry['submodule_git_url'].nil? ? nil : repo_git_submodule_url(@owner, @repository, entry['submodule_git_url']) json.size entry['size'] json.is_readme_file is_readme?(entry['type'], entry['name']) - json.content decode64_content(entry, @owner, @repository, @ref, @path) + json.content nil #decode64_content(entry, @owner, @repository, @ref, @path) json.target entry['target'] json.commit do json.partial! 'last_commit', latest_commit: entry['latest_commit'] From 5fff8bc23dc1478294a114278dc54eec4025075a Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 11:34:52 +0800 Subject: [PATCH 04/28] =?UTF-8?q?fixed=20=E9=A1=B9=E7=9B=AEmember=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0bot=E8=AE=BF=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/concerns/project_operable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/concerns/project_operable.rb b/app/models/concerns/project_operable.rb index d5d45a468..42fbc79a2 100644 --- a/app/models/concerns/project_operable.rb +++ b/app/models/concerns/project_operable.rb @@ -95,7 +95,7 @@ module ProjectOperable def member?(user_id) if owner.is_a?(User) - members.exists?(user_id: user_id) + members.exists?(user_id: user_id) || (user.platform == "bot" && BotInstall.joins(:bot).where(bot: { uid: user_id }).where(store_id: self.id).exists?) elsif owner.is_a?(Organization) members.exists?(user_id: user_id) || team_projects.joins(team: :team_users).where(team_users: {user_id: user_id}).present? else From 17c87f1043cfc99553f0df6fb259031c4ddfd3f8 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 11:48:42 +0800 Subject: [PATCH 05/28] =?UTF-8?q?fixed=20=E9=A1=B9=E7=9B=AEmember=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0bot=E8=AE=BF=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/concerns/project_operable.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/project_operable.rb b/app/models/concerns/project_operable.rb index 42fbc79a2..31d16dc9e 100644 --- a/app/models/concerns/project_operable.rb +++ b/app/models/concerns/project_operable.rb @@ -93,9 +93,14 @@ module ProjectOperable team_user.destroy! if team_user end + # 安装bot后的权限 + def is_install_bot?(user) + user.platform == "bot" && BotInstall.joins(:bot).where(bot: { uid: user_id }).where(store_id: self.id).exists? + end + def member?(user_id) if owner.is_a?(User) - members.exists?(user_id: user_id) || (user.platform == "bot" && BotInstall.joins(:bot).where(bot: { uid: user_id }).where(store_id: self.id).exists?) + members.exists?(user_id: user_id) || is_install_bot?(User.find_by(id: user_id)) elsif owner.is_a?(Organization) members.exists?(user_id: user_id) || team_projects.joins(team: :team_users).where(team_users: {user_id: user_id}).present? else From 004f5a096deec35cba76f466519e6383e9ef7c48 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 12:24:22 +0800 Subject: [PATCH 06/28] =?UTF-8?q?fixed=20=E9=A1=B9=E7=9B=AEmember=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0bot=E8=AE=BF=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/concerns/project_operable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/concerns/project_operable.rb b/app/models/concerns/project_operable.rb index 31d16dc9e..4fee9ea33 100644 --- a/app/models/concerns/project_operable.rb +++ b/app/models/concerns/project_operable.rb @@ -95,7 +95,7 @@ module ProjectOperable # 安装bot后的权限 def is_install_bot?(user) - user.platform == "bot" && BotInstall.joins(:bot).where(bot: { uid: user_id }).where(store_id: self.id).exists? + user.platform == "bot" && BotInstall.joins(:bot).where(bot: { uid: user.id }).where(store_id: self.id).exists? end def member?(user_id) From 844d121c7f2c7cd858f57931c8cbcc5968782012 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 4 Apr 2023 14:00:09 +0800 Subject: [PATCH 07/28] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E6=88=90=E5=8A=9F=E4=B9=8B=E5=90=8E=E6=B8=85=E9=99=A4?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/accounts_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 4a104129b..f70cd5773 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -207,7 +207,8 @@ class AccountsController < ApplicationController successful_authentication(@user) sync_pwd_to_gitea!(@user, {password: params[:password].to_s}) # TODO用户密码未同步 - + LimitForbidControl::UserLogin.new(user).clear + # session[:user_id] = @user.id end From 1e3fd4dfbcf6cd78e88b732408f933eb4b02117c Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 4 Apr 2023 14:02:50 +0800 Subject: [PATCH 08/28] fix --- 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 f70cd5773..2046dfa20 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -205,9 +205,9 @@ class AccountsController < ApplicationController return end + LimitForbidControl::UserLogin.new(@user).clear successful_authentication(@user) sync_pwd_to_gitea!(@user, {password: params[:password].to_s}) # TODO用户密码未同步 - LimitForbidControl::UserLogin.new(user).clear # session[:user_id] = @user.id end From 5302490d609259cda814781f196ce9f08bfc3ef5 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 14:37:09 +0800 Subject: [PATCH 09/28] =?UTF-8?q?fixed=20bot=E5=AE=89=E8=A3=85=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index f7bf4f0d6..74d66ce7f 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -16,7 +16,8 @@ class InstallationsController < ApplicationController end def repositories - @install_bots = BotInstall.where(:installer_id => current_user.id) + bot = Bot.find_by(uid: current_user.id) + @install_bots = BotInstall.where(:installer_id => bot.owner_id) end def update_secret From 1b183811dd2d801b22152aa4563b05517d0d8fe8 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 14:39:51 +0800 Subject: [PATCH 10/28] =?UTF-8?q?fixed=20bot=E5=AE=89=E8=A3=85=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index 74d66ce7f..a08174022 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -17,7 +17,7 @@ class InstallationsController < ApplicationController def repositories bot = Bot.find_by(uid: current_user.id) - @install_bots = BotInstall.where(:installer_id => bot.owner_id) + @install_bots = BotInstall.where(bot_id: bot.id).where(:installer_id => bot.owner_id) end def update_secret From 1d2ea48812aee74b75076a65b5847b69880ac48a Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 15:30:28 +0800 Subject: [PATCH 11/28] =?UTF-8?q?fixed=20bot=E5=AE=89=E8=A3=85=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E5=88=97=E8=A1=A8=EF=BC=8C=E4=B8=8Egithub=E5=B7=AE?= =?UTF-8?q?=E5=BC=82=EF=BC=8C=E6=89=80=E4=BB=A5=E5=8F=96=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=92=8Cbot=E5=AF=B9=E5=BA=94=E6=89=80?= =?UTF-8?q?=E6=9C=89=E7=9A=84=E4=BB=93=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index a08174022..a87916271 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -16,8 +16,10 @@ class InstallationsController < ApplicationController end def repositories + # 与github差异,所以取安装用户和bot对应所有的仓库 + install_bot = BotInstall.find params[:id] bot = Bot.find_by(uid: current_user.id) - @install_bots = BotInstall.where(bot_id: bot.id).where(:installer_id => bot.owner_id) + @install_bots = BotInstall.where(bot_id: bot.id).where(:installer_id => install_bot.installer_id) end def update_secret From c2cda6a4a29337102bdf4d2f27117b3975b2121b Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 15:30:39 +0800 Subject: [PATCH 12/28] =?UTF-8?q?fixed=20bot=E5=AE=89=E8=A3=85=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E5=88=97=E8=A1=A8=EF=BC=8C=E4=B8=8Egithub=E5=B7=AE?= =?UTF-8?q?=E5=BC=82=EF=BC=8C=E6=89=80=E4=BB=A5=E5=8F=96=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=92=8Cbot=E5=AF=B9=E5=BA=94=E6=89=80?= =?UTF-8?q?=E6=9C=89=E7=9A=84=E4=BB=93=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index dea64f215..d9990c523 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1080,7 +1080,7 @@ Rails.application.routes.draw do end resources :installations, only: [] do - get :repositories, on: :collection + get :repositories, on: :member end root 'main#index' From b9998ecf4bd3a0ff79a666e1dacf6ecfdaa4ce9d Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 4 Apr 2023 16:13:31 +0800 Subject: [PATCH 13/28] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E4=BD=BF=E7=94=A8tip=5Fexception?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/concerns/api/project_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/concerns/api/project_helper.rb b/app/controllers/concerns/api/project_helper.rb index 44cac08c7..56f826b55 100644 --- a/app/controllers/concerns/api/project_helper.rb +++ b/app/controllers/concerns/api/project_helper.rb @@ -1,7 +1,7 @@ module Api::ProjectHelper extend ActiveSupport::Concern - def load_project + def load_project namespace = params[:owner] repo = params[:repo] @@ -14,7 +14,7 @@ module Api::ProjectHelper else logger.info "###########:project not found" @project = nil - render_not_found and return + tip_exception(404, '您访问的页面不存在或已被删除') end @project end From a3093c82c6e1d8f024ce3e949b0238cf29431894 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 16:55:30 +0800 Subject: [PATCH 14/28] =?UTF-8?q?fixed=20bot=E5=AE=89=E8=A3=85id=E6=8D=A2?= =?UTF-8?q?=E6=88=90installer=5Fid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 25 ++++++++++++++++----- app/views/installations/index.json.jbuilder | 7 ++---- app/views/installations/show.json.jbuilder | 2 +- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index a87916271..76984ee58 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -8,18 +8,17 @@ class InstallationsController < ApplicationController end def index - @install_bots = BotInstall.where(:installer_id => current_user.id) + @install_bots = BotInstall.where(bot_id: get_bot_id) end def show - @install_bot = BotInstall.find params[:id] + @install_bot = BotInstall.find_by(bot_id: get_bot_id, installer_id: params[:id]) || BotInstall.find_by(id: params[:id]) + tip_exception "参数installer_id错误" if @install_bot.blank? end def repositories # 与github差异,所以取安装用户和bot对应所有的仓库 - install_bot = BotInstall.find params[:id] - bot = Bot.find_by(uid: current_user.id) - @install_bots = BotInstall.where(bot_id: bot.id).where(:installer_id => install_bot.installer_id) + @install_bots = BotInstall.where(bot_id: get_bot_id).where(installer_id: params[:id]) end def update_secret @@ -60,11 +59,13 @@ class InstallationsController < ApplicationController @install_bot.update_attributes!(state: 0) render_ok end + def unsuspended @install_bot = BotInstall.find params[:id] @install_bot.update_attributes!(state: 1) render_ok end + def auth_active begin @bot = Bot.find params[:id] @@ -89,7 +90,8 @@ class InstallationsController < ApplicationController end def access_tokens - @install_bot = BotInstall.find params[:id] + @install_bot = BotInstall.find_by(bot_id: get_bot_id, installer_id: params[:id]) || BotInstall.find_by(id: params[:id]) + tip_exception "参数installer_id错误" if @install_bot.blank? @bot = @install_bot.bot @application = Doorkeeper::Application.find_by(uid: @bot.client_id, secret: @bot.client_secret) tip_exception("该Bot未激活") if @application.blank? @@ -104,5 +106,16 @@ class InstallationsController < ApplicationController render_ok(token: @access_token.token) end + private + + def get_bot_id + header = request.authorization + pattern = /^Bearer /i + token = header.gsub(pattern, "") + decoded_token = JWT.decode token, nil, false + # 前面已验证token有效期和正确性 + decoded_token[0]["iss"] + end + end diff --git a/app/views/installations/index.json.jbuilder b/app/views/installations/index.json.jbuilder index 2163567ed..532f4c91f 100644 --- a/app/views/installations/index.json.jbuilder +++ b/app/views/installations/index.json.jbuilder @@ -2,10 +2,7 @@ json.status 0 json.message "success" json.data do json.array! @install_bots do |install_bot| - json.installation_id install_bot.id - json.extract! install_bot.bot, :id, :name - json.bot_id install_bot.bot.id - json.bot_name install_bot.bot.name - + json.extract! install_bot, :id, :bot_id, :installer_id, :state, :create_time, :update_time + json.bot_name install_bot&.bot&.name end end \ No newline at end of file diff --git a/app/views/installations/show.json.jbuilder b/app/views/installations/show.json.jbuilder index 33c7ba206..ee605b860 100644 --- a/app/views/installations/show.json.jbuilder +++ b/app/views/installations/show.json.jbuilder @@ -1,5 +1,5 @@ json.partial! "commons/success" json.extract! @install_bot, :id, :bot_id, :installer_id, :state, :create_time, :update_time -json.bot_name @install_bot.bot.name +json.bot_name @install_bot&.bot&.name From 7fdbc3dad1044d3db4ffb4dfcb85516f976278d3 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 4 Apr 2023 16:57:54 +0800 Subject: [PATCH 15/28] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Aapi=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E5=AE=98=E7=BD=91=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/docs/api.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/docs/api.html b/public/docs/api.html index ed8ee0500..88dfceb72 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -719,7 +719,7 @@ http://localhost:3000/api/licenses
await octokit.request('GET /api/licenses')
 

HTTP Request

-

GET https://forgeplus.trustie.net/api/licenses.json

+

GET https://www.gitlink.org.cn/api/licenses.json

请求参数

From 4f87c0697697b1df8c0d43a36fb7e11b5c32d1f4 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 17:15:45 +0800 Subject: [PATCH 16/28] =?UTF-8?q?fixed=20bot=E5=AE=89=E8=A3=85=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=8C=89=E5=AE=89=E8=A3=85=E8=80=85=E5=88=86=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 2 +- app/views/installations/index.json.jbuilder | 2 +- app/views/installations/show.json.jbuilder | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index 76984ee58..f13f7f459 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -8,7 +8,7 @@ class InstallationsController < ApplicationController end def index - @install_bots = BotInstall.where(bot_id: get_bot_id) + @install_bots = BotInstall.where(bot_id: get_bot_id).group(:installer_id) end def show diff --git a/app/views/installations/index.json.jbuilder b/app/views/installations/index.json.jbuilder index 532f4c91f..9235bd4f8 100644 --- a/app/views/installations/index.json.jbuilder +++ b/app/views/installations/index.json.jbuilder @@ -2,7 +2,7 @@ json.status 0 json.message "success" json.data do json.array! @install_bots do |install_bot| - json.extract! install_bot, :id, :bot_id, :installer_id, :state, :create_time, :update_time + json.extract! install_bot, :id, :bot_id, :installer_id json.bot_name install_bot&.bot&.name end end \ No newline at end of file diff --git a/app/views/installations/show.json.jbuilder b/app/views/installations/show.json.jbuilder index ee605b860..89db0107b 100644 --- a/app/views/installations/show.json.jbuilder +++ b/app/views/installations/show.json.jbuilder @@ -1,5 +1,5 @@ json.partial! "commons/success" -json.extract! @install_bot, :id, :bot_id, :installer_id, :state, :create_time, :update_time +json.extract! @install_bot, :id, :bot_id, :installer_id json.bot_name @install_bot&.bot&.name From e18063d7ca0ce2fe113e6e0aeb20364889d5da86 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 17:20:33 +0800 Subject: [PATCH 17/28] =?UTF-8?q?fixed=20bot=E5=AE=89=E8=A3=85=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=8C=89=E5=AE=89=E8=A3=85=E8=80=85=E5=88=86=E7=BB=84?= =?UTF-8?q?,=E5=A2=9E=E5=8A=A0=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/installations/index.json.jbuilder | 10 +++++++++- app/views/installations/show.json.jbuilder | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/views/installations/index.json.jbuilder b/app/views/installations/index.json.jbuilder index 9235bd4f8..366bdeeca 100644 --- a/app/views/installations/index.json.jbuilder +++ b/app/views/installations/index.json.jbuilder @@ -2,7 +2,15 @@ json.status 0 json.message "success" json.data do json.array! @install_bots do |install_bot| - json.extract! install_bot, :id, :bot_id, :installer_id + json.extract! install_bot, :id, :bot_id, :installer_id, :create_time, :update_time json.bot_name install_bot&.bot&.name + json.account do + user = User.find_by(id: install_bot.installer_id) + if user.present? + json.partial! "api/v1/users/simple_user", locals: {user: user} + else + json.nil! + end + end end end \ No newline at end of file diff --git a/app/views/installations/show.json.jbuilder b/app/views/installations/show.json.jbuilder index 89db0107b..4ab91c1e4 100644 --- a/app/views/installations/show.json.jbuilder +++ b/app/views/installations/show.json.jbuilder @@ -1,5 +1,13 @@ json.partial! "commons/success" -json.extract! @install_bot, :id, :bot_id, :installer_id +json.extract! @install_bot, :id, :bot_id, :installer_id, :create_time, :update_time json.bot_name @install_bot&.bot&.name +json.account do + user = User.find_by(id: @install_bot.installer_id) + if user.present? + json.partial! "api/v1/users/simple_user", locals: { user: user } + else + json.nil! + end +end From 04c30be5a6160d65bf63d29b449b6cec7e45a3dd Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 17:33:16 +0800 Subject: [PATCH 18/28] =?UTF-8?q?fixed=20bot=E5=AE=89=E8=A3=85log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index f13f7f459..7d47b2917 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -112,6 +112,7 @@ class InstallationsController < ApplicationController header = request.authorization pattern = /^Bearer /i token = header.gsub(pattern, "") + Rails.logger.info("request.authorization==#{request.authorization}") decoded_token = JWT.decode token, nil, false # 前面已验证token有效期和正确性 decoded_token[0]["iss"] From 80fa5330b2e374587eca29b5e835ac6a41bc517d Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 17:38:48 +0800 Subject: [PATCH 19/28] =?UTF-8?q?fixed=20bot=E5=AE=89=E8=A3=85=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E5=88=97=E8=A1=A8=E5=BF=85=E9=A1=BB=E4=BD=BF=E7=94=A8?= =?UTF-8?q?access=5Ftokens=E8=8E=B7=E5=8F=96=E5=88=B0bot=E7=9A=84token?= =?UTF-8?q?=E6=89=8D=E8=83=BD=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 5 +- test/jwt_github_test.rb | 32 +++++++++++ test/jwt_test.rb | 59 ++++++++++++--------- 3 files changed, 71 insertions(+), 25 deletions(-) create mode 100644 test/jwt_github_test.rb diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index 7d47b2917..85e2da5cb 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -18,7 +18,10 @@ class InstallationsController < ApplicationController def repositories # 与github差异,所以取安装用户和bot对应所有的仓库 - @install_bots = BotInstall.where(bot_id: get_bot_id).where(installer_id: params[:id]) + # 必须使用access_tokens获取到bot的token才能查询 + tip_exception "Token无效" if current_user.platform != "bot" + bot = Bot.find_by(uid: current_user.id) + @install_bots = BotInstall.where(bot_id: bot.id).where(installer_id: params[:id]) end def update_secret diff --git a/test/jwt_github_test.rb b/test/jwt_github_test.rb new file mode 100644 index 000000000..ad1d41177 --- /dev/null +++ b/test/jwt_github_test.rb @@ -0,0 +1,32 @@ +require 'openssl' +require 'jwt' # https://rubygems.org/gems/jwt + +# Private key contents +private_pem = File.read("/Users/xxq/Documents/gitlink-webhook.2022-06-09.private-key.pem") +private_key = OpenSSL::PKey::RSA.new(private_pem) + +# Generate the JWT +payload = { + # issued at time, 60 seconds in the past to allow for clock drift + iat: Time.now.to_i - 60, + # JWT expiration time (10 minute maximum) + exp: Time.now.to_i + (10 * 60), + # GitHub App's identifier + iss: "209248" +} + +jwt = JWT.encode(payload, private_key, "RS256") +puts jwt +# puts OpenSSL::PKey::RSA.new(private_key33).public_key.to_s +# +# rsa_private = OpenSSL::PKey::RSA.new(private_key33) +# rsa_public = rsa_private.public_key +# +# + +# puts decoded_token[0] +# puts decoded_token[0]["iss"] + +# serialized_private_key = OpenSSL::PKey::RSA::generate(2048).to_s + + diff --git a/test/jwt_test.rb b/test/jwt_test.rb index 8d0faaa3f..7ea6dc8f3 100644 --- a/test/jwt_test.rb +++ b/test/jwt_test.rb @@ -2,12 +2,35 @@ require 'openssl' require 'jwt' # https://rubygems.org/gems/jwt # Private key contents -private_pem = File.read("/Users/xxq/Documents/gitlink-webhook.2022-06-09.private-key.pem") - -private_key22="-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEApOebWmRV/ooNq5Ks04YnDU7pEezGShGvaiF0cIvn9jvmYHu0\nFialojvJV3VpB6xE6QBPXZ0Pi1lokZ9dMx8F5UWNx9WA7wf7xK3hAJLNml+GeewF\nou8vk/Ry7n6diLxETNVd7YzPvztn5qaMp/DXa+65i11H8a/XXqR7kCVnCevVlufh\nNr/Dp6dW31W8TInnDQasJFMZ8GY7f+tCwLXNc0M8p+TeDp9xmXHOrEB+S/mgbUOF\nXgRr6icbMmlT9bsAxYHrrDkcVxJhs0hq5vD3BaoK06gcZEnN7/HVNzgVSOYNsVNh\n9006cMgDSOwc9F8aulP7cr8k74INq1xswoGs9wIDAQABAoIBAHayc2NkF3YJXv+h\nqx7yUEfHBgKuAKiuBCqLfCnKuqPFx/So9h5/oPeeuzVlwL0SJePlIjuK4vZ128v9\n/vLeILtADmbJ6m2jvHh8hBmKkc3Ndplp50C5k/CWoufCYZhbk3oOlvZ3Rc4rb4VZ\nWqNDu3voMMv8z91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zBGZBfNQt4DQH9qR4l43c6NNkisWA9rvXvCDqXKmBq7wfpnkYr\n4Ul2hXYmsPJjP8e0BfG54PaSu3BDBMJMtcgDktMCgYBvzyDdnwdgVyc3tHgGbMFk\n1HHAAfT/ArrrxpsIFz+TJ8lAY92JGDGwENhO2TLrCAAXTYY5657w/GbFKzgj5y1m\nqKIekOzm2WjLApZ5h6L/zEUhuRVwf2s+0AP82qWIpFlNIP9yGeNs0qpUQ8q6/13O\nLuXL/3on8nq3S8LSwgv3/QKBgDfM+g7d5ouAnU29uH9/54Wo5pIVMxzYO4Gt2GIO\nvnirYz6hfCbHOwJJ3gPGRKPmkfjROC59E6F5iv48mF3w0M28MGn4N47VRSmGzwWZ\nJeTQhDDBFCxeZ45Xn2Xln9Cw15xUDwmzi7zhSMUtdkUK0x3q0a1xfLtgWE775lhl\njjzpAoGAdUXFW1elfjXpfIYZf7vUV7MPquKL7qAcopd96XBszhOn7g+ibzem+wgt\n1UTSeOBESYANHeJk2MuWPSRXk/FlQETVIcPAEp0kxbwQE+7YEdrMVeDcIe5lPwGD\n+WuS3kg0MPgUrXZXn74gcwWmSIOyHfqXULqOxWE25uU2icdV+2w=\n-----END RSA PRIVATE KEY-----\n" -private_key = OpenSSL::PKey::RSA.new(private_key33) -# puts private_key.to_json +# private_pem = File.read("/Users/xxq/Documents/gitlink-webhook.2022-06-09.private-key.pem") +private_pem = "-----BEGIN RSA PRIVATE KEY----- +MIIEowIBAAKCAQEAy3rJwhzC9K5f4Rc6KwYQKvdsUsbzrKdENBCjGq0kZ8LJltw+ +TRuLVp0hwrWXS9msadjBnzatYneBrqnggj87pU0Mf/f6KkTmIsFH2gDKNMN6hRg/ +JW5XXveexGa9dZIQHPKOmp9dC+YpLHOPRO0NsYJM/JoQ4rWRhtMvq0zR/fJDuXyt +xLehfH4N4ppVbdRGaK+FIKNCjHTmL/3jZ0b2J9D4Al9R5QWlEmRPa4ZFCOZNUMXK +nplNu2FE/ZjyKjE+f0MAn8hcSVR25X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qOqrLGYKUkM5v31jTRcnttzlYibOwoBriGbCIEv3yFFASuJKkjRRn1w +j1yhAoGBALqwZzRAle7t2jEWOyLaJeHUoSiZJv5dHOMRog7k5H24uTEKf3JCovQO +wZd4cIA4oXD/3b5cK3H2e5YjhBunsMRhRBLgz8FD4y69cKxbcgPvtjhkwYRB0/cy +21dHe2o7HfuZgUuh0kOlT0e326gQPIIlwuCBEAq6LzWrg8nd9Loz +-----END RSA PRIVATE KEY-----" +private_key = OpenSSL::PKey::RSA.new(private_pem) # Generate the JWT payload = { @@ -16,27 +39,15 @@ payload = { # JWT expiration time (10 minute maximum) exp: Time.now.to_i + (10 * 60), # GitHub App's identifier - iss: "782" + iss: "803" } jwt = JWT.encode(payload, private_key, "RS256") puts jwt -# puts OpenSSL::PKey::RSA.new(private_key33).public_key.to_s -# -rsa_private = OpenSSL::PKey::RSA.new(private_key33) -rsa_public = rsa_private.public_key - -# decoded_token = JWT.decode jwt, nil, false -begin - decoded_token = JWT.decode jwt, rsa_private, true, { algorithm: 'RS256' } -rescue JWT::DecodeError - puts "jwt is not mmmmmm" -end - -# -puts decoded_token[0] -puts decoded_token[0]["iss"] - -# serialized_private_key = OpenSSL::PKey::RSA::generate(2048).to_s + + +decoded_token = JWT.decode "eyJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE2ODA1OTkzNDAsImV4cCI6MTY4MDYwMDAwMCwiaXNzIjoiODAzIn0.wOCCMVbrulTVCIKDvmLtxCkTLtWJMGmY2mIZgfdJcKcixqZek1y_9YD7wF07wqP6qTjQaNiSDjdJSDGzO_Qi3qQT_2BaR6EWBUIcbaNz5GTHKLcOW4SFWj13OFJwjom6egz489b6qA3MPXmliWYR6F5zlLu1jlXjaWVvUZAy0AuAdmWiSocdjurt_giEIDefiRcPu_NbccWG-mAwa9wV9ja2PoZUJyHlzXR6rioLIO1rtw5bIX3E4YNPde9EkEK1eYLmedmhKfwlgX2CgdGodSHPg5Vro09XWiGaJkBwoi1T41BLVsb5hxqQc3DLrz1ZFFY1vXEkxIw4BIXitpk3kg", nil, false +puts decoded_token +puts Time.now.to_i - 60 - decoded_token[0]["exp"].to_i > 0 From bbc113ec1bd4c10c1775d27662b394792e19afb1 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 17:39:12 +0800 Subject: [PATCH 20/28] =?UTF-8?q?=E5=88=A0=E9=99=A4log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index 85e2da5cb..f4640fb61 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -115,7 +115,6 @@ class InstallationsController < ApplicationController header = request.authorization pattern = /^Bearer /i token = header.gsub(pattern, "") - Rails.logger.info("request.authorization==#{request.authorization}") decoded_token = JWT.decode token, nil, false # 前面已验证token有效期和正确性 decoded_token[0]["iss"] From 13148890ecb4fb3c9dc73d1cbf87a67f53783c13 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 17:40:53 +0800 Subject: [PATCH 21/28] =?UTF-8?q?token=E8=A7=A3=E5=AF=86=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index f4640fb61..807554fb1 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -19,7 +19,7 @@ class InstallationsController < ApplicationController def repositories # 与github差异,所以取安装用户和bot对应所有的仓库 # 必须使用access_tokens获取到bot的token才能查询 - tip_exception "Token无效" if current_user.platform != "bot" + tip_exception "无效Token" if current_user.platform != "bot" bot = Bot.find_by(uid: current_user.id) @install_bots = BotInstall.where(bot_id: bot.id).where(installer_id: params[:id]) end @@ -118,6 +118,9 @@ class InstallationsController < ApplicationController decoded_token = JWT.decode token, nil, false # 前面已验证token有效期和正确性 decoded_token[0]["iss"] + rescue JWT::DecodeError + Rails.logger.error "jwt token decode error:#{token}" + tip_exception("无效Token") end end From fccd6bb950e215eb74274e671c397e8430343f1c Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 4 Apr 2023 17:45:45 +0800 Subject: [PATCH 22/28] =?UTF-8?q?jwt=5Ftoken=E6=9C=89=E6=95=88=E6=9C=9F?= =?UTF-8?q?=E5=BB=B6=E9=95=BF=E5=88=B010=E5=88=86=E9=92=9F=EF=BC=8C?= =?UTF-8?q?=E9=98=B2=E6=AD=A2=E6=9C=8D=E5=8A=A1=E5=99=A8=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E8=AF=AF=E5=B7=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/bot.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/bot.rb b/app/models/bot.rb index 2098ac1e2..13ac70a78 100644 --- a/app/models/bot.rb +++ b/app/models/bot.rb @@ -36,7 +36,7 @@ class Bot < ApplicationRecord def self.decode_jwt_token(token) decoded_token = JWT.decode token, nil, false - return [nil, "Token已过期"] if Time.now.to_i - 60 - decoded_token[0]["exp"].to_i > 0 + return [nil, "Token已过期"] if Time.now.to_i - 10*60 - decoded_token[0]["exp"].to_i > 0 bot = Bot.find_by(id: decoded_token[0]["iss"]) return [nil, "Token不存在"] if bot.blank? rsa_private = OpenSSL::PKey::RSA.new(bot.private_key) From 63196e018a3874641f01ac73d8e8f82fe3b38d92 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 6 Apr 2023 16:47:23 +0800 Subject: [PATCH 23/28] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E9=A1=B9=E7=9B=AE=E6=A0=87=E8=AF=86=E6=AD=A3=E5=88=99?= =?UTF-8?q?=E8=A7=84=E5=88=99=E4=BB=A5=E5=8F=8A=E5=B8=A6.=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E6=97=A0=E6=B3=95=E6=AD=A3=E5=B8=B8=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/libs/custom_regexp.rb | 2 +- config/routes.rb | 4 ++-- config/routes/api.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/libs/custom_regexp.rb b/app/libs/custom_regexp.rb index 889da4df8..1bfeb4b71 100644 --- a/app/libs/custom_regexp.rb +++ b/app/libs/custom_regexp.rb @@ -10,6 +10,6 @@ module CustomRegexp IP = /^((\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3}(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])$/ URL_REGEX = /\A(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?\z/i - REPOSITORY_NAME_REGEX = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾 + REPOSITORY_NAME_REGEX = /^[a-zA-Z0-9][a-zA-Z0-9\-\_\.]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾 MD_REGEX = /^.+(\.[m|M][d|D])$/ end diff --git a/config/routes.rb b/config/routes.rb index 0d29e403f..7e69c2e38 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -451,7 +451,7 @@ Rails.application.routes.draw do namespace :traces do resources :trace_users, only: [:create] - scope "/:owner/:repo" do + scope "/:owner/:repo", constraints: { repo: /[^\/]+/ } do resource :projects, path: '/', only: [:index] do member do post :tasks @@ -464,7 +464,7 @@ Rails.application.routes.draw do end # Project Area START - scope "/:owner/:repo" do + scope "/:owner/:repo",constraints: { repo: /[^\/]+/ } do scope do get( '/activity', diff --git a/config/routes/api.rb b/config/routes/api.rb index 6e688a632..f39fa76c5 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -18,7 +18,7 @@ defaults format: :json do resources :feedbacks, only: [:create] end - scope ':repo' do + scope ':repo', constraints: { repo: /[^\/]+/ } do # projects resource :projects, path: '/', only: [:show, :update, :edit, :destroy] do collection do From 43292362376d86823157ca8c5ad1d30c2f381aa8 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 7 Apr 2023 10:32:57 +0800 Subject: [PATCH 24/28] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9Arouter?= =?UTF-8?q?=E5=8C=B9=E9=85=8D.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/routes.rb | 4 ++-- config/routes/api.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 7e69c2e38..2206f2846 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -451,7 +451,7 @@ Rails.application.routes.draw do namespace :traces do resources :trace_users, only: [:create] - scope "/:owner/:repo", constraints: { repo: /[^\/]+/ } do + scope "/:owner/:repo", constraints: { repo: /[^\/|.json]+/ } do resource :projects, path: '/', only: [:index] do member do post :tasks @@ -464,7 +464,7 @@ Rails.application.routes.draw do end # Project Area START - scope "/:owner/:repo",constraints: { repo: /[^\/]+/ } do + scope "/:owner/:repo",constraints: { repo: /[^\/|.json]+/ } do scope do get( '/activity', diff --git a/config/routes/api.rb b/config/routes/api.rb index f39fa76c5..ccc80abe3 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -18,7 +18,7 @@ defaults format: :json do resources :feedbacks, only: [:create] end - scope ':repo', constraints: { repo: /[^\/]+/ } do + scope ':repo', constraints: { repo: /[^\/|.json]+/ } do # projects resource :projects, path: '/', only: [:show, :update, :edit, :destroy] do collection do From 39a851b74bfebd0ff27254b8ec1b27aaf441f81e Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 7 Apr 2023 10:35:44 +0800 Subject: [PATCH 25/28] =?UTF-8?q?=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/routes.rb | 4 ++-- config/routes/api.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 2206f2846..7e69c2e38 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -451,7 +451,7 @@ Rails.application.routes.draw do namespace :traces do resources :trace_users, only: [:create] - scope "/:owner/:repo", constraints: { repo: /[^\/|.json]+/ } do + scope "/:owner/:repo", constraints: { repo: /[^\/]+/ } do resource :projects, path: '/', only: [:index] do member do post :tasks @@ -464,7 +464,7 @@ Rails.application.routes.draw do end # Project Area START - scope "/:owner/:repo",constraints: { repo: /[^\/|.json]+/ } do + scope "/:owner/:repo",constraints: { repo: /[^\/]+/ } do scope do get( '/activity', diff --git a/config/routes/api.rb b/config/routes/api.rb index ccc80abe3..f39fa76c5 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -18,7 +18,7 @@ defaults format: :json do resources :feedbacks, only: [:create] end - scope ':repo', constraints: { repo: /[^\/|.json]+/ } do + scope ':repo', constraints: { repo: /[^\/]+/ } do # projects resource :projects, path: '/', only: [:show, :update, :edit, :destroy] do collection do From eabf40468291e1bda4ab2cec6050cfeac51fc212 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 7 Apr 2023 10:57:13 +0800 Subject: [PATCH 26/28] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E9=A1=B9=E7=9B=AE=E6=8E=92=E9=99=A4.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/project.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 54d6ac520..4a356cbc7 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -380,7 +380,13 @@ class Project < ApplicationRecord user = Owner.find_by_login namespace_path user = User.new(login: namespace_path) if user.nil? - project = user&.projects&.find_by(identifier: identifier) || Project.find_by(identifier: "#{namespace_path}/#{identifier}") + if identifier.end_with?('.json') + project = user&.projects&.find_by(identifier: identifier) || Project.find_by(identifier: "#{namespace_path}/#{identifier}") + identifier = identifier.sub(/.*\K.json/, '') + project = user&.projects&.find_by(identifier: identifier) || Project.find_by(identifier: "#{namespace_path}/#{identifier}") + else + project = user&.projects&.find_by(identifier: identifier) || Project.find_by(identifier: "#{namespace_path}/#{identifier}") + end return nil if project.blank? [project, user] From d8eba81afd78783598f0b30285260d12b84c956d Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 7 Apr 2023 11:13:17 +0800 Subject: [PATCH 27/28] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Awebhook?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E6=95=B0=E6=8D=AE=E7=89=B9=E6=AE=8A=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../projects/webhooks/_simple_gitea_detail.json.jbuilder | 7 ++++++- app/views/projects/webhooks/edit.json.jbuilder | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/views/api/v1/projects/webhooks/_simple_gitea_detail.json.jbuilder b/app/views/api/v1/projects/webhooks/_simple_gitea_detail.json.jbuilder index 96c9eac12..09f9565a4 100644 --- a/app/views/api/v1/projects/webhooks/_simple_gitea_detail.json.jbuilder +++ b/app/views/api/v1/projects/webhooks/_simple_gitea_detail.json.jbuilder @@ -3,7 +3,12 @@ json.type webhook["type"] json.content_type webhook['config']['content_type'] json.http_method webhook['config']['http_method'] json.url webhook['config']['url'] -json.events webhook['events'] +event = webhook.events +if event["send_everything"] + json.events event["events"].keys.collect{|i| %w(pull_request issues).include?(i) ? i + "_only" : i} +else + json.events event["events"].select{|k, v| v}.keys.collect{|i| %w(pull_request issues).include?(i) ? i + "_only" : i} +end json.active webhook['active'] json.branch_filter webhook['branch_filter'] json.created_at format_time(webhook['created_at'].to_time) \ No newline at end of file diff --git a/app/views/projects/webhooks/edit.json.jbuilder b/app/views/projects/webhooks/edit.json.jbuilder index c54d10306..4085e2a64 100644 --- a/app/views/projects/webhooks/edit.json.jbuilder +++ b/app/views/projects/webhooks/edit.json.jbuilder @@ -5,7 +5,7 @@ json.create_time Time.at(@webhook.created_unix).strftime("%Y-%m-%d %H:%M:%S") event = @webhook.events json.branch_filter event["branch_filter"] if event["send_everything"] - json.events event["events"].keys.collect{|i| i == "pull_request" ? i + "_only" : i} + json.events event["events"].keys.collect{|i| %w(pull_request issues).include?(i) ? i + "_only" : i} else - json.events event["events"].select{|k, v| v}.keys.collect{|i| i == "pull_request" ? i + "_only" : i} + json.events event["events"].select{|k, v| v}.keys.collect{|i| %w(pull_request issues).include?(i) ? i + "_only" : i} end From 60b0ee6b28e9dac5479dd5e672f17626e81662bc Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 7 Apr 2023 11:27:19 +0800 Subject: [PATCH 28/28] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=A0=87=E8=AF=86=E6=8F=90=E7=A4=BA=E8=AF=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/forms/projects/create_form.rb | 2 +- app/forms/projects/migrate_form.rb | 2 +- app/forms/projects/update_form.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/forms/projects/create_form.rb b/app/forms/projects/create_form.rb index c51c2c60f..28cb296c0 100644 --- a/app/forms/projects/create_form.rb +++ b/app/forms/projects/create_form.rb @@ -3,7 +3,7 @@ class Projects::CreateForm < BaseForm :project_language_id, :ignore_id, :license_id, :private, :owner validates :user_id, :name, :repository_name, presence: true - validates :repository_name, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" } + validates :repository_name, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "项目标识只能包含数字,字母,下划线(_),中划线(-),英文句号(.),必须以数字和字母开头,不能以下划线/中划线开头和结尾" } validates :name, length: { maximum: 50 } validates :repository_name, length: { maximum: 100 } diff --git a/app/forms/projects/migrate_form.rb b/app/forms/projects/migrate_form.rb index ccd854478..c3684c2ef 100644 --- a/app/forms/projects/migrate_form.rb +++ b/app/forms/projects/migrate_form.rb @@ -3,7 +3,7 @@ class Projects::MigrateForm < BaseForm :project_language_id, :clone_addr, :private, :is_mirror, :auth_username, :auth_password, :owner validates :user_id, :name, :repository_name, :clone_addr, presence: true - validates :repository_name, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" } + validates :repository_name, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "项目标识只能包含数字,字母,下划线(_),中划线(-),英文句号(.),必须以数字和字母开头,不能以下划线/中划线开头和结尾" } validates :clone_addr, format: { with: CustomRegexp::URL_REGEX, multiline: true, message: "地址格式不正确" } validates :name, length: { maximum: 50 } validates :repository_name, length: { maximum: 100 } diff --git a/app/forms/projects/update_form.rb b/app/forms/projects/update_form.rb index a351420bc..2490fbed6 100644 --- a/app/forms/projects/update_form.rb +++ b/app/forms/projects/update_form.rb @@ -3,7 +3,7 @@ class Projects::UpdateForm < BaseForm validates :name, presence: true validates :name, length: { maximum: 50 } validates :description, length: { maximum: 200 } - validates :identifier, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" } + validates :identifier, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: '项目标识只能包含数字,字母,下划线(_),中划线(-),英文句号(.),必须以数字和字母开头,不能以下划线/中划线开头和结尾' } validate do check_project_category(project_category_id)