Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
cc5c821f
Commit
cc5c821f
authored
Sep 09, 2020
by
Etienne Baqué
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added enabled_group_deploy_keys for projects
Added related rspec.
parent
a4fe586d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
74 additions
and
0 deletions
+74
-0
app/models/group_deploy_key.rb
app/models/group_deploy_key.rb
+4
-0
app/models/project.rb
app/models/project.rb
+6
-0
spec/models/group_deploy_key_spec.rb
spec/models/group_deploy_key_spec.rb
+21
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+43
-0
No files found.
app/models/group_deploy_key.rb
View file @
cc5c821f
...
...
@@ -8,6 +8,10 @@ class GroupDeployKey < Key
validates
:user
,
presence:
true
scope
:for_groups
,
->
(
group_ids
)
do
joins
(
:group_deploy_keys_groups
).
where
(
group_deploy_keys_groups:
{
group_id:
group_ids
}).
uniq
end
def
type
'DeployKey'
end
...
...
app/models/project.rb
View file @
cc5c821f
...
...
@@ -2532,6 +2532,12 @@ class Project < ApplicationRecord
ci_config_path
.
presence
||
Ci
::
Pipeline
::
DEFAULT_CONFIG_PATH
end
def
enabled_group_deploy_keys
return
GroupDeployKey
.
none
unless
group
GroupDeployKey
.
for_groups
(
group
.
self_and_ancestors_ids
)
end
private
def
find_service
(
services
,
name
)
...
...
spec/models/group_deploy_key_spec.rb
View file @
cc5c821f
...
...
@@ -82,4 +82,25 @@ RSpec.describe GroupDeployKey do
end
end
end
describe
'.for_groups'
do
context
'when group deploy keys are enabled for some groups'
do
let_it_be
(
:group1
)
{
create
(
:group
)
}
let_it_be
(
:group2
)
{
create
(
:group
)
}
let_it_be
(
:group3
)
{
create
(
:group
)
}
let_it_be
(
:gdk1
)
{
create
(
:group_deploy_key
)
}
let_it_be
(
:gdk2
)
{
create
(
:group_deploy_key
)
}
let_it_be
(
:gdk3
)
{
create
(
:group_deploy_key
)
}
it
'returns these group deploy keys'
do
gdk1
.
groups
<<
group1
gdk1
.
groups
<<
group2
gdk2
.
groups
<<
group3
gdk3
.
groups
<<
group2
expect
(
described_class
.
for_groups
([
group1
.
id
,
group3
.
id
])).
to
contain_exactly
(
gdk1
,
gdk2
)
expect
(
described_class
.
for_groups
([
group2
.
id
])).
to
contain_exactly
(
gdk1
,
gdk3
)
end
end
end
end
spec/models/project_spec.rb
View file @
cc5c821f
...
...
@@ -6536,6 +6536,49 @@ RSpec.describe Project do
end
end
describe
'#enabled_group_deploy_keys'
do
let_it_be
(
:project
)
{
create
(
:project
)
}
subject
{
project
.
enabled_group_deploy_keys
}
context
'when a project does not have a group'
do
it
{
is_expected
.
to
be_empty
}
end
context
'when a project has a parent group'
do
let!
(
:group
)
{
create
(
:group
,
projects:
[
project
])
}
context
'and this group has a group deploy key enabled'
do
let!
(
:group_deploy_key
)
{
create
(
:group_deploy_key
,
groups:
[
group
])
}
it
{
is_expected
.
to
contain_exactly
(
group_deploy_key
)
}
context
'and this group has parent group which also has a group deploy key enabled'
do
let
(
:super_group
)
{
create
(
:group
)
}
it
'returns both group deploy keys'
do
super_group
=
create
(
:group
)
super_group_deploy_key
=
create
(
:group_deploy_key
,
groups:
[
super_group
])
group
.
update!
(
parent:
super_group
)
expect
(
subject
).
to
contain_exactly
(
group_deploy_key
,
super_group_deploy_key
)
end
end
end
context
'and another group has a group deploy key enabled'
do
let_it_be
(
:group_deploy_key
)
{
create
(
:group_deploy_key
)
}
it
'does not return this group deploy key'
do
another_group
=
create
(
:group
)
create
(
:group_deploy_key
,
groups:
[
another_group
])
expect
(
subject
).
to
be_empty
end
end
end
end
def
finish_job
(
export_job
)
export_job
.
start
export_job
.
finish
...
...
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