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:
Sojan Jose
2024-01-31 16:48:42 +04:00
committed by GitHub
parent ee3f734b7b
commit 390cd756e8
20 changed files with 398 additions and 62 deletions

View File

@@ -16,9 +16,9 @@ RSpec.describe 'Super Admin Application Config API', type: :request do
it 'shows the app_config page' do
sign_in(super_admin, scope: :super_admin)
get '/super_admin/app_config'
get '/super_admin/app_config?config=facebook'
expect(response).to have_http_status(:success)
expect(response.body).to include(config.name)
expect(response.body).to include(config.value)
end
end
end
@@ -34,7 +34,7 @@ RSpec.describe 'Super Admin Application Config API', type: :request do
context 'when it is an aunthenticated super admin' do
it 'shows the app_config page' do
sign_in(super_admin, scope: :super_admin)
post '/super_admin/app_config', params: { app_config: { FB_APP_ID: 'FB_APP_ID' } }
post '/super_admin/app_config?config=facebook', params: { app_config: { FB_APP_ID: 'FB_APP_ID' } }
expect(response).to have_http_status(:found)
expect(response).to redirect_to(super_admin_settings_path)

View File

@@ -0,0 +1,32 @@
require 'rails_helper'
RSpec.describe Internal::CheckNewVersionsJob do
subject(:job) { described_class.perform_now }
let(:reconsile_premium_config_service) { instance_double(Internal::ReconcilePlanConfigService) }
before do
allow(Internal::ReconcilePlanConfigService).to receive(:new).and_return(reconsile_premium_config_service)
allow(reconsile_premium_config_service).to receive(:perform)
allow(Rails.env).to receive(:production?).and_return(true)
end
it 'updates the plan info' do
data = { 'version' => '1.2.3', 'plan' => 'enterprise', 'plan_quantity' => 1, 'chatwoot_support_website_token' => '123',
'chatwoot_support_identifier_hash' => '123', 'chatwoot_support_script_url' => '123' }
allow(ChatwootHub).to receive(:sync_with_hub).and_return(data)
job
expect(InstallationConfig.find_by(name: 'INSTALLATION_PRICING_PLAN').value).to eq 'enterprise'
expect(InstallationConfig.find_by(name: 'INSTALLATION_PRICING_PLAN_QUANTITY').value).to eq 1
expect(InstallationConfig.find_by(name: 'CHATWOOT_SUPPORT_WEBSITE_TOKEN').value).to eq '123'
expect(InstallationConfig.find_by(name: 'CHATWOOT_SUPPORT_IDENTIFIER_HASH').value).to eq '123'
expect(InstallationConfig.find_by(name: 'CHATWOOT_SUPPORT_SCRIPT_URL').value).to eq '123'
end
it 'calls Internal::ReconcilePlanConfigService' do
data = { 'version' => '1.2.3' }
allow(ChatwootHub).to receive(:sync_with_hub).and_return(data)
job
expect(reconsile_premium_config_service).to have_received(:perform)
end
end

View File

@@ -0,0 +1,81 @@
require 'rails_helper'
RSpec.describe Internal::ReconcilePlanConfigService do
describe '#perform' do
let(:service) { described_class.new }
context 'when pricing plan is community' do
before do
allow(ChatwootHub).to receive(:pricing_plan).and_return('community')
end
it 'disables the premium features for accounts' do
account = create(:account)
account.enable_features!('disable_branding', 'audit_logs', 'response_bot')
response_bot_account = create(:account)
response_bot_account.enable_features!('response_bot')
disable_branding_account = create(:account)
disable_branding_account.enable_features!('disable_branding')
service.perform
expect(account.reload.enabled_features.keys).not_to include('response_bot', 'disable_branding', 'audit_logs')
expect(response_bot_account.reload.enabled_features.keys).not_to include('response_bot')
expect(disable_branding_account.reload.enabled_features.keys).not_to include('disable_branding')
end
it 'creates a premium config reset warning if config was modified' do
create(:installation_config, name: 'INSTALLATION_NAME', value: 'custom-name')
service.perform
expect(Redis::Alfred.get(Redis::Alfred::CHATWOOT_INSTALLATION_CONFIG_RESET_WARNING)).to eq('true')
end
it 'will not create a premium config reset warning if config is not modified' do
create(:installation_config, name: 'INSTALLATION_NAME', value: 'Chatwoot')
service.perform
expect(Redis::Alfred.get(Redis::Alfred::CHATWOOT_INSTALLATION_CONFIG_RESET_WARNING)).to be_nil
end
# To be enabled in the future when method is uncommented
# it 'updates the premium configs to default' do
# create(:installation_config, name: 'INSTALLATION_NAME', value: 'custom-name')
# create(:installation_config, name: 'LOGO', value: '/custom-path/logo.svg')
# service.perform
# expect(InstallationConfig.find_by(name: 'INSTALLATION_NAME').value).to eq('Chatwoot')
# expect(InstallationConfig.find_by(name: 'LOGO').value).to eq('/brand-assets/logo.svg')
# end
end
context 'when pricing plan is not community' do
before do
allow(ChatwootHub).to receive(:pricing_plan).and_return('enterprise')
end
it 'unset premium config warning on upgrade' do
Redis::Alfred.set(Redis::Alfred::CHATWOOT_INSTALLATION_CONFIG_RESET_WARNING, true)
service.perform
expect(Redis::Alfred.get(Redis::Alfred::CHATWOOT_INSTALLATION_CONFIG_RESET_WARNING)).to be_nil
end
it 'does not disable the premium features for accounts' do
account = create(:account)
account.enable_features!('disable_branding', 'audit_logs', 'response_bot')
response_bot_account = create(:account)
response_bot_account.enable_features!('response_bot')
disable_branding_account = create(:account)
disable_branding_account.enable_features!('disable_branding')
service.perform
expect(account.reload.enabled_features.keys).to include('response_bot', 'disable_branding', 'audit_logs')
expect(response_bot_account.reload.enabled_features.keys).to include('response_bot')
expect(disable_branding_account.reload.enabled_features.keys).to include('disable_branding')
end
it 'does not update the LOGO config' do
create(:installation_config, name: 'INSTALLATION_NAME', value: 'custom-name')
create(:installation_config, name: 'LOGO', value: '/custom-path/logo.svg')
service.perform
expect(InstallationConfig.find_by(name: 'INSTALLATION_NAME').value).to eq('custom-name')
expect(InstallationConfig.find_by(name: 'LOGO').value).to eq('/custom-path/logo.svg')
end
end
end
end

View File

@@ -4,7 +4,7 @@ RSpec.describe Internal::CheckNewVersionsJob do
subject(:job) { described_class.perform_now }
it 'updates the latest chatwoot version in redis' do
data = { 'version' => '1.2.3' }.to_json
data = { 'version' => '1.2.3' }
allow(Rails.env).to receive(:production?).and_return(true)
allow(ChatwootHub).to receive(:sync_with_hub).and_return(data)
job