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
5967c17e
Commit
5967c17e
authored
Jan 31, 2017
by
Grzegorz Bizon
Committed by
Jose Ivan Vargas
Mar 06, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduced the deploy keys presenter
parent
2ee86441
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
110 additions
and
32 deletions
+110
-32
app/controllers/projects/settings/repository_controller.rb
app/controllers/projects/settings/repository_controller.rb
+3
-18
app/presenters/projects/settings/deploy_keys_presenter.rb
app/presenters/projects/settings/deploy_keys_presenter.rb
+65
-0
app/views/projects/deploy_keys/_deploy_key.html.haml
app/views/projects/deploy_keys/_deploy_key.html.haml
+1
-1
app/views/projects/deploy_keys/_form.html.haml
app/views/projects/deploy_keys/_form.html.haml
+2
-2
app/views/projects/deploy_keys/_index.html.haml
app/views/projects/deploy_keys/_index.html.haml
+10
-10
app/views/projects/settings/repository/show.html.haml
app/views/projects/settings/repository/show.html.haml
+1
-1
spec/presenters/projects/settings/deploy_keys_presenter_spec.rb
...resenters/projects/settings/deploy_keys_presenter_spec.rb
+28
-0
No files found.
app/controllers/projects/settings/repository_controller.rb
View file @
5967c17e
...
@@ -7,7 +7,9 @@ module Projects
...
@@ -7,7 +7,9 @@ module Projects
before_action
:load_protected_branches
,
only:
[
:show
]
before_action
:load_protected_branches
,
only:
[
:show
]
def
show
def
show
define_deploy_keys_variables
@deploy_keys
=
DeployKeysPresenter
.
new
(
@project
,
current_user:
@current_user
)
define_protected_branches_controller
define_protected_branches_controller
end
end
...
@@ -15,25 +17,8 @@ module Projects
...
@@ -15,25 +17,8 @@ module Projects
@protected_branches
=
@project
.
protected_branches
.
order
(
:name
).
page
(
params
[
:page
])
@protected_branches
=
@project
.
protected_branches
.
order
(
:name
).
page
(
params
[
:page
])
end
end
def
set_index_vars
@enabled_keys
||=
@project
.
deploy_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
# Public keys that are already used by another accessible project are already
# in @available_project_keys.
@available_public_keys
-=
@available_project_keys
end
private
private
def
define_deploy_keys_variables
@key
=
DeployKey
.
new
set_index_vars
end
def
define_protected_branches_controller
def
define_protected_branches_controller
@protected_branch
=
@project
.
protected_branches
.
new
@protected_branch
=
@project
.
protected_branches
.
new
load_gon_index
(
@project
)
load_gon_index
(
@project
)
...
...
app/presenters/projects/settings/deploy_keys_presenter.rb
0 → 100644
View file @
5967c17e
module
Projects
module
Settings
class
DeployKeysPresenter
<
Gitlab
::
View
::
Presenter
::
Simple
presents
:project
def
new_key
@key
||=
DeployKey
.
new
end
def
enabled_keys
@enabled_keys
||=
project
.
deploy_keys
end
def
any_keys_enabled?
enabled_keys
.
any?
end
def
enabled_keys_size
enabled_keys
.
size
end
def
available_keys
@available_keys
||=
current_user
.
accessible_deploy_keys
-
enabled_keys
end
def
available_project_keys
@available_project_keys
||=
current_user
.
project_deploy_keys
-
enabled_keys
end
def
any_available_project_keys_enabled?
available_project_keys
.
any?
end
def
available_project_keys_size
available_project_keys
.
size
end
def
available_public_keys
return
@available_public_keys
if
defined?
(
@available_public_keys
)
@available_public_keys
||=
DeployKey
.
are_public
-
enabled_keys
# Public keys that are already used by another accessible project are already
# in @available_project_keys.
@available_public_keys
-=
available_project_keys
end
def
any_available_public_keys_enabled?
available_public_keys
.
any?
end
def
available_public_keys_size
available_public_keys
.
size
end
def
to_partial_path
'projects/deploy_keys/index'
end
def
form_partial_path
'projects/deploy_keys/form'
end
end
end
end
app/views/projects/deploy_keys/_deploy_key.html.haml
View file @
5967c17e
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
%span
.key-created-at
%span
.key-created-at
created
#{
time_ago_with_tooltip
(
deploy_key
.
created_at
)
}
created
#{
time_ago_with_tooltip
(
deploy_key
.
created_at
)
}
.visible-xs-block.visible-sm-block
.visible-xs-block.visible-sm-block
-
if
@available_keys
.
include?
(
deploy_key
)
-
if
@
deploy_keys
.
available_keys
.
include?
(
deploy_key
)
=
link_to
enable_namespace_project_deploy_key_path
(
@project
.
namespace
,
@project
,
deploy_key
),
class:
"btn btn-sm prepend-left-10"
,
method: :put
do
=
link_to
enable_namespace_project_deploy_key_path
(
@project
.
namespace
,
@project
,
deploy_key
),
class:
"btn btn-sm prepend-left-10"
,
method: :put
do
Enable
Enable
-
else
-
else
...
...
app/views/projects/deploy_keys/_form.html.haml
View file @
5967c17e
=
form_for
[
@project
.
namespace
.
becomes
(
Namespace
),
@project
,
@key
],
url:
namespace_project_deploy_keys_path
,
html:
{
class:
"js-requires-input"
}
do
|
f
|
=
form_for
[
@project
.
namespace
.
becomes
(
Namespace
),
@project
,
@
deploy_keys
.
new_
key
],
url:
namespace_project_deploy_keys_path
,
html:
{
class:
"js-requires-input"
}
do
|
f
|
=
form_errors
(
@key
)
=
form_errors
(
@
deploy_keys
.
new_
key
)
.form-group
.form-group
=
f
.
label
:title
,
class:
"label-light"
=
f
.
label
:title
,
class:
"label-light"
=
f
.
text_field
:title
,
class:
'form-control'
,
autofocus:
true
,
required:
true
=
f
.
text_field
:title
,
class:
'form-control'
,
autofocus:
true
,
required:
true
...
...
app/views/projects/deploy_keys/_index.html.haml
View file @
5967c17e
...
@@ -7,31 +7,31 @@
...
@@ -7,31 +7,31 @@
.col-lg-9
.col-lg-9
%h5
.prepend-top-0
%h5
.prepend-top-0
Create a new deploy key for this project
Create a new deploy key for this project
=
render
"projects/deploy_keys/form"
=
render
@deploy_keys
.
form_partial_path
.col-lg-9.col-lg-offset-3
.col-lg-9.col-lg-offset-3
%hr
%hr
.col-lg-9.col-lg-offset-3.append-bottom-default.deploy-keys
.col-lg-9.col-lg-offset-3.append-bottom-default.deploy-keys
%h5
.prepend-top-0
%h5
.prepend-top-0
Enabled deploy keys for this project (
#{
@
enabled_keys
.
size
}
)
Enabled deploy keys for this project (
#{
@
deploy_keys
.
enabled_keys_
size
}
)
-
if
@
enabled_keys
.
any
?
-
if
@
deploy_keys
.
any_keys_enabled
?
%ul
.well-list
%ul
.well-list
-
@enabled_keys
.
each
do
|
enabled_key
|
-
@
deploy_keys
.
enabled_keys
.
each
do
|
enabled_key
|
=
render
partial:
'projects/deploy_keys/deploy_key'
,
locals:
{
deploy_key:
enabled_key
}
=
render
partial:
'projects/deploy_keys/deploy_key'
,
locals:
{
deploy_key:
enabled_key
}
-
else
-
else
.settings-message.text-center
.settings-message.text-center
No deploy keys found. Create one with the form above or add existing one below.
No deploy keys found. Create one with the form above or add existing one below.
%h5
.prepend-top-default
%h5
.prepend-top-default
Deploy keys from projects you have access to (
#{
@
available_project_keys
.
size
}
)
Deploy keys from projects you have access to (
#{
@
deploy_keys
.
available_project_keys_
size
}
)
-
if
@
available_project_keys
.
any
?
-
if
@
deploy_keys
.
any_available_project_keys_enabled
?
%ul
.well-list
%ul
.well-list
-
@available_project_keys
.
each
do
|
available_key
|
-
@
deploy_keys
.
available_project_keys
.
each
do
|
available_key
|
=
render
partial:
'projects/deploy_keys/deploy_key'
,
locals:
{
deploy_key:
available_key
}
=
render
partial:
'projects/deploy_keys/deploy_key'
,
locals:
{
deploy_key:
available_key
}
-
else
-
else
.settings-message.text-center
.settings-message.text-center
No deploy keys from your projects could be found. Create one with the form above or add existing one below.
No deploy keys from your projects could be found. Create one with the form above or add existing one below.
-
if
@
available_public_keys
.
any
?
-
if
@
deploy_keys
.
any_available_public_keys_enabled
?
%h5
.prepend-top-default
%h5
.prepend-top-default
Public deploy keys available to any project (
#{
@
available_public_keys
.
size
}
)
Public deploy keys available to any project (
#{
@
deploy_keys
.
available_public_keys_
size
}
)
%ul
.well-list
%ul
.well-list
-
@available_public_keys
.
each
do
|
available_key
|
-
@
deploy_keys
.
available_public_keys
.
each
do
|
available_key
|
=
render
partial:
'projects/deploy_keys/deploy_key'
,
locals:
{
deploy_key:
available_key
}
=
render
partial:
'projects/deploy_keys/deploy_key'
,
locals:
{
deploy_key:
available_key
}
app/views/projects/settings/repository/show.html.haml
View file @
5967c17e
-
page_title
"Repository"
-
page_title
"Repository"
=
render
"projects/deploy_keys/index"
=
render
@deploy_keys
=
render
"projects/protected_branches/index"
=
render
"projects/protected_branches/index"
spec/presenters/projects/settings/deploy_keys_presenter_spec.rb
0 → 100644
View file @
5967c17e
require
'spec_helper'
describe
Projects
::
Settings
::
DeployKeysPresenter
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:user
)
{
create
(
:user
)
}
subject
(
:presenter
)
do
described_class
.
new
(
project
,
current_user:
user
)
end
it
'inherits from Gitlab::View::Presenter::Simple'
do
expect
(
described_class
.
superclass
).
to
eq
(
Gitlab
::
View
::
Presenter
::
Simple
)
end
describe
'#enabled_keys'
do
let
(
:deploy_key
)
do
create
(
:deploy_keys_project
,
project:
project
).
deploy_key
end
it
'returns project keys'
do
expect
(
presenter
.
enabled_keys
).
to
eq
[
deploy_key
]
end
it
'does not contain enabled_keys inside available_keys'
do
expect
(
presenter
.
available_keys
).
not_to
include
deploy_key
end
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