debian-mirror-gitlab/app/controllers/projects_controller.rb

560 lines
17 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2016-06-02 11:05:42 +05:30
class ProjectsController < Projects::ApplicationController
2018-11-20 20:47:30 +05:30
include API::Helpers::RelatedResourcesHelpers
2016-11-03 12:29:30 +05:30
include IssuableCollections
2015-11-26 14:37:03 +05:30
include ExtractsPath
2018-03-17 18:26:18 +05:30
include PreviewMarkdown
2018-11-08 19:23:39 +05:30
include SendFileUpload
2019-03-02 22:35:43 +05:30
include RecordUserLastActivity
2019-07-31 22:56:46 +05:30
include ImportUrlParams
2020-07-28 23:09:34 +05:30
include FiltersEvents
2015-11-26 14:37:03 +05:30
2018-11-29 20:51:05 +05:30
prepend_before_action(only: [:show]) { authenticate_sessionless_user!(:rss) }
2019-07-07 11:18:12 +05:30
around_action :allow_gitaly_ref_name_caching, only: [:index, :show]
2021-04-29 21:17:54 +05:30
before_action :disable_query_limiting, only: [:show, :create]
2021-01-29 00:20:46 +05:30
before_action :authenticate_user!, except: [:index, :show, :activity, :refs, :resolve, :unfoldered_environment_names]
2018-03-17 18:26:18 +05:30
before_action :redirect_git_extension, only: [:show]
2019-03-02 22:35:43 +05:30
before_action :project, except: [:index, :new, :create, :resolve]
before_action :repository, except: [:index, :new, :create, :resolve]
2021-09-30 23:02:18 +05:30
before_action :verify_git_import_enabled, only: [:create]
2018-03-17 18:26:18 +05:30
before_action :project_export_enabled, only: [:export, :download_export, :remove_export, :generate_new_export]
2018-11-08 19:23:39 +05:30
before_action :present_project, only: [:edit]
2019-01-03 12:48:30 +05:30
before_action :authorize_download_code!, only: [:refs]
2014-09-02 18:07:02 +05:30
# Authorize
2016-06-22 15:30:34 +05:30
before_action :authorize_admin_project!, only: [:edit, :update, :housekeeping, :download_export, :export, :remove_export, :generate_new_export]
2019-12-04 20:38:33 +05:30
before_action :authorize_archive_project!, only: [:archive, :unarchive]
2015-09-11 14:41:01 +05:30
before_action :event_filter, only: [:show, :activity]
2014-09-02 18:07:02 +05:30
2020-01-01 13:55:28 +05:30
# Project Export Rate Limit
before_action :export_rate_limit, only: [:export, :download_export, :generate_new_export]
2021-04-29 21:17:54 +05:30
before_action do
2021-11-18 22:05:49 +05:30
push_frontend_feature_flag(:lazy_load_commits, @project, default_enabled: :yaml)
2021-04-29 21:17:54 +05:30
push_frontend_feature_flag(:refactor_blob_viewer, @project, default_enabled: :yaml)
2021-11-18 22:05:49 +05:30
push_frontend_feature_flag(:refactor_text_viewer, @project, default_enabled: :yaml)
2021-09-30 23:02:18 +05:30
push_frontend_feature_flag(:increase_page_size_exponentially, @project, default_enabled: :yaml)
2021-11-11 11:23:49 +05:30
push_frontend_feature_flag(:paginated_tree_graphql_query, @project, default_enabled: :yaml)
2021-11-18 22:05:49 +05:30
push_frontend_feature_flag(:new_dir_modal, @project, default_enabled: :yaml)
2021-09-04 01:27:46 +05:30
end
2015-09-11 14:41:01 +05:30
layout :determine_layout
2014-09-02 18:07:02 +05:30
2021-01-03 14:25:43 +05:30
feature_category :projects, [
:index, :show, :new, :create, :edit, :update, :transfer,
2021-06-08 01:23:25 +05:30
:destroy, :resolve, :archive, :unarchive, :toggle_star, :activity
2021-01-03 14:25:43 +05:30
]
feature_category :source_code_management, [:remove_fork, :housekeeping, :refs]
feature_category :issue_tracking, [:preview_markdown, :new_issuable_address]
feature_category :importers, [:export, :remove_export, :generate_new_export, :download_export]
feature_category :code_review, [:unfoldered_environment_names]
2015-09-25 12:07:36 +05:30
def index
redirect_to(current_user ? root_path : explore_root_path)
end
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2014-09-02 18:07:02 +05:30
def new
2019-07-31 22:56:46 +05:30
@namespace = Namespace.find_by(id: params[:namespace_id]) if params[:namespace_id]
return access_denied! if @namespace && !can?(current_user, :create_projects, @namespace)
2018-03-17 18:26:18 +05:30
2019-07-31 22:56:46 +05:30
@project = Project.new(namespace_id: @namespace&.id)
2014-09-02 18:07:02 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2014-09-02 18:07:02 +05:30
def edit
2020-04-08 14:13:33 +05:30
@badge_api_endpoint = expose_path(api_v4_projects_badges_path(id: @project.id))
2020-03-13 15:44:24 +05:30
render_edit
2014-09-02 18:07:02 +05:30
end
def create
2019-04-03 18:18:56 +05:30
@project = ::Projects::CreateService.new(current_user, project_params(attributes: project_params_create_attributes)).execute
2014-09-02 18:07:02 +05:30
2015-04-26 12:48:37 +05:30
if @project.saved?
2021-11-18 22:05:49 +05:30
experiment(:new_project_sast_enabled, user: current_user).track(:created,
property: active_new_project_tab,
checked: Gitlab::Utils.to_boolean(project_params[:initialize_with_sast]),
project: @project,
namespace: @project.namespace
)
2015-04-26 12:48:37 +05:30
redirect_to(
2018-03-27 19:54:05 +05:30
project_path(@project, custom_import_params),
2017-09-10 17:25:29 +05:30
notice: _("Project '%{project_name}' was successfully created.") % { project_name: @project.name }
2015-04-26 12:48:37 +05:30
)
else
2021-06-08 01:23:25 +05:30
render 'new'
2014-09-02 18:07:02 +05:30
end
end
def update
2017-08-17 22:00:37 +05:30
result = ::Projects::UpdateService.new(@project, current_user, project_params).execute
2014-09-02 18:07:02 +05:30
2016-06-02 11:05:42 +05:30
# Refresh the repo in case anything changed
2017-08-17 22:00:37 +05:30
@repository = @project.repository
2016-06-02 11:05:42 +05:30
2021-04-17 20:07:23 +05:30
if result[:status] == :success
flash[:notice] = _("Project '%{project_name}' was successfully updated.") % { project_name: @project.name }
redirect_to(edit_project_path(@project, anchor: 'js-general-project-settings'))
else
flash[:alert] = result[:message]
@project.reset
render 'edit'
2014-09-02 18:07:02 +05:30
end
end
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2014-09-02 18:07:02 +05:30
def transfer
2015-11-26 14:37:03 +05:30
return access_denied! unless can?(current_user, :change_namespace, @project)
2015-09-11 14:41:01 +05:30
namespace = Namespace.find_by(id: params[:new_namespace_id])
::Projects::TransferService.new(project, current_user).execute(namespace)
if @project.errors[:new_namespace].present?
flash[:alert] = @project.errors[:new_namespace].first
end
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2015-09-11 14:41:01 +05:30
2015-11-26 14:37:03 +05:30
def remove_fork
return access_denied! unless can?(current_user, :remove_fork_project, @project)
2016-06-02 11:05:42 +05:30
if ::Projects::UnlinkForkService.new(@project, current_user).execute
2017-09-10 17:25:29 +05:30
flash[:notice] = _('The fork relationship has been removed.')
2015-11-26 14:37:03 +05:30
end
end
2015-09-11 14:41:01 +05:30
def activity
respond_to do |format|
format.html
format.json do
load_events
2020-02-01 01:16:34 +05:30
pager_json('events/_events', @events.count { |event| event.visible_to_user?(current_user) })
2015-09-11 14:41:01 +05:30
end
2015-04-26 12:48:37 +05:30
end
2014-09-02 18:07:02 +05:30
end
def show
2021-02-22 17:27:13 +05:30
@id, @ref, @path = extract_ref_path
2014-09-02 18:07:02 +05:30
if @project.import_in_progress?
2018-03-27 19:54:05 +05:30
redirect_to project_import_path(@project, custom_import_params)
2014-09-02 18:07:02 +05:30
return
end
2016-04-02 18:10:28 +05:30
if @project.pending_delete?
2017-09-10 17:25:29 +05:30
flash.now[:alert] = _("Project '%{project_name}' queued for deletion.") % { project_name: @project.name }
2016-04-02 18:10:28 +05:30
end
2014-09-02 18:07:02 +05:30
respond_to do |format|
format.html do
2016-06-02 11:05:42 +05:30
@notification_setting = current_user.notification_settings_for(@project) if current_user
2018-03-27 19:54:05 +05:30
@project = @project.present(current_user: current_user)
2016-11-03 12:29:30 +05:30
render_landing_page
2014-09-02 18:07:02 +05:30
end
2015-09-11 14:41:01 +05:30
format.atom do
load_events
2021-09-30 23:02:18 +05:30
@events = @events.select { |event| event.visible_to_user?(current_user) }
2017-09-10 17:25:29 +05:30
render layout: 'xml.atom'
2015-04-26 12:48:37 +05:30
end
2014-09-02 18:07:02 +05:30
end
end
def destroy
2015-04-26 12:48:37 +05:30
return access_denied! unless can?(current_user, :remove_project, @project)
2014-09-02 18:07:02 +05:30
2016-09-13 17:45:13 +05:30
::Projects::DestroyService.new(@project, current_user, {}).async_execute
2018-03-27 19:54:05 +05:30
flash[:notice] = _("Project '%{project_name}' is in the process of being deleted.") % { project_name: @project.full_name }
2014-09-02 18:07:02 +05:30
2018-11-18 11:00:15 +05:30
redirect_to dashboard_projects_path, status: :found
2015-09-11 14:41:01 +05:30
rescue Projects::DestroyService::DestroyError => ex
2019-12-26 22:10:19 +05:30
redirect_to edit_project_path(@project), status: :found, alert: ex.message
2014-09-02 18:07:02 +05:30
end
2018-03-17 18:26:18 +05:30
def new_issuable_address
2017-08-17 22:00:37 +05:30
return render_404 unless Gitlab::IncomingEmail.supports_issue_creation?
2014-09-02 18:07:02 +05:30
2017-08-17 22:00:37 +05:30
current_user.reset_incoming_email_token!
2018-03-17 18:26:18 +05:30
render json: { new_address: @project.new_issuable_address(current_user, params[:issuable_type]) }
2014-09-02 18:07:02 +05:30
end
def archive
2018-11-18 11:00:15 +05:30
::Projects::UpdateService.new(@project, current_user, archived: true).execute
2014-09-02 18:07:02 +05:30
respond_to do |format|
2015-04-26 12:48:37 +05:30
format.html { redirect_to project_path(@project) }
2014-09-02 18:07:02 +05:30
end
end
def unarchive
2018-11-18 11:00:15 +05:30
::Projects::UpdateService.new(@project, current_user, archived: false).execute
2014-09-02 18:07:02 +05:30
respond_to do |format|
2015-04-26 12:48:37 +05:30
format.html { redirect_to project_path(@project) }
2014-09-02 18:07:02 +05:30
end
end
def housekeeping
2021-03-08 18:12:59 +05:30
::Repositories::HousekeepingService.new(@project, :gc).execute
2016-06-02 11:05:42 +05:30
redirect_to(
project_path(@project),
2017-09-10 17:25:29 +05:30
notice: _("Housekeeping successfully started")
2016-06-02 11:05:42 +05:30
)
2021-03-08 18:12:59 +05:30
rescue ::Repositories::HousekeepingService::LeaseTaken => ex
2016-06-02 11:05:42 +05:30
redirect_to(
2018-11-20 20:47:30 +05:30
edit_project_path(@project, anchor: 'js-project-advanced-settings'),
2016-06-02 11:05:42 +05:30
alert: ex.to_s
)
end
2016-06-22 15:30:34 +05:30
def export
@project.add_export_job(current_user: current_user)
redirect_to(
2018-11-20 20:47:30 +05:30
edit_project_path(@project, anchor: 'js-export-project'),
2020-05-24 23:13:21 +05:30
notice: _("Project export started. A download link will be sent by email and made available on this page.")
2016-06-22 15:30:34 +05:30
)
end
def download_export
2018-11-20 20:47:30 +05:30
if @project.export_file_exists?
2021-09-04 01:27:46 +05:30
if @project.export_archive_exists?
send_upload(@project.export_file, attachment: @project.export_file.filename)
else
redirect_to(
edit_project_path(@project, anchor: 'js-export-project'),
alert: _("The file containing the export is not available yet; it may still be transferring. Please try again later.")
)
end
2016-06-22 15:30:34 +05:30
else
redirect_to(
2018-11-20 20:47:30 +05:30
edit_project_path(@project, anchor: 'js-export-project'),
2017-09-10 17:25:29 +05:30
alert: _("Project export link has expired. Please generate a new export from your project settings.")
2016-06-22 15:30:34 +05:30
)
end
end
def remove_export
if @project.remove_exports
2017-09-10 17:25:29 +05:30
flash[:notice] = _("Project export has been deleted.")
2016-06-22 15:30:34 +05:30
else
2017-09-10 17:25:29 +05:30
flash[:alert] = _("Project export could not be deleted.")
2016-06-22 15:30:34 +05:30
end
2018-03-17 18:26:18 +05:30
2018-11-20 20:47:30 +05:30
redirect_to(edit_project_path(@project, anchor: 'js-export-project'))
2016-06-22 15:30:34 +05:30
end
def generate_new_export
if @project.remove_exports
export
else
redirect_to(
2018-11-20 20:47:30 +05:30
edit_project_path(@project, anchor: 'js-export-project'),
2017-09-10 17:25:29 +05:30
alert: _("Project export could not be deleted.")
2016-06-22 15:30:34 +05:30
)
end
end
2014-09-02 18:07:02 +05:30
def toggle_star
current_user.toggle_star(@project)
2019-07-31 22:56:46 +05:30
@project.reset
2015-09-11 14:41:01 +05:30
render json: {
star_count: @project.star_count
2015-09-11 14:41:01 +05:30
}
2014-09-02 18:07:02 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2016-06-22 15:30:34 +05:30
def refs
2017-09-10 17:25:29 +05:30
find_refs = params['find']
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
find_branches = true
find_tags = true
find_commits = true
unless find_refs.nil?
find_branches = find_refs.include?('branches')
find_tags = find_refs.include?('tags')
find_commits = find_refs.include?('commits')
end
2016-06-22 15:30:34 +05:30
2017-09-10 17:25:29 +05:30
options = {}
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
if find_branches
branches = BranchesFinder.new(@repository, params).execute.take(100).map(&:name)
2018-11-08 19:23:39 +05:30
options['Branches'] = branches
2017-09-10 17:25:29 +05:30
end
if find_tags && @repository.tag_count.nonzero?
2021-11-18 22:05:49 +05:30
tags, _ = TagsFinder.new(@repository, params).execute
2017-09-10 17:25:29 +05:30
2021-11-18 22:05:49 +05:30
options['Tags'] = tags.take(100).map(&:name)
2016-06-22 15:30:34 +05:30
end
# If reference is commit id - we should add it to branch/tag selectbox
ref = Addressable::URI.unescape(params[:ref])
2017-09-10 17:25:29 +05:30
if find_commits && ref && options.flatten(2).exclude?(ref) && ref =~ /\A[0-9a-zA-Z]{6,52}\z/
2016-06-22 15:30:34 +05:30
options['Commits'] = [ref]
end
render json: options.to_json
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2016-06-22 15:30:34 +05:30
2019-10-12 21:52:04 +05:30
def resolve
@project = Project.find(params[:id])
if can?(current_user, :read_project, @project)
redirect_to @project
else
render_404
end
end
2021-01-03 14:25:43 +05:30
def unfoldered_environment_names
respond_to do |format|
format.json do
2021-06-08 01:23:25 +05:30
render json: Environments::EnvironmentNamesFinder.new(@project, current_user).execute
2021-01-03 14:25:43 +05:30
end
end
end
2019-10-12 21:52:04 +05:30
private
2016-11-03 12:29:30 +05:30
# Render project landing depending of which features are available
2018-12-13 13:39:08 +05:30
# So if page is not available in the list it renders the next page
2016-11-03 12:29:30 +05:30
#
# pages list order: repository readme, wiki home, issues list, customize workflow
def render_landing_page
2017-09-10 17:25:29 +05:30
if can?(current_user, :download_code, @project)
2016-11-03 12:29:30 +05:30
return render 'projects/no_repo' unless @project.repository_exists?
2018-03-17 18:26:18 +05:30
2021-04-17 20:07:23 +05:30
if @project.can_current_user_push_to_default_branch?
property = @project.empty_repo? ? 'empty' : 'nonempty'
experiment(:empty_repo_upload, project: @project).track(:view_project_show, property: property)
end
2021-09-04 01:27:46 +05:30
render 'projects/empty' if @project.empty_repo?
2016-11-03 12:29:30 +05:30
else
2018-03-17 18:26:18 +05:30
if can?(current_user, :read_wiki, @project)
2020-06-23 00:09:42 +05:30
@wiki = @project.wiki
@wiki_home = @wiki.find_page('home', params[:version_id])
2016-11-03 12:29:30 +05:30
elsif @project.feature_available?(:issues, current_user)
2018-03-17 18:26:18 +05:30
@issues = issuables_collection.page(params[:page])
2020-06-23 00:09:42 +05:30
@issuable_meta_data = Gitlab::IssuableMetadata.new(current_user, @issues).data
2016-11-03 12:29:30 +05:30
end
render :show
end
end
2018-03-27 19:54:05 +05:30
def finder_type
IssuesFinder
end
2015-09-11 14:41:01 +05:30
def determine_layout
if [:new, :create].include?(action_name.to_sym)
'application'
elsif [:edit, :update].include?(action_name.to_sym)
'project_settings'
else
'project'
end
2014-09-02 18:07:02 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2015-09-11 14:41:01 +05:30
def load_events
2017-09-10 17:25:29 +05:30
projects = Project.where(id: @project.id)
@events = EventCollection
.new(projects, offset: params[:offset].to_i, filter: event_filter)
.to_a
2020-02-01 01:16:34 +05:30
.map(&:present)
2014-09-02 18:07:02 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2014-09-02 18:07:02 +05:30
2019-04-03 18:18:56 +05:30
def project_params(attributes: [])
2017-08-17 22:00:37 +05:30
params.require(:project)
2019-04-03 18:18:56 +05:30
.permit(project_params_attributes + attributes)
2019-07-31 22:56:46 +05:30
.merge(import_url_params)
2017-08-17 22:00:37 +05:30
end
2016-09-29 09:46:39 +05:30
2021-01-29 00:20:46 +05:30
def project_feature_attributes
%i[
builds_access_level
issues_access_level
forking_access_level
merge_requests_access_level
repository_access_level
snippets_access_level
wiki_access_level
pages_access_level
metrics_dashboard_access_level
2021-02-22 17:27:13 +05:30
analytics_access_level
operations_access_level
2021-04-17 20:07:23 +05:30
security_and_compliance_access_level
2021-10-27 15:23:28 +05:30
container_registry_access_level
2021-01-29 00:20:46 +05:30
]
end
2021-03-11 19:13:27 +05:30
def project_setting_attributes
%i[
show_default_award_emojis
squash_option
2021-04-29 21:17:54 +05:30
mr_default_target_self
2021-10-29 20:43:33 +05:30
warn_about_potentially_unwanted_characters
2021-03-11 19:13:27 +05:30
]
end
2017-09-10 17:25:29 +05:30
def project_params_attributes
2017-08-17 22:00:37 +05:30
[
2020-06-23 00:09:42 +05:30
:allow_merge_on_skipped_pipeline,
2017-08-17 22:00:37 +05:30
:avatar,
:build_allow_git_fetch,
:build_coverage_regex,
2018-05-09 12:01:36 +05:30
:build_timeout_human_readable,
2018-03-17 18:26:18 +05:30
:resolve_outdated_diff_discussions,
2016-09-29 09:46:39 +05:30
:container_registry_enabled,
2017-08-17 22:00:37 +05:30
:default_branch,
:description,
2019-10-12 21:52:04 +05:30
:emails_disabled,
2019-07-07 11:18:12 +05:30
:external_authorization_classification_label,
2017-08-17 22:00:37 +05:30
:import_url,
:issues_tracker,
:issues_tracker_id,
:last_activity_at,
:lfs_enabled,
:name,
:only_allow_merge_if_all_discussions_are_resolved,
:only_allow_merge_if_pipeline_succeeds,
:path,
2019-04-03 18:18:56 +05:30
:printing_merge_request_link_enabled,
2017-08-17 22:00:37 +05:30
:public_builds,
2019-12-26 22:10:19 +05:30
:remove_source_branch_after_merge,
2017-08-17 22:00:37 +05:30
:request_access_enabled,
:runners_token,
:tag_list,
2021-09-04 01:27:46 +05:30
:topics,
2017-08-17 22:00:37 +05:30
:visibility_level,
2017-09-10 17:25:29 +05:30
:template_name,
2019-12-21 20:55:43 +05:30
:template_project_id,
2018-03-17 18:26:18 +05:30
:merge_method,
2021-11-18 22:05:49 +05:30
:initialize_with_sast,
2018-11-08 19:23:39 +05:30
:initialize_with_readme,
2020-03-13 15:44:24 +05:30
:autoclose_referenced_issues,
:suggestion_commit_message,
2020-10-24 23:57:45 +05:30
:packages_enabled,
2020-07-28 23:09:34 +05:30
:service_desk_enabled,
2021-03-11 19:13:27 +05:30
project_setting_attributes: project_setting_attributes
2021-01-29 00:20:46 +05:30
] + [project_feature_attributes: project_feature_attributes]
2014-09-02 18:07:02 +05:30
end
2015-04-26 12:48:37 +05:30
2019-04-03 18:18:56 +05:30
def project_params_create_attributes
[:namespace_id]
end
2018-03-27 19:54:05 +05:30
def custom_import_params
{}
end
def active_new_project_tab
project_params[:import_url].present? ? 'import' : 'blank'
end
2015-11-26 14:37:03 +05:30
def repo_exists?
2018-03-17 18:26:18 +05:30
project.repository_exists? && !project.empty_repo?
2016-11-03 12:29:30 +05:30
rescue Gitlab::Git::Repository::NoRepository
project.repository.expire_exists_cache
false
2015-11-26 14:37:03 +05:30
end
2016-08-24 12:49:21 +05:30
def project_view_files?
2017-08-17 22:00:37 +05:30
if current_user
current_user.project_view == 'files'
else
project_view_files_allowed?
end
2016-08-24 12:49:21 +05:30
end
2016-06-22 15:30:34 +05:30
# Override extract_ref from ExtractsPath, which returns the branch and file path
2015-11-26 14:37:03 +05:30
# for the blob/tree, which in this case is just the root of the default branch.
2016-06-22 15:30:34 +05:30
# This way we avoid to access the repository.ref_names.
def extract_ref(_id)
[get_id, '']
end
# Override get_id from ExtractsPath in this case is just the root of the default branch.
2015-11-26 14:37:03 +05:30
def get_id
project.repository.root_ref
end
2017-08-17 22:00:37 +05:30
def project_view_files_allowed?
!project.empty_repo? && can?(current_user, :download_code, project)
end
def build_canonical_path(project)
params[:namespace_id] = project.namespace.to_param
params[:id] = project.to_param
2018-06-27 16:04:02 +05:30
url_for(safe_params)
2017-08-17 22:00:37 +05:30
end
2018-03-17 18:26:18 +05:30
2021-09-30 23:02:18 +05:30
def verify_git_import_enabled
render_404 if project_params[:import_url] && !git_import_enabled?
end
2018-03-17 18:26:18 +05:30
def project_export_enabled
render_404 unless Gitlab::CurrentSettings.project_export_enabled?
end
2021-03-11 19:13:27 +05:30
# Redirect from localhost/group/project.git to localhost/group/project
2018-03-17 18:26:18 +05:30
def redirect_git_extension
2021-03-11 19:13:27 +05:30
return unless params[:format] == 'git'
# `project` calls `find_routable!`, so this will trigger the usual not-found
# behaviour when the user isn't authorized to see the project
2021-06-21 23:55:49 +05:30
return if project.nil? || performed?
2021-03-11 19:13:27 +05:30
redirect_to(request.original_url.sub(%r{\.git/?\Z}, ''))
2018-03-17 18:26:18 +05:30
end
2021-04-29 21:17:54 +05:30
def disable_query_limiting
Gitlab::QueryLimiting.disable!('https://gitlab.com/gitlab-org/gitlab/-/issues/20826')
2018-03-17 18:26:18 +05:30
end
2018-11-08 19:23:39 +05:30
def present_project
@project = @project.present(current_user: current_user)
end
2020-01-01 13:55:28 +05:30
def export_rate_limit
prefixed_action = "project_#{params[:action]}".to_sym
2021-04-17 20:07:23 +05:30
project_scope = params[:action] == 'download_export' ? @project : nil
2020-06-23 00:09:42 +05:30
if rate_limiter.throttled?(prefixed_action, scope: [current_user, project_scope].compact)
2020-01-01 13:55:28 +05:30
rate_limiter.log_request(request, "#{prefixed_action}_request_limit".to_sym, current_user)
2020-06-23 00:09:42 +05:30
render plain: _('This endpoint has been requested too many times. Try again later.'), status: :too_many_requests
2020-01-01 13:55:28 +05:30
end
end
def rate_limiter
::Gitlab::ApplicationRateLimiter
end
2020-03-13 15:44:24 +05:30
def render_edit
render 'edit'
end
2014-09-02 18:07:02 +05:30
end
2019-12-04 20:38:33 +05:30
2021-06-08 01:23:25 +05:30
ProjectsController.prepend_mod_with('ProjectsController')