summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2017-01-31 22:01:53 +0000
committerJames Lopez <james@jameslopez.es>2017-02-02 09:40:37 +0100
commit1b53ed13bc05c676dadd750e990b023e91244372 (patch)
tree2b4befe81e19dfd5fa4ee60ab45415e8351feec9
parente3be216a565b05b0efec54ef23595269a61d11eb (diff)
downloadgitlab-ce-1b53ed13bc05c676dadd750e990b023e91244372.tar.gz
Merge branch 'fix/import-user-validation-error' into 'master'
Fix user validation error in Import/Export Closes #23833 See merge request !8909
-rw-r--r--changelogs/unreleased/fix-import-user-validation-error.yml4
-rw-r--r--lib/gitlab/import_export/members_mapper.rb2
-rw-r--r--spec/lib/gitlab/import_export/members_mapper_spec.rb24
3 files changed, 30 insertions, 0 deletions
diff --git a/changelogs/unreleased/fix-import-user-validation-error.yml b/changelogs/unreleased/fix-import-user-validation-error.yml
new file mode 100644
index 00000000000..985a3b0b26f
--- /dev/null
+++ b/changelogs/unreleased/fix-import-user-validation-error.yml
@@ -0,0 +1,4 @@
+---
+title: Remove old project members when retrying an export
+merge_request:
+author:
diff --git a/lib/gitlab/import_export/members_mapper.rb b/lib/gitlab/import_export/members_mapper.rb
index 2405b94db50..a09577ae48d 100644
--- a/lib/gitlab/import_export/members_mapper.rb
+++ b/lib/gitlab/import_export/members_mapper.rb
@@ -41,6 +41,8 @@ module Gitlab
end
def ensure_default_member!
+ @project.project_members.destroy_all
+
ProjectMember.create!(user: @user, access_level: ProjectMember::MASTER, source_id: @project.id, importing: true)
end
diff --git a/spec/lib/gitlab/import_export/members_mapper_spec.rb b/spec/lib/gitlab/import_export/members_mapper_spec.rb
index b069696b5c7..75212c4f0d3 100644
--- a/spec/lib/gitlab/import_export/members_mapper_spec.rb
+++ b/spec/lib/gitlab/import_export/members_mapper_spec.rb
@@ -92,5 +92,29 @@ describe Gitlab::ImportExport::MembersMapper, services: true do
expect(members_mapper.map[exported_user_id]).to eq(user2.id)
end
end
+
+ context 'importer same as group member' do
+ let(:user2) { create(:admin, authorized_projects_populated: true) }
+ let(:group) { create(:group) }
+ let(:project) { create(:empty_project, :public, name: 'searchable_project', namespace: group) }
+ let(:members_mapper) do
+ described_class.new(
+ exported_members: exported_members, user: user2, project: project)
+ end
+
+ before do
+ group.add_users([user, user2], GroupMember::DEVELOPER)
+ end
+
+ it 'maps the project member' do
+ expect(members_mapper.map[exported_user_id]).to eq(user2.id)
+ end
+
+ it 'maps the project member if it already exists' do
+ project.add_master(user2)
+
+ expect(members_mapper.map[exported_user_id]).to eq(user2.id)
+ end
+ end
end
end