Commit 7d279f9302151e3c8f4c5df9c5200a72799409b9

Authored by Dmitriy Zaporozhets
1 parent 9e6d0710

better error handling for not found resource, gitolite error

app/controllers/application_controller.rb
@@ -5,7 +5,11 @@ class ApplicationController < ActionController::Base @@ -5,7 +5,11 @@ class ApplicationController < ActionController::Base
5 helper_method :abilities, :can? 5 helper_method :abilities, :can?
6 6
7 rescue_from Gitlabhq::Gitolite::AccessDenied do |exception| 7 rescue_from Gitlabhq::Gitolite::AccessDenied do |exception|
8 - render :file => File.join(Rails.root, "public", "githost_error"), :layout => false 8 + render "errors/gitolite", :layout => "error"
  9 + end
  10 +
  11 + rescue_from ActiveRecord::RecordNotFound do |exception|
  12 + render "errors/not_found", :layout => "error"
9 end 13 end
10 14
11 layout :layout_by_resource 15 layout :layout_by_resource
@@ -33,7 +37,8 @@ class ApplicationController < ActionController::Base @@ -33,7 +37,8 @@ class ApplicationController < ActionController::Base
33 end 37 end
34 38
35 def project 39 def project
36 - @project ||= Project.find_by_code(params[:project_id]) 40 + @project ||= current_user.projects.find_by_code(params[:project_id])
  41 + @project || render_404
37 end 42 end
38 43
39 def add_project_abilities 44 def add_project_abilities
@@ -45,15 +50,23 @@ class ApplicationController < ActionController::Base @@ -45,15 +50,23 @@ class ApplicationController < ActionController::Base
45 end 50 end
46 51
47 def authorize_project!(action) 52 def authorize_project!(action)
48 - return render_404 unless can?(current_user, action, project) 53 + return access_denied! unless can?(current_user, action, project)
49 end 54 end
50 55
51 def authorize_code_access! 56 def authorize_code_access!
52 - return render_404 unless can?(current_user, :download_code, project) 57 + return access_denied! unless can?(current_user, :download_code, project)
53 end 58 end
54 59
55 def access_denied! 60 def access_denied!
56 - render_404 61 + render "errors/access_denied", :layout => "error"
  62 + end
  63 +
  64 + def not_found!
  65 + render "errors/not_found", :layout => "error"
  66 + end
  67 +
  68 + def git_not_found!
  69 + render "errors/git_not_found", :layout => "error"
57 end 70 end
58 71
59 def method_missing(method_sym, *arguments, &block) 72 def method_missing(method_sym, *arguments, &block)
app/controllers/commits_controller.rb
@@ -26,6 +26,9 @@ class CommitsController < ApplicationController @@ -26,6 +26,9 @@ class CommitsController < ApplicationController
26 26
27 def show 27 def show
28 @commit = project.commit(params[:id]) 28 @commit = project.commit(params[:id])
  29 +
  30 + git_not_found! and return unless @commit
  31 +
29 @notes = project.commit_notes(@commit).fresh.limit(20) 32 @notes = project.commit_notes(@commit).fresh.limit(20)
30 @note = @project.build_commit_note(@commit) 33 @note = @project.build_commit_note(@commit)
31 34
app/controllers/errors_controller.rb
1 class ErrorsController < ApplicationController 1 class ErrorsController < ApplicationController
  2 + layout "error"
  3 +
2 def githost 4 def githost
3 - render :file => File.join(Rails.root, "public", "githost_error"), :layout => false 5 + render "errors/gitolite"
4 end 6 end
5 end 7 end
app/controllers/merge_requests_controller.rb
@@ -36,7 +36,7 @@ class MergeRequestsController &lt; ApplicationController @@ -36,7 +36,7 @@ class MergeRequestsController &lt; ApplicationController
36 def show 36 def show
37 unless @project.repo.heads.map(&:name).include?(@merge_request.target_branch) && 37 unless @project.repo.heads.map(&:name).include?(@merge_request.target_branch) &&
38 @project.repo.heads.map(&:name).include?(@merge_request.source_branch) 38 @project.repo.heads.map(&:name).include?(@merge_request.source_branch)
39 - head(404)and return 39 + git_not_found! and return
40 end 40 end
41 41
42 @notes = @merge_request.notes.inc_author.order("created_at DESC").limit(20) 42 @notes = @merge_request.notes.inc_author.order("created_at DESC").limit(20)
app/views/errors/access_denied.html.haml 0 → 100644
@@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
  1 +.alert-message.block-message.error
  2 + %h3 Access Denied
  3 + %hr
  4 + %p Youre not allowed to access this page
  5 + %p Ream more about project permissions #{link_to "here", help_permissions_path, :class => "vlink"}
app/views/errors/git_not_found.html.haml 0 → 100644
@@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
  1 +.alert-message.block-message.error
  2 + %h3 Git Resource Not found
  3 + %hr
  4 + %p
  5 + Application cant get access to some
  6 + %span.label branch
  7 + or
  8 + %span.label commit
  9 + in your repository. Maybe it was moved
app/views/errors/gitolite.html.haml 0 → 100644
@@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
  1 +.alert-message.block-message.error
  2 + %h3 Gitolite Error
  3 + %hr
  4 + %h4 Application cant get access to your gitolite system.
  5 + %ol
  6 + %li
  7 + %p
  8 + Check 'config/gitlab.yml' for correct settings.
  9 + %li
  10 + %p
  11 + Make sure web server user has access to gitolite.
  12 + %a{:href => "https://github.com/gitlabhq/gitlabhq/wiki/Gitolite"} Setup tutorial
  13 + %li
  14 + %p
  15 + Try:
  16 + %pre
  17 + sudo chmod -R 770 /home/git/repositories/
  18 + sudo chown -R git:git /home/git/repositories/
app/views/errors/not_found.html.haml 0 → 100644
@@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
  1 +.alert-message.block-message.error
  2 + %h3 Not found
  3 + %hr
  4 + %p Resource you were looking for doesn't exist.
  5 + %P You may have mistyped the address or it was removed.
app/views/layouts/error.html.haml 0 → 100644
@@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
  1 +!!! 5
  2 +%html{ :lang => "en"}
  3 + = render "layouts/head"
  4 + %body.application
  5 + = render "layouts/flash"
  6 + = render "layouts/head_panel", :title => ""
  7 + .container
  8 + %nav.main_menu
  9 + = render "layouts/const_menu_links"
  10 + .content
  11 + %h3= yield