FIX ci db bug
This commit is contained in:
parent
b74d43083e
commit
0467119605
|
@ -1,4 +1,6 @@
|
||||||
class Ci::BaseController < ApplicationController
|
class Ci::BaseController < ApplicationController
|
||||||
|
include Ci::DbConnectable
|
||||||
|
|
||||||
before_action :require_login
|
before_action :require_login
|
||||||
before_action :connect_to_ci_database
|
before_action :connect_to_ci_database
|
||||||
|
|
||||||
|
@ -44,20 +46,4 @@ class Ci::BaseController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Dynamically sets the database connection.
|
|
||||||
def connect_to_ci_database
|
|
||||||
db_config = Rails.configuration.database_configuration[Rails.env]["ci_server_db"]
|
|
||||||
return render_error('ci database config missing') if db_config.blank?
|
|
||||||
|
|
||||||
req_params = {
|
|
||||||
host: db_config["host"],
|
|
||||||
username: db_config['username'],
|
|
||||||
password: db_config['password'],
|
|
||||||
port: db_config['port'],
|
|
||||||
database: "#{current_user.login}_#{db_config['database']}"
|
|
||||||
}
|
|
||||||
db_params = Ci::Database.get_connection_params(req_params)
|
|
||||||
Ci::Database.set_connection(db_params)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
module Ci::DbConnectable
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
include do
|
||||||
|
end
|
||||||
|
|
||||||
|
# Dynamically sets the database connection.
|
||||||
|
def connect_to_ci_database
|
||||||
|
db_config = Rails.configuration.database_configuration[Rails.env]["ci_server_db"]
|
||||||
|
return render_error('ci database config missing') if db_config.blank?
|
||||||
|
|
||||||
|
req_params = {
|
||||||
|
host: db_config["host"],
|
||||||
|
username: db_config['username'],
|
||||||
|
password: db_config['password'],
|
||||||
|
port: db_config['port'],
|
||||||
|
database: "#{current_user.login}_#{db_config['database']}"
|
||||||
|
}
|
||||||
|
db_params = Ci::Database.get_connection_params(req_params)
|
||||||
|
Ci::Database.set_connection(db_params)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -1,7 +1,10 @@
|
||||||
class UsersController < ApplicationController
|
class UsersController < ApplicationController
|
||||||
|
include Ci::DbConnectable
|
||||||
|
|
||||||
before_action :load_user, only: [:show, :homepage_info, :sync_token, :sync_gitea_pwd, :projects, :watch_users, :fan_users]
|
before_action :load_user, only: [:show, :homepage_info, :sync_token, :sync_gitea_pwd, :projects, :watch_users, :fan_users]
|
||||||
before_action :check_user_exist, only: [:show, :homepage_info,:projects, :watch_users, :fan_users]
|
before_action :check_user_exist, only: [:show, :homepage_info,:projects, :watch_users, :fan_users]
|
||||||
before_action :require_login, only: %i[me list]
|
before_action :require_login, only: %i[me list]
|
||||||
|
before_action :connect_to_ci_database, only: :get_user_info
|
||||||
skip_before_action :check_sign, only: [:attachment_show]
|
skip_before_action :check_sign, only: [:attachment_show]
|
||||||
|
|
||||||
def list
|
def list
|
||||||
|
|
|
@ -13,4 +13,4 @@ json.user_phone_binded @user.phone.present?
|
||||||
json.profile_completed @user.profile_completed?
|
json.profile_completed @user.profile_completed?
|
||||||
json.professional_certification @user.professional_certification
|
json.professional_certification @user.professional_certification
|
||||||
json.devops_step @user.devops_step
|
json.devops_step @user.devops_step
|
||||||
json.ci_certification @user.ci_certification?
|
json.ci_certification @user.ci_certification? if !@user.is_a?(AnonymousUser)
|
||||||
|
|
Loading…
Reference in New Issue