Commit faaca5e1 authored by Sean McGivern's avatar Sean McGivern 🎄

Merge branch 'dm-more-namespace-full-path' into 'master'

Use Namespace#full_path instead of #path where appropriate

See merge request !9495
parents 3589cc06 dfbccdfc
Pipeline #6672921 passed with stages
in 91 minutes and 7 seconds
......@@ -39,7 +39,7 @@
$value = $block.find('.value');
$loading = $block.find('.block-loading').fadeOut();
if (issueUpdateURL) {
milestoneLinkTemplate = _.template('<a href="/<%- namespace %>/<%- path %>/milestones/<%- iid %>" class="bold has-tooltip" data-container="body" title="<%- remaining %>"><%- title %></a>');
milestoneLinkTemplate = _.template('<a href="/<%- full_path %>/milestones/<%- iid %>" class="bold has-tooltip" data-container="body" title="<%- remaining %>"><%- title %></a>');
milestoneLinkNoneTemplate = '<span class="no-value">None</span>';
collapsedSidebarLabelTemplate = _.template('<span class="has-tooltip" data-container="body" title="<%- remaining %>" data-placement="left"> <%- title %> </span>');
}
......@@ -181,8 +181,7 @@
$selectbox.hide();
$value.css('display', '');
if (data.milestone != null) {
data.milestone.namespace = _this.currentProject.namespace;
data.milestone.path = _this.currentProject.path;
data.milestone.full_path = _this.currentProject.full_path;
data.milestone.remaining = gl.utils.timeFor(data.milestone.due_date);
$value.html(milestoneLinkTemplate(data.milestone));
return $sidebarCollapsedValue.find('span').html(collapsedSidebarLabelTemplate(data.milestone));
......
......@@ -52,7 +52,7 @@ module IssuablesHelper
field_name: 'issuable_template',
selected: selected_template(issuable),
project_path: ref_project.path,
namespace_path: ref_project.namespace.path
namespace_path: ref_project.namespace.full_path
}
}
......
......@@ -359,7 +359,7 @@ class Project < ActiveRecord::Base
end
def reference_pattern
name_pattern = Gitlab::Regex::NAMESPACE_REGEX_STR
name_pattern = Gitlab::Regex::FULL_NAMESPACE_REGEX_STR
%r{
((?<namespace>#{name_pattern})\/)?
......@@ -847,10 +847,6 @@ class Project < ActiveRecord::Base
gitlab_shell.url_to_repo(path_with_namespace)
end
def namespace_dir
namespace.try(:path) || ''
end
def repo_exists?
@repo_exists ||= repository.exists?
rescue
......@@ -899,8 +895,8 @@ class Project < ActiveRecord::Base
def rename_repo
path_was = previous_changes['path'].first
old_path_with_namespace = File.join(namespace_dir, path_was)
new_path_with_namespace = File.join(namespace_dir, path)
old_path_with_namespace = File.join(namespace.full_path, path_was)
new_path_with_namespace = File.join(namespace.full_path, path)
Rails.logger.error "Attempting to rename #{old_path_with_namespace} -> #{new_path_with_namespace}"
......
......@@ -334,7 +334,7 @@ class User < ActiveRecord::Base
def reference_pattern
%r{
#{Regexp.escape(reference_prefix)}
(?<user>#{Gitlab::Regex::NAMESPACE_REF_REGEX_STR})
(?<user>#{Gitlab::Regex::FULL_NAMESPACE_REGEX_STR})
}x
end
end
......
......@@ -8,7 +8,7 @@
= f.text_field :name, class: "form-control top", required: true, title: "This field is required."
.username.form-group
= f.label :username
= f.text_field :username, class: "form-control middle", pattern: Gitlab::Regex::NAMESPACE_REGEX_STR_SIMPLE, required: true, title: 'Please create a username with only alphanumeric characters.'
= f.text_field :username, class: "form-control middle", pattern: Gitlab::Regex::NAMESPACE_REGEX_STR_JS, required: true, title: 'Please create a username with only alphanumeric characters.'
%p.validation-error.hide Username is already taken.
%p.validation-success.hide Username is available.
%p.validation-pending.hide Checking username availability...
......
......@@ -120,7 +120,7 @@
.form-group
- if @project.avatar?
.avatar-container.s160
= project_icon("#{@project.namespace.to_param}/#{@project.to_param}", alt: '', class: 'avatar project-avatar s160')
= project_icon(@project.full_path, alt: '', class: 'avatar project-avatar s160')
%p.light
- if @project.avatar_in_git
Project avatar in repository: #{ @project.avatar_in_git }
......
......@@ -17,7 +17,7 @@
%strong= parent.full_path + '/'
= f.text_field :path, placeholder: 'open-source', class: 'form-control',
autofocus: local_assigns[:autofocus] || false, required: true,
pattern: Gitlab::Regex::NAMESPACE_REGEX_STR_SIMPLE,
pattern: Gitlab::Regex::NAMESPACE_REGEX_STR_JS,
title: 'Please choose a group name with no special characters.'
- if parent
= f.hidden_field :parent_id, value: parent.id
......
......@@ -173,7 +173,7 @@
:javascript
gl.IssuableResource = new gl.SubbableResource('#{issuable_json_path(issuable)}');
new gl.IssuableTimeTracking("#{escape_javascript(serialize_issuable(issuable))}");
new MilestoneSelect('{"namespace":"#{@project.namespace.path}","path":"#{@project.path}"}');
new MilestoneSelect('{"full_path":"#{@project.full_path}"}');
new LabelsSelect();
new IssuableContext('#{escape_javascript(current_user.to_json(only: [:username, :id, :name]))}');
gl.Subscription.bindAll('.subscription');
......
......@@ -35,7 +35,7 @@ module Gitlab
end
def export_filename(project:)
basename = "#{Time.now.strftime('%Y-%m-%d_%H-%M-%3N')}_#{project.namespace.full_path}_#{project.path}"
basename = "#{Time.now.strftime('%Y-%m-%d_%H-%M-%3N')}_#{project.full_path.tr('/', '_')}"
"#{basename[0..FILENAME_LIMIT]}_export.tar.gz"
end
......
......@@ -5,17 +5,18 @@ module Gitlab
# The namespace regex is used in Javascript to validate usernames in the "Register" form. However, Javascript
# does not support the negative lookbehind assertion (?<!) that disallows usernames ending in `.git` and `.atom`.
# Since this is a non-trivial problem to solve in Javascript (heavily complicate the regex, modify view code to
# allow non-regex validatiions, etc), `NAMESPACE_REGEX_STR_SIMPLE` serves as a Javascript-compatible version of
# allow non-regex validatiions, etc), `NAMESPACE_REGEX_STR_JS` serves as a Javascript-compatible version of
# `NAMESPACE_REGEX_STR`, with the negative lookbehind assertion removed. This means that the client-side validation
# will pass for usernames ending in `.atom` and `.git`, but will be caught by the server-side validation.
PATH_REGEX_STR = '[a-zA-Z0-9_\.][a-zA-Z0-9_\-\.]*'.freeze
NAMESPACE_REGEX_STR_SIMPLE = PATH_REGEX_STR + '[a-zA-Z0-9_\-]|[a-zA-Z0-9_]'.freeze
NAMESPACE_REGEX_STR = '(?:' + NAMESPACE_REGEX_STR_SIMPLE + ')(?<!\.git|\.atom)'.freeze
PROJECT_REGEX_STR = PATH_REGEX_STR + '(?<!\.git|\.atom)'.freeze
NAMESPACE_REGEX_STR_JS = PATH_REGEX_STR + '[a-zA-Z0-9_\-]|[a-zA-Z0-9_]'.freeze
NO_SUFFIX_REGEX_STR = '(?<!\.git|\.atom)'.freeze
NAMESPACE_REGEX_STR = "(?:#{NAMESPACE_REGEX_STR_JS})#{NO_SUFFIX_REGEX_STR}".freeze
PROJECT_REGEX_STR = "(?:#{PATH_REGEX_STR})#{NO_SUFFIX_REGEX_STR}".freeze
# Same as NAMESPACE_REGEX_STR but allows `/` in the path.
# So `group/subgroup` will match this regex but not NAMESPACE_REGEX_STR
NAMESPACE_REF_REGEX_STR = '(?:[a-zA-Z0-9_\.][a-zA-Z0-9_\-\.\/]*[a-zA-Z0-9_\-]|[a-zA-Z0-9_])(?<!\.git|\.atom)'.freeze
FULL_NAMESPACE_REGEX_STR = "(?:#{NAMESPACE_REGEX_STR}/)*#{NAMESPACE_REGEX_STR}".freeze
def namespace_regex
@namespace_regex ||= /\A#{NAMESPACE_REGEX_STR}\z/.freeze
......
......@@ -19,8 +19,8 @@ describe Projects::BlobController do
before do
get(:show,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
namespace_id: project.namespace,
project_id: project,
id: id)
end
......@@ -50,8 +50,8 @@ describe Projects::BlobController do
before do
get(:show,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
namespace_id: project.namespace,
project_id: project,
id: id)
controller.instance_variable_set(:@blob, nil)
end
......
......@@ -16,8 +16,8 @@ describe Projects::BlameController do
before do
get(:show,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
namespace_id: project.namespace,
project_id: project,
id: id)
end
......
......@@ -14,8 +14,8 @@ describe Projects::BlobController do
render_views
def do_get(opts = {})
params = { namespace_id: project.namespace.to_param,
project_id: project.to_param,
params = { namespace_id: project.namespace,
project_id: project,
id: 'master/CHANGELOG' }
get :diff, params.merge(opts)
end
......@@ -40,8 +40,8 @@ describe Projects::BlobController do
describe 'PUT update' do
let(:default_params) do
{
namespace_id: project.namespace.to_param,
project_id: project.to_param,
namespace_id: project.namespace,
project_id: project,
id: 'master/CHANGELOG',
target_branch: 'master',
content: 'Added changes',
......@@ -96,8 +96,8 @@ describe Projects::BlobController do
context 'when editing on the fork' do
before do
default_params[:namespace_id] = forked_project.namespace.to_param
default_params[:project_id] = forked_project.to_param
default_params[:namespace_id] = forked_project.namespace
default_params[:project_id] = forked_project
end
it 'redirects to blob' do
......
......@@ -90,7 +90,7 @@ describe Projects::Boards::IssuesController do
params = {
namespace_id: project.namespace.to_param,
project_id: project.to_param,
project_id: project,
board_id: board.to_param,
list_id: list.try(:to_param)
}
......@@ -146,7 +146,7 @@ describe Projects::Boards::IssuesController do
sign_in(user)
post :create, namespace_id: project.namespace.to_param,
project_id: project.to_param,
project_id: project,
board_id: board.to_param,
list_id: list.to_param,
issue: { title: title },
......@@ -209,7 +209,7 @@ describe Projects::Boards::IssuesController do
sign_in(user)
patch :update, namespace_id: project.namespace.to_param,
project_id: project.to_param,
project_id: project,
board_id: board.to_param,
id: issue.to_param,
from_list_id: from_list_id,
......
......@@ -47,7 +47,7 @@ describe Projects::Boards::ListsController do
sign_in(user)
get :index, namespace_id: project.namespace.to_param,
project_id: project.to_param,
project_id: project,
board_id: board.to_param,
format: :json
end
......@@ -104,7 +104,7 @@ describe Projects::Boards::ListsController do
sign_in(user)
post :create, namespace_id: project.namespace.to_param,
project_id: project.to_param,
project_id: project,
board_id: board.to_param,
list: { label_id: label_id },
format: :json
......@@ -157,7 +157,7 @@ describe Projects::Boards::ListsController do
sign_in(user)
patch :update, namespace_id: project.namespace.to_param,
project_id: project.to_param,
project_id: project,
board_id: board.to_param,
id: list.to_param,
list: { position: position },
......@@ -200,7 +200,7 @@ describe Projects::Boards::ListsController do
sign_in(user)
delete :destroy, namespace_id: project.namespace.to_param,
project_id: project.to_param,
project_id: project,
board_id: board.to_param,
id: list.to_param,
format: :json
......@@ -244,7 +244,7 @@ describe Projects::Boards::ListsController do
sign_in(user)
post :generate, namespace_id: project.namespace.to_param,
project_id: project.to_param,
project_id: project,
board_id: board.to_param,
format: :json
end
......
......@@ -50,8 +50,8 @@ describe Projects::BoardsController do
end
def list_boards(format: :html)
get :index, namespace_id: project.namespace.to_param,
project_id: project.to_param,
get :index, namespace_id: project.namespace,
project_id: project,
format: format
end
end
......@@ -100,8 +100,8 @@ describe Projects::BoardsController do
end
def read_board(board:, format: :html)
get :show, namespace_id: project.namespace.to_param,
project_id: project.to_param,
get :show, namespace_id: project.namespace,
project_id: project,
id: board.to_param,
format: format
end
......
......@@ -22,8 +22,8 @@ describe Projects::BranchesController do
sign_in(user)
post :create,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
namespace_id: project.namespace,
project_id: project,
branch_name: branch,
ref: ref
end
......@@ -76,8 +76,8 @@ describe Projects::BranchesController do
it 'redirects' do
post :create,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
namespace_id: project.namespace,
project_id: project,
branch_name: branch,
issue_iid: issue.iid
......@@ -89,8 +89,8 @@ describe Projects::BranchesController do
expect(SystemNoteService).to receive(:new_issue_branch).with(issue, project, user, "1-feature-branch")
post :create,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
namespace_id: project.namespace,
project_id: project,
branch_name: branch,
issue_iid: issue.iid
end
......@@ -143,8 +143,8 @@ describe Projects::BranchesController do
expect(SystemNoteService).not_to receive(:new_issue_branch)
post :create,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
namespace_id: project.namespace,
project_id: project,
branch_name: branch,
issue_iid: issue.iid
end
......@@ -163,8 +163,8 @@ describe Projects::BranchesController do
post :destroy,
format: :html,
id: 'foo/bar/baz',
namespace_id: project.namespace.to_param,
project_id: project.to_param
namespace_id: project.namespace,
project_id: project
expect(response).to have_http_status(303)
end
......@@ -179,8 +179,8 @@ describe Projects::BranchesController do
post :destroy,
format: :js,
id: branch,
namespace_id: project.namespace.to_param,
project_id: project.to_param
namespace_id: project.namespace,
project_id: project
end
context "valid branch name, valid source" do
......@@ -210,8 +210,8 @@ describe Projects::BranchesController do
describe "DELETE destroy_all_merged" do
def destroy_all_merged
delete :destroy_all_merged,
namespace_id: project.namespace.to_param,
project_id: project.to_param
namespace_id: project.namespace,
project_id: project
end
context 'when user is allowed to push' do
......
......@@ -17,8 +17,8 @@ describe Projects::CommitController do
def go(extra_params = {})
params = {
namespace_id: project.namespace.to_param,
project_id: project.to_param
namespace_id: project.namespace,
project_id: project
}
get :show, params.merge(extra_params)
......@@ -125,8 +125,8 @@ describe Projects::CommitController do
it 'renders it' do
get(:show,
namespace_id: fork_project.namespace.to_param,
project_id: fork_project.to_param,
namespace_id: fork_project.namespace,
project_id: fork_project,
id: commit.id)
expect(response).to be_success
......@@ -139,8 +139,8 @@ describe Projects::CommitController do
commit = project.commit('5937ac0a7beb003549fc5fd26fc247adbce4a52e')
get(:branches,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
namespace_id: project.namespace,
project_id: project,
id: commit.id)
expect(assigns(:branches)).to include("master", "feature_conflict")
......@@ -152,8 +152,8 @@ describe Projects::CommitController do
context 'when target branch is not provided' do
it 'renders the 404 page' do
post(:revert,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
namespace_id: project.namespace,
project_id: project,
id: commit.id)
expect(response).not_to be_success
......@@ -164,8 +164,8 @@ describe Projects::CommitController do
context 'when the revert was successful' do
it 'redirects to the commits page' do
post(:revert,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
namespace_id: project.namespace,
project_id: project,
target_branch: 'master',
id: commit.id)
......@@ -177,8 +177,8 @@ describe Projects::CommitController do
context 'when the revert failed' do
before do
post(:revert,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
namespace_id: project.namespace,
project_id: project,
target_branch: 'master',
id: commit.id)
end
......@@ -186,8 +186,8 @@ describe Projects::CommitController do
it 'redirects to the commit page' do
# Reverting a commit that has been already reverted.
post(:revert,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
namespace_id: project.namespace,
project_id: project,
target_branch: 'master',
id: commit.id)
......@@ -201,8 +201,8 @@ describe Projects::CommitController do
context 'when target branch is not provided' do
it 'renders the 404 page' do
post(:cherry_pick,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
namespace_id: project.namespace,
project_id: project,
id: master_pickable_commit.id)
expect(response).not_to be_success
......@@ -213,8 +213,8 @@ describe Projects::CommitController do
context 'when the cherry-pick was successful' do
it 'redirects to the commits page' do
post(:cherry_pick,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
namespace_id: project.namespace,
project_id: project,
target_branch: 'master',
id: master_pickable_commit.id)
......@@ -226,8 +226,8 @@ describe Projects::CommitController do
context 'when the cherry_pick failed' do
before do
post(:cherry_pick,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
namespace_id: project.namespace,
project_id: project,
target_branch: 'master',
id: master_pickable_commit.id)
end
......@@ -235,8 +235,8 @@ describe Projects::CommitController do
it 'redirects to the commit page' do
# Cherry-picking a commit that has been already cherry-picked.
post(:cherry_pick,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
namespace_id: project.namespace,
project_id: project,
target_branch: 'master',
id: master_pickable_commit.id)
......@@ -249,8 +249,8 @@ describe Projects::CommitController do
describe 'GET diff_for_path' do
def diff_for_path(extra_params = {})
params = {
namespace_id: project.namespace.to_param,
project_id: project.to_param
namespace_id: project.namespace,
project_id: project
}
get :diff_for_path, params.merge(extra_params)
......@@ -313,8 +313,8 @@ describe Projects::CommitController do
describe 'GET pipelines' do
def get_pipelines(extra_params = {})
params = {
namespace_id: project.namespace.to_param,
project_id: project.to_param
namespace_id: project.namespace,
project_id: project
}
get :pipelines, params.merge(extra_params)
......
......@@ -16,8 +16,8 @@ describe Projects::CommitsController do
context "when the ref does not exist with the suffix" do
it "renders as atom" do
get(:show,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
namespace_id: project.namespace,
project_id: project,
id: "master.atom")
expect(response).to be_success
......@@ -33,8 +33,8 @@ describe Projects::CommitsController do
allow_any_instance_of(Repository).to receive(:commit).with('master.atom').and_return(commit)
get(:show,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
namespace_id: project.namespace,
project_id: project,
id: "master.atom")
end
......
......@@ -13,8 +13,8 @@ describe Projects::CompareController do
it 'compare shows some diffs' do
get(:show,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
namespace_id: project.namespace,
project_id: project,
from: ref_from,
to: ref_to)
......@@ -25,8 +25,8 @@ describe Projects::CompareController do
it 'compare shows some diffs with ignore whitespace change option' do
get(:show,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
namespace_id: project.namespace,
project_id: project,
from: '08f22f25',
to: '66eceea0',
w: 1)
......@@ -43,8 +43,8 @@ describe Projects::CompareController do
describe 'non-existent refs' do
it 'uses invalid source ref' do
get(:show,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
namespace_id: project.namespace,
project_id: project,
from: 'non-existent',
to: ref_to)
......@@ -55,8 +55,8 @@ describe Projects::CompareController do
it 'uses invalid target ref' do
get(:show,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
namespace_id: project.namespace,
project_id: project,
from: ref_from,
to: 'non-existent')
......@@ -67,8 +67,8 @@ describe Projects::CompareController do
it 'redirects back to index when params[:from] is empty and preserves params[:to]' do
post(:create,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
namespace_id: project.namespace,
project_id: project,
from: '',
to: 'master')
......@@ -77,8 +77,8 @@ describe Projects::CompareController do
it 'redirects back to index when params[:to] is empty and preserves params[:from]' do
post(:create,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
namespace_id: project.namespace,
project_id: project,
from: 'master',
to: '')
......@@ -87,8 +87,8 @@ describe Projects::CompareController do
it 'redirects back to index when params[:from] and params[:to] are empty' do
post(:create,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
namespace_id: project.namespace,
project_id: project,
from: '',
to: '')
......@@ -99,8 +99,8 @@ describe Projects::CompareController do
describe 'GET diff_for_path' do
def diff_for_path(extra_params = {})
params = {
namespace_id: project.namespace.to_param,
project_id: project.to_param
namespace_id: project.namespace,
project_id: project
}
get :diff_for_path, params.merge(extra_params)
......
......@@ -13,8 +13,8 @@ describe Projects::CycleAnalyticsController do
context 'with no data' do
it 'is true' do
get(:show,
namespace_id: project.namespace.to_param,
project_id: project.to_param)
namespace_id: project.namespace,
project_id: project)
expect(response).to be_success
expect(assigns(:cycle_analytics_no_data)).to eq(true)
......@@ -32,8 +32,8 @@ describe Projects::CycleAnalyticsController do
it 'is false' do
get(:show,
namespace_id: project.namespace.to_param,
project_id: project.to_param)
namespace_id: project.namespace,
project_id: project)
expect(response).to be_success
expect(assigns(:cycle_analytics_no_data)).to eq(false)
......
......@@ -17,8 +17,8 @@ describe Projects::FindFileController do
before do
get(:show,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
namespace_id: project.namespace,
project_id: project,
id: id)
end
......@@ -36,8 +36,8 @@ describe Projects::FindFileController do
describe "GET #list" do
def go(format: 'json')
get :list,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
namespace_id: project.namespace,
project_id: project,
id: id,
format: format
end
......
......@@ -9,8 +9,8 @@ describe Projects::ForksController do
describe 'GET index' do
def get_forks
get :index,
namespace_id: project.namespace.to_param,
project_id: project.to_param
namespace_id: project.namespace,
project_id: project
end
context 'when fork is public' do
......@@ -71,8 +71,8 @@ describe Projects::ForksController do