summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-01-31 15:12:02 +0100
committerJose Ivan Vargas <jvargas@gitlab.com>2017-03-06 09:47:44 -0600
commit5967c17e80ec0e17a2bdc615e18d1cb0a668f68f (patch)
tree5a55652f078056ae865afe1f37c5758a62fe614d /app
parent2ee86441158076344a07f2715a148a5bdbe161b0 (diff)
downloadgitlab-ce-5967c17e80ec0e17a2bdc615e18d1cb0a668f68f.tar.gz
Introduced the deploy keys presenter
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects/settings/repository_controller.rb21
-rw-r--r--app/presenters/projects/settings/deploy_keys_presenter.rb65
-rw-r--r--app/views/projects/deploy_keys/_deploy_key.html.haml2
-rw-r--r--app/views/projects/deploy_keys/_form.html.haml4
-rw-r--r--app/views/projects/deploy_keys/_index.html.haml20
-rw-r--r--app/views/projects/settings/repository/show.html.haml2
6 files changed, 82 insertions, 32 deletions
diff --git a/app/controllers/projects/settings/repository_controller.rb b/app/controllers/projects/settings/repository_controller.rb
index 3b04eb04ae0..99a3756531f 100644
--- a/app/controllers/projects/settings/repository_controller.rb
+++ b/app/controllers/projects/settings/repository_controller.rb
@@ -7,7 +7,9 @@ module Projects
before_action :load_protected_branches, only: [:show]
def show
- define_deploy_keys_variables
+ @deploy_keys = DeployKeysPresenter
+ .new(@project, current_user: @current_user)
+
define_protected_branches_controller
end
@@ -15,25 +17,8 @@ module Projects
@protected_branches = @project.protected_branches.order(:name).page(params[:page])
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
- def define_deploy_keys_variables
- @key = DeployKey.new
- set_index_vars
- end
-
def define_protected_branches_controller
@protected_branch = @project.protected_branches.new
load_gon_index(@project)
diff --git a/app/presenters/projects/settings/deploy_keys_presenter.rb b/app/presenters/projects/settings/deploy_keys_presenter.rb
new file mode 100644
index 00000000000..703d93708f6
--- /dev/null
+++ b/app/presenters/projects/settings/deploy_keys_presenter.rb
@@ -0,0 +1,65 @@
+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
diff --git a/app/views/projects/deploy_keys/_deploy_key.html.haml b/app/views/projects/deploy_keys/_deploy_key.html.haml
index d1e3cb14022..337f8c38a93 100644
--- a/app/views/projects/deploy_keys/_deploy_key.html.haml
+++ b/app/views/projects/deploy_keys/_deploy_key.html.haml
@@ -18,7 +18,7 @@
%span.key-created-at
created #{time_ago_with_tooltip(deploy_key.created_at)}
.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
Enable
- else
diff --git a/app/views/projects/deploy_keys/_form.html.haml b/app/views/projects/deploy_keys/_form.html.haml
index c91bb9c255a..1421da72418 100644
--- a/app/views/projects/deploy_keys/_form.html.haml
+++ b/app/views/projects/deploy_keys/_form.html.haml
@@ -1,5 +1,5 @@
-= form_for [@project.namespace.becomes(Namespace), @project, @key], url: namespace_project_deploy_keys_path, html: { class: "js-requires-input" } do |f|
- = form_errors(@key)
+= 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(@deploy_keys.new_key)
.form-group
= f.label :title, class: "label-light"
= f.text_field :title, class: 'form-control', autofocus: true, required: true
diff --git a/app/views/projects/deploy_keys/_index.html.haml b/app/views/projects/deploy_keys/_index.html.haml
index c41fb892862..91acad83bf3 100644
--- a/app/views/projects/deploy_keys/_index.html.haml
+++ b/app/views/projects/deploy_keys/_index.html.haml
@@ -7,31 +7,31 @@
.col-lg-9
%h5.prepend-top-0
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
%hr
.col-lg-9.col-lg-offset-3.append-bottom-default.deploy-keys
%h5.prepend-top-0
- Enabled deploy keys for this project (#{@enabled_keys.size})
- - if @enabled_keys.any?
+ Enabled deploy keys for this project (#{@deploy_keys.enabled_keys_size})
+ - if @deploy_keys.any_keys_enabled?
%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}
- else
.settings-message.text-center
No deploy keys found. Create one with the form above or add existing one below.
%h5.prepend-top-default
- Deploy keys from projects you have access to (#{@available_project_keys.size})
- - if @available_project_keys.any?
+ Deploy keys from projects you have access to (#{@deploy_keys.available_project_keys_size})
+ - if @deploy_keys.any_available_project_keys_enabled?
%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}
- else
.settings-message.text-center
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
- 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
- - @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}
diff --git a/app/views/projects/settings/repository/show.html.haml b/app/views/projects/settings/repository/show.html.haml
index 88291653d84..95d821f6135 100644
--- a/app/views/projects/settings/repository/show.html.haml
+++ b/app/views/projects/settings/repository/show.html.haml
@@ -1,4 +1,4 @@
- page_title "Repository"
-= render "projects/deploy_keys/index"
+= render @deploy_keys
= render "projects/protected_branches/index"