Class: Decidim::System::FileUploadSettingsForm

Inherits:
Form show all
Includes:
JsonbAttributes
Defined in:
decidim-system/app/forms/decidim/system/file_upload_settings_form.rb

Overview

A form object used to update organization file upload settings from the system dashboard.

Constant Summary

Constants included from AttributeObject::TypeMap

AttributeObject::TypeMap::Boolean, AttributeObject::TypeMap::Decimal

Instance Attribute Summary

Attributes inherited from AttributeObject::Form

#context

Instance Method Summary collapse

Methods inherited from AttributeObject::Form

ensure_hash, from_model, from_params, hash_from, infer_model_name, mimic, mimicked_model_name, model_name, #persisted?, #to_key, #to_model, #to_param, #valid?, #with_context

Methods included from AttributeObject::Model

#[], #[]=, #attributes, #attributes_with_values, #initialize, #to_h

Instance Method Details

#finalObject

This turns the attributes passed from the view into the final configuration array. Due to the UI component used for the array values, those values need to be handled as a single comma separated string in the view layer. Before we save those attributes, they need to be converted into arrays which is what this method does.



45
46
47
48
49
50
51
# File 'decidim-system/app/forms/decidim/system/file_upload_settings_form.rb', line 45

def final
  to_h.tap do |attr|
    csv_attributes.each do |key|
      attr[key] = csv_array_setting(attr[key])
    end
  end
end

#map_model(settings_hash) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'decidim-system/app/forms/decidim/system/file_upload_settings_form.rb', line 17

def map_model(settings_hash)
  settings_hash = if settings_hash.is_a?(Hash)
                    default_settings.deep_merge(settings_hash.deep_stringify_keys)
                  else
                    default_settings
                  end

  csv_attributes.each do |attr|
    next unless settings_hash.has_key?(attr.to_s)

    # For the view, the array values need to be in comma separated format
    # in order for them to work correctly with the tags inputs.
    value = settings_hash[attr.to_s]
    value.each do |k, v|
      value[k] = v.join(",") if v.is_a?(Array)
    end

    send("#{attr}=", value)
  end

  self.maximum_file_size = settings_hash["maximum_file_size"]
end