summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/concerns/redirect_request.rb7
-rw-r--r--app/controllers/projects/deploy_keys_controller.rb13
-rw-r--r--app/controllers/projects/protected_branches_controller.rb13
-rw-r--r--app/controllers/projects/settings/repository_controller.rb14
-rw-r--r--app/helpers/repository_helper.rb12
-rw-r--r--app/presenters/projects/settings/deploy_keys_presenter.rb4
-rw-r--r--app/views/projects/deploy_keys/_deploy_key.html.haml2
-rw-r--r--app/views/projects/deploy_keys/_index.html.haml2
-rw-r--r--changelogs/unreleased/26732-combine-deploy-keys-and-push-rules-and-mirror-repository-and-protect-branches-settings-pages.yml2
-rw-r--r--spec/controllers/projects/settings/repository_controller_spec.rb20
-rw-r--r--spec/helpers/repository_helper_spec.rb22
-rw-r--r--spec/presenters/projects/settings/deploy_keys_presenter_spec.rb43
12 files changed, 121 insertions, 33 deletions
diff --git a/app/controllers/concerns/redirect_request.rb b/app/controllers/concerns/redirect_request.rb
new file mode 100644
index 00000000000..acab5a8446a
--- /dev/null
+++ b/app/controllers/concerns/redirect_request.rb
@@ -0,0 +1,7 @@
+module RedirectRequest
+ extend ActiveSupport::Concern
+
+ def redirect_to_repository_settings(project)
+ redirect_to namespace_project_settings_repository_path(project.namespace, project)
+ end
+end
diff --git a/app/controllers/projects/deploy_keys_controller.rb b/app/controllers/projects/deploy_keys_controller.rb
index 0d60e782dfb..465757e07b1 100644
--- a/app/controllers/projects/deploy_keys_controller.rb
+++ b/app/controllers/projects/deploy_keys_controller.rb
@@ -1,4 +1,5 @@
class Projects::DeployKeysController < Projects::ApplicationController
+ include RedirectRequest
respond_to :html
# Authorize
@@ -7,32 +8,32 @@ class Projects::DeployKeysController < Projects::ApplicationController
layout "project_settings"
def index
- redirect_to namespace_project_settings_repository_path(@project.namespace, @project)
+ redirect_to_repository_settings(@project)
end
def new
- redirect_to namespace_project_settings_repository_path(@project.namespace, @project)
+ redirect_to_repository_settings(@project)
end
def create
@key = DeployKey.new(deploy_key_params.merge(user: current_user))
unless @key.valid? && @project.deploy_keys << @key
- flash[:alert] = @key.errors.full_messages.join(',').html_safe
+ flash[:alert] = @key.errors.full_messages.join(', ').html_safe
end
- redirect_to namespace_project_settings_repository_path(@project.namespace, @project)
+ redirect_to_repository_settings(@project)
end
def enable
Projects::EnableDeployKeyService.new(@project, current_user, params).execute
- redirect_to namespace_project_settings_repository_path(@project.namespace, @project)
+ redirect_to_repository_settings(@project)
end
def disable
@project.deploy_keys_projects.find_by(deploy_key_id: params[:id]).destroy
- redirect_to namespace_project_settings_repository_path(@project.namespace, @project)
+ redirect_to_repository_settings(@project)
end
protected
diff --git a/app/controllers/projects/protected_branches_controller.rb b/app/controllers/projects/protected_branches_controller.rb
index 1c22b9c2ca8..b7817a71e0d 100644
--- a/app/controllers/projects/protected_branches_controller.rb
+++ b/app/controllers/projects/protected_branches_controller.rb
@@ -1,4 +1,5 @@
class Projects::ProtectedBranchesController < Projects::ApplicationController
+ include RedirectRequest
# Authorize
before_action :require_non_empty_project
before_action :authorize_admin_project!
@@ -7,15 +8,15 @@ class Projects::ProtectedBranchesController < Projects::ApplicationController
layout "project_settings"
def index
- redirect_to namespace_project_settings_repository_path(@project.namespace, @project)
+ redirect_to_repository_settings(@project)
end
def create
@protected_branch = ::ProtectedBranches::CreateService.new(@project, current_user, protected_branch_params).execute
unless @protected_branch.persisted?
- flash[:alert] = @protected_branches.errors.full_messages.join(',').html_safe
+ flash[:alert] = @protected_branches.errors.full_messages.join(', ').html_safe
end
- redirect_to namespace_project_settings_repository_path(@project.namespace, @project)
+ redirect_to_repository_settings(@project)
end
def show
@@ -40,7 +41,7 @@ class Projects::ProtectedBranchesController < Projects::ApplicationController
@protected_branch.destroy
respond_to do |format|
- format.html { redirect_to namespace_project_settings_repository_path }
+ format.html { redirect_to_repository_settings(@project) }
format.js { head :ok }
end
end
@@ -56,8 +57,4 @@ class Projects::ProtectedBranchesController < Projects::ApplicationController
merge_access_levels_attributes: [:access_level, :id],
push_access_levels_attributes: [:access_level, :id])
end
-
- def load_protected_branches
- @protected_branches = @project.protected_branches.order(:name).page(params[:page])
- end
end
diff --git a/app/controllers/projects/settings/repository_controller.rb b/app/controllers/projects/settings/repository_controller.rb
index a8c6a1b419c..3c9417b9270 100644
--- a/app/controllers/projects/settings/repository_controller.rb
+++ b/app/controllers/projects/settings/repository_controller.rb
@@ -4,25 +4,25 @@ module Projects
include RepositoryHelper
before_action :authorize_admin_project!
- before_action :load_protected_branches, only: [:show]
def show
@deploy_keys = DeployKeysPresenter
.new(@project, current_user: @current_user)
- define_protected_branches_controller
- end
-
- def load_protected_branches
- @protected_branches = @project.protected_branches.order(:name).page(params[:page])
+ define_protected_branches
end
private
- def define_protected_branches_controller
+ def define_protected_branches
+ load_protected_branches
@protected_branch = @project.protected_branches.new
load_gon_index
end
+
+ def load_protected_branches
+ @protected_branches = @project.protected_branches.order(:name).page(params[:page])
+ end
end
end
end
diff --git a/app/helpers/repository_helper.rb b/app/helpers/repository_helper.rb
index a079f1a889c..e34f9338b54 100644
--- a/app/helpers/repository_helper.rb
+++ b/app/helpers/repository_helper.rb
@@ -2,16 +2,22 @@ module RepositoryHelper
def access_levels_options
{
push_access_levels: {
- "Roles" => ProtectedBranch::PushAccessLevel.human_access_levels.map { |id, text| { id: id, text: text, before_divider: true } },
+ "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 { |id, text| { id: id, text: text, before_divider: true } }
+ "Roles" => ProtectedBranch::MergeAccessLevel.human_access_levels.map do |id, text|
+ { id: id, text: text, before_divider: true }
+ end
}
}
end
def load_gon_index
- params = { open_branches: @project.open_branches.map { |br| { text: br.name, id: br.name, title: br.name } } }
+ params = { open_branches: @project.open_branches.map do |br|
+ { text: br.name, id: br.name, title: br.name }
+ end }
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 703d93708f6..25be14bd28b 100644
--- a/app/presenters/projects/settings/deploy_keys_presenter.rb
+++ b/app/presenters/projects/settings/deploy_keys_presenter.rb
@@ -35,6 +35,10 @@ module Projects
available_project_keys.size
end
+ def key_available?(deploy_key)
+ available_keys.include?(deploy_key)
+ end
+
def available_public_keys
return @available_public_keys if defined?(@available_public_keys)
diff --git a/app/views/projects/deploy_keys/_deploy_key.html.haml b/app/views/projects/deploy_keys/_deploy_key.html.haml
index 337f8c38a93..ec8fc4c9ee8 100644
--- a/app/views/projects/deploy_keys/_deploy_key.html.haml
+++ b/app/views/projects/deploy_keys/_deploy_key.html.haml
@@ -18,7 +18,7 @@
%span.key-created-at
created #{time_ago_with_tooltip(deploy_key.created_at)}
.visible-xs-block.visible-sm-block
- - if @deploy_keys.available_keys.include?(deploy_key)
+ - if @deploy_keys.key_available?(deploy_key)
= link_to enable_namespace_project_deploy_key_path(@project.namespace, @project, deploy_key), class: "btn btn-sm prepend-left-10", method: :put do
Enable
- else
diff --git a/app/views/projects/deploy_keys/_index.html.haml b/app/views/projects/deploy_keys/_index.html.haml
index 91acad83bf3..9f351d3b90e 100644
--- a/app/views/projects/deploy_keys/_index.html.haml
+++ b/app/views/projects/deploy_keys/_index.html.haml
@@ -19,7 +19,7 @@
= render partial: 'projects/deploy_keys/deploy_key', locals: {deploy_key: enabled_key}
- else
.settings-message.text-center
- No deploy keys found. Create one with the form above or add existing one below.
+ No deploy keys found. Create one with the form above.
%h5.prepend-top-default
Deploy keys from projects you have access to (#{@deploy_keys.available_project_keys_size})
- if @deploy_keys.any_available_project_keys_enabled?
diff --git a/changelogs/unreleased/26732-combine-deploy-keys-and-push-rules-and-mirror-repository-and-protect-branches-settings-pages.yml b/changelogs/unreleased/26732-combine-deploy-keys-and-push-rules-and-mirror-repository-and-protect-branches-settings-pages.yml
index 5a41a6df620..6fc4615dab8 100644
--- a/changelogs/unreleased/26732-combine-deploy-keys-and-push-rules-and-mirror-repository-and-protect-branches-settings-pages.yml
+++ b/changelogs/unreleased/26732-combine-deploy-keys-and-push-rules-and-mirror-repository-and-protect-branches-settings-pages.yml
@@ -1,5 +1,5 @@
---
-title: Combined deploy keys and push rules settings options into a single one called
+title: Combined deploy keys, push rules, protect branches and mirror repository settings options into a single one called
Repository
merge_request:
author:
diff --git a/spec/controllers/projects/settings/repository_controller_spec.rb b/spec/controllers/projects/settings/repository_controller_spec.rb
new file mode 100644
index 00000000000..65f7bb34f4a
--- /dev/null
+++ b/spec/controllers/projects/settings/repository_controller_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe Projects::Settings::IntegrationsController do
+ let(:project) { create(:empty_project, :public) }
+ let(:user) { create(:user) }
+
+ before do
+ project.team << [user, :master]
+ sign_in(user)
+ end
+
+ describe 'GET show' do
+ it 'renders show with 200 status code' do
+ get :show, namespace_id: project.namespace, project_id: project
+
+ expect(response).to have_http_status(200)
+ expect(response).to render_template(:show)
+ end
+ end
+end
diff --git a/spec/helpers/repository_helper_spec.rb b/spec/helpers/repository_helper_spec.rb
new file mode 100644
index 00000000000..f2a68cb2eae
--- /dev/null
+++ b/spec/helpers/repository_helper_spec.rb
@@ -0,0 +1,22 @@
+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
diff --git a/spec/presenters/projects/settings/deploy_keys_presenter_spec.rb b/spec/presenters/projects/settings/deploy_keys_presenter_spec.rb
index 26ed9ac93a0..8faaaf55d72 100644
--- a/spec/presenters/projects/settings/deploy_keys_presenter_spec.rb
+++ b/spec/presenters/projects/settings/deploy_keys_presenter_spec.rb
@@ -3,6 +3,11 @@ require 'spec_helper'
describe Projects::Settings::DeployKeysPresenter do
let(:project) { create(:empty_project) }
let(:user) { create(:user) }
+ let(:deploy_key) { create(:deploy_key, public: true) }
+
+ let!(:deploy_keys_project) do
+ create(:deploy_keys_project, project: project, deploy_key: deploy_key)
+ end
subject(:presenter) do
described_class.new(project, current_user: user)
@@ -13,16 +18,42 @@ describe Projects::Settings::DeployKeysPresenter do
end
describe '#enabled_keys' do
- let(:deploy_key) do
- create(:deploy_keys_project, project: project).deploy_key
- end
-
- it 'returns project keys' do
- expect(presenter.enabled_keys).to eq [deploy_key]
+ it 'returns currently enabled keys' do
+ expect(presenter.enabled_keys).to eq [deploy_keys_project.deploy_key]
end
it 'does not contain enabled_keys inside available_keys' do
expect(presenter.available_keys).not_to include deploy_key
end
+
+ it 'returns the enabled_keys size' do
+ expect(presenter.enabled_keys_size).to eq(1)
+ end
+
+ it 'returns true if there is any enabled_keys' do
+ expect(presenter.any_keys_enabled?).to eq(true)
+ end
+ end
+
+ describe '#available_keys/#available_project_keys' do
+ it 'returns the current available_keys' do
+ expect(presenter.available_keys).to be_empty
+ end
+
+ it 'returns the current available_project_keys' do
+ expect(presenter.available_project_keys).to be_empty
+ end
+
+ it 'returns if any available_project_keys are enabled' do
+ expect(presenter.any_available_project_keys_enabled?).to eq(false)
+ end
+
+ it 'returns the available_project_keys size' do
+ expect(presenter.available_project_keys_size).to eq(0)
+ end
+
+ it 'shows if there is an available key' do
+ expect(presenter.key_available?(deploy_key)).to eq(false)
+ end
end
end