FIX update query ci user and ci repo method

This commit is contained in:
Jasder 2020-09-09 09:57:44 +08:00
parent 0edac45e82
commit be6ff6a043
2 changed files with 10 additions and 16 deletions

View File

@ -24,18 +24,16 @@ class Ci::CloudAccountsController < Ci::BaseController
end end
def activate def activate
return render_error('请先在指定地址做用户认证') unless current_user.ci_certification? return render_error('请先在指定地址做用户认证') unless @user.ci_certification?
return render_error('该项目已经激活') if @repo && @repo.repo_active? return render_error('该项目已经激活') if @repo && @repo.repo_active?
ci_user = Ci::User.find_by(user_login: current_user.login)
repo = Ci::Repo.where(repo_namespace: current_user.login, repo_name: params[:repo]).first
begin begin
repo.activate!(ci_user.user_id) ActiveRecord::Base.transaction do
result = bind_hook!(current_user, @cloud_account, repo) repo.activate!(@user.user_id)
@project.update_columns(open_devops: true, gitea_webhook_id: result['id']) if result result = bind_hook!(@user, @cloud_account, @repo)
@project.update_columns(open_devops: true, gitea_webhook_id: result['id'])
@cloud_account.update_column(:ci_user_id, ci_user.user_id) @cloud_account.update_column(:ci_user_id, @user.user_id)
end
render_ok render_ok
rescue Exception => ex rescue Exception => ex
render_error(ex.message) render_error(ex.message)
@ -46,7 +44,6 @@ class Ci::CloudAccountsController < Ci::BaseController
@cloud_account = current_user.ci_cloud_account @cloud_account = current_user.ci_cloud_account
end end
def bind def bind
Ci::CreateCloudAccountForm.new(devops_params).validate! Ci::CreateCloudAccountForm.new(devops_params).validate!

View File

@ -8,16 +8,13 @@ class Ci::Repo < Ci::RemoteBase
logger.info "########namespace_path: #{namespace_path} ########identifier: #{identifier} " logger.info "########namespace_path: #{namespace_path} ########identifier: #{identifier} "
user = Ci::User.find_by_user_login namespace_path user = Ci::User.find_by_user_login namespace_path
return nil if user.blank? repo = Ci::Repo.where(repo_namespace: namespace_path, repo_name: identifier).first
repo = user.repos.find_by(repo_name: identifier) (user.blank? || repo.blank?) ? nil : [user, repo]
return nil if repo.blank?
[user, repo]
end end
def activate!(ci_user_id) def activate!(ci_user_id)
update_columns(repo_active: 1, update(repo_active: 1,
repo_signer: generate_code, repo_signer: generate_code,
repo_secret: generate_code, repo_secret: generate_code,
repo_user_id: ci_user_id, repo_user_id: ci_user_id,