Commit 7d279f9302151e3c8f4c5df9c5200a72799409b9
1 parent
9e6d0710
Exists in
master
and in
4 other branches
better error handling for not found resource, gitolite error
Showing
9 changed files
with
73 additions
and
7 deletions
Show diff stats
app/controllers/application_controller.rb
... | ... | @@ -5,7 +5,11 @@ class ApplicationController < ActionController::Base |
5 | 5 | helper_method :abilities, :can? |
6 | 6 | |
7 | 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 | 13 | end |
10 | 14 | |
11 | 15 | layout :layout_by_resource |
... | ... | @@ -33,7 +37,8 @@ class ApplicationController < ActionController::Base |
33 | 37 | end |
34 | 38 | |
35 | 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 | 42 | end |
38 | 43 | |
39 | 44 | def add_project_abilities |
... | ... | @@ -45,15 +50,23 @@ class ApplicationController < ActionController::Base |
45 | 50 | end |
46 | 51 | |
47 | 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 | 54 | end |
50 | 55 | |
51 | 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 | 58 | end |
54 | 59 | |
55 | 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 | 70 | end |
58 | 71 | |
59 | 72 | def method_missing(method_sym, *arguments, &block) | ... | ... |
app/controllers/commits_controller.rb
... | ... | @@ -26,6 +26,9 @@ class CommitsController < ApplicationController |
26 | 26 | |
27 | 27 | def show |
28 | 28 | @commit = project.commit(params[:id]) |
29 | + | |
30 | + git_not_found! and return unless @commit | |
31 | + | |
29 | 32 | @notes = project.commit_notes(@commit).fresh.limit(20) |
30 | 33 | @note = @project.build_commit_note(@commit) |
31 | 34 | ... | ... |
app/controllers/errors_controller.rb
app/controllers/merge_requests_controller.rb
... | ... | @@ -36,7 +36,7 @@ class MergeRequestsController < ApplicationController |
36 | 36 | def show |
37 | 37 | unless @project.repo.heads.map(&:name).include?(@merge_request.target_branch) && |
38 | 38 | @project.repo.heads.map(&:name).include?(@merge_request.source_branch) |
39 | - head(404)and return | |
39 | + git_not_found! and return | |
40 | 40 | end |
41 | 41 | |
42 | 42 | @notes = @merge_request.notes.inc_author.order("created_at DESC").limit(20) | ... | ... |
... | ... | @@ -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/ | ... | ... |