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
push_access_levels_attributes: [:access_level, :id, :user_id, :_destroy, :group_id])
end
def load_protected_branches
@protected_branches = @project.protected_branches.order(:name).page(params[:page])
end
......
module Projects
module Settings
class RepositoryController < Projects::ApplicationController
include RepositoryHelper
before_action :authorize_admin_project!
before_action :push_rule, only: [:show]
before_action :remote_mirror, only: [:show]
def show
@deploy_keys = DeployKeysPresenter
.new(@project, current_user: @current_user)
.new(@project, current_user: current_user)
define_protected_branches
end
......@@ -33,6 +31,26 @@ module Projects
def load_protected_branches
@protected_branches = @project.protected_branches.order(:name).page(params[:page])
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
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
module Settings
class DeployKeysPresenter < Gitlab::View::Presenter::Simple
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
@key ||= DeployKey.new
......@@ -15,10 +18,6 @@ module Projects
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
......@@ -31,10 +30,6 @@ module Projects
available_project_keys.any?
end
def available_project_keys_size
available_project_keys.size
end
def key_available?(deploy_key)
available_keys.include?(deploy_key)
end
......@@ -53,10 +48,6 @@ module Projects
available_public_keys.any?
end
def available_public_keys_size
available_public_keys.size
end
def to_partial_path
'projects/deploy_keys/index'
end
......
......@@ -15,8 +15,7 @@
Enabled deploy keys for this project (#{@deploy_keys.enabled_keys_size})
- if @deploy_keys.any_keys_enabled?
%ul.well-list
- @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', collection: @deploy_keys.enabled_keys, as: :deploy_key
- else
.settings-message.text-center
No deploy keys found. Create one with the form above.
......@@ -24,14 +23,12 @@
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
- @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', collection: @deploy_keys.available_project_keys, as: :deploy_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.
No deploy keys from your projects could be found. Create one with the form above
- if @deploy_keys.any_available_public_keys_enabled?
%h5.prepend-top-default
Public deploy keys available to any project (#{@deploy_keys.available_public_keys_size})
%ul.well-list
- @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', collection: @deploy_keys.available_public_keys, as: :deploy_key
require 'spec_helper'
describe Projects::Settings::IntegrationsController do
let(:project) { create(:empty_project, :public) }
describe Projects::Settings::RepositoryController do
let(:project) { create(:project_empty_repo, :public) }
let(:user) { create(:user) }
before do
project.team << [user, :master]
project.add_master(user)
sign_in(user)
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