diff --git a/app/controllers/blame_controller.rb b/app/controllers/blame_controller.rb index e3fb69b..37d7245 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 30c704f..30069d1 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 3e1595f..25a1f0f 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 81a9e90..3b8ebdb 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 96c5c7e..ae20f9c 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 29f924e..a89ebbc 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 23b8119..b7d25e3 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 114a6a1..82ae5b3 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 203bff5..3cbbb86 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 db6e48d..f8d8426 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 19baf53..68479a2 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 138d517..7f5f5cd 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_controller.rb deleted file mode 100644 index de4f317..0000000 --- a/app/controllers/project_controller.rb +++ /dev/null @@ -1,5 +0,0 @@ -class ProjectController < ApplicationController - before_filter :project - # Authorize - before_filter :add_project_abilities -end diff --git a/app/controllers/project_resource_controller.rb b/app/controllers/project_resource_controller.rb new file mode 100644 index 0000000..d297bba --- /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 81c267a..13b264a 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 e91c78b..fd2734e 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 9c585c9..d3fc816 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 ef72e2e..18b240e 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 03e5cc7..7324a45 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 8261acf..d0b699f 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 4d5c409..2e4ff7d 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 f13d072..a93afe1 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.html.haml deleted file mode 100644 index b1dbe41..0000000 --- a/app/views/layouts/project.html.haml +++ /dev/null @@ -1,41 +0,0 @@ -!!! 5 -%html{ lang: "en"} - = render "layouts/head" - %body{class: "#{app_theme} project"} - = render "layouts/flash" - = render "layouts/head_panel", title: @project.name - .container - %ul.main_menu - = nav_link(html_options: {class: "home #{project_tab_class}"}) do - = link_to @project.code, project_path(@project), title: "Project" - - - if @project.repo_exists? - - if can? current_user, :download_code, @project - = nav_link(controller: %w(tree blob blame)) do - = link_to 'Files', project_tree_path(@project, @ref || @project.root_ref) - = nav_link(controller: %w(commit commits compare repositories protected_branches)) do - = link_to "Commits", project_commits_path(@project, @ref || @project.root_ref) - = nav_link(path: 'projects#graph') do - = link_to "Network", graph_project_path(@project) - - - if @project.issues_enabled - = nav_link(controller: %w(issues milestones labels)) do - = link_to project_issues_filter_path(@project) do - Issues - %span.count.issue_counter= @project.issues.opened.count - - - if @project.repo_exists? && @project.merge_requests_enabled - = nav_link(controller: :merge_requests) do - = link_to project_merge_requests_path(@project) do - Merge Requests - %span.count.merge_counter= @project.merge_requests.opened.count - - - if @project.wall_enabled - = nav_link(path: 'projects#wall') do - = link_to 'Wall', wall_project_path(@project) - - - if @project.wiki_enabled - = nav_link(controller: :wikis) do - = link_to 'Wiki', project_wiki_path(@project, :index) - - .content= yield diff --git a/app/views/layouts/project_resource.html.haml b/app/views/layouts/project_resource.html.haml new file mode 100644 index 0000000..b1dbe41 --- /dev/null +++ b/app/views/layouts/project_resource.html.haml @@ -0,0 +1,41 @@ +!!! 5 +%html{ lang: "en"} + = render "layouts/head" + %body{class: "#{app_theme} project"} + = render "layouts/flash" + = render "layouts/head_panel", title: @project.name + .container + %ul.main_menu + = nav_link(html_options: {class: "home #{project_tab_class}"}) do + = link_to @project.code, project_path(@project), title: "Project" + + - if @project.repo_exists? + - if can? current_user, :download_code, @project + = nav_link(controller: %w(tree blob blame)) do + = link_to 'Files', project_tree_path(@project, @ref || @project.root_ref) + = nav_link(controller: %w(commit commits compare repositories protected_branches)) do + = link_to "Commits", project_commits_path(@project, @ref || @project.root_ref) + = nav_link(path: 'projects#graph') do + = link_to "Network", graph_project_path(@project) + + - if @project.issues_enabled + = nav_link(controller: %w(issues milestones labels)) do + = link_to project_issues_filter_path(@project) do + Issues + %span.count.issue_counter= @project.issues.opened.count + + - if @project.repo_exists? && @project.merge_requests_enabled + = nav_link(controller: :merge_requests) do + = link_to project_merge_requests_path(@project) do + Merge Requests + %span.count.merge_counter= @project.merge_requests.opened.count + + - if @project.wall_enabled + = nav_link(path: 'projects#wall') do + = link_to 'Wall', wall_project_path(@project) + + - if @project.wiki_enabled + = nav_link(controller: :wikis) do + = link_to 'Wiki', project_wiki_path(@project, :index) + + .content= yield -- libgit2 0.21.2