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
content_tag (append_link ? :a : :span), protocol,
class: klass,
href: (project.http_url_to_repo(current_user) if append_link),
href: (project.http_url_to_repo if append_link),
data: {
html: true,
placement: placement,
......
......@@ -276,7 +276,7 @@ module ProjectsHelper
when 'ssh'
project.ssh_url_to_repo
else
project.http_url_to_repo(current_user)
project.http_url_to_repo
end
end
......
......@@ -874,10 +874,8 @@ class Project < ActiveRecord::Base
url_to_repo
end
def http_url_to_repo(user = nil)
credentials = Gitlab::UrlSanitizer.http_credentials_for_user(user)
Gitlab::UrlSanitizer.new("#{web_url}.git", credentials: credentials).full_url
def http_url_to_repo
"#{web_url}.git"
end
def user_can_push_to_empty_repo?(user)
......
......@@ -42,11 +42,8 @@ class ProjectWiki
url_to_repo
end
def http_url_to_repo(user = nil)
url = "#{Gitlab.config.gitlab.url}/#{path_with_namespace}.git"
credentials = Gitlab::UrlSanitizer.http_credentials_for_user(user)
Gitlab::UrlSanitizer.new(url, credentials: credentials).full_url
def http_url_to_repo
"#{Gitlab.config.gitlab.url}/#{path_with_namespace}.git"
end
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
step 'I should see an http link to the repository' do
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
step 'I should see an ssh link to the repository' do
......
......@@ -18,12 +18,6 @@ module Gitlab
false
end
def self.http_credentials_for_user(user)
return {} unless user.respond_to?(:username)
{ user: user.username }
end
def initialize(url, credentials: nil)
@url = Addressable::URI.parse(url.strip)
@credentials = credentials
......
......@@ -32,7 +32,7 @@ feature 'Admin disables Git access protocol', feature: true do
scenario 'shows only HTTP url' do
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')
end
end
......
......@@ -56,14 +56,8 @@ feature 'Developer views empty project instructions', feature: true do
end
def expect_instructions_for(protocol)
url =
case protocol
when 'ssh'
project.ssh_url_to_repo
when 'http'
project.http_url_to_repo(developer)
end
msg = :"#{protocol.downcase}_url_to_repo"
expect(page).to have_content("git clone #{url}")
expect(page).to have_content("git clone #{project.send(msg)}")
end
end
......@@ -21,6 +21,6 @@ describe 'Projects > Wiki > User views Git access wiki page', :feature do
click_link 'Clone repository'
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
......@@ -62,11 +62,6 @@ describe Gitlab::UrlSanitizer, lib: true do
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
it { expect(url_sanitizer.sanitized_url).to eq("https://github.com/me/project.git") }
end
......@@ -76,7 +71,7 @@ describe Gitlab::UrlSanitizer, lib: true do
context 'when user is given to #initialize' 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
it { expect(url_sanitizer.credentials).to eq({ user: 'john.doe' }) }
......@@ -94,7 +89,7 @@ describe Gitlab::UrlSanitizer, lib: true do
context 'when user is given to #initialize' 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
it { expect(url_sanitizer.full_url).to eq("https://john.doe@github.com/me/project.git") }
......
......@@ -1909,22 +1909,12 @@ describe Project, models: true do
describe '#http_url_to_repo' do
let(:project) { create :empty_project }
context 'when no user is given' 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).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
describe '#pipeline_status' do
let(:project) { create(:project) }
it 'builds a pipeline status' do
......
......@@ -37,8 +37,7 @@ describe ProjectWiki, models: true do
describe "#http_url_to_repo" do
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 full http url to the repo' do
expected_url = "#{Gitlab.config.gitlab.url}/#{subject.path_with_namespace}.git"
expect(project_wiki.http_url_to_repo).to eq(expected_url)
......@@ -46,15 +45,6 @@ describe ProjectWiki, models: true do
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
describe "#wiki_base_path" do
it "returns the wiki base path" do
wiki_base_path = "#{Gitlab.config.gitlab.relative_url_root}/#{project.path_with_namespace}/wikis"
......
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