| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
class ApplicationController < ActionController::Base |
| 5 |
|
| 6 |
session :session_key => '_ks1_session_id', :secret => GitlabConfig["cookie_secret"] |
| 7 |
include AuthenticatedSystem |
| 8 |
include ExceptionNotifiable |
| 9 |
|
| 10 |
rescue_from ActiveRecord::RecordNotFound, :with => :render_not_found |
| 11 |
rescue_from ActionController::UnknownController, :with => :render_not_found |
| 12 |
rescue_from ActionController::UnknownAction, :with => :render_not_found |
| 13 |
|
| 14 |
def rescue_action(exception) |
| 15 |
return super if RAILS_ENV != "production" |
| 16 |
|
| 17 |
case exception |
| 18 |
|
| 19 |
|
| 20 |
when ActionController::RoutingError |
| 21 |
render_not_found |
| 22 |
else |
| 23 |
super |
| 24 |
end |
| 25 |
end |
| 26 |
|
| 27 |
protected |
| 28 |
|
| 29 |
def require_user_has_ssh_keys |
| 30 |
unless current_user.ssh_keys.count > 0 |
| 31 |
flash[:error] = "You need to upload your public key first" |
| 32 |
redirect_to new_account_key_path |
| 33 |
return |
| 34 |
end |
| 35 |
end |
| 36 |
|
| 37 |
def find_project |
| 38 |
project_slug = params[:project_id] ? params[:project_id] : params[:id] |
| 39 |
@project = Project.find_by_slug(project_slug, current_user) |
| 40 |
if @project |
| 41 |
@is_member = Member.is_member?(@project.id, current_user.id) if logged_in? |
| 42 |
else |
| 43 |
|
| 44 |
if params[:project_id] |
| 45 |
flash[:error] = "Project not found." |
| 46 |
redirect_to root_path |
| 47 |
end |
| 48 |
end |
| 49 |
end |
| 50 |
|
| 51 |
def find_project_and_repository |
| 52 |
find_project |
| 53 |
@repository = @project.repositories.find_by_name!(params[:repository_id]) |
| 54 |
end |
| 55 |
|
| 56 |
def check_repository_for_commits |
| 57 |
unless @repository.has_commits? |
| 58 |
flash[:notice] = "The repository doesn't have any commits yet" |
| 59 |
redirect_to project_repository_path(@project, @repository) and return |
| 60 |
end |
| 61 |
end |
| 62 |
|
| 63 |
def render_not_found |
| 64 |
render :file => "#{RAILS_ROOT}/public/ac_404.html", :status => 404 |
| 65 |
end |
| 66 |
|
| 67 |
def authorised |
| 68 |
unless @is_member |
| 69 |
flash[:error] = "Access denied." |
| 70 |
redirect_to root_path |
| 71 |
end |
| 72 |
end |
| 73 |
|
| 74 |
end |