Commit 59fa3064 authored by Kamil Trzciński's avatar Kamil Trzciński

Get rid of restored_project

This creates confusion on how data are processed,
because we get the same object out of order and
force to lazily initialise objects when they should
not need
parent 85a103fc
...@@ -312,7 +312,7 @@ module Gitlab ...@@ -312,7 +312,7 @@ module Gitlab
class Importer class Importer
def execute def execute
if import_file && check_version! && restorers.all?(&:restore) && overwrite_project if import_file && check_version! && restorers.all?(&:restore) && overwrite_project
project_tree.restored_project project
else else
raise Projects::ImportService::Error.new(@shared.errors.join(', ')) raise Projects::ImportService::Error.new(@shared.errors.join(', '))
end end
......
...@@ -17,7 +17,7 @@ module EE::Gitlab::ImportExport::Importer ...@@ -17,7 +17,7 @@ module EE::Gitlab::ImportExport::Importer
Gitlab::ImportExport::DesignRepoRestorer.new( Gitlab::ImportExport::DesignRepoRestorer.new(
path_to_bundle: design_repo_path, path_to_bundle: design_repo_path,
shared: shared, shared: shared,
project: project_tree.restored_project project: project
) )
end end
......
...@@ -11,7 +11,7 @@ module EE ...@@ -11,7 +11,7 @@ module EE
override :remove_feature_dependent_sub_relations override :remove_feature_dependent_sub_relations
def remove_feature_dependent_sub_relations(relation_item) def remove_feature_dependent_sub_relations(relation_item)
export_designs_disabled = ::Feature.disabled?(:export_designs, @project, default_enabled: true) # rubocop:disable Gitlab/ModuleWithInstanceVariables export_designs_disabled = ::Feature.disabled?(:export_designs, project, default_enabled: true)
if relation_item.is_a?(Hash) && export_designs_disabled if relation_item.is_a?(Hash) && export_designs_disabled
relation_item.except!('designs', 'design_versions') relation_item.except!('designs', 'design_versions')
......
...@@ -19,7 +19,7 @@ module Gitlab ...@@ -19,7 +19,7 @@ module Gitlab
def execute def execute
if import_file && check_version! && restorers.all?(&:restore) && overwrite_project if import_file && check_version! && restorers.all?(&:restore) && overwrite_project
project_tree.restored_project project
else else
raise Projects::ImportService::Error.new(shared.errors.to_sentence) raise Projects::ImportService::Error.new(shared.errors.to_sentence)
end end
...@@ -55,32 +55,32 @@ module Gitlab ...@@ -55,32 +55,32 @@ module Gitlab
end end
def avatar_restorer def avatar_restorer
Gitlab::ImportExport::AvatarRestorer.new(project: project_tree.restored_project, shared: shared) Gitlab::ImportExport::AvatarRestorer.new(project: project, shared: shared)
end end
def repo_restorer def repo_restorer
Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: repo_path, Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: repo_path,
shared: shared, shared: shared,
project: project_tree.restored_project) project: project)
end end
def wiki_restorer def wiki_restorer
Gitlab::ImportExport::WikiRestorer.new(path_to_bundle: wiki_repo_path, Gitlab::ImportExport::WikiRestorer.new(path_to_bundle: wiki_repo_path,
shared: shared, shared: shared,
project: ProjectWiki.new(project_tree.restored_project), project: ProjectWiki.new(project),
wiki_enabled: project.wiki_enabled?) wiki_enabled: project.wiki_enabled?)
end end
def uploads_restorer def uploads_restorer
Gitlab::ImportExport::UploadsRestorer.new(project: project_tree.restored_project, shared: shared) Gitlab::ImportExport::UploadsRestorer.new(project: project, shared: shared)
end end
def lfs_restorer def lfs_restorer
Gitlab::ImportExport::LfsRestorer.new(project: project_tree.restored_project, shared: shared) Gitlab::ImportExport::LfsRestorer.new(project: project, shared: shared)
end end
def statistics_restorer def statistics_restorer
Gitlab::ImportExport::StatisticsRestorer.new(project: project_tree.restored_project, shared: shared) Gitlab::ImportExport::StatisticsRestorer.new(project: project, shared: shared)
end end
def path_with_namespace def path_with_namespace
...@@ -105,8 +105,6 @@ module Gitlab ...@@ -105,8 +105,6 @@ module Gitlab
end end
def overwrite_project def overwrite_project
project = project_tree.restored_project
return unless can?(current_user, :admin_namespace, project.namespace) return unless can?(current_user, :admin_namespace, project.namespace)
if overwrite_project? if overwrite_project?
......
...@@ -7,7 +7,8 @@ module Gitlab ...@@ -7,7 +7,8 @@ module Gitlab
GROUP_MODELS = [GroupLabel, Milestone].freeze GROUP_MODELS = [GroupLabel, Milestone].freeze
attr_reader :user attr_reader :user
attr_reader :restored_project attr_reader :shared
attr_reader :project
def initialize(user:, shared:, project:) def initialize(user:, shared:, project:)
@path = File.join(shared.export_path, 'project.json') @path = File.join(shared.export_path, 'project.json')
...@@ -37,7 +38,7 @@ module Gitlab ...@@ -37,7 +38,7 @@ module Gitlab
end end
# ensure that we have latest version of the restore # ensure that we have latest version of the restore
@restored_project = @project.reload # rubocop:disable Cop/ActiveRecordAssociationReload @project.reload # rubocop:disable Cop/ActiveRecordAssociationReload
true true
rescue => e rescue => e
......
...@@ -534,7 +534,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do ...@@ -534,7 +534,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
it 'uses the project visibility' do it 'uses the project visibility' do
expect(restorer.restore).to eq(true) expect(restorer.restore).to eq(true)
expect(restorer.restored_project.visibility_level).to eq(visibility) expect(restorer.project.visibility_level).to eq(visibility)
end end
end end
...@@ -546,7 +546,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do ...@@ -546,7 +546,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::INTERNAL]) stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::INTERNAL])
expect(restorer.restore).to eq(true) expect(restorer.restore).to eq(true)
expect(restorer.restored_project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE) expect(restorer.project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE)
end end
end end
end end
...@@ -564,7 +564,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do ...@@ -564,7 +564,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
it 'uses the group visibility' do it 'uses the group visibility' do
expect(restorer.restore).to eq(true) expect(restorer.restore).to eq(true)
expect(restorer.restored_project.visibility_level).to eq(group_visibility) expect(restorer.project.visibility_level).to eq(group_visibility)
end end
end end
...@@ -574,7 +574,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do ...@@ -574,7 +574,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
it 'uses the project visibility' do it 'uses the project visibility' do
expect(restorer.restore).to eq(true) expect(restorer.restore).to eq(true)
expect(restorer.restored_project.visibility_level).to eq(visibility) expect(restorer.project.visibility_level).to eq(visibility)
end end
end end
...@@ -584,7 +584,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do ...@@ -584,7 +584,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
it 'uses the group visibility' do it 'uses the group visibility' do
expect(restorer.restore).to eq(true) expect(restorer.restore).to eq(true)
expect(restorer.restored_project.visibility_level).to eq(group_visibility) expect(restorer.project.visibility_level).to eq(group_visibility)
end end
context 'with restricted internal visibility' do context 'with restricted internal visibility' do
...@@ -592,7 +592,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do ...@@ -592,7 +592,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::INTERNAL]) stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::INTERNAL])
expect(restorer.restore).to eq(true) expect(restorer.restore).to eq(true)
expect(restorer.restored_project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE) expect(restorer.project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE)
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment