summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-08-08 16:38:50 +0000
committerRémy Coutable <remy@rymai.me>2016-08-08 16:38:50 +0000
commit59ce1af53b8d25d1b4ae8b6e59f069c5147ca572 (patch)
tree8ed2415778c4ea1b0f546e0c04c3b7bf6cda0c96
parentfd3a2cf76318a84dc6d3bab9bd9a767c5112106d (diff)
parentf04e9dad476cb6b2ac338dd8730d79b22f3fd070 (diff)
downloadgitlab-ce-59ce1af53b8d25d1b4ae8b6e59f069c5147ca572.tar.gz
Merge branch 'fix/import-pending-user' into 'master'
Support pending invitation project members importing projects Adds support for pending invitation project members on Import/Export - previously the import would fail. Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/19973 - [x] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added - Tests - [x] Added for this feature/bug - [x] All builds are passing - [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides) - [x] Branch has no merge conflicts with `master` (if you do - rebase it please) - [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits) See merge request !5683
-rw-r--r--CHANGELOG1
-rw-r--r--lib/gitlab/import_export/members_mapper.rb13
-rw-r--r--spec/lib/gitlab/import_export/members_mapper_spec.rb20
3 files changed, 29 insertions, 5 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 184704d8594..f5416434ab1 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -76,6 +76,7 @@ v 8.11.0 (unreleased)
- Add description to new_issue email and new_merge_request_email in text/plain content type. !5663 (dixpac)
- Speed up and reduce memory usage of Commit#repo_changes, Repository#expire_avatar_cache and IrkerWorker
- Add unfold links for Side-by-Side view. !5415 (Tim Masliuchenko)
+ - Adds support for pending invitation project members importing projects
v 8.10.5 (unreleased)
diff --git a/lib/gitlab/import_export/members_mapper.rb b/lib/gitlab/import_export/members_mapper.rb
index b459054c198..36c4cf6efa0 100644
--- a/lib/gitlab/import_export/members_mapper.rb
+++ b/lib/gitlab/import_export/members_mapper.rb
@@ -18,11 +18,14 @@ module Gitlab
@map ||=
begin
@exported_members.inject(missing_keys_tracking_hash) do |hash, member|
- existing_user = User.where(find_project_user_query(member)).first
- old_user_id = member['user']['id']
- if existing_user && add_user_as_team_member(existing_user, member)
- hash[old_user_id] = existing_user.id
+ if member['user']
+ old_user_id = member['user']['id']
+ existing_user = User.where(find_project_user_query(member)).first
+ hash[old_user_id] = existing_user.id if existing_user && add_team_member(member, existing_user)
+ else
+ add_team_member(member)
end
+
hash
end
end
@@ -45,7 +48,7 @@ module Gitlab
ProjectMember.create!(user: @user, access_level: ProjectMember::MASTER, source_id: @project.id, importing: true)
end
- def add_user_as_team_member(existing_user, member)
+ def add_team_member(member, existing_user = nil)
member['user'] = existing_user
ProjectMember.create(member_hash(member)).persisted?
diff --git a/spec/lib/gitlab/import_export/members_mapper_spec.rb b/spec/lib/gitlab/import_export/members_mapper_spec.rb
index 6d5aa0d04a2..770e8b0c2f4 100644
--- a/spec/lib/gitlab/import_export/members_mapper_spec.rb
+++ b/spec/lib/gitlab/import_export/members_mapper_spec.rb
@@ -26,6 +26,20 @@ describe Gitlab::ImportExport::MembersMapper, services: true do
"email" => user2.email,
"username" => user2.username
}
+ },
+ {
+ "id" => 3,
+ "access_level" => 40,
+ "source_id" => 14,
+ "source_type" => "Project",
+ "user_id" => nil,
+ "notification_level" => 3,
+ "created_at" => "2016-03-11T10:21:44.822Z",
+ "updated_at" => "2016-03-11T10:21:44.822Z",
+ "created_by_id" => 1,
+ "invite_email" => 'invite@test.com',
+ "invite_token" => 'token',
+ "invite_accepted_at" => nil
}]
end
@@ -47,5 +61,11 @@ describe Gitlab::ImportExport::MembersMapper, services: true do
expect(members_mapper.missing_author_ids.first).to eq(-1)
end
+
+ it 'has invited members with no user' do
+ members_mapper.map
+
+ expect(ProjectMember.find_by_invite_email('invite@test.com')).not_to be_nil
+ end
end
end