Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tatuya Kamada
gitlab-ce
Commits
d405c8fc
Commit
d405c8fc
authored
Nov 24, 2012
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create namespace on username init. Raise exception if project cannot be moved
parent
4023d9f8
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
8 deletions
+21
-8
app/observers/project_observer.rb
app/observers/project_observer.rb
+3
-2
app/observers/user_observer.rb
app/observers/user_observer.rb
+6
-2
lib/gitlab/project_mover.rb
lib/gitlab/project_mover.rb
+5
-1
lib/tasks/gitlab/activate_namespaces.rake
lib/tasks/gitlab/activate_namespaces.rake
+7
-3
No files found.
app/observers/project_observer.rb
View file @
d405c8fc
class
ProjectObserver
<
ActiveRecord
::
Observer
class
ProjectObserver
<
ActiveRecord
::
Observer
def
after_save
(
project
)
def
after_save
(
project
)
project
.
update_repository
# Move repository if namespace changed
# Move repository if namespace changed
if
project
.
namespace_id_changed?
and
not
project
.
new_record?
if
project
.
namespace_id_changed?
and
not
project
.
new_record?
old_dir
=
Namespace
.
find_by_id
(
project
.
namespace_id_was
).
try
(
:path
)
||
''
old_dir
=
Namespace
.
find_by_id
(
project
.
namespace_id_was
).
try
(
:path
)
||
''
...
@@ -9,6 +7,9 @@ class ProjectObserver < ActiveRecord::Observer
...
@@ -9,6 +7,9 @@ class ProjectObserver < ActiveRecord::Observer
Gitlab
::
ProjectMover
.
new
(
project
,
old_dir
,
new_dir
).
execute
Gitlab
::
ProjectMover
.
new
(
project
,
old_dir
,
new_dir
).
execute
end
end
# Update gitolite
project
.
update_repository
end
end
def
after_destroy
(
project
)
def
after_destroy
(
project
)
...
...
app/observers/user_observer.rb
View file @
d405c8fc
...
@@ -12,8 +12,12 @@ class UserObserver < ActiveRecord::Observer
...
@@ -12,8 +12,12 @@ class UserObserver < ActiveRecord::Observer
end
end
def
after_save
user
def
after_save
user
if
user
.
username_changed?
and
user
.
namespace
if
user
.
username_changed?
if
user
.
namespace
user
.
namespace
.
update_attributes
(
path:
user
.
username
)
user
.
namespace
.
update_attributes
(
path:
user
.
username
)
else
user
.
create_namespace!
(
path:
user
.
username
,
name:
user
.
name
)
end
end
end
end
end
...
...
lib/gitlab/project_mover.rb
View file @
d405c8fc
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
# Used for moving project repositories from one subdir to another
# Used for moving project repositories from one subdir to another
module
Gitlab
module
Gitlab
class
ProjectMover
class
ProjectMover
class
ProjectMoveError
<
StandardError
;
end
attr_reader
:project
,
:old_dir
,
:new_dir
attr_reader
:project
,
:old_dir
,
:new_dir
def
initialize
(
project
,
old_dir
,
new_dir
)
def
initialize
(
project
,
old_dir
,
new_dir
)
...
@@ -23,7 +25,9 @@ module Gitlab
...
@@ -23,7 +25,9 @@ module Gitlab
log_info
"Project
#{
project
.
name
}
was moved from
#{
old_path
}
to
#{
new_path
}
"
log_info
"Project
#{
project
.
name
}
was moved from
#{
old_path
}
to
#{
new_path
}
"
true
true
else
else
log_info
"Error! Project
#{
project
.
name
}
cannot be moved from
#{
old_path
}
to
#{
new_path
}
"
message
=
"Project
#{
project
.
name
}
cannot be moved from
#{
old_path
}
to
#{
new_path
}
"
log_info
"Error!
#{
message
}
"
raise
ProjectMoveError
.
new
(
message
)
false
false
end
end
end
end
...
...
lib/tasks/gitlab/activate_namespaces.rake
View file @
d405c8fc
...
@@ -2,11 +2,15 @@ namespace :gitlab do
...
@@ -2,11 +2,15 @@ namespace :gitlab do
desc
"GITLAB | Enable usernames and namespaces for user projects"
desc
"GITLAB | Enable usernames and namespaces for user projects"
task
activate_namespaces: :environment
do
task
activate_namespaces: :environment
do
User
.
find_each
(
batch_size:
500
)
do
|
user
|
User
.
find_each
(
batch_size:
500
)
do
|
user
|
next
if
user
.
namespace
User
.
transaction
do
User
.
transaction
do
username
=
user
.
email
.
match
(
/^[^@]*/
)[
0
]
username
=
user
.
email
.
match
(
/^[^@]*/
)[
0
]
user
.
update_attributes!
(
username:
username
)
if
user
.
update_attributes!
(
username:
username
)
user
.
create_namespace!
(
code:
username
,
name:
user
.
name
)
print
'.'
.
green
print
'.'
.
green
else
print
'F'
.
red
end
end
end
end
end
end
end
...
...
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