1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/app/services/setting_service.rb
2020-06-09 18:51:57 +02:00

23 lines
902 B
Ruby

# 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
def self.after_update(setting)
# 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'
# sync all users on stripe
return unless %w[stripe_public_key stripe_secret_key].include? setting.name
SyncMembersOnStripeWorker.perform_async(
setting.history_values.last&.invoicing_profile&.user&.id
)
end
end