Class: Decidim::DecidimAwesome::Admin::ConfigForm
- Inherits:
-
Form
- Object
- Form
- Decidim::DecidimAwesome::Admin::ConfigForm
- Includes:
- ActionView::Helpers::SanitizeHelper
- Defined in:
- app/forms/decidim/decidim_awesome/admin/config_form.rb
Instance Attribute Summary collapse
-
#valid_keys ⇒ Object
collect all keys anything not specified in the params (UpdateConfig command ignores it).
Class Method Summary collapse
-
.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
- #json_syntax ⇒ 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 anything not specified in the params (UpdateConfig command ignores it)
35 36 37 |
# File 'app/forms/decidim/decidim_awesome/admin/config_form.rb', line 35 def valid_keys @valid_keys end |
Class Method Details
.from_params(params, additional_params = {}) ⇒ Object
TODO: validate non general admins are here
49 50 51 52 53 54 |
# File 'app/forms/decidim/decidim_awesome/admin/config_form.rb', line 49 def self.from_params(params, additional_params = {}) instance = super(params, additional_params) instance.valid_keys = params.keys.map(&:to_sym) || [] instance.sanitize_labels! instance end |
Instance Method Details
#additional_proposal_sorting_labels ⇒ Object
56 57 58 59 60 |
# File 'app/forms/decidim/decidim_awesome/admin/config_form.rb', line 56 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
62 63 64 65 66 67 68 69 70 71 |
# File 'app/forms/decidim/decidim_awesome/admin/config_form.rb', line 62 def css_syntax scoped_styles.each do |key, code| next unless code SassC::Engine.new(code).render rescue SassC::SyntaxError => e errors.add(:scoped_styles, I18n.t("config.form.errors.incorrect_css", key:, scope: "decidim.decidim_awesome.admin")) errors.add(key.to_sym, e.) end end |
#json_syntax ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/forms/decidim/decidim_awesome/admin/config_form.rb', line 73 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_labels! ⇒ Object
formBuilder has a bug and do not sanitize text if users copy/paste text with format in the label input
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/forms/decidim/decidim_awesome/admin/config_form.rb', line 88 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 |