Commit 77bdb5d0 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Port of...

Port of 26732-combine-deploy-keys-and-push-rules-and-mirror-repository-and-protect-branches-settings-pages to EE
parent bf163b9d
...@@ -290,7 +290,7 @@ const UserCallout = require('./user_callout'); ...@@ -290,7 +290,7 @@ const UserCallout = require('./user_callout');
case 'admin:emails:show': case 'admin:emails:show':
new AdminEmailSelect(); new AdminEmailSelect();
break; break;
case 'projects:protected_branches:index': case 'projects:repository:show':
new gl.ProtectedBranchCreate(); new gl.ProtectedBranchCreate();
new gl.ProtectedBranchEditList(); new gl.ProtectedBranchEditList();
break; break;
......
...@@ -7,25 +7,22 @@ class Projects::DeployKeysController < Projects::ApplicationController ...@@ -7,25 +7,22 @@ class Projects::DeployKeysController < Projects::ApplicationController
layout "project_settings" layout "project_settings"
def index def index
@key = DeployKey.new redirect_to namespace_project_settings_repository_path(@project.namespace, @project)
set_index_vars
end end
def new def new
redirect_to namespace_project_deploy_keys_path(@project.namespace, @project) redirect_to namespace_project_settings_repository_path(@project.namespace, @project)
end end
def create def create
@key = DeployKey.new(deploy_key_params.merge(user: current_user)) @key = DeployKey.new(deploy_key_params.merge(user: current_user))
set_index_vars
if @key.valid? && @project.deploy_keys << @key unless @key.valid? && @project.deploy_keys << @key
log_audit_event(@key.title, action: :create) flash[:alert] = @key.errors.full_messages.join(',').html_safe
redirect_to namespace_project_deploy_keys_path(@project.namespace, @project)
else else
render "index" log_audit_event(@key.title, action: :create)
end end
redirect_to namespace_project_settings_repository_path(@project.namespace, @project)
end end
def enable def enable
...@@ -33,7 +30,7 @@ class Projects::DeployKeysController < Projects::ApplicationController ...@@ -33,7 +30,7 @@ class Projects::DeployKeysController < Projects::ApplicationController
Projects::EnableDeployKeyService.new(@project, current_user, params).execute Projects::EnableDeployKeyService.new(@project, current_user, params).execute
log_audit_event(@key.title, action: :create) log_audit_event(@key.title, action: :create)
redirect_to namespace_project_deploy_keys_path(@project.namespace, @project) redirect_to namespace_project_settings_repository_path(@project.namespace, @project)
end end
def disable def disable
...@@ -41,23 +38,11 @@ class Projects::DeployKeysController < Projects::ApplicationController ...@@ -41,23 +38,11 @@ class Projects::DeployKeysController < Projects::ApplicationController
@project.deploy_keys_projects.find_by(deploy_key_id: params[:id]).destroy @project.deploy_keys_projects.find_by(deploy_key_id: params[:id]).destroy
log_audit_event(@key.title, action: :destroy) log_audit_event(@key.title, action: :destroy)
redirect_back_or_default(default: { action: 'index' }) redirect_to namespace_project_settings_repository_path(@project.namespace, @project)
end end
protected protected
def set_index_vars
@enabled_keys ||= @project.deploy_keys
@available_keys ||= current_user.accessible_deploy_keys - @enabled_keys
@available_project_keys ||= current_user.project_deploy_keys - @enabled_keys
@available_public_keys ||= DeployKey.are_public - @enabled_keys
# Public keys that are already used by another accessible project are already
# in @available_project_keys.
@available_public_keys -= @available_project_keys
end
def deploy_key_params def deploy_key_params
params.require(:deploy_key).permit(:key, :title, :can_push) params.require(:deploy_key).permit(:key, :title, :can_push)
end end
......
class Projects::ProtectedBranchesController < Projects::ApplicationController class Projects::ProtectedBranchesController < Projects::ApplicationController
include RepositoryHelper
# Authorize # Authorize
before_action :require_non_empty_project before_action :require_non_empty_project
before_action :authorize_admin_project! before_action :authorize_admin_project!
before_action :load_protected_branch, only: [:show, :update, :destroy] before_action :load_protected_branch, only: [:show, :update, :destroy]
before_action :load_protected_branches, only: [:index]
layout "project_settings" layout "project_settings"
def index def index
@protected_branch = @project.protected_branches.new redirect_to namespace_project_settings_repository_path(@project.namespace, @project)
load_gon_index
end end
def create def create
@protected_branch = ::ProtectedBranches::CreateService.new(@project, current_user, protected_branch_params).execute @protected_branch = ::ProtectedBranches::CreateService.new(@project, current_user, protected_branch_params).execute
unless @protected_branch.persisted?
if @protected_branch.persisted? flash[:alert] = @protected_branches.errors.full_messages.join(',').html_safe
redirect_to namespace_project_protected_branches_path(@project.namespace, @project)
else
load_protected_branches
load_gon_index
render :index
end end
redirect_to namespace_project_settings_repository_path(@project.namespace, @project)
end end
def show def show
...@@ -46,7 +41,7 @@ class Projects::ProtectedBranchesController < Projects::ApplicationController ...@@ -46,7 +41,7 @@ class Projects::ProtectedBranchesController < Projects::ApplicationController
@protected_branch.destroy @protected_branch.destroy
respond_to do |format| respond_to do |format|
format.html { redirect_to namespace_project_protected_branches_path } format.html { redirect_to namespace_project_settings_repository_path }
format.js { head :ok } format.js { head :ok }
end end
end end
......
module Projects
module Settings
class RepositoryController < Projects::ApplicationController
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])
end
private
def define_protected_branches_controller
@protected_branch = @project.protected_branches.new
load_gon_index(@project)
end
end
end
end
module RepositoryHelper
def access_levels_options
{
push_access_levels: ProtectedBranch::PushAccessLevel.human_access_levels.map { |id, text| { id: id, text: text, before_divider: true } },
merge_access_levels: ProtectedBranch::MergeAccessLevel.human_access_levels.map { |id, text| { id: id, text: text, before_divider: true } }
}
end
def load_gon_index(project)
params = { open_branches: project.open_branches.map { |br| { text: br.name, id: br.name, title: br.name } } }
gon.push(params.merge(access_levels_options))
end
end
module Projects
module Settings
class DeployKeysPresenter < Gitlab::View::Presenter::Simple
presents :project
def new_key
@key ||= DeployKey.new
end
def enabled_keys
@enabled_keys ||= project.deploy_keys
end
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
def available_project_keys
@available_project_keys ||= current_user.project_deploy_keys - enabled_keys
end
def any_available_project_keys_enabled?
available_project_keys.any?
end
def available_project_keys_size
available_project_keys.size
end
def available_public_keys
return @available_public_keys if defined?(@available_public_keys)
@available_public_keys ||= DeployKey.are_public - enabled_keys
# Public keys that are already used by another accessible project are already
# in @available_project_keys.
@available_public_keys -= available_project_keys
end
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
def form_partial_path
'projects/deploy_keys/form'
end
end
end
end
...@@ -4,18 +4,14 @@ ...@@ -4,18 +4,14 @@
%span %span
Members Members
- if can_edit - if can_edit
= nav_link(controller: :deploy_keys) do = nav_link(controller: :repository) do
= link_to namespace_project_deploy_keys_path(@project.namespace, @project), title: 'Deploy Keys' do = link_to namespace_project_settings_repository_path(@project.namespace, @project), title: 'Repository' do
%span %span
Deploy Keys Repository
= nav_link(controller: :integrations) do = nav_link(controller: :integrations) do
= link_to namespace_project_settings_integrations_path(@project.namespace, @project), title: 'Integrations' do = link_to namespace_project_settings_integrations_path(@project.namespace, @project), title: 'Integrations' do
%span %span
Integrations Integrations
= nav_link(controller: :protected_branches) do
= link_to namespace_project_protected_branches_path(@project.namespace, @project), title: 'Protected Branches' do
%span
Protected Branches
- if @project.feature_available?(:builds, current_user) - if @project.feature_available?(:builds, current_user)
= nav_link(controller: :ci_cd) do = nav_link(controller: :ci_cd) do
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
%span.key-created-at %span.key-created-at
created #{time_ago_with_tooltip(deploy_key.created_at)} created #{time_ago_with_tooltip(deploy_key.created_at)}
.visible-xs-block.visible-sm-block .visible-xs-block.visible-sm-block
- if @available_keys.include?(deploy_key) - if @deploy_keys.available_keys.include?(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 = link_to enable_namespace_project_deploy_key_path(@project.namespace, @project, deploy_key), class: "btn btn-sm prepend-left-10", method: :put do
Enable Enable
- else - else
......
= form_for [@project.namespace.becomes(Namespace), @project, @key], url: namespace_project_deploy_keys_path, html: { class: "js-requires-input" } do |f| = form_for [@project.namespace.becomes(Namespace), @project, @deploy_keys.new_key], url: namespace_project_deploy_keys_path, html: { class: "js-requires-input" } do |f|
= form_errors(@key) = form_errors(@deploy_keys.new_key)
.form-group .form-group
= f.label :title, class: "label-light" = f.label :title, class: "label-light"
= f.text_field :title, class: 'form-control', autofocus: true, required: true = f.text_field :title, class: 'form-control', autofocus: true, required: true
......
- page_title "Deploy Keys"
.row.prepend-top-default .row.prepend-top-default
.col-lg-3.profile-settings-sidebar .col-lg-3.profile-settings-sidebar
%h4.prepend-top-0 %h4.prepend-top-0
= page_title Deploy Keys
%p %p
Deploy keys allow read-only access to your repository. Deploy keys can be used for CI, staging or production servers. You can create a deploy key or add an existing one. Deploy keys allow read-only access to your repository. Deploy keys can be used for CI, staging or production servers. You can create a deploy key or add an existing one.
.col-lg-9 .col-lg-9
%h5.prepend-top-0 %h5.prepend-top-0
Create a new deploy key for this project Create a new deploy key for this project
= render "form" = render @deploy_keys.form_partial_path
.col-lg-9.col-lg-offset-3 .col-lg-9.col-lg-offset-3
%hr %hr
.col-lg-9.col-lg-offset-3.append-bottom-default.deploy-keys .col-lg-9.col-lg-offset-3.append-bottom-default.deploy-keys
%h5.prepend-top-0 %h5.prepend-top-0
Enabled deploy keys for this project (#{@enabled_keys.size}) Enabled deploy keys for this project (#{@deploy_keys.enabled_keys_size})
- if @enabled_keys.any? - if @deploy_keys.any_keys_enabled?
%ul.well-list %ul.well-list
= render @enabled_keys - @deploy_keys.enabled_keys.each do |enabled_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 or add existing one below. No deploy keys found. Create one with the form above or add existing one below.
%h5.prepend-top-default %h5.prepend-top-default
Deploy keys from projects you have access to (#{@available_project_keys.size}) Deploy keys from projects you have access to (#{@deploy_keys.available_project_keys_size})
- if @available_project_keys.any? - if @deploy_keys.any_available_project_keys_enabled?
%ul.well-list %ul.well-list
= render @available_project_keys - @deploy_keys.available_project_keys.each do |available_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.
- if @available_public_keys.any? - if @deploy_keys.any_available_public_keys_enabled?
%h5.prepend-top-default %h5.prepend-top-default
Public deploy keys available to any project (#{@available_public_keys.size}) Public deploy keys available to any project (#{@deploy_keys.available_public_keys_size})
%ul.well-list %ul.well-list
= render @available_public_keys - @deploy_keys.available_public_keys.each do |available_key|
= render partial: 'projects/deploy_keys/deploy_key', locals: {deploy_key: available_key}
...@@ -25,6 +25,6 @@ ...@@ -25,6 +25,6 @@
- if can_admin_project - if can_admin_project
%th %th
%tbody %tbody
= render partial: @protected_branches, locals: { can_admin_project: can_admin_project } = render partial: 'projects/protected_branches/protected_branch', collection: @protected_branches, locals: { can_admin_project: can_admin_project}
= paginate @protected_branches, theme: 'gitlab' = paginate @protected_branches, theme: 'gitlab'
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
= f.label :name, class: 'col-md-2 text-right' do = f.label :name, class: 'col-md-2 text-right' do
Branch: Branch:
.col-md-10 .col-md-10
= render partial: "dropdown", locals: { f: f } = render partial: "projects/protected_branches/dropdown", locals: { f: f }
.help-block .help-block
= link_to 'Wildcards', help_page_path('user/project/protected_branches', anchor: 'wildcard-protected-branches') = link_to 'Wildcards', help_page_path('user/project/protected_branches', anchor: 'wildcard-protected-branches')
such as such as
......
...@@ -17,6 +17,6 @@ ...@@ -17,6 +17,6 @@
%p.append-bottom-0 Read more about #{link_to "protected branches", help_page_path("user/project/protected_branches"), class: "underlined-link"} and #{link_to "project permissions", help_page_path("user/permissions"), class: "underlined-link"}. %p.append-bottom-0 Read more about #{link_to "protected branches", help_page_path("user/project/protected_branches"), class: "underlined-link"} and #{link_to "project permissions", help_page_path("user/permissions"), class: "underlined-link"}.
.col-lg-9 .col-lg-9
- if can? current_user, :admin_project, @project - if can? current_user, :admin_project, @project
= render 'create_protected_branch' = render 'projects/protected_branches/create_protected_branch'
= render "branches_list" = render "projects/protected_branches/branches_list"
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
- else - else
(branch was removed from repository) (branch was removed from repository)
= render partial: 'protected_branch_access_summary', locals: { protected_branch: protected_branch } = render partial: 'projects/protected_branches/protected_branch_access_summary', locals: { protected_branch: protected_branch }
- if can_admin_project - if can_admin_project
%td %td
......
- page_title "Repository"
= render @deploy_keys
= render "projects/protected_branches/index"
...@@ -370,6 +370,7 @@ constraints(ProjectUrlConstrainer.new) do ...@@ -370,6 +370,7 @@ constraints(ProjectUrlConstrainer.new) do
resource :members, only: [:show] resource :members, only: [:show]
resource :ci_cd, only: [:show], controller: 'ci_cd' resource :ci_cd, only: [:show], controller: 'ci_cd'
resource :integrations, only: [:show] resource :integrations, only: [:show]
resource :repository, only: [:show], controller: :repository
end end
# Since both wiki and repository routing contains wildcard characters # Since both wiki and repository routing contains wildcard characters
......
...@@ -46,10 +46,10 @@ Feature: Project Active Tab ...@@ -46,10 +46,10 @@ Feature: Project Active Tab
And no other sub navs should be active And no other sub navs should be active
And the active main tab should be Settings And the active main tab should be Settings
Scenario: On Project Settings/Deploy Keys Scenario: On Project Settings/Repository
Given I visit my project's settings page Given I visit my project's settings page
And I click the "Deploy Keys" tab And I click the "Repository" tab
Then the active sub nav should be Deploy Keys Then the active sub nav should be Repository
And no other sub navs should be active And no other sub navs should be active
And the active main tab should be Settings And the active main tab should be Settings
......
...@@ -31,8 +31,10 @@ class Spinach::Features::ProjectActiveTab < Spinach::FeatureSteps ...@@ -31,8 +31,10 @@ class Spinach::Features::ProjectActiveTab < Spinach::FeatureSteps
click_link('Integrations') click_link('Integrations')
end end
step 'I click the "Deploy Keys" tab' do step 'I click the "Repository" tab' do
click_link('Deploy Keys') page.within '.layout-nav .controls' do
click_link('Repository')
end
end end
step 'I click the "Pages" tab' do step 'I click the "Pages" tab' do
...@@ -47,8 +49,8 @@ class Spinach::Features::ProjectActiveTab < Spinach::FeatureSteps ...@@ -47,8 +49,8 @@ class Spinach::Features::ProjectActiveTab < Spinach::FeatureSteps
ensure_active_sub_nav('Integrations') ensure_active_sub_nav('Integrations')
end end
step 'the active sub nav should be Deploy Keys' do step 'the active sub nav should be Repository' do
ensure_active_sub_nav('Deploy Keys') ensure_active_sub_nav('Repository')
end end
step 'the active sub nav should be Pages' do step 'the active sub nav should be Pages' do
......
...@@ -36,7 +36,7 @@ class Spinach::Features::ProjectDeployKeys < Spinach::FeatureSteps ...@@ -36,7 +36,7 @@ class Spinach::Features::ProjectDeployKeys < Spinach::FeatureSteps
end end
step 'I should be on deploy keys page' do step 'I should be on deploy keys page' do
expect(current_path).to eq namespace_project_deploy_keys_path(@project.namespace, @project) expect(current_path).to eq namespace_project_settings_repository_path(@project.namespace, @project)
end end
step 'I should see newly created deploy key' do step 'I should see newly created deploy key' do
......
...@@ -116,6 +116,20 @@ describe "Private Project Access", feature: true do ...@@ -116,6 +116,20 @@ describe "Private Project Access", feature: true do
it { is_expected.to be_denied_for(:external) } it { is_expected.to be_denied_for(:external) }
end end
describe "GET /:project_path/settings/repository" do
subject { namespace_project_settings_repository_path(project.namespace, project) }
it { is_expected.to be_allowed_for(:admin) }
it { is_expected.to be_allowed_for(:owner).of(project) }
it { is_expected.to be_allowed_for(:master).of(project) }
it { is_expected.to be_denied_for(:developer).of(project) }
it { is_expected.to be_denied_for(:reporter).of(project) }
it { is_expected.to be_denied_for(:guest).of(project) }
it { is_expected.to be_denied_for(:user) }
it { is_expected.to be_denied_for(:external) }
it { is_expected.to be_denied_for(:visitor) }
end
describe "GET /:project_path/blob" do describe "GET /:project_path/blob" do
let(:commit) { project.repository.commit } let(:commit) { project.repository.commit }
subject { namespace_project_blob_path(project.namespace, project, File.join(commit.id, '.gitignore'))} subject { namespace_project_blob_path(project.namespace, project, File.join(commit.id, '.gitignore'))}
......
require 'spec_helper'
describe Projects::Settings::DeployKeysPresenter do
let(:project) { create(:empty_project) }
let(:user) { create(:user) }
subject(:presenter) do
described_class.new(project, current_user: user)
end
it 'inherits from Gitlab::View::Presenter::Simple' do
expect(described_class.superclass).to eq(Gitlab::View::Presenter::Simple)
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]
end
it 'does not contain enabled_keys inside available_keys' do
expect(presenter.available_keys).not_to include deploy_key
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