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
- #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)
27 28 29 |
# File 'app/forms/decidim/decidim_awesome/admin/config_form.rb', line 27 def valid_keys @valid_keys end |
Class Method Details
.from_params(params, additional_params = {}) ⇒ Object
TODO: validate non general admins are here
34 35 36 37 38 39 |
# File 'app/forms/decidim/decidim_awesome/admin/config_form.rb', line 34 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
#css_syntax ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'app/forms/decidim/decidim_awesome/admin/config_form.rb', line 41 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: key, scope: "decidim.decidim_awesome.admin")) errors.add(key.to_sym, e.) end end |
#json_syntax ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'app/forms/decidim/decidim_awesome/admin/config_form.rb', line 52 def json_syntax proposal_custom_fields.each do |key, code| next unless code JSON.parse(code) rescue JSON::ParserError => e errors.add(:scoped_styles, I18n.t("config.form.errors.incorrect_json", key: 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
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/forms/decidim/decidim_awesome/admin/config_form.rb', line 64 def sanitize_labels! return unless proposal_custom_fields 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 end |