summaryrefslogtreecommitdiff
path: root/app/models/project.rb
diff options
context:
space:
mode:
authorMichael Kozono <mkozono@gmail.com>2017-07-28 09:25:13 -0700
committerMichael Kozono <mkozono@gmail.com>2017-07-28 14:48:39 -0700
commitf5fc912b33e0d343b8ef88b543a3b5b0b1f3cf9b (patch)
treeb39def691a8c4549bf696d2782adf6d3bfc2a5fd /app/models/project.rb
parent4c89929fb4211aa1cf5f311a0cec89988de45184 (diff)
downloadgitlab-ce-f5fc912b33e0d343b8ef88b543a3b5b0b1f3cf9b.tar.gz
Exclude keys linked to other projectsmk-fix-deploy-key-deletion
Diffstat (limited to 'app/models/project.rb')
-rw-r--r--app/models/project.rb13
1 files changed, 12 insertions, 1 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index d827bfaa806..90967a12b96 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -1265,7 +1265,18 @@ class Project < ActiveRecord::Base
end
def remove_private_deploy_keys
- deploy_keys.where(public: false).delete_all
+ exclude_keys_linked_to_other_projects = <<-SQL
+ NOT EXISTS (
+ SELECT 1
+ FROM deploy_keys_projects dkp2
+ WHERE dkp2.deploy_key_id = deploy_keys_projects.deploy_key_id
+ AND dkp2.project_id != deploy_keys_projects.project_id
+ )
+ SQL
+
+ deploy_keys.where(public: false)
+ .where(exclude_keys_linked_to_other_projects)
+ .delete_all
end
def remove_pages