e310230f62
- Remove duplicate code and move everything to builders - fixes: #4680
83 lines
2.4 KiB
Ruby
83 lines
2.4 KiB
Ruby
# loading installation configs
|
|
GlobalConfig.clear_cache
|
|
ConfigLoader.new.process
|
|
|
|
## Seeds productions
|
|
if Rails.env.production?
|
|
# Setup Onboarding flow
|
|
::Redis::Alfred.set(::Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING, true)
|
|
end
|
|
|
|
## Seeds for Local Development
|
|
unless Rails.env.production?
|
|
|
|
# Enables creating additional accounts from dashboard
|
|
installation_config = InstallationConfig.find_by(name: 'CREATE_NEW_ACCOUNT_FROM_DASHBOARD')
|
|
installation_config.value = true
|
|
installation_config.save!
|
|
GlobalConfig.clear_cache
|
|
|
|
account = Account.create!(
|
|
name: 'Acme Inc'
|
|
)
|
|
|
|
secondary_account = Account.create!(
|
|
name: 'Acme Org'
|
|
)
|
|
|
|
user = User.new(name: 'John', email: 'john@acme.inc', password: 'Password1!', type: 'SuperAdmin')
|
|
user.skip_confirmation!
|
|
user.save!
|
|
|
|
AccountUser.create!(
|
|
account_id: account.id,
|
|
user_id: user.id,
|
|
role: :administrator
|
|
)
|
|
|
|
AccountUser.create!(
|
|
account_id: secondary_account.id,
|
|
user_id: user.id,
|
|
role: :administrator
|
|
)
|
|
|
|
web_widget = Channel::WebWidget.create!(account: account, website_url: 'https://acme.inc')
|
|
|
|
inbox = Inbox.create!(channel: web_widget, account: account, name: 'Acme Support')
|
|
InboxMember.create!(user: user, inbox: inbox)
|
|
|
|
contact = ::ContactInboxWithContactBuilder.new(
|
|
source_id: user.id,
|
|
inbox: inbox,
|
|
hmac_verified: true,
|
|
contact_attributes: { name: 'jane', email: 'jane@example.com', phone_number: '+2320000' }
|
|
).perform&.contact
|
|
|
|
conversation = Conversation.create!(
|
|
account: account,
|
|
inbox: inbox,
|
|
status: :open,
|
|
assignee: user,
|
|
contact: contact,
|
|
contact_inbox: contact_inbox,
|
|
additional_attributes: {}
|
|
)
|
|
|
|
# sample email collect
|
|
Seeders::MessageSeeder.create_sample_email_collect_message conversation
|
|
|
|
Message.create!(content: 'Hello', account: account, inbox: inbox, conversation: conversation, message_type: :incoming)
|
|
|
|
# sample card
|
|
Seeders::MessageSeeder.create_sample_cards_message conversation
|
|
# input select
|
|
Seeders::MessageSeeder.create_sample_input_select_message conversation
|
|
# form
|
|
Seeders::MessageSeeder.create_sample_form_message conversation
|
|
# articles
|
|
Seeders::MessageSeeder.create_sample_articles_message conversation
|
|
# csat
|
|
Seeders::MessageSeeder.create_sample_csat_collect_message conversation
|
|
|
|
CannedResponse.create!(account: account, short_code: 'start', content: 'Hello welcome to chatwoot.')
|
|
end
|