debian-mirror-gitlab/app/controllers/projects/application_controller.rb

91 lines
2.3 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
class Projects::ApplicationController < ApplicationController
2017-08-17 22:00:37 +05:30
include RoutableActions
2016-06-02 11:05:42 +05:30
skip_before_action :authenticate_user!
2017-08-17 22:00:37 +05:30
before_action :redirect_git_extension
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
2017-08-17 22:00:37 +05:30
def redirect_git_extension
# Redirect from
# localhost/group/project.git
# to
# localhost/group/project
#
redirect_to url_for(params.merge(format: nil)) if params[:format] == 'git'
end
2016-06-02 11:05:42 +05:30
def project
2017-08-17 22:00:37 +05:30
return @project if @project
path = File.join(params[:namespace_id], params[:project_id] || params[:id])
auth_proc = ->(project) { !project.pending_delete? }
2016-06-02 11:05:42 +05:30
2017-08-17 22:00:37 +05:30
@project = find_routable!(Project, path, extra_authorization_proc: auth_proc)
end
def build_canonical_path(project)
params[:namespace_id] = project.namespace.to_param
params[:project_id] = project.to_param
url_for(params)
2016-06-02 11:05:42 +05:30
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-08-17 22:00:37 +05:30
def authorize_action!(action)
unless can?(current_user, action, project)
return access_denied!
end
2016-06-02 11:05:42 +05:30
end
def method_missing(method_sym, *arguments, &block)
if method_sym.to_s =~ /\Aauthorize_(.*)!\z/
2017-08-17 22:00:37 +05:30
authorize_action!($1.to_sym)
2016-06-02 11:05:42 +05:30
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-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
2017-08-17 22:00:37 +05:30
def require_pages_enabled!
not_found unless Gitlab.config.pages.enabled
end
2014-09-02 18:07:02 +05:30
end