| @@ -36,7 +36,7 @@ class Ci::BaseController < ApplicationController | |||||
| def find_cloud_account | def find_cloud_account | ||||
| @cloud_account ||= current_user.ci_cloud_account | @cloud_account ||= current_user.ci_cloud_account | ||||
| @cloud_account.blank? ? raise("未找到相关的记录") : @cloud_account | |||||
| @cloud_account.blank? ? nil : @cloud_account | |||||
| end | end | ||||
| def load_ci_user | def load_ci_user | ||||
| @@ -93,17 +93,11 @@ module Ci::CloudAccountManageable | |||||
| end | end | ||||
| def gitea_oauth_grant!(gitea_uid, application_id) | def gitea_oauth_grant!(gitea_uid, application_id) | ||||
| gitea_server_config = Rails.configuration.database_configuration[Rails.env]["gitea_server"] | |||||
| if gitea_server_config.blank? | |||||
| puts "[Gitea Server]: gitea database config missing" | |||||
| return | |||||
| else | |||||
| puts "[Gitea Server]: gitea db config is exists." | |||||
| end | |||||
| connection = establish_connection gitea_server_config | |||||
| connection = Gitea::Database.set_connection.connection | |||||
| unix_time = Time.now.to_i | unix_time = Time.now.to_i | ||||
| # TODO | |||||
| # 目前直接操作db,可以建立对应的model进行操作 | |||||
| sql = "INSERT INTO oauth2_grant ( user_id, application_id, counter, created_unix, updated_unix ) VALUES ( #{gitea_uid}, #{application_id}, 0, #{unix_time}, #{unix_time} );" | sql = "INSERT INTO oauth2_grant ( user_id, application_id, counter, created_unix, updated_unix ) VALUES ( #{gitea_uid}, #{application_id}, 0, #{unix_time}, #{unix_time} );" | ||||
| connection.execute(sql) | connection.execute(sql) | ||||
| @@ -0,0 +1,12 @@ | |||||
| module Gitea | |||||
| class Database < ActiveRecord::Base | |||||
| self.abstract_class = true | |||||
| def self.set_connection | |||||
| gitea_server_config = Rails.configuration.database_configuration[Rails.env]["gitea_server"] | |||||
| raise 'gitea database config missing' if gitea_server_config.blank? | |||||
| establish_connection gitea_server_config | |||||
| end | |||||
| end | |||||
| end | |||||
| @@ -2,8 +2,8 @@ class Ci::Repo < Ci::RemoteBase | |||||
| self.primary_key = 'repo_id' | self.primary_key = 'repo_id' | ||||
| belongs_to :user, foreign_key: :repo_user_id | belongs_to :user, foreign_key: :repo_user_id | ||||
| has_one :perm, foreign_key: :perm_repo_uid, dependent: :destroy | |||||
| has_many :builds, foreign_key: "build_repo_id", dependent: :destroy | |||||
| has_one :perm, foreign_key: :perm_repo_uid | |||||
| has_many :builds, foreign_key: :build_repo_id, dependent: :destroy | |||||
| def self.find_with_namespace(namespace_path, identifier) | def self.find_with_namespace(namespace_path, identifier) | ||||
| logger.info "########namespace_path: #{namespace_path} ########identifier: #{identifier} " | logger.info "########namespace_path: #{namespace_path} ########identifier: #{identifier} " | ||||
| @@ -1,8 +1,8 @@ | |||||
| class Ci::User < Ci::RemoteBase | class Ci::User < Ci::RemoteBase | ||||
| self.primary_key = 'user_id' | self.primary_key = 'user_id' | ||||
| has_many :repos, foreign_key: "repo_user_id", dependent: :destroy | |||||
| has_many :perms, foreign_key: "perm_user_id", dependent: :delete_all | |||||
| has_many :repos, foreign_key: :repo_user_id, dependent: :destroy | |||||
| has_many :perms, foreign_key: :perm_user_id, dependent: :delete_all | |||||
| has_one :ci_cloud_account, class_name: 'Ci::CloudAccount', foreign_key: :ci_user_id | has_one :ci_cloud_account, class_name: 'Ci::CloudAccount', foreign_key: :ci_user_id | ||||
| end | end | ||||
| @@ -22,7 +22,7 @@ module Droneable | |||||
| end | end | ||||
| def unbind_account! | def unbind_account! | ||||
| user_projects = selef.projects | |||||
| user_projects = self.projects | |||||
| user_projects.update_all(open_devops: false, open_devops_count: 0) | user_projects.update_all(open_devops: false, open_devops_count: 0) | ||||
| set_drone_step!(User::DEVOPS_UNINIT) | set_drone_step!(User::DEVOPS_UNINIT) | ||||
| @@ -0,0 +1,4 @@ | |||||
| class Gitea::Base < Gitea::Database | |||||
| self.abstract_class = true | |||||
| end | |||||