From 34675da6fafd0f3fb4344a95b2dc94532a814811 Mon Sep 17 00:00:00 2001 From: Sojan Jose Date: Wed, 13 Dec 2023 13:16:24 -0800 Subject: [PATCH] feat: Settings screen for custom branding (#8543) - Ability to configure Chatwoot custom branding from UI when using paid plans Co-authored-by: Nithin David Thomas <1277421+nithindavid@users.noreply.github.com> --- .../super_admin/app_configs_controller.rb | 29 +++++++++++++++---- .../super_admin/app_configs/show.html.erb | 6 ++-- .../super_admin/application/_icons.html.erb | 4 +++ app/views/super_admin/settings/show.html.erb | 12 +++++++- .../super_admin/app_configs_controller.rb | 23 +++++++++++++++ .../app/helpers/super_admin/features.yml | 6 ++++ .../super_admin/app_config_controller_spec.rb | 8 ++--- 7 files changed, 74 insertions(+), 14 deletions(-) create mode 100644 enterprise/app/controllers/enterprise/super_admin/app_configs_controller.rb diff --git a/app/controllers/super_admin/app_configs_controller.rb b/app/controllers/super_admin/app_configs_controller.rb index 2899a7defce4..ce06879c571d 100644 --- a/app/controllers/super_admin/app_configs_controller.rb +++ b/app/controllers/super_admin/app_configs_controller.rb @@ -1,21 +1,38 @@ class SuperAdmin::AppConfigsController < SuperAdmin::ApplicationController + before_action :set_config + before_action :allowed_configs def show - @allowed_configs = %w[FB_APP_ID FB_VERIFY_TOKEN FB_APP_SECRET] # ref: https://github.com/rubocop/rubocop/issues/7767 # rubocop:disable Style/HashTransformValues - @fb_config = InstallationConfig.where(name: @allowed_configs) - .pluck(:name, :serialized_value) - .map { |name, serialized_value| [name, serialized_value['value']] } - .to_h + @app_config = InstallationConfig.where(name: @allowed_configs) + .pluck(:name, :serialized_value) + .map { |name, serialized_value| [name, serialized_value['value']] } + .to_h # rubocop:enable Style/HashTransformValues end def create params['app_config'].each do |key, value| + next unless @allowed_configs.include?(key) + i = InstallationConfig.where(name: key).first_or_create(value: value, locked: false) i.value = value i.save! end - redirect_to super_admin_app_config_url + # rubocop:disable Rails/I18nLocaleTexts + redirect_to super_admin_settings_path, notice: 'App Configs updated successfully' + # rubocop:enable Rails/I18nLocaleTexts + end + + private + + def set_config + @config = params[:config] + end + + def allowed_configs + @allowed_configs = %w[FB_APP_ID FB_VERIFY_TOKEN FB_APP_SECRET] end end + +SuperAdmin::AppConfigsController.prepend_mod_with('SuperAdmin::AppConfigsController') diff --git a/app/views/super_admin/app_configs/show.html.erb b/app/views/super_admin/app_configs/show.html.erb index 6fb4a44faec2..a23b33d7f511 100644 --- a/app/views/super_admin/app_configs/show.html.erb +++ b/app/views/super_admin/app_configs/show.html.erb @@ -1,5 +1,5 @@ <% content_for(:title) do %> - App Config + Configure Settings <% end %>
- <%= form_with url: super_admin_app_config_url , method: :post do |form| %> + <%= form_with url: super_admin_app_config_url(config: @config) , method: :post do |form| %> <% @allowed_configs.each do |c| %>
<%= form.label "app_config[#{c}]", c %>
- <%= form.text_field "app_config[#{c}]", value: @fb_config[c] %> + <%= form.text_field "app_config[#{c}]", value: @app_config[c] %>
<% end %> diff --git a/app/views/super_admin/application/_icons.html.erb b/app/views/super_admin/application/_icons.html.erb index ac375193f0ed..54f3fbad14ad 100644 --- a/app/views/super_admin/application/_icons.html.erb +++ b/app/views/super_admin/application/_icons.html.erb @@ -135,4 +135,8 @@ + + + + diff --git a/app/views/super_admin/settings/show.html.erb b/app/views/super_admin/settings/show.html.erb index b512c31378e9..7609575a2259 100644 --- a/app/views/super_admin/settings/show.html.erb +++ b/app/views/super_admin/settings/show.html.erb @@ -79,7 +79,17 @@ <% end %>
-

<%= attrs[:name] %>

+
+

<%= attrs[:name] %>

+ <% if attrs[:enterprise] %> + EE + <% end %> + <% if attrs[:config_key].present? && attrs[:enabled] %> + + + + <% end %> +

<%= attrs[:description] %>

diff --git a/enterprise/app/controllers/enterprise/super_admin/app_configs_controller.rb b/enterprise/app/controllers/enterprise/super_admin/app_configs_controller.rb new file mode 100644 index 000000000000..c8a42e391c8c --- /dev/null +++ b/enterprise/app/controllers/enterprise/super_admin/app_configs_controller.rb @@ -0,0 +1,23 @@ +module Enterprise::SuperAdmin::AppConfigsController + private + + def allowed_configs + return super if ChatwootHub.pricing_plan == 'community' + + case @config + when 'custom_branding' + @allowed_configs = %w[ + LOGO_THUMBNAIL + LOGO + BRAND_NAME + INSTALLATION_NAME + BRAND_URL + WIDGET_BRAND_URL + TERMS_URL + PRIVACY_URL + ] + else + super + end + end +end diff --git a/enterprise/app/helpers/super_admin/features.yml b/enterprise/app/helpers/super_admin/features.yml index dd7b556fbf95..41e5af426671 100644 --- a/enterprise/app/helpers/super_admin/features.yml +++ b/enterprise/app/helpers/super_admin/features.yml @@ -3,21 +3,26 @@ custom_branding: description: 'Apply your own branding to this installation.' enabled: <%= (ChatwootHub.pricing_plan != 'community') %> icon: 'icon-paint-brush-line' + config_key: 'custom_branding' + enterprise: true agent_capacity: name: 'Agent Capacity' description: 'Set limits to auto-assigning conversations to your agents.' enabled: <%= (ChatwootHub.pricing_plan != 'community') %> icon: 'icon-hourglass-line' + enterprise: true audit_logs: name: 'Audit Logs' description: 'Track and trace account activities with ease with detailed audit logs.' enabled: <%= (ChatwootHub.pricing_plan != 'community') %> icon: 'icon-menu-search-line' + enterprise: true disable_branding: name: 'Disable Branding' description: 'Disable branding on live-chat widget and external emails.' enabled: <%= (ChatwootHub.pricing_plan != 'community') %> icon: 'icon-sailbot-fill' + enterprise: true live_chat: name: 'Live Chat' description: 'Improve your customer experience using a live chat on your website.' @@ -33,6 +38,7 @@ messenger: description: 'Stay connected with your customers on Facebook & Instagram.' enabled: true icon: 'icon-messenger-line' + config_key: 'facebook' whatsapp: name: 'WhatsApp' description: 'Manage your WhatsApp business interactions from Chatwoot.' diff --git a/spec/controllers/super_admin/app_config_controller_spec.rb b/spec/controllers/super_admin/app_config_controller_spec.rb index 3d6df46a8b72..338c3e611325 100644 --- a/spec/controllers/super_admin/app_config_controller_spec.rb +++ b/spec/controllers/super_admin/app_config_controller_spec.rb @@ -34,13 +34,13 @@ 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: { TESTKEY: 'TESTVALUE' } } + post '/super_admin/app_config', params: { app_config: { FB_APP_ID: 'FB_APP_ID' } } expect(response).to have_http_status(:found) - expect(response).to redirect_to(super_admin_app_config_path) + expect(response).to redirect_to(super_admin_settings_path) - config = GlobalConfig.get('TESTKEY') - expect(config['TESTKEY']).to eq('TESTVALUE') + config = GlobalConfig.get('FB_APP_ID') + expect(config['FB_APP_ID']).to eq('FB_APP_ID') end end end