feat: account onboarding with clearbit (#8857)
* feat: add clearbit lookup * chore: fix typo in .env.example * refactor: split lookup to reduce cognitive complexity * feat: add more fields to lookup * feat: extend accounts controller * feat: save extra data to custom_attributes * feat: allow v2 update with custom_attributes * feat: add update route * refactor: reduce complexity * feat: move update to v1 controller * test: add locale test * feat: remove update from routes * test: update API for custom attributes * test: all custom attributes * fix: v2 tests * test: enterprise accounts controller * fix: clearbit payload * fix: with modified env * feat: allow custom attributes updates to profile * refactor: reduce complexity * feat: allow clearbit api key in installation config * refactor: move clearbit to internal * feat: allow clearbit * chore: add display_title for June * feat: allow more internal options * refactor: use globalconfig to fetch clearbit token * test: move response body to a factory * refactor: update ops * chore: remove clearbit from .env.example * chore: apply suggestions from code review Co-authored-by: sojan-official <sojan@chatwoot.com> --------- Co-authored-by: sojan-official <sojan@chatwoot.com>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
module Enterprise::Api::V2::AccountsController
|
||||
private
|
||||
|
||||
def fetch_account_and_user_info
|
||||
data = fetch_from_clearbit
|
||||
|
||||
return if data.blank?
|
||||
|
||||
update_user_info(data)
|
||||
update_account_info(data)
|
||||
end
|
||||
|
||||
def fetch_from_clearbit
|
||||
Enterprise::ClearbitLookupService.lookup(@user.email)
|
||||
rescue StandardError => e
|
||||
Rails.logger.error "Error fetching data from clearbit: #{e}"
|
||||
nil
|
||||
end
|
||||
|
||||
def update_user_info(data)
|
||||
@user.update!(name: data[:name])
|
||||
end
|
||||
|
||||
def update_account_info(data)
|
||||
@account.update!(
|
||||
name: data[:company_name],
|
||||
custom_attributes: @account.custom_attributes.merge(
|
||||
'industry' => data[:industry],
|
||||
'company_size' => data[:company_size],
|
||||
'timezone' => data[:timezone],
|
||||
'logo' => data[:logo]
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
@@ -6,20 +6,30 @@ module Enterprise::SuperAdmin::AppConfigsController
|
||||
|
||||
case @config
|
||||
when 'custom_branding'
|
||||
@allowed_configs = %w[
|
||||
LOGO_THUMBNAIL
|
||||
LOGO
|
||||
LOGO_DARK
|
||||
BRAND_NAME
|
||||
INSTALLATION_NAME
|
||||
BRAND_URL
|
||||
WIDGET_BRAND_URL
|
||||
TERMS_URL
|
||||
PRIVACY_URL
|
||||
DISPLAY_MANIFEST
|
||||
]
|
||||
@allowed_configs = custom_branding_options
|
||||
when 'internal'
|
||||
@allowed_configs = internal_config_options
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def custom_branding_options
|
||||
%w[
|
||||
LOGO_THUMBNAIL
|
||||
LOGO
|
||||
LOGO_DARK
|
||||
BRAND_NAME
|
||||
INSTALLATION_NAME
|
||||
BRAND_URL
|
||||
WIDGET_BRAND_URL
|
||||
TERMS_URL
|
||||
PRIVACY_URL
|
||||
DISPLAY_MANIFEST
|
||||
]
|
||||
end
|
||||
|
||||
def internal_config_options
|
||||
%w[CHATWOOT_INBOX_TOKEN CHATWOOT_INBOX_HMAC_KEY ANALYTICS_TOKEN CLEARBIT_API_KEY]
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user