Commit f044679c authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'sh-fix-http-clone-panel' into 'master'

Fix missing Git clone button when protocol restriction setting enabled

Closes #55676

See merge request gitlab-org/gitlab-ce!24015
parents 4ae9d26e 29adade5
...@@ -26,6 +26,18 @@ module ApplicationSettingsHelper ...@@ -26,6 +26,18 @@ module ApplicationSettingsHelper
end end
end end
def all_protocols_enabled?
Gitlab::CurrentSettings.enabled_git_access_protocol.blank?
end
def ssh_enabled?
all_protocols_enabled? || enabled_protocol == 'ssh'
end
def http_enabled?
all_protocols_enabled? || enabled_protocol == 'http'
end
def enabled_project_button(project, protocol) def enabled_project_button(project, protocol)
case protocol case protocol
when 'ssh' when 'ssh'
......
- project = project || @project - project = project || @project
.git-clone-holder.js-git-clone-holder.input-group .git-clone-holder.js-git-clone-holder.input-group
- if allowed_protocols_present? %a#clone-dropdown.input-group-text.btn.btn-primary.btn-xs.clone-dropdown-btn.qa-clone-dropdown{ href: '#', data: { toggle: 'dropdown' } }
.input-group-text.clone-dropdown-btn.btn %span.append-right-4.js-clone-dropdown-label
%span.js-clone-dropdown-label = _('Clone')
= enabled_project_button(project, enabled_protocol) = sprite_icon("arrow-down", css_class: "icon")
- else
%a#clone-dropdown.input-group-text.btn.btn-primary.btn-xs.clone-dropdown-btn.qa-clone-dropdown{ href: '#', data: { toggle: 'dropdown' } }
%span.append-right-4.js-clone-dropdown-label
= _('Clone')
= sprite_icon("arrow-down", css_class: "icon")
%form.p-3.dropdown-menu.dropdown-menu-right.dropdown-menu-large.dropdown-menu-selectable.clone-options-dropdown.qa-clone-options %form.p-3.dropdown-menu.dropdown-menu-right.dropdown-menu-large.dropdown-menu-selectable.clone-options-dropdown.qa-clone-options
%li.pb-2 - if ssh_enabled?
%label.label-bold %li.pb-2
= _('Clone with SSH') %label.label-bold
.input-group = _('Clone with SSH')
= text_field_tag :ssh_project_clone, project.ssh_url_to_repo, class: "js-select-on-focus form-control qa-ssh-clone-url", readonly: true, aria: { label: 'Project clone URL' } .input-group
.input-group-append = text_field_tag :ssh_project_clone, project.ssh_url_to_repo, class: "js-select-on-focus form-control qa-ssh-clone-url", readonly: true, aria: { label: 'Project clone URL' }
= clipboard_button(target: '#ssh_project_clone', title: _("Copy URL to clipboard"), class: "input-group-text btn-default btn-clipboard") .input-group-append
= render_if_exists 'projects/buttons/geo' = clipboard_button(target: '#ssh_project_clone', title: _("Copy URL to clipboard"), class: "input-group-text btn-default btn-clipboard")
%li = render_if_exists 'projects/buttons/geo'
%li
- if http_enabled?
%label.label-bold %label.label-bold
= _('Clone with %{http_label}') % { http_label: gitlab_config.protocol.upcase } = _('Clone with %{http_label}') % { http_label: gitlab_config.protocol.upcase }
.input-group .input-group
......
...@@ -7,7 +7,9 @@ ...@@ -7,7 +7,9 @@
%button.btn.btn-primary.dropdown-toggle.js-dropdown-toggle{ type: "button", data: { toggle: "dropdown" } } %button.btn.btn-primary.dropdown-toggle.js-dropdown-toggle{ type: "button", data: { toggle: "dropdown" } }
= sprite_icon("arrow-down", css_class: "dropdown-btn-icon icon") = sprite_icon("arrow-down", css_class: "dropdown-btn-icon icon")
%ul.dropdown-menu.dropdown-menu-selectable.dropdown-menu-right.clone-options-dropdown{ data: { dropdown: true } } %ul.dropdown-menu.dropdown-menu-selectable.dropdown-menu-right.clone-options-dropdown{ data: { dropdown: true } }
%li - if ssh_enabled?
= dropdown_item_with_description(ssh_copy_label, project.ssh_url_to_repo, href: project.ssh_url_to_repo, data: { clone_type: 'ssh' }, default: true) %li
%li = dropdown_item_with_description(ssh_copy_label, project.ssh_url_to_repo, href: project.ssh_url_to_repo, data: { clone_type: 'ssh' }, default: true)
= dropdown_item_with_description(http_copy_label, project.http_url_to_repo, href: project.http_url_to_repo, data: { clone_type: 'http' }) - if http_enabled?
%li
= dropdown_item_with_description(http_copy_label, project.http_url_to_repo, href: project.http_url_to_repo, data: { clone_type: 'http' })
---
title: Fix missing Git clone button when protocol restriction setting enabled
merge_request: 24015
author:
type: fixed
require 'rails_helper' require 'rails_helper'
describe 'Admin disables Git access protocol' do describe 'Admin disables Git access protocol', :js do
include StubENV include StubENV
include MobileHelpers
let(:project) { create(:project, :empty_repo) } let(:project) { create(:project, :empty_repo) }
let(:admin) { create(:admin) } let(:admin) { create(:admin) }
...@@ -20,7 +21,24 @@ describe 'Admin disables Git access protocol' do ...@@ -20,7 +21,24 @@ describe 'Admin disables Git access protocol' do
visit_project visit_project
expect(page).to have_content("git clone #{project.ssh_url_to_repo}") expect(page).to have_content("git clone #{project.ssh_url_to_repo}")
expect(page).not_to have_selector('#clone-dropdown')
find('.clone-dropdown-btn').click
within('.git-clone-holder') do
expect(page).to have_content('Clone with SSH')
expect(page).not_to have_content('Clone with HTTP')
end
end
context 'mobile component' do
it 'shows only the SSH clone information' do
resize_screen_xs
visit_project
find('.dropdown-toggle').click
expect(page).to have_content('Copy SSH clone URL')
expect(page).not_to have_content('Copy HTTP clone URL')
end
end end
end end
...@@ -31,9 +49,25 @@ describe 'Admin disables Git access protocol' do ...@@ -31,9 +49,25 @@ describe 'Admin disables Git access protocol' do
it 'shows only HTTP url' do it 'shows only HTTP url' do
visit_project visit_project
find('.clone-dropdown-btn').click
expect(page).to have_content("git clone #{project.http_url_to_repo}") expect(page).to have_content("git clone #{project.http_url_to_repo}")
expect(page).not_to have_selector('#clone-dropdown')
within('.git-clone-holder') do
expect(page).to have_content('Clone with HTTP')
expect(page).not_to have_content('Clone with SSH')
end
end
context 'mobile component' do
it 'shows only the HTTP clone information' do
resize_screen_xs
visit_project
find('.dropdown-toggle').click
expect(page).to have_content('Copy HTTP clone URL')
expect(page).not_to have_content('Copy SSH clone URL')
end
end end
end end
...@@ -46,7 +80,24 @@ describe 'Admin disables Git access protocol' do ...@@ -46,7 +80,24 @@ describe 'Admin disables Git access protocol' do
visit_project visit_project
expect(page).to have_content("git clone #{project.ssh_url_to_repo}") expect(page).to have_content("git clone #{project.ssh_url_to_repo}")
expect(page).to have_selector('#clone-dropdown')
find('.clone-dropdown-btn').click
within('.git-clone-holder') do
expect(page).to have_content('Clone with SSH')
expect(page).to have_content('Clone with HTTP')
end
end
context 'mobile component' do
it 'shows both SSH and HTTP clone information' do
resize_screen_xs
visit_project
find('.dropdown-toggle').click
expect(page).to have_content('Copy HTTP clone URL')
expect(page).to have_content('Copy SSH clone URL')
end
end 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