Class: Spina::Account

Inherits:
ApplicationRecord show all
Includes:
AttrJson::NestedAttributes, AttrJson::Record, Partable, TranslatedContent
Defined in:
app/models/spina/account.rb

Instance Attribute Summary

Attributes included from Partable

#view_context

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TranslatedContent

#find_part

Methods inherited from ApplicationRecord

#to_partial_path

Class Method Details

.serialized_attr_accessor(*args) ⇒ Object

Spina previously stored account preferences with symbols as keys. Because of CVE-2022-32224 we’re changing that to strings instead. This fallback ensures backwards compatibility, but in the long run this should be refactored to use a simple JSONB-column with Postgres.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/spina/account.rb', line 22

def self.serialized_attr_accessor(*args)
  args.each do |method_name|
    define_method method_name do
      if preferences.try(:[], method_name.to_sym).present?
        ActiveSupport::Deprecation.warn("#{method_name} is stored as a symbol. Please set and save it again using #{method_name}= on your Spina::Account model to store it as a string. You can do this from the UI by saving your account preferences.")
      end

      preferences.try(:[], method_name.to_s) ||
        preferences.try(:[], method_name.to_sym)
    end

    define_method "#{method_name}=" do |value|
      self.preferences ||= {}
      self.preferences.except!(method_name.to_sym)
      self.preferences[method_name.to_s] = value
    end
  end
end

Instance Method Details

#to_sObject



14
15
16
# File 'app/models/spina/account.rb', line 14

def to_s
  name
end