Class: Decidim::System::UpdateOrganizationForm

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

Overview

A form object used to update organizations from the system dashboard.

Direct Known Subclasses

RegisterOrganizationForm

Constant Summary collapse

OMNIATH_PROVIDERS_ATTRIBUTES =
Decidim::OmniauthProvider.available.keys.map do |provider|
  Rails.application.secrets.dig(:omniauth, provider).keys.map do |setting|
    if setting == :enabled
      ["omniauth_settings_#{provider}_enabled".to_sym, Boolean]
    else
      ["omniauth_settings_#{provider}_#{setting}".to_sym, String]
    end
  end
end.flatten(1)

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 included from TranslatableAttributes

#default_locale?

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

#clean_available_authorizationsObject



77
78
79
80
81
# File 'decidim-system/app/forms/decidim/system/update_organization_form.rb', line 77

def clean_available_authorizations
  return unless available_authorizations

  available_authorizations.select(&:present?)
end

#clean_secondary_hostsObject



71
72
73
74
75
# File 'decidim-system/app/forms/decidim/system/update_organization_form.rb', line 71

def clean_secondary_hosts
  return unless secondary_hosts

  secondary_hosts.split("\n").map(&:chomp).select(&:present?)
end

#encrypted_omniauth_settingsObject



99
100
101
102
103
# File 'decidim-system/app/forms/decidim/system/update_organization_form.rb', line 99

def encrypted_omniauth_settings
  omniauth_settings.transform_values do |v|
    Decidim::OmniauthProvider.value_defined?(v) ? Decidim::AttributeEncryptor.encrypt(v) : v
  end
end

#encrypted_smtp_settingsObject



87
88
89
90
91
# File 'decidim-system/app/forms/decidim/system/update_organization_form.rb', line 87

def encrypted_smtp_settings
  smtp_settings["from"] = set_from

  smtp_settings.merge(encrypted_password: Decidim::AttributeEncryptor.encrypt(password))
end

#map_model(model) ⇒ Object



63
64
65
66
67
68
69
# File 'decidim-system/app/forms/decidim/system/update_organization_form.rb', line 63

def map_model(model)
  self.secondary_hosts = model.secondary_hosts.join("\n")
  self.omniauth_settings = (model.omniauth_settings || {}).transform_values do |v|
    Decidim::OmniauthProvider.value_defined?(v) ? Decidim::AttributeEncryptor.decrypt(v) : v
  end
  self.file_upload_settings = FileUploadSettingsForm.from_model(model.file_upload_settings)
end

#passwordObject



83
84
85
# File 'decidim-system/app/forms/decidim/system/update_organization_form.rb', line 83

def password
  encrypted_password.nil? ? super : Decidim::AttributeEncryptor.decrypt(encrypted_password)
end

#set_fromObject



93
94
95
96
97
# File 'decidim-system/app/forms/decidim/system/update_organization_form.rb', line 93

def set_from
  return from_email if from_label.blank?

  "#{from_label} <#{from_email}>"
end