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
68f4b597
Commit
68f4b597
authored
Sep 27, 2012
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1569 from jouve/simplify_controllers2
Simplify controllers and layout handling
parents
3e9836ae
be18397d
Changes
27
Hide whitespace changes
Inline
Side-by-side
Showing
27 changed files
with
42 additions
and
151 deletions
+42
-151
app/controllers/application_controller.rb
app/controllers/application_controller.rb
+7
-17
app/controllers/blame_controller.rb
app/controllers/blame_controller.rb
+1
-6
app/controllers/blob_controller.rb
app/controllers/blob_controller.rb
+1
-6
app/controllers/commit_controller.rb
app/controllers/commit_controller.rb
+1
-5
app/controllers/commits_controller.rb
app/controllers/commits_controller.rb
+1
-5
app/controllers/compare_controller.rb
app/controllers/compare_controller.rb
+1
-5
app/controllers/deploy_keys_controller.rb
app/controllers/deploy_keys_controller.rb
+1
-8
app/controllers/errors_controller.rb
app/controllers/errors_controller.rb
+0
-2
app/controllers/hooks_controller.rb
app/controllers/hooks_controller.rb
+1
-5
app/controllers/issues_controller.rb
app/controllers/issues_controller.rb
+1
-7
app/controllers/labels_controller.rb
app/controllers/labels_controller.rb
+1
-7
app/controllers/merge_requests_controller.rb
app/controllers/merge_requests_controller.rb
+1
-6
app/controllers/milestones_controller.rb
app/controllers/milestones_controller.rb
+1
-6
app/controllers/notes_controller.rb
app/controllers/notes_controller.rb
+1
-5
app/controllers/profile_controller.rb
app/controllers/profile_controller.rb
+0
-1
app/controllers/project_resource_controller.rb
app/controllers/project_resource_controller.rb
+5
-0
app/controllers/projects_controller.rb
app/controllers/projects_controller.rb
+4
-19
app/controllers/protected_branches_controller.rb
app/controllers/protected_branches_controller.rb
+1
-6
app/controllers/refs_controller.rb
app/controllers/refs_controller.rb
+4
-8
app/controllers/repositories_controller.rb
app/controllers/repositories_controller.rb
+1
-6
app/controllers/snippets_controller.rb
app/controllers/snippets_controller.rb
+1
-6
app/controllers/team_members_controller.rb
app/controllers/team_members_controller.rb
+1
-5
app/controllers/tree_controller.rb
app/controllers/tree_controller.rb
+1
-6
app/controllers/wikis_controller.rb
app/controllers/wikis_controller.rb
+1
-4
app/views/layouts/errors.html.haml
app/views/layouts/errors.html.haml
+0
-0
app/views/layouts/project_resource.html.haml
app/views/layouts/project_resource.html.haml
+0
-0
config/application.rb
config/application.rb
+4
-0
No files found.
app/controllers/application_controller.rb
View file @
68f4b597
...
@@ -10,19 +10,17 @@ class ApplicationController < ActionController::Base
...
@@ -10,19 +10,17 @@ class ApplicationController < ActionController::Base
helper_method
:abilities
,
:can?
helper_method
:abilities
,
:can?
rescue_from
Gitlab
::
Gitolite
::
AccessDenied
do
|
exception
|
rescue_from
Gitlab
::
Gitolite
::
AccessDenied
do
|
exception
|
render
"errors/gitolite"
,
layout:
"error"
,
status:
500
render
"errors/gitolite"
,
layout:
"error
s
"
,
status:
500
end
end
rescue_from
Encoding
::
CompatibilityError
do
|
exception
|
rescue_from
Encoding
::
CompatibilityError
do
|
exception
|
render
"errors/encoding"
,
layout:
"error"
,
status:
500
render
"errors/encoding"
,
layout:
"error
s
"
,
status:
500
end
end
rescue_from
ActiveRecord
::
RecordNotFound
do
|
exception
|
rescue_from
ActiveRecord
::
RecordNotFound
do
|
exception
|
render
"errors/not_found"
,
layout:
"error"
,
status:
404
render
"errors/not_found"
,
layout:
"error
s
"
,
status:
404
end
end
layout
:layout_by_resource
protected
protected
def
reject_blocked!
def
reject_blocked!
...
@@ -43,14 +41,6 @@ class ApplicationController < ActionController::Base
...
@@ -43,14 +41,6 @@ class ApplicationController < ActionController::Base
end
end
end
end
def
layout_by_resource
if
devise_controller?
"devise_layout"
else
"application"
end
end
def
set_current_user_for_mailer
def
set_current_user_for_mailer
MailerObserver
.
current_user
=
current_user
MailerObserver
.
current_user
=
current_user
end
end
...
@@ -68,7 +58,7 @@ class ApplicationController < ActionController::Base
...
@@ -68,7 +58,7 @@ class ApplicationController < ActionController::Base
end
end
def
project
def
project
@project
||=
current_user
.
projects
.
find_by_code
(
params
[
:project_id
])
@project
||=
current_user
.
projects
.
find_by_code
(
params
[
:project_id
]
||
params
[
:id
]
)
@project
||
render_404
@project
||
render_404
end
end
...
@@ -85,15 +75,15 @@ class ApplicationController < ActionController::Base
...
@@ -85,15 +75,15 @@ class ApplicationController < ActionController::Base
end
end
def
access_denied!
def
access_denied!
render
"errors/access_denied"
,
layout:
"error"
,
status:
404
render
"errors/access_denied"
,
layout:
"error
s
"
,
status:
404
end
end
def
not_found!
def
not_found!
render
"errors/not_found"
,
layout:
"error"
,
status:
404
render
"errors/not_found"
,
layout:
"error
s
"
,
status:
404
end
end
def
git_not_found!
def
git_not_found!
render
"errors/git_not_found"
,
layout:
"error"
,
status:
404
render
"errors/git_not_found"
,
layout:
"error
s
"
,
status:
404
end
end
def
method_missing
(
method_sym
,
*
arguments
,
&
block
)
def
method_missing
(
method_sym
,
*
arguments
,
&
block
)
...
...
app/controllers/blame_controller.rb
View file @
68f4b597
# Controller for viewing a file's blame
# Controller for viewing a file's blame
class
BlameController
<
Application
Controller
class
BlameController
<
ProjectResource
Controller
include
ExtractsPath
include
ExtractsPath
layout
"project"
before_filter
:project
# Authorize
# Authorize
before_filter
:add_project_abilities
before_filter
:authorize_read_project!
before_filter
:authorize_read_project!
before_filter
:authorize_code_access!
before_filter
:authorize_code_access!
before_filter
:require_non_empty_project
before_filter
:require_non_empty_project
...
...
app/controllers/blob_controller.rb
View file @
68f4b597
# Controller for viewing a file's blame
# Controller for viewing a file's blame
class
BlobController
<
Application
Controller
class
BlobController
<
ProjectResource
Controller
include
ExtractsPath
include
ExtractsPath
include
Gitlab
::
Encode
include
Gitlab
::
Encode
layout
"project"
before_filter
:project
# Authorize
# Authorize
before_filter
:add_project_abilities
before_filter
:authorize_read_project!
before_filter
:authorize_read_project!
before_filter
:authorize_code_access!
before_filter
:authorize_code_access!
before_filter
:require_non_empty_project
before_filter
:require_non_empty_project
...
...
app/controllers/commit_controller.rb
View file @
68f4b597
# Controller for a specific Commit
# Controller for a specific Commit
#
#
# Not to be confused with CommitsController, plural.
# Not to be confused with CommitsController, plural.
class
CommitController
<
ApplicationController
class
CommitController
<
ProjectResourceController
before_filter
:project
layout
"project"
# Authorize
# Authorize
before_filter
:add_project_abilities
before_filter
:authorize_read_project!
before_filter
:authorize_read_project!
before_filter
:authorize_code_access!
before_filter
:authorize_code_access!
before_filter
:require_non_empty_project
before_filter
:require_non_empty_project
...
...
app/controllers/commits_controller.rb
View file @
68f4b597
require
"base64"
require
"base64"
class
CommitsController
<
ApplicationController
class
CommitsController
<
ProjectResourceController
before_filter
:project
layout
"project"
include
ExtractsPath
include
ExtractsPath
# Authorize
# Authorize
before_filter
:add_project_abilities
before_filter
:authorize_read_project!
before_filter
:authorize_read_project!
before_filter
:authorize_code_access!
before_filter
:authorize_code_access!
before_filter
:require_non_empty_project
before_filter
:require_non_empty_project
...
...
app/controllers/compare_controller.rb
View file @
68f4b597
class
CompareController
<
ApplicationController
class
CompareController
<
ProjectResourceController
before_filter
:project
layout
"project"
# Authorize
# Authorize
before_filter
:add_project_abilities
before_filter
:authorize_read_project!
before_filter
:authorize_read_project!
before_filter
:authorize_code_access!
before_filter
:authorize_code_access!
before_filter
:require_non_empty_project
before_filter
:require_non_empty_project
...
...
app/controllers/deploy_keys_controller.rb
View file @
68f4b597
class
DeployKeysController
<
Application
Controller
class
DeployKeysController
<
ProjectResource
Controller
respond_to
:html
respond_to
:html
layout
"project"
before_filter
:project
# Authorize
# Authorize
before_filter
:add_project_abilities
before_filter
:authorize_admin_project!
before_filter
:authorize_admin_project!
def
project
@project
||=
Project
.
find_by_code
(
params
[
:project_id
])
end
def
index
def
index
@keys
=
@project
.
deploy_keys
.
all
@keys
=
@project
.
deploy_keys
.
all
end
end
...
...
app/controllers/errors_controller.rb
View file @
68f4b597
class
ErrorsController
<
ApplicationController
class
ErrorsController
<
ApplicationController
layout
"error"
def
githost
def
githost
render
"errors/gitolite"
render
"errors/gitolite"
end
end
...
...
app/controllers/hooks_controller.rb
View file @
68f4b597
class
HooksController
<
ApplicationController
class
HooksController
<
ProjectResourceController
before_filter
:project
layout
"project"
# Authorize
# Authorize
before_filter
:add_project_abilities
before_filter
:authorize_read_project!
before_filter
:authorize_read_project!
before_filter
:authorize_admin_project!
,
only:
[
:new
,
:create
,
:destroy
]
before_filter
:authorize_admin_project!
,
only:
[
:new
,
:create
,
:destroy
]
...
...
app/controllers/issues_controller.rb
View file @
68f4b597
class
IssuesController
<
ApplicationController
class
IssuesController
<
ProjectResourceController
before_filter
:project
before_filter
:module_enabled
before_filter
:module_enabled
before_filter
:issue
,
only:
[
:edit
,
:update
,
:destroy
,
:show
]
before_filter
:issue
,
only:
[
:edit
,
:update
,
:destroy
,
:show
]
helper_method
:issues_filter
helper_method
:issues_filter
layout
"project"
# Authorize
before_filter
:add_project_abilities
# Allow read any issue
# Allow read any issue
before_filter
:authorize_read_issue!
before_filter
:authorize_read_issue!
...
...
app/controllers/labels_controller.rb
View file @
68f4b597
class
LabelsController
<
ApplicationController
class
LabelsController
<
ProjectResourceController
before_filter
:project
before_filter
:module_enabled
before_filter
:module_enabled
layout
"project"
# Authorize
before_filter
:add_project_abilities
# Allow read any issue
# Allow read any issue
before_filter
:authorize_read_issue!
before_filter
:authorize_read_issue!
...
...
app/controllers/merge_requests_controller.rb
View file @
68f4b597
class
MergeRequestsController
<
ApplicationController
class
MergeRequestsController
<
ProjectResourceController
before_filter
:project
before_filter
:module_enabled
before_filter
:module_enabled
before_filter
:merge_request
,
only:
[
:edit
,
:update
,
:destroy
,
:show
,
:commits
,
:diffs
,
:automerge
,
:automerge_check
,
:raw
]
before_filter
:merge_request
,
only:
[
:edit
,
:update
,
:destroy
,
:show
,
:commits
,
:diffs
,
:automerge
,
:automerge_check
,
:raw
]
before_filter
:validates_merge_request
,
only:
[
:show
,
:diffs
,
:raw
]
before_filter
:validates_merge_request
,
only:
[
:show
,
:diffs
,
:raw
]
before_filter
:define_show_vars
,
only:
[
:show
,
:diffs
]
before_filter
:define_show_vars
,
only:
[
:show
,
:diffs
]
layout
"project"
# Authorize
before_filter
:add_project_abilities
# Allow read any merge_request
# Allow read any merge_request
before_filter
:authorize_read_merge_request!
before_filter
:authorize_read_merge_request!
...
...
app/controllers/milestones_controller.rb
View file @
68f4b597
class
MilestonesController
<
ApplicationController
class
MilestonesController
<
ProjectResourceController
before_filter
:project
before_filter
:module_enabled
before_filter
:module_enabled
before_filter
:milestone
,
only:
[
:edit
,
:update
,
:destroy
,
:show
]
before_filter
:milestone
,
only:
[
:edit
,
:update
,
:destroy
,
:show
]
layout
"project"
# Authorize
before_filter
:add_project_abilities
# Allow read any milestone
# Allow read any milestone
before_filter
:authorize_read_milestone!
before_filter
:authorize_read_milestone!
...
...
app/controllers/notes_controller.rb
View file @
68f4b597
class
NotesController
<
ApplicationController
class
NotesController
<
ProjectResourceController
before_filter
:project
# Authorize
# Authorize
before_filter
:add_project_abilities
before_filter
:authorize_read_note!
before_filter
:authorize_read_note!
before_filter
:authorize_write_note!
,
only:
[
:create
]
before_filter
:authorize_write_note!
,
only:
[
:create
]
...
...
app/controllers/profile_controller.rb
View file @
68f4b597
class
ProfileController
<
ApplicationController
class
ProfileController
<
ApplicationController
layout
"profile"
before_filter
:user
before_filter
:user
def
show
def
show
...
...
app/controllers/project_resource_controller.rb
0 → 100644
View file @
68f4b597
class
ProjectResourceController
<
ApplicationController
before_filter
:project
# Authorize
before_filter
:add_project_abilities
end
app/controllers/projects_controller.rb
View file @
68f4b597
require
Rails
.
root
.
join
(
'lib'
,
'gitlab'
,
'graph_commit'
)
require
Rails
.
root
.
join
(
'lib'
,
'gitlab'
,
'graph_commit'
)
class
ProjectsController
<
ApplicationController
class
ProjectsController
<
ProjectResourceController
before_filter
:project
,
except:
[
:index
,
:new
,
:create
]
skip_before_filter
:project
,
only:
[
:new
,
:create
]
layout
:determine_layout
# Authorize
# Authorize
before_filter
:add_project_abilities
before_filter
:authorize_read_project!
,
except:
[
:index
,
:new
,
:create
]
before_filter
:authorize_read_project!
,
except:
[
:index
,
:new
,
:create
]
before_filter
:authorize_admin_project!
,
only:
[
:edit
,
:update
,
:destroy
]
before_filter
:authorize_admin_project!
,
only:
[
:edit
,
:update
,
:destroy
]
before_filter
:require_non_empty_project
,
only:
[
:blob
,
:tree
,
:graph
]
before_filter
:require_non_empty_project
,
only:
[
:blob
,
:tree
,
:graph
]
layout
'application'
,
only:
[
:new
,
:create
]
def
new
def
new
@project
=
Project
.
new
@project
=
Project
.
new
end
end
...
@@ -93,19 +93,4 @@ class ProjectsController < ApplicationController
...
@@ -93,19 +93,4 @@ class ProjectsController < ApplicationController
format
.
html
{
redirect_to
root_path
}
format
.
html
{
redirect_to
root_path
}
end
end
end
end
protected
def
project
@project
||=
Project
.
find_by_code
(
params
[
:id
])
@project
||
render_404
end
def
determine_layout
if
@project
&&
!
@project
.
new_record?
"project"
else
"application"
end
end
end
end
app/controllers/protected_branches_controller.rb
View file @
68f4b597
class
ProtectedBranchesController
<
ApplicationController
class
ProtectedBranchesController
<
ProjectResourceController
before_filter
:project
# Authorize
# Authorize
before_filter
:add_project_abilities
before_filter
:authorize_read_project!
before_filter
:authorize_read_project!
before_filter
:require_non_empty_project
before_filter
:require_non_empty_project
before_filter
:authorize_admin_project!
,
only:
[
:destroy
,
:create
]
before_filter
:authorize_admin_project!
,
only:
[
:destroy
,
:create
]
layout
"project"
def
index
def
index
@branches
=
@project
.
protected_branches
.
all
@branches
=
@project
.
protected_branches
.
all
@protected_branch
=
@project
.
protected_branches
.
new
@protected_branch
=
@project
.
protected_branches
.
new
...
...
app/controllers/refs_controller.rb
View file @
68f4b597
class
RefsController
<
Application
Controller
class
RefsController
<
ProjectResource
Controller
include
Gitlab
::
Encode
include
Gitlab
::
Encode
before_filter
:project
# Authorize
# Authorize
before_filter
:add_project_abilities
before_filter
:authorize_read_project!
before_filter
:authorize_read_project!
before_filter
:authorize_code_access!
before_filter
:authorize_code_access!
before_filter
:require_non_empty_project
before_filter
:require_non_empty_project
...
@@ -11,11 +9,9 @@ class RefsController < ApplicationController
...
@@ -11,11 +9,9 @@ class RefsController < ApplicationController
before_filter
:ref
before_filter
:ref
before_filter
:define_tree_vars
,
only:
[
:blob
,
:logs_tree
]
before_filter
:define_tree_vars
,
only:
[
:blob
,
:logs_tree
]
layout
"project"
def
switch
respond_to
do
|
format
|
def
switch
format
.
html
do
respond_to
do
|
format
|
format
.
html
do
new_path
=
if
params
[
:destination
]
==
"tree"
new_path
=
if
params
[
:destination
]
==
"tree"
project_tree_path
(
@project
,
@ref
)
project_tree_path
(
@project
,
@ref
)
else
else
...
...
app/controllers/repositories_controller.rb
View file @
68f4b597
class
RepositoriesController
<
ApplicationController
class
RepositoriesController
<
ProjectResourceController
before_filter
:project
# Authorize
# Authorize
before_filter
:add_project_abilities
before_filter
:authorize_read_project!
before_filter
:authorize_read_project!
before_filter
:authorize_code_access!
before_filter
:authorize_code_access!
before_filter
:require_non_empty_project
before_filter
:require_non_empty_project
layout
"project"
def
show
def
show
@activities
=
@project
.
commits_with_refs
(
20
)
@activities
=
@project
.
commits_with_refs
(
20
)
end
end
...
...
app/controllers/snippets_controller.rb
View file @
68f4b597
class
SnippetsController
<
ApplicationController
class
SnippetsController
<
ProjectResourceController
before_filter
:project
before_filter
:snippet
,
only:
[
:show
,
:edit
,
:destroy
,
:update
,
:raw
]
before_filter
:snippet
,
only:
[
:show
,
:edit
,
:destroy
,
:update
,
:raw
]
layout
"project"
# Authorize
before_filter
:add_project_abilities
# Allow read any snippet
# Allow read any snippet
before_filter
:authorize_read_snippet!
before_filter
:authorize_read_snippet!
...
...
app/controllers/team_members_controller.rb
View file @
68f4b597
class
TeamMembersController
<
ApplicationController
class
TeamMembersController
<
ProjectResourceController
before_filter
:project
layout
"project"
# Authorize
# Authorize
before_filter
:add_project_abilities
before_filter
:authorize_read_project!
before_filter
:authorize_read_project!
before_filter
:authorize_admin_project!
,
except:
[
:index
,
:show
]
before_filter
:authorize_admin_project!
,
except:
[
:index
,
:show
]
...
...
app/controllers/tree_controller.rb
View file @
68f4b597
# Controller for viewing a repository's file structure
# Controller for viewing a repository's file structure
class
TreeController
<
Application
Controller
class
TreeController
<
ProjectResource
Controller
include
ExtractsPath
include
ExtractsPath
layout
"project"
before_filter
:project
# Authorize
# Authorize
before_filter
:add_project_abilities
before_filter
:authorize_read_project!
before_filter
:authorize_read_project!
before_filter
:authorize_code_access!
before_filter
:authorize_code_access!
before_filter
:require_non_empty_project
before_filter
:require_non_empty_project
...
...
app/controllers/wikis_controller.rb
View file @
68f4b597
class
WikisController
<
ApplicationController
class
WikisController
<
ProjectResourceController
before_filter
:project
before_filter
:add_project_abilities
before_filter
:authorize_read_wiki!
before_filter
:authorize_read_wiki!
before_filter
:authorize_write_wiki!
,
only:
[
:edit
,
:create
,
:history
]
before_filter
:authorize_write_wiki!
,
only:
[
:edit
,
:create
,
:history
]
before_filter
:authorize_admin_wiki!
,
only: :destroy
before_filter
:authorize_admin_wiki!
,
only: :destroy
layout
"project"
def
pages
def
pages
@wikis
=
@project
.
wikis
.
group
(
:slug
).
order
(
"created_at"
)
@wikis
=
@project
.
wikis
.
group
(
:slug
).
order
(
"created_at"
)
...
...
app/views/layouts/error.html.haml
→
app/views/layouts/error
s
.html.haml
View file @
68f4b597
File moved
app/views/layouts/project.html.haml
→
app/views/layouts/project
_resource
.html.haml
View file @
68f4b597
File moved
config/application.rb
View file @
68f4b597
...
@@ -53,5 +53,9 @@ module Gitlab
...
@@ -53,5 +53,9 @@ module Gitlab
# Add fonts
# Add fonts
config
.
assets
.
paths
<<
"
#{
Rails
.
root
}
/app/assets/fonts"
config
.
assets
.
paths
<<
"
#{
Rails
.
root
}
/app/assets/fonts"
config
.
to_prepare
do
Devise
::
SessionsController
.
layout
'devise_layout'
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