Class: Decidim::System::FileUploadSettingsForm

Inherits:
Form
  • Object
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.

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.


48
49
50
51
52
53
54
55
# File 'decidim-system/app/forms/decidim/system/file_upload_settings_form.rb', line 48

def final
  csv_attributes = [:allowed_file_extensions, :allowed_content_types]
  attributes.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
39
40
41
# File 'decidim-system/app/forms/decidim/system/file_upload_settings_form.rb', line 17

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

  attribute_set.each do |attr|
    key = attr.name.to_s
    next unless settings_hash.has_key?(key)

    # 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 = Rectify::FormAttribute.new(attr).value_from(
      settings_hash[key]
    )
    value.each do |k, v|
      value[k] = v.join(",") if v.is_a?(Array)
    end

    self[key] = value
  end
end