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

88 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
2018-05-09 12:01:36 +05:30
include ChecksCollaboration
2017-08-17 22:00:37 +05:30
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
2018-03-27 19:54:05 +05:30
helper_method :repository, :can_collaborate_with_project?, :user_access
2016-06-02 11:05:42 +05:30
private
def project
2017-08-17 22:00:37 +05:30
return @project if @project
2017-09-10 17:25:29 +05:30
return nil unless params[:project_id] || params[:id]
2017-08-17 22:00:37 +05:30
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
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
2017-09-10 17:25:29 +05:30
def check_project_feature_available!(feature)
render_404 unless project.feature_available?(feature, current_user)
end
def check_issuables_available!
render_404 unless project.feature_available?(:issues, current_user) ||
project.feature_available?(:merge_requests, current_user)
end
2016-06-02 11:05:42 +05:30
def method_missing(method_sym, *arguments, &block)
2017-09-10 17:25:29 +05:30
case method_sym.to_s
when /\Aauthorize_(.*)!\z/
2017-08-17 22:00:37 +05:30
authorize_action!($1.to_sym)
2017-09-10 17:25:29 +05:30
when /\Acheck_(.*)_available!\z/
check_project_feature_available!($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
2017-09-10 17:25:29 +05:30
redirect_to project_path(@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(
2017-09-10 17:25:29 +05:30
project_tree_path(@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
2017-08-17 22:00:37 +05:30
def require_pages_enabled!
2018-03-17 18:26:18 +05:30
not_found unless @project.pages_available?
end
def check_issues_available!
return render_404 unless @project.feature_available?(:issues, current_user)
2017-08-17 22:00:37 +05:30
end
2014-09-02 18:07:02 +05:30
end