Commit 8039b9c3 authored by Douwe Maan's avatar Douwe Maan

Merge branch '30410-revert-9347-and-10079' into 'master'

Resolve "Allow to disable username on checkout url"

Closes #30410 and #30174

See merge request !11792
parents c5e26e57 08134ad2
...@@ -56,7 +56,7 @@ module ButtonHelper ...@@ -56,7 +56,7 @@ module ButtonHelper
content_tag (append_link ? :a : :span), protocol, content_tag (append_link ? :a : :span), protocol,
class: klass, class: klass,
href: (project.http_url_to_repo(current_user) if append_link), href: (project.http_url_to_repo if append_link),
data: { data: {
html: true, html: true,
placement: placement, placement: placement,
......
...@@ -276,7 +276,7 @@ module ProjectsHelper ...@@ -276,7 +276,7 @@ module ProjectsHelper
when 'ssh' when 'ssh'
project.ssh_url_to_repo project.ssh_url_to_repo
else else
project.http_url_to_repo(current_user) project.http_url_to_repo
end end
end end
......
...@@ -874,10 +874,8 @@ class Project < ActiveRecord::Base ...@@ -874,10 +874,8 @@ class Project < ActiveRecord::Base
url_to_repo url_to_repo
end end
def http_url_to_repo(user = nil) def http_url_to_repo
credentials = Gitlab::UrlSanitizer.http_credentials_for_user(user) "#{web_url}.git"
Gitlab::UrlSanitizer.new("#{web_url}.git", credentials: credentials).full_url
end end
def user_can_push_to_empty_repo?(user) def user_can_push_to_empty_repo?(user)
......
...@@ -42,11 +42,8 @@ class ProjectWiki ...@@ -42,11 +42,8 @@ class ProjectWiki
url_to_repo url_to_repo
end end
def http_url_to_repo(user = nil) def http_url_to_repo
url = "#{Gitlab.config.gitlab.url}/#{path_with_namespace}.git" "#{Gitlab.config.gitlab.url}/#{path_with_namespace}.git"
credentials = Gitlab::UrlSanitizer.http_credentials_for_user(user)
Gitlab::UrlSanitizer.new(url, credentials: credentials).full_url
end end
def wiki_base_path def wiki_base_path
......
---
title: Revert the feature that would include the current user's username in the HTTP
clone URL
merge_request: 11792
author:
...@@ -49,7 +49,7 @@ class Spinach::Features::ExploreProjects < Spinach::FeatureSteps ...@@ -49,7 +49,7 @@ class Spinach::Features::ExploreProjects < Spinach::FeatureSteps
step 'I should see an http link to the repository' do step 'I should see an http link to the repository' do
project = Project.find_by(name: 'Community') project = Project.find_by(name: 'Community')
expect(page).to have_field('project_clone', with: project.http_url_to_repo(@user)) expect(page).to have_field('project_clone', with: project.http_url_to_repo)
end end
step 'I should see an ssh link to the repository' do step 'I should see an ssh link to the repository' do
......
...@@ -18,12 +18,6 @@ module Gitlab ...@@ -18,12 +18,6 @@ module Gitlab
false false
end end
def self.http_credentials_for_user(user)
return {} unless user.respond_to?(:username)
{ user: user.username }
end
def initialize(url, credentials: nil) def initialize(url, credentials: nil)
@url = Addressable::URI.parse(url.strip) @url = Addressable::URI.parse(url.strip)
@credentials = credentials @credentials = credentials
......
...@@ -32,7 +32,7 @@ feature 'Admin disables Git access protocol', feature: true do ...@@ -32,7 +32,7 @@ feature 'Admin disables Git access protocol', feature: true do
scenario 'shows only HTTP url' do scenario 'shows only HTTP url' do
visit_project visit_project
expect(page).to have_content("git clone #{project.http_url_to_repo(admin)}") expect(page).to have_content("git clone #{project.http_url_to_repo}")
expect(page).not_to have_selector('#clone-dropdown') expect(page).not_to have_selector('#clone-dropdown')
end end
end end
......
...@@ -56,14 +56,8 @@ feature 'Developer views empty project instructions', feature: true do ...@@ -56,14 +56,8 @@ feature 'Developer views empty project instructions', feature: true do
end end
def expect_instructions_for(protocol) def expect_instructions_for(protocol)
url = msg = :"#{protocol.downcase}_url_to_repo"
case protocol
when 'ssh' expect(page).to have_content("git clone #{project.send(msg)}")
project.ssh_url_to_repo
when 'http'
project.http_url_to_repo(developer)
end
expect(page).to have_content("git clone #{url}")
end end
end end
...@@ -21,6 +21,6 @@ describe 'Projects > Wiki > User views Git access wiki page', :feature do ...@@ -21,6 +21,6 @@ describe 'Projects > Wiki > User views Git access wiki page', :feature do
click_link 'Clone repository' click_link 'Clone repository'
expect(page).to have_text("Clone repository #{project.wiki.path_with_namespace}") expect(page).to have_text("Clone repository #{project.wiki.path_with_namespace}")
expect(page).to have_text(project.wiki.http_url_to_repo(user)) expect(page).to have_text(project.wiki.http_url_to_repo)
end end
end end
...@@ -62,11 +62,6 @@ describe Gitlab::UrlSanitizer, lib: true do ...@@ -62,11 +62,6 @@ describe Gitlab::UrlSanitizer, lib: true do
end end
end end
describe '.http_credentials_for_user' do
it { expect(described_class.http_credentials_for_user(user)).to eq({ user: 'john.doe' }) }
it { expect(described_class.http_credentials_for_user('foo')).to eq({}) }
end
describe '#sanitized_url' do describe '#sanitized_url' do
it { expect(url_sanitizer.sanitized_url).to eq("https://github.com/me/project.git") } it { expect(url_sanitizer.sanitized_url).to eq("https://github.com/me/project.git") }
end end
...@@ -76,7 +71,7 @@ describe Gitlab::UrlSanitizer, lib: true do ...@@ -76,7 +71,7 @@ describe Gitlab::UrlSanitizer, lib: true do
context 'when user is given to #initialize' do context 'when user is given to #initialize' do
let(:url_sanitizer) do let(:url_sanitizer) do
described_class.new("https://github.com/me/project.git", credentials: described_class.http_credentials_for_user(user)) described_class.new("https://github.com/me/project.git", credentials: { user: user.username })
end end
it { expect(url_sanitizer.credentials).to eq({ user: 'john.doe' }) } it { expect(url_sanitizer.credentials).to eq({ user: 'john.doe' }) }
...@@ -94,7 +89,7 @@ describe Gitlab::UrlSanitizer, lib: true do ...@@ -94,7 +89,7 @@ describe Gitlab::UrlSanitizer, lib: true do
context 'when user is given to #initialize' do context 'when user is given to #initialize' do
let(:url_sanitizer) do let(:url_sanitizer) do
described_class.new("https://github.com/me/project.git", credentials: described_class.http_credentials_for_user(user)) described_class.new("https://github.com/me/project.git", credentials: { user: user.username })
end end
it { expect(url_sanitizer.full_url).to eq("https://john.doe@github.com/me/project.git") } it { expect(url_sanitizer.full_url).to eq("https://john.doe@github.com/me/project.git") }
......
...@@ -1909,19 +1909,9 @@ describe Project, models: true do ...@@ -1909,19 +1909,9 @@ describe Project, models: true do
describe '#http_url_to_repo' do describe '#http_url_to_repo' do
let(:project) { create :empty_project } let(:project) { create :empty_project }
context 'when no user is given' do it 'returns the url to the repo without a username' do
it 'returns the url to the repo without a username' do expect(project.http_url_to_repo).to eq("#{project.web_url}.git")
expect(project.http_url_to_repo).to eq("#{project.web_url}.git") expect(project.http_url_to_repo).not_to include('@')
expect(project.http_url_to_repo).not_to include('@')
end
end
context 'when user is given' do
it 'returns the url to the repo with the username' do
user = build_stubbed(:user)
expect(project.http_url_to_repo(user)).to start_with("http://#{user.username}@")
end
end end
end end
......
...@@ -37,21 +37,11 @@ describe ProjectWiki, models: true do ...@@ -37,21 +37,11 @@ describe ProjectWiki, models: true do
describe "#http_url_to_repo" do describe "#http_url_to_repo" do
let(:project) { create :empty_project } let(:project) { create :empty_project }
context 'when no user is given' do it 'returns the full http url to the repo' do
it 'returns the url to the repo without a username' do expected_url = "#{Gitlab.config.gitlab.url}/#{subject.path_with_namespace}.git"
expected_url = "#{Gitlab.config.gitlab.url}/#{subject.path_with_namespace}.git"
expect(project_wiki.http_url_to_repo).to eq(expected_url) expect(project_wiki.http_url_to_repo).to eq(expected_url)
expect(project_wiki.http_url_to_repo).not_to include('@') expect(project_wiki.http_url_to_repo).not_to include('@')
end
end
context 'when user is given' do
it 'returns the url to the repo with the username' do
user = build_stubbed(:user)
expect(project_wiki.http_url_to_repo(user)).to start_with("http://#{user.username}@")
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