diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-04-24 19:28:04 +0300 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-05-04 14:52:55 +0300 |
commit | 3d6d0a09b65f032bbe1bd5ad4736dd764195bbe1 (patch) | |
tree | 72225f4bd77687266020a1391b5604478b67318c /app/services | |
parent | cf37bef287d7dd5d2dce3e2276489767b8c0671f (diff) |
Store application wide terms
This allows admins to define terms in the application settings.
Every time the terms are adjusted, a new version is stored and becomes
the 'active' version. This allows tracking which specific version was
accepted by a user.
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/application_settings/update_service.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/app/services/application_settings/update_service.rb b/app/services/application_settings/update_service.rb index 61589a07250..d6d3a661dab 100644 --- a/app/services/application_settings/update_service.rb +++ b/app/services/application_settings/update_service.rb @@ -1,7 +1,22 @@ module ApplicationSettings class UpdateService < ApplicationSettings::BaseService def execute + update_terms(@params.delete(:terms)) + @application_setting.update(@params) end + + private + + def update_terms(terms) + return unless terms.present? + + # Avoid creating a new terms record if the text is exactly the same. + terms = terms.strip + return if terms == @application_setting.terms + + ApplicationSetting::Term.create(terms: terms) + @application_setting.reset_memoized_terms + end end end |