2020-01-27 17:10:29 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Settings are saved in two database tables: Settings and HistoryValues.
|
|
|
|
# Due to the way the controller updates the settings, we cannot safely use ActiveRecord's callbacks (eg. after_update, after_commit...)
|
|
|
|
# so this service provides a wrapper around these operations.
|
|
|
|
class SettingService
|
2020-06-09 18:51:57 +02:00
|
|
|
def self.after_update(setting)
|
2020-01-27 17:10:29 +01:00
|
|
|
# update the stylesheet
|
|
|
|
Stylesheet.theme&.rebuild! if %w[main_color secondary_color].include? setting.name
|
|
|
|
Stylesheet.home_page&.rebuild! if setting.name == 'home_css'
|
|
|
|
|
|
|
|
# notify about a change in privacy policy
|
|
|
|
NotifyPrivacyUpdateWorker.perform_async(id) if setting.name == 'privacy_body'
|
2020-06-09 14:27:18 +02:00
|
|
|
|
|
|
|
# sync all users on stripe
|
2020-06-10 11:02:30 +02:00
|
|
|
SyncMembersOnStripeWorker.perform_async(setting.history_values.last&.invoicing_profile&.user&.id) if setting.name == 'stripe_secret_key'
|
2020-01-27 17:10:29 +01:00
|
|
|
end
|
|
|
|
end
|