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

Added delegations to comply with the new rubocop rules

Also fixed the deploy_keys view and moved the code from the repository_helper
to the repository_controller
parent a29517dd
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!
def show def show
...@@ -23,6 +21,27 @@ module Projects ...@@ -23,6 +21,27 @@ 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: {
"Roles" => ProtectedBranch::PushAccessLevel.human_access_levels.map do |id, text|
{ id: id, text: text, before_divider: true }
end
},
merge_access_levels: {
"Roles" => ProtectedBranch::MergeAccessLevel.human_access_levels.map do |id, text|
{ id: id, text: text, before_divider: true }
end
}
}
end
def load_gon_index
open_branches = @project.open_branches.map { |br| { text: br.name, id: br.name, title: br.name } }
params = { open_branches: open_branches }
gon.push(params.merge(access_levels_options))
end
end end
end end
end end
...@@ -15,9 +15,8 @@ module RepositoryHelper ...@@ -15,9 +15,8 @@ module RepositoryHelper
end end
def load_gon_index def load_gon_index
params = { open_branches: @project.open_branches.map do |br| open_branches = @project.open_branches.map { |br| { text: br.name, id: br.name, title: br.name } }
{ text: br.name, id: br.name, title: br.name } params = { open_branches: open_branches }
end }
gon.push(params.merge(access_levels_options)) gon.push(params.merge(access_levels_options))
end end
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,8 +23,7 @@ ...@@ -24,8 +23,7 @@
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 or add existing one below.
...@@ -33,5 +31,4 @@ ...@@ -33,5 +31,4 @@
%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(:empty_project, :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
......
require 'spec_helper'
describe RepositoryHelper do
let(:user) { create(:user, :admin) }
let(:project) { create(:project, :repository) }
before do
project.protected_branches.create(name: 'master')
end
describe 'Access Level Options' do
it 'has three push access levels' do
push_access_levels = helper.access_levels_options[:push_access_levels]["Roles"]
expect(push_access_levels.size).to eq(3)
end
it 'has one merge access level' do
merge_access_levels = helper.access_levels_options[:merge_access_levels]["Roles"]
expect(merge_access_levels.size).to eq(2)
end
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