2018-09-25 23:45:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-01-23 09:14:20 -05:00
|
|
|
class Projects::ApplicationController < ApplicationController
|
2018-08-30 16:39:56 -04:00
|
|
|
include CookiesHelper
|
2017-05-01 16:46:30 -04:00
|
|
|
include RoutableActions
|
2018-04-06 10:02:36 -04:00
|
|
|
include ChecksCollaboration
|
2017-05-01 16:46:30 -04:00
|
|
|
|
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'
|
2013-09-24 08:58:39 -04:00
|
|
|
|
2018-02-28 03:06:18 -05:00
|
|
|
helper_method :repository, :can_collaborate_with_project?, :user_access
|
2016-03-20 16:03:53 -04:00
|
|
|
|
2019-05-23 00:33:11 -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
|
|
|
|
|
2017-05-04 17:20:13 -04:00
|
|
|
def project
|
2017-05-05 13:48:01 -04:00
|
|
|
return @project if @project
|
2019-02-08 07:19:53 -05:00
|
|
|
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])
|
2017-05-04 17:20:13 -04:00
|
|
|
|
2021-08-19 11:10:29 -04:00
|
|
|
@project = find_routable!(Project, path, request.fullpath, extra_authorization_proc: auth_proc)
|
2016-03-20 16:03:53 -04:00
|
|
|
end
|
|
|
|
|
2022-02-23 04:12:16 -05:00
|
|
|
def auth_proc
|
|
|
|
->(project) { !project.pending_delete? }
|
|
|
|
end
|
|
|
|
|
2017-05-18 19:23:05 -04:00
|
|
|
def build_canonical_path(project)
|
|
|
|
params[:namespace_id] = project.namespace.to_param
|
|
|
|
params[:project_id] = project.to_param
|
|
|
|
|
2018-04-28 06:35:16 -04:00
|
|
|
url_for(safe_params)
|
2017-05-18 19:23:05 -04:00
|
|
|
end
|
|
|
|
|
2016-03-20 16:03:53 -04:00
|
|
|
def repository
|
|
|
|
@repository ||= project.repository
|
|
|
|
end
|
|
|
|
|
2017-05-05 07:24:07 -04:00
|
|
|
def authorize_action!(action)
|
|
|
|
unless can?(current_user, action, project)
|
2020-07-10 20:09:17 -04:00
|
|
|
access_denied!
|
2017-05-05 07:24:07 -04:00
|
|
|
end
|
2016-03-20 16:03:53 -04:00
|
|
|
end
|
|
|
|
|
2017-06-20 06:59:50 -04:00
|
|
|
def check_project_feature_available!(feature)
|
2017-06-20 07:13:04 -04: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 06:59:50 -04:00
|
|
|
end
|
|
|
|
|
2016-03-20 16:03:53 -04:00
|
|
|
def method_missing(method_sym, *arguments, &block)
|
2017-06-20 06:59:50 -04:00
|
|
|
case method_sym.to_s
|
|
|
|
when /\Aauthorize_(.*)!\z/
|
2020-09-03 05:08:20 -04:00
|
|
|
authorize_action!(Regexp.last_match(1).to_sym)
|
2017-06-20 06:59:50 -04:00
|
|
|
when /\Acheck_(.*)_available!\z/
|
2020-09-03 05:08:20 -04:00
|
|
|
check_project_feature_available!(Regexp.last_match(1).to_sym)
|
2016-03-20 16:03:53 -04:00
|
|
|
else
|
|
|
|
super
|
2013-09-24 08:58:39 -04:00
|
|
|
end
|
2016-03-20 16:03:53 -04:00
|
|
|
end
|
2013-09-24 08:58:39 -04:00
|
|
|
|
2016-03-20 16:03:53 -04:00
|
|
|
def require_non_empty_project
|
2016-04-07 00:10:24 -04:00
|
|
|
# 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?
|
2013-09-24 08:58:39 -04:00
|
|
|
end
|
|
|
|
|
2013-11-05 05:21:11 -05:00
|
|
|
def require_branch_head
|
2016-06-20 09:38:54 -04:00
|
|
|
unless @repository.branch_exists?(@ref)
|
2015-01-24 13:02:58 -05:00
|
|
|
redirect_to(
|
2017-06-29 13:06:35 -04:00
|
|
|
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"
|
2015-01-24 13:02:58 -05:00
|
|
|
)
|
2013-11-05 05:21:11 -05:00
|
|
|
end
|
|
|
|
end
|
2015-09-24 03:44:38 -04:00
|
|
|
|
2017-04-06 23:27:35 -04:00
|
|
|
def require_pages_enabled!
|
2017-08-29 06:15:19 -04:00
|
|
|
not_found unless @project.pages_available?
|
2017-04-06 23:27:35 -04:00
|
|
|
end
|
2018-01-08 04:06:25 -05:00
|
|
|
|
|
|
|
def check_issues_available!
|
|
|
|
return render_404 unless @project.feature_available?(:issues, current_user)
|
|
|
|
end
|
2013-01-23 09:14:20 -05:00
|
|
|
end
|
2022-02-23 04:12:16 -05:00
|
|
|
|
|
|
|
Projects::ApplicationController.prepend_mod_with('Projects::ApplicationController')
|