BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
aefa8bdb
Commit
aefa8bdb
authored
Aug 01, 2017
by
Yorick Peterse
Committed by
James Edwards-Jones
Aug 11, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge branch 'mk-fix-deploy-key-deletion' into 'master'
Fix deletion of deploy keys linked to other projects Closes #35630 See merge request !13162
parent
1d1f9a7c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
10 deletions
+49
-10
project.rb
app/models/project.rb
+12
-1
mk-fix-deploy-key-deletion.yml
changelogs/unreleased/mk-fix-deploy-key-deletion.yml
+4
-0
project_spec.rb
spec/models/project_spec.rb
+33
-9
No files found.
app/models/project.rb
View file @
aefa8bdb
...
@@ -1263,7 +1263,18 @@ class Project < ActiveRecord::Base
...
@@ -1263,7 +1263,18 @@ class Project < ActiveRecord::Base
end
end
def
remove_private_deploy_keys
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
end
def
remove_pages
def
remove_pages
...
...
changelogs/unreleased/mk-fix-deploy-key-deletion.yml
0 → 100644
View file @
aefa8bdb
---
title
:
Fix deletion of deploy keys linked to other projects
merge_request
:
13162
author
:
spec/models/project_spec.rb
View file @
aefa8bdb
...
@@ -2201,19 +2201,43 @@ describe Project, models: true do
...
@@ -2201,19 +2201,43 @@ describe Project, models: true do
end
end
describe
'#remove_private_deploy_keys'
do
describe
'#remove_private_deploy_keys'
do
it
'removes the private deploy keys of a project'
do
let!
(
:project
)
{
create
(
:empty_project
)
}
project
=
create
(
:empty_project
)
context
'for a private deploy key'
do
let!
(
:key
)
{
create
(
:deploy_key
,
public:
false
)
}
let!
(
:deploy_keys_project
)
{
create
(
:deploy_keys_project
,
deploy_key:
key
,
project:
project
)
}
context
'when the key is not linked to another project'
do
it
'removes the key'
do
project
.
remove_private_deploy_keys
expect
(
project
.
deploy_keys
).
not_to
include
(
key
)
end
end
context
'when the key is linked to another project'
do
before
do
another_project
=
create
(
:empty_project
)
create
(
:deploy_keys_project
,
deploy_key:
key
,
project:
another_project
)
end
private_key
=
create
(
:deploy_key
,
public:
false
)
it
'does not remove the key'
do
public_key
=
create
(
:deploy_key
,
public:
true
)
project
.
remove_private_deploy_keys
create
(
:deploy_keys_project
,
deploy_key:
private_key
,
project:
project
)
expect
(
project
.
deploy_keys
).
to
include
(
key
)
create
(
:deploy_keys_project
,
deploy_key:
public_key
,
project:
project
)
end
end
end
context
'for a public deploy key'
do
let!
(
:key
)
{
create
(
:deploy_key
,
public:
true
)
}
let!
(
:deploy_keys_project
)
{
create
(
:deploy_keys_project
,
deploy_key:
key
,
project:
project
)
}
project
.
remove_private_deploy_keys
it
'does not remove the key'
do
project
.
remove_private_deploy_keys
expect
(
project
.
deploy_keys
.
where
(
public:
false
).
any?
).
to
eq
(
false
)
expect
(
project
.
deploy_keys
).
to
include
(
key
)
e
xpect
(
project
.
deploy_keys
.
where
(
public:
true
).
any?
).
to
eq
(
true
)
e
nd
end
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment