diff options
author | James Lopez <james@gitlab.com> | 2017-04-05 13:09:31 +0300 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2017-04-05 13:09:31 +0300 |
commit | bdcd23b297a0234afcb8aae32bc215e827da09fc (patch) | |
tree | 6684b898400b27b995db5b243059a1da5f392c03 /app/controllers/import | |
parent | 65ea732cfebd7efe5a0ae9b31eef4349c38cfa4b (diff) |
Create subgroups if they don't exist while importing projects
Diffstat (limited to 'app/controllers/import')
-rw-r--r-- | app/controllers/import/base_controller.rb | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/app/controllers/import/base_controller.rb b/app/controllers/import/base_controller.rb index eeee027ef2d..9de0297ecfd 100644 --- a/app/controllers/import/base_controller.rb +++ b/app/controllers/import/base_controller.rb @@ -1,17 +1,27 @@ class Import::BaseController < ApplicationController private - def find_or_create_namespace(name, owner) - return current_user.namespace if name == owner + def find_or_create_namespace(names, owner) + return current_user.namespace if names == owner return current_user.namespace unless current_user.can_create_group? - begin - name = params[:target_namespace].presence || name - namespace = Group.create!(name: name, path: name, owner: current_user) - namespace.add_owner(current_user) - namespace - rescue ActiveRecord::RecordNotUnique, ActiveRecord::RecordInvalid - Namespace.find_by_full_path(name) + names = params[:target_namespace].presence || names + full_path_namespace = Namespace.find_by_full_path(names) + + return full_path_namespace if full_path_namespace + + names.split('/').inject(nil) do |parent, name| + begin + namespace = Group.create!(name: name, + path: name, + owner: current_user, + parent: parent) + namespace.add_owner(current_user) + + namespace + rescue ActiveRecord::RecordNotUnique, ActiveRecord::RecordInvalid + Namespace.where(parent: parent).find_by_path_or_name(name) + end end end end |