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
Léo-Paul Géneau
gitlab-ce
Commits
1d8e02c4
Commit
1d8e02c4
authored
Mar 11, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
solved a bunch of issues with mapping members/users
parent
b92411a0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
6 deletions
+20
-6
app/services/projects/import_export/members_mapper.rb
app/services/projects/import_export/members_mapper.rb
+3
-2
app/services/projects/import_export/relation_factory.rb
app/services/projects/import_export/relation_factory.rb
+12
-1
spec/services/projects/import_export/members_mapper_spec.rb
spec/services/projects/import_export/members_mapper_spec.rb
+5
-3
No files found.
app/services/projects/import_export/members_mapper.rb
View file @
1d8e02c4
...
...
@@ -28,9 +28,10 @@ module Projects
end
def
assign_member
(
existing_user
,
member
)
old_user_id
=
member
[
'user'
][
'id'
]
member
[
'user'
]
=
existing_user
project_member
=
ProjectMember
.
new
(
member_hash
(
member
))
@project_member_map
[
existing_user
.
id
]
=
project_member
if
project_member
.
save
@project_member_map
[
old_user_id
]
=
project_member
.
user
.
id
if
project_member
.
save
end
def
member_hash
(
member
)
...
...
@@ -42,7 +43,7 @@ module Projects
@default_project_member
||=
begin
default_member
=
ProjectMember
.
new
(
default_project_member_hash
)
default_member
if
default_member
.
save
default_member
.
user
.
id
if
default_member
.
save
end
end
...
...
app/services/projects/import_export/relation_factory.rb
View file @
1d8e02c4
...
...
@@ -3,17 +3,28 @@ module Projects
module
RelationFactory
extend
self
OVERRIDES
=
{
snippets: :project_snippets
}
OVERRIDES
=
{
snippets: :project_snippets
}.
freeze
USER_REFERENCES
=
%w(author_id assignee_id updated_by_id)
.
freeze
def
create
(
relation_sym
:,
relation_hash
:,
members_map
:)
relation_sym
=
parse_relation_sym
(
relation_sym
)
klass
=
relation_class
(
relation_sym
)
relation_hash
.
delete
(
'id'
)
#screw IDs for now
update_user_references
(
relation_hash
,
members_map
)
klass
.
new
(
relation_hash
)
end
private
#TODO nice to have, optimize this to only get called for specific models
def
update_user_references
(
relation_hash
,
members_map
)
USER_REFERENCES
.
each
do
|
reference
|
if
relation_hash
[
reference
]
relation_hash
[
reference
]
=
members_map
[
relation_hash
[
reference
]]
end
end
end
def
relation_class
(
relation_sym
)
relation_sym
.
to_s
.
classify
.
constantize
end
...
...
spec/services/projects/import_export/members_mapper_spec.rb
View file @
1d8e02c4
...
...
@@ -6,6 +6,7 @@ describe Projects::ImportExport::MembersMapper, services: true do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
:public
,
name:
'searchable_project'
)
}
let
(
:user2
)
{
create
(
:user
)
}
let
(
:exported_user_id
)
{
99
}
let
(
:exported_members
)
do
[{
"id"
=>
2
,
...
...
@@ -22,6 +23,7 @@ describe Projects::ImportExport::MembersMapper, services: true do
"invite_accepted_at"
=>
nil
,
"user"
=>
{
"id"
=>
exported_user_id
,
"email"
=>
user2
.
email
,
"username"
=>
user2
.
username
}
...
...
@@ -34,15 +36,15 @@ describe Projects::ImportExport::MembersMapper, services: true do
end
it
'maps a project member'
do
expect
(
project_member_user_id
(
user2
.
id
)
).
to
eq
(
user2
.
id
)
expect
(
members_mapper
.
map
[
exported_user_id
]
).
to
eq
(
user2
.
id
)
end
it
'defaults to importer project member if it does not exist'
do
expect
(
project_member_user_id
(
-
1
)
).
to
eq
(
user
.
id
)
expect
(
members_mapper
.
map
[
-
1
]
).
to
eq
(
user
.
id
)
end
end
def
project_member_user_id
(
id
)
members_mapper
.
map
[
id
]
.
user
.
id
members_mapper
.
map
[
id
]
end
end
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