From 078a8f0e662a1626b53bbf7f7c3e2b0599c94810 Mon Sep 17 00:00:00 2001 From: Cyril Date: Wed, 26 Sep 2012 01:21:37 +0200 Subject: [PATCH 1/4] factorize before_filters and layout for projects related controllers --- app/controllers/application_controller.rb | 2 +- app/controllers/commits_controller.rb | 6 +----- app/controllers/deploy_keys_controller.rb | 9 +------- app/controllers/hooks_controller.rb | 6 +----- app/controllers/issues_controller.rb | 8 +------ app/controllers/labels_controller.rb | 8 +------ app/controllers/merge_requests_controller.rb | 7 +------ app/controllers/milestones_controller.rb | 7 +------ app/controllers/notes_controller.rb | 6 +----- app/controllers/project_controller.rb | 16 ++++++++++++++ app/controllers/projects_controller.rb | 21 ++----------------- .../protected_branches_controller.rb | 7 +------ app/controllers/refs_controller.rb | 6 +----- app/controllers/repositories_controller.rb | 7 +------ app/controllers/snippets_controller.rb | 7 +------ app/controllers/team_members_controller.rb | 6 +----- app/controllers/wikis_controller.rb | 5 +---- 17 files changed, 33 insertions(+), 101 deletions(-) create mode 100644 app/controllers/project_controller.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5ac5c639f398..9ea11daf2bbb 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -76,7 +76,7 @@ def can?(object, action, subject) 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 1e7aec005f15..c79784d6b185 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 82c10512a643..29f924e80d1e 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 4359e99668f2..23b81194eb96 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 ceeee0096abc..114a6a198284 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 189d8d9866db..203bff56a71b 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 1d0da43f7c70..db6e48d5e094 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 e8dbc8e49f1b..19baf531eb99 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 f003ea7bf66c..138d5170bf66 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 000000000000..84c81ce2a171 --- /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 b4d026f55682..2a11611e84b4 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 @@ def destroy 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 78c9c9effa68..7675d3eb8992 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 9036143779c9..0139c09c5489 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 cd20677e1ad3..5f55ee432c3e 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 b00c92836944..3d404e67a860 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 a50dcd3eaeb9..8261acfec521 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 55ccfe721161..f13d072439ff 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") From bdf317addc2ae586c76f46ccb1aa8659513baf16 Mon Sep 17 00:00:00 2001 From: Cyril Date: Wed, 26 Sep 2012 22:24:52 +0200 Subject: [PATCH 2/4] layout selected by controller name --- app/controllers/application_controller.rb | 22 +++++-------------- app/controllers/errors_controller.rb | 2 -- app/controllers/profile_controller.rb | 1 - app/controllers/project_controller.rb | 11 ---------- app/controllers/projects_controller.rb | 2 ++ .../{error.html.haml => errors.html.haml} | 0 config/application.rb | 4 ++++ 7 files changed, 12 insertions(+), 30 deletions(-) rename app/views/layouts/{error.html.haml => errors.html.haml} (100%) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9ea11daf2bbb..a299a83b96ec 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -11,19 +11,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 check_token_auth @@ -51,14 +49,6 @@ def after_sign_in_path_for resource 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 @@ -93,15 +83,15 @@ def authorize_code_access! 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/errors_controller.rb b/app/controllers/errors_controller.rb index 9f60c64590ef..e998d72365c7 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/profile_controller.rb b/app/controllers/profile_controller.rb index 7ddbfe1128dd..2b8e18f6286a 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_controller.rb b/app/controllers/project_controller.rb index 84c81ce2a171..de4f317a7bd5 100644 --- a/app/controllers/project_controller.rb +++ b/app/controllers/project_controller.rb @@ -2,15 +2,4 @@ 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 2a11611e84b4..81c267a8ede1 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -8,6 +8,8 @@ class ProjectsController < ProjectController 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 diff --git a/app/views/layouts/error.html.haml b/app/views/layouts/errors.html.haml similarity index 100% rename from app/views/layouts/error.html.haml rename to app/views/layouts/errors.html.haml diff --git a/config/application.rb b/config/application.rb index 27de3fa2436b..fd0dd019ca14 100644 --- a/config/application.rb +++ b/config/application.rb @@ -53,5 +53,9 @@ class Application < Rails::Application # Add fonts config.assets.paths << "#{Rails.root}/app/assets/fonts" + + config.to_prepare do + Devise::SessionsController.layout 'devise_layout' + end end end From 933c5e414600d5e0170213db574ba6431c1444e4 Mon Sep 17 00:00:00 2001 From: Cyril Date: Thu, 27 Sep 2012 13:44:53 +0200 Subject: [PATCH 3/4] update new controllers --- app/controllers/blame_controller.rb | 7 +------ app/controllers/blob_controller.rb | 7 +------ app/controllers/commit_controller.rb | 6 +----- app/controllers/compare_controller.rb | 6 +----- app/controllers/tree_controller.rb | 7 +------ 5 files changed, 5 insertions(+), 28 deletions(-) diff --git a/app/controllers/blame_controller.rb b/app/controllers/blame_controller.rb index dd0837ea9ab5..e3fb69b5f6b7 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 < ProjectController 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 33387842ec2b..30c704f22aed 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 < ProjectController 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 de0d5b2ee7d0..3e1595f169fe 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 < 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/compare_controller.rb b/app/controllers/compare_controller.rb index 62f968fd1ed4..96c5c7e1b01a 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 < 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/tree_controller.rb b/app/controllers/tree_controller.rb index e6313783d6ef..4d5c409d42c4 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 < ProjectController 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 From be18397d82ca16fefed7287c8078a9b41bf37c95 Mon Sep 17 00:00:00 2001 From: Cyril Date: Thu, 27 Sep 2012 20:59:42 +0200 Subject: [PATCH 4/4] rename ProjectController to ProjectResourceController --- app/controllers/blame_controller.rb | 2 +- app/controllers/blob_controller.rb | 2 +- app/controllers/commit_controller.rb | 2 +- app/controllers/commits_controller.rb | 2 +- app/controllers/compare_controller.rb | 2 +- app/controllers/deploy_keys_controller.rb | 2 +- app/controllers/hooks_controller.rb | 2 +- app/controllers/issues_controller.rb | 2 +- app/controllers/labels_controller.rb | 2 +- app/controllers/merge_requests_controller.rb | 2 +- app/controllers/milestones_controller.rb | 2 +- app/controllers/notes_controller.rb | 2 +- .../{project_controller.rb => project_resource_controller.rb} | 2 +- app/controllers/projects_controller.rb | 2 +- app/controllers/protected_branches_controller.rb | 2 +- app/controllers/refs_controller.rb | 2 +- app/controllers/repositories_controller.rb | 2 +- app/controllers/snippets_controller.rb | 2 +- app/controllers/team_members_controller.rb | 2 +- app/controllers/tree_controller.rb | 2 +- app/controllers/wikis_controller.rb | 2 +- .../layouts/{project.html.haml => project_resource.html.haml} | 0 22 files changed, 21 insertions(+), 21 deletions(-) rename app/controllers/{project_controller.rb => project_resource_controller.rb} (59%) rename app/views/layouts/{project.html.haml => project_resource.html.haml} (100%) diff --git a/app/controllers/blame_controller.rb b/app/controllers/blame_controller.rb index e3fb69b5f6b7..37d7245ccb4a 100644 --- a/app/controllers/blame_controller.rb +++ b/app/controllers/blame_controller.rb @@ -1,5 +1,5 @@ # Controller for viewing a file's blame -class BlameController < ProjectController +class BlameController < ProjectResourceController include ExtractsPath # Authorize diff --git a/app/controllers/blob_controller.rb b/app/controllers/blob_controller.rb index 30c704f22aed..30069d199654 100644 --- a/app/controllers/blob_controller.rb +++ b/app/controllers/blob_controller.rb @@ -1,5 +1,5 @@ # Controller for viewing a file's blame -class BlobController < ProjectController +class BlobController < ProjectResourceController include ExtractsPath include Gitlab::Encode diff --git a/app/controllers/commit_controller.rb b/app/controllers/commit_controller.rb index 3e1595f169fe..25a1f0fe7080 100644 --- a/app/controllers/commit_controller.rb +++ b/app/controllers/commit_controller.rb @@ -1,7 +1,7 @@ # Controller for a specific Commit # # Not to be confused with CommitsController, plural. -class CommitController < ProjectController +class CommitController < ProjectResourceController # Authorize before_filter :authorize_read_project! before_filter :authorize_code_access! diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb index 81a9e90d0623..3b8ebdb5ddcf 100644 --- a/app/controllers/commits_controller.rb +++ b/app/controllers/commits_controller.rb @@ -1,6 +1,6 @@ require "base64" -class CommitsController < ProjectController +class CommitsController < ProjectResourceController include ExtractsPath # Authorize diff --git a/app/controllers/compare_controller.rb b/app/controllers/compare_controller.rb index 96c5c7e1b01a..ae20f9c0ba6d 100644 --- a/app/controllers/compare_controller.rb +++ b/app/controllers/compare_controller.rb @@ -1,4 +1,4 @@ -class CompareController < ProjectController +class CompareController < ProjectResourceController # Authorize before_filter :authorize_read_project! before_filter :authorize_code_access! diff --git a/app/controllers/deploy_keys_controller.rb b/app/controllers/deploy_keys_controller.rb index 29f924e80d1e..a89ebbcb8d54 100644 --- a/app/controllers/deploy_keys_controller.rb +++ b/app/controllers/deploy_keys_controller.rb @@ -1,4 +1,4 @@ -class DeployKeysController < ProjectController +class DeployKeysController < ProjectResourceController respond_to :html # Authorize diff --git a/app/controllers/hooks_controller.rb b/app/controllers/hooks_controller.rb index 23b81194eb96..b7d25e362520 100644 --- a/app/controllers/hooks_controller.rb +++ b/app/controllers/hooks_controller.rb @@ -1,4 +1,4 @@ -class HooksController < ProjectController +class HooksController < ProjectResourceController # Authorize 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 114a6a198284..82ae5b37deb2 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -1,4 +1,4 @@ -class IssuesController < ProjectController +class IssuesController < ProjectResourceController before_filter :module_enabled before_filter :issue, only: [:edit, :update, :destroy, :show] helper_method :issues_filter diff --git a/app/controllers/labels_controller.rb b/app/controllers/labels_controller.rb index 203bff56a71b..3cbbb8692e01 100644 --- a/app/controllers/labels_controller.rb +++ b/app/controllers/labels_controller.rb @@ -1,4 +1,4 @@ -class LabelsController < ProjectController +class LabelsController < ProjectResourceController before_filter :module_enabled # Allow read any issue diff --git a/app/controllers/merge_requests_controller.rb b/app/controllers/merge_requests_controller.rb index db6e48d5e094..f8d842636880 100644 --- a/app/controllers/merge_requests_controller.rb +++ b/app/controllers/merge_requests_controller.rb @@ -1,4 +1,4 @@ -class MergeRequestsController < ProjectController +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] diff --git a/app/controllers/milestones_controller.rb b/app/controllers/milestones_controller.rb index 19baf531eb99..68479a269238 100644 --- a/app/controllers/milestones_controller.rb +++ b/app/controllers/milestones_controller.rb @@ -1,4 +1,4 @@ -class MilestonesController < ProjectController +class MilestonesController < ProjectResourceController before_filter :module_enabled before_filter :milestone, only: [:edit, :update, :destroy, :show] diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 138d5170bf66..7f5f5cd28696 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -1,4 +1,4 @@ -class NotesController < ProjectController +class NotesController < ProjectResourceController # Authorize before_filter :authorize_read_note! before_filter :authorize_write_note!, only: [:create] diff --git a/app/controllers/project_controller.rb b/app/controllers/project_resource_controller.rb similarity index 59% rename from app/controllers/project_controller.rb rename to app/controllers/project_resource_controller.rb index de4f317a7bd5..d297bba635fa 100644 --- a/app/controllers/project_controller.rb +++ b/app/controllers/project_resource_controller.rb @@ -1,4 +1,4 @@ -class ProjectController < ApplicationController +class ProjectResourceController < ApplicationController before_filter :project # Authorize before_filter :add_project_abilities diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 81c267a8ede1..13b264a40594 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -1,6 +1,6 @@ require Rails.root.join('lib', 'gitlab', 'graph_commit') -class ProjectsController < ProjectController +class ProjectsController < ProjectResourceController skip_before_filter :project, only: [:new, :create] # Authorize diff --git a/app/controllers/protected_branches_controller.rb b/app/controllers/protected_branches_controller.rb index e91c78bdd35f..fd2734eff849 100644 --- a/app/controllers/protected_branches_controller.rb +++ b/app/controllers/protected_branches_controller.rb @@ -1,4 +1,4 @@ -class ProtectedBranchesController < ProjectController +class ProtectedBranchesController < ProjectResourceController # Authorize before_filter :authorize_read_project! before_filter :require_non_empty_project diff --git a/app/controllers/refs_controller.rb b/app/controllers/refs_controller.rb index 9c585c9373b3..d3fc816bfd9a 100644 --- a/app/controllers/refs_controller.rb +++ b/app/controllers/refs_controller.rb @@ -1,4 +1,4 @@ -class RefsController < ProjectController +class RefsController < ProjectResourceController include Gitlab::Encode # Authorize diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index ef72e2e9f025..18b240e45504 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -1,4 +1,4 @@ -class RepositoriesController < ProjectController +class RepositoriesController < ProjectResourceController # Authorize before_filter :authorize_read_project! before_filter :authorize_code_access! diff --git a/app/controllers/snippets_controller.rb b/app/controllers/snippets_controller.rb index 03e5cc73ce37..7324a4594ebb 100644 --- a/app/controllers/snippets_controller.rb +++ b/app/controllers/snippets_controller.rb @@ -1,4 +1,4 @@ -class SnippetsController < ProjectController +class SnippetsController < ProjectResourceController before_filter :snippet, only: [:show, :edit, :destroy, :update, :raw] # Allow read any snippet diff --git a/app/controllers/team_members_controller.rb b/app/controllers/team_members_controller.rb index 8261acfec521..d0b699f61d5b 100644 --- a/app/controllers/team_members_controller.rb +++ b/app/controllers/team_members_controller.rb @@ -1,4 +1,4 @@ -class TeamMembersController < ProjectController +class TeamMembersController < ProjectResourceController # Authorize 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 4d5c409d42c4..2e4ff7d315bc 100644 --- a/app/controllers/tree_controller.rb +++ b/app/controllers/tree_controller.rb @@ -1,5 +1,5 @@ # Controller for viewing a repository's file structure -class TreeController < ProjectController +class TreeController < ProjectResourceController include ExtractsPath # Authorize diff --git a/app/controllers/wikis_controller.rb b/app/controllers/wikis_controller.rb index f13d072439ff..a93afe114df6 100644 --- a/app/controllers/wikis_controller.rb +++ b/app/controllers/wikis_controller.rb @@ -1,4 +1,4 @@ -class WikisController < ProjectController +class WikisController < ProjectResourceController before_filter :authorize_read_wiki! before_filter :authorize_write_wiki!, only: [:edit, :create, :history] before_filter :authorize_admin_wiki!, only: :destroy diff --git a/app/views/layouts/project.html.haml b/app/views/layouts/project_resource.html.haml similarity index 100% rename from app/views/layouts/project.html.haml rename to app/views/layouts/project_resource.html.haml