cloudfoundry/cloud_controller_ng

View on GitHub
app/actions/isolation_segment_assign.rb

Summary

Maintainability
A
45 mins
Test Coverage
module VCAP::CloudController
  class IsolationSegmentAssign
    def assign(isolation_segment, organizations)
      isolation_segment.db.transaction do
        isolation_segment.lock!(:share)

        organizations.sort! { |o1, o2| o1.id <=> o2.id }.each do |org|
          org.lock!
          isolation_segment.add_organization(org)

          next unless org.default_isolation_segment_model.nil?

          org.update(default_isolation_segment_model: isolation_segment) if isolation_segment.is_shared_segment?
        end
      end
    end
  end
end