BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
dd35bd2d
Commit
dd35bd2d
authored
May 18, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'bvl-fix-incorrectly-renamed-routes' into 'master'
Fixes for the rename reserved paths helpers Closes #32528 See merge request !11492
parents
36ede008
f62f0c25
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
2 deletions
+51
-2
migration_classes.rb
...e/rename_reserved_paths_migration/v1/migration_classes.rb
+8
-0
rename_base.rb
...atabase/rename_reserved_paths_migration/v1/rename_base.rb
+2
-1
rename_namespaces.rb
...e/rename_reserved_paths_migration/v1/rename_namespaces.rb
+6
-0
rename_base_spec.rb
...se/rename_reserved_paths_migration/v1/rename_base_spec.rb
+9
-0
rename_namespaces_spec.rb
...ame_reserved_paths_migration/v1/rename_namespaces_spec.rb
+26
-1
No files found.
lib/gitlab/database/rename_reserved_paths_migration/v1/migration_classes.rb
View file @
dd35bd2d
...
...
@@ -48,6 +48,14 @@ module Gitlab
def
self
.
name
'Namespace'
end
def
kind
type
==
'Group'
?
'group'
:
'user'
end
end
class
User
<
ActiveRecord
::
Base
self
.
table_name
=
'users'
end
class
Route
<
ActiveRecord
::
Base
...
...
lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb
View file @
dd35bd2d
...
...
@@ -41,7 +41,8 @@ module Gitlab
new_full_path
)
update_column_in_batches
(
:routes
,
:path
,
replace_statement
)
do
|
table
,
query
|
query
.
where
(
MigrationClasses
::
Route
.
arel_table
[
:path
].
matches
(
"
#{
old_full_path
}
%"
))
path_or_children
=
table
[
:path
].
matches_any
([
old_full_path
,
"
#{
old_full_path
}
/%"
])
query
.
where
(
path_or_children
)
end
end
...
...
lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces.rb
View file @
dd35bd2d
...
...
@@ -29,9 +29,15 @@ module Gitlab
move_repositories
(
namespace
,
old_full_path
,
new_full_path
)
move_uploads
(
old_full_path
,
new_full_path
)
move_pages
(
old_full_path
,
new_full_path
)
rename_user
(
old_full_path
,
new_full_path
)
if
namespace
.
kind
==
'user'
remove_cached_html_for_projects
(
projects_for_namespace
(
namespace
).
map
(
&
:id
))
end
def
rename_user
(
old_username
,
new_username
)
MigrationClasses
::
User
.
where
(
username:
old_username
)
.
update_all
(
username:
new_username
)
end
def
move_repositories
(
namespace
,
old_full_path
,
new_full_path
)
repo_paths_for_namespace
(
namespace
).
each
do
|
repository_storage_path
|
# Ensure old directory exists before moving it
...
...
spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base_spec.rb
View file @
dd35bd2d
...
...
@@ -107,6 +107,15 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameBase do
expect
(
new_path
).
to
eq
(
'the-path0'
)
end
it
"doesn't rename routes that start with a similar name"
do
other_namespace
=
create
(
:namespace
,
path:
'the-path-but-not-really'
)
project
=
create
(
:empty_project
,
path:
'the-project'
,
namespace:
other_namespace
)
subject
.
rename_path_for_routable
(
migration_namespace
(
namespace
))
expect
(
project
.
route
.
reload
.
path
).
to
eq
(
'the-path-but-not-really/the-project'
)
end
context
"the-path namespace -> subgroup -> the-path0 project"
do
it
"updates the route of the project correctly"
do
subgroup
=
create
(
:group
,
path:
"subgroup"
,
parent:
namespace
)
...
...
spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb
View file @
dd35bd2d
...
...
@@ -137,7 +137,7 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces do
end
describe
"#rename_namespace"
do
let
(
:namespace
)
{
create
(
:
namespace
,
path
:
'the-path'
)
}
let
(
:namespace
)
{
create
(
:
group
,
name
:
'the-path'
)
}
it
'renames paths & routes for the namespace'
do
expect
(
subject
).
to
receive
(
:rename_path_for_routable
).
...
...
@@ -177,6 +177,31 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces do
subject
.
rename_namespace
(
namespace
)
end
it
"doesn't rename users for other namespaces"
do
expect
(
subject
).
not_to
receive
(
:rename_user
)
subject
.
rename_namespace
(
namespace
)
end
it
'renames the username of a namespace for a user'
do
user
=
create
(
:user
,
username:
'the-path'
)
expect
(
subject
).
to
receive
(
:rename_user
).
with
(
'the-path'
,
'the-path0'
)
subject
.
rename_namespace
(
user
.
namespace
)
end
end
describe
'#rename_user'
do
it
'renames a username'
do
subject
=
described_class
.
new
([],
migration
)
user
=
create
(
:user
,
username:
'broken'
)
subject
.
rename_user
(
'broken'
,
'broken0'
)
expect
(
user
.
reload
.
username
).
to
eq
(
'broken0'
)
end
end
describe
'#rename_namespaces'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment