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
Léo-Paul Géneau
gitlab-ce
Commits
554e18ab
Commit
554e18ab
authored
Aug 05, 2016
by
Z.J. van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create service for enabling deploy keys
parent
460065b7
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
22 deletions
+58
-22
app/controllers/projects/deploy_keys_controller.rb
app/controllers/projects/deploy_keys_controller.rb
+6
-14
app/services/enable_deploy_key_service.rb
app/services/enable_deploy_key_service.rb
+14
-0
lib/api/deploy_keys.rb
lib/api/deploy_keys.rb
+3
-3
spec/requests/api/deploy_keys_spec.rb
spec/requests/api/deploy_keys_spec.rb
+8
-5
spec/services/enable_deploy_key_service_spec.rb
spec/services/enable_deploy_key_service_spec.rb
+27
-0
No files found.
app/controllers/projects/deploy_keys_controller.rb
View file @
554e18ab
...
...
@@ -12,8 +12,7 @@ class Projects::DeployKeysController < Projects::ApplicationController
end
def
new
redirect_to
namespace_project_deploy_keys_path
(
@project
.
namespace
,
@project
)
redirect_to
namespace_project_deploy_keys_path
(
@project
.
namespace
,
@project
)
end
def
create
...
...
@@ -21,19 +20,16 @@ class Projects::DeployKeysController < Projects::ApplicationController
set_index_vars
if
@key
.
valid?
&&
@project
.
deploy_keys
<<
@key
redirect_to
namespace_project_deploy_keys_path
(
@project
.
namespace
,
@project
)
redirect_to
namespace_project_deploy_keys_path
(
@project
.
namespace
,
@project
)
else
render
"index"
end
end
def
enable
@key
=
accessible_keys
.
find
(
params
[
:id
])
@project
.
deploy_keys
<<
@key
EnableDeployKeyService
.
new
(
@project
,
current_user
,
params
).
execute
redirect_to
namespace_project_deploy_keys_path
(
@project
.
namespace
,
@project
)
redirect_to
namespace_project_deploy_keys_path
(
@project
.
namespace
,
@project
)
end
def
disable
...
...
@@ -47,7 +43,7 @@ class Projects::DeployKeysController < Projects::ApplicationController
def
set_index_vars
@enabled_keys
||=
@project
.
deploy_keys
@available_keys
||=
accessible
_keys
-
@enabled_keys
@available_keys
||=
current_user
.
accessible_deploy
_keys
-
@enabled_keys
@available_project_keys
||=
current_user
.
project_deploy_keys
-
@enabled_keys
@available_public_keys
||=
DeployKey
.
are_public
-
@enabled_keys
...
...
@@ -56,10 +52,6 @@ class Projects::DeployKeysController < Projects::ApplicationController
@available_public_keys
-=
@available_project_keys
end
def
accessible_keys
@accessible_keys
||=
current_user
.
accessible_deploy_keys
end
def
deploy_key_params
params
.
require
(
:deploy_key
).
permit
(
:key
,
:title
)
end
...
...
app/services/enable_deploy_key_service.rb
0 → 100644
View file @
554e18ab
class
EnableDeployKeyService
<
BaseService
def
execute
key
=
accessible_keys
.
find_by
(
id:
params
[
:key_id
]
||
params
[
:id
])
project
.
deploy_keys
<<
key
if
key
key
end
private
def
accessible_keys
current_user
.
accessible_deploy_keys
end
end
lib/api/deploy_keys.rb
View file @
554e18ab
...
...
@@ -76,12 +76,12 @@ module API
requires
:key_id
,
type:
Integer
,
desc:
'The ID of the deploy key'
end
post
":id/
#{
path
}
/:key_id/enable"
do
key
=
DeployKey
.
find
(
params
[
:key_id
])
key
=
EnableDeployKeyService
.
new
(
user_project
,
current_user
,
declared
(
params
)).
execute
if
user_project
.
deploy_keys
<<
key
if
key
present
key
,
with:
Entities
::
SSHKey
else
render_validation_error!
(
key
)
not_found!
(
'Deploy Key'
)
end
end
...
...
spec/requests/api/deploy_keys_spec.rb
View file @
554e18ab
...
...
@@ -6,8 +6,11 @@ describe API::API, api: true do
let
(
:user
)
{
create
(
:user
)
}
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:project
)
{
create
(
:project
,
creator_id:
user
.
id
)
}
let!
(
:deploy_keys_project
)
{
create
(
:deploy_keys_project
,
project:
project
)
}
let
(
:deploy_key
)
{
deploy_keys_project
.
deploy_key
}
let
(
:deploy_key
)
{
create
(
:deploy_key
,
public:
true
)
}
let!
(
:deploy_keys_project
)
do
create
(
:deploy_keys_project
,
project:
project
,
deploy_key:
deploy_key
)
end
describe
'GET /deploy_keys'
do
context
'when unauthenticated'
do
...
...
spec/services/enable_deploy_key_service_spec.rb
0 → 100644
View file @
554e18ab
require
'spec_helper'
describe
EnableDeployKeyService
,
services:
true
do
let
(
:deploy_key
)
{
create
(
:deploy_key
,
public:
true
)
}
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:user
)
{
project
.
creator
}
let!
(
:params
)
{
{
key_id:
deploy_key
.
id
}
}
it
'enables the key'
do
expect
do
service
.
execute
end
.
to
change
{
project
.
deploy_keys
.
count
}.
from
(
0
).
to
(
1
)
end
context
'trying to add an unaccessable key'
do
let
(
:another_key
)
{
create
(
:another_key
)
}
let!
(
:params
)
{
{
key_id:
another_key
.
id
}
}
it
'returns nil if the key cannot be added'
do
expect
(
service
.
execute
).
to
be
nil
end
end
def
service
EnableDeployKeyService
.
new
(
project
,
user
,
params
)
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