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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
e0dc7352
Commit
e0dc7352
authored
Mar 24, 2017
by
Jarka Kadlecova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Project deploy keys json end point
parent
8f6608af
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
144 additions
and
2 deletions
+144
-2
app/controllers/projects/deploy_keys_controller.rb
app/controllers/projects/deploy_keys_controller.rb
+7
-2
app/presenters/projects/settings/deploy_keys_presenter.rb
app/presenters/projects/settings/deploy_keys_presenter.rb
+11
-0
app/serializers/deploy_key_entity.rb
app/serializers/deploy_key_entity.rb
+12
-0
app/serializers/deploy_key_serializer.rb
app/serializers/deploy_key_serializer.rb
+3
-0
app/serializers/project_entity.rb
app/serializers/project_entity.rb
+12
-0
changelogs/unreleased/29667-deploy-keys.yml
changelogs/unreleased/29667-deploy-keys.yml
+4
-0
spec/controllers/projects/deploy_keys_controller_spec.rb
spec/controllers/projects/deploy_keys_controller_spec.rb
+66
-0
spec/serializers/deploy_key_entity_spec.rb
spec/serializers/deploy_key_entity_spec.rb
+29
-0
No files found.
app/controllers/projects/deploy_keys_controller.rb
View file @
e0dc7352
...
...
@@ -8,7 +8,12 @@ class Projects::DeployKeysController < Projects::ApplicationController
layout
"project_settings"
def
index
redirect_to_repository_settings
(
@project
)
respond_to
do
|
format
|
format
.
html
{
redirect_to_repository_settings
(
@project
)
}
format
.
json
do
render
json:
Projects
::
Settings
::
DeployKeysPresenter
.
new
(
@project
,
current_user:
current_user
).
as_json
end
end
end
def
new
...
...
app/presenters/projects/settings/deploy_keys_presenter.rb
View file @
e0dc7352
...
...
@@ -48,6 +48,17 @@ module Projects
available_public_keys
.
any?
end
def
as_json
serializer
=
DeployKeySerializer
.
new
opts
=
{
user:
current_user
}
{
enabled_keys:
serializer
.
represent
(
enabled_keys
,
opts
),
available_project_keys:
serializer
.
represent
(
available_project_keys
,
opts
),
public_keys:
serializer
.
represent
(
available_public_keys
,
opts
)
}
end
def
to_partial_path
'projects/deploy_keys/index'
end
...
...
app/serializers/deploy_key_entity.rb
0 → 100644
View file @
e0dc7352
class
DeployKeyEntity
<
Grape
::
Entity
expose
:id
expose
:user_id
expose
:title
expose
:fingerprint
expose
:can_push
expose
:created_at
expose
:updated_at
expose
:projects
,
using:
ProjectEntity
do
|
deploy_key
|
deploy_key
.
projects
.
select
{
|
project
|
options
[
:user
].
can?
(
:read_project
,
project
)
}
end
end
app/serializers/deploy_key_serializer.rb
0 → 100644
View file @
e0dc7352
class
DeployKeySerializer
<
BaseSerializer
entity
DeployKeyEntity
end
app/serializers/project_entity.rb
0 → 100644
View file @
e0dc7352
class
ProjectEntity
<
Grape
::
Entity
expose
:id
expose
:name
expose
:full_path
do
|
project
|
project
.
full_path
end
expose
:full_name
do
|
project
|
project
.
full_name
end
end
changelogs/unreleased/29667-deploy-keys.yml
0 → 100644
View file @
e0dc7352
---
title
:
Project deploy keys json end point
merge_request
:
author
:
spec/controllers/projects/deploy_keys_controller_spec.rb
0 → 100644
View file @
e0dc7352
require
'spec_helper'
describe
Projects
::
DeployKeysController
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:user
)
{
create
(
:user
)
}
before
do
project
.
team
<<
[
user
,
:master
]
sign_in
(
user
)
end
describe
'GET index'
do
let
(
:params
)
do
{
namespace_id:
project
.
namespace
,
project_id:
project
}
end
context
'when html requested'
do
it
'redirects to blob'
do
get
:index
,
params
expect
(
response
).
to
redirect_to
(
namespace_project_settings_repository_path
(
params
))
end
end
context
'when json requested'
do
let
(
:project2
)
{
create
(
:empty_project
,
:internal
)}
let
(
:project_private
)
{
create
(
:empty_project
,
:private
)}
let
(
:deploy_key_internal
)
do
create
(
:deploy_key
,
key:
'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCdMHEHyhRjbhEZVddFn6lTWdgEy5Q6Bz4nwGB76xWZI5YT/1WJOMEW+sL5zYd31kk7sd3FJ5L9ft8zWMWrr/iWXQikC2cqZK24H1xy+ZUmrRuJD4qGAaIVoyyzBL+avL+lF8J5lg6YSw8gwJY/lX64/vnJHUlWw2n5BF8IFOWhiw== dummy@gitlab.com'
)
end
let
(
:deploy_key_actual
)
do
create
(
:deploy_key
,
key:
'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDNd/UJWhPrpb+b/G5oL109y57yKuCxE+WUGJGYaj7WQKsYRJmLYh1mgjrl+KVyfsWpq4ylOxIfFSnN9xBBFN8mlb0Fma5DC7YsSsibJr3MZ19ZNBprwNcdogET7aW9I0In7Wu5f2KqI6e5W/spJHCy4JVxzVMUvk6Myab0LnJ2iQ== dummy@gitlab.com'
)
end
let!
(
:deploy_key_public
)
{
create
(
:deploy_key
,
public:
true
)
}
let!
(
:deploy_keys_project_internal
)
do
create
(
:deploy_keys_project
,
project:
project2
,
deploy_key:
deploy_key_internal
)
end
let!
(
:deploy_keys_actual_project
)
do
create
(
:deploy_keys_project
,
project:
project
,
deploy_key:
deploy_key_actual
)
end
let!
(
:deploy_keys_project_private
)
do
create
(
:deploy_keys_project
,
project:
project_private
,
deploy_key:
create
(
:another_deploy_key
))
end
before
do
project2
.
team
<<
[
user
,
:developer
]
end
it
'returns json in a correct format'
do
get
:index
,
params
.
merge
(
format: :json
)
json
=
JSON
.
parse
(
response
.
body
)
expect
(
json
.
keys
).
to
match_array
(
%w(enabled_keys available_project_keys public_keys)
)
expect
(
json
[
'enabled_keys'
].
count
).
to
eq
(
1
)
expect
(
json
[
'available_project_keys'
].
count
).
to
eq
(
1
)
expect
(
json
[
'public_keys'
].
count
).
to
eq
(
1
)
end
end
end
end
spec/serializers/deploy_key_entity_spec.rb
0 → 100644
View file @
e0dc7352
require
'spec_helper'
describe
DeployKeyEntity
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:empty_project
,
:internal
)}
let
(
:project_private
)
{
create
(
:empty_project
,
:private
)}
let
(
:deploy_key
)
{
create
(
:deploy_key
)
}
let!
(
:deploy_key_internal
)
{
create
(
:deploy_keys_project
,
project:
project
,
deploy_key:
deploy_key
)
}
let!
(
:deploy_key_private
)
{
create
(
:deploy_keys_project
,
project:
project_private
,
deploy_key:
deploy_key
)
}
let
(
:entity
)
{
described_class
.
new
(
deploy_key
,
user:
user
)
}
it
'returns deploy keys with projects a user can read'
do
expected_result
=
{
id:
deploy_key
.
id
,
user_id:
deploy_key
.
user_id
,
title:
deploy_key
.
title
,
fingerprint:
deploy_key
.
fingerprint
,
can_push:
deploy_key
.
can_push
,
created_at:
deploy_key
.
created_at
,
updated_at:
deploy_key
.
updated_at
,
projects:
[
{
id:
project
.
id
,
name:
project
.
name
,
full_path:
project
.
full_path
,
full_name:
project
.
full_name
}
]
}
expect
(
entity
.
as_json
).
to
eq
(
expected_result
)
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