chore: Reorganize the installation config settings (#8794)
- Reorganizing installation config settings to move more configurations into UI from environment variables - Changes to installation config to support premium plans in the enterprise edition - Fixes the broken premium indicator in account/show and accounts/edit page
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
# TODO: Move this values to features.yml itself
|
||||
# No need to replicate the same values in two places
|
||||
custom_branding:
|
||||
name: 'Custom Branding'
|
||||
description: 'Apply your own branding to this installation.'
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
module Enterprise::Internal::CheckNewVersionsJob
|
||||
def perform
|
||||
super
|
||||
update_plan_info
|
||||
reconcile_premium_config_and_features
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_plan_info
|
||||
return if @instance_info.blank?
|
||||
|
||||
update_installation_config(key: 'INSTALLATION_PRICING_PLAN', value: @instance_info['plan'])
|
||||
update_installation_config(key: 'INSTALLATION_PRICING_PLAN_QUANTITY', value: @instance_info['plan_quantity'])
|
||||
update_installation_config(key: 'CHATWOOT_SUPPORT_WEBSITE_TOKEN', value: @instance_info['chatwoot_support_website_token'])
|
||||
update_installation_config(key: 'CHATWOOT_SUPPORT_IDENTIFIER_HASH', value: @instance_info['chatwoot_support_identifier_hash'])
|
||||
update_installation_config(key: 'CHATWOOT_SUPPORT_SCRIPT_URL', value: @instance_info['chatwoot_support_script_url'])
|
||||
end
|
||||
|
||||
def update_installation_config(key:, value:)
|
||||
config = InstallationConfig.find_or_initialize_by(name: key)
|
||||
config.value = value
|
||||
config.locked = true
|
||||
config.save!
|
||||
end
|
||||
|
||||
def reconcile_premium_config_and_features
|
||||
Internal::ReconcilePlanConfigService.new.perform
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,60 @@
|
||||
class Internal::ReconcilePlanConfigService
|
||||
def perform
|
||||
remove_premium_config_reset_warning
|
||||
return if ChatwootHub.pricing_plan != 'community'
|
||||
|
||||
create_premium_config_reset_warning if premium_config_reset_required?
|
||||
|
||||
# We will have this enabled in the future
|
||||
# reconcile_premium_config
|
||||
reconcile_premium_features
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def config_path
|
||||
@config_path ||= Rails.root.join('enterprise/config')
|
||||
end
|
||||
|
||||
def premium_config
|
||||
@premium_config ||= YAML.safe_load(File.read("#{config_path}/premium_installation_config.yml")).freeze
|
||||
end
|
||||
|
||||
def remove_premium_config_reset_warning
|
||||
Redis::Alfred.delete(Redis::Alfred::CHATWOOT_INSTALLATION_CONFIG_RESET_WARNING)
|
||||
end
|
||||
|
||||
def create_premium_config_reset_warning
|
||||
Redis::Alfred.set(Redis::Alfred::CHATWOOT_INSTALLATION_CONFIG_RESET_WARNING, true)
|
||||
end
|
||||
|
||||
def premium_config_reset_required?
|
||||
premium_config.any? do |config|
|
||||
config = config.with_indifferent_access
|
||||
existing_config = InstallationConfig.find_by(name: config[:name])
|
||||
existing_config&.value != config[:value] if existing_config.present?
|
||||
end
|
||||
end
|
||||
|
||||
def reconcile_premium_config
|
||||
premium_config.each do |config|
|
||||
new_config = config.with_indifferent_access
|
||||
existing_config = InstallationConfig.find_by(name: new_config[:name])
|
||||
next if existing_config&.value == new_config[:value]
|
||||
|
||||
existing_config&.update!(value: new_config[:value])
|
||||
end
|
||||
end
|
||||
|
||||
def premium_features
|
||||
@premium_features ||= YAML.safe_load(File.read("#{config_path}/premium_features.yml")).freeze
|
||||
end
|
||||
|
||||
def reconcile_premium_features
|
||||
Account.find_in_batches do |accounts|
|
||||
accounts.each do |account|
|
||||
account.disable_features!(*premium_features)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
4
enterprise/config/premium_features.yml
Normal file
4
enterprise/config/premium_features.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
# List of the premium features in EE edition
|
||||
- disable_branding
|
||||
- audit_logs
|
||||
- response_bot
|
||||
22
enterprise/config/premium_installation_config.yml
Normal file
22
enterprise/config/premium_installation_config.yml
Normal file
@@ -0,0 +1,22 @@
|
||||
# ------- Branding Related Config ------- #
|
||||
- name: INSTALLATION_NAME
|
||||
value: 'Chatwoot'
|
||||
- name: LOGO_THUMBNAIL
|
||||
value: '/brand-assets/logo_thumbnail.svg'
|
||||
- name: LOGO
|
||||
value: '/brand-assets/logo.svg'
|
||||
- name: LOGO_DARK
|
||||
value: '/brand-assets/logo_dark.svg'
|
||||
- name: BRAND_URL
|
||||
value: 'https://www.chatwoot.com'
|
||||
- name: WIDGET_BRAND_URL
|
||||
value: 'https://www.chatwoot.com'
|
||||
- name: BRAND_NAME
|
||||
value: 'Chatwoot'
|
||||
- name: TERMS_URL
|
||||
value: 'https://www.chatwoot.com/terms-of-service'
|
||||
- name: PRIVACY_URL
|
||||
value: 'https://www.chatwoot.com/privacy-policy'
|
||||
- name: DISPLAY_MANIFEST
|
||||
value: true
|
||||
# ------- End of Branding Related Config ------- #
|
||||
Reference in New Issue
Block a user