From 616e3a8092b3c02acf9f191a6b4d8e9a69c05264 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Thu, 23 May 2024 14:30:41 +0530 Subject: [PATCH] feat: allow setting dashboard scripts from super_admin (#9514) This PR allows setting scripts for `vueapp.html.erb` via super admin config. This PR has the following changes 1. Allow `DASHBOARD_SCRIPTS` in internal config 2. Remove existing scripts from `vueapp.html.erb` 3. Add scripts from `GlobalConfig` to `vueapp.html.erb` --------- Co-authored-by: Muhsin Keloth --- .env.example | 6 ---- app/controllers/dashboard_controller.rb | 5 +++ app/views/layouts/vueapp.html.erb | 36 ++----------------- .../super_admin/app_configs/show.html.erb | 11 ++++-- config/installation_config.yml | 5 +++ .../super_admin/app_configs_controller.rb | 2 +- 6 files changed, 22 insertions(+), 43 deletions(-) diff --git a/.env.example b/.env.example index 26b1487ae7a8..21a72526de85 100644 --- a/.env.example +++ b/.env.example @@ -184,12 +184,6 @@ ANDROID_SHA256_CERT_FINGERPRINT=AC:73:8E:DE:EB:56:EA:CC:10:87:02:A7:65:37:7B:38: # SENTRY_DSN= -# MICROSOFT CLARITY -# MS_CLARITY_TOKEN=xxxxxxxxx - -# GOOGLE_TAG_MANAGER -# GOOGLE_TAG = GTM-XXXXXXX - ## Scout ## https://scoutapm.com/docs/ruby/configuration # SCOUT_KEY=YOURKEY diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 521d027cca34..e656c25501e9 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -3,6 +3,7 @@ class DashboardController < ActionController::Base before_action :set_application_pack before_action :set_global_config + before_action :set_dashboard_scripts around_action :switch_locale before_action :ensure_installation_onboarding, only: [:index] before_action :render_hc_if_custom_domain, only: [:index] @@ -35,6 +36,10 @@ def set_global_config ).merge(app_config) end + def set_dashboard_scripts + @dashboard_scripts = GlobalConfig.get_value('DASHBOARD_SCRIPTS') + end + def ensure_installation_onboarding redirect_to '/installation/onboarding' if ::Redis::Alfred.get(::Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING) end diff --git a/app/views/layouts/vueapp.html.erb b/app/views/layouts/vueapp.html.erb index eb129867c4a2..cf800cda24e5 100644 --- a/app/views/layouts/vueapp.html.erb +++ b/app/views/layouts/vueapp.html.erb @@ -70,40 +70,8 @@
<%= yield %> - <% if @global_config['CHATWOOT_INBOX_TOKEN'].present? %> - - <% end %> - <% if ENV.fetch('MS_CLARITY_TOKEN', nil).present? %> - - <% end %> - <% if ENV.fetch('GOOGLE_TAG', nil).present? %> - + <% if @dashboard_scripts.present? %> + <%= @dashboard_scripts.html_safe %> <% end %> diff --git a/app/views/super_admin/app_configs/show.html.erb b/app/views/super_admin/app_configs/show.html.erb index 83f99f6bd9f9..1754808e5a49 100644 --- a/app/views/super_admin/app_configs/show.html.erb +++ b/app/views/super_admin/app_configs/show.html.erb @@ -13,18 +13,25 @@
<%= form.label "app_config[#{key}]", @installation_configs[key]&.dig('display_title') || key %>
-
+
<% if @installation_configs[key]&.dig('type') == 'boolean' %> <%= form.select "app_config[#{key}]", [["True", true], ["False", false]], { selected: ActiveModel::Type::Boolean.new.cast(@app_config[key]) }, class: "mt-2 border border-slate-100 p-1 rounded-md" %> + <% elsif @installation_configs[key]&.dig('type') == 'code' %> + <%= form.text_area "app_config[#{key}]", + value: @app_config[key], + rows: 12, + wrap: 'off', + class: "mt-2 border font-mono text-xs border-slate-100 p-1 rounded-md overflow-scroll" + %> <% else %> <%= form.text_field "app_config[#{key}]", value: @app_config[key] %> <% end %> <%if @installation_configs[key]&.dig('description').present? %> -

+

<%= @installation_configs[key]&.dig('description') %>

<% end %> diff --git a/config/installation_config.yml b/config/installation_config.yml index b0f4549aa049..419a63352996 100644 --- a/config/installation_config.yml +++ b/config/installation_config.yml @@ -163,6 +163,11 @@ value: display_title: 'Clearbit API Key' description: 'This API key is used for onboarding the users, to pre-fill account data.' +- name: DASHBOARD_SCRIPTS + value: + display_title: 'Dashboard Scripts' + description: 'Scripts are loaded as the last item in the tag' + type: code # ------- End of Chatwoot Internal Config for Cloud ----# # ------- Chatwoot Internal Config for Self Hosted ----# diff --git a/enterprise/app/controllers/enterprise/super_admin/app_configs_controller.rb b/enterprise/app/controllers/enterprise/super_admin/app_configs_controller.rb index ae1394a24d35..39a131ba2d15 100644 --- a/enterprise/app/controllers/enterprise/super_admin/app_configs_controller.rb +++ b/enterprise/app/controllers/enterprise/super_admin/app_configs_controller.rb @@ -30,6 +30,6 @@ def custom_branding_options end def internal_config_options - %w[CHATWOOT_INBOX_TOKEN CHATWOOT_INBOX_HMAC_KEY ANALYTICS_TOKEN CLEARBIT_API_KEY] + %w[CHATWOOT_INBOX_TOKEN CHATWOOT_INBOX_HMAC_KEY ANALYTICS_TOKEN CLEARBIT_API_KEY DASHBOARD_SCRIPTS] end end