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
6f900028
Commit
6f900028
authored
Nov 10, 2020
by
Etienne Baqué
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Applied reviewer suggestions
parent
d1ff11b5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
6 deletions
+8
-6
app/controllers/autocomplete_controller.rb
app/controllers/autocomplete_controller.rb
+3
-1
app/models/deploy_key.rb
app/models/deploy_key.rb
+3
-3
spec/models/deploy_key_spec.rb
spec/models/deploy_key_spec.rb
+2
-2
No files found.
app/controllers/autocomplete_controller.rb
View file @
6f900028
...
...
@@ -53,7 +53,9 @@ class AutocompleteController < ApplicationController
end
def
deploy_keys_with_owners
render
json:
DeployKeySerializer
.
new
.
represent
(
DeployKey
.
with_write_access_for_project
(
project
),
{
with_owner:
true
,
user:
current_user
})
deploy_keys
=
DeployKey
.
with_write_access_for_project
(
project
)
render
json:
DeployKeySerializer
.
new
.
represent
(
deploy_keys
,
{
with_owner:
true
,
user:
current_user
})
end
private
...
...
app/models/deploy_key.rb
View file @
6f900028
...
...
@@ -8,7 +8,7 @@ class DeployKey < Key
has_many
:projects
,
through: :deploy_keys_projects
scope
:in_projects
,
->
(
projects
)
{
joins
(
:deploy_keys_projects
).
where
(
deploy_keys_projects:
{
project_id:
projects
})
}
scope
:with_write_access
,
->
{
joins
(
:deploy_keys_projects
).
where
(
deploy_keys_projects:
{
can_push:
true
}
)
}
scope
:with_write_access
,
->
{
joins
(
:deploy_keys_projects
).
merge
(
DeployKeysProject
.
with_write_access
)
}
scope
:are_public
,
->
{
where
(
public:
true
)
}
scope
:with_projects
,
->
{
includes
(
deploy_keys_projects:
{
project:
[
:route
,
namespace: :route
]
})
}
...
...
@@ -57,8 +57,8 @@ class DeployKey < Key
end
def
self
.
with_write_access_for_project
(
project
,
deploy_key:
nil
)
query
=
in_projects
(
project
&
.
id
).
with_write_access
query
=
query
.
where
(
id:
deploy_key
.
id
)
if
deploy_key
query
=
in_projects
(
project
).
with_write_access
query
=
query
.
where
(
id:
deploy_key
)
if
deploy_key
query
end
...
...
spec/models/deploy_key_spec.rb
View file @
6f900028
...
...
@@ -59,14 +59,14 @@ RSpec.describe DeployKey, :mailer do
it
'only returns deploy keys with write access'
do
create
(
:deploy_keys_project
,
project:
project
)
expect
(
subject
)
.
to
contain_exactly
(
deploy_key
)
is_expected
.
to
contain_exactly
(
deploy_key
)
end
it
'returns deploy keys only for this project'
do
other_project
=
create
(
:project
)
create
(
:deploy_keys_project
,
:write_access
,
project:
other_project
)
expect
(
subject
)
.
to
contain_exactly
(
deploy_key
)
is_expected
.
to
contain_exactly
(
deploy_key
)
end
context
'and a specific deploy key is passed in'
do
...
...
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