2015-02-05 13:31:36 -05:00
|
|
|
class Import::BaseController < ApplicationController
|
|
|
|
private
|
|
|
|
|
2017-04-05 06:09:31 -04:00
|
|
|
def find_or_create_namespace(names, owner)
|
|
|
|
return current_user.namespace if names == owner
|
2016-08-30 13:34:37 -04:00
|
|
|
return current_user.namespace unless current_user.can_create_group?
|
2016-08-29 17:17:11 -04:00
|
|
|
|
2017-04-05 06:09:31 -04:00
|
|
|
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
|
2015-02-05 13:31:36 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|