Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2016-11-01 21:16:32 +0300
committerRobert Speicher <rspeicher@gmail.com>2016-11-01 21:16:32 +0300
commitacd36957097ccd42c0a3d7fd10e7da8e8e468244 (patch)
treefdc17d344ecaefd7c1e3efe9e6430428e61366e5
parenta23ca284c720755dbfc1d2f0138c0fa3ad073b9d (diff)
Revert "Fixed Import/Export foreign key issue to do with project members"
This reverts commit a23ca284c720755dbfc1d2f0138c0fa3ad073b9d.
-rw-r--r--lib/gitlab/import_export/attribute_cleaner.rb28
-rw-r--r--lib/gitlab/import_export/members_mapper.rb7
-rw-r--r--lib/gitlab/import_export/relation_factory.rb7
-rw-r--r--spec/lib/gitlab/import_export/attribute_cleaner_spec.rb37
4 files changed, 4 insertions, 75 deletions
diff --git a/lib/gitlab/import_export/attribute_cleaner.rb b/lib/gitlab/import_export/attribute_cleaner.rb
deleted file mode 100644
index 34169319b26..00000000000
--- a/lib/gitlab/import_export/attribute_cleaner.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-module Gitlab
- module ImportExport
- class AttributeCleaner
- ALLOWED_REFERENCES = RelationFactory::PROJECT_REFERENCES + RelationFactory::USER_REFERENCES + ['group_id']
-
- def self.clean(*args)
- new(*args).clean
- end
-
- def initialize(relation_hash:, relation_class:)
- @relation_hash = relation_hash
- @relation_class = relation_class
- end
-
- def clean
- @relation_hash.reject do |key, _value|
- prohibited_key?(key) || !@relation_class.attribute_method?(key)
- end.except('id')
- end
-
- private
-
- def prohibited_key?(key)
- key.end_with?('_id') && !ALLOWED_REFERENCES.include?(key)
- end
- end
- end
-end
diff --git a/lib/gitlab/import_export/members_mapper.rb b/lib/gitlab/import_export/members_mapper.rb
index 740ed25b8f4..b459054c198 100644
--- a/lib/gitlab/import_export/members_mapper.rb
+++ b/lib/gitlab/import_export/members_mapper.rb
@@ -52,12 +52,7 @@ module Gitlab
end
def member_hash(member)
- parsed_hash(member).merge('source_id' => @project.id, 'importing' => true)
- end
-
- def parsed_hash(member)
- Gitlab::ImportExport::AttributeCleaner.clean(relation_hash: member.deep_stringify_keys,
- relation_class: ProjectMember)
+ member.except('id').merge(source_id: @project.id, importing: true)
end
def find_project_user_query(member)
diff --git a/lib/gitlab/import_export/relation_factory.rb b/lib/gitlab/import_export/relation_factory.rb
index 1d3adca847d..e9c1b79fa45 100644
--- a/lib/gitlab/import_export/relation_factory.rb
+++ b/lib/gitlab/import_export/relation_factory.rb
@@ -9,7 +9,7 @@ module Gitlab
builds: 'Ci::Build',
hooks: 'ProjectHook' }.freeze
- USER_REFERENCES = %w[author_id assignee_id updated_by_id user_id created_by_id].freeze
+ USER_REFERENCES = %w[author_id assignee_id updated_by_id user_id].freeze
BUILD_MODELS = %w[Ci::Build commit_status].freeze
@@ -23,7 +23,7 @@ module Gitlab
def initialize(relation_sym:, relation_hash:, members_mapper:, user:)
@relation_name = OVERRIDES[relation_sym] || relation_sym
- @relation_hash = relation_hash.except('noteable_id').merge('project_id' => project_id)
+ @relation_hash = relation_hash.except('id', 'noteable_id')
@members_mapper = members_mapper
@user = user
@imported_object_retries = 0
@@ -147,8 +147,7 @@ module Gitlab
end
def parsed_relation_hash
- @parsed_relation_hash ||= Gitlab::ImportExport::AttributeCleaner.clean(relation_hash: @relation_hash,
- relation_class: relation_class)
+ @relation_hash.reject { |k, _v| !relation_class.attribute_method?(k) }
end
def set_st_diffs
diff --git a/spec/lib/gitlab/import_export/attribute_cleaner_spec.rb b/spec/lib/gitlab/import_export/attribute_cleaner_spec.rb
deleted file mode 100644
index 63bab0f0d0d..00000000000
--- a/spec/lib/gitlab/import_export/attribute_cleaner_spec.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-require 'spec_helper'
-
-describe Gitlab::ImportExport::AttributeCleaner, lib: true do
- let(:relation_class){ double('relation_class').as_null_object }
- let(:unsafe_hash) do
- {
- 'id' => 101,
- 'service_id' => 99,
- 'moved_to_id' => 99,
- 'namespace_id' => 99,
- 'ci_id' => 99,
- 'random_project_id' => 99,
- 'random_id' => 99,
- 'milestone_id' => 99,
- 'project_id' => 99,
- 'user_id' => 99,
- 'random_id_in_the_middle' => 99,
- 'notid' => 99
- }
- end
-
- let(:post_safe_hash) do
- {
- 'project_id' => 99,
- 'user_id' => 99,
- 'random_id_in_the_middle' => 99,
- 'notid' => 99
- }
- end
-
- it 'removes unwanted attributes from the hash' do
- # allow(relation_class).to receive(:attribute_method?).and_return(true)
- parsed_hash = described_class.clean(relation_hash: unsafe_hash, relation_class: relation_class)
-
- expect(parsed_hash).to eq(post_safe_hash)
- end
-end