Class: Decidim::DecidimAwesome::Admin::ConfigForm
- Inherits:
-
Form
- Object
- Form
- Decidim::DecidimAwesome::Admin::ConfigForm
- Includes:
- ActionView::Helpers::SanitizeHelper, TranslatableAttributes
- Defined in:
- app/forms/decidim/decidim_awesome/admin/config_form.rb
Instance Attribute Summary collapse
-
#valid_keys ⇒ Object
collect all keys specified in the params (UpdateConfig command ignores everything else).
Class Method Summary collapse
- .build_force_authorizations(raw_groups) ⇒ Object
-
.from_params(params, additional_params = {}) ⇒ Object
TODO: validate non general admins are here.
Instance Method Summary collapse
- #additional_proposal_sorting_labels ⇒ Object
- #css_syntax ⇒ Object
- #force_authorizations_attributes ⇒ Object
- #json_syntax ⇒ Object
- #sanitize_arrays! ⇒ Object
-
#sanitize_labels! ⇒ Object
formBuilder has a bug and do not sanitize text if users copy/paste text with format in the label input.
Instance Attribute Details
#valid_keys ⇒ Object
collect all keys specified in the params (UpdateConfig command ignores everything else)
43 44 45 |
# File 'app/forms/decidim/decidim_awesome/admin/config_form.rb', line 43 def valid_keys @valid_keys end |
Class Method Details
.build_force_authorizations(raw_groups) ⇒ Object
67 68 69 70 71 |
# File 'app/forms/decidim/decidim_awesome/admin/config_form.rb', line 67 def self.(raw_groups) raw_groups.transform_values do |group_data| group_data.is_a?(AuthorizationGroupForm) ? group_data : AuthorizationGroupForm.new(group_data) end end |
.from_params(params, additional_params = {}) ⇒ Object
TODO: validate non general admins are here
58 59 60 61 62 63 64 65 |
# File 'app/forms/decidim/decidim_awesome/admin/config_form.rb', line 58 def self.from_params(params, additional_params = {}) instance = super(params, additional_params) instance.valid_keys = params.keys.map(&:to_sym) || [] instance. = (instance.) instance.sanitize_labels! instance.sanitize_arrays! instance end |
Instance Method Details
#additional_proposal_sorting_labels ⇒ Object
79 80 81 82 83 |
# File 'app/forms/decidim/decidim_awesome/admin/config_form.rb', line 79 def additional_proposal_sorting_labels Decidim::DecidimAwesome.possible_additional_proposal_sortings.index_by do |sorting| I18n.t(sorting, scope: "decidim.proposals.proposals.orders") end end |
#css_syntax ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/forms/decidim/decidim_awesome/admin/config_form.rb', line 85 def css_syntax styles = {} styles.merge!(scoped_styles: scoped_styles.values) if scoped_styles.present? styles.merge!(scoped_admin_styles: scoped_admin_styles.values) if scoped_admin_styles.present? styles.each do |key, values| next if values.blank? values.each { |code| SassC::Engine.new(code).render } rescue SassC::SyntaxError => e errors.add(key, I18n.t("config.form.errors.incorrect_css", key:, scope: "decidim.decidim_awesome.admin")) errors.add(key.to_sym, e.) end end |
#force_authorizations_attributes ⇒ Object
73 74 75 76 77 |
# File 'app/forms/decidim/decidim_awesome/admin/config_form.rb', line 73 def return {} unless .is_a?(Hash) .transform_values(&:verification_settings) end |
#json_syntax ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'app/forms/decidim/decidim_awesome/admin/config_form.rb', line 99 def json_syntax fields = {} fields.merge!(proposal_custom_fields: proposal_custom_fields.values) if proposal_custom_fields.present? fields.merge!(proposal_private_custom_fields: proposal_private_custom_fields.values) if proposal_private_custom_fields.present? fields.each do |key, values| next if values.blank? values.each { |code| JSON.parse(code) } rescue JSON::JSONError => e errors.add(key, I18n.t("config.form.errors.incorrect_json", key:, scope: "decidim.decidim_awesome.admin")) errors.add(key.to_sym, e.) end end |
#sanitize_arrays! ⇒ Object
142 143 144 145 146 |
# File 'app/forms/decidim/decidim_awesome/admin/config_form.rb', line 142 def sanitize_arrays! scoped_admins.transform_values! do |code| code.is_a?(Array) ? code.compact_blank : code end end |
#sanitize_labels! ⇒ Object
formBuilder has a bug and do not sanitize text if users copy/paste text with format in the label input
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'app/forms/decidim/decidim_awesome/admin/config_form.rb', line 114 def sanitize_labels! proposal_custom_fields.transform_values! do |code| next unless code json = JSON.parse(code) json.map! do |item| item["label"] = (item["label"]) item end JSON.generate(json) rescue JSON::ParserError code end proposal_private_custom_fields.transform_values! do |code| next unless code json = JSON.parse(code) json.map! do |item| item["label"] = (item["label"]) item end JSON.generate(json) rescue JSON::ParserError code end end |