summaryrefslogtreecommitdiff
path: root/app/controllers/import/base_controller.rb
blob: eeee027ef2d8ada7200c4a19778341877fdad240 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Import::BaseController < ApplicationController
  private

  def find_or_create_namespace(name, owner)
    return current_user.namespace if name == 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)
    end
  end
end