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)
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
48 49 50 51 52 53 |
# File 'app/forms/decidim/decidim_awesome/admin/config_form.rb', line 48 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
55 56 57 58 59 60 61 62 63 64 |
# File 'app/forms/decidim/decidim_awesome/admin/config_form.rb', line 55 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
66 67 68 69 70 71 72 73 74 75 |
# File 'app/forms/decidim/decidim_awesome/admin/config_form.rb', line 66 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
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/forms/decidim/decidim_awesome/admin/config_form.rb', line 78 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 |