2018-09-26 03:45:43 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-01-23 14:14:20 +00:00
|
|
|
class Projects::ApplicationController < ApplicationController
|
2018-08-30 20:39:56 +00:00
|
|
|
include CookiesHelper
|
2017-05-01 20:46:30 +00:00
|
|
|
include RoutableActions
|
2018-04-06 14:02:36 +00:00
|
|
|
include ChecksCollaboration
|
2017-05-01 20:46:30 +00:00
|
|
|
|
2016-03-20 20:03:53 +00:00
|
|
|
skip_before_action :authenticate_user!
|
2016-03-21 23:09:20 +00:00
|
|
|
before_action :project
|
|
|
|
before_action :repository
|
2015-04-30 17:06:18 +00:00
|
|
|
layout 'project'
|
2013-09-24 12:58:39 +00:00
|
|
|
|
2018-02-28 08:06:18 +00:00
|
|
|
helper_method :repository, :can_collaborate_with_project?, :user_access
|
2016-03-20 20:03:53 +00:00
|
|
|
|
2019-05-23 04:33:11 +00:00
|
|
|
rescue_from Gitlab::Template::Finders::RepoTemplateFinder::FileNotFoundError do |exception|
|
|
|
|
log_exception(exception)
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
|
2016-03-20 20:03:53 +00:00
|
|
|
private
|
|
|
|
|
2017-05-04 21:20:13 +00:00
|
|
|
def project
|
2017-05-05 17:48:01 +00:00
|
|
|
return @project if @project
|
2019-02-08 12:19:53 +00:00
|
|
|
return unless params[:project_id] || params[:id]
|
2017-05-05 17:48:01 +00:00
|
|
|
|
|
|
|
path = File.join(params[:namespace_id], params[:project_id] || params[:id])
|
2017-05-04 21:20:13 +00:00
|
|
|
|
2021-08-19 15:10:29 +00:00
|
|
|
@project = find_routable!(Project, path, request.fullpath, extra_authorization_proc: auth_proc)
|
2016-03-20 20:03:53 +00:00
|
|
|
end
|
|
|
|
|
2022-02-23 09:12:16 +00:00
|
|
|
def auth_proc
|
|
|
|
->(project) { !project.pending_delete? }
|
|
|
|
end
|
|
|
|
|
2022-05-03 00:08:25 +00:00
|
|
|
def authorize_read_build_trace!
|
|
|
|
return if can?(current_user, :read_build_trace, build)
|
|
|
|
|
|
|
|
if build.debug_mode?
|
|
|
|
access_denied!(
|
|
|
|
_('You must have developer or higher permissions in the associated project to view job logs when debug trace ' \
|
|
|
|
"is enabled. To disable debug trace, set the 'CI_DEBUG_TRACE' variable to 'false' in your pipeline " \
|
|
|
|
'configuration or CI/CD settings. If you need to view this job log, a project maintainer must add you to ' \
|
|
|
|
'the project with developer permissions or higher.')
|
|
|
|
)
|
|
|
|
else
|
|
|
|
access_denied!(_('The current user is not authorized to access the job log.'))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-18 23:23:05 +00:00
|
|
|
def build_canonical_path(project)
|
|
|
|
params[:namespace_id] = project.namespace.to_param
|
|
|
|
params[:project_id] = project.to_param
|
|
|
|
|
2018-04-28 10:35:16 +00:00
|
|
|
url_for(safe_params)
|
2017-05-18 23:23:05 +00:00
|
|
|
end
|
|
|
|
|
2016-03-20 20:03:53 +00:00
|
|
|
def repository
|
|
|
|
@repository ||= project.repository
|
|
|
|
end
|
|
|
|
|
2017-05-05 11:24:07 +00:00
|
|
|
def authorize_action!(action)
|
|
|
|
unless can?(current_user, action, project)
|
2020-07-11 00:09:17 +00:00
|
|
|
access_denied!
|
2017-05-05 11:24:07 +00:00
|
|
|
end
|
2016-03-20 20:03:53 +00:00
|
|
|
end
|
|
|
|
|
2017-06-20 10:59:50 +00:00
|
|
|
def check_project_feature_available!(feature)
|
2017-06-20 11:13:04 +00:00
|
|
|
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)
|
2017-06-20 10:59:50 +00:00
|
|
|
end
|
|
|
|
|
2016-03-20 20:03:53 +00:00
|
|
|
def method_missing(method_sym, *arguments, &block)
|
2017-06-20 10:59:50 +00:00
|
|
|
case method_sym.to_s
|
|
|
|
when /\Aauthorize_(.*)!\z/
|
2020-09-03 09:08:20 +00:00
|
|
|
authorize_action!(Regexp.last_match(1).to_sym)
|
2017-06-20 10:59:50 +00:00
|
|
|
when /\Acheck_(.*)_available!\z/
|
2020-09-03 09:08:20 +00:00
|
|
|
check_project_feature_available!(Regexp.last_match(1).to_sym)
|
2016-03-20 20:03:53 +00:00
|
|
|
else
|
|
|
|
super
|
2013-09-24 12:58:39 +00:00
|
|
|
end
|
2016-03-20 20:03:53 +00:00
|
|
|
end
|
2013-09-24 12:58:39 +00:00
|
|
|
|
2016-03-20 20:03:53 +00:00
|
|
|
def require_non_empty_project
|
2016-04-07 04:10:24 +00:00
|
|
|
# Be sure to return status code 303 to avoid a double DELETE:
|
|
|
|
# http://api.rubyonrails.org/classes/ActionController/Redirecting.html
|
2018-07-02 10:43:06 +00:00
|
|
|
redirect_to project_path(@project), status: :see_other if @project.empty_repo?
|
2013-09-24 12:58:39 +00:00
|
|
|
end
|
|
|
|
|
2013-11-05 10:21:11 +00:00
|
|
|
def require_branch_head
|
2016-06-20 13:38:54 +00:00
|
|
|
unless @repository.branch_exists?(@ref)
|
2015-01-24 18:02:58 +00:00
|
|
|
redirect_to(
|
2017-06-29 17:06:35 +00:00
|
|
|
project_tree_path(@project, @ref),
|
2015-12-08 21:30:40 +00:00
|
|
|
notice: "This action is not allowed unless you are on a branch"
|
2015-01-24 18:02:58 +00:00
|
|
|
)
|
2013-11-05 10:21:11 +00:00
|
|
|
end
|
|
|
|
end
|
2015-09-24 07:44:38 +00:00
|
|
|
|
2017-04-07 03:27:35 +00:00
|
|
|
def require_pages_enabled!
|
2017-08-29 10:15:19 +00:00
|
|
|
not_found unless @project.pages_available?
|
2017-04-07 03:27:35 +00:00
|
|
|
end
|
2018-01-08 09:06:25 +00:00
|
|
|
|
|
|
|
def check_issues_available!
|
|
|
|
return render_404 unless @project.feature_available?(:issues, current_user)
|
|
|
|
end
|
2013-01-23 14:14:20 +00:00
|
|
|
end
|
2022-02-23 09:12:16 +00:00
|
|
|
|
|
|
|
Projects::ApplicationController.prepend_mod_with('Projects::ApplicationController')
|