This instance will be upgraded to Heptapod 0.31.0 (final) on 2022-05-24 at 14:00 UTC+2 (a few minutes of down time)

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

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 cdfcb28c0d3d
module Projects
module Settings
class RepositoryController < Projects::ApplicationController
include RepositoryHelper
before_action :authorize_admin_project!
def show
......@@ -23,6 +21,27 @@ def define_protected_branches
def load_protected_branches
@protected_branches = @project.protected_branches.order(:name).page(params[:page])
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
......@@ -15,9 +15,8 @@ def access_levels_options
end
def load_gon_index
params = { open_branches: @project.open_branches.map do |br|
{ text: br.name, id: br.name, title: br.name }
end }
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
......@@ -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 @@ 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
......@@ -31,10 +30,6 @@ def any_available_project_keys_enabled?
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 @@ 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
......
......@@ -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,8 +23,7 @@
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.
......@@ -33,5 +31,4 @@
%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
describe Projects::Settings::RepositoryController do
let(:project) { create(:empty_project, :public) }
let(:user) { create(:user) }
before do
project.team << [user, :master]
project.add_master(user)
sign_in(user)
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