summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-09-27 12:53:01 -0700
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-09-27 12:53:01 -0700
commit68f4b59738b43d9d6969528188ec74a87546a29f (patch)
tree65abe373fa1316a7e072b0fa997d519764def4d3 /app
parent3e9836ae1e21dfaf60a5059959c7bc38dc17decf (diff)
parentbe18397d82ca16fefed7287c8078a9b41bf37c95 (diff)
downloadgitlab-ce-68f4b59738b43d9d6969528188ec74a87546a29f.tar.gz
Merge pull request #1569 from jouve/simplify_controllers2
Simplify controllers and layout handling
Diffstat (limited to 'app')
-rw-r--r--app/controllers/application_controller.rb24
-rw-r--r--app/controllers/blame_controller.rb7
-rw-r--r--app/controllers/blob_controller.rb7
-rw-r--r--app/controllers/commit_controller.rb6
-rw-r--r--app/controllers/commits_controller.rb6
-rw-r--r--app/controllers/compare_controller.rb6
-rw-r--r--app/controllers/deploy_keys_controller.rb9
-rw-r--r--app/controllers/errors_controller.rb2
-rw-r--r--app/controllers/hooks_controller.rb6
-rw-r--r--app/controllers/issues_controller.rb8
-rw-r--r--app/controllers/labels_controller.rb8
-rw-r--r--app/controllers/merge_requests_controller.rb7
-rw-r--r--app/controllers/milestones_controller.rb7
-rw-r--r--app/controllers/notes_controller.rb6
-rw-r--r--app/controllers/profile_controller.rb1
-rw-r--r--app/controllers/project_resource_controller.rb5
-rw-r--r--app/controllers/projects_controller.rb23
-rw-r--r--app/controllers/protected_branches_controller.rb7
-rw-r--r--app/controllers/refs_controller.rb12
-rw-r--r--app/controllers/repositories_controller.rb7
-rw-r--r--app/controllers/snippets_controller.rb7
-rw-r--r--app/controllers/team_members_controller.rb6
-rw-r--r--app/controllers/tree_controller.rb7
-rw-r--r--app/controllers/wikis_controller.rb5
-rw-r--r--app/views/layouts/errors.html.haml (renamed from app/views/layouts/error.html.haml)0
-rw-r--r--app/views/layouts/project_resource.html.haml (renamed from app/views/layouts/project.html.haml)0
26 files changed, 38 insertions, 151 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 334135c89c2..c4c99204e03 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -10,19 +10,17 @@ class ApplicationController < ActionController::Base
helper_method :abilities, :can?
rescue_from Gitlab::Gitolite::AccessDenied do |exception|
- render "errors/gitolite", layout: "error", status: 500
+ render "errors/gitolite", layout: "errors", status: 500
end
rescue_from Encoding::CompatibilityError do |exception|
- render "errors/encoding", layout: "error", status: 500
+ render "errors/encoding", layout: "errors", status: 500
end
rescue_from ActiveRecord::RecordNotFound do |exception|
- render "errors/not_found", layout: "error", status: 404
+ render "errors/not_found", layout: "errors", status: 404
end
- layout :layout_by_resource
-
protected
def reject_blocked!
@@ -43,14 +41,6 @@ class ApplicationController < ActionController::Base
end
end
- def layout_by_resource
- if devise_controller?
- "devise_layout"
- else
- "application"
- end
- end
-
def set_current_user_for_mailer
MailerObserver.current_user = current_user
end
@@ -68,7 +58,7 @@ class ApplicationController < ActionController::Base
end
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
end
@@ -85,15 +75,15 @@ class ApplicationController < ActionController::Base
end
def access_denied!
- render "errors/access_denied", layout: "error", status: 404
+ render "errors/access_denied", layout: "errors", status: 404
end
def not_found!
- render "errors/not_found", layout: "error", status: 404
+ render "errors/not_found", layout: "errors", status: 404
end
def git_not_found!
- render "errors/git_not_found", layout: "error", status: 404
+ render "errors/git_not_found", layout: "errors", status: 404
end
def method_missing(method_sym, *arguments, &block)
diff --git a/app/controllers/blame_controller.rb b/app/controllers/blame_controller.rb
index dd0837ea9ab..37d7245ccb4 100644
--- a/app/controllers/blame_controller.rb
+++ b/app/controllers/blame_controller.rb
@@ -1,13 +1,8 @@
# Controller for viewing a file's blame
-class BlameController < ApplicationController
+class BlameController < ProjectResourceController
include ExtractsPath
- layout "project"
-
- before_filter :project
-
# Authorize
- before_filter :add_project_abilities
before_filter :authorize_read_project!
before_filter :authorize_code_access!
before_filter :require_non_empty_project
diff --git a/app/controllers/blob_controller.rb b/app/controllers/blob_controller.rb
index 33387842ec2..30069d19965 100644
--- a/app/controllers/blob_controller.rb
+++ b/app/controllers/blob_controller.rb
@@ -1,14 +1,9 @@
# Controller for viewing a file's blame
-class BlobController < ApplicationController
+class BlobController < ProjectResourceController
include ExtractsPath
include Gitlab::Encode
- layout "project"
-
- before_filter :project
-
# Authorize
- before_filter :add_project_abilities
before_filter :authorize_read_project!
before_filter :authorize_code_access!
before_filter :require_non_empty_project
diff --git a/app/controllers/commit_controller.rb b/app/controllers/commit_controller.rb
index de0d5b2ee7d..25a1f0fe708 100644
--- a/app/controllers/commit_controller.rb
+++ b/app/controllers/commit_controller.rb
@@ -1,12 +1,8 @@
# Controller for a specific Commit
#
# Not to be confused with CommitsController, plural.
-class CommitController < ApplicationController
- before_filter :project
- layout "project"
-
+class CommitController < ProjectResourceController
# Authorize
- before_filter :add_project_abilities
before_filter :authorize_read_project!
before_filter :authorize_code_access!
before_filter :require_non_empty_project
diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb
index bd67ee88adf..3b8ebdb5ddc 100644
--- a/app/controllers/commits_controller.rb
+++ b/app/controllers/commits_controller.rb
@@ -1,13 +1,9 @@
require "base64"
-class CommitsController < ApplicationController
- before_filter :project
- layout "project"
-
+class CommitsController < ProjectResourceController
include ExtractsPath
# Authorize
- before_filter :add_project_abilities
before_filter :authorize_read_project!
before_filter :authorize_code_access!
before_filter :require_non_empty_project
diff --git a/app/controllers/compare_controller.rb b/app/controllers/compare_controller.rb
index 62f968fd1ed..ae20f9c0ba6 100644
--- a/app/controllers/compare_controller.rb
+++ b/app/controllers/compare_controller.rb
@@ -1,9 +1,5 @@
-class CompareController < ApplicationController
- before_filter :project
- layout "project"
-
+class CompareController < ProjectResourceController
# Authorize
- before_filter :add_project_abilities
before_filter :authorize_read_project!
before_filter :authorize_code_access!
before_filter :require_non_empty_project
diff --git a/app/controllers/deploy_keys_controller.rb b/app/controllers/deploy_keys_controller.rb
index 82c10512a64..a89ebbcb8d5 100644
--- a/app/controllers/deploy_keys_controller.rb
+++ b/app/controllers/deploy_keys_controller.rb
@@ -1,16 +1,9 @@
-class DeployKeysController < ApplicationController
+class DeployKeysController < ProjectResourceController
respond_to :html
- layout "project"
- before_filter :project
# Authorize
- before_filter :add_project_abilities
before_filter :authorize_admin_project!
- def project
- @project ||= Project.find_by_code(params[:project_id])
- end
-
def index
@keys = @project.deploy_keys.all
end
diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb
index 9f60c64590e..e998d72365c 100644
--- a/app/controllers/errors_controller.rb
+++ b/app/controllers/errors_controller.rb
@@ -1,6 +1,4 @@
class ErrorsController < ApplicationController
- layout "error"
-
def githost
render "errors/gitolite"
end
diff --git a/app/controllers/hooks_controller.rb b/app/controllers/hooks_controller.rb
index 4359e99668f..b7d25e36252 100644
--- a/app/controllers/hooks_controller.rb
+++ b/app/controllers/hooks_controller.rb
@@ -1,9 +1,5 @@
-class HooksController < ApplicationController
- before_filter :project
- layout "project"
-
+class HooksController < ProjectResourceController
# Authorize
- before_filter :add_project_abilities
before_filter :authorize_read_project!
before_filter :authorize_admin_project!, only: [:new, :create, :destroy]
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb
index ceeee0096ab..82ae5b37deb 100644
--- a/app/controllers/issues_controller.rb
+++ b/app/controllers/issues_controller.rb
@@ -1,14 +1,8 @@
-class IssuesController < ApplicationController
- before_filter :project
+class IssuesController < ProjectResourceController
before_filter :module_enabled
before_filter :issue, only: [:edit, :update, :destroy, :show]
helper_method :issues_filter
- layout "project"
-
- # Authorize
- before_filter :add_project_abilities
-
# Allow read any issue
before_filter :authorize_read_issue!
diff --git a/app/controllers/labels_controller.rb b/app/controllers/labels_controller.rb
index 189d8d9866d..3cbbb8692e0 100644
--- a/app/controllers/labels_controller.rb
+++ b/app/controllers/labels_controller.rb
@@ -1,12 +1,6 @@
-class LabelsController < ApplicationController
- before_filter :project
+class LabelsController < ProjectResourceController
before_filter :module_enabled
- layout "project"
-
- # Authorize
- before_filter :add_project_abilities
-
# Allow read any issue
before_filter :authorize_read_issue!
diff --git a/app/controllers/merge_requests_controller.rb b/app/controllers/merge_requests_controller.rb
index 1d0da43f7c7..f8d84263688 100644
--- a/app/controllers/merge_requests_controller.rb
+++ b/app/controllers/merge_requests_controller.rb
@@ -1,13 +1,8 @@
-class MergeRequestsController < ApplicationController
- before_filter :project
+class MergeRequestsController < ProjectResourceController
before_filter :module_enabled
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 :define_show_vars, only: [:show, :diffs]
- layout "project"
-
- # Authorize
- before_filter :add_project_abilities
# Allow read any merge_request
before_filter :authorize_read_merge_request!
diff --git a/app/controllers/milestones_controller.rb b/app/controllers/milestones_controller.rb
index e8dbc8e49f1..68479a26923 100644
--- a/app/controllers/milestones_controller.rb
+++ b/app/controllers/milestones_controller.rb
@@ -1,11 +1,6 @@
-class MilestonesController < ApplicationController
- before_filter :project
+class MilestonesController < ProjectResourceController
before_filter :module_enabled
before_filter :milestone, only: [:edit, :update, :destroy, :show]
- layout "project"
-
- # Authorize
- before_filter :add_project_abilities
# Allow read any milestone
before_filter :authorize_read_milestone!
diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb
index f003ea7bf66..7f5f5cd2869 100644
--- a/app/controllers/notes_controller.rb
+++ b/app/controllers/notes_controller.rb
@@ -1,9 +1,5 @@
-class NotesController < ApplicationController
- before_filter :project
-
+class NotesController < ProjectResourceController
# Authorize
- before_filter :add_project_abilities
-
before_filter :authorize_read_note!
before_filter :authorize_write_note!, only: [:create]
diff --git a/app/controllers/profile_controller.rb b/app/controllers/profile_controller.rb
index 7ddbfe1128d..2b8e18f6286 100644
--- a/app/controllers/profile_controller.rb
+++ b/app/controllers/profile_controller.rb
@@ -1,5 +1,4 @@
class ProfileController < ApplicationController
- layout "profile"
before_filter :user
def show
diff --git a/app/controllers/project_resource_controller.rb b/app/controllers/project_resource_controller.rb
new file mode 100644
index 00000000000..d297bba635f
--- /dev/null
+++ b/app/controllers/project_resource_controller.rb
@@ -0,0 +1,5 @@
+class ProjectResourceController < ApplicationController
+ before_filter :project
+ # Authorize
+ before_filter :add_project_abilities
+end
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index b4d026f5568..13b264a4059 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -1,15 +1,15 @@
require Rails.root.join('lib', 'gitlab', 'graph_commit')
-class ProjectsController < ApplicationController
- before_filter :project, except: [:index, :new, :create]
- layout :determine_layout
+class ProjectsController < ProjectResourceController
+ skip_before_filter :project, only: [:new, :create]
# Authorize
- before_filter :add_project_abilities
before_filter :authorize_read_project!, except: [:index, :new, :create]
before_filter :authorize_admin_project!, only: [:edit, :update, :destroy]
before_filter :require_non_empty_project, only: [:blob, :tree, :graph]
+ layout 'application', only: [:new, :create]
+
def new
@project = Project.new
end
@@ -93,19 +93,4 @@ class ProjectsController < ApplicationController
format.html { redirect_to root_path }
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
diff --git a/app/controllers/protected_branches_controller.rb b/app/controllers/protected_branches_controller.rb
index 2556f0954d4..fd2734eff84 100644
--- a/app/controllers/protected_branches_controller.rb
+++ b/app/controllers/protected_branches_controller.rb
@@ -1,15 +1,10 @@
-class ProtectedBranchesController < ApplicationController
- before_filter :project
-
+class ProtectedBranchesController < ProjectResourceController
# Authorize
- before_filter :add_project_abilities
before_filter :authorize_read_project!
before_filter :require_non_empty_project
before_filter :authorize_admin_project!, only: [:destroy, :create]
- layout "project"
-
def index
@branches = @project.protected_branches.all
@protected_branch = @project.protected_branches.new
diff --git a/app/controllers/refs_controller.rb b/app/controllers/refs_controller.rb
index e92f45272d6..d3fc816bfd9 100644
--- a/app/controllers/refs_controller.rb
+++ b/app/controllers/refs_controller.rb
@@ -1,9 +1,7 @@
-class RefsController < ApplicationController
+class RefsController < ProjectResourceController
include Gitlab::Encode
- before_filter :project
# Authorize
- before_filter :add_project_abilities
before_filter :authorize_read_project!
before_filter :authorize_code_access!
before_filter :require_non_empty_project
@@ -11,11 +9,9 @@ class RefsController < ApplicationController
before_filter :ref
before_filter :define_tree_vars, only: [:blob, :logs_tree]
- layout "project"
-
- def switch
- respond_to do |format|
- format.html do
+ def switch
+ respond_to do |format|
+ format.html do
new_path = if params[:destination] == "tree"
project_tree_path(@project, @ref)
else
diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb
index 614582fa8fe..18b240e4550 100644
--- a/app/controllers/repositories_controller.rb
+++ b/app/controllers/repositories_controller.rb
@@ -1,14 +1,9 @@
-class RepositoriesController < ApplicationController
- before_filter :project
-
+class RepositoriesController < ProjectResourceController
# Authorize
- before_filter :add_project_abilities
before_filter :authorize_read_project!
before_filter :authorize_code_access!
before_filter :require_non_empty_project
- layout "project"
-
def show
@activities = @project.commits_with_refs(20)
end
diff --git a/app/controllers/snippets_controller.rb b/app/controllers/snippets_controller.rb
index a38fd52f262..7324a4594eb 100644
--- a/app/controllers/snippets_controller.rb
+++ b/app/controllers/snippets_controller.rb
@@ -1,10 +1,5 @@
-class SnippetsController < ApplicationController
- before_filter :project
+class SnippetsController < ProjectResourceController
before_filter :snippet, only: [:show, :edit, :destroy, :update, :raw]
- layout "project"
-
- # Authorize
- before_filter :add_project_abilities
# Allow read any snippet
before_filter :authorize_read_snippet!
diff --git a/app/controllers/team_members_controller.rb b/app/controllers/team_members_controller.rb
index a50dcd3eaeb..d0b699f61d5 100644
--- a/app/controllers/team_members_controller.rb
+++ b/app/controllers/team_members_controller.rb
@@ -1,9 +1,5 @@
-class TeamMembersController < ApplicationController
- before_filter :project
- layout "project"
-
+class TeamMembersController < ProjectResourceController
# Authorize
- before_filter :add_project_abilities
before_filter :authorize_read_project!
before_filter :authorize_admin_project!, except: [:index, :show]
diff --git a/app/controllers/tree_controller.rb b/app/controllers/tree_controller.rb
index e6313783d6e..2e4ff7d315b 100644
--- a/app/controllers/tree_controller.rb
+++ b/app/controllers/tree_controller.rb
@@ -1,13 +1,8 @@
# Controller for viewing a repository's file structure
-class TreeController < ApplicationController
+class TreeController < ProjectResourceController
include ExtractsPath
- layout "project"
-
- before_filter :project
-
# Authorize
- before_filter :add_project_abilities
before_filter :authorize_read_project!
before_filter :authorize_code_access!
before_filter :require_non_empty_project
diff --git a/app/controllers/wikis_controller.rb b/app/controllers/wikis_controller.rb
index 55ccfe72116..a93afe114df 100644
--- a/app/controllers/wikis_controller.rb
+++ b/app/controllers/wikis_controller.rb
@@ -1,10 +1,7 @@
-class WikisController < ApplicationController
- before_filter :project
- before_filter :add_project_abilities
+class WikisController < ProjectResourceController
before_filter :authorize_read_wiki!
before_filter :authorize_write_wiki!, only: [:edit, :create, :history]
before_filter :authorize_admin_wiki!, only: :destroy
- layout "project"
def pages
@wikis = @project.wikis.group(:slug).order("created_at")
diff --git a/app/views/layouts/error.html.haml b/app/views/layouts/errors.html.haml
index 1f5c03bdced..1f5c03bdced 100644
--- a/app/views/layouts/error.html.haml
+++ b/app/views/layouts/errors.html.haml
diff --git a/app/views/layouts/project.html.haml b/app/views/layouts/project_resource.html.haml
index b1dbe41ce65..b1dbe41ce65 100644
--- a/app/views/layouts/project.html.haml
+++ b/app/views/layouts/project_resource.html.haml