Blob of app/controllers/application.rb (raw blob data)

1 # Filters added to this controller apply to all controllers in the application.
2 # Likewise, all the methods added will be available for all controllers.
3
4 class ApplicationController < ActionController::Base
5 session :session_key => '_ks1_session_id', :secret => GitoriousConfig["cookie_secret"]
6 include AuthenticatedSystem
7 include ExceptionNotifiable
8
9 rescue_from ActiveRecord::RecordNotFound, :with => :render_not_found
10 rescue_from ActionController::UnknownController, :with => :render_not_found
11 rescue_from ActionController::UnknownAction, :with => :render_not_found
12
13 def rescue_action(exception)
14 return super if RAILS_ENV != "production"
15
16 case exception
17 # Can't catch RoutingError with rescue_from it seems,
18 # so do it the old-fashioned way
19 when ActionController::RoutingError
20 render_not_found
21 else
22 super
23 end
24 end
25
26 protected
27 def require_user_has_ssh_keys
28 unless current_user.ssh_keys.count > 0
29 flash[:error] = "You need to upload your public key first"
30 redirect_to new_account_key_path
31 return
32 end
33 end
34
35 def find_project
36 @project = Project.find_by_slug!(params[:project_id])
37 end
38
39 def find_project_and_repository
40 @project = Project.find_by_slug!(params[:project_id])
41 @repository = @project.repositories.find_by_name!(params[:repository_id])
42 end
43
44 def check_repository_for_commits
45 unless @repository.has_commits?
46 flash[:notice] = "The repository doesn't have any commits yet"
47 redirect_to project_repository_path(@project, @repository) and return
48 end
49 end
50
51 def render_not_found
52 render :file => "#{RAILS_ROOT}/public/404.html", :status => 404
53 end
54 end