1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-29 10:24:20 +01:00
fab-manager/app/models/setting.rb

74 lines
2.7 KiB
Ruby
Raw Normal View History

2016-03-23 18:39:41 +01:00
class Setting < ActiveRecord::Base
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
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
name_genre
reminder_enable
reminder_delay
event_explications_alert
space_explications_alert
visibility_yearly
visibility_others
display_name_enable
2018-12-17 16:02:02 +01:00
machines_sort_by] }
2016-03-23 18:39:41 +01:00
after_update :update_stylesheet, :notify_privacy_policy_changed if :value_changed?
2016-03-23 18:39:41 +01:00
def update_stylesheet
2018-12-17 16:02:02 +01:00
Stylesheet.first&.rebuild! if %w[main_color secondary_color].include? name
2016-03-23 18:39:41 +01:00
end
def notify_privacy_policy_changed
return unless name == 'privacy_body'
NotificationCenter.call type: :notify_privacy_policy_changed,
receiver: User.all,
attached_object: self
end
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
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
save && history_values.create(user: admin, value: val)
end
2016-03-23 18:39:41 +01:00
end