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-0.5.0 decidim-admin/app/forms/decidim/admin/permission_form.rb
decidim-admin-0.4.4 app/forms/decidim/admin/permission_form.rb
decidim-0.4.4 decidim-admin/app/forms/decidim/admin/permission_form.rb
decidim-admin-0.4.3 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.4.2 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.4.1 app/forms/decidim/admin/permission_form.rb
decidim-0.4.3 decidim-admin/app/forms/decidim/admin/permission_form.rb
decidim-0.4.2 decidim-admin/app/forms/decidim/admin/permission_form.rb
decidim-0.4.1 decidim-admin/app/forms/decidim/admin/permission_form.rb
decidim-admin-0.4.0 app/forms/decidim/admin/permission_form.rb
decidim-0.4.0 decidim-admin/app/forms/decidim/admin/permission_form.rb
decidim-admin-0.3.2 app/forms/decidim/admin/permission_form.rb
decidim-0.3.2 decidim-admin/app/forms/decidim/admin/permission_form.rb
decidim-admin-0.3.1 app/forms/decidim/admin/permission_form.rb
decidim-0.3.1 decidim-admin/app/forms/decidim/admin/permission_form.rb
decidim-admin-0.3.0 app/forms/decidim/admin/permission_form.rb
decidim-0.3.0 decidim-admin/app/forms/decidim/admin/permission_form.rb
decidim-admin-0.2.0 app/forms/decidim/admin/permission_form.rb
decidim-0.2.0 decidim-admin/app/forms/decidim/admin/permission_form.rb