Skip to content

Commit

Permalink
408-three-fold-approach (#489)
Browse files Browse the repository at this point in the history
* leave the default analytics settings until the customer has updated the tenant settings
  • Loading branch information
alishaevn authored May 19, 2023
1 parent 80d1aaf commit 6e3f4d2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
31 changes: 24 additions & 7 deletions app/models/concerns/account_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]'
Expand All @@ -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: '[email protected]'
Expand Down Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions config/analytics.yml
Original file line number Diff line number Diff line change
@@ -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'] %>

0 comments on commit 6e3f4d2

Please sign in to comment.