Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
17c09916
Commit
17c09916
authored
Jan 18, 2017
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix and refactor note user mapping
parent
b3bb8dc4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
18 deletions
+41
-18
lib/gitlab/import_export/members_mapper.rb
lib/gitlab/import_export/members_mapper.rb
+0
-2
lib/gitlab/import_export/relation_factory.rb
lib/gitlab/import_export/relation_factory.rb
+3
-7
spec/lib/gitlab/import_export/members_mapper_spec.rb
spec/lib/gitlab/import_export/members_mapper_spec.rb
+36
-7
spec/lib/gitlab/import_export/relation_factory_spec.rb
spec/lib/gitlab/import_export/relation_factory_spec.rb
+2
-2
No files found.
lib/gitlab/import_export/members_mapper.rb
View file @
17c09916
...
...
@@ -7,7 +7,6 @@ module Gitlab
@exported_members
=
user
.
admin?
?
exported_members
:
[]
@user
=
user
@project
=
project
@missing_author_ids
=
[]
# This needs to run first, as second call would be from #map
# which means project members already exist.
...
...
@@ -39,7 +38,6 @@ module Gitlab
def
missing_keys_tracking_hash
Hash
.
new
do
|
_
,
key
|
@missing_author_ids
<<
key
default_user_id
end
end
...
...
lib/gitlab/import_export/relation_factory.rb
View file @
17c09916
...
...
@@ -80,17 +80,13 @@ module Gitlab
# is left.
def
set_note_author
old_author_id
=
@relation_hash
[
'author_id'
]
# Users with admin access can map users
@relation_hash
[
'author_id'
]
=
admin_user?
?
@members_mapper
.
map
[
old_author_id
]
:
@members_mapper
.
default_user_id
author
=
@relation_hash
.
delete
(
'author'
)
update_note_for_missing_author
(
author
[
'name'
])
if
missing
_author?
(
old_author_id
)
update_note_for_missing_author
(
author
[
'name'
])
unless
has
_author?
(
old_author_id
)
end
def
missing
_author?
(
old_author_id
)
!
admin_user?
||
@members_mapper
.
missing_author_id
s
.
include?
(
old_author_id
)
def
has
_author?
(
old_author_id
)
admin_user?
&&
!
@members_mapper
.
map
.
key
s
.
include?
(
old_author_id
)
end
def
missing_author_note
(
updated_at
,
author_name
)
...
...
spec/lib/gitlab/import_export/members_mapper_spec.rb
View file @
17c09916
...
...
@@ -24,7 +24,7 @@ describe Gitlab::ImportExport::MembersMapper, services: true do
{
"id"
=>
exported_user_id
,
"email"
=>
user2
.
email
,
"username"
=>
user2
.
username
"username"
=>
'test'
}
},
{
...
...
@@ -48,6 +48,12 @@ describe Gitlab::ImportExport::MembersMapper, services: true do
exported_members:
exported_members
,
user:
user
,
project:
project
)
end
it
'includes the exported user ID in the map'
do
members_mapper
.
map
[
-
1
]
expect
(
members_mapper
.
map
.
keys
).
to
include
(
exported_user_id
)
end
it
'maps a project member'
do
expect
(
members_mapper
.
map
[
exported_user_id
]).
to
eq
(
user2
.
id
)
end
...
...
@@ -56,12 +62,6 @@ describe Gitlab::ImportExport::MembersMapper, services: true do
expect
(
members_mapper
.
map
[
-
1
]).
to
eq
(
user
.
id
)
end
it
'updates missing author IDs on missing project member'
do
members_mapper
.
map
[
-
1
]
expect
(
members_mapper
.
missing_author_ids
.
first
).
to
eq
(
-
1
)
end
it
'has invited members with no user'
do
members_mapper
.
map
...
...
@@ -86,5 +86,34 @@ describe Gitlab::ImportExport::MembersMapper, services: true do
expect
(
members_mapper
.
map
[
-
1
]).
to
eq
(
user
.
id
)
end
end
context
'chooses the one with an email first'
do
before
do
exported_members
<<
{
"id"
=>
2
,
"access_level"
=>
40
,
"source_id"
=>
14
,
"source_type"
=>
"Project"
,
"user_id"
=>
19
,
"notification_level"
=>
3
,
"created_at"
=>
"2016-03-11T10:21:44.822Z"
,
"updated_at"
=>
"2016-03-11T10:21:44.822Z"
,
"created_by_id"
=>
nil
,
"invite_email"
=>
nil
,
"invite_token"
=>
nil
,
"invite_accepted_at"
=>
nil
,
"user"
=>
{
"id"
=>
exported_user_id
,
"email"
=>
'test@email.com'
,
"username"
=>
user2
.
username
}
}
end
it
'maps the project member that has a matching email first'
do
expect
(
members_mapper
.
map
[
exported_user_id
]).
to
eq
(
user2
.
id
)
end
end
end
end
spec/lib/gitlab/import_export/relation_factory_spec.rb
View file @
17c09916
...
...
@@ -128,7 +128,7 @@ describe Gitlab::ImportExport::RelationFactory, lib: true do
let
(
:new_user
)
{
create
(
:user
)
}
let
(
:exported_member
)
do
{
"id"
=>
999
,
"id"
=>
111
,
"access_level"
=>
30
,
"source_id"
=>
1
,
"source_type"
=>
"Project"
,
...
...
@@ -137,7 +137,7 @@ describe Gitlab::ImportExport::RelationFactory, lib: true do
"created_at"
=>
"2016-11-18T09:29:42.634Z"
,
"updated_at"
=>
"2016-11-18T09:29:42.634Z"
,
"user"
=>
{
"id"
=>
new_user
.
id
,
"id"
=>
999
,
"email"
=>
new_user
.
email
,
"username"
=>
new_user
.
username
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment