Rename Projects & Namespaces based on entire paths
This commit is contained in:
parent
e50f4bc066
commit
389057f001
6 changed files with 38 additions and 9 deletions
|
@ -27,7 +27,8 @@ class RenameReservedDynamicPaths < ActiveRecord::Migration
|
|||
users
|
||||
]
|
||||
|
||||
DISALLOWED_WILDCARD_PATHS = %w[objects folders file]
|
||||
DISALLOWED_WILDCARD_PATHS = %w[info/lfs/objects gitlab-lfs/objects
|
||||
environments/folders]
|
||||
|
||||
def up
|
||||
rename_root_paths(DISALLOWED_ROOT_PATHS)
|
||||
|
|
|
@ -13,6 +13,10 @@ module Gitlab
|
|||
@migration = migration
|
||||
end
|
||||
|
||||
def path_patterns
|
||||
@path_patterns ||= paths.map { |path| "%#{path}" }
|
||||
end
|
||||
|
||||
def rename_path_for_routable(routable)
|
||||
old_path = routable.path
|
||||
old_full_path = routable.full_path
|
||||
|
|
|
@ -16,9 +16,9 @@ module Gitlab
|
|||
elsif type == :top_level
|
||||
MigrationClasses::Namespace.where(parent_id: nil)
|
||||
end
|
||||
with_paths = MigrationClasses::Namespace.arel_table[:path].
|
||||
matches_any(paths)
|
||||
namespaces.where(with_paths)
|
||||
with_paths = MigrationClasses::Route.arel_table[:path].
|
||||
matches_any(path_patterns)
|
||||
namespaces.joins(:route).where(with_paths)
|
||||
end
|
||||
|
||||
def rename_namespace(namespace)
|
||||
|
@ -43,8 +43,8 @@ module Gitlab
|
|||
end
|
||||
|
||||
def repo_paths_for_namespace(namespace)
|
||||
projects_for_namespace(namespace).
|
||||
select('distinct(repository_storage)').map(&:repository_storage_path)
|
||||
projects_for_namespace(namespace).distinct.select(:repository_storage).
|
||||
map(&:repository_storage_path)
|
||||
end
|
||||
|
||||
def projects_for_namespace(namespace)
|
||||
|
|
|
@ -28,9 +28,10 @@ module Gitlab
|
|||
end
|
||||
|
||||
def projects_for_paths
|
||||
with_paths = MigrationClasses::Project.arel_table[:path]
|
||||
.matches_any(paths)
|
||||
MigrationClasses::Project.where(with_paths)
|
||||
with_paths = MigrationClasses::Route.arel_table[:path]
|
||||
.matches_any(path_patterns)
|
||||
|
||||
MigrationClasses::Project.joins(:route).where(with_paths)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,6 +14,19 @@ describe Gitlab::Database::RenameReservedPathsMigration::RenameNamespaces do
|
|||
end
|
||||
|
||||
describe '#namespaces_for_paths' do
|
||||
context 'nested namespaces' do
|
||||
let(:subject) { described_class.new(['parent/the-Path'], migration) }
|
||||
|
||||
it 'includes the namespace' do
|
||||
parent = create(:namespace, path: 'parent')
|
||||
child = create(:namespace, path: 'the-path', parent: parent)
|
||||
|
||||
found_ids = subject.namespaces_for_paths(type: :wildcard).
|
||||
map(&:id)
|
||||
expect(found_ids).to contain_exactly(child.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'for wildcard namespaces' do
|
||||
it 'only returns child namespaces with the correct path' do
|
||||
_root_namespace = create(:namespace, path: 'THE-path')
|
||||
|
|
|
@ -9,6 +9,16 @@ describe Gitlab::Database::RenameReservedPathsMigration::RenameProjects do
|
|||
end
|
||||
|
||||
describe '#projects_for_paths' do
|
||||
it 'searches using nested paths' do
|
||||
namespace = create(:namespace, path: 'hello')
|
||||
project = create(:empty_project, path: 'THE-path', namespace: namespace)
|
||||
|
||||
result_ids = described_class.new(['Hello/the-path'], migration).
|
||||
projects_for_paths.map(&:id)
|
||||
|
||||
expect(result_ids).to contain_exactly(project.id)
|
||||
end
|
||||
|
||||
it 'includes the correct projects' do
|
||||
project = create(:empty_project, path: 'THE-path')
|
||||
_other_project = create(:empty_project)
|
||||
|
|
Loading…
Reference in a new issue