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
e90b1e14
Commit
e90b1e14
authored
Mar 10, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored project creation to create the associations as well
parent
40de1b46
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
7 deletions
+48
-7
app/services/projects/import_export/project_factory.rb
app/services/projects/import_export/project_factory.rb
+40
-0
app/services/projects/import_export/project_tree_restorer.rb
app/services/projects/import_export/project_tree_restorer.rb
+8
-7
No files found.
app/services/projects/import_export/project_factory.rb
0 → 100644
View file @
e90b1e14
module
Projects
module
ImportExport
module
ProjectFactory
extend
self
def
create
(
project_params
:,
user
:)
project
=
Project
.
new
(
project_params
.
except
(
'id'
))
project
.
creator
=
user
check_namespace
(
project_params
[
'namespace_id'
],
project
,
user
)
end
def
check_namespace
(
namespace_id
,
project
,
user
)
if
namespace_id
# Find matching namespace and check if it allowed
# for current user if namespace_id passed.
unless
allowed_namespace?
(
user
,
namespace_id
)
project
.
namespace_id
=
nil
deny_namespace
(
project
)
end
else
# Set current user namespace if namespace_id is nil
project
.
namespace_id
=
user
.
namespace_id
end
project
end
private
def
allowed_namespace?
(
user
,
namespace_id
)
namespace
=
Namespace
.
find_by
(
id:
namespace_id
)
user
.
can?
(
:create_projects
,
namespace
)
end
def
deny_namespace
(
project
)
project
.
errors
.
add
(
:namespace
,
"is not valid"
)
end
end
end
end
app/services/projects/import_export/project_tree_restorer.rb
View file @
e90b1e14
...
...
@@ -3,7 +3,7 @@ module Projects
class
ProjectTreeRestorer
attr_reader
:project
def
initialize
(
path:
,
user:
user
)
def
initialize
(
path
:
,
user
:
)
@path
=
path
@user
=
user
end
...
...
@@ -13,22 +13,23 @@ module Projects
def
restore
json
=
IO
.
read
(
@path
)
tree_hash
=
ActiveSupport
::
JSON
.
decode
(
json
)
project_params
=
tree_hash
.
reject
{
|
_key
,
value
|
value
.
is_a?
(
Array
)
}
project
=
Projects
::
ImportExport
::
ProjectFactory
.
create
(
project_params:
project_params
,
user:
@user
)
project
.
save
relation_hash
=
{}
ImportExport
.
project_tree
.
each
do
|
relation
|
next
if
tree_hash
[
relation
.
to_s
].
empty?
relation_hash
[
relation
.
to_s
]
=
create_relation
(
relation
,
tree_hash
[
relation
.
to_s
])
relation_hash
[
relation
.
to_s
]
=
create_relation
(
relation
,
tree_hash
[
relation
.
to_s
],
project
.
id
)
project
.
update_attribute
(
relation
,
relation_hash
[
relation
.
to_s
])
end
project_params
=
tree_hash
.
delete_if
{
|
_key
,
value
|
value
.
is_a?
(
Array
)}
@project
=
::
Projects
::
CreateService
.
new
(
@user
,
project_params
).
execute
@project
.
saved?
end
private
def
create_relation
(
relation
,
relation_hash_list
)
def
create_relation
(
relation
,
relation_hash_list
,
project_id
)
relation_hash_list
.
map
do
|
relation_hash
|
Projects
::
ImportExport
::
RelationFactory
.
create
(
relation_sym:
relation
,
relation_hash:
relation_hash
)
relation_sym:
relation
,
relation_hash:
relation_hash
.
merge
(
project_id:
project_id
)
)
end
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