summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorCyril <jv.cyril@gmail.com>2012-09-26 01:21:37 +0200
committerCyril <jv.cyril@gmail.com>2012-09-26 22:27:43 +0200
commit078a8f0e662a1626b53bbf7f7c3e2b0599c94810 (patch)
treebc650d9d1fb9d5934ae09f98d9d3ba7619dfb224 /app
parent0439387be00bfb862b4454000f805f11fb8cc389 (diff)
downloadgitlab-ce-078a8f0e662a1626b53bbf7f7c3e2b0599c94810.tar.gz
factorize before_filters and layout for projects related controllers
Diffstat (limited to 'app')
-rw-r--r--app/controllers/application_controller.rb2
-rw-r--r--app/controllers/commits_controller.rb6
-rw-r--r--app/controllers/deploy_keys_controller.rb9
-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/project_controller.rb16
-rw-r--r--app/controllers/projects_controller.rb21
-rw-r--r--app/controllers/protected_branches_controller.rb7
-rw-r--r--app/controllers/refs_controller.rb6
-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/wikis_controller.rb5
17 files changed, 33 insertions, 101 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 5ac5c639f39..9ea11daf2bb 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -76,7 +76,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
diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb
index 1e7aec005f1..c79784d6b18 100644
--- a/app/controllers/commits_controller.rb
+++ b/app/controllers/commits_controller.rb
@@ -1,11 +1,7 @@
require "base64"
-class CommitsController < ApplicationController
- before_filter :project
- layout "project"
-
+class CommitsController < ProjectController
# 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..29f924e80d1 100644
--- a/app/controllers/deploy_keys_controller.rb
+++ b/app/controllers/deploy_keys_controller.rb
@@ -1,16 +1,9 @@
-class DeployKeysController < ApplicationController
+class DeployKeysController < ProjectController
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/hooks_controller.rb b/app/controllers/hooks_controller.rb
index 4359e99668f..23b81194eb9 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 < ProjectController
# 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..114a6a19828 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 < ProjectController
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..203bff56a71 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 < ProjectController
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..db6e48d5e09 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 < ProjectController
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..19baf531eb9 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 < ProjectController
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..138d5170bf6 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 < ProjectController
# Authorize
- before_filter :add_project_abilities
-
before_filter :authorize_read_note!
before_filter :authorize_write_note!, only: [:create]
diff --git a/app/controllers/project_controller.rb b/app/controllers/project_controller.rb
new file mode 100644
index 00000000000..84c81ce2a17
--- /dev/null
+++ b/app/controllers/project_controller.rb
@@ -0,0 +1,16 @@
+class ProjectController < ApplicationController
+ before_filter :project
+ # Authorize
+ before_filter :add_project_abilities
+
+ layout :determine_layout
+
+ protected
+ def determine_layout
+ if @project && !@project.new_record?
+ 'project'
+ else
+ 'application'
+ end
+ end
+end
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index b4d026f5568..2a11611e84b 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -1,11 +1,9 @@
require Rails.root.join('lib', 'gitlab', 'graph_commit')
-class ProjectsController < ApplicationController
- before_filter :project, except: [:index, :new, :create]
- layout :determine_layout
+class ProjectsController < ProjectController
+ 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]
@@ -93,19 +91,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 78c9c9effa6..7675d3eb899 100644
--- a/app/controllers/protected_branches_controller.rb
+++ b/app/controllers/protected_branches_controller.rb
@@ -1,16 +1,11 @@
-class ProtectedBranchesController < ApplicationController
- before_filter :project
-
+class ProtectedBranchesController < ProjectController
# 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]
before_filter :render_full_content
- 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 9036143779c..0139c09c548 100644
--- a/app/controllers/refs_controller.rb
+++ b/app/controllers/refs_controller.rb
@@ -1,11 +1,9 @@
require 'github/markup'
-class RefsController < ApplicationController
+class RefsController < ProjectController
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
@@ -14,8 +12,6 @@ class RefsController < ApplicationController
before_filter :define_tree_vars, only: [:tree, :blob, :blame, :logs_tree]
before_filter :render_full_content
- layout "project"
-
def switch
respond_to do |format|
format.html do
diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb
index cd20677e1ad..5f55ee432c3 100644
--- a/app/controllers/repositories_controller.rb
+++ b/app/controllers/repositories_controller.rb
@@ -1,15 +1,10 @@
-class RepositoriesController < ApplicationController
- before_filter :project
-
+class RepositoriesController < ProjectController
# Authorize
- before_filter :add_project_abilities
before_filter :authorize_read_project!
before_filter :authorize_code_access!
before_filter :require_non_empty_project
before_filter :render_full_content
- 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 b00c9283694..3d404e67a86 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 < ProjectController
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..8261acfec52 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 < ProjectController
# Authorize
- before_filter :add_project_abilities
before_filter :authorize_read_project!
before_filter :authorize_admin_project!, except: [:index, :show]
diff --git a/app/controllers/wikis_controller.rb b/app/controllers/wikis_controller.rb
index 55ccfe72116..f13d072439f 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 < ProjectController
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")