mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-11 05:36:07 +10:00
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
20 lines
530 B
Ruby
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
|