diff options
-rw-r--r-- | app/controllers/projects/settings/repository_controller.rb | 23 | ||||
-rw-r--r-- | app/helpers/repository_helper.rb | 5 | ||||
-rw-r--r-- | app/presenters/projects/settings/deploy_keys_presenter.rb | 15 | ||||
-rw-r--r-- | app/views/projects/deploy_keys/_index.html.haml | 9 | ||||
-rw-r--r-- | spec/controllers/projects/settings/repository_controller_spec.rb | 4 | ||||
-rw-r--r-- | spec/helpers/repository_helper_spec.rb | 22 |
6 files changed, 31 insertions, 47 deletions
diff --git a/app/controllers/projects/settings/repository_controller.rb b/app/controllers/projects/settings/repository_controller.rb index 3c9417b9270..7a1edee0822 100644 --- a/app/controllers/projects/settings/repository_controller.rb +++ b/app/controllers/projects/settings/repository_controller.rb @@ -1,8 +1,6 @@ module Projects module Settings class RepositoryController < Projects::ApplicationController - include RepositoryHelper - before_action :authorize_admin_project! def show @@ -23,6 +21,27 @@ module Projects 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 diff --git a/app/helpers/repository_helper.rb b/app/helpers/repository_helper.rb index e34f9338b54..cd0ca3f9450 100644 --- a/app/helpers/repository_helper.rb +++ b/app/helpers/repository_helper.rb @@ -15,9 +15,8 @@ module RepositoryHelper 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 diff --git a/app/presenters/projects/settings/deploy_keys_presenter.rb b/app/presenters/projects/settings/deploy_keys_presenter.rb index 25be14bd28b..86ac513b3c0 100644 --- a/app/presenters/projects/settings/deploy_keys_presenter.rb +++ b/app/presenters/projects/settings/deploy_keys_presenter.rb @@ -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 diff --git a/app/views/projects/deploy_keys/_index.html.haml b/app/views/projects/deploy_keys/_index.html.haml index 9f351d3b90e..0cbe9b3275a 100644 --- a/app/views/projects/deploy_keys/_index.html.haml +++ b/app/views/projects/deploy_keys/_index.html.haml @@ -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 diff --git a/spec/controllers/projects/settings/repository_controller_spec.rb b/spec/controllers/projects/settings/repository_controller_spec.rb index 65f7bb34f4a..77faf96033d 100644 --- a/spec/controllers/projects/settings/repository_controller_spec.rb +++ b/spec/controllers/projects/settings/repository_controller_spec.rb @@ -1,11 +1,11 @@ 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 diff --git a/spec/helpers/repository_helper_spec.rb b/spec/helpers/repository_helper_spec.rb deleted file mode 100644 index f2a68cb2eae..00000000000 --- a/spec/helpers/repository_helper_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -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 |