diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-08-23 17:04:22 +0300 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2017-08-23 17:04:22 +0300 |
commit | 9ec60b5030608b7fbb9bd1a2e9a4d95d9b350f99 (patch) | |
tree | c7595ebcf74f2a502336bcc3250aba1649b0829c /app | |
parent | c184a135f2a17a4bcf6189ae92e6cedb31855033 (diff) | |
parent | f76d8c902a08040eeaacc8c7a3a9506fb55501e7 (diff) |
Merge branch 'bvl-improve-bare-project-import' into 'master'
Make the import take subgroups into account
Closes #36664 and #30546
See merge request !13670
Diffstat (limited to 'app')
-rw-r--r-- | app/services/groups/nested_create_service.rb | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/app/services/groups/nested_create_service.rb b/app/services/groups/nested_create_service.rb new file mode 100644 index 00000000000..8d793f5c02e --- /dev/null +++ b/app/services/groups/nested_create_service.rb @@ -0,0 +1,45 @@ +module Groups + class NestedCreateService < Groups::BaseService + attr_reader :group_path + + def initialize(user, params) + @current_user, @params = user, params.dup + + @group_path = @params.delete(:group_path) + end + + def execute + return nil unless group_path + + if group = Group.find_by_full_path(group_path) + return group + end + + create_group_path + end + + private + + def create_group_path + group_path_segments = group_path.split('/') + + last_group = nil + partial_path_segments = [] + while subgroup_name = group_path_segments.shift + partial_path_segments << subgroup_name + partial_path = partial_path_segments.join('/') + + new_params = params.reverse_merge( + path: subgroup_name, + name: subgroup_name, + parent: last_group + ) + new_params[:visibility_level] ||= Gitlab::CurrentSettings.current_application_settings.default_group_visibility + + last_group = Group.find_by_full_path(partial_path) || Groups::CreateService.new(current_user, new_params).execute + end + + last_group + end + end +end |