2020-01-22 11:53:40 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Setting is a configuration element of the platform. Only administrators are allowed to modify Settings
|
|
|
|
# For some settings, changing them will involve some callback actions (like rebuilding the stylesheets if the theme color Setting is changed).
|
|
|
|
# A full history of the previous values is kept in database with the date and the author of the change
|
2020-01-27 17:10:29 +01:00
|
|
|
# after_update callback is handled by SettingService
|
2020-03-25 10:16:47 +01:00
|
|
|
class Setting < ApplicationRecord
|
2018-12-17 16:02:02 +01:00
|
|
|
has_many :history_values
|
2016-03-23 18:39:41 +01:00
|
|
|
validates :name, inclusion:
|
2018-12-17 16:02:02 +01:00
|
|
|
{ in: %w[about_title
|
2016-03-23 18:39:41 +01:00
|
|
|
about_body
|
|
|
|
about_contacts
|
2019-04-18 15:57:56 +02:00
|
|
|
privacy_draft
|
2019-04-18 12:30:00 +02:00
|
|
|
privacy_body
|
|
|
|
privacy_dpo
|
2016-03-23 18:39:41 +01:00
|
|
|
twitter_name
|
|
|
|
home_blogpost
|
|
|
|
machine_explications_alert
|
|
|
|
training_explications_alert
|
|
|
|
training_information_message
|
|
|
|
subscription_explications_alert
|
|
|
|
invoice_logo
|
|
|
|
invoice_reference
|
|
|
|
invoice_code-active
|
|
|
|
invoice_code-value
|
|
|
|
invoice_order-nb
|
|
|
|
invoice_VAT-active
|
|
|
|
invoice_VAT-rate
|
|
|
|
invoice_text
|
|
|
|
invoice_legals
|
|
|
|
booking_window_start
|
|
|
|
booking_window_end
|
|
|
|
booking_slot_duration
|
|
|
|
booking_move_enable
|
|
|
|
booking_move_delay
|
|
|
|
booking_cancel_enable
|
|
|
|
booking_cancel_delay
|
|
|
|
main_color
|
|
|
|
secondary_color
|
|
|
|
fablab_name
|
2016-08-17 12:49:52 +02:00
|
|
|
name_genre
|
|
|
|
reminder_enable
|
2016-11-29 16:46:19 +01:00
|
|
|
reminder_delay
|
2017-02-15 09:48:27 +01:00
|
|
|
event_explications_alert
|
2017-08-24 18:34:18 +02:00
|
|
|
space_explications_alert
|
|
|
|
visibility_yearly
|
2018-07-24 12:24:51 +02:00
|
|
|
visibility_others
|
2018-09-18 15:30:54 +02:00
|
|
|
display_name_enable
|
2019-07-30 16:06:35 +02:00
|
|
|
machines_sort_by
|
|
|
|
accounting_journal_code
|
2019-09-17 12:35:34 +02:00
|
|
|
accounting_card_client_code
|
|
|
|
accounting_card_client_label
|
2019-09-19 11:51:14 +02:00
|
|
|
accounting_wallet_client_code
|
|
|
|
accounting_wallet_client_label
|
|
|
|
accounting_other_client_code
|
|
|
|
accounting_other_client_label
|
2019-07-30 16:06:35 +02:00
|
|
|
accounting_wallet_code
|
|
|
|
accounting_wallet_label
|
|
|
|
accounting_VAT_code
|
|
|
|
accounting_VAT_label
|
|
|
|
accounting_subscription_code
|
|
|
|
accounting_subscription_label
|
|
|
|
accounting_Machine_code
|
|
|
|
accounting_Machine_label
|
|
|
|
accounting_Training_code
|
|
|
|
accounting_Training_label
|
|
|
|
accounting_Event_code
|
|
|
|
accounting_Event_label
|
|
|
|
accounting_Space_code
|
2020-01-13 17:05:53 +01:00
|
|
|
accounting_Space_label
|
|
|
|
hub_last_version
|
2020-01-15 10:46:04 +01:00
|
|
|
hub_public_key
|
2020-01-21 16:16:12 +01:00
|
|
|
fab_analytics
|
2020-01-22 11:53:40 +01:00
|
|
|
link_name
|
2020-01-27 17:10:29 +01:00
|
|
|
home_content
|
2020-04-07 17:53:19 +02:00
|
|
|
home_css
|
|
|
|
origin
|
|
|
|
uuid] }
|
2018-12-17 16:02:02 +01:00
|
|
|
def value
|
|
|
|
last_value = history_values.order(HistoryValue.arel_table['created_at'].desc).first
|
|
|
|
last_value&.value
|
|
|
|
end
|
2016-03-23 18:39:41 +01:00
|
|
|
|
2019-04-23 12:58:01 +02:00
|
|
|
def last_update
|
|
|
|
last_value = history_values.order(HistoryValue.arel_table['created_at'].desc).first
|
|
|
|
last_value&.created_at
|
|
|
|
end
|
|
|
|
|
2018-12-17 16:02:02 +01:00
|
|
|
def value=(val)
|
|
|
|
admin = User.admins.first
|
2019-06-03 16:51:43 +02:00
|
|
|
save && history_values.create(invoicing_profile: admin.invoicing_profile, value: val)
|
2018-12-17 16:02:02 +01:00
|
|
|
end
|
2016-03-23 18:39:41 +01:00
|
|
|
end
|