From 6e3f4d2384f5e4acdc3b994c1206812622a37e0f Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Fri, 19 May 2023 00:28:08 -0500 Subject: [PATCH] 408-three-fold-approach (#489) * leave the default analytics settings until the customer has updated the tenant settings --- app/models/concerns/account_settings.rb | 31 +++++++++++++++++++------ config/analytics.yml | 18 +++++++------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/app/models/concerns/account_settings.rb b/app/models/concerns/account_settings.rb index 89b434b50..742fc541c 100644 --- a/app/models/concerns/account_settings.rb +++ b/app/models/concerns/account_settings.rb @@ -15,6 +15,13 @@ module AccountSettings end setting :allow_signup, type: 'boolean', default: true + setting :analytics_id, type: 'string' + setting :analytics_oauth_app_name, type: 'string' + setting :analytics_oauth_app_version, type: 'string' + setting :analytics_oauth_private_key_secret, type: 'string' + setting :analytics_oauth_private_key_path, type: 'string' + setting :analytics_oauth_private_key_value, type: 'string' + setting :analytics_oauth_client_email, type: 'string' setting :bulkrax_validations, type: 'boolean', disabled: true setting :cache_api, type: 'boolean', default: false setting :contact_email, type: 'string', default: 'consortial-ir@palci.org' @@ -29,13 +36,6 @@ module AccountSettings setting :google_scholarly_work_types, type: 'array', disabled: true setting :geonames_username, type: 'string', default: '' setting :gtm_id, type: 'string' - setting :analytics_id, type: 'string' - setting :analytics_oauth_app_name, type: 'string' - setting :analytics_oauth_app_version, type: 'string' - setting :analytics_oauth_private_key_secret, type: 'string' - setting :analytics_oauth_private_key_path, type: 'string' - setting :analytics_oauth_private_key_value, type: 'string' - setting :analytics_oauth_client_email, type: 'string' setting :locale_name, type: 'string', disabled: true setting :monthly_email_list, type: 'array', disabled: true setting :oai_admin_email, type: 'string', default: 'changeme@example.com' @@ -192,6 +192,23 @@ def reload_library_config end def reload_analytics + # fall back to the default values if they aren't set in the tenant + unless analytics_id.present? && + analytics_oauth_app_name.present? && + analytics_oauth_app_version.present? && + analytics_oauth_private_key_secret.present? && + analytics_oauth_client_email.present? && + (analytics_oauth_private_key_value.present? || analytics_oauth_private_key_path.present?) + + config = Hyrax::Analytics::Config.load_from_yaml + analytics_id ||= config.analytics_id + analytics_oauth_app_name ||= config.app_name + analytics_oauth_app_version ||= config.app_version + analytics_oauth_private_key_secret ||= config.privkey_secret + analytics_oauth_private_key_value ||= config.privkey_value + analytics_oauth_client_email ||= config.client_email + end + # require the analytics to be set per tenant Hyrax::Analytics.config.analytics_id = analytics_id Hyrax::Analytics.config.app_name = analytics_oauth_app_name diff --git a/config/analytics.yml b/config/analytics.yml index 072d6d693..ceb35e167 100644 --- a/config/analytics.yml +++ b/config/analytics.yml @@ -1,12 +1,12 @@ # # To integrate your app with Google Analytics, uncomment the lines below and add your API key information. # -# analytics: -# google: -# analytics_id: <%= ENV['GOOGLE_ANALYTICS_ID'] %> -# app_name: <%= ENV['GOOGLE_OAUTH_APP_NAME'] %> -# app_version: <%= ENV['GOOGLE_OAUTH_APP_VERSION'] %> -# privkey_value: <%= ENV['GOOGLE_OAUTH_PRIVATE_KEY_VALUE'] %> -# # OR privkey_path: <%= ENV['GOOGLE_OAUTH_PRIVATE_KEY_PATH'] %> -# privkey_secret: <%= ENV['GOOGLE_OAUTH_PRIVATE_KEY_SECRET'] %> -# client_email: <%= ENV['GOOGLE_OAUTH_CLIENT_EMAIL'] %> +analytics: + google: + analytics_id: <%= ENV['GOOGLE_ANALYTICS_ID'] %> + app_name: <%= ENV['GOOGLE_OAUTH_APP_NAME'] %> + app_version: <%= ENV['GOOGLE_OAUTH_APP_VERSION'] %> + privkey_value: <%= ENV['GOOGLE_OAUTH_PRIVATE_KEY_VALUE'] %> + # OR privkey_path: <%= ENV['GOOGLE_OAUTH_PRIVATE_KEY_PATH'] %> + privkey_secret: <%= ENV['GOOGLE_OAUTH_PRIVATE_KEY_SECRET'] %> + client_email: <%= ENV['GOOGLE_OAUTH_CLIENT_EMAIL'] %>