From ed7c5b0a2d9d0748b92f3b3a3a01d47a0383634c Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 5 Dec 2022 15:49:59 +0800 Subject: [PATCH 1/9] =?UTF-8?q?fixed=20=E7=AC=AC=E4=B8=89=E6=96=B9?= =?UTF-8?q?=E6=8E=88=E6=9D=83gitee=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/initializers/omniauth.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index 543b2249f..9ae36427e 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -1,10 +1,11 @@ config = Rails.application.config_for(:configuration) OmniAuth.config.add_camelization 'qq', 'QQ' if config.dig("oauth", "qq") -OmniAuth.config.add_camelization 'github', 'GitHub' if config.dig("oauth", "github") -OmniAuth.config.add_camelization 'gitee', 'Gitee' if config.dig("oauth", "gitee") -OmniAuth.config.add_camelization 'wechat', 'Wechat' if config.dig("oauth", "wechat") +# OmniAuth.config.add_camelization 'github', 'GitHub' if config.dig("oauth", "github") +# OmniAuth.config.add_camelization 'gitee', 'Gitee' if config.dig("oauth", "gitee") +# OmniAuth.config.add_camelization 'wechat', 'Wechat' if config.dig("oauth", "wechat") OmniAuth.config.logger = Rails.logger +OmniAuth.config.request_validation_phase = nil OmniAuth.config.before_request_phase = nil OmniAuth.config.before_callback_phase = nil OmniAuth.config.on_failure = Proc.new { |env| @@ -22,6 +23,6 @@ Rails.application.config.middleware.use OmniAuth::Builder do provider :gitee, config.dig("oauth", "gitee", "appid"), config.dig("oauth", "gitee", "secret"), { provider_ignores_state: true, scope: "user_info emails" } end if config.dig("oauth", "wechat").present? - provider :gitee, config.dig("oauth", "wechat", "appid"), config.dig("oauth", "wechat", "secret"), { provider_ignores_state: true, scope: "snsapi_login" } + provider :wechat, config.dig("oauth", "wechat", "appid"), config.dig("oauth", "wechat", "secret"), { provider_ignores_state: true, scope: "snsapi_login" } end end From e41adbc4a8e0212841d7869da0421335f4a9d275 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 5 Dec 2022 15:50:57 +0800 Subject: [PATCH 2/9] =?UTF-8?q?fixed=20=E7=AC=AC=E4=B8=89=E6=96=B9?= =?UTF-8?q?=E6=8E=88=E6=9D=83gitee=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/initializers/omniauth.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index 9ae36427e..876dbad58 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -5,7 +5,6 @@ OmniAuth.config.add_camelization 'qq', 'QQ' if config.dig("oauth", "qq") # OmniAuth.config.add_camelization 'gitee', 'Gitee' if config.dig("oauth", "gitee") # OmniAuth.config.add_camelization 'wechat', 'Wechat' if config.dig("oauth", "wechat") OmniAuth.config.logger = Rails.logger -OmniAuth.config.request_validation_phase = nil OmniAuth.config.before_request_phase = nil OmniAuth.config.before_callback_phase = nil OmniAuth.config.on_failure = Proc.new { |env| From daf7514afe3e8752fb7c29dc24a24d9c18a7a3b9 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 5 Dec 2022 17:46:21 +0800 Subject: [PATCH 3/9] =?UTF-8?q?fixed=20=E7=AC=AC=E4=B8=89=E6=96=B9?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E7=99=BB=E5=BD=95=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/oauth/callbacks_controller.rb | 5 ++++- config/initializers/omniauth.rb | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/controllers/oauth/callbacks_controller.rb b/app/controllers/oauth/callbacks_controller.rb index 513563d23..b97fdc023 100644 --- a/app/controllers/oauth/callbacks_controller.rb +++ b/app/controllers/oauth/callbacks_controller.rb @@ -2,6 +2,7 @@ class Oauth::CallbacksController < Oauth::BaseController def create process_callback rescue Exception => e + Rails.logger.info "授权失败:#{e}" tip_exception("授权失败") end @@ -38,7 +39,9 @@ class Oauth::CallbacksController < Oauth::BaseController new_user = true login = build_login_name(platform, auth_hash.info.nickname) mail = "#{login}@example.org" if mail.blank? - reg_result = autologin_register(login, mail, "Ec#{login}2022#", platform, nil, nickname) + code = %W(0 1 2 3 4 5 6 7 8 9) + rand_password = code.sample(10).join + reg_result = autologin_register(login, mail, rand_password, platform, nil, nickname) Rails.logger.info("[OAuth2] omniauth.auth [reg_result] #{reg_result} ") if reg_result[:message].blank? open_user = "OpenUsers::#{platform.to_s.capitalize}".constantize.create!(user_id: reg_result[:user][:id], uid: uid, extra: auth_hash.extra) diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index 543b2249f..876dbad58 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -1,9 +1,9 @@ config = Rails.application.config_for(:configuration) OmniAuth.config.add_camelization 'qq', 'QQ' if config.dig("oauth", "qq") -OmniAuth.config.add_camelization 'github', 'GitHub' if config.dig("oauth", "github") -OmniAuth.config.add_camelization 'gitee', 'Gitee' if config.dig("oauth", "gitee") -OmniAuth.config.add_camelization 'wechat', 'Wechat' if config.dig("oauth", "wechat") +# OmniAuth.config.add_camelization 'github', 'GitHub' if config.dig("oauth", "github") +# OmniAuth.config.add_camelization 'gitee', 'Gitee' if config.dig("oauth", "gitee") +# OmniAuth.config.add_camelization 'wechat', 'Wechat' if config.dig("oauth", "wechat") OmniAuth.config.logger = Rails.logger OmniAuth.config.before_request_phase = nil OmniAuth.config.before_callback_phase = nil @@ -22,6 +22,6 @@ Rails.application.config.middleware.use OmniAuth::Builder do provider :gitee, config.dig("oauth", "gitee", "appid"), config.dig("oauth", "gitee", "secret"), { provider_ignores_state: true, scope: "user_info emails" } end if config.dig("oauth", "wechat").present? - provider :gitee, config.dig("oauth", "wechat", "appid"), config.dig("oauth", "wechat", "secret"), { provider_ignores_state: true, scope: "snsapi_login" } + provider :wechat, config.dig("oauth", "wechat", "appid"), config.dig("oauth", "wechat", "secret"), { provider_ignores_state: true, scope: "snsapi_login" } end end From 73d89a89e2c771a3eee4fe52ae910dad181b4671 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 6 Dec 2022 10:12:41 +0800 Subject: [PATCH 4/9] =?UTF-8?q?fixed=20=E7=AC=AC=E4=B8=89=E6=96=B9?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E7=99=BB=E5=BD=95=E9=85=8D=E7=BD=AEurl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/settings_controller.rb | 3 ++- config/routes.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index e365c3e29..de07ed8f2 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -76,11 +76,12 @@ class SettingsController < ApplicationController url: EducoderOauth.oauth_url, method: 'get' } + platform_url = Rails.application.config_for(:configuration)['platform_url'] config = Rails.application.config_for(:configuration) (config.dig("oauth").keys - ["educoder"]).each do |provider| @third_party_new << { name: provider, - url: "/auth/#{provider}", + url: "#{platform_url}/auth/#{provider}", method: 'post' } end diff --git a/config/routes.rb b/config/routes.rb index 0efac72c0..22773794c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,7 +20,7 @@ Rails.application.routes.draw do get 'attachments/download/:id', to: 'attachments#show' get 'attachments/download/:id/:filename', to: 'attachments#show' - get 'auth/qq/callback', to: 'oauth/qq#create' + # get 'auth/qq/callback', to: 'oauth/qq#create' get 'auth/failure', to: 'oauth/base#auth_failure' get 'auth/cas/callback', to: 'oauth/cas#create' get 'auth/:provider/callback', to: 'oauth/callbacks#create' From ee27c9020596b2f27ea6c2112b6682a3606d39e4 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 6 Dec 2022 10:24:48 +0800 Subject: [PATCH 5/9] =?UTF-8?q?fixed=20qq=E5=91=BD=E5=90=8D=E8=B0=83?= =?UTF-8?q?=E6=95=B4=EF=BC=8C=E6=96=B9=E4=BE=BF=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/open_users/qq.rb | 2 +- app/models/user.rb | 2 +- app/services/oauth/create_or_find_qq_account_service.rb | 4 ++-- config/routes.rb | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/open_users/qq.rb b/app/models/open_users/qq.rb index ef1a4b470..204e870ec 100644 --- a/app/models/open_users/qq.rb +++ b/app/models/open_users/qq.rb @@ -16,7 +16,7 @@ # index_open_users_on_user_id (user_id) # -class OpenUsers::QQ < OpenUser +class OpenUsers::Qq < OpenUser def nickname extra&.[]('nickname') end diff --git a/app/models/user.rb b/app/models/user.rb index 04b5e9c3a..4288c4d4c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -119,7 +119,7 @@ class User < Owner has_one :user_extension, dependent: :destroy has_many :open_users, dependent: :destroy has_one :wechat_open_user, class_name: 'OpenUsers::Wechat' - has_one :qq_open_user, class_name: 'OpenUsers::QQ' + has_one :qq_open_user, class_name: 'OpenUsers::Qq' accepts_nested_attributes_for :user_extension, update_only: true has_many :fork_users, dependent: :destroy diff --git a/app/services/oauth/create_or_find_qq_account_service.rb b/app/services/oauth/create_or_find_qq_account_service.rb index dafcc3f88..9faaed1fd 100644 --- a/app/services/oauth/create_or_find_qq_account_service.rb +++ b/app/services/oauth/create_or_find_qq_account_service.rb @@ -10,7 +10,7 @@ class Oauth::CreateOrFindQqAccountService < ApplicationService def call new_user = false # 存在该用户 - open_user = OpenUsers::QQ.find_by(uid: params['uid']) + open_user = OpenUsers::Qq.find_by(uid: params['uid']) return [open_user.user, new_user] if open_user.present? if user.blank? || !user.logged? @@ -32,7 +32,7 @@ class Oauth::CreateOrFindQqAccountService < ApplicationService Util.download_file(params.dig('info', 'image'), avatar_path) end - new_open_user = OpenUsers::QQ.create!(user: user, uid: params['uid']) + new_open_user = OpenUsers::Qq.create!(user: user, uid: params['uid']) Rails.cache.write(new_open_user.can_bind_cache_key, 1, expires_in: 1.hours) if new_user # 方便后面进行账号绑定 end diff --git a/config/routes.rb b/config/routes.rb index bfeb6ef8b..233b40a82 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,7 +20,7 @@ Rails.application.routes.draw do get 'attachments/download/:id', to: 'attachments#show' get 'attachments/download/:id/:filename', to: 'attachments#show' - get 'auth/qq/callback', to: 'oauth/qq#create' + # get 'auth/qq/callback', to: 'oauth/qq#create' get 'auth/failure', to: 'oauth/base#auth_failure' get 'auth/cas/callback', to: 'oauth/cas#create' get 'auth/:provider/callback', to: 'oauth/callbacks#create' From 2238c8fcbb9430e0b24bf53c288503a4057e7fc8 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 6 Dec 2022 10:24:48 +0800 Subject: [PATCH 6/9] =?UTF-8?q?fixed=20qq=E5=91=BD=E5=90=8D=E8=B0=83?= =?UTF-8?q?=E6=95=B4=EF=BC=8C=E6=96=B9=E4=BE=BF=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/open_users/qq.rb | 2 +- app/models/user.rb | 2 +- app/services/oauth/create_or_find_qq_account_service.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/open_users/qq.rb b/app/models/open_users/qq.rb index ef1a4b470..204e870ec 100644 --- a/app/models/open_users/qq.rb +++ b/app/models/open_users/qq.rb @@ -16,7 +16,7 @@ # index_open_users_on_user_id (user_id) # -class OpenUsers::QQ < OpenUser +class OpenUsers::Qq < OpenUser def nickname extra&.[]('nickname') end diff --git a/app/models/user.rb b/app/models/user.rb index b37ebc039..df35f3a2f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -120,7 +120,7 @@ class User < Owner has_one :user_extension, dependent: :destroy has_many :open_users, dependent: :destroy has_one :wechat_open_user, class_name: 'OpenUsers::Wechat' - has_one :qq_open_user, class_name: 'OpenUsers::QQ' + has_one :qq_open_user, class_name: 'OpenUsers::Qq' accepts_nested_attributes_for :user_extension, update_only: true has_many :fork_users, dependent: :destroy diff --git a/app/services/oauth/create_or_find_qq_account_service.rb b/app/services/oauth/create_or_find_qq_account_service.rb index dafcc3f88..9faaed1fd 100644 --- a/app/services/oauth/create_or_find_qq_account_service.rb +++ b/app/services/oauth/create_or_find_qq_account_service.rb @@ -10,7 +10,7 @@ class Oauth::CreateOrFindQqAccountService < ApplicationService def call new_user = false # 存在该用户 - open_user = OpenUsers::QQ.find_by(uid: params['uid']) + open_user = OpenUsers::Qq.find_by(uid: params['uid']) return [open_user.user, new_user] if open_user.present? if user.blank? || !user.logged? @@ -32,7 +32,7 @@ class Oauth::CreateOrFindQqAccountService < ApplicationService Util.download_file(params.dig('info', 'image'), avatar_path) end - new_open_user = OpenUsers::QQ.create!(user: user, uid: params['uid']) + new_open_user = OpenUsers::Qq.create!(user: user, uid: params['uid']) Rails.cache.write(new_open_user.can_bind_cache_key, 1, expires_in: 1.hours) if new_user # 方便后面进行账号绑定 end From 7b724cfeca954c3dc69342fed4e23a933c87d85c Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 7 Dec 2022 15:36:33 +0800 Subject: [PATCH 7/9] =?UTF-8?q?fixed=20=E7=94=A8=E6=88=B7=E7=AE=80?= =?UTF-8?q?=E4=BB=8B=E6=94=AF=E6=8C=81=E8=A1=A8=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20221207128751_update_user_super.rb | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 db/migrate/20221207128751_update_user_super.rb diff --git a/db/migrate/20221207128751_update_user_super.rb b/db/migrate/20221207128751_update_user_super.rb new file mode 100644 index 000000000..9f9cd2087 --- /dev/null +++ b/db/migrate/20221207128751_update_user_super.rb @@ -0,0 +1,5 @@ +class UpdateUserSuper < ActiveRecord::Migration[5.2] + def change + execute("ALTER TABLE `user_extensions` MODIFY `super_description` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;") + end +end From bc6f5cec4da4244fca9a9bf5fd0f473257eef121 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 8 Dec 2022 11:51:59 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E8=B4=A1=E7=8C=AE=E8=80=85=E8=A1=8C=E6=95=B0=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 +- .../api/v1/projects/code_stats_controller.rb | 8 +++++ .../v1/projects/code_stats/list_service.rb | 34 +++++++++++++++++++ .../projects/code_stats/index.json.jbuilder | 14 ++++++++ config/routes/api.rb | 1 + 5 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 app/controllers/api/v1/projects/code_stats_controller.rb create mode 100644 app/services/api/v1/projects/code_stats/list_service.rb create mode 100644 app/views/api/v1/projects/code_stats/index.json.jbuilder diff --git a/Gemfile b/Gemfile index c01570e41..009eda921 100644 --- a/Gemfile +++ b/Gemfile @@ -139,4 +139,4 @@ gem 'doorkeeper' gem 'doorkeeper-jwt' -gem 'gitea-client', '~> 0.10.5' \ No newline at end of file +gem 'gitea-client', '~> 0.10.6' \ No newline at end of file diff --git a/app/controllers/api/v1/projects/code_stats_controller.rb b/app/controllers/api/v1/projects/code_stats_controller.rb new file mode 100644 index 000000000..7ec671f3c --- /dev/null +++ b/app/controllers/api/v1/projects/code_stats_controller.rb @@ -0,0 +1,8 @@ +class Api::V1::Projects::CodeStatsController < Api::V1::BaseController + before_action :require_public_and_member_above, only: [:index] + + def index + @result_object = Api::V1::Projects::CodeStats::ListService.call(@project, {ref: params[:ref]}, current_user&.gitea_token) + puts @result_object + end +end \ No newline at end of file diff --git a/app/services/api/v1/projects/code_stats/list_service.rb b/app/services/api/v1/projects/code_stats/list_service.rb new file mode 100644 index 000000000..84f4bac36 --- /dev/null +++ b/app/services/api/v1/projects/code_stats/list_service.rb @@ -0,0 +1,34 @@ +class Api::V1::Projects::CodeStats::ListService < ApplicationService + + attr_reader :project, :ref, :owner, :repo, :token + attr_accessor :gitea_data + + def initialize(project, params, token=nil) + @project = project + @ref = params[:ref] + @owner = project&.owner.login + @repo = project&.identifier + @token = token + end + + def call + load_gitea_data + + gitea_data + end + + private + def request_params + param = { + access_token: token + } + param.merge!(ref: ref) if ref.present? + + param + end + + def load_gitea_data + @gitea_data = $gitea_client.get_repos_code_stats_by_owner_repo(owner, repo, {query: request_params}) rescue nil + raise Error, '获取贡献者贡献度失败!' unless @gitea_data.is_a?(Hash) + end +end \ No newline at end of file diff --git a/app/views/api/v1/projects/code_stats/index.json.jbuilder b/app/views/api/v1/projects/code_stats/index.json.jbuilder new file mode 100644 index 000000000..d438e2624 --- /dev/null +++ b/app/views/api/v1/projects/code_stats/index.json.jbuilder @@ -0,0 +1,14 @@ +json.author_count @result_object["author_count"] +json.commit_count @result_object["commit_count"] +json.change_files @result_object["change_files"] +json.additions @result_object["additions"] +json.deletions @result_object["deletions"] +json.commit_count_in_all_branches @result_object["commit_count_in_all_branches"] +json.authors @result_object["authors"].each do |author| + json.author do + json.partial! 'api/v1/users/commit_user', locals: { user: render_cache_commit_author(author), name: author['name'] } + end + json.commits author["commits"] + json.additions author["additions"] + json.deletions author["deletions"] +end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index 1c55d59d9..19531526e 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -52,6 +52,7 @@ defaults format: :json do end end resources :commits, only: [:index] + resources :code_stats, only: [:index] get '/commits/:sha/diff', to: 'commits#diff' get '/git/blobs/:sha', to: 'git#blobs' get '/git/trees/:sha', to: 'git#trees' From 1aab51104f522aceec5196fab55a6fae647eccd8 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 8 Dec 2022 14:35:46 +0800 Subject: [PATCH 9/9] =?UTF-8?q?fixed=20=E7=AC=AC=E4=B8=89=E6=96=B9?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E7=99=BB=E5=BD=95=E9=85=8D=E7=BD=AE=E6=94=AF?= =?UTF-8?q?=E6=8C=81Get=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/settings_controller.rb | 2 +- config/initializers/omniauth.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index de07ed8f2..50b86d74c 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -82,7 +82,7 @@ class SettingsController < ApplicationController @third_party_new << { name: provider, url: "#{platform_url}/auth/#{provider}", - method: 'post' + method: 'get' } end end diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index 876dbad58..37736b79a 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -5,6 +5,7 @@ OmniAuth.config.add_camelization 'qq', 'QQ' if config.dig("oauth", "qq") # OmniAuth.config.add_camelization 'gitee', 'Gitee' if config.dig("oauth", "gitee") # OmniAuth.config.add_camelization 'wechat', 'Wechat' if config.dig("oauth", "wechat") OmniAuth.config.logger = Rails.logger +OmniAuth.config.allowed_request_methods = %i[get post] OmniAuth.config.before_request_phase = nil OmniAuth.config.before_callback_phase = nil OmniAuth.config.on_failure = Proc.new { |env|