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
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
Hide 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
...
@@ -12,8 +12,7 @@ class Projects::DeployKeysController < Projects::ApplicationController
end
end
def
new
def
new
redirect_to
namespace_project_deploy_keys_path
(
@project
.
namespace
,
redirect_to
namespace_project_deploy_keys_path
(
@project
.
namespace
,
@project
)
@project
)
end
end
def
create
def
create
...
@@ -21,19 +20,16 @@ class Projects::DeployKeysController < Projects::ApplicationController
...
@@ -21,19 +20,16 @@ class Projects::DeployKeysController < Projects::ApplicationController
set_index_vars
set_index_vars
if
@key
.
valid?
&&
@project
.
deploy_keys
<<
@key
if
@key
.
valid?
&&
@project
.
deploy_keys
<<
@key
redirect_to
namespace_project_deploy_keys_path
(
@project
.
namespace
,
redirect_to
namespace_project_deploy_keys_path
(
@project
.
namespace
,
@project
)
@project
)
else
else
render
"index"
render
"index"
end
end
end
end
def
enable
def
enable
@key
=
accessible_keys
.
find
(
params
[
:id
])
EnableDeployKeyService
.
new
(
@project
,
current_user
,
params
).
execute
@project
.
deploy_keys
<<
@key
redirect_to
namespace_project_deploy_keys_path
(
@project
.
namespace
,
redirect_to
namespace_project_deploy_keys_path
(
@project
.
namespace
,
@project
)
@project
)
end
end
def
disable
def
disable
...
@@ -45,9 +41,9 @@ class Projects::DeployKeysController < Projects::ApplicationController
...
@@ -45,9 +41,9 @@ class Projects::DeployKeysController < Projects::ApplicationController
protected
protected
def
set_index_vars
def
set_index_vars
@enabled_keys
||=
@project
.
deploy_keys
@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_project_keys
||=
current_user
.
project_deploy_keys
-
@enabled_keys
@available_public_keys
||=
DeployKey
.
are_public
-
@enabled_keys
@available_public_keys
||=
DeployKey
.
are_public
-
@enabled_keys
...
@@ -56,10 +52,6 @@ class Projects::DeployKeysController < Projects::ApplicationController
...
@@ -56,10 +52,6 @@ class Projects::DeployKeysController < Projects::ApplicationController
@available_public_keys
-=
@available_project_keys
@available_public_keys
-=
@available_project_keys
end
end
def
accessible_keys
@accessible_keys
||=
current_user
.
accessible_deploy_keys
end
def
deploy_key_params
def
deploy_key_params
params
.
require
(
:deploy_key
).
permit
(
:key
,
:title
)
params
.
require
(
:deploy_key
).
permit
(
:key
,
:title
)
end
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
...
@@ -76,12 +76,12 @@ module API
requires
:key_id
,
type:
Integer
,
desc:
'The ID of the deploy key'
requires
:key_id
,
type:
Integer
,
desc:
'The ID of the deploy key'
end
end
post
":id/
#{
path
}
/:key_id/enable"
do
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
present
key
,
with:
Entities
::
SSHKey
else
else
render_validation_error!
(
key
)
not_found!
(
'Deploy Key'
)
end
end
end
end
...
...
spec/requests/api/deploy_keys_spec.rb
View file @
554e18ab
...
@@ -3,11 +3,14 @@ require 'spec_helper'
...
@@ -3,11 +3,14 @@ require 'spec_helper'
describe
API
::
API
,
api:
true
do
describe
API
::
API
,
api:
true
do
include
ApiHelpers
include
ApiHelpers
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:project
)
{
create
(
:project
,
creator_id:
user
.
id
)
}
let
(
:project
)
{
create
(
:project
,
creator_id:
user
.
id
)
}
let!
(
:deploy_keys_project
)
{
create
(
:deploy_keys_project
,
project:
project
)
}
let
(
:deploy_key
)
{
create
(
:deploy_key
,
public:
true
)
}
let
(
:deploy_key
)
{
deploy_keys_project
.
deploy_key
}
let!
(
:deploy_keys_project
)
do
create
(
:deploy_keys_project
,
project:
project
,
deploy_key:
deploy_key
)
end
describe
'GET /deploy_keys'
do
describe
'GET /deploy_keys'
do
context
'when unauthenticated'
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