diff --git a/app/controllers/ci/base_controller.rb b/app/controllers/ci/base_controller.rb index 20a9cb15e..47788ed77 100644 --- a/app/controllers/ci/base_controller.rb +++ b/app/controllers/ci/base_controller.rb @@ -11,6 +11,11 @@ class Ci::BaseController < ApplicationController @ci_user, @repo = Ci::Repo.find_with_namespace(namespace, id) end + def load_all_repo + namespace = current_user.login + @repos = Ci::Repo.find_all_with_namespace(namespace) + end + private def authorize_access_project! unless @project.manager?(current_user) diff --git a/app/controllers/ci/cloud_accounts_controller.rb b/app/controllers/ci/cloud_accounts_controller.rb index 2d2c83a1a..52ef9a801 100644 --- a/app/controllers/ci/cloud_accounts_controller.rb +++ b/app/controllers/ci/cloud_accounts_controller.rb @@ -5,6 +5,7 @@ class Ci::CloudAccountsController < Ci::BaseController before_action :load_project, only: %i[create activate] before_action :authorize_owner!, only: %i[create activate] before_action :load_repo, only: %i[activate] + before_action :load_all_repo, only: %i[unbind] before_action :find_cloud_account, only: %i[show oauth_grant] before_action :validate_params!, only: %i[create bind] before_action only: %i[create bind] do @@ -96,6 +97,11 @@ class Ci::CloudAccountsController < Ci::BaseController def unbind ActiveRecord::Base.transaction do unbind_account! + if @repos + @repos.each do |repo| + repo.deactivate! + end + end render_ok end rescue Exception => ex diff --git a/app/models/ci/repo.rb b/app/models/ci/repo.rb index 8396cfa90..6fb42e046 100644 --- a/app/models/ci/repo.rb +++ b/app/models/ci/repo.rb @@ -14,6 +14,12 @@ class Ci::Repo < Ci::RemoteBase [user, repo] end + def self.find_all_with_namespace(namespace_path) + logger.info "########namespace_path: #{namespace_path}" + repos = Ci::Repo.where(repo_namespace: namespace_path) + return repos + end + def activate!(ci_user_id) update(repo_active: 1, repo_signer: generate_code,