Sha256: 899ed5a7b5aa3c01cae72229c1fc37062c7fd014aa3636a384d6100e54df0adc

Contents?: true

Size: 848 Bytes

Versions: 59

Compression:

Stored size: 848 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # This form handles permissions for a particular action in the admin panel.
    class PermissionForm < Form
      attribute :authorization_handler_name, String
      attribute :options, String

      validate :sanitize
      validate :options_is_valid_json

      private

      def sanitize
        self.authorization_handler_name = nil if authorization_handler_name.blank?
        self.options = nil if authorization_handler_name.blank?
        self.options = nil if options.blank?
      end

      def options_is_valid_json
        return unless options

        result = JSON.parse(options)
        errors.add(:options, :invalid_json) unless result.is_a?(Hash)
        result
      rescue JSON::ParserError
        errors.add(:options, :invalid_json)
      end
    end
  end
end

Version data entries

59 entries across 59 versions & 2 rubygems

Version Path
decidim-admin-0.11.2 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.11.1 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.11.0.pre1 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.10.1 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.10.0 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.9.3 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.9.2 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.9.1 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.9.0 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.8.4 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.8.3 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.8.2 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.8.1 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.8.0 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.7.4 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.7.3 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.7.2 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.7.1 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.7.0 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.6.8 app/forms/decidim/admin/permission_form.rb