Files
gitlabhq/app/controllers/import/base_controller.rb
Dmitriy ZaporozhetsandMarin Jankovski 956a392a21 Merge branch 'fix_importers' into 'master'
Fix importers with OCC

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/1180

Using validates_uniqueness_of does not guarantee the absence of duplicate record insertions. When users click button "import all" it will create duplicating group in database and data integrity will be broken.

http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#method-i-validates_uniqueness_of

I use optimistic concurrency control for handling this situation.

See merge request !1647

Conflicts:
	db/schema.rb
2015-03-11 11:31:15 -07:00

20 lines
530 B
Ruby

class Import::BaseController < ApplicationController
private
def get_or_create_namespace
begin
namespace = Group.create!(name: @target_namespace, path: @target_namespace, owner: current_user)
namespace.add_owner(current_user)
rescue ActiveRecord::RecordNotUnique, ActiveRecord::RecordInvalid
namespace = Namespace.find_by_path_or_name(@target_namespace)
unless namespace.owner == current_user
@already_been_taken = true
return false
end
end
namespace
end
end