Class: Decidim::System::FileUploadSettingsForm

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

Overview

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

Instance Method Summary collapse

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 '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 '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