Commit b2bbb997 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Removed repository_helper.rb

Used collection on the deploy_keys/_index.html partial render calls,
also added delegate methods on the deploy_keys_presenter.rb

Fixed the repository_controller_spec.rb
parent 51f7245e
...@@ -58,6 +58,7 @@ class Projects::ProtectedBranchesController < Projects::ApplicationController ...@@ -58,6 +58,7 @@ class Projects::ProtectedBranchesController < Projects::ApplicationController
push_access_levels_attributes: [:access_level, :id, :user_id, :_destroy, :group_id]) push_access_levels_attributes: [:access_level, :id, :user_id, :_destroy, :group_id])
end end
def load_protected_branches def load_protected_branches
@protected_branches = @project.protected_branches.order(:name).page(params[:page]) @protected_branches = @project.protected_branches.order(:name).page(params[:page])
end end
......
module Projects module Projects
module Settings module Settings
class RepositoryController < Projects::ApplicationController class RepositoryController < Projects::ApplicationController
include RepositoryHelper
before_action :authorize_admin_project! before_action :authorize_admin_project!
before_action :push_rule, only: [:show] before_action :push_rule, only: [:show]
before_action :remote_mirror, only: [:show] before_action :remote_mirror, only: [:show]
def show def show
@deploy_keys = DeployKeysPresenter @deploy_keys = DeployKeysPresenter
.new(@project, current_user: @current_user) .new(@project, current_user: current_user)
define_protected_branches define_protected_branches
end end
...@@ -33,6 +31,26 @@ module Projects ...@@ -33,6 +31,26 @@ module Projects
def load_protected_branches def load_protected_branches
@protected_branches = @project.protected_branches.order(:name).page(params[:page]) @protected_branches = @project.protected_branches.order(:name).page(params[:page])
end end
def access_levels_options
{
push_access_levels: ProtectedBranch::PushAccessLevel.human_access_levels.map { |id, text| { id: id, text: text } },
merge_access_levels: ProtectedBranch::MergeAccessLevel.human_access_levels.map { |id, text| { id: id, text: text } },
selected_merge_access_levels: @protected_branch.merge_access_levels.map { |access_level| access_level.user_id || access_level.access_level },
selected_push_access_levels: @protected_branch.push_access_levels.map { |access_level| access_level.user_id || access_level.access_level }
}
end
def open_branches
branches = @project.open_branches.map { |br| { text: br.name, id: br.name, title: br.name } }
{ open_branches: branches }
end
def load_gon_index
params = open_branches
params[:current_project_id] = @project.id if @project
gon.push(params.merge(access_levels_options))
end
end end
end end
end end
module RepositoryHelper
def access_levels_options
{
push_access_levels: ProtectedBranch::PushAccessLevel.human_access_levels.map do |id, text|
{ id: id, text: text }
end,
merge_access_levels: ProtectedBranch::MergeAccessLevel.human_access_levels.map do |id, text|
{ id: id, text: text }
end,
selected_merge_access_levels: @protected_branch.merge_access_levels.map do |access_level|
access_level.user_id || access_level.access_level
end,
selected_push_access_levels: @protected_branch.push_access_levels.map do |access_level|
access_level.user_id || access_level.access_level
end
}
end
def load_gon_index
params = { open_branches: @project.open_branches.map do |br|
{ text: br.name, id: br.name, title: br.name }
end }
params.merge!(current_project_id: @project.id) if @project
gon.push(params.merge(access_levels_options))
end
end
...@@ -2,6 +2,9 @@ module Projects ...@@ -2,6 +2,9 @@ module Projects
module Settings module Settings
class DeployKeysPresenter < Gitlab::View::Presenter::Simple class DeployKeysPresenter < Gitlab::View::Presenter::Simple
presents :project presents :project
delegate :size, to: :enabled_keys, prefix: true
delegate :size, to: :available_project_keys, prefix: true
delegate :size, to: :available_public_keys, prefix: true
def new_key def new_key
@key ||= DeployKey.new @key ||= DeployKey.new
...@@ -15,10 +18,6 @@ module Projects ...@@ -15,10 +18,6 @@ module Projects
enabled_keys.any? enabled_keys.any?
end end
def enabled_keys_size
enabled_keys.size
end
def available_keys def available_keys
@available_keys ||= current_user.accessible_deploy_keys - enabled_keys @available_keys ||= current_user.accessible_deploy_keys - enabled_keys
end end
...@@ -31,10 +30,6 @@ module Projects ...@@ -31,10 +30,6 @@ module Projects
available_project_keys.any? available_project_keys.any?
end end
def available_project_keys_size
available_project_keys.size
end
def key_available?(deploy_key) def key_available?(deploy_key)
available_keys.include?(deploy_key) available_keys.include?(deploy_key)
end end
...@@ -53,10 +48,6 @@ module Projects ...@@ -53,10 +48,6 @@ module Projects
available_public_keys.any? available_public_keys.any?
end end
def available_public_keys_size
available_public_keys.size
end
def to_partial_path def to_partial_path
'projects/deploy_keys/index' 'projects/deploy_keys/index'
end end
......
...@@ -15,8 +15,7 @@ ...@@ -15,8 +15,7 @@
Enabled deploy keys for this project (#{@deploy_keys.enabled_keys_size}) Enabled deploy keys for this project (#{@deploy_keys.enabled_keys_size})
- if @deploy_keys.any_keys_enabled? - if @deploy_keys.any_keys_enabled?
%ul.well-list %ul.well-list
- @deploy_keys.enabled_keys.each do |enabled_key| = render partial: 'projects/deploy_keys/deploy_key', collection: @deploy_keys.enabled_keys, as: :deploy_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. No deploy keys found. Create one with the form above.
...@@ -24,14 +23,12 @@ ...@@ -24,14 +23,12 @@
Deploy keys from projects you have access to (#{@deploy_keys.available_project_keys_size}) Deploy keys from projects you have access to (#{@deploy_keys.available_project_keys_size})
- if @deploy_keys.any_available_project_keys_enabled? - if @deploy_keys.any_available_project_keys_enabled?
%ul.well-list %ul.well-list
- @deploy_keys.available_project_keys.each do |available_key| = render partial: 'projects/deploy_keys/deploy_key', collection: @deploy_keys.available_project_keys, as: :deploy_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
- if @deploy_keys.any_available_public_keys_enabled? - if @deploy_keys.any_available_public_keys_enabled?
%h5.prepend-top-default %h5.prepend-top-default
Public deploy keys available to any project (#{@deploy_keys.available_public_keys_size}) Public deploy keys available to any project (#{@deploy_keys.available_public_keys_size})
%ul.well-list %ul.well-list
- @deploy_keys.available_public_keys.each do |available_key| = render partial: 'projects/deploy_keys/deploy_key', collection: @deploy_keys.available_public_keys, as: :deploy_key
= render partial: 'projects/deploy_keys/deploy_key', locals: {deploy_key: available_key}
require 'spec_helper' require 'spec_helper'
describe Projects::Settings::IntegrationsController do describe Projects::Settings::RepositoryController do
let(:project) { create(:empty_project, :public) } let(:project) { create(:project_empty_repo, :public) }
let(:user) { create(:user) } let(:user) { create(:user) }
before do before do
project.team << [user, :master] project.add_master(user)
sign_in(user) sign_in(user)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment