2014-09-02 18:07:02 +05:30
|
|
|
class Projects::ApplicationController < ApplicationController
|
2016-06-02 11:05:42 +05:30
|
|
|
skip_before_action :authenticate_user!
|
2015-09-11 14:41:01 +05:30
|
|
|
before_action :project
|
|
|
|
before_action :repository
|
|
|
|
layout 'project'
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
helper_method :repository, :can_collaborate_with_project?
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def project
|
|
|
|
unless @project
|
|
|
|
namespace = params[:namespace_id]
|
2014-09-02 18:07:02 +05:30
|
|
|
id = params[:project_id] || params[:id]
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
# Redirect from
|
|
|
|
# localhost/group/project.git
|
|
|
|
# to
|
|
|
|
# localhost/group/project
|
|
|
|
#
|
|
|
|
if id =~ /\.git\Z/
|
|
|
|
redirect_to request.original_url.gsub(/\.git\/?\Z/, '')
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
project_path = "#{namespace}/#{id}"
|
|
|
|
@project = Project.find_with_namespace(project_path)
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
if can?(current_user, :read_project, @project) && !@project.pending_delete?
|
2016-06-02 11:05:42 +05:30
|
|
|
if @project.path_with_namespace != project_path
|
|
|
|
redirect_to request.original_url.gsub(project_path, @project.path_with_namespace)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
@project = nil
|
|
|
|
|
|
|
|
if current_user.nil?
|
|
|
|
authenticate_user!
|
|
|
|
else
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@project
|
|
|
|
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
|
|
|
|
|
|
|
|
def authorize_project!(action)
|
|
|
|
return access_denied! unless can?(current_user, action, project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def method_missing(method_sym, *arguments, &block)
|
|
|
|
if method_sym.to_s =~ /\Aauthorize_(.*)!\z/
|
|
|
|
authorize_project!($1.to_sym)
|
|
|
|
else
|
|
|
|
super
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
def require_non_empty_project
|
|
|
|
# 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?
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def require_branch_head
|
2016-06-22 15:30:34 +05:30
|
|
|
unless @repository.branch_exists?(@ref)
|
2015-04-26 12:48:37 +05:30
|
|
|
redirect_to(
|
|
|
|
namespace_project_tree_path(@project.namespace, @project, @ref),
|
2015-12-23 02:04:40 +05:30
|
|
|
notice: "This action is not allowed unless you are on a branch"
|
2015-04-26 12:48:37 +05:30
|
|
|
)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
2015-10-24 18:46:33 +05:30
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
def apply_diff_view_cookie!
|
2016-09-13 17:45:13 +05:30
|
|
|
@show_changes_tab = params[:view].present?
|
2016-06-02 11:05:42 +05:30
|
|
|
cookies.permanent[:diff_view] = params.delete(:view) if params[:view].present?
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
def builds_enabled
|
2016-09-29 09:46:39 +05:30
|
|
|
return render_404 unless @project.feature_available?(:builds, current_user)
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|