2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
class Import::BaseController < ApplicationController
|
2020-03-09 13:42:32 +05:30
|
|
|
before_action :import_rate_limit, only: [:create]
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
private
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-10-15 14:42:47 +05:30
|
|
|
def find_already_added_projects(import_type)
|
2020-03-09 13:42:32 +05:30
|
|
|
current_user.created_projects.where(import_type: import_type).with_import_state
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-10-15 14:42:47 +05:30
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-10-15 14:42:47 +05:30
|
|
|
def find_jobs(import_type)
|
|
|
|
current_user.created_projects
|
2020-03-09 13:42:32 +05:30
|
|
|
.with_import_state
|
2018-11-08 19:23:39 +05:30
|
|
|
.where(import_type: import_type)
|
|
|
|
.to_json(only: [:id], methods: [:import_status])
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-10-15 14:42:47 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
# deprecated: being replaced by app/services/import/base_service.rb
|
2017-08-17 22:00:37 +05:30
|
|
|
def find_or_create_namespace(names, owner)
|
|
|
|
names = params[:target_namespace].presence || names
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
return current_user.namespace if names == owner
|
|
|
|
|
|
|
|
group = Groups::NestedCreateService.new(current_user, group_path: names).execute
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
group.errors.any? ? current_user.namespace : group
|
|
|
|
rescue => e
|
|
|
|
Gitlab::AppLogger.error(e)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
current_user.namespace
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
# deprecated: being replaced by app/services/import/base_service.rb
|
2018-11-08 19:23:39 +05:30
|
|
|
def project_save_error(project)
|
|
|
|
project.errors.full_messages.join(', ')
|
|
|
|
end
|
2020-03-09 13:42:32 +05:30
|
|
|
|
|
|
|
def import_rate_limit
|
|
|
|
key = "project_import".to_sym
|
|
|
|
|
|
|
|
if rate_limiter.throttled?(key, scope: [current_user, key])
|
|
|
|
rate_limiter.log_request(request, "#{key}_request_limit".to_sym, current_user)
|
|
|
|
|
|
|
|
redirect_back_or_default(options: { alert: _('This endpoint has been requested too many times. Try again later.') })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def rate_limiter
|
|
|
|
::Gitlab::ApplicationRateLimiter
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|