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

578 lines
18 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
2022-03-02 08:16:31 +05:30
include SourcegraphDecorator
2022-04-04 11:22:00 +05:30
include PlanningHierarchy
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]
2022-05-07 20:08:51 +05:30
before_action :authenticate_user!, except: [:index, :show, :activity, :refs, :unfoldered_environment_names]
2018-03-17 18:26:18 +05:30
before_action :redirect_git_extension, only: [:show]
2022-05-07 20:08:51 +05:30
before_action :project, except: [:index, :new, :create]
before_action :repository, except: [:index, :new, :create]
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
2022-01-26 12:08:38 +05:30
before_action :check_export_rate_limit!, only: [:export, :download_export, :generate_new_export]
2020-01-01 13:55:28 +05:30
2021-04-29 21:17:54 +05:30
before_action do
2022-07-16 23:28:13 +05:30
push_frontend_feature_flag(:lazy_load_commits, @project)
push_frontend_feature_flag(:refactor_blob_viewer, @project)
push_frontend_feature_flag(:highlight_js, @project)
push_frontend_feature_flag(:increase_page_size_exponentially, @project)
2022-01-26 12:08:38 +05:30
push_licensed_feature(:file_locks) if @project.present? && @project.licensed_feature_available?(:file_locks)
2022-07-16 23:28:13 +05:30
push_licensed_feature(:security_orchestration_policies) if @project.present? && @project.licensed_feature_available?(:security_orchestration_policies)
2022-06-21 17:19:12 +05:30
push_force_frontend_feature_flag(:work_items, @project&.work_items_feature_flag_enabled?)
2022-07-23 23:45:48 +05:30
push_frontend_feature_flag(:work_items_mvc_2)
push_frontend_feature_flag(:package_registry_access_level)
push_frontend_feature_flag(:work_items_hierarchy, @project)
end
before_action only: :edit do
push_frontend_feature_flag(:enforce_auth_checks_on_uploads, @project)
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,
2022-05-07 20:08:51 +05:30
:destroy, :archive, :unarchive, :toggle_star, :activity
2021-01-03 14:25:43 +05:30
]
feature_category :source_code_management, [:remove_fork, :housekeeping, :refs]
2021-12-11 22:18:48 +05:30
feature_category :team_planning, [:preview_markdown, :new_issuable_address]
2021-01-03 14:25:43 +05:30
feature_category :importers, [:export, :remove_export, :generate_new_export, :download_export]
feature_category :code_review, [:unfoldered_environment_names]
2022-04-04 11:22:00 +05:30
feature_category :portfolio_management, [:planning_hierarchy]
2022-01-26 12:08:38 +05:30
2022-07-16 23:28:13 +05:30
urgency :low, [:export, :remove_export, :generate_new_export, :download_export]
urgency :low, [:preview_markdown, :new_issuable_address]
2022-06-21 17:19:12 +05:30
# TODO: Set high urgency for #show https://gitlab.com/gitlab-org/gitlab/-/issues/334444
2022-07-16 23:28:13 +05:30
urgency :low, [:refs, :show, :toggle_star, :transfer, :archive, :destroy, :update, :create,
:activity, :edit, :new, :export, :remove_export, :generate_new_export, :download_export]
2022-01-26 12:08:38 +05:30
urgency :high, [:unfoldered_environment_names]
2021-01-03 14:25:43 +05:30
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
2022-06-21 17:19:12 +05:30
@current_user_group =
if current_user.manageable_groups(include_groups_with_developer_maintainer_access: true).count == 1
current_user.manageable_groups(include_groups_with_developer_maintainer_access: true).first
else
nil
end
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?
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
2022-01-26 12:08:38 +05:30
return redirect_to edit_project_path(@project)
2015-09-11 14:41:01 +05:30
end
2022-01-26 12:08:38 +05:30
redirect_to edit_project_path(@project)
2015-09-11 14:41:01 +05:30
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
2022-01-26 12:08:38 +05:30
redirect_to edit_project_path(@project)
2015-11-26 14:37:03 +05:30
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) }
2022-05-07 20:08:51 +05:30
render layout: 'xml'
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
)
2022-07-16 23:28:13 +05:30
rescue Project::ExportLimitExceeded => ex
redirect_to(
edit_project_path(@project, anchor: 'js-export-project'),
alert: ex.to_s
)
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
2022-04-04 11:22:00 +05:30
find_refs = 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
2022-04-04 11:22:00 +05:30
branches = BranchesFinder.new(@repository, refs_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?
2022-06-21 17:19:12 +05:30
tags = TagsFinder.new(@repository, refs_params).execute
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
2022-04-04 11:22:00 +05:30
ref = Addressable::URI.unescape(refs_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
2022-06-21 17:19:12 +05:30
rescue Gitlab::Git::CommandError
render json: { error: _('Unable to load refs') }, status: :service_unavailable
2016-06-22 15:30:34 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2016-06-22 15:30:34 +05:30
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
2022-04-04 11:22:00 +05:30
def refs_params
2022-05-07 20:08:51 +05:30
params.permit(:search, :sort, :ref, find: [])
2022-04-04 11:22:00 +05:30
end
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
2022-07-16 23:28:13 +05:30
Gitlab::Tracking.event('project_overview', 'render', user: current_user, project: @project.project)
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-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
2022-07-23 23:45:48 +05:30
package_registry_access_level
2021-01-29 00:20:46 +05:30
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
2022-07-16 23:28:13 +05:30
enforce_auth_checks_on_uploads
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,
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,
2022-06-21 17:19:12 +05:30
:ci_separated_caches,
2020-03-13 15:44:24 +05:30
:suggestion_commit_message,
2020-10-24 23:57:45 +05:30
:packages_enabled,
2020-07-28 23:09:34 +05:30
:service_desk_enabled,
2022-04-04 11:22:00 +05:30
:merge_commit_template_or_default,
:squash_commit_template_or_default,
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
2022-01-26 12:08:38 +05:30
def check_export_rate_limit!
2020-01-01 13:55:28 +05:30
prefixed_action = "project_#{params[:action]}".to_sym
2022-06-21 17:19:12 +05:30
group_scope = params[:action] == 'download_export' ? @project.namespace : nil
2020-06-23 00:09:42 +05:30
2022-06-21 17:19:12 +05:30
check_rate_limit!(prefixed_action, scope: [current_user, group_scope].compact)
2020-01-01 13:55:28 +05:30
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')