2021-12-10 10:10:24 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Gitlab::Seeder::Crm
|
|
|
|
attr_reader :group, :organizations_per_group, :contacts_per_group
|
|
|
|
|
|
|
|
def initialize(group, organizations_per_group: 10, contacts_per_group: 40)
|
|
|
|
@group = group
|
|
|
|
@organizations_per_group = organizations_per_group
|
|
|
|
@contacts_per_group = contacts_per_group
|
|
|
|
end
|
|
|
|
|
|
|
|
def seed!
|
|
|
|
organization_ids = []
|
|
|
|
|
2021-12-10 22:13:45 -05:00
|
|
|
organizations_per_group.times do |index|
|
2021-12-10 10:10:24 -05:00
|
|
|
organization_ids << ::CustomerRelations::Organization.create!(
|
|
|
|
group_id: group.id,
|
2021-12-10 22:13:45 -05:00
|
|
|
name: "#{FFaker::Company.name}-#{index}"
|
2021-12-10 10:10:24 -05:00
|
|
|
).id
|
|
|
|
|
|
|
|
print '.'
|
|
|
|
end
|
|
|
|
|
|
|
|
contacts_per_group.times do |index|
|
|
|
|
first_name = FFaker::Name.first_name
|
|
|
|
last_name = FFaker::Name.last_name
|
|
|
|
organization_id = index % 3 == 0 ? organization_ids.sample : nil
|
|
|
|
::CustomerRelations::Contact.create!(
|
|
|
|
group_id: group.id,
|
|
|
|
first_name: first_name,
|
|
|
|
last_name: last_name,
|
2022-03-22 08:07:28 -04:00
|
|
|
email: "#{first_name}.#{last_name}-#{index}@example.org",
|
2021-12-10 10:10:24 -05:00
|
|
|
organization_id: organization_id
|
|
|
|
)
|
|
|
|
|
|
|
|
print '.'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Gitlab::Seeder.quiet do
|
|
|
|
puts "\nGenerating group crm organizations and contacts"
|
|
|
|
|
2022-03-28 20:09:12 -04:00
|
|
|
Group.not_mass_generated.where('parent_id IS NULL').first(10).each do |group|
|
2021-12-10 10:10:24 -05:00
|
|
|
Gitlab::Seeder::Crm.new(group).seed!
|
|
|
|
end
|
|
|
|
end
|