2013-01-23 09:14:20 -05:00
|
|
|
class Projects::ApplicationController < ApplicationController
|
2017-05-01 16:46:30 -04:00
|
|
|
include RoutableActions
|
|
|
|
|
2016-03-20 16:03:53 -04:00
|
|
|
skip_before_action :authenticate_user!
|
2017-05-04 17:20:13 -04:00
|
|
|
before_action :redirect_git_extension
|
2016-03-21 19:09:20 -04:00
|
|
|
before_action :project
|
|
|
|
before_action :repository
|
2015-04-30 13:06:18 -04:00
|
|
|
layout 'project'
|
2013-09-24 08:58:39 -04:00
|
|
|
|
2016-03-20 16:03:53 -04:00
|
|
|
helper_method :repository, :can_collaborate_with_project?
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-05-04 17:20:13 -04:00
|
|
|
def redirect_git_extension
|
|
|
|
# Redirect from
|
|
|
|
# localhost/group/project.git
|
|
|
|
# to
|
|
|
|
# localhost/group/project
|
|
|
|
#
|
2017-05-04 20:06:01 -04:00
|
|
|
redirect_to url_for(params.merge(format: nil)) if params[:format] == 'git'
|
2017-05-04 17:20:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def project
|
2017-05-05 13:48:01 -04:00
|
|
|
return @project if @project
|
|
|
|
|
|
|
|
path = File.join(params[:namespace_id], params[:project_id] || params[:id])
|
|
|
|
auth_proc = ->(project) { !project.pending_delete? }
|
2017-05-04 17:20:13 -04:00
|
|
|
|
2017-05-05 13:48:01 -04:00
|
|
|
@project = find_routable!(Project, path, extra_authorization_proc: auth_proc)
|
2016-03-20 16:03:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def repository
|
|
|
|
@repository ||= project.repository
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_collaborate_with_project?(project = nil)
|
|
|
|
project ||= @project
|
|
|
|
|
|
|
|
can?(current_user, :push_code, project) ||
|
|
|
|
(current_user && current_user.already_forked?(project))
|
|
|
|
end
|
|
|
|
|
2017-05-05 07:24:07 -04:00
|
|
|
def authorize_action!(action)
|
|
|
|
unless can?(current_user, action, project)
|
|
|
|
return access_denied!
|
|
|
|
end
|
2016-03-20 16:03:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def method_missing(method_sym, *arguments, &block)
|
|
|
|
if method_sym.to_s =~ /\Aauthorize_(.*)!\z/
|
2017-05-05 07:24:07 -04:00
|
|
|
authorize_action!($1.to_sym)
|
2016-03-20 16:03:53 -04:00
|
|
|
else
|
|
|
|
super
|
2013-09-24 08:58:39 -04:00
|
|
|
end
|
2016-03-20 16:03:53 -04:00
|
|
|
end
|
2013-09-24 08:58:39 -04:00
|
|
|
|
2016-03-20 16:03:53 -04:00
|
|
|
def require_non_empty_project
|
2016-04-07 00:10:24 -04:00
|
|
|
# Be sure to return status code 303 to avoid a double DELETE:
|
|
|
|
# http://api.rubyonrails.org/classes/ActionController/Redirecting.html
|
|
|
|
redirect_to namespace_project_path(@project.namespace, @project), status: 303 if @project.empty_repo?
|
2013-09-24 08:58:39 -04:00
|
|
|
end
|
|
|
|
|
2013-11-05 05:21:11 -05:00
|
|
|
def require_branch_head
|
2016-06-20 09:38:54 -04:00
|
|
|
unless @repository.branch_exists?(@ref)
|
2015-01-24 13:02:58 -05:00
|
|
|
redirect_to(
|
|
|
|
namespace_project_tree_path(@project.namespace, @project, @ref),
|
2015-12-08 16:30:40 -05:00
|
|
|
notice: "This action is not allowed unless you are on a branch"
|
2015-01-24 13:02:58 -05:00
|
|
|
)
|
2013-11-05 05:21:11 -05:00
|
|
|
end
|
|
|
|
end
|
2015-09-24 03:44:38 -04:00
|
|
|
|
2015-10-22 21:52:17 -04:00
|
|
|
def apply_diff_view_cookie!
|
2016-04-18 14:13:38 -04:00
|
|
|
cookies.permanent[:diff_view] = params.delete(:view) if params[:view].present?
|
2015-10-22 21:52:17 -04:00
|
|
|
end
|
|
|
|
|
2015-12-08 06:55:38 -05:00
|
|
|
def builds_enabled
|
2016-08-01 18:31:21 -04:00
|
|
|
return render_404 unless @project.feature_available?(:builds, current_user)
|
2015-09-24 03:44:38 -04:00
|
|
|
end
|
2017-04-06 23:27:35 -04:00
|
|
|
|
|
|
|
def require_pages_enabled!
|
|
|
|
not_found unless Gitlab.config.pages.enabled
|
|
|
|
end
|
2013-01-23 09:14:20 -05:00
|
|
|
end
|