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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
26622f4c
Commit
26622f4c
authored
Nov 22, 2012
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve routing. Project access via namespace
parent
a4d1bc17
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
8 deletions
+21
-8
app/controllers/application_controller.rb
app/controllers/application_controller.rb
+4
-1
app/models/project.rb
app/models/project.rb
+8
-1
app/observers/project_observer.rb
app/observers/project_observer.rb
+7
-4
config/routes.rb
config/routes.rb
+2
-2
No files found.
app/controllers/application_controller.rb
View file @
26622f4c
...
@@ -63,7 +63,10 @@ class ApplicationController < ActionController::Base
...
@@ -63,7 +63,10 @@ class ApplicationController < ActionController::Base
end
end
def
project
def
project
@project
||=
current_user
.
projects
.
find_by_code
(
params
[
:project_id
]
||
params
[
:id
])
id
=
params
[
:project_id
]
||
params
[
:id
]
id
=
id
.
split
(
"/"
)
if
id
.
include?
(
"/"
)
@project
||=
current_user
.
projects
.
find_by_code
(
id
)
@project
||
render_404
@project
||
render_404
end
end
...
...
app/models/project.rb
View file @
26622f4c
...
@@ -135,8 +135,12 @@ class Project < ActiveRecord::Base
...
@@ -135,8 +135,12 @@ class Project < ActiveRecord::Base
end
end
def
to_param
def
to_param
if
namespace
namespace
.
code
+
"/"
+
code
else
code
code
end
end
end
def
web_url
def
web_url
[
Gitlab
.
config
.
url
,
code
].
join
(
"/"
)
[
Gitlab
.
config
.
url
,
code
].
join
(
"/"
)
...
@@ -201,4 +205,7 @@ class Project < ActiveRecord::Base
...
@@ -201,4 +205,7 @@ class Project < ActiveRecord::Base
path
path
end
end
end
end
def
move_repo
end
end
end
app/observers/project_observer.rb
View file @
26622f4c
class
ProjectObserver
<
ActiveRecord
::
Observer
class
ProjectObserver
<
ActiveRecord
::
Observer
def
after_save
(
project
)
def
before_save
(
project
)
project
.
update_repository
# Move repository if namespace changed
# Move repository if namespace changed
if
project
.
namespace_id_changed?
if
project
.
namespace_id_changed?
move_project
(
project
)
move_project
(
project
)
end
end
end
end
def
after_save
(
project
)
project
.
update_repository
end
def
after_destroy
(
project
)
def
after_destroy
(
project
)
log_info
(
"Project
\"
#{
project
.
name
}
\"
was removed"
)
log_info
(
"Project
\"
#{
project
.
name
}
\"
was removed"
)
...
@@ -35,7 +37,8 @@ class ProjectObserver < ActiveRecord::Observer
...
@@ -35,7 +37,8 @@ class ProjectObserver < ActiveRecord::Observer
old_path
=
File
.
join
(
Gitlab
.
config
.
git_base_path
,
old_dir
,
"
#{
project
.
path
}
.git"
)
old_path
=
File
.
join
(
Gitlab
.
config
.
git_base_path
,
old_dir
,
"
#{
project
.
path
}
.git"
)
new_path
=
File
.
join
(
new_dir_path
,
"
#{
project
.
path
}
.git"
)
new_path
=
File
.
join
(
new_dir_path
,
"
#{
project
.
path
}
.git"
)
binding
.
pry
`mv
#{
old_path
}
#{
new_path
}
`
`mv
#{
old_path
}
#{
new_path
}
`
log_info
"Project
#{
project
.
name
}
was moved from
#{
old_path
}
to
#{
new_path
}
"
end
end
end
end
config/routes.rb
View file @
26622f4c
...
@@ -18,7 +18,7 @@ Gitlab::Application.routes.draw do
...
@@ -18,7 +18,7 @@ Gitlab::Application.routes.draw do
project_root:
Gitlab
.
config
.
git_base_path
,
project_root:
Gitlab
.
config
.
git_base_path
,
upload_pack:
Gitlab
.
config
.
git_upload_pack
,
upload_pack:
Gitlab
.
config
.
git_upload_pack
,
receive_pack:
Gitlab
.
config
.
git_receive_pack
receive_pack:
Gitlab
.
config
.
git_receive_pack
}),
at:
'/:path'
,
constraints:
{
path:
/[\w\.-]+\.git/
}
}),
at:
'/:path'
,
constraints:
{
path:
/[
-\/
\w\.-]+\.git/
}
#
#
# Help
# Help
...
@@ -107,7 +107,7 @@ Gitlab::Application.routes.draw do
...
@@ -107,7 +107,7 @@ Gitlab::Application.routes.draw do
#
#
# Project Area
# Project Area
#
#
resources
:projects
,
constraints:
{
id:
/[
^\/
]+/
},
except:
[
:new
,
:create
,
:index
],
path:
"/"
do
resources
:projects
,
constraints:
{
id:
/[
a-zA-Z.\/0-9_\-
]+/
},
except:
[
:new
,
:create
,
:index
],
path:
"/"
do
member
do
member
do
get
"wall"
get
"wall"
get
"graph"
get
"graph"
...
...
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