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
7b855b75
Commit
7b855b75
authored
Mar 11, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
project members import stuff
parent
cbae4038
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
91 additions
and
5 deletions
+91
-5
app/services/projects/import_export/members_mapper.rb
app/services/projects/import_export/members_mapper.rb
+45
-2
app/services/projects/import_export/project_factory.rb
app/services/projects/import_export/project_factory.rb
+1
-1
app/services/projects/import_export/project_tree_restorer.rb
app/services/projects/import_export/project_tree_restorer.rb
+3
-2
spec/services/projects/import_export/members_mapper_spec.rb
spec/services/projects/import_export/members_mapper_spec.rb
+42
-0
No files found.
app/services/projects/import_export/members_mapper.rb
View file @
7b855b75
...
...
@@ -6,12 +6,55 @@ module Projects
new
(
*
args
).
map
end
def
initialize
(
exported_members
:)
def
initialize
(
exported_members
:
,
user
:,
project_id
:
)
@exported_members
=
exported_members
@user
=
user
@project_id
=
project_id
end
def
map
#TODO
@project_member_map
||=
project_member_map
end
private
def
project_member_map
@project_member_map
=
Hash
.
new
(
default_project_member
)
@exported_members
.
each
do
|
member
|
existing_user
=
User
.
where
(
find_project_user_query
(
member
)).
first
assign_member
(
existing_user
,
member
)
if
existing_user
end
@project_member_map
end
def
assign_member
(
existing_user
,
member
)
member
[
'user'
]
=
existing_user
project_member
=
ProjectMember
.
new
(
member_hash
(
member
))
@project_member_map
[
member
[
'id'
]]
=
project_member
if
project_member
.
save
end
def
member_hash
(
member
)
member
.
except
(
'id'
).
merge
(
source_id:
@project_id
)
end
def
default_project_member
@default_project_member
||=
begin
default_member
=
ProjectMember
.
new
(
default_project_member_hash
)
default_member
if
default_member
.
save
end
end
def
default_project_member_hash
{
user:
@user
,
access_level:
ProjectMember
::
MASTER
,
source_id:
@project_id
}
end
def
find_project_user_query
(
member
)
user_arel
[
:username
].
eq
(
member
[
'user'
][
'username'
]).
or
(
user_arel
[
:email
].
eq
(
member
[
'user'
][
'email'
]))
end
def
user_arel
@user_arel
||=
User
.
arel_table
end
end
end
...
...
app/services/projects/import_export/project_factory.rb
View file @
7b855b75
...
...
@@ -3,7 +3,7 @@ module Projects
module
ProjectFactory
extend
self
def
create
(
project_params
:,
user
:
,
members_map
:
)
def
create
(
project_params
:,
user
:)
project
=
Project
.
new
(
project_params
.
except
(
'id'
))
project
.
creator
=
user
check_namespace
(
project_params
[
'namespace_id'
],
project
,
user
)
...
...
app/services/projects/import_export/project_tree_restorer.rb
View file @
7b855b75
...
...
@@ -17,7 +17,8 @@ module Projects
private
def
members_map
@members
||=
Projects
::
ImportExport
::
MembersMapper
.
map
(
exported_members:
@tree_hash
.
delete
(
'project_members'
))
@members
||=
Projects
::
ImportExport
::
MembersMapper
.
map
(
exported_members:
@tree_hash
.
delete
(
'project_members'
),
user:
@user
,
project_id:
project
.
id
)
end
def
create_relations
...
...
@@ -35,7 +36,7 @@ module Projects
def
create_project
project_params
=
@tree_hash
.
reject
{
|
_key
,
value
|
value
.
is_a?
(
Array
)
}
project
=
Projects
::
ImportExport
::
ProjectFactory
.
create
(
project_params:
project_params
,
user:
@user
,
members_map:
members_map
)
project_params:
project_params
,
user:
@user
)
project
.
save
project
end
...
...
spec/services/projects/import_export/members_mapper_spec.rb
0 → 100644
View file @
7b855b75
require
'spec_helper'
describe
Projects
::
ImportExport
::
MembersMapper
,
services:
true
do
describe
:map
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
:public
,
name:
'searchable_project'
)
}
let
(
:user2
)
{
create
(
:user
)
}
let
(
: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"
=>
{
"email"
=>
user2
.
email
,
"username"
=>
user2
.
username
}
}]
}
let
(
:members_mapper
)
do
Projects
::
ImportExport
::
MembersMapper
.
new
(
exported_members:
exported_members
,
user:
user
,
project_id:
project
.
id
)
end
it
'maps a project member'
do
expect
(
project_member_map_id
(
user2
.
id
)).
to
eq
(
user2
.
id
)
end
it
'defaults to importer project member if it does not exist'
do
expect
(
project_member_map_id
(
-
1
)).
to
eq
(
user
.
id
)
end
end
def
project_member_map_id
(
id
)
members_mapper
.
map
[
id
][
'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