gitlab-org--gitlab-foss/app/controllers/projects/application_controller.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

97 lines
2.5 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
class Projects::ApplicationController < ApplicationController
include CookiesHelper
include RoutableActions
include ChecksCollaboration
2016-03-20 16:03:53 -04:00
skip_before_action :authenticate_user!
2016-03-21 19:09:20 -04:00
before_action :project
before_action :repository
2015-04-30 13:06:18 -04:00
layout 'project'
helper_method :repository, :can_collaborate_with_project?, :user_access
2016-03-20 16:03:53 -04:00
rescue_from Gitlab::Template::Finders::RepoTemplateFinder::FileNotFoundError do |exception|
log_exception(exception)
render_404
end
2016-03-20 16:03:53 -04:00
private
def project
2017-05-05 13:48:01 -04:00
return @project if @project
return unless params[:project_id] || params[:id]
2017-05-05 13:48:01 -04:00
path = File.join(params[:namespace_id], params[:project_id] || params[:id])
@project = find_routable!(Project, path, request.fullpath, extra_authorization_proc: auth_proc)
2016-03-20 16:03:53 -04:00
end
def auth_proc
->(project) { !project.pending_delete? }
end
def build_canonical_path(project)
params[:namespace_id] = project.namespace.to_param
params[:project_id] = project.to_param
url_for(safe_params)
end
2016-03-20 16:03:53 -04:00
def repository
@repository ||= project.repository
end
def authorize_action!(action)
unless can?(current_user, action, project)
access_denied!
end
2016-03-20 16:03:53 -04:00
end
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-03-20 16:03:53 -04:00
def method_missing(method_sym, *arguments, &block)
case method_sym.to_s
when /\Aauthorize_(.*)!\z/
authorize_action!(Regexp.last_match(1).to_sym)
when /\Acheck_(.*)_available!\z/
check_project_feature_available!(Regexp.last_match(1).to_sym)
2016-03-20 16:03:53 -04:00
else
super
end
2016-03-20 16:03:53 -04:00
end
2016-03-20 16:03:53 -04:00
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
2018-07-02 06:43:06 -04:00
redirect_to project_path(@project), status: :see_other if @project.empty_repo?
end
def require_branch_head
2016-06-20 09:38:54 -04:00
unless @repository.branch_exists?(@ref)
redirect_to(
project_tree_path(@project, @ref),
2015-12-08 16:30:40 -05:00
notice: "This action is not allowed unless you are on a branch"
)
end
end
def require_pages_enabled!
not_found unless @project.pages_available?
end
def check_issues_available!
return render_404 unless @project.feature_available?(:issues, current_user)
end
end
Projects::ApplicationController.prepend_mod_with('Projects::ApplicationController')