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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
0f1ab09a
Commit
0f1ab09a
authored
Mar 06, 2020
by
nmilojevic1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add project export presenter
- Clean streaming serializer - Clean TreeSaver
parent
74332275
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
35 deletions
+51
-35
app/presenters/projects/import_export/project_export_presenter.rb
...enters/projects/import_export/project_export_presenter.rb
+33
-0
lib/gitlab/import_export/json/streaming_serializer.rb
lib/gitlab/import_export/json/streaming_serializer.rb
+1
-16
lib/gitlab/import_export/project/tree_saver.rb
lib/gitlab/import_export/project/tree_saver.rb
+17
-19
No files found.
app/presenters/projects/import_export/project_export_presenter.rb
0 → 100644
View file @
0f1ab09a
# frozen_string_literal: true
module
Projects
module
ImportExport
class
ProjectExportPresenter
<
Gitlab
::
View
::
Presenter
::
Delegated
presents
:project
def
project_members
group_members
.
as_json
(
group_members_tree
).
each
do
|
group_member
|
group_member
[
'source_type'
]
=
'Project'
# Make group members project members of the future import
end
end
def
as_json
(
*
_args
)
self
.
respond_to?
(
:override_description
)
?
super
.
merge
(
"description"
=>
override_description
)
:
super
end
private
# rubocop: disable CodeReuse/ActiveRecord
def
group_members
return
[]
unless
current_user
.
can?
(
:admin_group
,
project
.
group
)
# We need `.where.not(user_id: nil)` here otherwise when a group has an
# invitee, it would make the following query return 0 rows since a NULL
# user_id would be present in the subquery
# See http://stackoverflow.com/questions/129077/not-in-clause-and-null-values
non_null_user_ids
=
project
.
project_members
.
where
.
not
(
user_id:
nil
).
select
(
:user_id
)
GroupMembersFinder
.
new
(
project
.
group
).
execute
.
where
.
not
(
user_id:
non_null_user_ids
)
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
lib/gitlab/import_export/json/streaming_serializer.rb
View file @
0f1ab09a
...
...
@@ -6,9 +6,6 @@ module Gitlab
class
StreamingSerializer
include
Gitlab
::
ImportExport
::
CommandLineUtil
attr_reader
:overrides
attr_reader
:additional_relations
BATCH_SIZE
=
100
class
Raw
<
String
...
...
@@ -20,9 +17,7 @@ module Gitlab
def
initialize
(
exportable
,
relations_schema
,
json_writer
)
@exportable
=
exportable
@relations_schema
=
relations_schema
@overrides
=
{}
@json_writer
=
json_writer
@additional_relations
=
{}
end
def
execute
...
...
@@ -40,10 +35,7 @@ module Gitlab
def
serialize_root
attributes
=
exportable
.
as_json
(
relations_schema
.
merge
(
include:
nil
,
preloads:
nil
))
data
=
attributes
.
merge
(
overrides
)
json_writer
.
set
(
data
)
json_writer
.
set
(
attributes
)
end
def
serialize_relation
(
definition
)
...
...
@@ -54,7 +46,6 @@ module Gitlab
options
=
definition
.
first
.
second
record
=
exportable
.
public_send
(
key
)
# rubocop: disable GitlabSecurity/PublicSend
if
record
.
is_a?
(
ActiveRecord
::
Relation
)
serialize_many_relations
(
key
,
record
,
options
)
else
...
...
@@ -74,12 +65,6 @@ module Gitlab
json_writer
.
append
(
key
,
item
)
end
end
additional_relations
[
key
].
to_a
.
each
do
|
item
|
item
=
Raw
.
new
(
item
.
to_json
(
options
))
json_writer
.
append
(
key
,
item
)
end
end
def
serialize_single_relation
(
key
,
record
,
options
)
...
...
lib/gitlab/import_export/project/tree_saver.rb
View file @
0f1ab09a
...
...
@@ -17,15 +17,13 @@ module Gitlab
def
save
json_writer
=
ImportExport
::
JSON
::
LegacyWriter
.
new
(
File
.
join
(
@shared
.
export_path
,
"project.json"
))
serializer
=
ImportExport
::
JSON
::
StreamingSerializer
.
new
(
@project
,
reader
.
project_tree
,
json_writer
)
serializer
.
overrides
[
'description'
]
=
@params
[
:description
]
if
@params
[
:description
].
present?
serializer
.
additional_relations
[
'project_members'
]
=
group_members_array
serializer
=
ImportExport
::
JSON
::
StreamingSerializer
.
new
(
exportable
,
reader
.
project_tree
,
json_writer
)
serializer
.
execute
true
#
rescue => e
#
@shared.error(e)
#
false
rescue
=>
e
@shared
.
error
(
e
)
false
ensure
json_writer
&
.
close
end
...
...
@@ -36,22 +34,22 @@ module Gitlab
@reader
||=
Gitlab
::
ImportExport
::
Reader
.
new
(
shared:
@shared
)
end
def
group_members_array
group_members
.
as_json
(
reader
.
group_members_tree
).
each
do
|
group_member
|
group_member
[
'source_type'
]
=
'Project'
# Make group members project members of the future import
end
def
exportable
@project
.
present
(
exportable_params
)
end
def
group_members
return
[]
unless
@current_user
.
can?
(
:admin_group
,
@project
.
group
)
# We need `.where.not(user_id: nil)` here otherwise when a group has an
# invitee, it would make the following query return 0 rows since a NULL
# user_id would be present in the subquery
# See http://stackoverflow.com/questions/129077/not-in-clause-and-null-values
non_null_user_ids
=
@project
.
project_members
.
where
.
not
(
user_id:
nil
).
select
(
:user_id
)
def
exportable_params
params
=
{
presenter_class:
presenter_class
,
current_user:
@current_user
,
group_members_tree:
reader
.
group_members_tree
}
params
[
:override_description
]
=
@params
[
:description
]
if
@params
[
:description
]
params
end
GroupMembersFinder
.
new
(
@project
.
group
).
execute
.
where
.
not
(
user_id:
non_null_user_ids
)
def
presenter_class
Projects
::
ImportExport
::
ProjectExportPresenter
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